zephyr/kernel
Andy Ross b1182bf83b kernel/timeout: Serialize handler callbacks on SMP
On multiprocessor systems, it's routine to enter sys_clock_announce()
in parallel (the driver will generally announce zero ticks on all but
one cpu).

When that happens, each call will independently enter the loop over
the timeout list.  The access is correctly synchronized, so the list
handling is correct.  But the lock is RELEASED around the invocation
of the callback, which means that the individual callbacks may
interleave between cpus.  That means that individual
application-provided callbacks may be executed in parallel, which to
the app is indistinguishable from "out of order".

That's surprising and error-prone.  Don't do it.  Place a secondary
outer spinlock around the announce loop (but not the timeslicing
handling) to correctly serialize the timeout handling on a single cpu.

(It should be noted that this was discovered not because of a timeout
callback race, but because the resulting simultaneous calls to
sys_clock_set_timeout from separate cores seems to cause extremely
high latency excursions on intel_adsp hardware using the cavs_timer
driver.  That hardware issue is still poorly understood, but this fix
is desirable regardless.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2022-04-08 09:28:47 +02:00
..
include everywhere: fix typos 2022-03-18 13:24:08 -04:00
paging
atomic_c.c
banner.c
cache_handlers.c
CMakeLists.txt
compiler_stack_protect.c
condvar.c
device.c
errno.c
events.c
fatal.c
futex.c
idle.c pm: Do not suspend during kernel initialization 2022-01-19 14:14:28 -05:00
init.c kernel: Remove idle thread cpu index on single-core devices 2022-03-30 10:08:48 -04:00
Kconfig kernel: SMP is Symmetric multiprocessing 2022-03-15 11:07:29 -04:00
Kconfig.vm everywhere: fix typos 2022-03-18 13:24:08 -04:00
kheap.c
mailbox.c kernel: remove @return doc for void functions 2022-01-12 16:02:16 -05:00
main_weak.c
mem_domain.c
mem_slab.c kernel: remove @return doc for void functions 2022-01-12 16:02:16 -05:00
mempool.c
mmu.c kernel: mmu: add a log line for z_phys_unmap 2022-02-24 08:38:38 -06:00
msg_q.c
mutex.c everywhere: fix typos 2022-03-18 13:24:08 -04:00
pipes.c kernel: pipes: add pipe flush routines 2022-01-10 12:17:14 -05:00
poll.c everywhere: fix typos 2022-03-14 20:22:24 -04:00
queue.c
sched.c sched: formalize the passing of NULL to z_get_next_switch_handle() 2022-03-18 13:32:49 -04:00
sem.c
smp.c kernel: Refactor SMP cpu initialization a bit 2022-03-01 09:59:15 -05:00
stack.c
system_work_q.c
thread.c kernel: Reduce strncpy in z_impl_k_thread_name_set by null char 2022-03-10 10:12:48 +01:00
timeout.c kernel/timeout: Serialize handler callbacks on SMP 2022-04-08 09:28:47 +02:00
timer.c kernel: remove @return doc for void functions 2022-01-12 16:02:16 -05:00
usage.c kernel: Update CPU runtime stats of non-idle time 2022-01-20 08:22:01 -05:00
userspace_handler.c
userspace.c userspace: plug thread index leak in k_object_alloc() 2022-03-14 19:18:34 -04:00
version.c
work.c
xip.c kernel/init.c: allow for memset/memcpy alternatives during early boot 2022-02-21 21:00:12 -05:00