diff options
author | njl <njl@FreeBSD.org> | 2004-06-19 02:27:23 +0000 |
---|---|---|
committer | njl <njl@FreeBSD.org> | 2004-06-19 02:27:23 +0000 |
commit | 6f4685cc9a4b463d82cde1be8325a1d0b845d3bd (patch) | |
tree | 9ec93ad2cb27da3bddb839c0baff17f61224342d /sys/dev | |
parent | f67091f0468031ed8526b0fb70e941bd3de3ab87 (diff) | |
download | FreeBSD-src-6f4685cc9a4b463d82cde1be8325a1d0b845d3bd.zip FreeBSD-src-6f4685cc9a4b463d82cde1be8325a1d0b845d3bd.tar.gz |
Add more precision to the cx_usage sysctl output and special-case 0%.
Submitted by: YONETANI Tomokazu <qhwt+freebsd-acpi AT les.ath.cx>
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/acpica/acpi_cpu.c | 16 |
1 files changed, 11 insertions, 5 deletions
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); |