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 /pcp | |
parent | e341217fea844e1c45b7079146b9de7cb68e8c2a (diff) | |
parent | edf236f9fcf257c5266cead0c3bc45087d937e65 (diff) |
Merge branch 'cpu_count' of cgzones/htop
Diffstat (limited to 'pcp')
-rw-r--r-- | pcp/PCPProcessList.c | 28 | ||||
-rw-r--r-- | pcp/PCPProcessList.h | 2 |
2 files changed, 22 insertions, 8 deletions
diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c index 2731a8ae..ae974435 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); @@ -372,7 +375,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); @@ -538,7 +541,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++) @@ -547,7 +550,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++) @@ -607,7 +610,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); @@ -618,7 +621,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) @@ -671,3 +674,12 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { double period = (this->timestamp - sample) * 100; PCPProcessList_updateProcesses(this, period, ×tamp); } + +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/pcp/PCPProcessList.h b/pcp/PCPProcessList.h index f1784904..7f0f6fe4 100644 --- a/pcp/PCPProcessList.h +++ b/pcp/PCPProcessList.h @@ -69,4 +69,6 @@ void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); +bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id); + #endif |