diff options
author | Daniel Lange <DLange@git.local> | 2021-08-02 15:21:07 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2021-08-02 15:21:07 +0200 |
commit | ed82ce6456f0f904a0ab2b346b85d7cf46df109c (patch) | |
tree | 1b02b20548da6dbcdf53872c3c99a3c013588fd1 | |
parent | e341217fea844e1c45b7079146b9de7cb68e8c2a (diff) | |
parent | edf236f9fcf257c5266cead0c3bc45087d937e65 (diff) |
Merge branch 'cpu_count' of cgzones/htop
40 files changed, 554 insertions, 282 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c597627c..617ed305 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity --disable-unicode --disable-sensors + run: ./configure --enable-werror --enable-affinity --disable-unicode --disable-sensors - name: Enable compatibility modes run: | sed -i 's/#define HAVE_FSTATAT 1/#undef HAVE_FSTATAT/g' config.h @@ -26,7 +26,7 @@ jobs: - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-unicode --disable-sensors" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-affinity --disable-unicode --disable-sensors" build-ubuntu-latest-minimal-clang: runs-on: ubuntu-latest @@ -44,11 +44,11 @@ jobs: - name: Bootstrap run: ./autogen.sh - name: Configure - run: ./configure --enable-werror --enable-linux-affinity --disable-unicode --disable-sensors + run: ./configure --enable-werror --enable-affinity --disable-unicode --disable-sensors - name: Build run: make -k - name: Distcheck - run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-linux-affinity --disable-unicode --disable-sensors" + run: make distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-werror --enable-affinity --disable-unicode --disable-sensors" build-ubuntu-latest-full-featured-gcc: runs-on: ubuntu-latest @@ -34,7 +34,7 @@ in the source distribution for its full text. #include "Vector.h" #include "XUtils.h" -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) #include "Affinity.h" #include "AffinityPanel.h" #endif @@ -302,10 +302,10 @@ static Htop_Reaction actionSetAffinity(State* st) { if (Settings_isReadonly()) return HTOP_OK; - if (st->pl->cpuCount == 1) + if (st->pl->activeCPUs == 1) return HTOP_OK; -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) const Process* p = (const Process*) Panel_getSelected((Panel*)st->mainPanel); if (!p) return HTOP_OK; @@ -328,8 +328,11 @@ static Htop_Reaction actionSetAffinity(State* st) { Affinity_delete(affinity2); } Object_delete(affinityPanel); -#endif return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; +#else + return HTOP_OK; +#endif + } static Htop_Reaction actionKill(State* st) { @@ -484,7 +487,7 @@ static const struct { { .key = " F9 k: ", .roInactive = true, .info = "kill process/tagged processes" }, { .key = " F7 ]: ", .roInactive = true, .info = "higher priority (root only)" }, { .key = " F8 [: ", .roInactive = false, .info = "lower priority (+ nice)" }, -#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) +#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)) { .key = " a: ", .roInactive = true, .info = "set CPU affinity" }, #endif { .key = " e: ", .roInactive = false, .info = "show process environment" }, @@ -22,7 +22,7 @@ in the source distribution for its full text. #else #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS #endif -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) #include <sched.h> #endif @@ -59,7 +59,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) { if (ok) { affinity = Affinity_new(pl); if (hwloc_bitmap_last(cpuset) == -1) { - for (unsigned int i = 0; i < pl->cpuCount; i++) { + for (unsigned int i = 0; i < pl->existingCPUs; i++) { Affinity_add(affinity, i); } } else { @@ -84,7 +84,7 @@ bool Affinity_set(Process* proc, Arg arg) { return ok; } -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) Affinity* Affinity_get(const Process* proc, ProcessList* pl) { cpu_set_t cpuset; @@ -93,7 +93,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) { return NULL; Affinity* affinity = Affinity_new(pl); - for (unsigned int i = 0; i < pl->cpuCount; i++) { + for (unsigned int i = 0; i < pl->existingCPUs; i++) { if (CPU_ISSET(i, &cpuset)) { Affinity_add(affinity, i); } @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "ProcessList.h" -#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY) +#if defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY) #include <stdbool.h> #include "Object.h" @@ -20,8 +20,8 @@ in the source distribution for its full text. #endif -#if defined(HAVE_LIBHWLOC) && defined(HAVE_LINUX_AFFINITY) -#error hwloc and linux affinity are mutual exclusive. +#if defined(HAVE_LIBHWLOC) && defined(HAVE_AFFINITY) +#error hwloc and affinity support are mutual exclusive. #endif @@ -38,12 +38,12 @@ void Affinity_delete(Affinity* this); void Affinity_add(Affinity* this, unsigned int id); -#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY) +#if defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY) Affinity* Affinity_get(const Process* proc, ProcessList* pl); bool Affinity_set(Process* proc, Arg arg); -#endif /* HAVE_LIBHWLOC || HAVE_LINUX_AFFINITY */ +#endif /* HAVE_LIBHWLOC || HAVE_AFFINITY */ #endif diff --git a/AffinityPanel.c b/AffinityPanel.c index 25169994..dbce5ca0 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -383,7 +383,10 @@ Panel* AffinityPanel_new(ProcessList* pl, const Affinity* affinity, int* width) Panel_setHeader(super, "Use CPUs:"); unsigned int curCpu = 0; - for (unsigned int i = 0; i < pl->cpuCount; i++) { + for (unsigned int i = 0; i < pl->existingCPUs; i++) { + if (!ProcessList_isCPUonline(this->pl, i)) + continue; + char number[16]; xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); unsigned cpu_width = 4 + strlen(number); @@ -427,7 +430,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { Affinity_add(affinity, i); hwloc_bitmap_foreach_end(); #else - for (unsigned int i = 0; i < this->pl->cpuCount; i++) { + for (int i = 0; i < Vector_size(this->cpuids); i++) { const MaskItem* item = (const MaskItem*)Vector_get(this->cpuids, i); if (item->value) { Affinity_add(affinity, item->cpu); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index c098b470..384c8864 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -94,9 +94,9 @@ const PanelClass AvailableMetersPanel_class = { // Handle (&CPUMeter_class) entries in the AvailableMetersPanel static void AvailableMetersPanel_addCPUMeters(Panel* super, const MeterClass* type, const ProcessList* pl) { - if (pl->cpuCount > 1) { + if (pl->existingCPUs > 1) { Panel_add(super, (Object*) ListItem_new("CPU average", 0)); - for (unsigned int i = 1; i <= pl->cpuCount; i++) { + for (unsigned int i = 1; i <= pl->existingCPUs; i++) { char buffer[50]; xSnprintf(buffer, sizeof(buffer), "%s %d", type->uiName, Settings_cpuId(pl->settings, i - 1)); Panel_add(super, (Object*) ListItem_new(buffer, i)); @@ -43,7 +43,7 @@ static void CPUMeter_init(Meter* this) { unsigned int cpu = this->param; if (cpu == 0) { Meter_setCaption(this, "Avg"); - } else if (this->pl->cpuCount > 1) { + } else if (this->pl->activeCPUs > 1) { char caption[10]; xSnprintf(caption, sizeof(caption), "%3u", Settings_cpuId(this->pl->settings, cpu - 1)); Meter_setCaption(this, caption); @@ -59,21 +59,24 @@ static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) { } static void CPUMeter_updateValues(Meter* this) { + memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); + unsigned int cpu = this->param; - if (cpu > this->pl->cpuCount) { + if (cpu > this->pl->existingCPUs) { xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "absent"); - for (uint8_t i = 0; i < this->curItems; i++) - this->values[i] = 0; return; } - memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); + + double percent = Platform_setCPUValues(this, cpu); + if (isnan(percent)) { + xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "offline"); + return; + } char cpuUsageBuffer[8] = { 0 }; char cpuFrequencyBuffer[16] = { 0 }; char cpuTemperatureBuffer[16] = { 0 }; - double percent = Platform_setCPUValues(this, cpu); - if (this->pl->settings->showCPUUsage) { xSnprintf(cpuUsageBuffer, sizeof(cpuUsageBuffer), "%.1f%%", percent); } @@ -112,7 +115,7 @@ static void CPUMeter_display(const Object* cast, RichString* out) { int len; const Meter* this = (const Meter*)cast; - if (this->param > this->pl->cpuCount) { + if (this->param > this->pl->existingCPUs) { RichString_appendAscii(out, CRT_colors[METER_TEXT], "absent"); return; } @@ -206,7 +209,7 @@ static void AllCPUsMeter_updateValues(Meter* this) { } static void CPUMeterCommonInit(Meter* this, int ncol) { - unsigned int cpus = this->pl->cpuCount; + unsigned int cpus = this->pl->existingCPUs; CPUMeterData* data = this->meterData; if (!data) { data = this->meterData = xMalloc(sizeof(CPUMeterData)); diff --git a/CommandLine.c b/CommandLine.c index 66df3777..d932bb04 100644 --- a/CommandLine.c +++ b/CommandLine.c @@ -295,7 +295,7 @@ int CommandLine_run(const char* name, int argc, char** argv) { Hashtable* dm = DynamicMeters_new(); ProcessList* pl = ProcessList_new(ut, dm, flags.pidMatchList, flags.userId); - Settings* settings = Settings_new(pl->cpuCount); + Settings* settings = Settings_new(pl->activeCPUs); pl->settings = settings; Header* header = Header_new(pl, settings, 2); diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index c91e6a2d..bb3b05ed 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -47,12 +47,12 @@ static void LoadAverageMeter_updateValues(Meter* this) { if (this->values[0] < 1.0) { this->curAttributes = OK_attributes; this->total = 1.0; - } else if (this->values[0] < this->pl->cpuCount) { + } else if (this->values[0] < this->pl->activeCPUs) { this->curAttributes = Medium_attributes; - this->total = this->pl->cpuCount; + this->total = this->pl->activeCPUs; } else { this->curAttributes = High_attributes; - this->total = 2 * this->pl->cpuCount; + this->total = 2 * this->pl->activeCPUs; } xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]); @@ -79,12 +79,12 @@ static void LoadMeter_updateValues(Meter* this) { if (this->values[0] < 1.0) { this->curAttributes = OK_attributes; this->total = 1.0; - } else if (this->values[0] < this->pl->cpuCount) { + } else if (this->values[0] < this->pl->activeCPUs) { this->curAttributes = Medium_attributes; - this->total = this->pl->cpuCount; + this->total = this->pl->activeCPUs; } else { this->curAttributes = High_attributes; - this->total = 2 * this->pl->cpuCount; + this->total = 2 * this->pl->activeCPUs; } xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f", this->values[0]); @@ -824,7 +824,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field case PERCENT_NORM_CPU: { float cpuPercentage = this->percent_cpu; if (field == PERCENT_NORM_CPU) { - cpuPercentage /= this->processList->cpuCount; + cpuPercentage /= this->processList->activeCPUs; } if (cpuPercentage > 999.9F) { xSnprintf(buffer, n, "%4u ", (unsigned int)cpuPercentage); diff --git a/ProcessList.c b/ProcessList.c index d3a773b3..8ab4d8f6 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -34,7 +34,8 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users this->userId = userId; // set later by platform-specific code - this->cpuCount = 0; + this->activeCPUs = 0; + this->existingCPUs = 0; this->monotonicMs = 0; // always maintain valid realtime timestamps diff --git a/ProcessList.h b/ProcessList.h index da4a50da..93958cbb 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -83,12 +83,15 @@ typedef struct ProcessList_ { memory_t usedSwap; memory_t cachedSwap; - unsigned int cpuCount; + unsigned int activeCPUs; + unsigned int existingCPUs; } ProcessList; +/* Implemented by platforms */ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* pidMatchList, uid_t userId); void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); +bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id); ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* pidMatchList, uid_t userId); @@ -80,8 +80,11 @@ To install on the local system run `make install`. By default `make install` ins enable Performance Co-Pilot support via a new pcp-htop utility dependency: *libpcp* default: *no* + * `--enable-affinity`: + enable `sched_setaffinity(2)` and `sched_getaffinity(2)` for affinity support; conflicts with hwloc + default: *check* * `--enable-hwloc`: - enable hwloc support for CPU affinity; disables Linux affinity + enable hwloc support for CPU affinity; disables affinity support dependency: *libhwloc* default: *no* * `--enable-static`: @@ -113,9 +116,6 @@ To install on the local system run `make install`. By default `make install` ins * `--enable-ancient-vserver`: enable ancient VServer support (implies `--enable-vserver`) default: *no* - * `--enable-linux-affinity`: - enable Linux `sched_setaffinity(2)` and `sched_getaffinity(2)` for affinity support; conflicts with hwloc - default: *check* * `--enable-delayacct`: enable Linux delay accounting support dependencies: *pkg-config*(build-time), *libnl-3* and *libnl-genl-3* diff --git a/TasksMeter.c b/TasksMeter.c index 3840bf9b..9fb6c804 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -28,7 +28,7 @@ static void TasksMeter_updateValues(Meter* this) { this->values[0] = pl->kernelThreads; this->values[1] = pl->userlandThreads; this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads; - this->values[3] = MINIMUM(pl->runningTasks, pl->cpuCount); + this->values[3] = MINIMUM(pl->runningTasks, pl->activeCPUs); this->total = pl->totalTasks; xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%d/%d", (int) this->values[3], (int) this->total); diff --git a/UptimeMeter.c b/UptimeMeter.c index 51ceef8c..9036e539 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -19,7 +19,7 @@ static const int UptimeMeter_attributes[] = { static void UptimeMeter_updateValues(Meter* this) { int totalseconds = Platform_getUptime(); - if (totalseconds == -1) { + if (totalseconds <= 0) { xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "(unknown)"); return; } diff --git a/configure.ac b/configure.ac index be40187a..1c83c28e 100644 --- a/configure.ac +++ b/configure.ac @@ -355,9 +355,44 @@ AC_CHECK_FUNCS( [set_escdelay] ) AC_CHECK_FUNCS( [getmouse] ) +AC_ARG_ENABLE([affinity], + [AS_HELP_STRING([--enable-affinity], + [enable sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])], + [], + [enable_affinity=check]) +if test "x$enable_affinity" = xcheck; then + if test "x$enable_hwloc" = xyes; then + enable_affinity=no + else + AC_MSG_CHECKING([for usable sched_setaffinity]) + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ + #include <sched.h> + #include <errno.h> + static cpu_set_t cpuset; + ]], [[ + CPU_ZERO(&cpuset); + sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); + if (errno == ENOSYS) return 1; + ]])], + [enable_affinity=yes + AC_MSG_RESULT([yes])], + [enable_affinity=no + AC_MSG_RESULT([no])], + [AC_MSG_RESULT([yes (assumed while cross compiling)])]) + fi +fi +if test "x$enable_affinity" = xyes; then + if test "x$enable_hwloc" = xyes; then + AC_MSG_ERROR([--enable-hwloc and --enable-affinity are mutual exclusive. Specify at most one of them.]) + fi + AC_DEFINE([HAVE_AFFINITY], [1], [Define if sched_setaffinity and sched_getaffinity are to be used.]) +fi + + AC_ARG_ENABLE([hwloc], [AS_HELP_STRING([--enable-hwloc], - [enable hwloc support for CPU affinity; disables Linux affinity; requires libhwloc @<:@default=no@:>@])], + [enable hwloc support for CPU affinity; disables affinity support; requires libhwloc @<:@default=no@:>@])], [], [enable_hwloc=no]) case "$enable_hwloc" in @@ -433,41 +468,6 @@ if test "x$enable_ancient_vserver" = xyes; then fi -AC_ARG_ENABLE([linux_affinity], - [AS_HELP_STRING([--enable-linux-affinity], - [enable Linux sched_setaffinity and sched_getaffinity for affinity support, conflicts with hwloc @<:@default=check@:>@])], - [], - [enable_linux_affinity=check]) -if test "x$enable_linux_affinity" = xcheck; then - if test "x$enable_hwloc" = xyes; then - enable_linux_affinity=no - else - AC_MSG_CHECKING([for usable sched_setaffinity]) - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[ - #include <sched.h> - #include <errno.h> - static cpu_set_t cpuset; - ]], [[ - CPU_ZERO(&cpuset); - sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); - if (errno == ENOSYS) return 1; - ]])], - [enable_linux_affinity=yes - AC_MSG_RESULT([yes])], - [enable_linux_affinity=no - AC_MSG_RESULT([no])], - [AC_MSG_RESULT([yes (assumed while cross compiling)])]) - fi -fi -if test "x$enable_linux_affinity" = xyes; then - if test "x$enable_hwloc" = xyes; then - AC_MSG_ERROR([--enable-hwloc and --enable-linux-affinity are mutual exclusive. Specify at most one of them.]) - fi - AC_DEFINE([HAVE_LINUX_AFFINITY], [1], [Define if Linux sched_setaffinity and sched_getaffinity are to be used.]) -fi - - AC_ARG_ENABLE([capabilities], [AS_HELP_STRING([--enable-capabilities], [enable Linux capabilities support; requires libcap @<:@default=check@:>@])], @@ -688,11 +688,11 @@ AC_MSG_RESULT([ (Linux) openvz: $enable_openvz (Linux) vserver: $enable_vserver (Linux) ancient vserver: $enable_ancient_vserver - (Linux) affinity: $enable_linux_affinity (Linux) delay accounting: $enable_delayacct (Linux) sensors: $enable_sensors (Linux) capabilities: $enable_capabilities unicode: $enable_unicode + affinity: $enable_affinity hwloc: $enable_hwloc debug: $enable_debug static: $enable_static diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 91d62c4a..8d14efe1 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -134,7 +134,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, H ProcessList_init(&this->super, Class(DarwinProcess), usersTable, dynamicMeters, pidMatchList, userId); /* Initialize the CPU information */ - this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load); + this->super.activeCPUs = ProcessList_allocateCPULoadInfo(&this->prev_load); + // TODO: support offline CPUs and hot swapping + this->super.existingCPUs = this->super.activeCPUs; ProcessList_getHostInfo(&this->host_info); ProcessList_allocateCPULoadInfo(&this->curr_load); @@ -184,13 +186,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { /* Get the time difference */ dpl->global_diff = 0; - for (unsigned int i = 0; i < dpl->super.cpuCount; ++i) { + for (unsigned int i = 0; i < dpl->super.existingCPUs; ++i) { for (size_t j = 0; j < CPU_STATE_MAX; ++j) { dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; } } - const double time_interval = ticksToNanoseconds(dpl->global_diff) / (double) dpl->super.cpuCount; + const double time_interval = ticksToNanoseconds(dpl->global_diff) / (double) dpl->super.activeCPUs; /* Clear the thread counts */ super->kernelThreads = 0; @@ -234,3 +236,12 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { free(ps); } + +bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id) { + assert(id < super->existingCPUs); + + // TODO: support offline CPUs and hot swapping + (void) super; (void) id; + + return true; +} diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index bd39ab0e..24259d3e 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -34,4 +34,6 @@ 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/darwin/Platform.c b/darwin/Platform.c index df7e133f..d4d15dad 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -186,21 +186,21 @@ int Platform_getMaxPid() { static double Platform_setCPUAverageValues(Meter* mtr) { const ProcessList* dpl = mtr->pl; - unsigned int cpus = dpl->cpuCount; + unsigned int activeCPUs = dpl->activeCPUs; double sumNice = 0.0; double sumNormal = 0.0; double sumKernel = 0.0; double sumPercent = 0.0; - for (unsigned int i = 1; i <= cpus; i++) { + for (unsigned int i = 1; i <= dpl->existingCPUs; i++) { sumPercent += Platform_setCPUValues(mtr, i); sumNice += mtr->values[CPU_METER_NICE]; sumNormal += mtr->values[CPU_METER_NORMAL]; sumKernel += mtr->values[CPU_METER_KERNEL]; } - mtr->values[CPU_METER_NICE] = sumNice / cpus; - mtr->values[CPU_METER_NORMAL] = sumNormal / cpus; - mtr->values[CPU_METER_KERNEL] = sumKernel / cpus; - return sumPercent / cpus; + mtr->values[CPU_METER_NICE] = sumNice / activeCPUs; + mtr->values[CPU_METER_NORMAL] = sumNormal / activeCPUs; + mtr->values[CPU_METER_KERNEL] = sumKernel / activeCPUs; + return sumPercent / activeCPUs; } double Platform_setCPUValues(Meter* mtr, unsigned int cpu) { diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 9bf6ffef..9b1bb41f 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -95,13 +95,15 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, H sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_o, &len, NULL, 0); } - pl->cpuCount = MAXIMUM(cpus, 1); + pl->existingCPUs = MAXIMUM(cpus, 1); + // TODO: support offline CPUs and hot swapping + pl->activeCPUs = pl->existingCPUs; if (cpus == 1 ) { dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); } else { // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + dfpl->cpus = xRealloc(dfpl->cpus, (pl->existingCPUs + 1) * sizeof(CPUData)); } len = sizeof(kernelFScale); @@ -140,8 +142,8 @@ void ProcessList_delete(ProcessList* this) { static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl; - unsigned int cpus = pl->cpuCount; // actual CPU count - unsigned int maxcpu = cpus; // max iteration (in case we have average + smp) + unsigned int cpus = pl->existingCPUs; // actual CPU count + unsigned int maxcpu = cpus; // max iteration (in case we have average + smp) int cp_times_offset; assert(cpus > 0); @@ -430,7 +432,6 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { int count = 0; - // TODO Kernel Threads seem to be skipped, need to figure out the correct flag const struct kinfo |