-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cortexm_common: disable IRQ during thread_sched_idle #14534
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy, and @bergzand mentioned in offline as well about all the nested irq_disable/enable
we are having, but this is the best fix ATM. So ACK!
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_tools
should work on the iotlab_m3 (see tests/test_tools: fails oniotlab-m3
due tocore
/cpu
regression #14521)tests/xtimer_periodic_wakeup
should work on the nucleo-l152 (see core: make idle thread optional #14224 (comment))Issues/PRs references
Fixes #14521
See #14224 (comment)