[rtems-libbsd commit] Optimize callout handline via static timer wheel

Sebastian Huber sebh at rtems.org
Mon Sep 17 07:53:35 UTC 2018


Module:    rtems-libbsd
Branch:    master
Commit:    a85d90007eaf6756eda00af1a9d0d15621b52eec
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=a85d90007eaf6756eda00af1a9d0d15621b52eec

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Aug  4 14:32:19 2017 +0200

Optimize callout handline via static timer wheel

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 afa9eab..5427def 100644
--- a/freebsd/sys/kern/kern_timeout.c
+++ b/freebsd/sys/kern/kern_timeout.c
@@ -128,11 +128,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 - 1)
+#endif /* __rtems__ */
 
 /*
  * The callout cpu exec entities represent informations necessary for
@@ -170,10 +175,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;
@@ -359,8 +367,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__
 	/*
@@ -380,8 +390,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__
@@ -400,8 +412,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__
@@ -412,8 +426,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 cpu0 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 3c0b8da..3bba449 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -472,8 +472,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



More information about the vc mailing list