zephyr/kernel
Benjamin Walsh 6f4bc80901 kernel/timeout: fix handling expired timeouts in reverve queuing order
Queuing in the timeout_q of timeouts expiring on the same tick queue
them in reverse order: as soon as the new timeout finds a timeout
expiring on the same tick or later, it get prepended to that timeout:
this allows exiting the traversal of the timeout as soon as possible,
which is done with interrupts locked, thus reducing interrupt latency.
However, this has the side-effect of handling the timeouts expiring on
the same tick in the reverse order that they are queued.

For example:

    thread_c, prio 4:

        uint32_t uptime = k_uptime_get_32();

        while(uptime == k_uptime_get_32()); /* align on tick */

        k_timer_start(&timer_a, 5, 0);
        k_timer_start(&timer_b, 5, 0);

    thread_a, prio 5:

        k_timer_status_sync(&timer_a);
        printk("thread_a got timer_a\n");

    thread_b, prio 5:

        k_timer_status_sync(&timer_b);
        printk("thread_b got timer_b\n");

One could "reasonably" expect thread_a to run first, since both threads
have the same prio, and timer_a was started before timer_b, thus
inserted first in the timeout_q first (time-wise). However, thread_b
will run before thread_a, since timer_b's timeout is prepended to
timer_a's.

This patch keeps the reversing of the order when adding timeouts in the
timeout_q, thus preserving the same interrupt latency; however, when
dequeuing them and adding them to the expired queue, we now reverse that
order _again_, causing the timeouts to be handled in the expected order.

Change-Id: Id83045f63e2be88809d6089b8ae62034e4e3facb
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-16 04:56:25 +00:00
..
configs kernel: add LEGACY_KERNEL option 2017-01-09 19:42:13 +00:00
include kernel/timeouts: add description of timeouts queued on the same tick 2017-02-16 04:56:25 +00:00
alert.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
atomic_c.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
compiler_stack_protect.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
device.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
errno.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
fifo.c kernel/poll: add missing poll_event runtime init 2017-02-03 13:54:00 +00:00
idle.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
init.c kernel: init: use C implementation for STACK_CANARY_INIT 2017-02-07 22:18:21 +00:00
int_latency_bench.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
Kconfig Xtensa port: Increased idle thread stack size to avoid stack overflow. 2017-02-13 08:04:27 -08:00
Kconfig.event_logger license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
Kconfig.power_mgmt kernel: Remove redundant TICKLESS_IDLE_SUPPORTED option 2017-02-08 13:02:34 +00:00
legacy_offload.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
legacy_timer.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
lifo.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
mailbox.c kernel: rename thread states symbols 2017-01-24 13:34:49 +00:00
Makefile kernel: add k_poll() API 2017-02-02 00:30:00 +00:00
mem_pool.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
mem_slab.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
msg_q.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
mutex.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
pipes.c kernel: rename thread states symbols 2017-01-24 13:34:49 +00:00
poll.c kernel/poll: fix signal.signaled not being set when k_poll() waits 2017-02-09 23:54:27 +00:00
sched.c kernel/sched: protect thread sched_lock with compiler barriers 2017-02-16 04:56:21 +00:00
sem.c kernel/poll: add missing poll_event runtime init 2017-02-03 13:54:00 +00:00
stack.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
sys_clock.c kernel/timeout: fix handling expired timeouts in reverve queuing order 2017-02-16 04:56:25 +00:00
system_work_q.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
thread_abort.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
thread.c kernel: thread: Fix legacy symbol mixup in fp path 2017-02-03 03:20:31 +00:00
timer.c kernel: k_timer_stop: remove assert when called from an ISR 2017-02-04 19:25:11 +00:00
version.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00
work_q.c license: Replace Apache boilerplate with SPDX tag 2017-01-19 03:50:58 +00:00