Skip to content

Commit

Permalink
c-p-a: add counters to control-plane-agent (#1630)
Browse files Browse the repository at this point in the history
Issue #1616 describes the need to add event counters to the
`control-plane-agent` task. In particular, it's desirable to have
counters of each IPC event and MGS message received by the
`control-plane-agent` task. This commit uses the ringbuf counters added
in #1621 and the `#[count(children)]` attribute added in this branch to
generate counters from `control-plane-agent`'s MGS message events.
  • Loading branch information
hawkw committed Feb 26, 2024
1 parent d118d12 commit be4f6f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
15 changes: 9 additions & 6 deletions lib/ringbuf/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use syn::{parse_macro_input, DeriveInput, parse::{Parse, ParseStream}};

use syn::{
parse::{Parse, ParseStream},
parse_macro_input, DeriveInput,
};

/// Derives an implementation of the `ringbuf::Count` trait for the annotated
/// `enum` type.
///
Expand Down Expand Up @@ -69,10 +72,10 @@ fn gen_count_impl(input: DeriveInput) -> Result<impl ToTokens, syn::Error> {
VariantAttr::Skip => {
any_skipped = true;
continue 'variants;
},
}
VariantAttr::Children => {
count_children = Some(attr);
},
}
}
}

Expand Down Expand Up @@ -131,7 +134,8 @@ fn gen_count_impl(input: DeriveInput) -> Result<impl ToTokens, syn::Error> {
#[doc = " has been recorded by this ringbuf."]
pub #ident: core::sync::atomic::AtomicU32
});
field_inits.push(quote! { #ident: core::sync::atomic::AtomicU32::new(0) });
field_inits
.push(quote! { #ident: core::sync::atomic::AtomicU32::new(0) });
}
}

Expand Down Expand Up @@ -201,7 +205,6 @@ impl Parse for VariantAttr {
}
}


fn counts_ty(ident: &Ident) -> Ident {
Ident::new(&format!("{ident}Counts"), Span::call_site())
}
26 changes: 19 additions & 7 deletions task/control-plane-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use idol_runtime::{
ClientError, Leased, LenLimit, NotificationHandler, RequestError,
};
use mutable_statics::mutable_statics;
use ringbuf::{ringbuf, ringbuf_entry};
use ringbuf::{counted_ringbuf, ringbuf_entry};
use task_control_plane_agent_api::MAX_INSTALLINATOR_IMAGE_ID_LEN;
use task_control_plane_agent_api::{
BarcodeParseError, ControlPlaneAgentError, UartClient, VpdIdentity,
Expand Down Expand Up @@ -48,18 +48,30 @@ task_slot!(SYS, sys);
#[allow(dead_code)] // Not all cases are used by all variants
#[derive(Debug, Clone, Copy, PartialEq, ringbuf::Count)]
enum Log {
#[count(skip)]
Empty,
BarcodeParseError(BarcodeParseError),
Rx(UdpMetadata),
SendError(SendError),
#[count(children)]
MgsMessage(MgsMessage),
UsartTxFull { remaining: usize },
UsartTxFull {
remaining: usize,
},
UsartRxOverrun,
UsartRxBufferDataDropped { num_bytes: u64 },
SerialConsoleSend { buffered: usize },
UpdatePartial { bytes_written: u32 },
UsartRxBufferDataDropped {
num_bytes: u64,
},
SerialConsoleSend {
buffered: usize,
},
UpdatePartial {
bytes_written: u32,
},
UpdateComplete,
HostFlashSectorsErased { num_sectors: usize },
HostFlashSectorsErased {
num_sectors: usize,
},
ExpectedRspTimeout,
RotReset(SprotError),
SprotCabooseSize(u32),
Expand All @@ -72,7 +84,7 @@ enum Log {
// `Log` enum above (which itself is only used by our ringbuf logs). The MGS
// protocol is defined in the `gateway-messages` crate (which is shared with
// MGS proper and other tools like `sp-sim` in the omicron repository).
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, ringbuf::Count)]
enum MgsMessage {
Discovery,
IgnitionState {
Expand Down

0 comments on commit be4f6f1

Please sign in to comment.