From eba141e6dcef379f3be50e3e2a5a1e4bfad9131a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 25 Jul 2025 02:51:16 -0400 Subject: usr: kstat: Add CPU percent online reporting Reports the CPU online percentage given how many cores are online and how many cores are offline. Signed-off-by: Ian Moffett --- usr.bin/kstat/kstat.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'usr.bin/kstat/kstat.c') diff --git a/usr.bin/kstat/kstat.c b/usr.bin/kstat/kstat.c index 853bc8b..e3b7e6a 100644 --- a/usr.bin/kstat/kstat.c +++ b/usr.bin/kstat/kstat.c @@ -37,6 +37,8 @@ get_sched_stat(void) { struct sched_stat stat; struct sched_cpu *cpu; + double nonline, noffline; + uint16_t online_percent; int fd; fd = open("/ctl/sched/stat", O_RDONLY); @@ -50,10 +52,15 @@ get_sched_stat(void) } close(fd); + noffline = stat.nhlt; + nonline = (stat.ncpu - noffline); + online_percent = (uint16_t)(((double)nonline / (nonline + noffline)) * 100); + printf("-------------------------------\n"); printf("Number of tasks: %d\n", stat.nproc); printf("Number of cores online: %d\n", stat.ncpu); printf("Scheduler quantum: %d usec\n", stat.quantum_usec); + printf("CPU is %d%% online\n", online_percent); printf("-------------------------------\n"); /* -- cgit v1.2.3