aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2021-09-21 08:35:19 +0200
committerDaniel Lange <DLange@git.local>2021-09-21 08:35:19 +0200
commit69f439eff387a6ecb52734e400b297a3c85f2285 (patch)
tree2a988b7868b749654796183ba70b4272965da1bf /openbsd
parentc55320e9e2a8916e911bcd39ab37b79e3a7d03b2 (diff)
downloaddebian_htop-upstream/3.1.0.tar.gz
debian_htop-upstream/3.1.0.tar.bz2
debian_htop-upstream/3.1.0.zip
New upstream version 3.1.0upstream/3.1.0
Diffstat (limited to 'openbsd')
-rw-r--r--openbsd/OpenBSDProcess.c39
-rw-r--r--openbsd/OpenBSDProcess.h9
-rw-r--r--openbsd/OpenBSDProcessList.c240
-rw-r--r--openbsd/OpenBSDProcessList.h9
-rw-r--r--openbsd/Platform.c57
-rw-r--r--openbsd/Platform.h54
6 files changed, 309 insertions, 99 deletions
diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c
index 00aea63..90994a7 100644
--- a/openbsd/OpenBSDProcess.c
+++ b/openbsd/OpenBSDProcess.c
@@ -6,7 +6,7 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
-#include "OpenBSDProcess.h"
+#include "openbsd/OpenBSDProcess.h"
#include <stdlib.h>
@@ -63,9 +63,9 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.flags = 0,
.pidColumn = true,
},
- [TTY_NR] = {
- .name = "TTY_NR",
- .title = " TTY ",
+ [TTY] = {
+ .name = "TTY",
+ .title = "TTY ",
.description = "Controlling terminal",
.flags = 0,
},
@@ -81,12 +81,14 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.title = " MINFLT ",
.description = "Number of minor faults which have not required loading a memory page from disk",
.flags = 0,
+ .defaultSortDesc = true,
},
[MAJFLT] = {
.name = "MAJFLT",
.title = " MAJFLT ",
.description = "Number of major faults which have required loading a memory page from disk",
.flags = 0,
+ .defaultSortDesc = true,
},
[PRIORITY] = {
.name = "PRIORITY",
@@ -106,6 +108,12 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.description = "Time the process was started",
.flags = 0,
},
+ [ELAPSED] = {
+ .name = "ELAPSED",
+ .title = "ELAPSED ",
+ .description = "Time since the process was started",
+ .flags = 0,
+ },
[PROCESSOR] = {
.name = "PROCESSOR",
.title = "CPU ",
@@ -117,12 +125,14 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.title = " VIRT ",
.description = "Total program size in virtual memory",
.flags = 0,
+ .defaultSortDesc = true,
},
[M_RESIDENT] = {
.name = "M_RESIDENT",
.title = " RES ",
.description = "Resident set size, size of the text and data sections, plus stack usage",
.flags = 0,
+ .defaultSortDesc = true,
},
[ST_UID] = {
.name = "ST_UID",
@@ -135,18 +145,21 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.title = "CPU% ",
.description = "Percentage of the CPU time the process used in the last sampling",
.flags = 0,
+ .defaultSortDesc = true,
},
[PERCENT_NORM_CPU] = {
.name = "PERCENT_NORM_CPU",
.title = "NCPU%",
.description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)",
.flags = 0,
+ .defaultSortDesc = true,
},
[PERCENT_MEM] = {
.name = "PERCENT_MEM",
.title = "MEM% ",
.description = "Percentage of the memory the process is using, based on resident memory size",
.flags = 0,
+ .defaultSortDesc = true,
},
[USER] = {
.name = "USER",
@@ -159,6 +172,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.title = " TIME+ ",
.description = "Total time the process has spent in user and system time",
.flags = 0,
+ .defaultSortDesc = true,
},
[NLWP] = {
.name = "NLWP",
@@ -173,6 +187,19 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
.flags = 0,
.pidColumn = true,
},
+ [PROC_COMM] = {
+ .name = "COMM",
+ .title = "COMM ",
+ .description = "comm string of the process",
+ .flags = 0,
+ },
+ [CWD] = {
+ .name = "CWD",
+ .title = "CWD ",
+ .description = "The current working directory of the process",
+ .flags = PROCESS_FLAG_CWD,
+ },
+
};
Process* OpenBSDProcess_new(const Settings* settings) {
@@ -226,7 +253,3 @@ const ProcessClass OpenBSDProcess_class = {
.writeField = OpenBSDProcess_writeField,
.compareByKey = OpenBSDProcess_compareByKey
};
-
-bool Process_isThread(const Process* this) {
- return Process_isKernelThread(this) || Process_isUserlandThread(this);
-}
diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h
index 6aab29a..ce078a0 100644
--- a/openbsd/OpenBSDProcess.h
+++ b/openbsd/OpenBSDProcess.h
@@ -17,11 +17,10 @@ in the source distribution for its full text.
typedef struct OpenBSDProcess_ {
Process super;
-} OpenBSDProcess;
-
-#define Process_isKernelThread(_process) (_process->pgrp == 0)
-#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
+ /* 'Kernel virtual addr of u-area' to detect main threads */
+ uint64_t addr;
+} OpenBSDProcess;
extern const ProcessClass OpenBSDProcess_class;
@@ -31,6 +30,4 @@ Process* OpenBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast);
-bool Process_isThread(const Process* this);
-
#endif
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index ff5c927..cb47395 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -6,7 +6,7 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
-#include "OpenBSDProcessList.h"
+#include "openbsd/OpenBSDProcessList.h"
#include <kvm.h>
#include <limits.h>
@@ -25,34 +25,85 @@ in the source distribution for its full text.
#include "CRT.h"
#include "Macros.h"
#include "Object.h"
-#include "OpenBSDProcess.h"
#include "Process.h"
#include "ProcessList.h"
#include "Settings.h"
#include "XUtils.h"
+#include "openbsd/OpenBSDProcess.h"
static long fscale;
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 fmib[] = { CTL_KERN, KERN_FSCALE };
+static void OpenBSDProcessList_updateCPUcount(ProcessList* super) {
+ OpenBSDProcessList* opl = (OpenBSDProcessList*) super;
+ const int nmib[] = { CTL_HW, HW_NCPU };
+ const int mib[] = { CTL_HW, HW_NCPUONLINE };
int r;
+ unsigned int value;
+ size_t size;
+ bool change = false;
+
+ size = sizeof(value);
+ r = sysctl(mib, 2, &value, &size, NULL, 0);
+ if (r < 0 || value < 1) {
+ value = 1;
+ }
+
+ if (value != super->activeCPUs) {
+ super->activeCPUs = value;
+ change = true;
+ }
+
+ size = sizeof(value);
+ r = sysctl(nmib, 2, &value, &size, NULL, 0);
+ if (r < 0 || value < 1) {
+ value = super->activeCPUs;
+ }
+
+ if (value != super->existingCPUs) {
+ opl->cpuData = xReallocArray(opl->cpuData, value + 1, sizeof(CPUData));
+ super->existingCPUs = value;
+ change = true;
+ }
+
+ if (change) {
+ CPUData* dAvg = &opl->cpuData[0];
+ memset(dAvg, '\0', sizeof(CPUData));
+ dAvg->totalTime = 1;
+ dAvg->totalPeriod = 1;
+ dAvg->online = true;
+
+ for (unsigned int i = 0; i < super->existingCPUs; i++) {
+ CPUData* d = &opl->cpuData[i + 1];
+ memset(d, '\0', sizeof(CPUData));
+ d->totalTime = 1;
+ d->totalPeriod = 1;
+
+ 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");
+ }
+ d->online = (cpu_stats.cs_flags & CPUSTATS_ONLINE);
+ }
+ }
+}
+
+
+ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId) {
+ const int fmib[] = { CTL_KERN, KERN_FSCALE };
size_t size;
char errbuf[_POSIX2_LINE_MAX];
OpenBSDProcessList* opl = xCalloc(1, sizeof(OpenBSDProcessList));
ProcessList* pl = (ProcessList*) opl;
- ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidMatchList, userId);
+ ProcessList_init(pl, Class(OpenBSDProcess), usersTable, dynamicMeters, dynamicColumns, pidMatchList, userId);
- size = sizeof(pl->cpuCount);
- r = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0);
- if (r < 0 || pl->cpuCount < 1) {
- pl->cpuCount = 1;
- }
- opl->cpus = xCalloc(pl->cpuCount + 1, sizeof(CPUData));
+ OpenBSDProcessList_updateCPUcount(pl);
size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) {
@@ -63,17 +114,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
CRT_fatalError("pagesize sysconf call failed");
pageSizeKB = pageSize / ONE_K;
- for (int i = 0; i <= pl->cpuCount; i++) {
- CPUData* d = opl->cpus + i;
- d->totalTime = 1;
- d->totalPeriod = 1;
- }
-
opl->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (opl->kd == NULL) {
CRT_fatalError("kvm_openfiles() failed");
}
+ opl->cpuSpeed = -1;
+
return pl;
}
@@ -84,7 +131,7 @@ void ProcessList_delete(ProcessList* this) {
kvm_close(opl->kd);
}
- free(opl->cpus);
+ free(opl->cpuData);
ProcessList_done(this);
free(this);
@@ -143,15 +190,37 @@ static void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
}
}
-static char* OpenBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc* kproc, int* basenameEnd) {
+static void OpenBSDProcessList_updateCwd(const struct kinfo_proc* kproc, Process* proc) {
+ const int mib[] = { CTL_KERN, KERN_PROC_CWD, kproc->p_pid };
+ char buffer[2048];
+ size_t size = sizeof(buffer);
+ if (sysctl(mib, 3, buffer, &size, NULL, 0) != 0) {
+ free(proc->procCwd);
+ proc->procCwd = NULL;
+ return;
+ }
+
+ /* Kernel threads return an empty buffer */
+ if (buffer[0] == '\0') {
+ free(proc->procCwd);
+ proc->procCwd = NULL;
+ return;
+ }
+
+ free_and_xStrdup(&proc->procCwd, buffer);
+}
+
+static void OpenBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_proc* kproc, Process* proc) {
+ Process_updateComm(proc, kproc->p_comm);
+
/*
* Like OpenBSD's top(1), we try to fall back to the command name
* (argv[0]) if we fail to construct the full command.
*/
char** arg = kvm_getargv(kd, kproc, 500);
if (arg == NULL || *arg == NULL) {
- *basenameEnd = strlen(kproc->p_comm);
- return xStrdup(kproc->p_comm);
+ Process_updateCmdline(proc, kproc->p_comm, 0, strlen(kproc->p_comm));
+ return;
}
size_t len = 0;
@@ -162,22 +231,30 @@ static char* OpenBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_pr
/* don't use xMalloc here - we want to handle huge argv's gracefully */
char* s;
if ((s = malloc(len)) == NULL) {
- *basenameEnd = strlen(kproc->p_comm);
- return xStrdup(kproc->p_comm);
+ Process_updateCmdline(proc, kproc->p_comm, 0, strlen(kproc->p_comm));
+ return;
}
*s = '\0';
+ int start = 0;
+ int end = 0;
for (int i = 0; arg[i] != NULL; i++) {
size_t n = strlcat(s, arg[i], len);
if (i == 0) {
- *basenameEnd = MINIMUM(n, len - 1);
+ end = MINIMUM(n, len - 1);
+ /* check if cmdline ended earlier, e.g 'kdeinit5: Running...' */
+ for (int j = end; j > 0; j--) {
+ if (arg[0][j] == ' ' && arg[0][j - 1] != '\\') {
+ end = (arg[0][j - 1] == ':') ? (j - 1) : j;
+ }
+ }
}
/* the trailing space should get truncated anyway */
strlcat(s, " ", len);
}
- return s;
+ Process_updateCmdline(proc, s, start, end);
}
/*
@@ -192,79 +269,108 @@ static double getpcpu(const struct kinfo_proc* kp) {
static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
const Settings* settings = this->super.settings;
- bool hideKernelThreads = settings->hideKernelThreads;
- bool hideUserlandThreads = settings->hideUserlandThreads;
+ const bool hideKernelThreads = settings->hideKernelThreads;
+ const bool hideUserlandThreads = settings->hideUserlandThreads;
int count = 0;
- const struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_KTHREAD, 0, sizeof(struct kinfo_proc), &count);
+ const struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_KTHREAD | KERN_PROC_SHOW_THREADS, 0, sizeof(struct kinfo_proc), &count);
for (int i = 0; i < count; i++) {
const struct kinfo_proc* kproc = &kprocs[i];
- bool preExisting = false;
- Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
- //OpenBSDProcess* fp = (OpenBSDProcess*) proc;
+ /* Ignore main threads */
+ if (kproc->p_tid != -1) {
+ Process* containingProcess = ProcessList_findProcess(&this->super, kproc->p_pid);
+ if (containingProcess) {
+ if (((OpenBSDProcess*)containingProcess)->addr == kproc->p_addr)
+ continue;
- proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
+ containingProcess->nlwp++;
+ }
+ }
+
+ bool preExisting = false;
+ Process* proc = ProcessList_getProcess(&this->super, (kproc->p_tid == -1) ? kproc->p_pid : kproc->p_tid, &preExisting, OpenBSDProcess_new);
+ OpenBSDProcess* fp = (OpenBSDProcess*) proc;
if (!preExisting) {
proc->ppid = kproc->p_ppid;
proc->tpgid = kproc->p_tpgid;
proc->tgid = kproc->p_pid;
proc->session = kproc->p_sid;
- proc->tty_nr = kproc->p_tdev;
proc->pgrp = kproc->p__pgid;
- proc->st_uid = kproc->p_uid;
+ proc->isKernelThread = proc->pgrp == 0;
+ proc->isUserlandThread = kproc->p_tid != -1;
proc->starttime_ctime = kproc->p_ustart_sec;
Process_fillStarttimeBuffer(proc);
- proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
ProcessList_add(&this->super, proc);
- proc->comm = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset);
+
+ OpenBSDProcessList_updateProcessName(this->kd, kproc, proc);
+
+ if (settings->flags & PROCESS_FLAG_CWD) {
+ OpenBSDProcessList_updateCwd(kproc, proc);
+ }
+
+ proc->tty_nr = kproc->p_tdev;
+ const char* name = ((dev_t)kproc->p_tdev != NODEV) ? devname(kproc->p_tdev, S_IFCHR) : NULL;
+ if (!name || String_eq(name, "??")) {
+ free(proc->tty_name);
+ proc->tty_name = NULL;
+ } else {
+ free_and_xStrdup(&proc->tty_name, name);
+ }
} else {
if (settings->updateProcessNames) {
- free(proc->comm);
- proc->comm = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset);
+ OpenBSDProcessList_updateProcessName(this->kd, kproc, proc);
}
}
+ fp->addr = kproc->p_addr;
proc->m_virt = kproc->p_vm_dsize * pageSizeKB;
proc->m_resident = kproc->p_vm_rssize * pageSizeKB;
- proc->percent_mem = proc->m_resident / (double)(this->super.totalMem) * 100.0;
- proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount * 100.0);
- //proc->nlwp = kproc->p_numthreads;
+ proc->percent_mem = proc->m_resident / (float)this->super.totalMem * 100.0F;
+ proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0F, this->super.activeCPUs * 100.0F);
proc->nice = kproc->p_nice - 20;
proc->time = 100 * (kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 1000000));
proc->priority = kproc->p_priority - PZERO;
+ proc->processor = kproc->p_cpuid;
+ proc->minflt = kproc->p_uru_minflt;
+ proc->majflt = kproc->p_uru_majflt;
+ proc->nlwp = 1;
+
+ if (proc->st_uid != kproc->p_uid) {
+ proc->st_uid = kproc->p_uid;
+ proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
+ }
switch (kproc->p_stat) {
case SIDL: proc->state = 'I'; break;
- case SRUN: proc->state = 'R'; break;
+ case SRUN: proc->state = 'P'; break;
case SSLEEP: proc->state = 'S'; break;
case SSTOP: proc->state = 'T'; break;
case SZOMB: proc->state = 'Z'; break;
case SDEAD: proc->state = 'D'; break;
- case SONPROC: proc->state = 'P'; break;
+ case SONPROC: proc->state = 'R'; break;
default: proc->state = '?';
}
if (Process_isKernelThread(proc)) {
this->super.kernelThreads++;
+ } else if (Process_isUserlandThread(proc)) {
+ this->super.userlandThreads++;
}
this->super.totalTasks++;
- // SRUN ('R') means runnable, not running
- if (proc->state == 'P') {
+ if (proc->state == 'R') {
this->super.runningTasks++;
}
+
+ proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
proc->updated = true;
}
}
-static unsigned long long saturatingSub(unsigned long long a, unsigned long long b) {
- return a > b ? a - b : 0;
-}
-
-static void getKernelCPUTimes(int cpuId, u_int64_t* times) {
+static void getKernelCPUTimes(unsigned int cpuId, u_int64_t* times) {
const int mib[] = { CTL_KERN, KERN_CPTIME2, cpuId };
size_t length = sizeof(*times) * CPUSTATES;
if (sysctl(mib, 3, times, &length, NULL, 0) == -1 || length != sizeof(*times) * CPUSTATES) {
@@ -313,9 +419,14 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) {
u_int64_t kernelTimes[CPUSTATES] = {0};
u_int64_t avg[CPUSTATES] = {0};
- for (int i = 0; i < this->super.cpuCount; i++) {
+ for (unsigned int i = 0; i < this->super.existingCPUs; i++) {
+ CPUData* cpu = &this->cpuData[i + 1];
+
+ if (!cpu->online) {
+ continue;
+ }
+
getKernelCPUTimes(i, kernelTimes);
- CPUData* cpu = this->cpus + i + 1;
kernelCPUTimesToHtop(kernelTimes, cpu);
avg[CP_USER] += cpu->userTime;
@@ -329,15 +440,27 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) {
}
for (int i = 0; i < CPUSTATES; i++) {
- avg[i] /= this->super.cpuCount;
+ avg[i] /= this->super.activeCPUs;
}
- kernelCPUTimesToHtop(avg, this->cpus);
+ kernelCPUTimesToHtop(avg, &this->cpuData[0]);
+
+ {
+ const int mib[] = { CTL_HW, HW_CPUSPEED };
+ int cpuSpeed;
+ size_t size = sizeof(cpuSpeed);
+ if (sysctl(mib, 2, &cpuSpeed, &size, NULL, 0) == -1) {
+ this->cpuSpeed = -1;
+ } else {
+ this->cpuSpeed = cpuSpeed;
+ }
+ }
}
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
OpenBSDProcessList* opl = (OpenBSDProcessList*) super;
+ OpenBSDProcessList_updateCPUcount(super);
OpenBSDProcessList_scanMemoryInfo(super);
OpenBSDProcessList_scanCPUTime(opl);
@@ -348,3 +471,10 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
OpenBSDProcessList_scanProcs(opl);
}
+
+bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id) {
+ assert(id < super->existingCPUs);
+
+ const OpenBSDProcessList* opl = (const OpenBSDProcessList*) super;
+ return opl->cpuData[id + 1].online;
+}
diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h
index a6195a5..5245705 100644
--- a/openbsd/OpenBSDProcessList.h
+++ b/openbsd/OpenBSDProcessList.h
@@ -35,21 +35,26 @@ typedef struct CPUData_ {
unsigned long long int spinPeriod;
unsigned long long int intrPeriod;
unsigned long long int idlePeriod;
+
+ bool online;
} CPUData;
typedef struct OpenBSDProcessList_ {
ProcessList super;
kvm_t* kd;
- CPUData* cpus;
+ CPUData* cpuData;
+ int cpuSpeed;
} OpenBSDProcessList;
-ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
+ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId);
void ProcessList_delete(ProcessList* this);
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate);
+bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id);
+
#endif
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index 8ee8141..a62381f 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -6,7 +6,7 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
-#include "Platform.h"
+#include "openbsd/Platform.h"
#include <errno.h>
#include <kvm.h>
@@ -15,6 +15,8 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <sys/signal.h> // needs to be included before <sys/proc.h> for 'struct sigaltstack'
+#include <sys/proc.h>
#include <sys/resource.h>
#include <sys/sensors.h>
#include <sys/sysctl.h>
@@ -30,16 +32,18 @@ in the source distribution for its full text.
#include "LoadAverageMeter.h"
#include "Macros.h"
#include "MemoryMeter.h"
+#include "MemorySwapMeter.h"
#include "Meter.h"
-#include "OpenBSDProcess.h"
-#include "OpenBSDProcessList.h"
#include "ProcessList.h"
#include "Settings.h"
#include "SignalsPanel.h"
#include "SwapMeter.h"
+#include "SysArchMeter.h"
#include "TasksMeter.h"
#include "UptimeMeter.h"
#include "XUtils.h"
+#include "openbsd/OpenBSDProcess.h"
+#include "openbsd/OpenBSDProcessList.h"
const ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
@@ -95,10 +99,12 @@ const MeterClass* const Platform_meterTypes[] = {
&LoadMeter_class,
&MemoryMeter_class,
&SwapMeter_class,
+ &MemorySwapMeter_class,
&TasksMeter_class,
&UptimeMeter_class,
&BatteryMeter_class,
&HostnameMeter_class,
+ &SysArchMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&AllCPUs4Meter_class,
@@ -160,17 +166,23 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
}
int Platform_getMaxPid() {
- // this is hard-coded in sys/proc.h - no sysctl exists
- return 99999;
+ return 2 * THREAD_PID_OFFSET;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const OpenBSDProcessList* pl = (const OpenBSDProcessList*) this->pl;
- const CPUData* cpuData = &(pl->cpus[cpu]);
- double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;
+ const CPUData* cpuData = &(pl->cpuData[cpu]);
+ double total;
double totalPercent;
double* v = this->values;
+ if (!cpuData->online) {
+ this->curItems = 0;
+ return NAN;
+ }
+
+ total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;
+
v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0;
v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0;
if (this->pl->settings->detailedCPUTime) {
@@ -194,6 +206,8 @@ double Platform_setCPUValues(Meter* this, int cpu) {
v[CPU_METER_TEMPERATURE] = NAN;
+ v[CPU_METER_FREQUENCY] = (pl->cpuSpeed != -1) ? pl->cpuSpeed : NAN;
+
return totalPercent;
}
@@ -206,13 +220,16 @@ void Platform_setMemoryValues(Meter* this) {
this->total = pl->totalMem;
this->values[0] = usedMem;
this->values[1] = buffersMem;
- this->values[2] = cachedMem;
+ // this->values[2] = "shared memory, like tmpfs and shm"
+ this->values[3] = cachedMem;
+ // this->values[4] = "available memory"
}
void Platform_setSwapValues(Meter* this) {
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
+ this->values[1] = NAN;
}
char* Platform_getProcessEnv(pid_t pid) {
@@ -264,14 +281,14 @@ char* Platform_getProcessEnv(pid_t pid) {
}
char* Platform_getInodeFilename(pid_t pid, ino_t inode) {
- (void)pid;
- (void)inode;
- return NULL;
+ (void)pid;
+ (void)inode;
+ return NULL;
}
FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
- (void)pid;
- return NULL;
+ (void)pid;
+ return NULL;
}
bool Platform_getDiskIO(DiskIOData* data) {
@@ -280,15 +297,9 @@ bool Platform_getDiskIO(DiskIOData* data) {
return false;
}
-bool Platform_getNetworkIO(unsigned long int* bytesReceived,
- unsigned long int* packetsReceived,
- unsigned long int* bytesTransmitted,
- unsigned long int* packetsTransmitted) {
+bool Platform_getNetworkIO(NetworkIOData* data) {
// TODO
- *bytesReceived = 0;
- *packetsReceived = 0;
- *bytesTransmitted = 0;
- *packetsTransmitted = 0;
+ (void)data;
return false;
}
@@ -301,7 +312,7 @@ static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, si
if (errno == ENOENT)
return false;
}
- if (strcmp(name, snsrdev->xname) == 0) {
+ if (String_eq(name, snsrdev->xname)) {
return true;
}
}
diff --git a/openbsd/Platform.h b/openbsd/Platform.h
index e7a5966..bf43ae5 100644
--- a/openbsd/Platform.h
+++ b/openbsd/Platform.h
@@ -14,10 +14,15 @@ in the source distribution for its full text.
#include "Action.h"
#include "BatteryMeter.h"
#include "DiskIOMeter.h"
+#include "Hashtable.h"
#include "Meter.h"
+#include "NetworkIOMeter.h"
#include "Process.h"
#include "ProcessLocksScreen.h"
#include "SignalsPanel.h"
+#include "generic/gettime.h"
+#include "generic/hostname.h"
+#include "generic/uname.h"
extern const ProcessField Platform_defaultFields[];
@@ -41,7 +46,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void);
-double Platform_setCPUValues(Meter* this, int cpu);
+double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this);
@@ -55,11 +60,50 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
bool Platform_getDiskIO(DiskIOData* data);
-bool Platform_getNetworkIO(unsigned long int* bytesReceived,
- unsigned long int* packetsReceived,
- unsigned long int* bytesTransmitted,
- unsigned long int* packetsTransmitted);
+bool Platform_getNetworkIO(NetworkIOData* data);
void Platform_getBattery(double* percent, ACPresence* isOnAC);
+static inline void Platform_getHostname(char* buffer, size_t size) {
+ Generic_hostname(buffer, size);
+}
+
+static inline void Platform_getRelease(char** string) {
+ *string = Generic_uname();
+}
+
+#define PLATFORM_LONG_OPTIONS
+
+static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
+
+static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
+ return false;
+}
+
+static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
+ Generic_gettime_realtime(tv, msec);
+}
+
+static inline void Platform_gettime_monotonic(uint64_t* msec) {
+ Generic_gettime_monotonic(msec);
+}
+
+static inline Hashtable* Platform_dynamicMeters(void) { return NULL; }
+
+static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { }
+
+static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { }
+
+static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { }
+
+static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { }
+
+static inline Hashtable* Platform_dynamicColumns(void) { return NULL; }
+
+static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
+
+static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { return NULL; }
+
+static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) { return false; }
+
#endif

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