Index: sys/timeout.h =================================================================== RCS file: /cvs/src/sys/sys/timeout.h,v retrieving revision 1.26 diff -u -p -r1.26 timeout.h --- sys/timeout.h 22 Sep 2016 12:55:24 -0000 1.26 +++ sys/timeout.h 26 Sep 2016 02:56:21 -0000 @@ -27,6 +27,8 @@ #ifndef _SYS_TIMEOUT_H_ #define _SYS_TIMEOUT_H_ +#include + /* * Interface for handling time driven events in the kernel. * @@ -51,18 +53,7 @@ * These functions may be called in interrupt context (anything below splhigh). */ -struct circq { - struct circq *next; /* next element */ - struct circq *prev; /* previous element */ -}; - -struct timeout { - struct circq to_list; /* timeout queue, don't move */ - void (*to_func)(void *); /* function to call */ - void *to_arg; /* function argument */ - int to_time; /* ticks on event */ - int to_flags; /* misc flags */ -}; +#ifdef _KERNEL /* * flags in the to_flags field. @@ -72,7 +63,6 @@ struct timeout { #define TIMEOUT_INITIALIZED 4 /* timeout is initialized */ #define TIMEOUT_TRIGGERED 8 /* timeout is running or ran */ -#ifdef _KERNEL /* * special macros * @@ -82,9 +72,6 @@ struct timeout { #define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE) #define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED) #define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED) - -#define TIMEOUT_INITIALIZER(_f, _a) \ - { { NULL, NULL }, (_f), (_a), 0, TIMEOUT_INITIALIZED } struct bintime; Index: kern/kern_timeout.c =================================================================== RCS file: /cvs/src/sys/kern/kern_timeout.c,v retrieving revision 1.49 diff -u -p -r1.49 kern_timeout.c --- kern/kern_timeout.c 22 Sep 2016 12:55:24 -0000 1.49 +++ kern/kern_timeout.c 26 Sep 2016 02:56:21 -0000 @@ -375,6 +375,7 @@ softclock(void *arg) int delta; struct circq *bucket; struct timeout *to; + int needsproc = 0; mtx_enter(&timeout_mutex); while (!CIRCQ_EMPTY(&timeout_todo)) { @@ -391,7 +392,7 @@ softclock(void *arg) CIRCQ_INSERT(&to->to_list, bucket); } else if (to->to_flags & TIMEOUT_NEEDPROCCTX) { CIRCQ_INSERT(&to->to_list, &timeout_proc); - wakeup(&timeout_proc); + needsproc = 1; } else { #ifdef DEBUG if (delta < 0) @@ -401,6 +402,9 @@ softclock(void *arg) } } mtx_leave(&timeout_mutex); + + if (needsproc) + wakeup(&timeout_proc); } void @@ -415,6 +419,7 @@ softclock_thread(void *arg) { CPU_INFO_ITERATOR cii; struct cpu_info *ci; + struct sleep_state sls; struct timeout *to; KERNEL_ASSERT_LOCKED(); @@ -427,16 +432,18 @@ softclock_thread(void *arg) KASSERT(ci != NULL); sched_peg_curproc(ci); - mtx_enter(&timeout_mutex); for (;;) { - while (CIRCQ_EMPTY(&timeout_proc)) - msleep(&timeout_proc, &timeout_mutex, PSWP, "bored", 0); + sleep_setup(&sls, &timeout_proc, PSWP, "bored"); + sleep_finish(&sls, CIRCQ_EMPTY(&timeout_proc)); - to = timeout_from_circq(CIRCQ_FIRST(&timeout_proc)); - CIRCQ_REMOVE(&to->to_list); - timeout_run(to); + mtx_enter(&timeout_mutex); + while (!CIRCQ_EMPTY(&timeout_proc)) { + to = timeout_from_circq(CIRCQ_FIRST(&timeout_proc)); + CIRCQ_REMOVE(&to->to_list); + timeout_run(to); + } + mtx_leave(&timeout_mutex); } - mtx_leave(&timeout_mutex); } #ifndef SMALL_KERNEL