Skip to content

Commit 3f9272f

Browse files
committed
packrat: Return an error if an ereport was lost (#2225)
This commit changes `task-packrat-api`'s `deliver_ereport` IPC to return an error if the ereport did not fit in the buffer, rather than being infallible. In the future, this may allow some tasks to attempt re-delivery periodically until there's space.
1 parent 69d3793 commit 3f9272f

File tree

7 files changed

+54
-17
lines changed

7 files changed

+54
-17
lines changed

drv/cosmo-seq-server/src/vcore.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ enum Trace {
7272
StatusCml(Rail, Result<u8, ResponseCode>),
7373
StatusMfrSpecific(Rail, Result<u8, ResponseCode>),
7474
I2cError(Rail, PmbusCmd, raa229620a::Error),
75-
EreportSentOff(Rail, usize),
75+
EreportSent(Rail, usize),
76+
EreportLost(Rail, usize, packrat::EreportWriteError),
7677
EreportTooBig(Rail),
7778
}
7879

@@ -448,7 +449,14 @@ fn deliver_ereport(
448449
match data.serialize(&mut s) {
449450
Ok(_) => {
450451
let len = s.into_encoder().into_writer().position();
451-
packrat.deliver_ereport(&ereport_buf[..len]);
452+
match packrat.deliver_ereport(&ereport_buf[..len]) {
453+
Ok(_) => {
454+
ringbuf_entry!(Trace::EreportSent(rail, len));
455+
}
456+
Err(e) => {
457+
ringbuf_entry!(Trace::EreportLost(rail, len, e));
458+
}
459+
}
452460
ringbuf_entry!(Trace::EreportSentOff(rail, len));
453461
}
454462
Err(_) => {

drv/gimlet-seq-server/src/vcore.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ enum Trace {
6161
StatusMfrSpecific(Result<u8, ResponseCode>),
6262
Reading { timestamp: u64, volts: units::Volts },
6363
Error(ResponseCode),
64-
EreportSentOff(usize),
64+
EreportSent(usize),
65+
EreportLost(usize, packrat_api::EreportWriteError),
6566
EreportTooBig,
6667
}
6768

@@ -343,8 +344,14 @@ fn deliver_ereport(packrat: &packrat_api::Packrat, data: &impl Serialize) {
343344
match data.serialize(&mut s) {
344345
Ok(_) => {
345346
let len = s.into_encoder().into_writer().position();
346-
packrat.deliver_ereport(&ereport_buf[..len]);
347-
ringbuf_entry!(Trace::EreportSentOff(len));
347+
match packrat.deliver_ereport(&ereport_buf[..len]) {
348+
Ok(_) => {
349+
ringbuf_entry!(Trace::EreportSent(len));
350+
}
351+
Err(e) => {
352+
ringbuf_entry!(Trace::EreportLost(len, e));
353+
}
354+
}
348355
}
349356
Err(_) => {
350357
// XXX(eliza): ereport didn't fit in buffer...what do

idl/packrat.idol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ Interface(
120120
leases: {
121121
"data": (type: "[u8]", read: true, max_len: Some(1024)),
122122
},
123-
reply: Simple("()"),
123+
reply: Result(
124+
ok: "()",
125+
err: CLike("EreportWriteError"),
126+
),
124127
idempotent: true,
125128
),
126129
"read_ereports": (

task/ereportulator/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ enum Trace {
6262
EreportDelivered {
6363
encoded_len: usize,
6464
},
65+
EreportLost {
66+
encoded_len: usize,
67+
err: task_packrat_api::EreportWriteError,
68+
},
6569
}
6670

6771
counted_ringbuf!(Trace, 16, Trace::None);
@@ -121,8 +125,10 @@ impl idl::InOrderEreportulatorImpl for ServerImpl {
121125
encoder.into_writer().position()
122126
};
123127

124-
self.packrat.deliver_ereport(&self.buf[..encoded_len]);
125-
ringbuf_entry!(Trace::EreportDelivered { encoded_len });
128+
match self.packrat.deliver_ereport(&self.buf[..encoded_len]) {
129+
Ok(_) => ringbuf_entry!(Trace::EreportDelivered { encoded_len }),
130+
Err(err) => ringbuf_entry!(Trace::EreportLost { encoded_len, err }),
131+
}
126132

127133
Ok(())
128134
}

task/packrat-api/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ pub enum EreportReadError {
6060
RestartIdNotSet = 1,
6161
}
6262

63+
#[derive(
64+
Copy, Clone, Debug, FromPrimitive, Eq, PartialEq, IdolError, counters::Count,
65+
)]
66+
pub enum EreportWriteError {
67+
/// Indicates that an ereport was lost because it would not have fit in
68+
/// Packrat's ereport buffer.
69+
Lost = 1,
70+
}
71+
6372
include!(concat!(env!("OUT_DIR"), "/client_stub.rs"));

task/packrat/src/ereport.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
1515
use super::ereport_messages;
1616

17-
use core::convert::Infallible;
1817
use idol_runtime::{ClientError, Leased, LenLimit, RequestError};
1918
use minicbor::CborLen;
2019
use minicbor_lease::LeasedWriter;
2120
use ringbuf::{counted_ringbuf, ringbuf_entry};
22-
use task_packrat_api::{EreportReadError, VpdIdentity};
21+
use task_packrat_api::{EreportReadError, EreportWriteError, VpdIdentity};
2322
use userlib::{kipc, sys_get_timer, RecvMessage, TaskId};
2423
use zerocopy::IntoBytes;
2524

@@ -118,7 +117,7 @@ impl EreportStore {
118117
&mut self,
119118
msg: &RecvMessage,
120119
data: LenLimit<Leased<idol_runtime::R, [u8]>, RECV_BUF_SIZE>,
121-
) -> Result<(), RequestError<Infallible>> {
120+
) -> Result<(), RequestError<EreportWriteError>> {
122121
data.read_range(0..data.len(), self.recv)
123122
.map_err(|_| ClientError::WentAway.fail())?;
124123
let timestamp = sys_get_timer().now;
@@ -132,7 +131,12 @@ impl EreportStore {
132131
len: data.len() as u32,
133132
result,
134133
});
135-
Ok(())
134+
match result {
135+
snitch_core::InsertResult::Inserted => Ok(()),
136+
snitch_core::InsertResult::Lost => {
137+
Err(RequestError::from(EreportWriteError::Lost))
138+
}
139+
}
136140
}
137141

138142
pub(crate) fn read_ereports(

task/packrat/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ use idol_runtime::{Leased, LenLimit, NotificationHandler, RequestError};
6969
use ringbuf::{ringbuf, ringbuf_entry};
7070
use static_cell::ClaimOnceCell;
7171
use task_packrat_api::{
72-
CacheGetError, CacheSetError, EreportReadError, HostStartupOptions,
73-
MacAddressBlock, VpdIdentity,
72+
CacheGetError, CacheSetError, EreportReadError, EreportWriteError,
73+
HostStartupOptions, MacAddressBlock, VpdIdentity,
7474
};
7575
use userlib::RecvMessage;
7676

@@ -519,7 +519,7 @@ impl idl::InOrderPackratImpl for ServerImpl {
519519
&mut self,
520520
_: &RecvMessage,
521521
_: LenLimit<Leased<idol_runtime::R, [u8]>, 1024usize>,
522-
) -> Result<(), RequestError<Infallible>> {
522+
) -> Result<(), RequestError<EreportWriteError>> {
523523
// go away, we don't know how to do that
524524
Err(idol_runtime::ClientError::UnknownOperation.fail())
525525
}
@@ -529,7 +529,7 @@ impl idl::InOrderPackratImpl for ServerImpl {
529529
&mut self,
530530
msg: &RecvMessage,
531531
data: LenLimit<Leased<idol_runtime::R, [u8]>, 1024usize>,
532-
) -> Result<(), RequestError<Infallible>> {
532+
) -> Result<(), RequestError<EreportWriteError>> {
533533
self.ereport_store.deliver_ereport(msg, data)
534534
}
535535

@@ -585,7 +585,7 @@ impl NotificationHandler for ServerImpl {
585585
mod idl {
586586
use super::{
587587
ereport_messages, CacheGetError, CacheSetError, EreportReadError,
588-
HostStartupOptions, MacAddressBlock, VpdIdentity,
588+
EreportWriteError, HostStartupOptions, MacAddressBlock, VpdIdentity,
589589
};
590590

591591
include!(concat!(env!("OUT_DIR"), "/server_stub.rs"));

0 commit comments

Comments
 (0)