[PATCH] Optimize callout handline via static timer wheel
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Sep 14 12:28:44 UTC 2018
The number of callouts is a compile-time constant in libbsd. Use this
in struct callout_cpu and avoid dynamic allocation of tables. This
signficantly reduces the count of load instructions in the callout
handling.
---
freebsd/sys/kern/kern_timeout.c | 18 +++++++++++++++++-
rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h | 2 --
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/freebsd/sys/kern/kern_timeout.c b/freebsd/sys/kern/kern_timeout.c
index f6a495222..c5ff77bd0 100644
--- a/freebsd/sys/kern/kern_timeout.c
+++ b/freebsd/sys/kern/kern_timeout.c
@@ -130,11 +130,16 @@ SYSCTL_INT(_kern, OID_AUTO, pin_default_swi, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &p
SYSCTL_INT(_kern, OID_AUTO, pin_pcpu_swi, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &pin_pcpu_swi,
0, "Pin the per-CPU swis (except PCPU 0, which is also default");
+#ifndef __rtems__
/*
* TODO:
* allocate more timeout table slots when table overflows.
*/
u_int callwheelsize, callwheelmask;
+#else /* __rtems__ */
+#define callwheelsize (2 * ncallout)
+#define callwheelmask (callwheelsize - 1u)
+#endif /* __rtems__ */
/*
* The callout cpu exec entities represent informations necessary for
@@ -172,10 +177,13 @@ struct callout_cpu {
struct cc_exec cc_exec_entity;
#endif /* __rtems__ */
struct callout *cc_next;
+#ifndef __rtems__
struct callout *cc_callout;
struct callout_list *cc_callwheel;
-#ifndef __rtems__
struct callout_tailq cc_expireq;
+#else /* __rtems__ */
+ struct callout cc_callout[ncallout];
+ struct callout_list cc_callwheel[callwheelsize];
#endif /* __rtems__ */
struct callout_slist cc_callfree;
sbintime_t cc_firstevent;
@@ -361,8 +369,10 @@ callout_callwheel_init(void *dummy)
* Calculate callout wheel size, should be next power of two higher
* than 'ncallout'.
*/
+#ifndef __rtems__
callwheelsize = 1 << fls(ncallout);
callwheelmask = callwheelsize - 1;
+#endif /* __rtems__ */
#ifndef __rtems__
/*
@@ -382,8 +392,10 @@ callout_callwheel_init(void *dummy)
timeout_cpu = PCPU_GET(cpuid);
#endif /* __rtems__ */
cc = CC_CPU(timeout_cpu);
+#ifndef __rtems__
cc->cc_callout = malloc(ncallout * sizeof(struct callout),
M_CALLOUT, M_WAITOK);
+#endif /* __rtems__ */
callout_cpu_init(cc, timeout_cpu);
}
#ifndef __rtems__
@@ -402,8 +414,10 @@ callout_cpu_init(struct callout_cpu *cc, int cpu)
mtx_init(&cc->cc_lock, "callout", NULL, MTX_SPIN | MTX_RECURSE);
SLIST_INIT(&cc->cc_callfree);
cc->cc_inited = 1;
+#ifndef __rtems__
cc->cc_callwheel = malloc(sizeof(struct callout_list) * callwheelsize,
M_CALLOUT, M_WAITOK);
+#endif /* __rtems__ */
for (i = 0; i < callwheelsize; i++)
LIST_INIT(&cc->cc_callwheel[i]);
#ifndef __rtems__
@@ -414,8 +428,10 @@ callout_cpu_init(struct callout_cpu *cc, int cpu)
cc_cce_cleanup(cc, i);
snprintf(cc->cc_ktr_event_name, sizeof(cc->cc_ktr_event_name),
"callwheel cpu %d", cpu);
+#ifndef __rtems__
if (cc->cc_callout == NULL) /* Only BSP handles timeout(9) */
return;
+#endif /* __rtems__ */
for (i = 0; i < ncallout; i++) {
c = &cc->cc_callout[i];
callout_init(c, 0);
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 2d7e5db4e..a4672a16b 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -465,8 +465,6 @@
#define callout_schedule_on _bsd_callout_schedule_on
#define _callout_stop_safe _bsd__callout_stop_safe
#define callout_when _bsd_callout_when
-#define callwheelmask _bsd_callwheelmask
-#define callwheelsize _bsd_callwheelsize
#define camellia_decrypt _bsd_camellia_decrypt
#define camellia_decrypt128 _bsd_camellia_decrypt128
#define camellia_decrypt256 _bsd_camellia_decrypt256
--
2.13.7
More information about the devel
mailing list