From a3c1522ce64b00c6d310947ebc6dad9fe1e28d55 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 9 Aug 2022 16:25:42 -0400 Subject: Add support for rtos-trace behind a feature flag --- embassy-executor/Cargo.toml | 1 + embassy-executor/src/executor/raw/mod.rs | 35 ++++++++++++++++++++++++++++++++ embassy-executor/src/lib.rs | 21 +++++++++++++++++++ 3 files changed, 57 insertions(+) (limited to 'embassy-executor') diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d8ac4ac00..d10752b3e 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -53,6 +53,7 @@ time-tick-16mhz = ["time"] [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } +rtos-trace = { version = "0.1.2", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true} diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/executor/raw/mod.rs index fb4cc6288..c943ecd84 100644 --- a/embassy-executor/src/executor/raw/mod.rs +++ b/embassy-executor/src/executor/raw/mod.rs @@ -22,6 +22,8 @@ use core::{mem, ptr}; use atomic_polyfill::{AtomicU32, Ordering}; use critical_section::CriticalSection; +#[cfg(feature = "rtos-trace")] +use rtos_trace::trace; use self::run_queue::{RunQueue, RunQueueItem}; use self::util::UninitCell; @@ -306,6 +308,9 @@ impl Executor { /// - `task` must NOT be already enqueued (in this executor or another one). #[inline(always)] unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull) { + #[cfg(feature = "rtos-trace")] + trace::task_ready_begin(task.as_ptr() as u32); + if self.run_queue.enqueue(cs, task) { (self.signal_fn)(self.signal_ctx) } @@ -323,6 +328,9 @@ impl Executor { pub(super) unsafe fn spawn(&'static self, task: NonNull) { task.as_ref().executor.set(self); + #[cfg(feature = "rtos-trace")] + trace::task_new(task.as_ptr() as u32); + critical_section::with(|cs| { self.enqueue(cs, task); }) @@ -365,9 +373,15 @@ impl Executor { return; } + #[cfg(feature = "rtos-trace")] + trace::task_exec_begin(p.as_ptr() as u32); + // Run the task task.poll_fn.read()(p as _); + #[cfg(feature = "rtos-trace")] + trace::task_exec_end(); + // Enqueue or update into timer_queue #[cfg(feature = "time")] self.timer_queue.update(p); @@ -381,6 +395,9 @@ impl Executor { let next_expiration = self.timer_queue.next_expiration(); driver::set_alarm(self.alarm, next_expiration.as_ticks()); } + + #[cfg(feature = "rtos-trace")] + trace::system_idle(); } /// Get a spawner that spawns tasks in this executor. @@ -425,3 +442,21 @@ pub(crate) unsafe fn register_timer(at: Instant, waker: &core::task::Waker) { let expires_at = task.expires_at.get(); task.expires_at.set(expires_at.min(at)); } + +#[cfg(feature = "rtos-trace")] +impl rtos_trace::RtosTraceOSCallbacks for Executor { + fn task_list() { + // We don't know what tasks exist, so we can't send them. + } + #[cfg(feature = "time")] + fn time() -> u64 { + Instant::now().as_micros() + } + #[cfg(not(feature = "time"))] + fn time() -> u64 { + 0 + } +} + +#[cfg(feature = "rtos-trace")] +rtos_trace::global_os_callbacks!{Executor} diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 69e4aeb4b..dd99f9e52 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -19,4 +19,25 @@ pub use embassy_macros::{main, task}; /// Implementation details for embassy macros. DO NOT USE. pub mod export { pub use atomic_polyfill as atomic; + + #[cfg(feature = "rtos-trace")] + pub use rtos_trace::trace; + + /// Expands the given block of code when `embassy-executor` is compiled with + /// the `rtos-trace` feature. + #[doc(hidden)] + #[macro_export] + #[cfg(feature = "rtos-trace")] + macro_rules! rtos_trace { + ($($tt:tt)*) => { $($tt)* }; + } + + /// Does not expand the given block of code when `embassy-executor` is + /// compiled without the `rtos-trace` feature. + #[doc(hidden)] + #[macro_export] + #[cfg(not(feature = "rtos-trace"))] + macro_rules! rtos_trace { + ($($tt:tt)*) => {}; + } } -- cgit From 145af0e4ab75d931cba401f1755f383bcc713892 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 10 Aug 2022 17:09:11 -0400 Subject: cargo fmt --- embassy-executor/src/executor/raw/mod.rs | 2 +- embassy-executor/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/executor/raw/mod.rs index c943ecd84..56220d10e 100644 --- a/embassy-executor/src/executor/raw/mod.rs +++ b/embassy-executor/src/executor/raw/mod.rs @@ -459,4 +459,4 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor { } #[cfg(feature = "rtos-trace")] -rtos_trace::global_os_callbacks!{Executor} +rtos_trace::global_os_callbacks! {Executor} diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index dd99f9e52..32724c15c 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -19,7 +19,6 @@ pub use embassy_macros::{main, task}; /// Implementation details for embassy macros. DO NOT USE. pub mod export { pub use atomic_polyfill as atomic; - #[cfg(feature = "rtos-trace")] pub use rtos_trace::trace; -- cgit From 0bf178dd1b11d97f20cb93c5fdb0c779259be0f8 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 16 Aug 2022 00:42:08 -0400 Subject: Add separate feature flag to enable interrupt tracing --- embassy-executor/Cargo.toml | 3 +++ embassy-executor/src/lib.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d10752b3e..ca00f2e71 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -50,6 +50,9 @@ time-tick-1000hz = ["time"] time-tick-1mhz = ["time"] time-tick-16mhz = ["time"] +# Trace interrupt invocations with rtos-trace. +rtos-trace-interrupt = ["rtos-trace"] + [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 32724c15c..47c0c1d64 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -23,20 +23,20 @@ pub mod export { pub use rtos_trace::trace; /// Expands the given block of code when `embassy-executor` is compiled with - /// the `rtos-trace` feature. + /// the `rtos-trace-interrupt` feature. #[doc(hidden)] #[macro_export] - #[cfg(feature = "rtos-trace")] - macro_rules! rtos_trace { + #[cfg(feature = "rtos-trace-interrupt")] + macro_rules! rtos_trace_interrupt { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `embassy-executor` is - /// compiled without the `rtos-trace` feature. + /// compiled without the `rtos-trace-interrupt` feature. #[doc(hidden)] #[macro_export] - #[cfg(not(feature = "rtos-trace"))] - macro_rules! rtos_trace { + #[cfg(not(feature = "rtos-trace-interrupt"))] + macro_rules! rtos_trace_interrupt { ($($tt:tt)*) => {}; } } -- cgit From 478f4727846f6a43c28fff3b09cb639c0b800465 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 22 Aug 2022 15:51:44 +0200 Subject: Remove Forever, switch to static_cell. --- embassy-executor/Cargo.toml | 1 + embassy-executor/src/arch/cortex_m.rs | 2 +- embassy-executor/src/arch/riscv32.rs | 2 +- embassy-executor/src/arch/std.rs | 2 +- embassy-executor/src/arch/wasm.rs | 2 +- embassy-executor/src/arch/xtensa.rs | 2 +- embassy-executor/src/lib.rs | 6 ++++++ 7 files changed, 12 insertions(+), 5 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 7d5c4a045..184e770cd 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -44,6 +44,7 @@ embassy-time = { version = "0.1.0", path = "../embassy-time", optional = true} atomic-polyfill = "1.0.1" critical-section = "1.1" cfg-if = "1.0.0" +static_cell = "1.0" # WASM dependencies wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs index d6e758dfb..4b27a264e 100644 --- a/embassy-executor/src/arch/cortex_m.rs +++ b/embassy-executor/src/arch/cortex_m.rs @@ -41,7 +41,7 @@ impl Executor { /// Executor instance in a place where it'll live forever and grants you mutable /// access. There's a few ways to do this: /// - /// - a [Forever](crate::util::Forever) (safe) + /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) /// - a `static mut` (unsafe) /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) /// diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs index 7a7d5698c..2a4b006da 100644 --- a/embassy-executor/src/arch/riscv32.rs +++ b/embassy-executor/src/arch/riscv32.rs @@ -43,7 +43,7 @@ impl Executor { /// Executor instance in a place where it'll live forever and grants you mutable /// access. There's a few ways to do this: /// - /// - a [Forever](crate::util::Forever) (safe) + /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) /// - a `static mut` (unsafe) /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) /// diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs index b93ab8a79..701f0eb18 100644 --- a/embassy-executor/src/arch/std.rs +++ b/embassy-executor/src/arch/std.rs @@ -40,7 +40,7 @@ impl Executor { /// Executor instance in a place where it'll live forever and grants you mutable /// access. There's a few ways to do this: /// - /// - a [Forever](crate::util::Forever) (safe) + /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) /// - a `static mut` (unsafe) /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) /// diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs index 9d5aa31ed..98091cfbb 100644 --- a/embassy-executor/src/arch/wasm.rs +++ b/embassy-executor/src/arch/wasm.rs @@ -59,7 +59,7 @@ impl Executor { /// Executor instance in a place where it'll live forever and grants you mutable /// access. There's a few ways to do this: /// - /// - a [Forever](crate::util::Forever) (safe) + /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) /// - a `static mut` (unsafe) /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) pub fn start(&'static mut self, init: impl FnOnce(Spawner)) { diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs index 20bd7b8a5..f908aaa70 100644 --- a/embassy-executor/src/arch/xtensa.rs +++ b/embassy-executor/src/arch/xtensa.rs @@ -43,7 +43,7 @@ impl Executor { /// Executor instance in a place where it'll live forever and grants you mutable /// access. There's a few ways to do this: /// - /// - a [Forever](crate::util::Forever) (safe) + /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) /// - a `static mut` (unsafe) /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) /// diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 93f2eaa6d..e4cbd04b9 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -67,3 +67,9 @@ pub mod raw; mod spawner; pub use spawner::*; + +/// Do not use. Used for macros and HALs only. Not covered by semver guarantees. +#[doc(hidden)] +pub mod _export { + pub use static_cell::StaticCell; +} -- cgit From f2daad20ab9acb7e0b8fa3c8079ca8a573817fb0 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 22 Aug 2022 09:11:00 +0200 Subject: Remove warnings --- embassy-executor/src/raw/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index c55d10699..e1258ebb5 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -5,7 +5,7 @@ //! ## WARNING: here be dragons! //! //! Using this module requires respecting subtle safety contracts. If you can, prefer using the safe -//! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. +//! [executor wrappers](crate::Executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. mod run_queue; #[cfg(feature = "integrated-timers")] @@ -249,7 +249,7 @@ impl TaskPool { /// /// This is the core of the Embassy executor. It is low-level, requiring manual /// handling of wakeups and task polling. If you can, prefer using one of the -/// higher level executors in [`crate::executor`]. +/// [higher level executors](crate::Executor). /// /// The raw executor leaves it up to you to handle wakeups and scheduling: /// -- cgit From bd4ae2e9526cb66c15b7335cfbc803106637c7e1 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 23 Aug 2022 19:55:49 +0200 Subject: Enable 'std' feature on critical-section for WASM This fixes the WASM support which was failing due to missing critical-section implementation. This also upgrades the bindgen dependency and ensures that tooling works. --- embassy-executor/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'embassy-executor') diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 184e770cd..1a611720c 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -47,5 +47,5 @@ cfg-if = "1.0.0" static_cell = "1.0" # WASM dependencies -wasm-bindgen = { version = "0.2.76", features = ["nightly"], optional = true } -js-sys = { version = "0.3", optional = true } \ No newline at end of file +wasm-bindgen = { version = "0.2.82", optional = true } +js-sys = { version = "0.3", optional = true } -- cgit