From c55320e9e2a8916e911bcd39ab37b79e3a7d03b2 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Jan 2021 20:43:27 +0100 Subject: New upstream version 3.0.5 --- solaris/Platform.c | 8 +--- solaris/Platform.h | 7 +-- solaris/ProcessField.h | 22 +++++++++ solaris/SolarisProcess.c | 106 +++++++++++++++++-------------------------- solaris/SolarisProcess.h | 20 +------- solaris/SolarisProcessList.c | 76 +++++++++++++++++++------------ solaris/SolarisProcessList.h | 1 + 7 files changed, 115 insertions(+), 125 deletions(-) create mode 100644 solaris/ProcessField.h (limited to 'solaris') diff --git a/solaris/Platform.c b/solaris/Platform.c index 014eaf5..968e013 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -86,7 +86,7 @@ const SignalItem Platform_signals[] = { const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); -ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; +const ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; const MeterClass* const Platform_meterTypes[] = { &CPUMeter_class, @@ -119,10 +119,6 @@ const MeterClass* const Platform_meterTypes[] = { NULL }; -int Platform_numberOfFields = LAST_PROCESSFIELD; - -extern char Process_pidFormat[20]; - void Platform_init(void) { /* no platform-specific setup needed */ } @@ -209,7 +205,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); - v[CPU_METER_FREQUENCY] = NAN; + v[CPU_METER_FREQUENCY] = cpuData->frequency; v[CPU_METER_TEMPERATURE] = NAN; return percent; diff --git a/solaris/Platform.h b/solaris/Platform.h index c338115..de2b2c9 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -25,7 +25,6 @@ in the source distribution for its full text. #define kill(pid, signal) kill(pid / 1024, signal) -extern ProcessFieldData Process_fields[]; typedef struct var kvar_t; typedef struct envAccum_ { @@ -41,14 +40,10 @@ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; -extern ProcessField Platform_defaultFields[]; +extern const ProcessField Platform_defaultFields[]; extern const MeterClass* const Platform_meterTypes[]; -extern int Platform_numberOfFields; - -extern char Process_pidFormat[20]; - void Platform_init(void); void Platform_done(void); diff --git a/solaris/ProcessField.h b/solaris/ProcessField.h new file mode 100644 index 0000000..eb9f157 --- /dev/null +++ b/solaris/ProcessField.h @@ -0,0 +1,22 @@ +#ifndef HEADER_SolarisProcessField +#define HEADER_SolarisProcessField +/* +htop - solaris/ProcessField.h +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + + +#define PLATFORM_PROCESS_FIELDS \ + ZONEID = 100, \ + ZONE = 101, \ + PROJID = 102, \ + TASKID = 103, \ + POOLID = 104, \ + CONTID = 105, \ + LWPID = 106, \ + // End of list + + +#endif /* HEADER_SolarisProcessField */ diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index e0a3db2..d905f7a 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -18,26 +18,16 @@ in the source distribution for its full text. #include -const ProcessClass SolarisProcess_class = { - .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = SolarisProcess_compare - }, - .writeField = SolarisProcess_writeField, -}; - -ProcessFieldData Process_fields[] = { +const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, - [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, + [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, O onproc, Z zombie, T stopped, W waiting)", .flags = 0, }, - [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, }, - [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, }, - [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, }, + [PPID] = { .name = "PPID", .title = "PPID", .description = "Parent process ID", .flags = 0, .pidColumn = true, }, + [PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, }, + [SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, }, [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, }, - [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, }, + [TPGID] = { .name = "TPGID", .title = "TPGID", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, .pidColumn = true, }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, }, [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, @@ -53,31 +43,14 @@ ProcessFieldData Process_fields[] = { [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, - [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, }, - [ZONEID] = { .name = "ZONEID", .title = " ZONEID ", .description = "Zone ID", .flags = 0, }, + [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, }, + [ZONEID] = { .name = "ZONEID", .title = "ZONEID", .description = "Zone ID", .flags = 0, .pidColumn = true, }, [ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, }, - [PROJID] = { .name = "PROJID", .title = " PRJID ", .description = "Project ID", .flags = 0, }, - [TASKID] = { .name = "TASKID", .title = " TSKID ", .description = "Task ID", .flags = 0, }, - [POOLID] = { .name = "POOLID", .title = " POLID ", .description = "Pool ID", .flags = 0, }, - [CONTID] = { .name = "CONTID", .title = " CNTID ", .description = "Contract ID", .flags = 0, }, - [LWPID] = { .name = "LWPID", .title = " LWPID ", .description = "LWP ID", .flags = 0, }, - [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, -}; - -ProcessPidColumn Process_pidColumns[] = { - { .id = ZONEID, .label = "ZONEID" }, - { .id = TASKID, .label = "TSKID" }, - { .id = PROJID, .label = "PRJID" }, - { .id = POOLID, .label = "POLID" }, - { .id = CONTID, .label = "CNTID" }, - { .id = PID, .label = "PID" }, - { .id = PPID, .label = "PPID" }, - { .id = LWPID, .label = "LWPID" }, - { .id = TPGID, .label = "TPGID" }, - { .id = TGID, .label = "TGID" }, - { .id = PGRP, .label = "PGRP" }, - { .id = SESSION, .label = "SID" }, - { .id = 0, .label = NULL }, + [PROJID] = { .name = "PROJID", .title = "PRJID", .description = "Project ID", .flags = 0, .pidColumn = true, }, + [TASKID] = { .name = "TASKID", .title = "TSKID", .description = "Task ID", .flags = 0, .pidColumn = true, }, + [POOLID] = { .name = "POOLID", .title = "POLID", .description = "Pool ID", .flags = 0, .pidColumn = true, }, + [CONTID] = { .name = "CONTID", .title = "CNTID", .description = "Contract ID", .flags = 0, .pidColumn = true, }, + [LWPID] = { .name = "LWPID", .title = "LWPID", .description = "LWP ID", .flags = 0, .pidColumn = true, }, }; Process* SolarisProcess_new(const Settings* settings) { @@ -94,42 +67,34 @@ void Process_delete(Object* cast) { free(sp); } -void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field) { +static void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field) { const SolarisProcess* sp = (const SolarisProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; int n = sizeof(buffer) - 1; - switch ((int) field) { + switch (field) { // add Solaris-specific fields here - case ZONEID: xSnprintf(buffer, n, Process_pidFormat, sp->zoneid); break; - case PROJID: xSnprintf(buffer, n, Process_pidFormat, sp->projid); break; - case TASKID: xSnprintf(buffer, n, Process_pidFormat, sp->taskid); break; - case POOLID: xSnprintf(buffer, n, Process_pidFormat, sp->poolid); break; - case CONTID: xSnprintf(buffer, n, Process_pidFormat, sp->contid); break; - case ZONE: xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break; - case PID: xSnprintf(buffer, n, Process_pidFormat, sp->realpid); break; - case PPID: xSnprintf(buffer, n, Process_pidFormat, sp->realppid); break; - case LWPID: xSnprintf(buffer, n, Process_pidFormat, sp->lwpid); break; + case ZONEID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->zoneid); break; + case PROJID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->projid); break; + case TASKID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->taskid); break; + case POOLID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->poolid); break; + case CONTID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->contid); break; + case ZONE: Process_printLeftAlignedField(str, attr, sp->zname ? sp->zname : "global", ZONENAME_MAX/4); return; + case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->realpid); break; + case PPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->realppid); break; + case LWPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->lwpid); break; default: Process_writeField(this, str, field); return; } - RichString_append(str, attr, buffer); + RichString_appendWide(str, attr, buffer); } -long SolarisProcess_compare(const void* v1, const void* v2) { - const SolarisProcess *p1, *p2; - const Settings* settings = ((const Process*)v1)->settings; +static int SolarisProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const SolarisProcess* p1 = (const SolarisProcess*)v1; + const SolarisProcess* p2 = (const SolarisProcess*)v2; - if (settings->direction == 1) { - p1 = (const SolarisProcess*)v1; - p2 = (const SolarisProcess*)v2; - } else { - p2 = (const SolarisProcess*)v1; - p1 = (const SolarisProcess*)v2; - } - - switch ((int) settings->sortKey) { + switch (key) { case ZONEID: return SPACESHIP_NUMBER(p1->zoneid, p2->zoneid); case PROJID: @@ -149,7 +114,7 @@ long SolarisProcess_compare(const void* v1, const void* v2) { case LWPID: return SPACESHIP_NUMBER(p1->lwpid, p2->lwpid); default: - return Process_compare(v1, v2); + return Process_compareByKey_Base(v1, v2, key); } } @@ -164,3 +129,14 @@ bool Process_isThread(const Process* this) { return 0; } } + +const ProcessClass SolarisProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = Process_compare + }, + .writeField = SolarisProcess_writeField, + .compareByKey = SolarisProcess_compareByKey +}; diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h index 4756634..74cbb86 100644 --- a/solaris/SolarisProcess.h +++ b/solaris/SolarisProcess.h @@ -13,18 +13,6 @@ in the source distribution for its full text. #include #include -typedef enum SolarisProcessField_ { - // Add platform-specific fields here, with ids >= 100 - ZONEID = 100, - ZONE = 101, - PROJID = 102, - TASKID = 103, - POOLID = 104, - CONTID = 105, - LWPID = 106, - LAST_PROCESSFIELD = 107, -} SolarisProcessField; - typedef struct SolarisProcess_ { Process super; int kernel; @@ -46,18 +34,12 @@ typedef struct SolarisProcess_ { extern const ProcessClass SolarisProcess_class; -extern ProcessFieldData Process_fields[]; - -extern ProcessPidColumn Process_pidColumns[]; +extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; Process* SolarisProcess_new(const Settings* settings); void Process_delete(Object* cast); -void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field); - -long SolarisProcess_compare(const void* v1, const void* v2); - bool Process_isThread(const Process* this); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 4249fa6..2ba23ac 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -14,7 +14,6 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include @@ -25,9 +24,11 @@ in the source distribution for its full text. #include "CRT.h" - #define MAXCMDLINE 255 +static int pageSize; +static int pageSizeKB; + char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { char* zname; @@ -50,13 +51,18 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui spl->kd = kstat_open(); - pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN); + pageSize = sysconf(_SC_PAGESIZE); + if (pageSize == -1) + CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)"); + pageSizeKB = pageSize / 1024; - if (pl->cpuCount == 1 ) { + pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN); + if (pl->cpuCount == -1) + CRT_fatalError("Cannot get CPU count by sysconf(_SC_NPROCESSORS_ONLN)"); + else if (pl->cpuCount == 1) spl->cpus = xRealloc(spl->cpus, sizeof(CPUData)); - } else { + else spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); - } return pl; } @@ -65,11 +71,11 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { const SolarisProcessList* spl = (SolarisProcessList*) pl; int cpus = pl->cpuCount; kstat_t* cpuinfo = NULL; - int kchain = 0; 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; @@ -87,21 +93,31 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { // Calculate per-CPU statistics first for (int i = 0; i < cpus; i++) { if (spl->kd != NULL) { - cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys"); - } - if (cpuinfo != NULL) { - kchain = kstat_read(spl->kd, cpuinfo, NULL); - } - if (kchain != -1 ) { - idletime = kstat_data_lookup(cpuinfo, "cpu_nsec_idle"); - intrtime = kstat_data_lookup(cpuinfo, "cpu_nsec_intr"); - krnltime = kstat_data_lookup(cpuinfo, "cpu_nsec_kernel"); - usertime = kstat_data_lookup(cpuinfo, "cpu_nsec_user"); + if ((cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys")) != NULL) { + if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { + idletime = kstat_data_lookup(cpuinfo, "cpu_nsec_idle"); + intrtime = kstat_data_lookup(cpuinfo, "cpu_nsec_intr"); + krnltime = kstat_data_lookup(cpuinfo, "cpu_nsec_kernel"); + usertime = kstat_data_lookup(cpuinfo, "cpu_nsec_user"); + } + } } assert( (idletime != NULL) && (intrtime != NULL) && (krnltime != NULL) && (usertime != NULL) ); + if (pl->settings->showCPUFrequency) { + if (spl->kd != NULL) { + if ((cpuinfo = kstat_lookup(spl->kd, "cpu_info", i, NULL)) != NULL) { + if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { + cpu_freq = kstat_data_lookup(cpuinfo, "current_clock_Hz"); + } + } + } + + assert( cpu_freq != NULL ); + } + CPUData* cpuData = &(spl->cpus[i + arrskip]); uint64_t totaltime = (idletime->value.ui64 - cpuData->lidle) @@ -121,6 +137,8 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { 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 (cpus > 1) { userbuf += cpuData->userPercent; @@ -158,8 +176,8 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 1 - physical memory if (spl->kd != NULL && meminfo == NULL) { - // Look up the kstat chain just one, it never changes - meminfo = kstat_lookup(spl->kd, "unix", 0, "system_pages"); + // Look up the kstat chain just once, it never changes + meminfo = kstat_lookup(spl->kd, "unix", 0, "system_pages"); } if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd, meminfo, NULL); @@ -169,9 +187,9 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { freemem_pgs = kstat_data_lookup(meminfo, "freemem"); pages = kstat_data_lookup(meminfo, "pagestotal"); - pl->totalMem = totalmem_pgs->value.ui64 * CRT_pageSizeKB; - if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) { - pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * CRT_pageSizeKB; + pl->totalMem = totalmem_pgs->value.ui64 * pageSizeKB; + if (pl->totalMem > freemem_pgs->value.ui64 * pageSizeKB) { + pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * pageSizeKB; } else { pl->usedMem = 0; // This can happen in non-global zone (in theory) } @@ -179,13 +197,13 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pl->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" - pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; + pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * pageSizeKB; } else { // Fall back to basic sysconf if kstat isn't working - pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; + pl->totalMem = sysconf(_SC_PHYS_PAGES) * pageSize; pl->buffersMem = 0; pl->cachedMem = 0; - pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * CRT_pageSize); + pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * pageSize); } // Part 2 - swap @@ -215,8 +233,8 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { } free(spathbase); free(sl); - pl->totalSwap = totalswap * CRT_pageSizeKB; - pl->usedSwap = pl->totalSwap - (totalfree * CRT_pageSizeKB); + pl->totalSwap = totalswap * pageSizeKB; + pl->usedSwap = pl->totalSwap - (totalfree * pageSizeKB); } static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { @@ -323,8 +341,8 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* proc->pgrp = _psinfo->pr_pgid; proc->nlwp = _psinfo->pr_nlwp; proc->tty_nr = _psinfo->pr_ttydev; - proc->m_resident = _psinfo->pr_rssize / CRT_pageSizeKB; - proc->m_virt = _psinfo->pr_size / CRT_pageSizeKB; + proc->m_resident = _psinfo->pr_rssize; // KB + proc->m_virt = _psinfo->pr_size; // KB if (!preExisting) { sproc->realpid = _psinfo->pr_pid; diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index f800d9d..78362b6 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -33,6 +33,7 @@ typedef struct CPUData_ { double irqPercent; double idlePercent; double systemAllPercent; + double frequency; uint64_t luser; uint64_t lkrnl; uint64_t lintr; -- cgit v1.2.3