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 /pcp | |
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 'pcp')
-rw-r--r-- | pcp/PCPProcessList.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c index fccd60d7..a27bd474 100644 --- a/pcp/PCPProcessList.c +++ b/pcp/PCPProcessList.c @@ -33,10 +33,13 @@ static int PCPProcessList_computeCPUcount(void) { static void PCPProcessList_updateCPUcount(PCPProcessList* this) { ProcessList* pl = &(this->super); unsigned int cpus = PCPProcessList_computeCPUcount(); - if (cpus == pl->cpuCount) + if (cpus == pl->existingCPUs) return; - pl->cpuCount = cpus; + pl->existingCPUs = cpus; + // TODO: support offline CPUs and hot swapping + pl->activeCPUs = pl->existingCPUs; + free(this->percpu); free(this->values); @@ -79,7 +82,7 @@ void ProcessList_delete(ProcessList* pl) { PCPProcessList* this = (PCPProcessList*) pl; ProcessList_done(pl); free(this->values); - for (unsigned int i = 0; i < pl->cpuCount; i++) + for (unsigned int i = 0; i < pl->existingCPUs; i++) free(this->percpu[i]); free(this->percpu); free(this->cpu); @@ -371,7 +374,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period, float percent_cpu = (pp->utime + pp->stime - lasttimes) / period * 100.0; proc->percent_cpu = isnan(percent_cpu) ? - 0.0 : CLAMP(percent_cpu, 0.0, pl->cpuCount * 100.0); + 0.0 : CLAMP(percent_cpu, 0.0, pl->activeCPUs * 100.0); proc->percent_mem = proc->m_resident / (double)pl->totalMem * 100.0; PCPProcessList_updateUsername(proc, pid, offset, pl->usersTable); @@ -539,7 +542,7 @@ static void PCPProcessList_updateAllCPUTime(PCPProcessList* this, Metric metric, static void PCPProcessList_updatePerCPUTime(PCPProcessList* this, Metric metric, CPUMetric cpumetric) { - int cpus = this->super.cpuCount; + int cpus = this->super.existingCPUs; if (Metric_values(metric, this->values, cpus, PM_TYPE_U64) == NULL) memset(this->values, 0, cpus * sizeof(pmAtomValue)); for (int i = 0; i < cpus; i++) @@ -548,7 +551,7 @@ static void PCPProcessList_updatePerCPUTime(PCPProcessList* this, Metric metric, static void PCPProcessList_updatePerCPUReal(PCPProcessList* this, Metric metric, CPUMetric cpumetric) { - int cpus = this->super.cpuCount; + int cpus = this->super.existingCPUs; if (Metric_values(metric, this->values, cpus, PM_TYPE_DOUBLE) == NULL) memset(this->values, 0, cpus * sizeof(pmAtomValue)); for (int i = 0; i < cpus; i++) @@ -608,7 +611,7 @@ static void PCPProcessList_updateHeader(ProcessList* super, const Settings* sett PCPProcessList_updateAllCPUTime(this, PCP_CPU_GUEST, CPU_GUEST_TIME); PCPProcessList_deriveCPUTime(this->cpu); - for (unsigned int i = 0; i < super->cpuCount; i++) + for (unsigned int i = 0; i < super->existingCPUs; i++) PCPProcessList_backupCPUTime(this->percpu[i]); PCPProcessList_updatePerCPUTime(this, PCP_PERCPU_USER, CPU_USER_TIME); PCPProcessList_updatePerCPUTime(this, PCP_PERCPU_NICE, CPU_NICE_TIME); @@ -619,7 +622,7 @@ static void PCPProcessList_updateHeader(ProcessList* super, const Settings* sett PCPProcessList_updatePerCPUTime(this, PCP_PERCPU_SOFTIRQ, CPU_SOFTIRQ_TIME); PCPProcessList_updatePerCPUTime(this, PCP_PERCPU_STEAL, CPU_STEAL_TIME); PCPProcessList_updatePerCPUTime(this, PCP_PERCPU_GUEST, CPU_GUEST_TIME); - for (unsigned int i = 0; i < super->cpuCount; i++) + for (unsigned int i = 0; i < super->existingCPUs; i++) PCPProcessList_deriveCPUTime(this->percpu[i]); if (settings->showCPUFrequency) |