Fix CPU detection in cgroup v2 constrained environments#303
Fix CPU detection in cgroup v2 constrained environments#303rucoder wants to merge 1 commit intointel:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes CPU detection failures in cgroup v2 constrained environments by removing the sysconf(_SC_NPROCESSORS_CONF) validation check that caused false positives when CPU limits were applied.
Key Changes:
- Removed sysconf() validation that conflicted with sysfs scanning in cgroup v2 environments
- Enhanced error messages with more specific context including the SYSTEM_CPU path
- Added debug/error logging for CPU topology detection failures
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@rucoder Please make sure that your patch follows the project's style. Also make sure that unit-tests are passed: |
|
Hi @rucoder, Thanks, |
5f57930 to
26cc9d4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
lib/os_cpuinfo.c:279
- Memory leak: namelist is not freed when this error path is taken. The namelist was successfully allocated by scandir at line 260, so it needs to be freed before returning. Add cleanup code to free the namelist entries and the namelist itself before returning NULL.
cpu = (struct pqos_cpuinfo *)malloc(mem_sz);
if (cpu == NULL) {
LOG_ERROR("Couldn't allocate CPU topology structure!\n");
return NULL;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Remove sysconf(_SC_NPROCESSORS_CONF) validation that causes false failures when the library runs in a process with cgroup v2 CPU limits. When cpu.max is set in cgroup v2, sysconf(_SC_NPROCESSORS_CONF) returns the cgroup-limited CPU count rather than the actual system CPU count. However, scanning /sys/devices/system/cpu always returns the real number of cores in the system, causing a mismatch and spurious check failures. By removing the sysconf() call and relying solely on the sysfs scan, we ensure consistent CPU topology detection regardless of cgroup constraints. Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
26cc9d4 to
aa52552
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Merged by |
Description
Remove sysconf(_SC_NPROCESSORS_CONF) validation that causes false failures when the library runs in a process with cgroup v2 CPU limits.
When cpu.max is set in cgroup v2, sysconf(_SC_NPROCESSORS_CONF) returns the cgroup-limited CPU count rather than the actual system CPU count. However, scanning /sys/devices/system/cpu always returns the real number of cores in the system, causing a mismatch and spurious check failures.
By removing the sysconf() call and relying solely on the sysfs scan, we ensure consistent CPU topology detection regardless of cgroup constraints.
Affected parts
Motivation and Context
https://github.com/lf-edge/eve uses libpqos from privileged system container pkg/pillar. This is a houskeeping conitainer that creates user workloads and it is restricted only to core 0 but has full visibility of /sys/fs so the library did not initilize
How Has This Been Tested?
This was tested from EVE OS on a real device with intel RDT support
Types of changes
Checklist: