-
Notifications
You must be signed in to change notification settings - Fork 50
potential solution to hyperthreading reporting error #415
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
Conversation
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.
Pull Request Overview
This PR enhances hyperthreading detection by leveraging the Thread(s) per core
attribute and falling back to an online-CPU range when needed.
- Add extraction and parsing of "On-line CPU(s) list" and "Thread(s) per core" from
lscpu
output - Adjust
hyperthreadingFromOutput
to prefer online-CPU counts and threads-per-core before legacy logical-CPU checks - Introduce
parseCPURanges
andparseCPURangeCount
helpers for CPU-range string parsing
Comments suppressed due to low confidence (2)
internal/report/table_helpers.go:456
- [nitpick] Consider renaming
onlineCpus
toonlineCPUListStr
or similar to clarify that this variable holds the raw range string, not the parsed count.
onlineCpus := valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^On-line CPU\(.*:\s*(.+?)$`)
internal/report/table_helpers.go:2052
- Add unit tests for
parseCPURanges
(andparseCPURangeCount
) covering edge cases such as empty strings, invalid formats, overlapping ranges, and duplicates.
// parseCPURanges parses CPU range strings like "0-7,32-35" and returns the total count
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.
Approach seems sound. Code looks good. I believe there is a util function that will parse the ranges for you. Please check and reuse, if applicable.
Co-authored-by: Copilot <[email protected]>
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.
Looks like we lost the unit tests that were previously in table_helpers_test.go.
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.
Thanks @adgubrud .
Previous approach was to use lscpu output to provide the logical CPU count and compare that with the product of the number of physical cores active and the number of sockets active. Older kernels seem to account for only online CPUs in the logical CPU count but newer kernels (e.g. 6.8) count the number of logical CPUs available in the whole system, regardless of if they are active or not.
Since this approach has been working so far (to an extent) I tried to keep that original calculation as a default behavior. However, if the attribute "Thread(s) per core" is available from lscpu, we use that to determine if hyperthreading is enabled. As a fallback, there is a function to enumerate the number of online cores ("On-line CPU(s) list" in lscpu), then compare that number with the number of physical cores and number of sockets if the number of online cores is less than what is reported with the "CPU(s)" attribute from lscpu.