Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Nov 2000 13:00:14 -0800
From:      Jake Burkholder <jburkhol@home.com>
To:        arch@freebsd.org
Cc:        smp@freebsd.org
Subject:   review: callout patch
Message-ID:  <20001126210014.D824BBA7A@io.yi.org>

next in thread | raw e-mail | index | archive | help

This patch makes most of sys/kern/* sources use callout_reset for
registering callouts rather than timeout(9).  This should greatly
reduce the use of the fixed size callfree allocator pool.  Currently
we panic when it runs out.

This was motivated by NetBSD, who have completely removed timeout(9)
from their kernel.

Please review it.

Index: compat/linux/linux_misc.c
===================================================================
RCS file: /home/ncvs/src/sys/compat/linux/linux_misc.c,v
retrieving revision 1.88
diff -u -r1.88 linux_misc.c
--- compat/linux/linux_misc.c	2000/11/10 21:30:18	1.88
+++ compat/linux/linux_misc.c	2000/11/26 00:55:05
@@ -115,9 +115,9 @@
     old_it = p->p_realtimer;
     getmicrouptime(&tv);
     if (timevalisset(&old_it.it_value))
-	untimeout(realitexpire, (caddr_t)p, p->p_ithandle);
+	callout_stop(&p->p_itcallout);
     if (it.it_value.tv_sec != 0) {
-	p->p_ithandle = timeout(realitexpire, (caddr_t)p, tvtohz(&it.it_value));
+	callout_reset(&p->p_itcallout, tvtohz(&it.it_value), realitexpire, p);
 	timevaladd(&it.it_value, &tv);
     }
     p->p_realtimer = it;
Index: kern/init_main.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/init_main.c,v
retrieving revision 1.147
diff -u -r1.147 init_main.c
--- kern/init_main.c	2000/11/22 07:41:57	1.147
+++ kern/init_main.c	2000/11/26 00:21:00
@@ -312,6 +312,9 @@
 
 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
 
+	callout_init(&p->p_itcallout, 0);
+	callout_init(&p->p_slpcallout, 0);
+
 	/* Create credentials. */
 	cred0.p_refcnt = 1;
 	cred0.p_uidinfo = uifind(0);
Index: kern/kern_acct.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_acct.c,v
retrieving revision 1.26
diff -u -r1.26 kern_acct.c
--- kern/kern_acct.c	2000/07/04 03:34:06	1.26
+++ kern/kern_acct.c	2000/11/26 07:30:52
@@ -77,11 +77,9 @@
 static void	acctwatch __P((void *));
 
 /*
- * Accounting callout handle used for periodic scheduling of
- * acctwatch.
+ * Accounting callout used for periodic scheduling of acctwatch.
  */
-static struct	callout_handle acctwatch_handle
-    = CALLOUT_HANDLE_INITIALIZER(&acctwatch_handle);
+static struct	callout acctwatch_callout;
 
 /*
  * Accounting vnode pointer, and saved vnode pointer.
@@ -148,7 +146,7 @@
 	 * close the file, and (if no new file was specified, leave).
 	 */
 	if (acctp != NULLVP || savacctp != NULLVP) {
-		untimeout(acctwatch, NULL, acctwatch_handle);
+		callout_stop(&acctwatch_callout);
 		error = vn_close((acctp != NULLVP ? acctp : savacctp), FWRITE,
 		    p->p_ucred, p);
 		acctp = savacctp = NULLVP;
@@ -161,6 +159,7 @@
 	 * free space watcher.
 	 */
 	acctp = nd.ni_vp;
+	callout_init(&acctwatch_callout, 0);
 	acctwatch(NULL);
 	return (error);
 }
@@ -329,5 +328,5 @@
 			log(LOG_NOTICE, "Accounting suspended\n");
 		}
 	}
-	acctwatch_handle = timeout(acctwatch, NULL, acctchkfreq * hz);
+	callout_reset(&acctwatch_callout, acctchkfreq * hz, acctwatch, NULL);
 }
Index: kern/kern_exit.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.104
diff -u -r1.104 kern_exit.c
--- kern/kern_exit.c	2000/11/22 07:41:58	1.104
+++ kern/kern_exit.c	2000/11/26 00:05:38
@@ -172,7 +172,7 @@
 	p->p_flag |= P_WEXIT;
 	SIGEMPTYSET(p->p_siglist);
 	if (timevalisset(&p->p_realtimer.it_value))
