summaryrefslogtreecommitdiffstats
path: root/openbsd/OpenBSDProcessList.c
diff options
context:
space:
mode:
authorStuart Henderson <stu@spacehopper.org>2021-03-27 13:26:26 +0000
committerChristian Göttsche <cgzones@googlemail.com>2021-04-18 16:58:20 +0200
commitfeec16cbb53dabc6a52ef2f69a6a13798be82617 (patch)
tree2b13a817bae18fd71c6e06cb532bd1fdc33e3103 /openbsd/OpenBSDProcessList.c
parentd63394b5f6f251228b38e7f5f319ebad9a168e96 (diff)
don't include offline CPUs in summary for OpenBSD
By default, OpenBSD disables SMT (hyperthreading) cpu pseudo-cores. This can be changed at runtime by setting the hw.smt sysctl so they may become active later, therefore they are still present in cpu stat structures but are marked as offline. As done with native top(1), this drops them from the cpu summary graphs.
Diffstat (limited to 'openbsd/OpenBSDProcessList.c')
-rw-r--r--openbsd/OpenBSDProcessList.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index fbe7c103..1c6c0e2f 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -37,9 +37,12 @@ static int pageSize;
static int pageSizeKB;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
- const int mib[] = { CTL_HW, HW_NCPU };
+ const int nmib[] = { CTL_HW, HW_NCPU };
+ const int mib[] = { CTL_HW, HW_NCPUONLINE };
const int fmib[] = { CTL_KERN, KERN_FSCALE };
int r;
+ unsigned int cpu_index_c = 0;
+ unsigned int ncpu;
size_t size;
char errbuf[_POSIX2_LINE_MAX];
@@ -54,6 +57,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
}
opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData));
+ size = sizeof(int);
+ r = sysctl(nmib, 2, &ncpu, &size, NULL, 0);
+ if (r < 0) {
+ ncpu = pl->cpuCount;
+ }
+
size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) {
CRT_fatalError("fscale sysctl call failed");
@@ -76,6 +85,23 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
opl->cpuSpeed = -1;
+ for (unsigned int i = 0; i < ncpu; i++) {
+ const int ncmib[] = { CTL_KERN, KERN_CPUSTATS, i };
+ struct cpustats cpu_stats;
+
+ size = sizeof(cpu_stats);
+ if (sysctl(ncmib, 3, &cpu_stats, &size, NULL, 0) < 0) {
+ CRT_fatalError("ncmib sysctl call failed");
+ }
+ if (cpu_stats.cs_flags & CPUSTATS_ONLINE) {
+ opl->cpus[cpu_index_c].cpuIndex = i;
+ cpu_index_c++;
+ }
+
+ if (cpu_index_c == pl->cpuCount)
+ break;
+ }
+
return pl;
}
@@ -340,7 +366,7 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) {
u_int64_t avg[CPUSTATES] = {0};
for (unsigned int i = 0; i < this->super.cpuCount; i++) {
- getKernelCPUTimes(i, kernelTimes);
+ getKernelCPUTimes(this->cpus[i].cpuIndex, kernelTimes);
CPUData* cpu = this->cpus + i + 1;
kernelCPUTimesToHtop(kernelTimes, cpu);