Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Mar 2013 10:37:17 +0000 (UTC)
From:      Andre Oppermann <andre@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r248032 - in head/sys: kern sys vm
Message-ID:  <201303081037.r28AbHff059451@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andre
Date: Fri Mar  8 10:37:17 2013
New Revision: 248032
URL: http://svnweb.freebsd.org/changeset/base/248032

Log:
  Move the callout subsystem initialization to its own SYSINIT()
  from being indirectly called via cpu_startup()+vm_ksubmap_init().
  The boot order position remains the same at SI_SUB_CPU.
  
  Allocation of the callout array is changed to stardard kernel malloc
  from a slightly obscure direct kernel_map allocation.
  
  kern_timeout_callwheel_alloc() is renamed to callout_callwheel_init()
  to better describe its purpose.
  kern_timeout_callwheel_init() is removed simplifying the per-cpu
  initialization.
  
  Reviewed by:	davide

Modified:
  head/sys/kern/kern_timeout.c
  head/sys/sys/systm.h
  head/sys/vm/vm_init.c

Modified: head/sys/kern/kern_timeout.c
==============================================================================
--- head/sys/kern/kern_timeout.c	Fri Mar  8 10:14:58 2013	(r248031)
+++ head/sys/kern/kern_timeout.c	Fri Mar  8 10:37:17 2013	(r248032)
@@ -187,6 +187,7 @@ struct callout_cpu cc_cpu;
 
 static int timeout_cpu;
 
