-
Notifications
You must be signed in to change notification settings - Fork 7.3k
arch: arm: restrict IRQ lock to minimum during pendSV exception #15735
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
arch: arm: restrict IRQ lock to minimum during pendSV exception #15735
Conversation
When performing thread context-switch it is not necessary to have IRQs locked while saving the current thread's callee-saved (and possibly floating point) registers. We only need to lock the interrupts when accessing the thread ready queue cache. Signed-off-by: Ioannis Glaropoulos <[email protected]>
This patch is an optimization; reduces the time we lock the IRQs during context switch. The patch is based on the assumption that |
can you illustrate what happens if, during this window where we have partially saved the register state, we get an interrupt which causes the system to decide to schedule some other thread? |
So... yes, the _current pointer only gets assigned in the arch-defined z_swap() implementation (or for USE_SWITCH architectures, the kernel-provided portable one). You're safe as far as that goes. But remember that PendSV is not atomic with respect to the original call to z_swap(). The thread to which you are swapping is not necessarily the one the kernel thread "thought" it was switching to when it called z_swap() in the first place. If , as I understand the commit message, all the unlocked code here is doing is writing to stack memory (and the stack pointer is always consistent!) then this should be OK. But if you're inspecting or writing to other memory it's likely to have holes. |
@andyross thanks very much for your feedback. @andrewboie sure, I can briefly comment on this:
A preempting ISR will, therefore, allow the context saving to safely resume when returning to the pendSV. Also, for ARM an interrupt cannot be, normally, nested in its own. Therefore, the pendSV cannot be interrupted by another pendSV playing with context saving! All this patch is doing is to un-protect the context saving of the current thread; as I argued above, this seems not needed, as the _current pointer is not changed by any other Kernel/ARCH code. It is only touched later in the swap routine. If a preempting interrupt decides to schedule some other thread, it will modify the ready queue cache, but that is fine, until the very last moment we will need to read this! And that part of the swap-routine is still protected inside interrupts lock-unlock. |
@pizi-nordic pls, have a quick look, as well |
When performing thread context-switch it is not necessary to
have IRQs locked while saving the current thread's callee-saved
(and possibly floating point) registers. We only need to lock
the interrupts when accessing the thread ready queue cache.
Signed-off-by: Ioannis Glaropoulos [email protected]