Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Conversation

@ejalberti
Copy link
Contributor

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.

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>
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)
}

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?

Copy link
Contributor Author

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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants