From owner-freebsd-acpi@FreeBSD.ORG Fri Jun 18 05:26:53 2004 Return-Path: Delivered-To: freebsd-acpi@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E46B216A4CE for ; Fri, 18 Jun 2004 05:26:53 +0000 (GMT) Received: from les.ath.cx (12.41.244.43.ap.yournet.ne.jp [43.244.41.12]) by mx1.FreeBSD.org (Postfix) with SMTP id 8D1FB43D4C for ; Fri, 18 Jun 2004 05:26:52 +0000 (GMT) (envelope-from qhwt+freebsd-acpi@les.ath.cx) Received: (qmail 48971 invoked by uid 1000); 18 Jun 2004 05:26:15 -0000 Date: Fri, 18 Jun 2004 14:26:15 +0900 From: YONETANI Tomokazu To: freebsd-acpi@freebsd.org Message-ID: <20040618052615.GA48947@les.ath.cx> References: <20040616131055.GA37637@les.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040616131055.GA37637@les.ath.cx> User-Agent: Mutt/1.5.6i Subject: Re: cx_usage X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jun 2004 05:26:54 -0000 Hello. On Wed, Jun 16, 2004 at 10:10:55PM +0900, YONETANI Tomokazu wrote: > What do you think about the following changes? > > - print 100% instead of 99% when there's only 1 Cx state, and 0% > when the sum is zero. > - two digits from fractional part of each percentage are shown; > my Laptop PC barely enters into C3 state and hw.acpi.cpu.cx_usage > is almost always "0% 99% 0%" after revision 1.39. it's now shown as > "0.00% 99.96% 0.03%" Actually, cpu_cx_stats[i] * 100 may not fit in u_int and would print incorrect value as values grow. Please try this instead. --- /home/build/freebsd/current/sys/dev/acpica/acpi_cpu.c 2004-06-16 15:27:25.000000000 +0900 +++ acpi_cpu.c 2004-06-16 15:24:38.000000000 +0900 @@ -1046,15 +1051,22 @@ struct sbuf sb; char buf[128]; int i; - u_int sum; + u_int64_t frac, real, sum; - /* Avoid divide by 0 potential error. */ - sum = 1; + sum = 0; for (i = 0; i < cpu_cx_count; i++) sum += cpu_cx_stats[i]; sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN); - for (i = 0; i < cpu_cx_count; i++) - sbuf_printf(&sb, "%u%% ", (cpu_cx_stats[i] * 100) / sum); + for (i = 0; i < cpu_cx_count; i++) { + if (sum == 0) + sbuf_printf(&sb, "0%% "); + else { + real = cpu_cx_stats[i] * 100; + frac = (real % sum) * 100; + sbuf_printf(&sb, "%u.%02u%% ", + (u_int)(real / sum), (u_int)(frac / sum)); + } + } sbuf_trim(&sb); sbuf_finish(&sb); sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);