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/src/executor/raw/mod.rs | 35 ++++++++++++++++++++++++++++++++ embassy-executor/src/lib.rs | 21 +++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'embassy-executor/src') 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