+static void	callout_cpu_init(struct callout_cpu *cc);
 static void	softclock_call_cc(struct callout *c, struct callout_cpu *cc,
 #ifdef CALLOUT_PROFILING
 		    int *mpcalls, int *lockcalls, int *gcalls,
@@ -246,19 +247,14 @@ cc_cce_migrating(struct callout_cpu *cc,
 }
 
 /*
- * kern_timeout_callwheel_alloc() - kernel low level callwheel initialization
- *
- *	This code is called very early in the kernel initialization sequence,
- *	and may be called more then once.
+ * Kernel low level callwheel initialization
+ * called on cpu0 during kernel startup.
  */
-caddr_t
-kern_timeout_callwheel_alloc(caddr_t v)
+static void
+callout_callwheel_init(void *dummy)
 {
 	struct callout_cpu *cc;
 
-	timeout_cpu = PCPU_GET(cpuid);
-	cc = CC_CPU(timeout_cpu);
-
 	/*
 	 * Calculate the size of the callout wheel and the preallocated
 	 * timeout() structures.
@@ -273,13 +269,23 @@ kern_timeout_callwheel_alloc(caddr_t v)
 	callwheelsize = 1 << fls(ncallout);
 	callwheelmask = callwheelsize - 1;
 
-	cc->cc_callout = (struct callout *)v;
-	v = (caddr_t)(cc->cc_callout + ncallout);
-	cc->cc_callwheel = (struct callout_list *)v;
-	v = (caddr_t)(cc->cc_callwheel + callwheelsize);
-	return(v);
+	/*
+	 * Only cpu0 handles timeout(9) and receives a preallocation.
+	 *
+	 * XXX: Once all timeout(9) consumers are converted this can
+	 * be removed.
+	 */
+	timeout_cpu = PCPU_GET(cpuid);
+	cc = CC_CPU(timeout_cpu);
+	cc->cc_callout = malloc(ncallout * sizeof(struct callout),
+	    M_CALLOUT, M_WAITOK);
+	callout_cpu_init(cc);
 }
+SYSINIT(callwheel_init, SI_SUB_CPU, SI_ORDER_ANY, callout_callwheel_init, NULL);
 
+/*
+ * Initialize the per-cpu callout structures.
+ */
 static void
 callout_cpu_init(struct callout_cpu *cc)
 {
@@ -288,13 +294,15 @@ callout_cpu_init(struct callout_cpu *cc)
 
 	mtx_init(&cc->cc_lock, "callout", NULL, MTX_SPIN | MTX_RECURSE);
 	SLIST_INIT(&cc->cc_callfree);
+	cc->cc_callwheel = malloc(sizeof(struct callout_tailq) * callwheelsize,
+	    M_CALLOUT, M_WAITOK);
 	for (i = 0; i < callwheelsize; i++)
 		LIST_INIT(&cc->cc_callwheel[i]);
 	TAILQ_INIT(&cc->cc_expireq);
 	cc->cc_firstevent = INT64_MAX;
 	for (i = 0; i < 2; i++)
 		cc_cce_cleanup(cc, i);
-	if (cc->cc_callout == NULL)
+	if (cc->cc_callout == NULL)	/* Only cpu0 handles timeout(9) */
 		return;
 	for (i = 0; i < ncallout; i++) {
 		c = &cc->cc_callout[i];
@@ -335,19 +343,6 @@ callout_cpu_switch(struct callout *c, st
 #endif
 
 /*
- * kern_timeout_callwheel_init() - initialize previously reserved callwheel
- *				   space.
- *
- *	This code is called just once, after the space reserved for the
- *	callout wheel has been finalized.
- */
-void
-kern_timeout_callwheel_init(void)
-{
-	callout_cpu_init(CC_CPU(timeout_cpu));
-}
-
-/*
  * Start standard softclock thread.
  */
 static void
@@ -367,18 +362,14 @@ start_softclock(void *dummy)
 		if (cpu == timeout_cpu)
 			continue;
 		cc = CC_CPU(cpu);
+		cc->cc_callout = NULL;	/* Only cpu0 handles timeout(9). */
+		callout_cpu_init(cc);
 		if (swi_add(NULL, "clock", softclock, cc, SWI_CLOCK,
 		    INTR_MPSAFE, &cc->cc_cookie))
 			panic("died while creating standard software ithreads");
-		cc->cc_callout = NULL;	/* Only cpu0 handles timeout(). */
-		cc->cc_callwheel = malloc(
-		    sizeof(struct callout_list) * callwheelsize, M_CALLOUT,
-		    M_WAITOK);
-		callout_cpu_init(cc);
 	}
 #endif
 }
-
 SYSINIT(start_softclock, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softclock, NULL);
 
 #define	CC_HASH_SHIFT	8

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h	Fri Mar  8 10:14:58 2013	(r248031)
+++ head/sys/sys/systm.h	Fri Mar  8 10:37:17 2013	(r248032)
@@ -321,8 +321,6 @@ typedef void timeout_t(void *);	/* timeo
 void	callout_handle_init(struct callout_handle *);
 struct	callout_handle timeout(timeout_t *, void *, int);
 void	untimeout(timeout_t *, void *, struct callout_handle);
-caddr_t	kern_timeout_callwheel_alloc(caddr_t v);
-void	kern_timeout_callwheel_init(void);
 
 /* Stubs for obsolete functions that used to be for interrupt management */
 static __inline intrmask_t	splbio(void)		{ return 0; }

Modified: head/sys/vm/vm_init.c
==============================================================================
--- head/sys/vm/vm_init.c	Fri Mar  8 10:14:58 2013	(r248031)
+++ head/sys/vm/vm_init.c	Fri Mar  8 10:37:17 2013	(r248032)
@@ -157,8 +157,6 @@ vm_ksubmap_init(struct kva_md_info *kmi)
 again:
 	v = (caddr_t)firstaddr;
 
-	v = kern_timeout_callwheel_alloc(v);
-
 	/*
 	 * Discount the physical memory larger than the size of kernel_map
 	 * to avoid eating up all of KVA space.
@@ -202,10 +200,5 @@ again:
 	 * XXX: Mbuf system machine-specific initializations should
 	 *      go here, if anywhere.
 	 */
-
-	/*
-	 * Initialize the callouts we just allocated.
-	 */
-	kern_timeout_callwheel_init();
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303081037.r28AbHff059451>