summaryrefslogtreecommitdiffstats
path: root/netbsd
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-05-02 16:56:18 +1000
committerNathan Scott <nathans@redhat.com>2023-05-08 13:06:38 +1000
commit72235d8e098d9d79029dca65122605741e1aafad (patch)
tree96593b8bd9dc95dc5ab321bd363d36351cbd0a99 /netbsd
parent0bdade1b6cb40c5bd374a93ac0489058a7421bb5 (diff)
Adapt platform code for the new Machine base class
Move host-centric data to new derived <Platform>Machine classes, separate from process-list-centric data.
Diffstat (limited to 'netbsd')
-rw-r--r--netbsd/NetBSDMachine.c282
-rw-r--r--netbsd/NetBSDMachine.h54
-rw-r--r--netbsd/NetBSDProcessList.c280
-rw-r--r--netbsd/NetBSDProcessList.h40
-rw-r--r--netbsd/Platform.c7
5 files changed, 356 insertions, 307 deletions
diff --git a/netbsd/NetBSDMachine.c b/netbsd/NetBSDMachine.c
new file mode 100644
index 00000000..1e2a0a13
--- /dev/null
+++ b/netbsd/NetBSDMachine.c
@@ -0,0 +1,282 @@
+/*
+htop - NetBSDMachine.c
+(C) 2014 Hisham H. Muhammad
+(C) 2015 Michael McConville
+(C) 2021 Santhosh Raju
+(C) 2021 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "netbsd/NetBSDMachine.h"
+
+#include <kvm.h>
+#include <math.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/sched.h>
+#include <sys/swap.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <uvm/uvm_extern.h>
+
+#include "CRT.h"
+#include "Machine.h"
+#include "Macros.h"
+#include "Object.h"
+#include "Settings.h"
+#include "XUtils.h"
+
+
+static const struct {
+ const char* name;
+ long int scale;
+} freqSysctls[] = {
+ { "machdep.est.frequency.current", 1 },
+ { "machdep.powernow.frequency.current", 1 },
+ { "machdep.intrepid.frequency.current", 1 },
+ { "machdep.loongson.frequency.current", 1 },
+ { "machdep.cpu.frequency.current", 1 },
+ { "machdep.frequency.current", 1 },
+ { "machdep.tsc_freq", 1000000 },
+};
+
+static void NetBSDMachine_updateCPUcount(NetBSDMachine* this) {
+ Machine* super = &this->super;
+
+ // Definitions for sysctl(3), cf. https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#813
+ const int mib_ncpu_existing[] = { CTL_HW, HW_NCPU }; // Number of existing CPUs
+ const int mib_ncpu_online[] = { CTL_HW, HW_NCPUONLINE }; // Number of online/active CPUs
+
+ int r;
+ unsigned int value;
+ size_t size;
+
+ bool change = false;
+
+ // Query the number of active/online CPUs.
+ size = sizeof(value);
+ r = sysctl(mib_ncpu_online, 2, &value, &size, NULL, 0);
+ if (r < 0 || value < 1) {
+ value = 1;
+ }
+
+ if (value != super->activeCPUs) {
+ super->activeCPUs = value;
+ change = true;
+ }
+
+ // Query the total number of CPUs.
+ size = sizeof(value);
+ r = sysctl(mib_ncpu_existing, 2, &value, &size, NULL, 0);
+ if (r < 0 || value < 1) {
+ value = super->activeCPUs;
+ }
+
+ if (value != super->existingCPUs) {
+ opl->cpuData = xReallocArray(this->cpuData, value + 1, sizeof(CPUData));
+ super->existingCPUs = value;
+ change = true;
+ }
+
+ // Reset CPU stats when number of online/existing CPU cores changed
+ if (change) {
+ CPUData* dAvg = &this->cpuData[0];
+ memset(dAvg, '\0', sizeof(CPUData));
+ dAvg->totalTime = 1;
+ dAvg->totalPeriod = 1;
+
+ for (unsigned int i = 0; i < super->existingCPUs; i++) {
+ CPUData* d = &this->cpuData[i + 1];
+ memset(d, '\0', sizeof(CPUData));
+ d->totalTime = 1;
+ d->totalPeriod = 1;
+ }
+ }
+}
+
+Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
+ const int fmib[] = { CTL_KERN, KERN_FSCALE };
+ size_t size;
+ char errbuf[_POSIX2_LINE_MAX];
+
+ NetBSDMachine* this = xCalloc(1, sizeof(NetBSDMachine));
+ Machine* super = &this->super;
+ Machine_init(super, usersTable, userId);
+
+ NetBSDMachine_updateCPUcount(this);
+
+ size = sizeof(this->fscale);
+ if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0) {
+ CRT_fatalError("fscale sysctl call failed");
+ }
+
+ if ((this->pageSize = sysconf(_SC_PAGESIZE)) == -1)
+ CRT_fatalError("pagesize sysconf call failed");
+ this->pageSizeKB = this->pageSize / ONE_K;
+
+ this->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
+ if (this->kd == NULL) {
+ CRT_fatalError("kvm_openfiles() failed");
+ }
+
+ return this;
+}
+
+void Machine_delete(Machine* super) {
+ NetBSDMachine* this = (NetBSDProcessList*) super;
+
+ Machine_done(super);
+
+ if (this->kd) {
+ kvm_close(this->kd);
+ }
+ free(this->cpuData);
+ free(this);
+}
+
+static void NetBSDMachine_scanMemoryInfo(NetBSDMachine* this) {
+ Machine* super = &this->super;
+
+ static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
+ struct uvmexp_sysctl uvmexp;
+ size_t size_uvmexp = sizeof(uvmexp);
+
+ if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) {
+ CRT_fatalError("uvmexp sysctl call failed");
+ }
+
+ super->totalMem = uvmexp.npages * this->pageSizeKB;
+ super->buffersMem = 0;
+ super->cachedMem = (uvmexp.filepages + uvmexp.execpages) * this->pageSizeKB;
+ super->usedMem = (uvmexp.active + uvmexp.wired) * this->pageSizeKB;
+ super->totalSwap = uvmexp.swpages * this->pageSizeKB;
+ super->usedSwap = uvmexp.swpginuse * this->pageSizeKB;
+}
+
+static void getKernelCPUTimes(int cpuId, u_int64_t* times) {
+ const int mib[] = { CTL_KERN, KERN_CP_TIME, cpuId };
+ size_t length = sizeof(*times) * CPUSTATES;
+ if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || length != sizeof(*times) * CPUSTATES) {
+ CRT_fatalError("sysctl kern.cp_time2 failed");
+ }
+}
+
+static void kernelCPUTimesToHtop(const u_int64_t* times, CPUData* cpu) {
+ unsigned long long totalTime = 0;
+ for (int i = 0; i < CPUSTATES; i++) {
+ totalTime += times[i];
+ }
+
+ unsigned long long sysAllTime = times[CP_INTR] + times[CP_SYS];
+
+ cpu->totalPeriod = saturatingSub(totalTime, cpu->totalTime);
+ cpu->userPeriod = saturatingSub(times[CP_USER], cpu->userTime);
+ cpu->nicePeriod = saturatingSub(times[CP_NICE], cpu->niceTime);
+ cpu->sysPeriod = saturatingSub(times[CP_SYS], cpu->sysTime);
+ cpu->sysAllPeriod = saturatingSub(sysAllTime, cpu->sysAllTime);
+ cpu->intrPeriod = saturatingSub(times[CP_INTR], cpu->intrTime);
+ cpu->idlePeriod = saturatingSub(times[CP_IDLE], cpu->idleTime);
+
+ cpu->totalTime = totalTime;
+ cpu->userTime = times[CP_USER];
+ cpu->niceTime = times[CP_NICE];
+ cpu->sysTime = times[CP_SYS];
+ cpu->sysAllTime = sysAllTime;
+ cpu->intrTime = times[CP_INTR];
+ cpu->idleTime = times[CP_IDLE];
+}
+
+static void NetBSDMachine_scanCPUTime(NetBSDMachine* this) {
+ const Machine* super = &this->super;
+
+ u_int64_t kernelTimes[CPUSTATES] = {0};
+ u_int64_t avg[CPUSTATES] = {0};
+
+ for (unsigned int i = 0; i < super->existingCPUs; i++) {
+ getKernelCPUTimes(i, kernelTimes);
+ CPUData* cpu = &this->cpuData[i + 1];
+ kernelCPUTimesToHtop(kernelTimes, cpu);
+
+ avg[CP_USER] += cpu->userTime;
+ avg[CP_NICE] += cpu->niceTime;
+ avg[CP_SYS] += cpu->sysTime;
+ avg[CP_INTR] += cpu->intrTime;
+ avg[CP_IDLE] += cpu->idleTime;
+ }
+
+ for (int i = 0; i < CPUSTATES; i++) {
+ avg[i] /= super->activeCPUs;
+ }
+
+ kernelCPUTimesToHtop(avg, &this->cpuData[0]);
+}
+
+static void NetBSDMachine_scanCPUFrequency(NetBSDMachine* this) {
+ const Machine* super = &this->super;
+ unsigned int cpus = super->existingCPUs;
+ bool match = false;
+ char name[64];
+ long int freq = 0;
+ size_t freqSize;
+
+ for (unsigned int i = 0; i < cpus; i++) {
+ this->cpuData[i + 1].frequency = NAN;
+ }
+
+ /* newer hardware supports per-core frequency, for e.g. ARM big.LITTLE */
+ for (unsigned int i = 0; i < cpus; i++) {
+ xSnprintf(name, sizeof(name), "machdep.cpufreq.cpu%u.current", i);
+ freqSize = sizeof(freq);
+ if (sysctlbyname(name, &freq, &freqSize, NULL, 0) != -1) {
+ this->cpuData[i + 1].frequency = freq; /* already in MHz */
+ match = true;
+ }
+ }
+
+ if (match) {
+ return;
+ }
+
+ /*
+ * Iterate through legacy sysctl nodes for single-core frequency until
+ * we find a match...
+ */
+ for (size_t i = 0; i < ARRAYSIZE(freqSysctls); i++) {
+ freqSize = sizeof(freq);
+ if (sysctlbyname(freqSysctls[i].name, &freq, &freqSize, NULL, 0) != -1) {
+ freq /= freqSysctls[i].scale; /* scale to MHz */
+ match = true;
+ break;
+ }
+ }
+
+ if (match) {
+ for (unsigned int i = 0; i < cpus; i++) {
+ this->cpuData[i + 1].frequency = freq;
+ }
+ }
+}
+
+void Machine_scan(Machine* super) {
+ NetBSDMachine* this = (NetBSDMachine*) super;
+
+ NetBSDProcessList_scanMemoryInfo(this);
+ NetBSDProcessList_scanCPUTime(this);
+
+ if (super->settings->showCPUFrequency) {
+ NetBSDProcessList_scanCPUFrequency(npl);
+ }
+}
+
+bool Machine_isCPUonline(const Machine* host, unsigned int id) {
+ assert(id < host->existingCPUs);
+
+ // TODO: Support detecting online / offline CPUs.
+ return true;
+}
diff --git a/netbsd/NetBSDMachine.h b/netbsd/NetBSDMachine.h
new file mode 100644
index 00000000..57070d67
--- /dev/null
+++ b/netbsd/NetBSDMachine.h
@@ -0,0 +1,54 @@
+#ifndef HEADER_NetBSDMachine
+#define HEADER_NetBSDMachine
+/*
+htop - NetBSDMachine.h
+(C) 2014 Hisham H. Muhammad
+(C) 2015 Michael McConville
+(C) 2021 Santhosh Raju
+(C) 2021 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include <kvm.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#include "Machine.h"
+#include "ProcessList.h"
+
+
+typedef struct CPUData_ {
+ unsigned long long int totalTime;
+ unsigned long long int userTime;
+ unsigned long long int niceTime;
+ unsigned long long int sysTime;
+ unsigned long long int sysAllTime;
+ unsigned long long int spinTime;
+ unsigned long long int intrTime;
+ unsigned long long int idleTime;
+
+ unsigned long long int totalPeriod;
+ unsigned long long int userPeriod;
+ unsigned long long int nicePeriod;
+ unsigned long long int sysPeriod;
+ unsigned long long int sysAllPeriod;
+ unsigned long long int spinPeriod;
+ unsigned long long int intrPeriod;
+ unsigned long long int idlePeriod;
+
+ double frequency;
+} CPUData;
+
+typedef struct NetBSDProcessList_ {
+ ProcessList super;
+ kvm_t* kd;
+
+ long fscale;
+ int pageSize;
+ int pageSizeKB;
+
+ CPUData* cpuData;
+} NetBSDProcessList;
+
+#endif
diff --git a/netbsd/NetBSDProcessList.c b/netbsd/NetBSDProcessList.c
index b7b6915a..9e5a9be4 100644
--- a/netbsd/NetBSDProcessList.c
+++ b/netbsd/NetBSDProcessList.c
@@ -20,7 +20,6 @@ in the source distribution for its full text.
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/sched.h>
-#include <sys/swap.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <uvm/uvm_extern.h>
@@ -32,137 +31,23 @@ in the source distribution for its full text.
#include "ProcessList.h"
#include "Settings.h"
#include "XUtils.h"
+#include "netbsd/NetBSDMachine.h"
#include "netbsd/NetBSDProcess.h"
-static long fscale;
-static int pageSize;
-static int pageSizeKB;
-
-static const struct {
- const char* name;
- long int scale;
-} freqSysctls[] = {
- { "machdep.est.frequency.current", 1 },
- { "machdep.powernow.frequency.current", 1 },
- { "machdep.intrepid.frequency.current", 1 },
- { "machdep.loongson.frequency.current", 1 },
- { "machdep.cpu.frequency.current", 1 },
- { "machdep.frequency.current", 1 },
- { "machdep.tsc_freq", 1000000 },
-};
-
-static void NetBSDProcessList_updateCPUcount(ProcessList* super) {
- NetBSDProcessList* opl = (NetBSDProcessList*) super;
- Machine* host = super->host;
-
- // Definitions for sysctl(3), cf. https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#813
- const int mib_ncpu_existing[] = { CTL_HW, HW_NCPU }; // Number of existing CPUs
- const int mib_ncpu_online[] = { CTL_HW, HW_NCPUONLINE }; // Number of online/active CPUs
-
- int r;
- unsigned int value;
- size_t size;
-
- bool change = false;
-
- // Query the number of active/online CPUs.
- size = sizeof(value);
- r = sysctl(mib_ncpu_online, 2, &value, &size, NULL, 0);
- if (r < 0 || value < 1) {
- value = 1;
- }
-
- if (value != host->activeCPUs) {
- host->activeCPUs = value;
- change = true;
- }
-
- // Query the total number of CPUs.
- size = sizeof(value);
- r = sysctl(mib_ncpu_existing, 2, &value, &size, NULL, 0);
- if (r < 0 || value < 1) {
- value = host->activeCPUs;
- }
-
- if (value != host->existingCPUs) {
- opl->cpuData = xReallocArray(opl->cpuData, value + 1, sizeof(CPUData));
- host->existingCPUs = value;
- change = true;
- }
-
- // Reset CPU stats when number of online/existing CPU cores changed
- if (change) {
- CPUData* dAvg = &opl->cpuData[0];
- memset(dAvg, '\0', sizeof(CPUData));
- dAvg->totalTime = 1;
- dAvg->totalPeriod = 1;
-
- for (unsigned int i = 0; i < host->existingCPUs; i++) {
- CPUData* d = &opl->cpuData[i + 1];
- memset(d, '\0', sizeof(CPUData));
- d->totalTime = 1;
- d->totalPeriod = 1;
- }
- }
-}
-
ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) {
- const int fmib[] = { CTL_KERN, KERN_FSCALE };
- size_t size;
- char errbuf[_POSIX2_LINE_MAX];
-
- NetBSDProcessList* npl = xCalloc(1, sizeof(NetBSDProcessList));
- ProcessList* pl = (ProcessList*) npl;
- ProcessList_init(pl, Class(NetBSDProcess), host, pidMatchList);
+ NetBSDProcessList* this = xCalloc(1, sizeof(NetBSDProcessList));
+ ProcessList* super = (ProcessList*) this;
- NetBSDProcessList_updateCPUcount(pl);
-
- size = sizeof(fscale);
- if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) {
- CRT_fatalError("fscale sysctl call failed");
- }
+ ProcessList_init(super, Class(NetBSDProcess), host, pidMatchList);
- if ((pageSize = sysconf(_SC_PAGESIZE)) == -1)
- CRT_fatalError("pagesize sysconf call failed");
- pageSizeKB = pageSize / ONE_K;
-
- npl->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
- if (npl->kd == NULL) {
- CRT_fatalError("kvm_openfiles() failed");
- }
-
- return pl;
+ return super;
}
void ProcessList_delete(ProcessList* this) {
NetBSDProcessList* npl = (NetBSDProcessList*) this;
-
- if (npl->kd) {
- kvm_close(npl->kd);
- }
-
- free(npl->cpuData);
-
ProcessList_done(this);
- free(this);
-}
-
-static void NetBSDProcessList_scanMemoryInfo(Machine* host) {
- static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
- struct uvmexp_sysctl uvmexp;
- size_t size_uvmexp = sizeof(uvmexp);
-
- if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) {
- CRT_fatalError("uvmexp sysctl call failed");
- }
-
- host->totalMem = uvmexp.npages * pageSizeKB;
- host->buffersMem = 0;
- host->cachedMem = (uvmexp.filepages + uvmexp.execpages) * pageSizeKB;
- host->usedMem = (uvmexp.active + uvmexp.wired) * pageSizeKB;
- host->totalSwap = uvmexp.swpages * pageSizeKB;
- host->usedSwap = uvmexp.swpginuse * pageSizeKB;
+ free(npl);
}
static void NetBSDProcessList_updateExe(const struct kinfo_proc2* kproc, Process* proc) {
@@ -255,21 +140,22 @@ static void NetBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_pr
/*
* Borrowed with modifications from NetBSD's top(1).
*/
-static double getpcpu(const struct kinfo_proc2* kp) {
- if (fscale == 0)
+static double getpcpu(const NetBSDMachine* nhost, const struct kinfo_proc2* kp) {
+ if (nhost->fscale == 0)
return 0.0;
- return 100.0 * (double)kp->p_pctcpu / fscale;
+ return 100.0 * (double)kp->p_pctcpu / nhost->fscale;
}
static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
const Machine* host = this->super.host;
+ const NetBSDMachine* nhost = (const NetBSDMachine*) host;
const Settings* settings = host->settings;
bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads;
int count = 0;
- const struct kinfo_proc2* kprocs = kvm_getproc2(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &count);
+ const struct kinfo_proc2* kprocs = kvm_getproc2(nhost->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &count);
for (int i = 0; i < count; i++) {
const struct kinfo_proc2* kproc = &kprocs[i];
@@ -302,10 +188,10 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
}
NetBSDProcessList_updateExe(kproc, proc);
- NetBSDProcessList_updateProcessName(this->kd, kproc, proc);
+ NetBSDProcessList_updateProcessName(nhost->kd, kproc, proc);
} else {
if (settings->updateProcessNames) {
- NetBSDProcessList_updateProcessName(this->kd, kproc, proc);
+ NetBSDProcessList_updateProcessName(nhost->kd, kproc, proc);
}
}
@@ -321,8 +207,8 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
proc->m_virt = kproc->p_vm_vsize;
proc->m_resident = kproc->p_vm_rssize;
- proc->percent_mem = (proc->m_resident * pageSizeKB) / (double)(host->totalMem) * 100.0;
- proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, host->activeCPUs * 100.0);
+ proc->percent_mem = (proc->m_resident * nhost->pageSizeKB) / (double)(host->totalMem) * 100.0;
+ proc->percent_cpu = CLAMP(getpcpu(nhost, kproc), 0.0, host->activeCPUs * 100.0);
Process_updateCPUFieldWidths(proc->percent_cpu);
proc->nlwp = kproc->p_nlwps;
@@ -334,7 +220,7 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
proc->majflt = kproc->p_uru_majflt;
int nlwps = 0;
- const struct kinfo_lwp* klwps = kvm_getlwps(this->kd, kproc->p_pid, kproc->p_paddr, sizeof(struct kinfo_lwp), &nlwps);
+ const struct kinfo_lwp* klwps = kvm_getlwps(nhost->kd, kproc->p_pid, kproc->p_paddr, sizeof(struct kinfo_lwp), &nlwps);
/* TODO: According to the link below, SDYING should be a regarded state */
/* Taken from: https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/sys/proc.h */
@@ -379,140 +265,8 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
}
}
-static void getKernelCPUTimes(int cpuId, u_int64_t* times) {
- const int mib[] = { CTL_KERN, KERN_CP_TIME, cpuId };
- size_t length = sizeof(*times) * CPUSTATES;
- if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || length != sizeof(*times) * CPUSTATES) {
- CRT_fatalError("sysctl kern.cp_time2 failed");
- }
-}
-
-static void kernelCPUTimesToHtop(const u_int64_t* times, CPUData* cpu) {
- unsigned long long totalTime = 0;
- for (int i = 0; i < CPUSTATES; i++) {
- totalTime += times[i];
- }
-
- unsigned long long sysAllTime = times[CP_INTR] + times[CP_SYS];
-
- cpu->totalPeriod = saturatingSub(totalTime, cpu->totalTime);
- cpu->userPeriod = saturatingSub(times[CP_USER], cpu->userTime);
- cpu->nicePeriod = saturatingSub(times[CP_NICE], cpu->niceTime);
- cpu->sysPeriod = saturatingSub(times[CP_SYS], cpu->sysTime);
- cpu->sysAllPeriod = saturatingSub(sysAllTime, cpu->sysAllTime);
- cpu->intrPeriod = saturatingSub(times[CP_INTR], cpu->intrTime);
- cpu->idlePeriod = saturatingSub(times[CP_IDLE], cpu->idleTime);
-
- cpu->totalTime = totalTime;
- cpu->userTime = times[CP_USER];
- cpu->niceTime = times[CP_NICE];
- cpu->sysTime = times[CP_SYS];
- cpu->sysAllTime = sysAllTime;
- cpu->intrTime = times[CP_INTR];
- cpu->idleTime = times[CP_IDLE];
-}
-
-static void NetBSDProcessList_scanCPUTime(NetBSDProcessList* this) {
- const Machine* host = this->super.host;
- u_int64_t kernelTimes[CPUSTATES] = {0};
- u_int64_t avg[CPUSTATES] = {0};
-
- for (unsigned int i = 0; i < host->existingCPUs; i++) {
- getKernelCPUTimes(i, kernelTimes);
- CPUData* cpu = &this->cpuData[i + 1];
- kernelCPUTimesToHtop(kernelTimes, cpu);
-
- avg[CP_USER] += cpu->userTime;
- avg[CP_NICE] += cpu->niceTime;
- avg[CP_SYS] += cpu->sysTime;
- avg[CP_INTR] += cpu->intrTime;
- avg[CP_IDLE] += cpu->idleTime;
- }
-
- for (int i = 0; i < CPUSTATES; i++) {
- avg[i] /= host->activeCPUs;
- }
-
- kernelCPUTimesToHtop(avg, &this->cpuData[0]);
-}
-
-static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
- const Machine* host = this->super.host;
- unsigned int cpus = host->existingCPUs;
- bool match = false;
- char name[64];
- long int freq = 0;
- size_t freqSize;
-
- for (unsigned int i = 0; i < cpus; i++) {
- this->cpuData[i + 1].frequency = NAN;
- }
-
- /* newer hardware supports per-core frequency, for e.g. ARM big.LITTLE */
- for (unsigned int i = 0; i < cpus; i++) {
- xSnprintf(name, sizeof(name), "machdep.cpufreq.cpu%u.current", i);
- freqSize = sizeof(freq);
- if (sysctlbyname(name, &freq, &freqSize, NULL, 0) != -1) {
- this->cpuData[i + 1].frequency = freq; /* already in MHz */
- match = true;
- }
- }
-
- if (match) {
- return;
- }
-
- /*
- * Iterate through legacy sysctl nodes for single-core frequency until
- * we find a match...
- */
- for (size_t i = 0; i < ARRAYSIZE(freqSysctls); i++) {
- freqSize = sizeof(freq);
- if (sysctlbyname(freqSysctls[i].name, &freq, &freqSize, NULL, 0) != -1) {
- freq /= freqSysctls[i].scale; /* scale to MHz */
- match = true;
- break;
- }
- }
-
- if (match) {
- for (unsigned int i = 0; i < cpus; i++) {
- this->cpuData[i + 1].frequency = freq;
- }
- }
-}
-
-void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
+void ProcessList_goThroughEntries(ProcessList* super) {
NetBSDProcessList* npl = (NetBSDProcessList*) super;
- NetBSDProcessList_scanMemoryInfo(super->host);
- NetBSDProcessList_scanCPUTime(npl);
-
- if (super->settings->showCPUFrequency) {
- NetBSDProcessList_scanCPUFrequency(npl);
- }
-
- // in pause mode only gather global data for meters (CPU/memory/...)
- if (pauseProcessUpdate) {
- return;
- }
-
NetBSDProcessList_scanProcs(npl);
}
-
-Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
- Machine* this = xCalloc(1, sizeof(Machine));
- Machine_init(this, usersTable, userId);
- return this;
-}
-
-void Machine_delete(Machine* host) {
- free(host);
-}
-
-bool Machine_isCPUonline(const Machine* host, unsigned int id) {
- assert(id < host->existingCPUs);
-
- // TODO: Support detecting online / offline CPUs.
- return true;
-}
diff --git a/netbsd/NetBSDProcessList.h b/netbsd/NetBSDProcessList.h
index 0fe18b03..362d84fc 100644
--- a/netbsd/NetBSDProcessList.h
+++ b/netbsd/NetBSDProcessList.h
@@ -10,55 +10,15 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
-#include <kvm.h>
#include <stdbool.h>
#include <sys/types.h>
#include "Hashtable.h"
#include "ProcessList.h"
-#include "UsersTable.h"
-typedef struct CPUData_ {
- unsigned long long int totalTime;
- unsigned long long int userTime;
- unsigned long long int niceTime;
- unsigned long long int sysTime;
- unsigned long long int sysAllTime;
- unsigned long long int spinTime;
- unsigned long long int intrTime;
- unsigned long long int idleTime;
-
- unsigned long long int totalPeriod;
- unsigned long long int userPeriod;
- unsigned long long int nicePeriod;
- unsigned long long int sysPeriod;
- unsigned long long int sysAllPeriod;
- unsigned long long int spinPeriod;
- unsigned long long int intrPeriod;
- unsigned long long int idlePeriod;
-
- double frequency;
-} CPUData;
-
typedef struct NetBSDProcessList_ {
ProcessList super;
- kvm_t* kd;
-
- CPUData* cpuData;
} NetBSDProcessList;
-
-ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList);
-
-void ProcessList_delete(ProcessList* this);
-
-void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate);
-
-Machine* Machine_new(UsersTable* usersTable, uid_t userId);
-
-bool Machine_isCPUonline(const Machine* host, unsigned int id);
-
-void Machine_delete(Machine* host);
-
#endif
diff --git a/netbsd/Platform.c b/netbsd/Platform.c
index ea81a26a..1d6509ff 100644
--- a/netbsd/Platform.c
+++ b/netbsd/Platform.c
@@ -45,7 +45,6 @@ in the source distribution for its full text.
#include "MemoryMeter.h"
#include "MemorySwapMeter.h"
#include "Meter.h"
-#include "ProcessList.h"
#include "Settings.h"
#include "SignalsPanel.h"
#include "SwapMeter.h"
@@ -54,8 +53,8 @@ in the source distribution for its full text.
#include "UptimeMeter.h"
#include "XUtils.h"
#include "generic/fdstat_sysctl.h"
+#include "netbsd/NetBSDMachine.h"
#include "netbsd/NetBSDProcess.h"
-#include "netbsd/NetBSDProcessList.h"
/*
* The older proplib APIs will be deprecated in NetBSD 10, but we still
@@ -238,8 +237,8 @@ int Platform_getMaxPid(void) {
double Platform_setCPUValues(Meter* this, int cpu) {
const Machine* host = this->host;
- const NetBSDProcessList* npl = (const NetBSDProcessList*) host->pl;
- const CPUData* cpuData = &npl->cpuData[cpu];
+ const NetBSDMachine* nhost = (const NetBSDMachine*) host;
+ const CPUData* cpuData = &nhost->cpuData[cpu];
double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;
double totalPercent;
double* v = this->values;

© 2014-2024 Faster IT GmbH | imprint | privacy policy