Skip to content

Fix CPU detection in cgroup v2 constrained environments#303

Closed
rucoder wants to merge 1 commit intointel:masterfrom
rucoder:rucoder/cpu-count-cgroupv2
Closed

Fix CPU detection in cgroup v2 constrained environments#303
rucoder wants to merge 1 commit intointel:masterfrom
rucoder:rucoder/cpu-count-cgroupv2

Conversation

@rucoder
Copy link
Contributor

@rucoder rucoder commented Nov 26, 2025

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

  • 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

  • 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:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@rstorozh rstorozh requested a review from Copilot December 5, 2025 13:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rstorozh
Copy link
Contributor

rstorozh commented Dec 8, 2025

@rucoder Please make sure that your patch follows the project's style.
You should use the following commands for this:
$ export CHECKPATCH=<path_to_checkpatch>checkpatch.pl
$ make style
Here, is the path to Linux Kernel's checkpatch.pl utility. For example <linux_kernel_repo>/scripts/checkpatch.pl

Also make sure that unit-tests are passed:
$ cd unit-test
<intel-cmt-cat/unit-test> make clean
<intel-cmt-cat/unit-test> make
<intel-cmt-cat/unit-test> make run

@rkanagar
Copy link
Contributor

Hi @rucoder,
Please rebase and address all the review comments. We are ready to merge.

Thanks,
Raghavan K.

@rucoder
Copy link
Contributor Author

rucoder commented Feb 3, 2026

Hi @rucoder, Please rebase and address all the review comments. We are ready to merge.

Thanks, Raghavan K.

@rkanagar @rstorozh I'll address all the comments ASAP

@rkanagar
Copy link
Contributor

rkanagar commented Feb 3, 2026

Hi @rucoder, Please rebase and address all the review comments. We are ready to merge.
Thanks, Raghavan K.

@rkanagar @rstorozh I'll address all the comments ASAP

Hi @rucoder ,
Not required. I have done the required changes without changing author name. Mostly i will merge tomorrow. Thanks.

@rucoder rucoder force-pushed the rucoder/cpu-count-cgroupv2 branch from 5f57930 to 26cc9d4 Compare February 3, 2026 13:45
@rucoder
Copy link
Contributor Author

rucoder commented Feb 3, 2026

@rkanagar I rebased and fixed issues anyways to become familiar with the process in case i eve have to make any PRs again. could you approve the worklow ?

@rstorozh thanks for the instructions. I followed them and run tests + checkpatch.pl

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rkanagar
Copy link
Contributor

rkanagar commented Feb 6, 2026

Merged by
aad3a0f

@rkanagar rkanagar closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants