From d77fae999805227e9f6d66e66e81b38ed176eb86 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Tue, 17 Mar 2026 09:26:34 +0800 Subject: [PATCH 1/5] Allow guest time to be hidden in "non-detailed" CPU meter When both the options "Add guest time in CPU meter percentage" and "Detailed CPU time" are turned off, the CPU meter used to show the "virtual" CPU time in the bar display as a glitch. Now fix it. Signed-off-by: Kang-Che Sung --- linux/Platform.c | 6 +++++- pcp/Platform.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/linux/Platform.c b/linux/Platform.c index cecaf3b5d..e94b9e65b 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -370,8 +370,12 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; } else { v[CPU_METER_KERNEL] = cpuData->systemAllPeriod / total * 100.0; + this->curItems = 3; + v[CPU_METER_IRQ] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; - this->curItems = 4; + if (settings->accountGuestInCPUMeter) { + this->curItems = 4; + } } percent = sumPositiveValues(v, this->curItems); diff --git a/pcp/Platform.c b/pcp/Platform.c index c335b379d..e31abf791 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -574,9 +574,13 @@ static double Platform_setOneCPUValues(Meter* this, const Settings* settings, pm v[CPU_METER_IOWAIT] = values[CPU_IOWAIT_PERIOD].ull / total * 100.0; } else { v[CPU_METER_KERNEL] = values[CPU_SYSTEM_ALL_PERIOD].ull / total * 100.0; + this->curItems = 3; + value = values[CPU_STEAL_PERIOD].ull + values[CPU_GUEST_PERIOD].ull; v[CPU_METER_IRQ] = value / total * 100.0; - this->curItems = 4; + if (settings->accountGuestInCPUMeter) { + this->curItems = 4; + } } percent = sumPositiveValues(v, this->curItems); From c4d997832e9efd19134d159cd288ed89e39e6566 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Tue, 16 Jun 2026 14:22:16 +0800 Subject: [PATCH 2/5] netbsd & openbsd: Adjust CPU meter value assignment code The "curItems" member of the CPUMeter will be set to not larger than necessary. (Note: NetBSD and OpenBSD code currently do not support "softirq", "steal", "guest" and "iowait" times.) The meter values of "softirq", "steal", "guest" and "iowait" are now unconditionally set to 0.0 on update, just to be safe. No user-visible change in behavior is intended. Signed-off-by: Kang-Che Sung --- netbsd/Platform.c | 16 ++++++++-------- openbsd/Platform.c | 17 ++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/netbsd/Platform.c b/netbsd/Platform.c index 5f2a716f8..e5c3b8cc0 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -267,17 +267,17 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (host->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->sysPeriod / total * 100.0; v[CPU_METER_IRQ] = cpuData->intrPeriod / total * 100.0; - v[CPU_METER_SOFTIRQ] = 0.0; - v[CPU_METER_STEAL] = 0.0; - v[CPU_METER_GUEST] = 0.0; - v[CPU_METER_IOWAIT] = 0.0; - v[CPU_METER_FREQUENCY] = NAN; - this->curItems = 8; + this->curItems = 4; } else { v[CPU_METER_KERNEL] = cpuData->sysAllPeriod / total * 100.0; - v[CPU_METER_IRQ] = 0.0; // No steal nor guest on NetBSD - this->curItems = 4; + v[CPU_METER_IRQ] = 0.0; + this->curItems = 3; } + v[CPU_METER_SOFTIRQ] = 0.0; + v[CPU_METER_STEAL] = 0.0; + v[CPU_METER_GUEST] = 0.0; + v[CPU_METER_IOWAIT] = 0.0; + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; totalPercent = CLAMP(totalPercent, 0.0, 100.0); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 066e0672b..cf51831bb 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -218,19 +218,18 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { if (host->settings->detailedCPUTime) { v[CPU_METER_KERNEL] = cpuData->sysPeriod / total * 100.0; v[CPU_METER_IRQ] = cpuData->intrPeriod / total * 100.0; - v[CPU_METER_SOFTIRQ] = 0.0; - v[CPU_METER_STEAL] = 0.0; - v[CPU_METER_GUEST] = 0.0; - v[CPU_METER_IOWAIT] = 0.0; - v[CPU_METER_FREQUENCY] = NAN; - this->curItems = 8; + this->curItems = 4; } else { v[CPU_METER_KERNEL] = cpuData->sysAllPeriod / total * 100.0; - v[CPU_METER_IRQ] = 0.0; // No steal nor guest on OpenBSD - this->curItems = 4; + v[CPU_METER_IRQ] = 0.0; + this->curItems = 3; } - totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; + v[CPU_METER_SOFTIRQ] = 0.0; + v[CPU_METER_STEAL] = 0.0; + v[CPU_METER_GUEST] = 0.0; + v[CPU_METER_IOWAIT] = 0.0; + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; totalPercent = CLAMP(totalPercent, 0.0, 100.0); v[CPU_METER_TEMPERATURE] = NAN; From c076c65b6c39bfa97809bc142e075f5bcac63be8 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Tue, 16 Jun 2026 14:30:47 +0800 Subject: [PATCH 3/5] Revert "Fix CPU virtualization bar color and help text in non-detailed mode" This reverts commit 47aeb0a1f282fe294c6ba1e5dbebe05157b6e88c. --- Action.c | 4 ++-- CPUMeter.c | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Action.c b/Action.c index d630cb80d..7f0920546 100644 --- a/Action.c +++ b/Action.c @@ -804,8 +804,8 @@ static Htop_Reaction actionHelp(State* st) { addbartext(CRT_colors[CPU_IOWAIT], "/", "io-wait"); addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } else { - addbartext(CRT_colors[CPU_GUEST], "/", "virt"); - addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); + addbartext(CRT_colors[CPU_GUEST], "/", "guest"); + addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } addattrstr(CRT_colors[BAR_BORDER], "]"); diff --git a/CPUMeter.c b/CPUMeter.c index 7bc096dbc..960db5015 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -36,13 +36,6 @@ static const int CPUMeter_attributes[] = { CPU_IOWAIT }; -static const int CPUMeter_attributes_summary[] = { - CPU_NICE, - CPU_NORMAL, - CPU_SYSTEM, - CPU_GUEST -}; - typedef struct CPUMeterData_ { unsigned int cpus; Meter** meters; @@ -89,11 +82,6 @@ static void CPUMeter_updateValues(Meter* this) { const Machine* host = this->host; const Settings* settings = host->settings; - if (settings->detailedCPUTime) { - this->curAttributes = CPUMeter_attributes; - } else { - this->curAttributes = CPUMeter_attributes_summary; - } unsigned int cpu = this->param; if (cpu > host->existingCPUs) { From 7b8233f327777346511e910586b9a7143fc41812 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Tue, 16 Jun 2026 14:30:50 +0800 Subject: [PATCH 4/5] Restore "virtualized" word for non-detailed CPU meter in help screen The time displayed is (steal+guest), not just guest CPU time. Regression from 3d8fa0b926a463006773534411df91be2b9d68ed Signed-off-by: Kang-Che Sung --- Action.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Action.c b/Action.c index 7f0920546..c7b80407a 100644 --- a/Action.c +++ b/Action.c @@ -804,8 +804,8 @@ static Htop_Reaction actionHelp(State* st) { addbartext(CRT_colors[CPU_IOWAIT], "/", "io-wait"); addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } else { - addbartext(CRT_colors[CPU_GUEST], "/", "guest"); - addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); + addbartext(CRT_colors[CPU_GUEST], "/", "virtualized"); + addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } addattrstr(CRT_colors[BAR_BORDER], "]"); From b04df0813719d5c19c1815579b62524266a2214c Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Tue, 16 Jun 2026 14:30:58 +0800 Subject: [PATCH 5/5] Use CPU_METER_STEAL for 'virtualized' CPU time in non-detailed mode Linux and PCP platform code used to write the 'virtualized' (steal+guest) CPU time into the CPU_METER_IRQ item when the "detailed CPU time" option is off, which would result in a wrong color painted for virtual CPU time in bar mode. Write the 'virtualized' CPU time to CPU_METER_STEAL instead, which is more appropriate for the job. Also update the "virtualized" CPU meter item in the help screen: (1) The color is now CPU_STEAL for consistency. (2) In monochrome mode, two dummy items are displayed before the "virtualized" word so that the bar meter symbol mapping is correct. Signed-off-by: Kang-Che Sung --- Action.c | 5 ++++- CPUMeter.c | 6 +++--- linux/Platform.c | 6 ++++-- pcp/Platform.c | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Action.c b/Action.c index c7b80407a..8d1572cbe 100644 --- a/Action.c +++ b/Action.c @@ -803,8 +803,11 @@ static Htop_Reaction actionHelp(State* st) { addbartext(CRT_colors[CPU_GUEST], "/", "guest"); addbartext(CRT_colors[CPU_IOWAIT], "/", "io-wait"); addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); + } else if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { + addbartext(CRT_colors[CPU_STEAL], "/-/-/", "virtualized"); + addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } else { - addbartext(CRT_colors[CPU_GUEST], "/", "virtualized"); + addbartext(CRT_colors[CPU_STEAL], "/", "virtualized"); addbartext(CRT_colors[BAR_SHADOW], " ", "used%"); } addattrstr(CRT_colors[BAR_BORDER], "]"); diff --git a/CPUMeter.c b/CPUMeter.c index 960db5015..205a69ea4 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -185,10 +185,10 @@ static void CPUMeter_display(const Object* cast, RichString* out) { len = xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_NICE]); RichString_appendAscii(out, CRT_colors[METER_TEXT], "low:"); RichString_appendnAscii(out, CRT_colors[CPU_NICE_TEXT], buffer, len); - if (isNonnegative(this->values[CPU_METER_IRQ])) { - len = xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_IRQ]); + if (isNonnegative(this->values[CPU_METER_STEAL])) { + len = xSnprintf(buffer, sizeof(buffer), "%5.1f%% ", this->values[CPU_METER_STEAL]); RichString_appendAscii(out, CRT_colors[METER_TEXT], "vir:"); - RichString_appendnAscii(out, CRT_colors[CPU_GUEST], buffer, len); + RichString_appendnAscii(out, CRT_colors[CPU_STEAL], buffer, len); } } diff --git a/linux/Platform.c b/linux/Platform.c index e94b9e65b..026294343 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -372,9 +372,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_KERNEL] = cpuData->systemAllPeriod / total * 100.0; this->curItems = 3; - v[CPU_METER_IRQ] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; + v[CPU_METER_IRQ] = 0.0; // Accounted in 'kernel' + v[CPU_METER_SOFTIRQ] = 0.0; // Accounted in 'kernel' + v[CPU_METER_STEAL] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; if (settings->accountGuestInCPUMeter) { - this->curItems = 4; + this->curItems = 6; } } diff --git a/pcp/Platform.c b/pcp/Platform.c index e31abf791..f0f225b14 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -576,10 +576,12 @@ static double Platform_setOneCPUValues(Meter* this, const Settings* settings, pm v[CPU_METER_KERNEL] = values[CPU_SYSTEM_ALL_PERIOD].ull / total * 100.0; this->curItems = 3; + v[CPU_METER_IRQ] = 0.0; + v[CPU_METER_SOFTIRQ] = 0.0; value = values[CPU_STEAL_PERIOD].ull + values[CPU_GUEST_PERIOD].ull; - v[CPU_METER_IRQ] = value / total * 100.0; + v[CPU_METER_STEAL] = value / total * 100.0; if (settings->accountGuestInCPUMeter) { - this->curItems = 4; + this->curItems = 6; } }