Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions embassy-executor/src/platform/avr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ mod thread {
avr_device::interrupt::disable();
if !SIGNAL_WORK_THREAD_MODE.swap(false, Ordering::SeqCst) {
avr_device::interrupt::enable();
self.inner.trace_system_idle();
avr_device::asm::sleep();
} else {
avr_device::interrupt::enable();
Expand Down
1 change: 1 addition & 0 deletions embassy-executor/src/platform/cortex_ar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod thread {
unsafe {
self.inner.poll();
}
self.inner.trace_system_idle();
wfe();
}
}
Expand Down
1 change: 1 addition & 0 deletions embassy-executor/src/platform/cortex_m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ mod thread {
loop {
unsafe {
self.inner.poll();
self.inner.trace_system_idle();
asm!("wfe");
};
}
Expand Down
1 change: 1 addition & 0 deletions embassy-executor/src/platform/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mod thread {
}
// if not, wait for interrupt
else {
self.inner.trace_system_idle();
core::arch::asm!("wfi");
}
});
Expand Down
1 change: 1 addition & 0 deletions embassy-executor/src/platform/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod thread {
break;
}

self.inner.trace_system_idle();
self.signaler.wait();
}
}
Expand Down
12 changes: 12 additions & 0 deletions embassy-executor/src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,18 @@ impl Executor {
self.inner.poll()
}

/// Signal to the tracing system that the whole system is about to go idle.
///
/// While `executor_idle` is emitted automatically at the end of each `poll`,
/// `trace_system_idle` must be called by each executor before putting the
/// entire system into idle. Do NOT call it from an interrupt executor, which
/// returns to a preempted context after polling and is therefore not idle.
#[inline]
pub fn trace_system_idle(&'static self) {
#[cfg(feature = "_any_trace")]
trace::system_idle();
}

/// Get a spawner that spawns tasks in this executor.
///
/// It is OK to call this method multiple times to obtain multiple
Expand Down
9 changes: 9 additions & 0 deletions embassy-executor/src/raw/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ pub(crate) fn executor_idle(executor: &SyncExecutor) {
unsafe {
_embassy_trace_executor_idle(executor as *const _ as u32)
}
// NOTE: `rtos_trace::trace::system_idle()` is intentionally NOT emitted here.
// In case of multiple executors, executor_idle does NOT necessarily mean
// that the entire system is going to idle, another executor could take over.
// Executors are responsible for calling `trace_system_idle()`
// before putting the entire system into idle.
}

#[inline]
pub(crate) fn system_idle() {
#[cfg(feature = "rtos-trace")]
rtos_trace::trace::system_idle();
}
Expand Down
3 changes: 3 additions & 0 deletions embassy-mcxa/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl Executor {
if let Some(s) = sleep {
break s;
}
self.inner.trace_system_idle();
debug_lo();
do_wfe();
debug_hi();
Expand All @@ -123,6 +124,7 @@ impl Executor {
continue;
}

self.inner.trace_system_idle();
debug_lo();
do_wfe();
debug_hi();
Expand All @@ -144,6 +146,7 @@ impl Executor {
//
// We STAY in the CS for the deep sleep to ensure that we handle wake-up
// completely BEFORE yielding control flow back to interrupts.
self.inner.trace_system_idle();
debug_lo();
let do_wfe_sleep = critical_section::with(|cs| {
let did_deep_sleep = crate::clocks::deep_sleep_if_possible(&cs);
Expand Down
1 change: 1 addition & 0 deletions embassy-rp/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mod thread {
loop {
unsafe {
self.inner.poll();
self.inner.trace_system_idle();
asm!("wfe");
};
}
Expand Down
1 change: 1 addition & 0 deletions embassy-stm32/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod thread {
SIGNAL_WORK_THREAD_MODE.store(false, core::sync::atomic::Ordering::SeqCst);
} else {
// if not, sleep waiting for interrupt
self.inner.trace_system_idle();
crate::low_power::sleep(cs);
}
});
Expand Down