From 6f4685cc9a4b463d82cde1be8325a1d0b845d3bd Mon Sep 17 00:00:00 2001 From: njl Date: Sat, 19 Jun 2004 02:27:23 +0000 Subject: Add more precision to the cx_usage sysctl output and special-case 0%. Submitted by: YONETANI Tomokazu --- sys/dev/acpica/acpi_cpu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sys/dev/acpica') diff --git a/sys/dev/acpica/acpi_cpu.c b/sys/dev/acpica/acpi_cpu.c index 7098652..3691c81 100644 --- a/sys/dev/acpica/acpi_cpu.c +++ b/sys/dev/acpica/acpi_cpu.c @@ -1046,15 +1046,21 @@ acpi_cpu_usage_sysctl(SYSCTL_HANDLER_ARGS) struct sbuf sb; char buf[128]; int i; - u_int sum; + uint64_t fract, sum, whole; - /* 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) { + whole = cpu_cx_stats[i] * 100; + fract = (whole % sum) * 100; + sbuf_printf(&sb, "%u.%02u%% ", (u_int)(whole / sum), + (u_int)(fract / sum)); + } else + sbuf_printf(&sb, "0%% "); + } sbuf_trim(&sb); sbuf_finish(&sb); sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); -- cgit v1.1