-		untimeout(realitexpire, (caddr_t)p, p->p_ithandle);
+		callout_stop(&p->p_itcallout);
 
 	/*
 	 * Reset any sigio structures pointing to us as a result of
Index: kern/kern_fork.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.84
diff -u -r1.84 kern_fork.c
--- kern/kern_fork.c	2000/11/22 07:41:58	1.84
+++ kern/kern_fork.c	2000/11/26 00:20:48
@@ -483,6 +483,9 @@
 	LIST_INIT(&p2->p_heldmtx);
 	LIST_INIT(&p2->p_contested);
 
+	callout_init(&p2->p_itcallout, 0);
+	callout_init(&p2->p_slpcallout, 0);
+
 #ifdef KTRACE
 	/*
 	 * Copy traceflag and tracefile if enabled.
Index: kern/kern_synch.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_synch.c,v
retrieving revision 1.110
diff -u -r1.110 kern_synch.c
--- kern/kern_synch.c	2000/11/22 07:41:58	1.110
+++ kern/kern_synch.c	2000/11/26 00:55:54
@@ -70,6 +70,9 @@
 int	lbolt;
 int	sched_quantum;		/* Roundrobin scheduling quantum in ticks. */
 
+static struct callout schedcpu_callout;
+static struct callout roundrobin_callout;
+
 static int	curpriority_cmp __P((struct proc *p));
 static void	endtsleep __P((void *));
 static void	maybe_resched __P((struct proc *chk));
@@ -175,7 +178,7 @@
  		need_resched();
 #endif
 
- 	timeout(roundrobin, NULL, sched_quantum);
+	callout_reset(&roundrobin_callout, sched_quantum, roundrobin, NULL);
 }
 
 /*
@@ -344,7 +347,7 @@
 	lockmgr(&allproc_lock, LK_RELEASE, NULL, CURPROC);
 	vmmeter();
 	wakeup((caddr_t)&lbolt);
-	timeout(schedcpu, (void *)0, hz);
+	callout_reset(&schedcpu_callout, hz, schedcpu, NULL);
 }
 
 /*
@@ -414,7 +417,6 @@
 {
 	struct proc *p = curproc;
 	int s, sig, catch = priority & PCATCH;
-	struct callout_handle thandle;
 	int rval = 0;
 	WITNESS_SAVE_DECL(mtx);
 
@@ -465,7 +467,7 @@
 		p, p->p_pid, p->p_comm, (void *) sched_lock.mtx_lock);
 	TAILQ_INSERT_TAIL(&slpque[LOOKUP(ident)], p, p_slpq);
 	if (timo)
-		thandle = timeout(endtsleep, (void *)p, timo);
+		callout_reset(&p->p_slpcallout, timo, endtsleep, p);
 	/*
 	 * We put ourselves on the sleep queue and start our timeout
 	 * before calling CURSIG, as we could stop there, and a wakeup
@@ -517,7 +519,7 @@
 			goto out;
 		}
 	} else if (timo)
-		untimeout(endtsleep, (void *)p, thandle);
+		callout_stop(&p->p_slpcallout);
 	mtx_exit(&sched_lock, MTX_SPIN);
 
 	if (catch && (sig != 0 || (sig = CURSIG(p)))) {
@@ -628,7 +630,6 @@
 	s = splhigh();
 
 	if (p->p_wchan != NULL) {
-		struct callout_handle thandle;
 		int sig;
 		int catch;
 
@@ -646,7 +647,7 @@
 		 */
 
 		if (timo)
-			thandle = timeout(endtsleep, (void *)p, timo);
+			callout_reset(&p->p_slpcallout, timo, endtsleep, p);
 
 		sig = 0;
 		catch = priority & PCATCH;
@@ -687,7 +688,7 @@
 				goto out;
 			}
 		} else if (timo)
