aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2022-08-09 16:25:42 -0400
committerQuentin Smith <[email protected]>2022-08-10 05:04:13 -0400
commita3c1522ce64b00c6d310947ebc6dad9fe1e28d55 (patch)
treebe394a8985abb71dc3f16f815102360cf4befbbd
parentb7b4c84067e0e85fa641a540458438297176f2e4 (diff)
Add support for rtos-trace behind a feature flag
-rw-r--r--embassy-executor/Cargo.toml1
-rw-r--r--embassy-executor/src/executor/raw/mod.rs35
-rw-r--r--embassy-executor/src/lib.rs21
-rw-r--r--embassy-macros/src/macros/cortex_m_interrupt_take.rs8
4 files changed, 64 insertions, 1 deletions
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"]
53[dependencies] 53[dependencies]
54defmt = { version = "0.3", optional = true } 54defmt = { version = "0.3", optional = true }
55log = { version = "0.4.14", optional = true } 55log = { version = "0.4.14", optional = true }
56rtos-trace = { version = "0.1.2", optional = true }
56 57
57embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } 58embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
58embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true} 59embedded-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};
22 22
23use atomic_polyfill::{AtomicU32, Ordering}; 23use atomic_polyfill::{AtomicU32, Ordering};
24use critical_section::CriticalSection; 24use critical_section::CriticalSection;
25#[cfg(feature = "rtos-trace")]
26use rtos_trace::trace;
25 27
26use self::run_queue::{RunQueue, RunQueueItem}; 28use self::run_queue::{RunQueue, RunQueueItem};
27use self::util::UninitCell; 29use self::util::UninitCell;
@@ -306,6 +308,9 @@ impl Executor {
306 /// - `task` must NOT be already enqueued (in this executor or another one). 308 /// - `task` must NOT be already enqueued (in this executor or another one).
307 #[inline(always)] 309 #[inline(always)]
308 unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull<TaskHeader>) { 310 unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull<TaskHeader>) {
311 #[cfg(feature = "rtos-trace")]
312 trace::task_ready_begin(task.as_ptr() as u32);
313
309 if self.run_queue.enqueue(cs, task) { 314 if self.run_queue.enqueue(cs, task) {
310 (self.signal_fn)(self.signal_ctx) 315 (self.signal_fn)(self.signal_ctx)
311 } 316 }
@@ -323,6 +328,9 @@ impl Executor {
323 pub(super) unsafe fn spawn(&'static self, task: NonNull<TaskHeader>) { 328 pub(super) unsafe fn spawn(&'static self, task: NonNull<TaskHeader>) {
324 task.as_ref().executor.set(self); 329 task.as_ref().executor.set(self);
325 330
331 #[cfg(feature = "rtos-trace")]
332 trace::task_new(task.as_ptr() as u32);
333
326 critical_section::with(|cs| { 334 critical_section::with(|cs| {
327 self.enqueue(cs, task); 335 self.enqueue(cs, task);
328 }) 336 })
@@ -365,9 +373,15 @@ impl Executor {
365 return; 373 return;
366 } 374 }
367 375
376 #[cfg(feature = "rtos-trace")]
377 trace::task_exec_begin(p.as_ptr() as u32);
378
368 // Run the task 379 // Run the task
369 task.poll_fn.read()(p as _); 380 task.poll_fn.read()(p as _);
370 381
382 #[cfg(feature = "rtos-trace")]
383 trace::task_exec_end();
384
371 // Enqueue or update into timer_queue 385 // Enqueue or update into timer_queue
372 #[cfg(feature = "time")] 386 #[cfg(feature = "time")]
373 self.timer_queue.update(p); 387 self.timer_queue.update(p);
@@ -381,6 +395,9 @@ impl Executor {
381 let next_expiration = self.timer_queue.next_expiration(); 395 let next_expiration = self.timer_queue.next_expiration();
382 driver::set_alarm(self.alarm, next_expiration.as_ticks()); 396 driver::set_alarm(self.alarm, next_expiration.as_ticks());
383 } 397 }
398
399 #[cfg(feature = "rtos-trace")]
400 trace::system_idle();
384 } 401 }
385 402
386 /// Get a spawner that spawns tasks in this executor. 403 /// 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) {
425 let expires_at = task.expires_at.get(); 442 let expires_at = task.expires_at.get();
426 task.expires_at.set(expires_at.min(at)); 443 task.expires_at.set(expires_at.min(at));
427} 444}
445
446#[cfg(feature = "rtos-trace")]
447impl rtos_trace::RtosTraceOSCallbacks for Executor {
448 fn task_list() {
449 // We don't know what tasks exist, so we can't send them.
450 }
451 #[cfg(feature = "time")]
452 fn time() -> u64 {
453 Instant::now().as_micros()
454 }
455 #[cfg(not(feature = "time"))]
456 fn time() -> u64 {
457 0
458 }
459}
460
461#[cfg(feature = "rtos-trace")]
462rtos_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};
19/// Implementation details for embassy macros. DO NOT USE. 19/// Implementation details for embassy macros. DO NOT USE.
20pub mod export { 20pub mod export {
21 pub use atomic_polyfill as atomic; 21 pub use atomic_polyfill as atomic;
22
23 #[cfg(feature = "rtos-trace")]
24 pub use rtos_trace::trace;
25
26 /// Expands the given block of code when `embassy-executor` is compiled with
27 /// the `rtos-trace` feature.
28 #[doc(hidden)]
29 #[macro_export]
30 #[cfg(feature = "rtos-trace")]
31 macro_rules! rtos_trace {
32 ($($tt:tt)*) => { $($tt)* };
33 }
34
35 /// Does not expand the given block of code when `embassy-executor` is
36 /// compiled without the `rtos-trace` feature.
37 #[doc(hidden)]
38 #[macro_export]
39 #[cfg(not(feature = "rtos-trace"))]
40 macro_rules! rtos_trace {
41 ($($tt:tt)*) => {};
42 }
22} 43}
diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs
index 133eb5c26..5431704da 100644
--- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs
+++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs
@@ -19,7 +19,13 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> {
19 let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); 19 let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed);
20 let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); 20 let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed);
21 let func: fn(*mut ()) = ::core::mem::transmute(func); 21 let func: fn(*mut ()) = ::core::mem::transmute(func);
22 func(ctx) 22 ::embassy_executor::rtos_trace! {
23 ::embassy_executor::export::trace::isr_enter();
24 }
25 func(ctx);
26 ::embassy_executor::rtos_trace! {
27 ::embassy_executor::export::trace::isr_exit();
28 }
23 } 29 }
24 30
25 static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false); 31 static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false);