zephyr/kernel
Daniel Leung 8ad5ad2214 kernel: don't unlock and then lock immediately in idle loop
Inside the idle loop, in some configuration, IRQ is unlocked and
then immediately locked again. There is a side effect:

1. IRQ is unlocked in middle of the loop.
2. Another thread (A) can now run so idle thread is un-scheduled.
3. Thread A runs to its end and going through the thread
   self-abort path.
4. Idle thread is rescheduled again, and continues to run
   the remaining loop when it eventuall calls k_cpu_idle().
   The "pending abort" path is not being executed on thread A
   at this point.
5. Now, thread A is suspended, and the CPU is in idle waiting
   for interrupts (e.g. timeouts).
6. Thread B is waiting to join on thread A. Since thread A has
   not been terminated yet so thread B is waiting until
   the idle thread runs again and starts executing from
   the beginning of while loop.
7. Depending on how many threads are running and how active
   the platform is, idle thread may not run again for a while,
   resulting in thread B appearing to be stuck.

To avoid this situation, the unlock/lock pair in middle of
the loop is removed so no rescheduling can be done mid-loop.
When there is no thread abort pending, it simply locks IRQ
and calls k_cpu_idle(). This is almost identical to the idle
loop before the thread abort code was introduced (except
the check for cpu->pending_abort).

Fixes #30573

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-12-15 08:27:27 -05:00
..
include power: standarize PM Kconfigs and cleanup 2020-12-09 15:18:29 -05:00
atomic_c.c
banner.c kernel: init: move banner handling 2020-11-27 20:08:14 -05:00
cache_handlers.c
CMakeLists.txt kernel: Make the "heap" backend to mem_pool default 2020-12-07 21:50:14 -05:00
compiler_stack_protect.c
device.c power: standarize PM Kconfigs and cleanup 2020-12-09 15:18:29 -05:00
errno.c
fatal.c twister: rename in code 2020-12-11 14:13:02 -05:00
futex.c
idle.c kernel: don't unlock and then lock immediately in idle loop 2020-12-15 08:27:27 -05:00
init.c Revert "kernel: fix usage of KERNEL_COHERENCE macro" 2020-12-08 14:27:27 -05:00
Kconfig power: standarize PM Kconfigs and cleanup 2020-12-09 15:18:29 -05:00
kheap.c kernel: add k_heap_aligned_alloc 2020-12-08 13:21:26 -05:00
mailbox.c kernel: Remove legacy mem_pool usage 2020-12-07 21:50:14 -05:00
mem_domain.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
mem_slab.c kernel: mem_slab: Optimize mem_slab_free 2020-12-07 11:36:48 +01:00
mempool.c kernel: Remove z_mem_pool wrapper internals 2020-12-07 21:50:14 -05:00
mmu.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
msg_q.c
mutex.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
pipes.c kernel: Remove legacy mem_pool usage 2020-12-07 21:50:14 -05:00
poll.c kernel: Rename struct _poller 2020-11-11 10:59:52 -05:00
queue.c kernel/queue: fix queue append/get race 2020-10-28 17:01:41 +01:00
sched.c Revert "kernel: fix usage of KERNEL_COHERENCE macro" 2020-12-08 14:27:27 -05:00
sem.c
smp.c
stack.c
system_work_q.c
thread_abort.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
thread.c kernel: thread: make offload_sem visible for releasing it outside 2020-12-09 21:52:09 -05:00
timeout.c Revert "kernel: fix usage of KERNEL_COHERENCE macro" 2020-12-08 14:27:27 -05:00
timer.c
userspace_handler.c
userspace.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
version.c
work_q.c kernel: Add K_DELAYED_WORK_DEFINE 2020-11-27 20:08:30 -05:00
xip.c kernel: move xip code to dedicated file 2020-11-27 20:08:14 -05:00