cortexm_common: disable IRQ during thread_sched_idle#14534
cortexm_common: disable IRQ during thread_sched_idle#14534miri64 merged 1 commit intoRIOT-OS:masterfrom
Conversation
A race condition is present where an IRQ is serviced between the priority increase of the PENDSV and the sleep. When the IRQ is serviced before the WFI sleep, the core will sleep until the next IRQ and the thread activated by the IRQ will not be scheduled until a new IRQ triggers. This commit wraps an IRQ disable and restore around the priority modification and sleep to prevent interrupts from being serviced until the WFI call returns.
|
Confirmed, that this fixes #14534. |
|
This fixes the issue mentioned in #14224 (comment) as well. |
|
Failing tests are the usual suspects. I think the |
|
@bergzand please provide a backport. |
|
Isn't the root cause of that problem that RIOT will configure all interrupts with the same priority? So instead of disabling interrupts, why not just give a higher priority to the PendSV interrupt to begin with? |
That's exactly what is described here. RIOT/cpu/cortexm_common/include/cpu_conf_common.h Lines 113 to 146 in a20d663 It can probably be done in the future, but I don't think the current scheduler routines are exactly thread safe (as already shown in this PR). |
|
See also https://developer.arm.com/documentation/ka001284/1-0/?search=5eec6e71e24a5e02d07b259a for some background reading on this:
|
Contribution description
A race condition is present where an IRQ is serviced between the
priority increase of the PENDSV and the sleep. When the IRQ
is serviced before the WFI sleep, the core will sleep until the next
IRQ and the thread activated by the IRQ will not be scheduled until
a new IRQ triggers.
This commit wraps an IRQ disable and restore around the priority
modification and sleep to prevent interrupts from being serviced until
the WFI call returns.
Testing procedure
tests/test_toolsshould work on the iotlab_m3 (see tests/test_tools: fails oniotlab-m3due tocore/cpuregression #14521)tests/xtimer_periodic_wakeupshould work on the nucleo-l152 (see core: make idle thread optional #14224 (comment))Issues/PRs references
Fixes #14521
See #14224 (comment)