From owner-freebsd-questions@FreeBSD.ORG Fri Aug 19 21:25:12 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4F52516A420 for ; Fri, 19 Aug 2005 21:25:12 +0000 (GMT) (envelope-from kannanv@juniper.net) Received: from borg.juniper.net (borg.juniper.net [207.17.137.119]) by mx1.FreeBSD.org (Postfix) with ESMTP id EAFE043D55 for ; Fri, 19 Aug 2005 21:25:11 +0000 (GMT) (envelope-from kannanv@juniper.net) Received: from unknown (HELO beta.jnpr.net) (172.24.18.109) by borg.juniper.net with ESMTP; 19 Aug 2005 14:25:12 -0700 X-BrightmailFiltered: true X-Brightmail-Tracker: AAAAAA== X-IronPort-AV: i="3.96,127,1122879600"; d="scan'208"; a="487326241:sNHT22907620" Received: from gluon.jnpr.net ([172.24.15.23]) by beta.jnpr.net with Microsoft SMTPSVC(6.0.3790.211); Fri, 19 Aug 2005 14:25:11 -0700 Received: from 172.17.21.203 ([172.17.21.203]) by gluon.jnpr.net ([172.24.15.23]) via Exchange Front-End Server outlook.juniper.net ([172.24.18.177]) with Microsoft Exchange Server HTTP-DAV ; Fri, 19 Aug 2005 21:25:10 +0000 User-Agent: Microsoft-Entourage/11.1.0.040913 Date: Fri, 19 Aug 2005 14:25:10 -0700 From: Kannan Varadhan To: Chris St Denis , Message-ID: In-Reply-To: <200508191359843.SM01472@chris> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-OriginalArrivalTime: 19 Aug 2005 21:25:11.0224 (UTC) FILETIME=[7B040380:01C5A504] Cc: Subject: Re: Calculating the load average in the freebsd kernel X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Aug 2005 21:25:12 -0000 Thanks Chris. Yes, I did see that earlier. Two things about it: 1. It is for the linux kernel. Interestingly, the linux kernel is almost close enough to the BSD kernel, particularly in the choice of constants and usage, although in atypical convolutions. The main difference is in how it is an unfolded expression, which makes it hard to follow immediately, and in the formula itself, for which, ... 2. The linux formula though is: 67 #define CALC_LOAD(load,exp,n) \ 68 load *= exp; \ 69 load += n*(FIXED_1-exp); \ 70 load >>= FSHIFT; Which is load = ((load * exp) + n * (f_1 - exp)) >> FSHIFT. Exp is really (in BSD speak) FSCALE * \alpha, f_1 is FSCALE, so this formula boils down to (\alpha * load) + nrun * (1 - \alpha), a nice clean formula. Thanks, Kannan On 8/19/05 1:58 PM, "Chris St Denis" wrote: > This may help > > http://www.teamquest.com/resources/gunther/ldavg1.shtml > > -----Original Message----- > From: owner-freebsd-questions@freebsd.org > [mailto:owner-freebsd-questions@freebsd.org] On Behalf Of Kannan Varadhan > Sent: Friday, August 19, 2005 12:08 PM > To: freebsd-questions@freebsd.org > Subject: Calculating the load average in the freebsd kernel > > Hello, > > I am staring at the code in kern/kern_synch.c that calculates the load > average of the system, and I cannot fully understand how the freebsd version > works. Specifically, it looks as: > > /* > * Constants for averages over 1, 5, and 15 minutes > * when sampling at 5 second intervals. > */ > static fixpt_t cexp[3] = { > 0.9200444146293232 * FSCALE, /* exp(-1/12) */ > 0.9834714538216174 * FSCALE, /* exp(-1/60) */ > 0.9944598480048967 * FSCALE, /* exp(-1/180) */ > }; > > ... > > /* > * Compute a tenex style load average of a quantity on > * 1, 5 and 15 minute intervals. > * XXXKSE Needs complete rewrite when correct info is available. > * Completely Bogus.. only works with 1:1 (but compiles ok now :-) > */ > static void > loadav(void *arg) > { > int i, nrun; > struct loadavg *avg; > > nrun = sched_load(); > avg = &averunnable; > > for (i = 0; i < 3; i++) > avg->ldavg[i] = (cexp[i] * avg->ldavg[i] + > nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT; > > ... > > And elsewhere, FSCALE is defined as 1< > Focusing only the formula, then > > avg->ldavg[i] = (cexp[i] * avg->ldavg[i] + > nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT; > ^^^^^^ > Why do we have that extra FSCALE multiplier in the second term? If I do > some logical simplifications, this seems to get me: > > (\alpha * FSCALE * ldavg[I] + nrum * FSCALE * FSCALE (1 - \alpha)) >> FSHIFT > > I.e. > > \alpha * ldavg[I] + nrun * FSCALE * (1 - \alpha) > > What am I missing in this arithmetic? > > Thanks, > > Kannan > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"