kernel/sched: Address thread abort termination delay issue on SMP
It's possible for a thread to abort itself simultaneously with an external abort from another thread. In fact in our test suite this is a common thing, as ztest will abort its own spawend threads at the end of a test, as they tend to be exiting on their own. When that happens, the thread marks itself DEAD and does all its scheduler bookeeping, but it is STILL RUNNING on its own stack until it makes its way to its final swap. The external context would see that "dead" metadata and return from k_thread_abort(), allowing the next test to reuse and spawn the same thread struct while the old context was still running. Obviously that's bad. Unfortunately, this is impossible to address completely without modifying every SMP architecture to add a API-visible hook to every swap that signals completion. In practice the best we can do is add a delay. But note the optimization: almost always, the scheduler IPI catches the running thread and kills it from interrupt context (i.e. on a different stack). When that happens, we know that the interrupted thread will never be resumed (because it's dead) and can elide the delay. We only pay the cost when we actually detect a race. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
60247ca149
commit
e06ba702d5
2 changed files with 37 additions and 2 deletions
|
@ -59,8 +59,11 @@
|
|||
/* Thread is being aborted (SMP only) */
|
||||
#define _THREAD_ABORTING (BIT(5))
|
||||
|
||||
/* Thread was aborted in interrupt context (SMP only) */
|
||||
#define _THREAD_ABORTED_IN_ISR (BIT(6))
|
||||
|
||||
/* Thread is present in the ready queue */
|
||||
#define _THREAD_QUEUED (BIT(6))
|
||||
#define _THREAD_QUEUED (BIT(7))
|
||||
|
||||
/* end - states */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue