This repository was archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Change CPUs accounting system #56
Open
ejalberti
wants to merge
1
commit into
intel:master
Choose a base branch
from
ejalberti:change-cpu-accounting
base: master
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.
Open
Conversation
This file contains hidden or 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
This commit aims to change the accounting system of CPUs. In some cases, the number of CPUs obtained through the runtime library function is slightly less than the actual/real number of CPUs. Due to the update of CPUs accounting system in the Power Optimization Library, even if the CPUs are recognized by the library, they are not accounted for when creating profiles. This change introduces reading the number of CPUs online through sysfs (/sys/devices/system/cpu/online), just like it's done in the library. Signed-off-by: Eduardo Juliano Alberti <eduardo.alberti@windriver.com>
bartwensley
reviewed
Aug 17, 2023
Comment on lines
+425
to
+457
| func getNumberOfCpus(logger *logr.Logger) uint { | ||
| // First, try to get CPUs from sysfs. If the sysfs isn't available | ||
| // return Number of CPUs from runtime | ||
| cpusAvailable, err := readStringFromFile(path.Join(basePath, "online")) | ||
| if err != nil { | ||
| logger.V(5).Info("Error during online cpus file reading. Returning runtime.", "Runtime CPUS", rt.NumCPU()) | ||
| return uint(rt.NumCPU()) | ||
| } | ||
|
|
||
| // Delete \n character and split the string to get | ||
| // first and last element | ||
| cpusAvailable = strings.Replace(cpusAvailable, "\n", "", -1) | ||
| cpuSlice := strings.Split(cpusAvailable, "-") | ||
| if len(cpuSlice) < 2 { | ||
| logger.V(3).Info("Error during CPU slicing. Returning runtime.", "Runtime CPUS", rt.NumCPU()) | ||
| return uint(rt.NumCPU()) | ||
| } | ||
|
|
||
| // Calculate number of CPUs, if an error occurs | ||
| // return the number of CPUs from runtime | ||
| firstElement, err := strconv.Atoi(cpuSlice[0]) | ||
| if err != nil { | ||
| logger.V(3).Info("Error during first element convertion. Returning runtime.", "Runtime CPUS", rt.NumCPU()) | ||
| return uint(rt.NumCPU()) | ||
| } | ||
| secondElement, err := strconv.Atoi(cpuSlice[1]) | ||
| if err != nil { | ||
| logger.V(3).Info("Error during second element convertion. Returning runtime.", "Runtime CPUS", rt.NumCPU()) | ||
| return uint(rt.NumCPU()) | ||
| } | ||
| logger.V(3).Info("Success in accounting online CPUS.", "Online CPUS", uint((secondElement-firstElement)+1)) | ||
| return uint((secondElement - firstElement) + 1) | ||
| } |
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.
Instead of duplicating this code, why not export it from the power-optimization-library and use it directly?
Contributor
Author
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.
Hi @bartwensley, your suggestion is more elegant. In this proposal, I aimed to affect only the PM code, but I could review it and propose this change in both repositories. Do you think it is better?
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This commit aims to change the accounting system of CPUs. In some cases, the number of CPUs obtained through the runtime library function is slightly less than the actual/real number of CPUs.
Due to the update of CPUs accounting system in the Power Optimization Library, even if the CPUs are recognized by the library, they are not accounted for when creating profiles.
This change introduces reading the number of CPUs online through sysfs (/sys/devices/system/cpu/online), just like it's done in the library.