aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-08-21 13:18:04 +0000
committerGitHub <[email protected]>2022-08-21 13:18:04 +0000
commit1b9599025868d3a5d0d8e773593b05df8b2fecf2 (patch)
tree97643e046656bdd8297b07dea9a62160a9ecce82 /embassy-executor
parentb7d77985cf230416e53190c4edde4030e42266ed (diff)
parent614b894ff871add9f0394fcf9ef220f133c4aae4 (diff)
Merge #897
897: Add support for `rtos-trace` behind a feature flag r=lulf a=quentinmit This allows SystemView to be used to profile the behavior of the user's application. Co-authored-by: Quentin Smith <[email protected]>
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/Cargo.toml4
-rw-r--r--embassy-executor/src/lib.rs25
-rw-r--r--embassy-executor/src/raw/mod.rs35
3 files changed, 64 insertions, 0 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index 25c3f0abd..7d5c4a045 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -30,9 +30,13 @@ nightly = []
30 30
31integrated-timers = ["dep:embassy-time"] 31integrated-timers = ["dep:embassy-time"]
32 32
33# Trace interrupt invocations with rtos-trace.
34rtos-trace-interrupt = ["rtos-trace"]
35
33[dependencies] 36[dependencies]
34defmt = { version = "0.3", optional = true } 37defmt = { version = "0.3", optional = true }
35log = { version = "0.4.14", optional = true } 38log = { version = "0.4.14", optional = true }
39rtos-trace = { version = "0.1.2", optional = true }
36 40
37futures-util = { version = "0.3.17", default-features = false } 41futures-util = { version = "0.3.17", default-features = false }
38embassy-macros = { version = "0.1.0", path = "../embassy-macros"} 42embassy-macros = { version = "0.1.0", path = "../embassy-macros"}
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index 9328a7378..93f2eaa6d 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -38,6 +38,31 @@ cfg_if::cfg_if! {
38 } 38 }
39} 39}
40 40
41#[doc(hidden)]
42/// Implementation details for embassy macros. DO NOT USE.
43pub mod export {
44 #[cfg(feature = "rtos-trace")]
45 pub use rtos_trace::trace;
46
47 /// Expands the given block of code when `embassy-executor` is compiled with
48 /// the `rtos-trace-interrupt` feature.
49 #[doc(hidden)]
50 #[macro_export]
51 #[cfg(feature = "rtos-trace-interrupt")]
52 macro_rules! rtos_trace_interrupt {
53 ($($tt:tt)*) => { $($tt)* };
54 }
55
56 /// Does not expand the given block of code when `embassy-executor` is
57 /// compiled without the `rtos-trace-interrupt` feature.
58 #[doc(hidden)]
59 #[macro_export]
60 #[cfg(not(feature = "rtos-trace-interrupt"))]
61 macro_rules! rtos_trace_interrupt {
62 ($($tt:tt)*) => {};
63 }
64}
65
41pub mod raw; 66pub mod raw;
42 67
43mod spawner; 68mod spawner;
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index afe67decb..c55d10699 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -26,6 +26,8 @@ use critical_section::CriticalSection;
26use embassy_time::driver::{self, AlarmHandle}; 26use embassy_time::driver::{self, AlarmHandle};
27#[cfg(feature = "integrated-timers")] 27#[cfg(feature = "integrated-timers")]
28use embassy_time::Instant; 28use embassy_time::Instant;
29#[cfg(feature = "rtos-trace")]
30use rtos_trace::trace;
29 31
30use self::run_queue::{RunQueue, RunQueueItem}; 32use self::run_queue::{RunQueue, RunQueueItem};
31use self::util::UninitCell; 33use 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 = "integrated-timers")] 386 #[cfg(feature = "integrated-timers")]
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.
@@ -426,3 +443,21 @@ unsafe fn _embassy_time_schedule_wake(at: Instant, waker: &core::task::Waker) {
426 let expires_at = task.expires_at.get(); 443 let expires_at = task.expires_at.get();
427 task.expires_at.set(expires_at.min(at)); 444 task.expires_at.set(expires_at.min(at));
428} 445}
446
447#[cfg(feature = "rtos-trace")]
448impl rtos_trace::RtosTraceOSCallbacks for Executor {
449 fn task_list() {
450 // We don't know what tasks exist, so we can't send them.
451 }
452 #[cfg(feature = "integrated-timers")]
453 fn time() -> u64 {
454 Instant::now().as_micros()
455 }
456 #[cfg(not(feature = "integrated-timers"))]
457 fn time() -> u64 {
458 0
459 }
460}
461
462#[cfg(feature = "rtos-trace")]
463rtos_trace::global_os_callbacks! {Executor}