Skip to content

Commit

Permalink
Hooked up logging to the runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbin committed Jul 2, 2024
1 parent 41e3a3e commit 0e4343b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
25 changes: 19 additions & 6 deletions copper/src/copperlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ extern crate alloc;
use bincode_derive::{Decode, Encode};
use std::fmt;

use copper_traits::CopperListPayload;
use serde_derive::Serialize;
use std::fmt::Display;
use std::iter::{Chain, Rev};
use std::slice::{Iter as SliceIter, IterMut as SliceIterMut};

use copper_traits::CopperListPayload;

const MAX_TASKS: usize = 512;

#[derive(Debug, Encode, Decode, PartialEq, Clone, Copy)]
Expand All @@ -16,15 +17,27 @@ pub struct CopperLiskMask {
mask: [u128; MAX_TASKS / 128 + 1],
}

#[derive(Debug, Encode, Decode, PartialEq, Copy, Clone)]
#[derive(Debug, Encode, Decode, Serialize, PartialEq, Copy, Clone)]
pub enum CopperListState {
Free,
Initialized,
ProcessingTasks(CopperLiskMask),
Processing,
DoneProcessing,
BeingSerialized,
}

impl Display for CopperListState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CopperListState::Free => write!(f, "Free"),
CopperListState::Initialized => write!(f, "Initialized"),
CopperListState::Processing => write!(f, "Processing"),
CopperListState::DoneProcessing => write!(f, "DoneProcessing"),
CopperListState::BeingSerialized => write!(f, "BeingSerialized"),
}
}
}

#[derive(Debug, Encode, Decode)]
pub struct CopperList<P: CopperListPayload> {
pub id: u32,
Expand All @@ -42,11 +55,11 @@ impl<P: CopperListPayload> CopperList<P> {
}
}

pub(crate) fn change_state(&mut self, new_state: CopperListState) {
pub fn change_state(&mut self, new_state: CopperListState) {
self.state = new_state; // TODO: probably wise here to enforce a state machine.
}

pub(crate) fn get_state(&self) -> CopperListState {
pub fn get_state(&self) -> CopperListState {
self.state
}
}
Expand Down
14 changes: 11 additions & 3 deletions copper/src/curuntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ impl<CT, P: CopperListPayload + 'static, const NBCL: usize> CuRuntime<CT, P, NBC

pub fn end_of_processing(&mut self, culistid: u32) {
debug!("End of processing for CL #{}", culistid);
self.copper_lists.asc_iter_mut().for_each(|cl| {
if cl.id == culistid {
let mut is_top = true;
self.copper_lists.iter_mut().for_each(|cl| {
if cl.id == culistid && cl.get_state() == CopperListState::Processing {
cl.change_state(CopperListState::DoneProcessing);
}
if cl.get_state() == CopperListState::DoneProcessing {
// if we have a series of copper lists that are done processing at the top of the circular buffer
// serialize them all and Free them.
if is_top && cl.get_state() == CopperListState::DoneProcessing {
cl.change_state(CopperListState::BeingSerialized);
debug!("Logging CL #{}", cl.id);
self.logger.log(&cl).unwrap();
cl.change_state(CopperListState::Free);
} else {
is_top = false;
}
});
}
Expand Down
4 changes: 1 addition & 3 deletions copper_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,13 @@ pub fn copper_runtime(args: TokenStream, input: TokenStream) -> TokenStream {

let mut culist = &mut self.copper_runtime.copper_lists.create().expect("Ran out of space for copper lists"); // FIXME: error handling.
let id = culist.id;
culist.change_state(copper::copperlist::CopperListState::Processing);
let payload = &mut culist.payload;

#(#runtime_plan_code)*
drop(payload);

let md = collect_metadata(&culist);
for m in md.iter() {
println!("Metadata: {}", m);
}
let e2e = md.last().unwrap().after_process.unwrap() - md.first().unwrap().before_process.unwrap();
let e2en: u64 = e2e.into();
println!("End to end latency {}, mean latency per hop: {}", e2e, e2en / (md.len() as u64));
Expand Down

0 comments on commit 0e4343b

Please sign in to comment.