-
Notifications
You must be signed in to change notification settings - Fork 411
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
feat: add a function to get number of logical cpu cores #4880
feat: add a function to get number of logical cpu cores #4880
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
TODO:
|
Test on docker with |
Signed-off-by: Lloyd-Pottiger <[email protected]>
/rebuild |
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
It does not work in some case…… I will write a doc and do more tests. |
Is it easy to add tests for it? How about setting up a docker, or more directly, just use cgroup in tests? |
Currently, I did not find the way to test by gtests. I tested manually before. (I did not test on cgroup v2 because I still could not set up the environment after trying a lot on my own machine) Do you mean run a docker in a unit test? Maybe it is hard, and is not a good way which means we may need to introduce more dependencies. However, there are some bugs indeed. I will fix later. |
I have wrote a doc about this pr in #4879 (comment). |
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
Signed-off-by: Lloyd-Pottiger <[email protected]>
std::getline(infile, line); | ||
unsigned cpu_count = 0; | ||
size_t first = 0; | ||
while (first < line.size()) |
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.
Can we change it to for(line by line)
?
return std::min(cpuset_count, quota_count); | ||
} | ||
|
||
static unsigned read_cpuset_count_from(const char * filename, unsigned default_value) |
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.
Would you like to add some gtests
to test all of functions?
You can find some example in man
.
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 will
What problem does this PR solve?
Issue Number: close #4879
Problem Summary:
What is changed and how it works?
Add a function to get number of logical cpu cores:
$cpu = std::thread::hardware_concurrency()
$cpu = min(len(cpuset), cgroup_quota / cgroup_period)
detail doc: #4879 (comment)
Check List
Tests
Side effects
Documentation
Release note