-			untimeout(endtsleep, (void *)p, thandle);
+			callout_stop(&p->p_slpcallout);
 		mtx_exit(&sched_lock, MTX_SPIN);
 
 		if (catch && (sig != 0 || (sig = CURSIG(p)))) {
@@ -1036,6 +1037,10 @@
 sched_setup(dummy)
 	void *dummy;
 {
+
+	callout_init(&schedcpu_callout, 1);
+	callout_init(&roundrobin_callout, 0);
+
 	/* Kick off timeout driven events by calling first time. */
 	roundrobin(NULL);
 	schedcpu(NULL);
Index: kern/kern_time.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_time.c,v
retrieving revision 1.70
diff -u -r1.70 kern_time.c
--- kern/kern_time.c	2000/04/18 15:15:20	1.70
+++ kern/kern_time.c	2000/11/26 01:13:48
@@ -513,10 +513,10 @@
 	s = splclock(); /* XXX: still needed ? */
 	if (uap->which == ITIMER_REAL) {
 		if (timevalisset(&p->p_realtimer.it_value))
-			untimeout(realitexpire, (caddr_t)p, p->p_ithandle);
+			callout_stop(&p->p_itcallout);
 		if (timevalisset(&aitv.it_value)) 
-			p->p_ithandle = timeout(realitexpire, (caddr_t)p,
-						tvtohz(&aitv.it_value));
+			callout_reset(&p->p_itcallout, tvtohz(&aitv.it_value),
+			    realitexpire, p);
 		getmicrouptime(&ctv);
 		timevaladd(&aitv.it_value, &ctv);
 		p->p_realtimer = aitv;
@@ -560,8 +560,8 @@
 		if (timevalcmp(&p->p_realtimer.it_value, &ctv, >)) {
 			ntv = p->p_realtimer.it_value;
 			timevalsub(&ntv, &ctv);
-			p->p_ithandle = timeout(realitexpire, (caddr_t)p,
-			    tvtohz(&ntv) - 1);
+			callout_reset(&p->p_itcallout, tvtohz(&ntv) - 1,
+			    realitexpire, p);
 			splx(s);
 			return;
 		}
Index: kern/uipc_domain.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/uipc_domain.c,v
retrieving revision 1.22
diff -u -r1.22 uipc_domain.c
--- kern/uipc_domain.c	1999/08/28 00:46:21	1.22
+++ kern/uipc_domain.c	2000/11/26 07:09:06
@@ -61,6 +61,9 @@
 static void domaininit __P((void *));
 SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
 
+static struct callout pffast_callout;
+static struct callout pfslow_callout;
+
 static void	pffasttimo __P((void *));
 static void	pfslowtimo __P((void *));
 
@@ -136,9 +139,12 @@
 
 	if (max_linkhdr < 16)		/* XXX */
 		max_linkhdr = 16;
+
+	callout_init(&pffast_callout, 0);
+	callout_init(&pfslow_callout, 0);
 
-	timeout(pffasttimo, (void *)0, 1);
-	timeout(pfslowtimo, (void *)0, 1);
+	callout_reset(&pffast_callout, 1, pffasttimo, NULL);
+	callout_reset(&pfslow_callout, 1, pfslowtimo, NULL);
 }
 
 
@@ -214,7 +220,7 @@
 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
 			if (pr->pr_slowtimo)
 				(*pr->pr_slowtimo)();
-	timeout(pfslowtimo, (void *)0, hz/2);
+	callout_reset(&pfslow_callout, hz/2, pfslowtimo, NULL);
 }
 
 static void
@@ -228,5 +234,5 @@
 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
 			if (pr->pr_fasttimo)
 				(*pr->pr_fasttimo)();
-	timeout(pffasttimo, (void *)0, hz/5);
+	callout_reset(&pffast_callout, hz/5, pffasttimo, NULL);
 }
Index: sys/proc.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/proc.h,v
retrieving revision 1.124
diff -u -r1.124 proc.h
--- sys/proc.h	2000/11/22 07:42:01	1.124
+++ sys/proc.h	2000/11/26 00:28:23
@@ -157,10 +157,6 @@
 	LIST_ENTRY(proc) p_sibling;	/* List of sibling processes. */
 	LIST_HEAD(, proc) p_children;	/* Pointer to list of children. */
 
-	struct callout_handle p_ithandle; /*
-					      * Callout handle for scheduling
-					      * p_realtimer.
-					      */
 /* The following fields are all zeroed upon creation in fork. */
 #define	p_startzero	p_oppid
 
@@ -173,11 +169,13 @@
 	u_int	p_estcpu;	 /* Time averaged value of p_cpticks. */
 	int	p_cpticks;	 /* Ticks of cpu time. */
 	fixpt_t	p_pctcpu;	 /* %cpu for this process during p_swtime */
+	struct	callout p_slpcallout;	/* Callout for sleep. */
 	void	*p_wchan;	 /* Sleep address. */
 	const char *p_wmesg;	 /* Reason for sleep. */
 	u_int	p_swtime;	 /* Time swapped in or out. */
 	u_int	p_slptime;	 /* Time since last blocked. */
 
+	struct	callout p_itcallout;	/* Interval timer callout. */
 	struct	itimerval p_realtimer;	/* Alarm timer. */
 	u_int64_t p_runtime;		/* Real time in microsec. */
 	u_int64_t p_uu;			/* Previous user time in microsec. */




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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