Repository navigation
Add hide_offline_cpus setting to hide offline CPUs in the CPU meters - #2104
Conversation
On machines booted with nosmt (or with CPUs otherwise offlined), the multi-CPU meters draw a bar reading "offline" for every disabled thread, doubling the height of the header on large SMT systems for no benefit. Add a "Hide offline CPUs in the CPUs meters" display option (htoprc key hide_offline_cpus, default off). When enabled, the CPUs meters lay out the sequence of online CPUs instead of every existing CPU, so the first/second half and multi-column layouts split over the shown CPUs only. Sub-meters are now kept per CPU id and created when a CPU is first shown, so a CPU that is hidden or shifts to another slot keeps its graph history; the meter recomputes its own height whenever the shown sequence changes. Header_updateData now recalculates the header height and reports whether it changed, so the refresh loop re-lays out the screen when CPUs go online or offline at runtime instead of leaving blank or clipped rows until the terminal is resized. Closes htop-dev#853 Assisted-by: Claude Fable 5.1 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Edouard Schweisguth <edznux@gmail.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughAdds a persistent Assessment against linked issues:
Suggested reviewers: Priority: ⬇️ Low Change: Feature · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The option is off by default, and reported tests covered CPU filtering, split layouts, and hot-plug redraws. No merge blocker is evident. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The reviewed paths affect interactive CPU display and do not show a new privileged operation or security boundary. Dynamic CPU changes and incomplete coverage leave some residual uncertainty. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Offline bars fade from view Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 90e2a14a-af2b-4327-8129-d7dff80b6645
📒 Files selected for processing (7)
CPUMeter.cDisplayOptionsPanel.cHeader.cHeader.hScreenManager.cSettings.cSettings.h
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Follow the ModuleName_functionName() convention from the style guide for the static helpers shared by the CPUs meters. Assisted-by: Claude Fable 5.1 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Edouard Schweisguth <edznux@gmail.com>
ravi-arnan
left a comment
There was a problem hiding this comment.
Reviewed this closely since I did the adjacent CPU hotplug fix (#2064). Fetched the PR head (f0ea593) and built on Linux under htop's own warning set: exit 0, zero new warnings in any touched file. Also ran the built binary for a few seconds of live refreshes under a pty with asserts enabled: no crash, no assert trip. All 16 CPUs on my machine are online, so the hide path itself is compile-verified plus traced by hand, not runtime-tested; stating that boundary explicitly.
Things I verified that hold up:
- The per-CPU-id
meters[]indexing subsumes the mid-range removal case from #2064: arbitrary online/offline gaps are handled by construction, and the Left/Right halves now partition the shown sequence, which is the sane semantic with hiding on. Machine_isCPUonline()exists on all 8 platform backends, so the new gate is portable with no extra ifdefs.Header_updateData()void-to-bool is source-compatible with the two other callers (DisplayOptionsPanel.c:235,AvailableMetersPanel.c:86); both use it as a bare statement.AllCPUsMeter_updateMode()callsMeter_init(), which is only a->initdispatch (Meter.h), so there is no updateMode/init recursion; mode propagation to the sub-meters throughcommonInitSubMetersis correct.- The
xReallocArraygrowth path forshowncannot expose uninitialized slots: when the array grows,changedis true and the compare short-circuits. - Bonus this brings along:
Header_updateDatareporting height changes up toScreenManager_resizemeans a live hotplug while htop runs now resizes the header instead of leaving a stale height.
One nit (non-blocking): the settings label says "(e.g. SMT siblings disabled by nosmt)", but offline CPUs equally come from hot-unplug. Suggest widening it, e.g. "(e.g. disabled by nosmt/nosmp or hot-unplugged)".
One question: hidden CPUs stop receiving Meter_updateValues(), so when a CPU comes back the first delta spans the whole hidden interval. For CPU% that reads as an average over the gap, which seems fine, but is that the intended semantic, or should a re-shown CPU reset its history instead?
No blocking issues found. Leaving approval to the maintainers.
|
@ravi-arnan you can test by temporarily disabling a core and set to 1 to re-enable it :) |
|
Follow-up on the testing boundary I flagged in my review: I took a real CPU offline Method. CPU 12 offline through the kernel ( Results with cpu12 offline:
Live hotplug in one instance (hide=1): started with cpu12 offline (15 rows), brought And the answer to my own question (does a re-shown CPU average over the hidden gap): The label nit from the review still stands if you want it (the setup text mentions nosmt |
from the clang analyzer CI job |
The clang static analyzer cannot tell that the shown sub-meters are never NULL (they come from Meter_new(), defined in another translation unit) and reports a NULL dereference in CPUMeter_commonUpdateHeight(): CPUMeter.c:332:12: warning: Access to field 'h' results in a dereference of a null pointer [core.NullDereference] Fall back to a height of 1 when the first shown sub-meter is NULL, like when no CPU is shown. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Just added a null check! let me know :) |
|
Verified the null-deref fix at
Full build at head under htop's warning set I also agree it is a false positive rather than a real hazard: whenever Nothing blocking from me; the earlier label nit ( |
|
Thank you both! |
Hello :)
Context
I was working on a relatively large server where we disabled SMT and this caused the 64 core / 128 threads listing to have 64
[offline]CPU displayed. This was less than ideal when using a small terminal pane, especially to see the load on the other 64 cores, so I decided to take a look at it. I noticed #853 and decided to pick it up!I don't know the codebase, and I'm not a particularly good C dev, but I've reviewed the code and steered my agent for a bit to achieve this. I do believe it went a bit too far with some changes, but I also think it made sense for the purpose of the PR.
I do believe I've followed the contribution guidance and the AI disclosure and all as well, but happy to change.
Goal
On machines booted with nosmt (or with CPUs otherwise offlined), the multi-CPU meters draw a bar reading "offline" for every disabled thread, doubling the height of the header on large SMT systems for no benefit.
Add a "Hide offline CPUs in the CPUs meters" display option (htoprc key hide_offline_cpus, default off).
When enabled, the CPUs meters lay out the sequence of online CPUs instead of every existing CPU, so the first/second half and multi-column layouts split over the shown CPUs only. Sub-meters are now kept per CPU id and created when a CPU is first shown, so a CPU that is hidden or shifts to another slot keeps its graph history; the meter recomputes its own height whenever the shown sequence changes.
Header_updateData now recalculates the header height and reports whether it changed, so the refresh loop re-lays out the screen when CPUs go online or offline at runtime instead of leaving blank or clipped rows until the terminal is resized.
Recorded run
Here's an example of how it looks on my 16C/32T machine, with a script that disables cores over time.
htop-issue-853-implem-crf24.mp4
Closes #853
Assisted-by: Claude Fable 5.1 noreply@anthropic.com