Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jan 2004 07:43:30 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 44848 for review
Message-ID:  <200401061543.i06FhUWj021960@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=44848

Change 44848 by jhb@jhb_blue on 2004/01/06 07:42:41

	Stick loadav() in its own thread since it uses allproc_lock.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_synch.c#60 edit
.. //depot/projects/smpng/sys/notes#2 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_synch.c#60 (text+ko) ====

@@ -76,7 +76,6 @@
 int	hogticks;
 int	lbolt;
 
-static struct callout loadav_callout;
 static struct callout lbolt_callout;
 
 struct loadavg averunnable =
@@ -96,7 +95,8 @@
 SYSCTL_INT(_kern, OID_AUTO, fscale, CTLFLAG_RD, 0, FSCALE, "");
 
 static void	endtsleep(void *);
-static void	loadav(void *arg);
+static void	loadav(void);
+static void	loadav_thread(void *dummy);
 static void	lboltcb(void *arg);
 
 /*
@@ -577,7 +577,7 @@
  * Completely Bogus.. only works with 1:1 (but compiles ok now :-)
  */
 static void
-loadav(void *arg)
+loadav(void)
 {
 	int i, nrun;
 	struct loadavg *avg;
@@ -606,14 +606,31 @@
 	for (i = 0; i < 3; i++)
 		avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
 		    nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
+}
 
-	/*
-	 * Schedule the next update to occur after 5 seconds, but add a
-	 * random variation to avoid synchronisation with processes that
-	 * run at regular intervals.
-	 */
-	callout_reset(&loadav_callout, hz * 4 + (int)(random() % (hz * 2 + 1)),
-	    loadav, NULL);
+/*
+ * Main loop for a kthread that executes loadav() periodically.
+ */
+static void
+loadav_thread(void *dummy)
+{
+	struct proc *p;
+	int nowake;
+
+	p = curthread->td_proc;
+	PROC_LOCK(p);
+	p->p_flag |= P_NOLOAD;
+	PROC_UNLOCK(p);
+	for (;;) {
+		loadav();
+		/*
+		 * Schedule the next update to occur after 5 seconds, but
+		 * add a random variation to avoid synchronisation with
+		 * processes that run at regular intervals.
+		 */
+		tsleep(&nowake, curthread->td_priority, "-", hz * 4 +
+		    (int)(random() % (hz * 2 + 1)));
+	}
 }
 
 static void
@@ -632,8 +649,10 @@
 	callout_init(&lbolt_callout, CALLOUT_MPSAFE);
 
 	/* Kick off timeout driven events by calling first time. */
-	loadav(NULL);
 	lboltcb(NULL);
+
+	/* Kick off loadav kernel process. */
+	kthread_create(loadav_thread, NULL, NULL, 0, 0, "loadav");
 }
 
 /*

==== //depot/projects/smpng/sys/notes#2 (text+ko) ====

@@ -43,6 +43,7 @@
   - Untested
 + Move schedcpu() into its own kthread.
   + Committed
+- Move loadav() into the schedcpu kthread.
 - Remove some bogus atomic_load_acq()'s and add ia32_pause()'s to
   stop_cpus() and restart_cpus().
   - Untested



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