Skip to content

Commit

Permalink
host-sp-comms: add event counters
Browse files Browse the repository at this point in the history
This branch adds event counters to `host-sp-comms`'s existing 20-element
ringbuffer, so that the total number of events can be tracked. In
particular, we count the total number of each message variant messages
sent and received between the host and SP, and each variant of the
`KeyLookupResult`, `KeySetResult`, and `InventoryResult` messages.

Depends on #1635.
  • Loading branch information
hawkw committed Feb 28, 2024
1 parent 42bc641 commit 75a1e80
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/host-sp-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ oxide-barcode.path = "../oxide-barcode"
unwrap-lite.path = "../unwrap-lite"
drv-i2c-types.path = "../../drv/i2c-types" # to implement From<ResponseCode>
task-sensor-types.path = "../../task/sensor-types"
counters.path = "../../lib/counters"
66 changes: 58 additions & 8 deletions lib/host-sp-messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ pub struct Header {
/// expect. When updating this enum, make sure to update that test and check
/// that it contains the expected values.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, SerializedSize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize,
Serialize,
SerializedSize,
counters::Count,
)]
pub enum HostToSp {
// Microoptimization: insert a dummy variant first, so we never serialize a
// command value of `0` to make COBS's life slightly easier.
#[count(skip)]
_Unused,
RequestReboot,
RequestPowerOff,
Expand Down Expand Up @@ -128,11 +137,20 @@ pub enum HostToSp {
/// expect. When updating this enum, make sure to update that test and check
/// that it contains the expected values.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, SerializedSize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize,
Serialize,
SerializedSize,
counters::Count,
)]
pub enum SpToHost {
// Microoptimization: insert a dummy variant first, so we never serialize a
// command value of `0` to make COBS's life slightly easier.
#[count(skip)]
_Unused,
Ack,
DecodeFailure(DecodeFailureReason),
Expand Down Expand Up @@ -160,14 +178,15 @@ pub enum SpToHost {
// If `result` is `KeyLookupResult::Ok`, this will be followed by a binary
// blob of length at most `max_response_len` from the corresponding request.
// For any other result, there is no subsequent binary blob.
KeyLookupResult(KeyLookupResult),
KeyLookupResult(#[count(children)] KeyLookupResult),
// If `result` is `InventoryDataResult::Ok`, this will be followed by a
// binary blob of a hubpack-serialized `InventoryData` value.
InventoryData {
#[count(children)]
result: InventoryDataResult,
name: [u8; 32],
},
KeySetResult(KeySetResult),
KeySetResult(#[count(children)] KeySetResult),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, num_derive::FromPrimitive)]
Expand All @@ -184,7 +203,15 @@ pub enum Key {
}

#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, SerializedSize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize,
Serialize,
SerializedSize,
counters::Count,
)]
pub enum KeyLookupResult {
Ok,
Expand All @@ -198,7 +225,15 @@ pub enum KeyLookupResult {
}

#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, SerializedSize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize,
Serialize,
SerializedSize,
counters::Count,
)]
pub enum KeySetResult {
Ok,
Expand All @@ -215,7 +250,15 @@ pub enum KeySetResult {
///
/// These **cannot be reordered**; the host and SP must agree on them.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, SerializedSize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize,
Serialize,
SerializedSize,
counters::Count,
)]
pub enum InventoryDataResult {
Ok,
Expand Down Expand Up @@ -481,7 +524,14 @@ impl hubpack::SerializedSize for Bsu {

// See RFD 316 for values.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize_repr, Serialize_repr,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Deserialize_repr,
Serialize_repr,
counters::Count,
)]
#[repr(u8)]
pub enum DecodeFailureReason {
Expand Down
2 changes: 2 additions & 0 deletions task/host-sp-comms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ zerocopy.workspace = true
tlvc = { workspace = true, optional = true }
pmbus = { workspace = true, optional = true }

counters.path = "../../lib/counters"

drv-gimlet-hf-api.path= "../../drv/gimlet-hf-api"
drv-gimlet-seq-api.path= "../../drv/gimlet-seq-api"
drv-oxide-vpd.path= "../../drv/oxide-vpd"
Expand Down
13 changes: 9 additions & 4 deletions task/host-sp-comms/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use hubpack::SerializedSize;
use idol_runtime::{NotificationHandler, RequestError};
use multitimer::{Multitimer, Repeat};
use mutable_statics::mutable_statics;
use ringbuf::{ringbuf, ringbuf_entry};
use ringbuf::{counted_ringbuf, ringbuf_entry};
use static_assertions::const_assert;
use task_control_plane_agent_api::{
ControlPlaneAgent, MAX_INSTALLINATOR_IMAGE_ID_LEN,
Expand Down Expand Up @@ -89,13 +89,15 @@ const MAX_HOST_FAIL_MESSAGE_LEN: usize = 4096;
// of that for us.
const NUM_HOST_MAC_ADDRESSES: u16 = 3;

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, counters::Count)]
enum Trace {
#[count(skip)]
None,
UartRxOverrun,
ParseError(DecodeFailureReason),
ParseError(#[count(children)] DecodeFailureReason),
SetState {
now: u64,
#[count(children)]
state: PowerState,
},
HfMux {
Expand All @@ -104,13 +106,15 @@ enum Trace {
},
JefeNotification {
now: u64,
#[count(children)]
state: PowerState,
},
OutOfSyncRequest,
OutOfSyncRxNoise,
Request {
now: u64,
sequence: u64,
#[count(children)]
message: HostToSp,
},
ResponseBufferReset {
Expand All @@ -119,11 +123,12 @@ enum Trace {
Response {
now: u64,
sequence: u64,
#[count(children)]
message: SpToHost,
},
}

ringbuf!(Trace, 20, Trace::None);
counted_ringbuf!(Trace, 20, Trace::None);

#[derive(Debug, Clone, Copy, PartialEq)]
enum TimerDisposition {
Expand Down

0 comments on commit 75a1e80

Please sign in to comment.