Skip to content

Commit

Permalink
feat(bench): support for esp
Browse files Browse the repository at this point in the history
  • Loading branch information
elenaf9 committed Sep 13, 2024
1 parent 1b6db3d commit 8a26742
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ modules:
- nrf
- rp
- stm32
- esp

- name: wifi-esp
context:
Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ defmt = { workspace = true, optional = true }

[target.'cfg(context = "cortex-m")'.dependencies]
cortex-m = { workspace = true, features = ["critical-section-single-core"] }

[target.'cfg(context = "esp")'.dependencies]
esp-hal = { workspace = true }
28 changes: 28 additions & 0 deletions src/riot-rs-bench/src/esp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use esp_hal::{
peripherals,
timer::systimer::{SystemTimer, Unit as _},
};

use crate::Error;

#[allow(missing_docs)]
pub fn benchmark<F: Fn() -> ()>(iterations: usize, f: F) -> Result<usize, Error> {
let mut systimer_periph = unsafe { peripherals::SYSTIMER::steal() };
let timer = SystemTimer::new(&mut systimer_periph);

// Reset counter of unit0, which is read in `SystemTimer::now()`.
timer.unit0.set_count(0);

while SystemTimer::now() == 0 {}

let before = SystemTimer::now();

for _ in 0..iterations {
f();
}

SystemTimer::now()
.checked_sub(before)
.map(|total| total as usize / iterations)
.ok_or(Error::SystemTimerWrapped)
}
6 changes: 4 additions & 2 deletions src/riot-rs-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ cfg_if::cfg_if! {
if #[cfg(context = "cortex-m")] {
mod cortexm;
use cortexm as bench;
}
else if #[cfg(context = "riot-rs")] {
} else if #[cfg(context = "esp")] {
mod esp;
use esp as bench;
} else if #[cfg(context = "riot-rs")] {
// When run with laze but the architecture is not supported
compile_error!("benchmarking is not supported for this architecture");
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/benchmarks/bench_sched_yield/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apps:
- name: bench_sched_yield
selects:
- sw/benchmark
- executor-thread
- ?release

0 comments on commit 8a26742

Please sign in to comment.