Skip to content

lib: include die name in decoded record. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,28 @@ impl Header {
}
}

#[cfg(feature = "collateral_manager")]
pub(super) fn get_root_path_cm<T: CollateralTree>(
&self,
cm: &CollateralManager<T>,
) -> Option<String> {
if let HeaderType::Type6 { socket_id, .. } = self.header_type {
if let Some(die) = self.die(cm) {
Some(format!("processors.cpu{socket_id}.{die}"))
} else {
self.get_root_path()
}
} else {
None
}
}

pub(super) fn get_root_path(&self) -> Option<String> {
if let HeaderType::Type6 {
socket_id, die_id, ..
} = self.header_type
{
Some(format!("processors.cpu{}.die{}", socket_id, die_id))
Some(format!("processors.cpu{socket_id}.die{die_id}"))
} else {
None
}
Expand Down
21 changes: 12 additions & 9 deletions lib/src/record/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ impl Record {

pub fn decode_with_csv(&self, layout: &[u8], offset: usize) -> Result<Node, Error> {
let mut root = Node::root();
let record_root = if let Some(custom_root) = self.header.get_root_path() {
root.create_hierarchy(&custom_root)
} else {
&mut root
};

let csv = str::from_utf8(layout)?;
let mut columns = Vec::new();
Expand Down Expand Up @@ -97,9 +92,9 @@ impl Record {
current_path.clear();
current_path.push(top.to_owned());

if record_root.get(top).is_none() {
if root.get(top).is_none() {
// Top-level is assumed to be the record name
record_root.add(Node::record(top));
root.add(Node::record(top));
}
}

Expand All @@ -111,7 +106,7 @@ impl Record {
}
}

let node = record_root.create_hierarchy_from_iter(&current_path);
let node = root.create_hierarchy_from_iter(&current_path);
node.description = entry.description;
if let Some(value) = self.read_field(offset * 8 + entry.offset, entry.size) {
node.kind = NodeType::Field { value }
Expand Down Expand Up @@ -144,12 +139,20 @@ impl Record {
) -> Result<Node, Error> {
let paths = self.header.decode_definitions_paths(cm)?;

let mut root = Node::root();
let record_root = if let Some(custom_root) = self.header.get_root_path_cm(cm) {
root.create_hierarchy(&custom_root)
} else {
&mut root
};

for mut path in paths {
path.push(decode_def);
let Ok(layout) = cm.get_item_with_header(&self.header, path) else {
continue;
};
return self.decode_with_csv(layout, offset);
record_root.merge(self.decode_with_csv(layout, offset)?);
return Ok(root);
}

Err(Error::MissingDecodeDefinitions(self.header.version.clone()))
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ fn header_type6_decode() {

let root = record.decode(&mut cm).unwrap();
let version = root
.get_by_path("processors.cpu0.die1.mca.hdr.version.revision")
.get_by_path("processors.cpu0.io1.mca.hdr.version.revision")
.unwrap();

assert_eq!(version.kind, NodeType::Field { value: 2 });

let die_id = root
.get_by_path("processors.cpu0.die1.mca.hdr.die_skt_info.die_id")
.get_by_path("processors.cpu0.io1.mca.hdr.die_skt_info.die_id")
.unwrap();

assert_eq!(die_id.kind, NodeType::Field { value: 1 });
Expand Down