diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-06-12 18:17:28 +0200 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2021-07-18 07:44:02 +0200 |
commit | 41af31be7ffbd34518b27aad56a4f54af6a8adf3 (patch) | |
tree | 6e86813a332e93f7ee22b873d7522fa766b4af97 /CPUMeter.c | |
parent | c9abd788b17ab28424961310b7e224498510780c (diff) |
Rework CPU counting
Currently htop does not support offline CPUs and hot-swapping, e.g. via
echo 0 > /sys/devices/system/cpu/cpu2/online
Split the current single cpuCount variable into activeCPUs and
existingCPUs.
Supersedes: #650
Related: #580
Diffstat (limited to 'CPUMeter.c')
-rw-r--r-- | CPUMeter.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -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)); |