From 41af31be7ffbd34518b27aad56a4f54af6a8adf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 12 Jun 2021 18:17:28 +0200 Subject: 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 --- AffinityPanel.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'AffinityPanel.c') diff --git a/AffinityPanel.c b/AffinityPanel.c index 25169994..56d8d89c 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -383,7 +383,8 @@ 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++) { + /* TODO: skip offline CPUs */ char number[16]; xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); unsigned cpu_width = 4 + strlen(number); @@ -427,7 +428,8 @@ 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 (unsigned int i = 0; i < this->pl->existingCPUs; i++) { + /* TODO: skip offline CPUs */ const MaskItem* item = (const MaskItem*)Vector_get(this->cpuids, i); if (item->value) { Affinity_add(affinity, item->cpu); -- cgit v1.2.3