Fix CPU detection in cgroup v2 constrained environments
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
- [x] library
- [ ] pqos utility
- [ ] rdtset utility
- [ ] other: (please specify)
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
- [x] 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 not work as expected)
Checklist:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
@rucoder Please make sure that your patch follows the project's style.
You should use the following commands for this:
Also make sure that unit-tests are passed: