Skip to content

Commit

Permalink
Add default functions in BenchmarkModule trait
Browse files Browse the repository at this point in the history
This refactoring reduces a bit the number of lines of LoC by deduplicating the empty functions in the trait directly
  • Loading branch information
francois141 authored and CharlyCst committed Feb 6, 2025
1 parent 0486a13 commit d9700ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
4 changes: 0 additions & 4 deletions src/benchmark/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ impl BenchmarkModule for CounterBenchmark {
"Counter benchmark"
}

fn start_interval_counters(_scope: Scope) {}

fn stop_interval_counters(_scope: Scope) {}

fn increment_counter(counter: Counter) {
if counter == FirmwareExits {
NB_FIRMWARE_EXIT[hard_id()]
Expand Down
26 changes: 1 addition & 25 deletions src/benchmark/empty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::benchmark::default::IntervalCounter;
use crate::benchmark::{BenchmarkModule, Counter, Scope};
use crate::virt::VirtContext;
use crate::benchmark::BenchmarkModule;

pub struct EmptyBenchmark {}

Expand All @@ -12,26 +10,4 @@ impl BenchmarkModule for EmptyBenchmark {
fn name() -> &'static str {
"Empty Benchmark"
}

fn start_interval_counters(_scope: Scope) {}

fn stop_interval_counters(_scope: Scope) {}

fn increment_counter(_counter: Counter) {}

fn update_inteval_counter_stats(
&mut self,
_counter: &IntervalCounter,
_scope: &Scope,
_value: usize,
) {
}

fn read_counters(_ctx: &mut VirtContext) {}

fn display_counters() {}

fn get_counter_value(_core_id: usize, _counter: Counter) -> usize {
0
}
}
23 changes: 13 additions & 10 deletions src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ pub trait BenchmarkModule {
fn init() -> Self;
fn name() -> &'static str;

fn start_interval_counters(scope: Scope);
fn stop_interval_counters(scope: Scope);
fn increment_counter(counter: Counter);
fn start_interval_counters(_scope: Scope) {}
fn stop_interval_counters(_scope: Scope) {}
fn increment_counter(_counter: Counter) {}

fn update_inteval_counter_stats(
&mut self,
counter: &IntervalCounter,
scope: &Scope,
value: usize,
);
_counter: &IntervalCounter,
_scope: &Scope,
_value: usize,
) {
}

/// Print formated string with value of the counters
fn display_counters();
fn display_counters() {}

/// Read the performance counters into the virtual registers.
///
/// Note: the specific ABI is depends on the benchmark back-end.
fn read_counters(ctx: &mut VirtContext);
fn read_counters(_ctx: &mut VirtContext) {}

fn get_counter_value(core_id: usize, counter: Counter) -> usize;
fn get_counter_value(_core_id: usize, _counter: Counter) -> usize {
0
}
}

pub enum Scope {
Expand Down

0 comments on commit d9700ae

Please sign in to comment.