diff --git a/tests/bench/.cargo/config.toml b/tests/bench/.cargo/config.toml new file mode 100644 index 000000000..38e6c8559 --- /dev/null +++ b/tests/bench/.cargo/config.toml @@ -0,0 +1,21 @@ +[unstable] +build-std = ["core"] +build-std-features = ["panic_immediate_abort"] + +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +#runner = "../../sshprobe.sh" +runner = "teleprobe local run --chip nRF52840_xxAA --elf" +#runner = "teleprobe client run -s" +#runner = "probe-rs run --chip nRF52840_xxAA" + +rustflags = [ + # Code-size optimizations. + "-Z", "trap-unreachable=no", + "-C", "no-vectorize-loops", +] + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,smoltcp=info" diff --git a/tests/bench/Cargo.toml b/tests/bench/Cargo.toml new file mode 100644 index 000000000..4ae26db9c --- /dev/null +++ b/tests/bench/Cargo.toml @@ -0,0 +1,22 @@ +[package] +edition = "2021" +name = "embassy-bench" +version = "0.1.0" +license = "MIT OR Apache-2.0" + +[dependencies] +teleprobe-meta = "1" +embassy-executor = { version = "0.6.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly"] } +static_cell = { version = "2", features = ["nightly"] } +defmt = "0.3" +defmt-rtt = "0.4" +cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } +cortex-m-rt = "0.7.0" +panic-probe = { version = "0.3", features = ["print-defmt"] } + +[profile.release] +codegen-units = 1 +debug = 2 +incremental = false +lto = "fat" +opt-level = 's' diff --git a/tests/bench/build.rs b/tests/bench/build.rs new file mode 100644 index 000000000..b895e336b --- /dev/null +++ b/tests/bench/build.rs @@ -0,0 +1,10 @@ +use std::error::Error; + +fn main() -> Result<(), Box> { + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + println!("cargo:rustc-link-arg-bins=-Tteleprobe.x"); + + Ok(()) +} diff --git a/tests/bench/memory.x b/tests/bench/memory.x new file mode 100644 index 000000000..b06b64eb6 --- /dev/null +++ b/tests/bench/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x00810000, LENGTH = 192K + RAM : ORIGIN = 0x20000000, LENGTH = 64K +} diff --git a/tests/bench/src/bin/selfwake.rs b/tests/bench/src/bin/selfwake.rs new file mode 100644 index 000000000..84a20661f --- /dev/null +++ b/tests/bench/src/bin/selfwake.rs @@ -0,0 +1,56 @@ +#![no_std] +#![no_main] +teleprobe_meta::target!(b"nrf52840-dk"); + +use core::future::Future; +use core::pin::Pin; +use core::task::{Context, Poll}; + +use cortex_m_rt::{entry, exception}; +use defmt::{info, unwrap}; +use embassy_executor::raw::TaskStorage; +use embassy_executor::Executor; +use static_cell::StaticCell; +use {defmt_rtt as _, panic_probe as _}; + +static mut COUNTER: u32 = 0; + +#[exception] +fn SysTick() -> ! { + let c = unsafe { COUNTER }; + info!("Test OK, count={=u32}, cycles={=u32}", c, 0x00ffffff * 100 / c); + cortex_m::asm::bkpt(); + loop {} +} + +struct Task1 {} +impl Future for Task1 { + type Output = (); + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + unsafe { COUNTER += 1 }; + cx.waker().wake_by_ref(); + Poll::Pending + } +} + +static EXECUTOR: StaticCell = StaticCell::new(); +static TASK1: TaskStorage = TaskStorage::new(); + +#[entry] +fn main() -> ! { + info!("Hello World!"); + + //let _p = embassy_nrf::init(Default::default()); + let executor = EXECUTOR.init(Executor::new()); + executor.run(|spawner| { + unwrap!(spawner.spawn(TASK1.spawn(|| Task1 {}))); + + let mut systick: cortex_m::peripheral::SYST = unsafe { core::mem::transmute(()) }; + systick.disable_counter(); + systick.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core); + systick.set_reload(0x00ffffff); + systick.enable_interrupt(); + systick.enable_counter(); + }); +}