From owner-p4-projects@FreeBSD.ORG Tue Jan 6 07:43:58 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5DFC916A4D1; Tue, 6 Jan 2004 07:43:58 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 30EE916A4CE for ; Tue, 6 Jan 2004 07:43:58 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id F163E43D78 for ; Tue, 6 Jan 2004 07:43:30 -0800 (PST) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i06FhU0B021963 for ; Tue, 6 Jan 2004 07:43:30 -0800 (PST) (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i06FhUWj021960 for perforce@freebsd.org; Tue, 6 Jan 2004 07:43:30 -0800 (PST) (envelope-from jhb@freebsd.org) Date: Tue, 6 Jan 2004 07:43:30 -0800 (PST) Message-Id: <200401061543.i06FhUWj021960@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Subject: PERFORCE change 44848 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jan 2004 15:43:58 -0000 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