Skip to content
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

Measure the Cost of Traps, World Switches, and Misaligned Operat… #372

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

francois141
Copy link
Collaborator

…ions with the Protect Payload Policy

This commit extends the tracing firmware with three new latency measurements in the Protect Payload policy and ensures that no additional performance losses are introduced.

@francois141
Copy link
Collaborator Author

@CharlyCst Let's first merge this pr and then the other. So we can see the cycle gain for the decoder

@francois141 francois141 marked this pull request as draft January 4, 2025 11:12
@francois141 francois141 force-pushed the benchmark-cost-emulation branch from e98c201 to e66ee3a Compare January 4, 2025 19:12
@francois141 francois141 marked this pull request as ready for review January 4, 2025 19:13
@francois141 francois141 changed the title WIP: Measure the Cost of Traps, World Switches, and Misaligned Operat… Measure the Cost of Traps, World Switches, and Misaligned Operat… Jan 4, 2025
Copy link
Owner

@CharlyCst CharlyCst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, it's cool to have more stats :)

So turns out tracing_firmware and tracing_firmware_protect_payload are basically the same file at the exception of the name of the policy according to diff:

➜  firmware git:(851f56c5) ✗ diff tracing_firmware/main.rs tracing_firmware_protect_payload/main.rs
36c36
<         "Default",
---
>         "Protect",
74c74
<         "Default",
---
>         "Protect",
80c80
<         "Default",
---
>         "Protect",

But can simply read the policy name from the config, as we do in Miralis:

pub const POLICY_NAME: &str = parse_str_or(option_env!("MIRALIS_POLICY_NAME"), "default_policy");

(if the firmware don't have access to it then we should fix that and expose the environment variables too)

Using this we can simply have a single tracing firmware (and so we don't need the library anymore), which will make things much easier to maintain in the long run :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am writing some comments here, but as explained in the main review feedback we can simply get rid of this library by having a single tracing firmware and keeping things simple.

So the comments on this file are simply informational.

Comment on lines 1 to 7
//! Miralis ABI
//!
//! While miralis forwards standard SBI calls to the virtualized firmware, miralis do expose its own
//! ABI for the firmware to interact with.
//!
//! The Miralis ABI tries to be compatible with the SBI specification as best as it can.
//! See: https://github.com/riscv-non-isa/riscv-sbi-doc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy paste from another library, it doesn't explain what this library is doing nor how it should be used. The current doc comment might cause confusion and make the crate less maintainable.

values[i] = $in();
}

let stats = get_statistics(values);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro uses locally-defined function, so it will fail with a compile error when used by another crate or module. There is a simple way to fix this, which is to use an absolute path for each local function used. There is a magic variable $crate to do that:

let stats = $crate::get_statistics(values)

With the above version the macro can be used without importing the get_statistics function. In general macros in libraries should encapsulate all of their import so that they work like standard functions.

Comment on lines 48 to 61
global_asm!(
r#"
.text
.align 4
.global _empty_handler
_empty_handler:
// Skip illegal instruction (pc += 4)
csrrw x5, mepc, x5
addi x5, x5, 4
csrrw x5, mepc, x5
// Return back to OS
mret
"#,
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In libraries we don't want to insert global assembly, because it can override existing symbols and cause at best linker errors, at worst arbitrarily bad things.

@francois141 francois141 force-pushed the benchmark-cost-emulation branch from e66ee3a to 804837d Compare January 7, 2025 22:22
@francois141
Copy link
Collaborator Author

@CharlyCst Thank you for all the nice and relevants comments. I did the changes. Feel free to review again ;)

… with the Protect Payload Policy

This commit extends the tracing firmware by introducing three new latency measurements in the Protect Payload policy and ensures that no additional performance losses are incurred.
@CharlyCst CharlyCst force-pushed the benchmark-cost-emulation branch from 804837d to fa7032b Compare January 9, 2025 15:07
Copy link
Owner

@CharlyCst CharlyCst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, looks good to me :)

@CharlyCst CharlyCst merged commit b378908 into main Jan 9, 2025
1 check passed
@CharlyCst CharlyCst deleted the benchmark-cost-emulation branch January 9, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants