aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2022-08-23 23:01:51 -0400
committerQuentin Smith <[email protected]>2022-08-23 23:01:51 -0400
commit2900ab79e7afa0ca3e0d800f8a91c3253a333db1 (patch)
treea5066235f8b1ac6c2520105db2e5c48630bc006d /embassy-executor/src/raw
parent14eae9ca06f63a69ccc29d5fd9e1dec3848a3e98 (diff)
parent529535194d4b5d58b31fd6a7541176105e3c63f7 (diff)
Merge remote-tracking branch 'origin/master' into nrf-pdm
Diffstat (limited to 'embassy-executor/src/raw')
-rw-r--r--embassy-executor/src/raw/mod.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index afe67decb..e1258ebb5 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -5,7 +5,7 @@
5//! ## WARNING: here be dragons! 5//! ## WARNING: here be dragons!
6//! 6//!
7//! Using this module requires respecting subtle safety contracts. If you can, prefer using the safe 7//! Using this module requires respecting subtle safety contracts. If you can, prefer using the safe
8//! executor wrappers in [`executor`](crate::executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe. 8//! [executor wrappers](crate::Executor) and the [`embassy_executor::task`](embassy_macros::task) macro, which are fully safe.
9 9
10mod run_queue; 10mod run_queue;
11#[cfg(feature = "integrated-timers")] 11#[cfg(feature = "integrated-timers")]
@@ -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;
@@ -247,7 +249,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> {
247/// 249///
248/// This is the core of the Embassy executor. It is low-level, requiring manual 250/// This is the core of the Embassy executor. It is low-level, requiring manual
249/// handling of wakeups and task polling. If you can, prefer using one of the 251/// handling of wakeups and task polling. If you can, prefer using one of the
250/// higher level executors in [`crate::executor`]. 252/// [higher level executors](crate::Executor).
251/// 253///
252/// The raw executor leaves it up to you to handle wakeups and scheduling: 254/// The raw executor leaves it up to you to handle wakeups and scheduling:
253/// 255///
@@ -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}