From 126fcaef25f878c22fff128c3709af547303fe75 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 15 Dec 2021 13:29:32 +0100 Subject: [PATCH] add CPU spin support on OpenBSD (#471) * add CPU spin support on OpenBSD * use consistent ifdefs --- src/print_cpu_usage.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index 712bbff..bc4b784 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -43,6 +43,9 @@ struct cpu_usage { int nice; int system; int idle; +#if defined(__OpenBSD__) + int spin; +#endif int total; }; @@ -151,7 +154,12 @@ void print_cpu_usage(cpu_usage_ctx_t *ctx) { curr_all.nice = cp_time[CP_NICE]; curr_all.system = cp_time[CP_SYS]; curr_all.idle = cp_time[CP_IDLE]; +#if defined(__OpenBSD__) + curr_all.spin = cp_time[CP_SPIN]; + curr_all.total = curr_all.user + curr_all.nice + curr_all.system + curr_all.idle + curr_all.spin; +#else curr_all.total = curr_all.user + curr_all.nice + curr_all.system + curr_all.idle; +#endif diff_idle = curr_all.idle - prev_all.idle; diff_total = curr_all.total - prev_all.total; diff_usage = (diff_total ? (1000 * (diff_total - diff_idle) / diff_total + 5) / 10 : 0);