From owner-freebsd-hackers Sat Mar 20 12:18:38 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from bingsun1.cc.binghamton.edu (bingsun1.cc.binghamton.edu [128.226.1.2]) by hub.freebsd.org (Postfix) with ESMTP id 0C7D614E8C for ; Sat, 20 Mar 1999 12:18:36 -0800 (PST) (envelope-from bf20761@binghamton.edu) Received: from localhost by bingsun1.cc.binghamton.edu (8.9.3/8.9.3) with SMTP id PAA18704 for ; Sat, 20 Mar 1999 15:18:15 -0500 (EST) X-Authentication-Warning: bingsun1.cc.binghamton.edu: bf20761 owned process doing -bs Date: Sat, 20 Mar 1999 15:18:15 -0500 (EST) From: zhihuizhang X-Sender: bf20761@bingsun1 To: freebsd-hackers@FreeBSD.ORG Subject: Calculation of load average and CCPU_SHIFT Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I am looking into the source code in file vm_meter.c and kern_synch.c of FreeBSD 2.2.8. They use integer multiplication and shift operation to replace the costly float multiplication. The FSCALE and FSHIFT are for this purpose. But I could not understand the usage of CCPU_SHIFT in schedcpu(). Specifically, please explain the following comments in the source code in more detail if possible: -------------------------------------------------------------------- To estimate CCPU_SHIFT for exp(-1/20), the following formula was used: 1 - exp(-1/20) ~= 0.0487 ~= 0.0488 == 1 (fixed pt, *11* bits). Scale factor for scaled integers used to count %cpu time and load averages. The number of CPU 'tick's that map to a unique '%age' can be expressed by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that can be calculated (assuming 32 bits) can be closely approximated using the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). For the scheduler to maintain a 1:1 mapping of CPU 'tick' to '%age', FSHIFT must be at least 11; this gives us a maximum load average of ~1024. ------------------------------------------------------------------- Any help or hint is appreciated. -------------------------------------------------- | Zhihui Zhang, http://cs.binghamton.edu/~zzhang | | Dept. of Computer Science, SUNY at Binghamton | -------------------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message