Skip to content

executor: emit rtos-trace system_idle only at real sleep sites#6502

Open
basil-huber wants to merge 1 commit into
embassy-rs:mainfrom
basil-huber:fix/system-idle-only-on-real-idle
Open

executor: emit rtos-trace system_idle only at real sleep sites#6502
basil-huber wants to merge 1 commit into
embassy-rs:mainfrom
basil-huber:fix/system-idle-only-on-real-idle

Conversation

@basil-huber

Copy link
Copy Markdown

Previously, executors would call rtos-trace's system_idle callback after polling.
For InterruptExecutors this is incorrect: the executor finishes polling and returns to the preempted (lower-priority) context, so execution continues and the system is not idle. Only the thread-mode executor reaching its wait site means the system is truly idle.

This misleads notably SystemView
(https://www.segger.com/products/development-tools/systemview/), connected via the systemview-target crate
(https://crates.io/crates/systemview-target), which misinterprets the events and produces a corrupted timeline.

Stop emitting system_idle in executor_idle, and add a public Executor::trace_system_idle() that each thread-mode run loop calls at its genuine wait site instead. It is a no-op unless a trace feature is enabled, and must not be called from an interrupt executor.

The behaviour of the following executors stays the same:

  • embassy-executor/src/platform/cortex_m.rs: Executor
  • embassy-executor/src/platform/cortex_ar.rs: Executor
  • embassy-rp/src/executor.rs: Executor

The following executors do NOT call system_idle anymore:

  • embassy-executor/src/platform/cortex_m.rs: InterruptExecutor
  • embassy-rp/src/executor.rs: InterruptExecutor
  • embassy-stm32/src/executor.rs: InterruptExecutor
  • embassy-executor/src/platform/spin.rs: Executor
  • embassy-executor/src/platform/wasm.rs: Executor

The following executors call system_idle only before actually idling:

  • embassy-executor/src/platform/riscv32.rs: Executor
  • embassy-executor/src/platform/std.rs: Executor
  • embassy-executor/src/platform/avr.rs: Executor
  • embassy-stm32/src/executor.rs: Executor
  • embassy-mcxa/src/executor.rs: Executor

Note: these differences only affect the rtos-trace feature.

Previously, executors would call rtos-trace's system_idle callback
after polling.
For InterruptExecutors this is incorrect: the executor finishes
polling and returns to the preempted (lower-priority) context,
so execution continues and the system is not idle. Only the thread-mode
executor reaching its wait site means the system is truly idle.

This misleads notably SystemView
(https://www.segger.com/products/development-tools/systemview/),
connected via the systemview-target crate
(https://crates.io/crates/systemview-target), which misinterprets the
events and produces a corrupted timeline.

Stop emitting `system_idle` in `executor_idle`, and add a public
`Executor::trace_system_idle()` that each thread-mode run loop calls at
its genuine wait site instead. It is a no-op unless a trace feature is
enabled, and must not be called from an interrupt executor.

The behaviour of the following executors stays the same:
- embassy-executor/src/platform/cortex_m.rs: Executor
- embassy-executor/src/platform/cortex_ar.rs: Executor
- embassy-rp/src/executor.rs: Executor

The following executors do NOT call `system_idle` anymore:
- embassy-executor/src/platform/cortex_m.rs: InterruptExecutor
- embassy-rp/src/executor.rs: InterruptExecutor
- embassy-stm32/src/executor.rs: InterruptExecutor
- embassy-executor/src/platform/spin.rs: Executor
- embassy-executor/src/platform/wasm.rs: Executor

The following executors call `system_idle` only before actually idling:
- embassy-executor/src/platform/riscv32.rs: Executor
- embassy-executor/src/platform/std.rs: Executor
- embassy-executor/src/platform/avr.rs: Executor
- embassy-stm32/src/executor.rs: Executor
- embassy-mcxa/src/executor.rs: Executor

Note: these differences only affect the `rtos-trace` feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant