Skip to content

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

Merged
merged 8 commits into from
Jul 15, 2025

Conversation

adgubrud
Copy link
Contributor

@adgubrud adgubrud commented Jul 9, 2025

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.

@adgubrud adgubrud requested a review from harp-intel as a code owner July 9, 2025 19:47
@harp-intel harp-intel requested a review from Copilot July 9, 2025 22:43
Copy link
Contributor

@Copilot Copilot AI left a 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 and parseCPURangeCount helpers for CPU-range string parsing
Comments suppressed due to low confidence (2)

internal/report/table_helpers.go:456

  • [nitpick] Consider renaming onlineCpus to onlineCPUListStr 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 (and parseCPURangeCount) 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

Copy link
Contributor

@harp-intel harp-intel left a 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.

Copy link
Contributor

@harp-intel harp-intel left a 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.

Copy link
Contributor

@harp-intel harp-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adgubrud .

@harp-intel harp-intel merged commit 176af16 into intel:main Jul 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PerfSpect can incorrectly report HT on/off when half or more cores are off-lined.
2 participants