Skip to content

cv::getCPUCount has no support for Linux cgroups v2 #25284

@johnteslade

Description

@johnteslade

System Information

OpenCV version: 4.9.0
Operating System / Platform: Fedora 38

Detailed description

Code was added in #16457 (bug #16268) to inspect /sys/fs/cgroup/ under Linux to see if opencv is running in a constrained environment and cannot use all the CPUs of the system. But cgroups in the Linux kernel now has v2 which changes the underlying file structure (see torvalds/linux@0d59363).

This means that under cgroups v2 opencv incorrectly counts the CPUs and ends up opening far too any threads.

Steps to reproduce

Expected behaviour (this is seen when run under cgroups v1).

docker run --cpu-quota=300000 --cpu-period=100000  ...

$ opencv_version --threads
Parallel framework: pthreads (nthreads=3)

But under cgroups v2 this gives the wrong answer (8 is number of cores on my system)

docker run --cpu-quota=300000 --cpu-period=100000 ...

$ opencv_version --threads
Parallel framework: pthreads (nthreads=8)

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions