Skip to content
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 a minimum of 1 thread per core for CPU total calculation #1756

Merged
merged 1 commit into from Sep 6, 2022

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Jul 5, 2022

Description

In some LXD containers running with VT-x hardware virtualization, it appears that threads per core is 0, resulting in a total number of CPUs of 0. Add a test case and handle some quirks with the lscpu output.

This pull request also makes the default CPU configurable in the tests. Normally CPU 0 is the default, but on some virtualized hosts this is not the case.

Related Issue

Closes #1755

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@stanhu stanhu requested review from a team as code owners July 5, 2022 17:33
@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
21.4% 21.4% Duplication

@ramereth
Copy link
Contributor

ramereth commented Jul 7, 2022

LGTM

@johnmccrae
Copy link
Contributor

Please update the description to show why the default cpu is configurable.

@stanhu
Copy link
Contributor Author

stanhu commented Jul 19, 2022

Please update the description to show why the default cpu is configurable.

@johnmccrae Could you elaborate? I don't quite understand.

@stanhu
Copy link
Contributor Author

stanhu commented Aug 2, 2022

#1761 might be an alternative solution: if we get 0, give up and use /proc/cpuinfo.

@jaymzh
Copy link
Collaborator

jaymzh commented Aug 9, 2022

Please update the description to show why the default cpu is configurable.

@johnmccrae Could you elaborate? I don't quite understand.

@stanhu - Your change to do max[val, 1] is obviously correct. But you changed all the tests to stop checking for CPU 0 and start looking for some configurable "default_cpu" - but your PR description doesn't mention this change at all or why you are making it.

@jaymzh jaymzh added the Status: Waiting on Contributor A pull request that has unresolved requested actions from the author. label Aug 23, 2022
@jaymzh
Copy link
Collaborator

jaymzh commented Aug 23, 2022

Ping @stanhu ?

@stanhu
Copy link
Contributor Author

stanhu commented Aug 24, 2022

@jaymzh Oh, right, thanks. It's been a while since I worked on this so I forgot that I did that. Updated. 😄

Copy link
Collaborator

@jaymzh jaymzh left a comment

Choose a reason for hiding this comment

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

Thanks. Looks good, minus the lint failures. Can you run the rubocop autocorrecting rake task? @tpowell-progress is trying to find the exact command.

In some LXD containers running with VT-x hardware virtualization, it
appears that threads per core is 0, resulting in a total number of
CPUs of 0. Add a test case and handle some quirks with the `lscpu`
output.

Closes chef#1755

Signed-off-by: Stan Hu <stanhu@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Aug 30, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
21.4% 21.4% Duplication

@stanhu
Copy link
Contributor Author

stanhu commented Aug 30, 2022

Thanks. Looks good, minus the lint failures. Can you run the rubocop autocorrecting rake task? @tpowell-progress is trying to find the exact command.

I manually corrected them. Running git diff --name-only main | xargs bundle exec rubocop -a corrected almost the entire file. 😄

@jaymzh jaymzh self-requested a review September 6, 2022 19:46
@jaymzh jaymzh merged commit ee199cf into chef:main Sep 6, 2022
@jaymzh
Copy link
Collaborator

jaymzh commented Sep 6, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting on Contributor A pull request that has unresolved requested actions from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPU total is 0 when threads-per-core is 0
5 participants