From owner-freebsd-questions@FreeBSD.ORG Sat Mar 6 08:18:05 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 041A6106564A for ; Sat, 6 Mar 2010 08:18:05 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) by mx1.freebsd.org (Postfix) with ESMTP id 7BD838FC0C for ; Sat, 6 Mar 2010 08:18:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id o268HnPY058817; Sat, 6 Mar 2010 19:17:49 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Sat, 6 Mar 2010 19:17:48 +1100 (EST) From: Ian Smith To: Dan Nelson In-Reply-To: <20100306065621.D5AC91065704@hub.freebsd.org> Message-ID: <20100306183731.N17960@sola.nimnet.asn.au> References: <20100306065621.D5AC91065704@hub.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: freebsd-questions@freebsd.org, Peter Steele Subject: Re: Calculating kernel/user/idle time 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: Sat, 06 Mar 2010 08:18:05 -0000 In freebsd-questions Digest, Vol 300, Issue 11, Message: 8 On Fri, 5 Mar 2010 16:58:20 -0600 Dan Nelson wrote: > In the last episode (Mar 05), Peter Steele said: > > > What's the proper way to calculate kernel/user/idle time? I know the raw > > values come from sysctl kern.cp_time, but these values need to be > > "massaged" based on the number of CPUs and so on. Can someone explain > > briefly what the algorithm is calculating the final percentages > > representing these times. > > They shouldn't need to be massaged. Just sample the values at two > intervals, and your percentages can be calculated by dividing each delta by > the sum of the deltas (since the sum equals the total CPU usage over the > interval, by definition). If you want to calculate per-cpu usage, use the > kern.cp_times sysctl instead. A bit over a year ago mav@ redesigned powerd's algorithm for measuring 'summary' load for multiple CPUs, as explained with revision 1.21.2.2 at http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.sbin/powerd/powerd.c which code may prove worthwhile exploring, or stealing. cheers, Ian