diff options
Diffstat (limited to 'embassy-executor/src/executor/raw/mod.rs')
| -rw-r--r-- | embassy-executor/src/executor/raw/mod.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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 | ||
| 23 | use atomic_polyfill::{AtomicU32, Ordering}; | 23 | use atomic_polyfill::{AtomicU32, Ordering}; |
| 24 | use critical_section::CriticalSection; | 24 | use critical_section::CriticalSection; |
| 25 | #[cfg(feature = "rtos-trace")] | ||
| 26 | use rtos_trace::trace; | ||
| 25 | 27 | ||
| 26 | use self::run_queue::{RunQueue, RunQueueItem}; | 28 | use self::run_queue::{RunQueue, RunQueueItem}; |
| 27 | use self::util::UninitCell; | 29 | use 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")] | ||
| 447 | impl 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")] | ||
| 462 | rtos_trace::global_os_callbacks!{Executor} | ||
