summaryrefslogtreecommitdiffstats
path: root/solaris
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 /solaris
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 'solaris')
-rw-r--r--solaris/Platform.c21
-rw-r--r--solaris/SolarisMachine.c332
-rw-r--r--solaris/SolarisMachine.h59
-rw-r--r--solaris/SolarisProcessList.c332
-rw-r--r--solaris/SolarisProcessList.h36
5 files changed, 414 insertions, 366 deletions
diff --git a/solaris/Platform.c b/solaris/Platform.c
index 8c88fc85..ad899492 100644
--- a/solaris/Platform.c
+++ b/solaris/Platform.c
@@ -34,10 +34,11 @@ in the source distribution for its full text.
#include "HostnameMeter.h"
#include "SysArchMeter.h"
#include "UptimeMeter.h"
+
+#include "solaris/SolarisMachine.h"
+
#include "zfs/ZfsArcMeter.h"
#include "zfs/ZfsCompressedArcMeter.h"
-#include "SolarisProcess.h"
-#include "SolarisProcessList.h"
const ScreenDefaults Platform_defaultScreens[] = {
@@ -195,15 +196,15 @@ int Platform_getMaxPid(void) {
double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const Machine* host = this->host;
- const SolarisProcessList* spl = (const SolarisProcessList*) host->pl;
+ const SolarisMachine* shost = (const SolarisMachine*) host;
unsigned int cpus = host->existingCPUs;
const CPUData* cpuData = NULL;
if (cpus == 1) {
// single CPU box has everything in spl->cpus[0]
- cpuData = &(spl->cpus[0]);
+ cpuData = &(shost->cpus[0]);
} else {
- cpuData = &(spl->cpus[cpu]);
+ cpuData = &(shost->cpus[cpu]);
}
if (!cpuData->online) {
@@ -216,7 +217,7 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) {
v[CPU_METER_NICE] = cpuData->nicePercent;
v[CPU_METER_NORMAL] = cpuData->userPercent;
- if (host->settings->detailedCPUTime) {
+ if (super->settings->detailedCPUTime) {
v[CPU_METER_KERNEL] = cpuData->systemPercent;
v[CPU_METER_IRQ] = cpuData->irqPercent;
this->curItems = 4;
@@ -255,15 +256,15 @@ void Platform_setSwapValues(Meter* this) {
}
void Platform_setZfsArcValues(Meter* this) {
- const SolarisProcessList* spl = (const SolarisProcessList*) this->host->pl;
+ const SolarisMachine* shost = (SolarisMachine*) this->host;
- ZfsArcMeter_readStats(this, &(spl->zfs));
+ ZfsArcMeter_readStats(this, &(shost->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
- const SolarisProcessList* spl = (const SolarisProcessList*) this->host->pl;
+ const SolarisMachine* shost = (SolarisMachine*) this->host;
- ZfsCompressedArcMeter_readStats(this, &(spl->zfs));
+ ZfsCompressedArcMeter_readStats(this, &(shost->zfs));
}
static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr_t addr, const char* str) {
diff --git a/solaris/SolarisMachine.c b/solaris/SolarisMachine.c
new file mode 100644
index 00000000..9ce4ced2
--- /dev/null
+++ b/solaris/SolarisMachine.c
@@ -0,0 +1,332 @@
+/*
+htop - SolarisMachine.c
+(C) 2014 Hisham H. Muhammad
+(C) 2017,2018 Guy M. Broome
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+
+#include "solaris/SolarisMachine.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <limits.h>
+#include <string.h>
+#include <procfs.h>
+#include <errno.h>
+#include <pwd.h>
+#include <math.h>
+#include <time.h>
+
+#include "CRT.h"
+#include "solaris/Platform.h"
+
+
+static void SolarisMachine_updateCPUcount(SolarisMachine* this) {
+ Machine* super = &this->super;
+ long int s;
+ bool change = false;
+
+ s = sysconf(_SC_NPROCESSORS_CONF);
+ if (s < 1)
+ CRT_fatalError("Cannot get existing CPU count by sysconf(_SC_NPROCESSORS_CONF)");
+
+ if (s != super->existingCPUs) {
+ if (s == 1) {
+ this->cpus = xRealloc(this->cpus, sizeof(CPUData));
+ this->cpus[0].online = true;
+ } else {
+ this->cpus = xReallocArray(this->cpus, s + 1, sizeof(CPUData));
+ this->cpus[0].online = true; /* average is always "online" */
+ for (int i = 1; i < s + 1; i++) {
+ this->cpus[i].online = false;
+ }
+ }
+
+ change = true;
+ super->existingCPUs = s;
+ }
+
+ s = sysconf(_SC_NPROCESSORS_ONLN);
+ if (s < 1)
+ CRT_fatalError("Cannot get active CPU count by sysconf(_SC_NPROCESSORS_ONLN)");
+
+ if (s != super->activeCPUs) {
+ change = true;
+ hsuper->activeCPUs = s;
+ }
+
+ if (change) {
+ kstat_close(this->kd);
+ this->kd = kstat_open();
+ if (!this->kd)
+ CRT_fatalError("Cannot open kstat handle");
+ }
+}
+
+
+static void SolarisMachine_scanCPUTime(SolarisMachine* this) {
+ Machine* super = &this->super;
+ unsigned int activeCPUs = super->activeCPUs;
+ unsigned int existingCPUs = super->existingCPUs;
+ kstat_t* cpuinfo = NULL;
+ kstat_named_t* idletime = NULL;
+ kstat_named_t* intrtime = NULL;
+ kstat_named_t* krnltime = NULL;
+ kstat_named_t* usertime = NULL;
+ kstat_named_t* cpu_freq = NULL;
+ double idlebuf = 0;
+ double intrbuf = 0;
+ double krnlbuf = 0;
+ double userbuf = 0;
+ int arrskip = 0;
+
+ assert(existingCPUs > 0);
+ assert(this->kd);
+
+ if (existingCPUs > 1) {
+ // Store values for the stats loop one extra element up in the array
+ // to leave room for the average to be calculated afterwards
+ arrskip++;
+ }
+
+ // Calculate per-CPU statistics first
+ for (unsigned int i = 0; i < existingCPUs; i++) {
+ CPUData* cpuData = &(this->cpus[i + arrskip]);
+
+ if ((cpuinfo = kstat_lookup_wrapper(this->kd, "cpu", i, "sys")) != NULL) {
+ cpuData->online = true;
+ if (kstat_read(this->kd, cpuinfo, NULL) != -1) {
+ idletime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_idle");
+ intrtime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_intr");
+ krnltime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_kernel");
+ usertime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_user");
+ }
+ } else {
+ cpuData->online = false;
+ continue;
+ }
+
+ assert( (idletime != NULL) && (intrtime != NULL)
+ && (krnltime != NULL) && (usertime != NULL) );
+
+ if (super->settings->showCPUFrequency) {
+ if ((cpuinfo = kstat_lookup_wrapper(this->kd, "cpu_info", i, NULL)) != NULL) {
+ if (kstat_read(this->kd, cpuinfo, NULL) != -1) {
+ cpu_freq = kstat_data_lookup_wrapper(cpuinfo, "current_clock_Hz");
+ }
+ }
+
+ assert( cpu_freq != NULL );
+ }
+
+ uint64_t totaltime = (idletime->value.ui64 - cpuData->lidle)
+ + (intrtime->value.ui64 - cpuData->lintr)
+ + (krnltime->value.ui64 - cpuData->lkrnl)
+ + (usertime->value.ui64 - cpuData->luser);
+
+ // Calculate percentages of deltas since last reading
+ cpuData->userPercent = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
+ cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
+ cpuData->systemPercent = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
+ cpuData->irqPercent = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
+ cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
+ cpuData->idlePercent = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
+ // Store current values to use for the next round of deltas
+ cpuData->luser = usertime->value.ui64;
+ cpuData->lkrnl = krnltime->value.ui64;
+ cpuData->lintr = intrtime->value.ui64;
+ cpuData->lidle = idletime->value.ui64;
+ // Add frequency in MHz
+ cpuData->frequency = super->settings->showCPUFrequency ? (double)cpu_freq->value.ui64 / 1E6 : NAN;
+ // Accumulate the current percentages into buffers for later average calculation
+ if (existingCPUs > 1) {
+ userbuf += cpuData->userPercent;
+ krnlbuf += cpuData->systemPercent;
+ intrbuf += cpuData->irqPercent;
+ idlebuf += cpuData->idlePercent;
+ }
+ }
+
+ if (existingCPUs > 1) {
+ CPUData* cpuData = &(this->cpus[0]);
+ cpuData->userPercent = userbuf / activeCPUs;
+ cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
+ cpuData->systemPercent = krnlbuf / activeCPUs;
+ cpuData->irqPercent = intrbuf / activeCPUs;
+ cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
+ cpuData->idlePercent = idlebuf / activeCPUs;
+ }
+}
+
+static void SolarisMachine_scanMemoryInfo(SolarisMachine* this) {
+ Machine* super = &this->super;
+ static kstat_t *meminfo = NULL;
+ int ksrphyserr = -1;
+ kstat_named_t *totalmem_pgs = NULL;
+ kstat_named_t *freemem_pgs = NULL;
+ kstat_named_t *pages = NULL;
+ struct swaptable *sl = NULL;
+ struct swapent *swapdev = NULL;
+ uint64_t totalswap = 0;
+ uint64_t totalfree = 0;
+ int nswap = 0;
+ char *spath = NULL;
+ char *spathbase = NULL;
+
+ // Part 1 - physical memory
+ if (this->kd != NULL && meminfo == NULL) {
+ // Look up the kstat chain just once, it never changes
+ meminfo = kstat_lookup_wrapper(this->kd, "unix", 0, "system_pages");
+ }
+ if (meminfo != NULL) {
+ ksrphyserr = kstat_read(this->kd, meminfo, NULL);
+ }
+ if (ksrphyserr != -1) {
+ totalmem_pgs = kstat_data_lookup_wrapper(meminfo, "physmem");
+ freemem_pgs = kstat_data_lookup_wrapper(meminfo, "freemem");
+ pages = kstat_data_lookup_wrapper(meminfo, "pagestotal");
+
+ super->totalMem = totalmem_pgs->value.ui64 * this->pageSizeKB;
+ if (super->totalMem > freemem_pgs->value.ui64 * this->pageSizeKB) {
+ super->usedMem = super->totalMem - freemem_pgs->value.ui64 * this->pageSizeKB;
+ } else {
+ super->usedMem = 0; // This can happen in non-global zone (in theory)
+ }
+ // Not sure how to implement this on Solaris - suggestions welcome!
+ super->cachedMem = 0;
+ // Not really "buffers" but the best Solaris analogue that I can find to
+ // "memory in use but not by programs or the kernel itself"
+ super->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * this->pageSizeKB;
+ } else {
+ // Fall back to basic sysconf if kstat isn't working
+ super->totalMem = sysconf(_SC_PHYS_PAGES) * this->pageSize;
+ super->buffersMem = 0;
+ super->cachedMem = 0;
+ super->usedMem = super->totalMem - (sysconf(_SC_AVPHYS_PAGES) * this->pageSize);
+ }
+
+ // Part 2 - swap
+ nswap = swapctl(SC_GETNSWP, NULL);
+ if (nswap > 0) {
+ sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int));
+ }
+ if (sl != NULL) {
+ spathbase = xMalloc( nswap * MAXPATHLEN );
+ }
+ if (spathbase != NULL) {
+ spath = spathbase;
+ swapdev = sl->swt_ent;
+ for (int i = 0; i < nswap; i++, swapdev++) {
+ swapdev->ste_path = spath;
+ spath += MAXPATHLEN;
+ }
+ sl->swt_n = nswap;
+ }
+ nswap = swapctl(SC_LIST, sl);
+ if (nswap > 0) {
+ swapdev = sl->swt_ent;
+ for (int i = 0; i < nswap; i++, swapdev++) {
+ totalswap += swapdev->ste_pages;
+ totalfree += swapdev->ste_free;
+ }
+ }
+ free(spathbase);
+ free(sl);
+ super->totalSwap = totalswap * this->pageSizeKB;
+ super->usedSwap = super->totalSwap - (totalfree * this->pageSizeKB);
+}
+
+static void SolarisMachine_scanZfsArcstats(SolarisMachine* this) {
+ kstat_named_t *cur_kstat = NULL;
+ kstat_t *arcstats = NULL;
+ int ksrphyserr = -1;
+
+ if (this->kd != NULL) {
+ arcstats = kstat_lookup_wrapper(this->kd, "zfs", 0, "arcstats");
+ }
+ if (arcstats != NULL) {
+ ksrphyserr = kstat_read(this->kd, arcstats, NULL);
+ }
+ if (ksrphyserr != -1) {
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" );
+ this->zfs.size = cur_kstat->value.ui64 / 1024;
+ this->zfs.enabled = this->zfs.size > 0 ? 1 : 0;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" );
+ this->zfs.max = cur_kstat->value.ui64 / 1024;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" );
+ this->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" );
+ this->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" );
+ this->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" );
+ this->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" );
+ this->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
+
+ if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) {
+ this->zfs.compressed = cur_kstat->value.ui64 / 1024;
+ this->zfs.isCompressed = 1;
+
+ cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" );
+ this->zfs.uncompressed = cur_kstat->value.ui64 / 1024;
+ } else {
+ this->zfs.isCompressed = 0;
+ }
+ }
+}
+
+void Machine_scan(Machine* super) {
+ SolarisMachine* this = (SolarisMachine*) super;
+
+ SolarisMachine_updateCPUcount(this);
+ SolarisMachine_scanCPUTime(this);
+ SolarisMachine_scanMemoryInfo(this);
+ SolarisMachine_scanZfsArcstats(this);
+}
+
+Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
+ SolarisMachine* this = xCalloc(1, sizeof(SolarisMachine));
+ Machine *super = &this->super;
+
+ Machine_init(super, usersTable, userId);
+
+ this->pageSize = sysconf(_SC_PAGESIZE);
+ if (this->pageSize == -1)
+ CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)");
+ this->pageSizeKB = this->pageSize / 1024;
+
+ SolarisMachine_updateCPUcount(this);
+
+ return super;
+}
+
+void Machine_delete(Machine* super) {
+ SolarisMachine* this = (SolarisMachine*) super;
+
+ Machine_done(super);
+
+ free(this->cpus);
+ if (this->kd) {
+ kstat_close(this->kd);
+ }
+ free(this);
+}
+
+bool Machine_isCPUonline(const Machine* super, unsigned int id) {
+ assert(id < super->existingCPUs);
+
+ const SolarisMachine* this = (const SolarisMachine*) super;
+
+ return (super->existingCPUs == 1) ? true : this->cpus[id + 1].online;
+}
diff --git a/solaris/SolarisMachine.h b/solaris/SolarisMachine.h
new file mode 100644
index 00000000..da091c6e
--- /dev/null
+++ b/solaris/SolarisMachine.h
@@ -0,0 +1,59 @@
+#ifndef HEADER_SolarisMachine
+#define HEADER_SolarisMachine
+/*
+htop - SolarisMachine.h
+(C) 2014 Hisham H. Muhammad
+(C) 2017,2018 Guy M. Broome
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include <kstat.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/param.h>
+#include <sys/uio.h>
+#include <sys/resource.h>
+#include <sys/sysconf.h>
+#include <sys/sysinfo.h>
+#include <sys/swap.h>
+
+#include "Hashtable.h"
+#include "UsersTable.h"
+
+#include "zfs/ZfsArcStats.h"
+
+
+#define ZONE_ERRMSGLEN 1024
+extern char zone_errmsg[ZONE_ERRMSGLEN];
+
+typedef struct CPUData_ {
+ double userPercent;
+ double nicePercent;
+ double systemPercent;
+ double irqPercent;
+ double idlePercent;
+ double systemAllPercent;
+ double frequency;
+ uint64_t luser;
+ uint64_t lkrnl;
+ uint64_t lintr;
+ uint64_t lidle;
+ bool online;
+} CPUData;
+
+typedef struct SolarisMachine_ {
+ Machine super;
+
+ kstat_ctl_t* kd;
+ CPUData* cpus;
+
+ int pageSize;
+ int pageSizeKB;
+
+ ZfsArcStats zfs;
+} SolarisMachine;
+
+#endif
diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c
index 84991d6e..e759b187 100644
--- a/solaris/SolarisProcessList.c
+++ b/solaris/SolarisProcessList.c
@@ -29,9 +29,6 @@ in the source distribution for its full text.
#define GZONE "global "
#define UZONE "unknown "
-static int pageSize;
-static int pageSizeKB;
-
static char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
char* zname;
@@ -47,296 +44,18 @@ static char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sp
return zname;
}
-static void SolarisProcessList_updateCPUcount(ProcessList* super) {
- Machine* host = super->host;
- SolarisProcessList* spl = (SolarisProcessList*) super;
- long int s;
- bool change = false;
-
- s = sysconf(_SC_NPROCESSORS_CONF);
- if (s < 1)
- CRT_fatalError("Cannot get existing CPU count by sysconf(_SC_NPROCESSORS_CONF)");
-
- if (s != host->existingCPUs) {
- if (s == 1) {
- spl->cpus = xRealloc(spl->cpus, sizeof(CPUData));
- spl->cpus[0].online = true;
- } else {
- spl->cpus = xReallocArray(spl->cpus, s + 1, sizeof(CPUData));
- spl->cpus[0].online = true; /* average is always "online" */
- for (int i = 1; i < s + 1; i++) {
- spl->cpus[i].online = false;
- }
- }
-
- change = true;
- host->existingCPUs = s;
- }
-
- s = sysconf(_SC_NPROCESSORS_ONLN);
- if (s < 1)
- CRT_fatalError("Cannot get active CPU count by sysconf(_SC_NPROCESSORS_ONLN)");
-
- if (s != host->activeCPUs) {
- change = true;
- host->activeCPUs = s;
- }
-
- if (change) {
- kstat_close(spl->kd);
- spl->kd = kstat_open();
- if (!spl->kd)
- CRT_fatalError("Cannot open kstat handle");
- }
-}
-
ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) {
SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList));
ProcessList* pl = (ProcessList*) spl;
- ProcessList_init(pl, Class(SolarisProcess), host, pidMatchList);
-
- spl->kd = kstat_open();
- if (!spl->kd)
- CRT_fatalError("Cannot open kstat handle");
- pageSize = sysconf(_SC_PAGESIZE);
- if (pageSize == -1)
- CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)");
- pageSizeKB = pageSize / 1024;
-
- SolarisProcessList_updateCPUcount(pl);
+ ProcessList_init(pl, Class(SolarisProcess), host, pidMatchList);
return pl;
}
-static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
- const SolarisProcessList* spl = (SolarisProcessList*) pl;
- unsigned int activeCPUs = pl->host->activeCPUs;
- unsigned int existingCPUs = pl->host->existingCPUs;
- kstat_t* cpuinfo = NULL;
- kstat_named_t* idletime = NULL;
- kstat_named_t* intrtime = NULL;
- kstat_named_t* krnltime = NULL;
- kstat_named_t* usertime = NULL;
- kstat_named_t* cpu_freq = NULL;
- double idlebuf = 0;
- double intrbuf = 0;
- double krnlbuf = 0;
- double userbuf = 0;
- int arrskip = 0;
-
- assert(existingCPUs > 0);
- assert(spl->kd);
-
- if (existingCPUs > 1) {
- // Store values for the stats loop one extra element up in the array
- // to leave room for the average to be calculated afterwards
- arrskip++;
- }
-
- // Calculate per-CPU statistics first
- for (unsigned int i = 0; i < existingCPUs; i++) {
- CPUData* cpuData = &(spl->cpus[i + arrskip]);
-
- if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu", i, "sys")) != NULL) {
- cpuData->online = true;
- if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {
- idletime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_idle");
- intrtime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_intr");
- krnltime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_kernel");
- usertime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_user");
- }
- } else {
- cpuData->online = false;
- continue;
- }
-
- assert( (idletime != NULL) && (intrtime != NULL)
- && (krnltime != NULL) && (usertime != NULL) );
-
- if (pl->settings->showCPUFrequency) {
- if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu_info", i, NULL)) != NULL) {
- if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {
- cpu_freq = kstat_data_lookup_wrapper(cpuinfo, "current_clock_Hz");
- }
- }
-
- assert( cpu_freq != NULL );
- }
-
- uint64_t totaltime = (idletime->value.ui64 - cpuData->lidle)
- + (intrtime->value.ui64 - cpuData->lintr)
- + (krnltime->value.ui64 - cpuData->lkrnl)
- + (usertime->value.ui64 - cpuData->luser);
-
- // Calculate percentages of deltas since last reading
- cpuData->userPercent = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
- cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
- cpuData->systemPercent = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
- cpuData->irqPercent = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
- cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
- cpuData->idlePercent = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
- // Store current values to use for the next round of deltas
- cpuData->luser = usertime->value.ui64;
- cpuData->lkrnl = krnltime->value.ui64;
- cpuData->lintr = intrtime->value.ui64;
- cpuData->lidle = idletime->value.ui64;
- // Add frequency in MHz
- cpuData->frequency = pl->settings->showCPUFrequency ? (double)cpu_freq->value.ui64 / 1E6 : NAN;
- // Accumulate the current percentages into buffers for later average calculation
- if (existingCPUs > 1) {
- userbuf += cpuData->userPercent;
- krnlbuf += cpuData->systemPercent;
- intrbuf += cpuData->irqPercent;
- idlebuf += cpuData->idlePercent;
- }
- }
-
- if (existingCPUs > 1) {
- CPUData* cpuData = &(spl->cpus[0]);
- cpuData->userPercent = userbuf / activeCPUs;
- cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
- cpuData->systemPercent = krnlbuf / activeCPUs;
- cpuData->irqPercent = intrbuf / activeCPUs;
- cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
- cpuData->idlePercent = idlebuf / activeCPUs;
- }
-}
-
-static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
- Machine* host = pl->host;
- SolarisProcessList* spl = (SolarisProcessList*) pl;
-
- static kstat_t *meminfo = NULL;
- int ksrphyserr = -1;
- kstat_named_t *totalmem_pgs = NULL;
- kstat_named_t *freemem_pgs = NULL;
- kstat_named_t *pages = NULL;
- struct swaptable *sl = NULL;
- struct swapent *swapdev = NULL;
- uint64_t totalswap = 0;
- uint64_t totalfree = 0;
- int nswap = 0;
- char *spath = NULL;
- char *spathbase = NULL;
-
- // Part 1 - physical memory
- if (spl->kd != NULL && meminfo == NULL) {
- // Look up the kstat chain just once, it never changes
- meminfo = kstat_lookup_wrapper(spl->kd, "unix", 0, "system_pages");
- }
- if (meminfo != NULL) {
- ksrphyserr = kstat_read(spl->kd, meminfo, NULL);
- }
- if (ksrphyserr != -1) {
- totalmem_pgs = kstat_data_lookup_wrapper(meminfo, "physmem");
- freemem_pgs = kstat_data_lookup_wrapper(meminfo, "freemem");
- pages = kstat_data_lookup_wrapper(meminfo, "pagestotal");
-
- host->totalMem = totalmem_pgs->value.ui64 * pageSizeKB;
- if (host->totalMem > freemem_pgs->value.ui64 * pageSizeKB) {
- host->usedMem = host->totalMem - freemem_pgs->value.ui64 * pageSizeKB;
- } else {
- host->usedMem = 0; // This can happen in non-global zone (in theory)
- }
- // Not sure how to implement this on Solaris - suggestions welcome!
- host->cachedMem = 0;
- // Not really "buffers" but the best Solaris analogue that I can find to
- // "memory in use but not by programs or the kernel itself"
- host->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * pageSizeKB;
- } else {
- // Fall back to basic sysconf if kstat isn't working
- host->totalMem = sysconf(_SC_PHYS_PAGES) * pageSize;
- host->buffersMem = 0;
- host->cachedMem = 0;
- host->usedMem = host->totalMem - (sysconf(_SC_AVPHYS_PAGES) * pageSize);
- }
-
- // Part 2 - swap
- nswap = swapctl(SC_GETNSWP, NULL);
- if (nswap > 0) {
- sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int));
- }
- if (sl != NULL) {
- spathbase = xMalloc( nswap * MAXPATHLEN );
- }
- if (spathbase != NULL) {
- spath = spathbase;
- swapdev = sl->swt_ent;
- for (int i = 0; i < nswap; i++, swapdev++) {
- swapdev->ste_path = spath;
- spath += MAXPATHLEN;
- }
- sl->swt_n = nswap;
- }
- nswap = swapctl(SC_LIST, sl);
- if (nswap > 0) {
- swapdev = sl->swt_ent;
- for (int i = 0; i < nswap; i++, swapdev++) {
- totalswap += swapdev->ste_pages;
- totalfree += swapdev->ste_free;
- }
- }
- free(spathbase);
- free(sl);
- host->totalSwap = totalswap * pageSizeKB;
- host->usedSwap = host->totalSwap - (totalfree * pageSizeKB);
-}
-
-static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) {
- SolarisProcessList* spl = (SolarisProcessList*) pl;
- kstat_t *arcstats = NULL;
- int ksrphyserr = -1;
- kstat_named_t *cur_kstat = NULL;
-
- if (spl->kd != NULL) {
- arcstats = kstat_lookup_wrapper(spl->kd, "zfs", 0, "arcstats");
- }
- if (arcstats != NULL) {
- ksrphyserr = kstat_read(spl->kd, arcstats, NULL);
- }
- if (ksrphyserr != -1) {
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" );
- spl->zfs.size = cur_kstat->value.ui64 / 1024;
- spl->zfs.enabled = spl->zfs.size > 0 ? 1 : 0;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" );
- spl->zfs.max = cur_kstat->value.ui64 / 1024;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" );
- spl->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" );
- spl->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" );
- spl->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" );
- spl->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" );
- spl->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
-
- if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) {
- spl->zfs.compressed = cur_kstat->value.ui64 / 1024;
- spl->zfs.isCompressed = 1;
-
- cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" );
- spl->zfs.uncompressed = cur_kstat->value.ui64 / 1024;
- } else {
- spl->zfs.isCompressed = 0;
- }
- }
-}
-
void ProcessList_delete(ProcessList* pl) {
SolarisProcessList* spl = (SolarisProcessList*) pl;
ProcessList_done(pl);
- free(spl->cpus);
- if (spl->kd) {
- kstat_close(spl->kd);
- }
free(spl);
}
@@ -392,7 +111,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
// Setup process list
ProcessList* pl = (ProcessList*) listptr;
SolarisProcessList* spl = (SolarisProcessList*) listptr;
- Machine* host = pl->super.host;
+ Machine* host = pl->host;
id_t lwpid_real = _lwpsinfo->pr_lwpid;
if (lwpid_real > 1023) {
@@ -407,8 +126,9 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
getpid = lwpid;
}
- Process* proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new);
- SolarisProcess* sproc = (SolarisProcess*) proc;
+ Process* proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new);
+ SolarisProcess* sproc = (SolarisProcess*) proc;
+ const Settings* settings = host->settings;
// Common code pass 1
proc->show = false;
@@ -455,7 +175,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
Process_updateComm(proc, _psinfo->pr_fname);
Process_updateCmdline(proc, _psinfo->pr_psargs, 0, 0);
- if (proc->settings->ss->flags & PROCESS_FLAG_CWD) {
+ if (settings->ss->flags & PROCESS_FLAG_CWD) {
SolarisProcessList_updateCwd(_psinfo->pr_pid, proc);
}
}
@@ -479,7 +199,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
}
// Update proc and thread counts based on settings
- if (proc->isKernelThread && !pl->settings->hideKernelThreads) {
+ if (proc->isKernelThread && !settings->hideKernelThreads) {
pl->kernelThreads += proc->nlwp;
pl->totalTasks += proc->nlwp + 1;
if (proc->state == RUNNING) {
@@ -489,14 +209,14 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
if (proc->state == RUNNING) {
pl->runningTasks++;
}
- if (pl->settings->hideUserlandThreads) {
+ if (settings->hideUserlandThreads) {
pl->totalTasks++;
} else {
pl->userlandThreads += proc->nlwp;
pl->totalTasks += proc->nlwp + 1;
}
}
- proc->show = !(pl->settings->hideKernelThreads && proc->isKernelThread);
+ proc->show = !(settings->hideKernelThreads && proc->isKernelThread);
} else { // We are not in the master LWP, so jump to the LWP handling code
proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu / (double)32768) * (double)100.0;
Process_updateCPUFieldWidths(proc->percent_cpu);
@@ -512,10 +232,10 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
}
// Top-level process only gets this for the representative LWP
- if (proc->isKernelThread && !pl->settings->hideKernelThreads) {
+ if (proc->isKernelThread && !settings->hideKernelThreads) {
proc->show = true;
}
- if (!proc->isKernelThread && !pl->settings->hideUserlandThreads) {
+ if (!proc->isKernelThread && !settings->hideUserlandThreads) {
proc->show = true;
}
} // Top-level LWP or subordinate LWP
@@ -540,35 +260,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
return 0;
}
-void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
- SolarisProcessList_updateCPUcount(super);
- SolarisProcessList_scanCPUTime(super);
- SolarisProcessList_scanMemoryInfo(super);
- SolarisProcessList_scanZfsArcstats(super);
-
- // in pause mode only gather global data for meters (CPU/memory/...)
- if (pauseProcessUpdate) {
- return;
- }
-
+void ProcessList_goThroughEntries(ProcessList* super) {
super->kernelThreads = 1;
proc_walk(&SolarisProcessList_walkproc, super, PR_WALK_LWP);
}
-
-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);
-
- const SolarisProcessList* spl = (const SolarisProcessList*) host->pl;
-
- return (super->host->existingCPUs == 1) ? true : spl->cpus[id + 1].online;
-}
diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h
index 7cb64167..d8280117 100644
--- a/solaris/SolarisProcessList.h
+++ b/solaris/SolarisProcessList.h
@@ -18,7 +18,6 @@ in the source distribution for its full text.
#include <sys/resource.h>
#include <sys/sysconf.h>
#include <sys/sysinfo.h>
-#include <sys/swap.h>
#include "Hashtable.h"
#include "ProcessList.h"
@@ -26,44 +25,9 @@ in the source distribution for its full text.
#include "solaris/SolarisProcess.h"
-#include "zfs/ZfsArcStats.h"
-
-
-#define ZONE_ERRMSGLEN 1024
-extern char zone_errmsg[ZONE_ERRMSGLEN];
-
-typedef struct CPUData_ {
- double userPercent;
- double nicePercent;
- double systemPercent;
- double irqPercent;
- double idlePercent;
- double systemAllPercent;
- double frequency;
- uint64_t luser;
- uint64_t lkrnl;
- uint64_t lintr;
- uint64_t lidle;
- bool online;
-} CPUData;
typedef struct SolarisProcessList_ {
ProcessList super;
- kstat_ctl_t* kd;
- CPUData* cpus;
- ZfsArcStats zfs;
} SolarisProcessList;
-ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList);
-
-void ProcessList_delete(ProcessList* pl);
-
-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

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