-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sysconf() to determine active and existing CPUs on Linux #1342
Draft
glaubitz
wants to merge
1
commit into
htop-dev:main
Choose a base branch
from
glaubitz:linux-cpu-enum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to assume that CPUs can only be offline from the end of the CPU numbering range (i.e. greater than active but less that existing) - I'm not certain that assumption is universally true. Isn't it possible to take an arbitrary CPU offline? (a quick google suggests yes, any CPU can be taken offline).
The existing code (which is supposed to do the same thing sysconf is doing internally in glibc AFAICS) will visit each CPU and test whether it is online or offline. It'd be best to understand where the current code gets it wrong than to replace it in this way (though certainly would been nice to remove all that code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thought about this, too. However, I wasn't sure whether the mapping of the CPU array in
htop
actually directly matches the CPU enumeration of the Linux kernel. My impression was thathtop
just counts the number of available CPUs and displays them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
htop currently does not have a proper sense of CPU core mapping. That's also where most of the temperature mapping goes wrong. A proper solution would be to build a proper map of IDs to underlying (physical) CPUs and their threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we need to find a way to reliably determine the online status of a CPU. Currently, it checks for the presence of an
online
file if I remember correctly which does not exist. Plus, the UI needs an option to hide offline CPUs as otherwise the large number of offline CPUs are cluttering the UI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are two separate issues, but yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, LXD cpu.limit can assign any thread to the container, so it can for example give it one thread ID 10 and this code will not mark it online because 10 is not equal or more than 1.
lscpu shows things correctly.
[0] # lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 48 On-line CPU(s) list: 2,5,19,21,24,30 Off-line CPU(s) list: 0,1,3,4,6-18,20,22,23,25-29,31-47
https://github.com/search?q=repo%3Autil-linux%2Futil-linux+is_cpu_online&type=code
So does /sys/devices/system/cpu/online:
But in current master many more threads are marked online than they should be, as per screenshots in the main issue.
This one marks too little in comparison.