-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
core: Add cgroupsv2 support to parallel.cpp #25285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The parallel code works out how many CPUs are on the system by checking
the quota it has been assigned in the Linux cgroup. The existing code
works under cgroups v1 but the file structure changed in cgroups v2.
From [1]:
"cpu.cfs_quota_us" and "cpu.cfs_period_us" are replaced by "cpu.max"
which contains both quota and period.
This commit add support to parallel so it will read from the cgroups v2
location. v1 support is still retained.
Resolves opencv#25284
[1] torvalds/linux@0d59363
|
I've build and tested this locally on my Linux system (Fedora 38) running cgroups v2 and the opencv is now reporting the expected number of threads when running in a container with a quota. |
| #elif defined CV_CPU_GROUPS_1 | ||
|
|
||
| #if defined CV_HAVE_CGROUPS | ||
| static unsigned ncpus_impl_cpuset = (unsigned)getNumberOfCPUsImpl("/sys/fs/cgroup/cpuset/cpuset.cpus"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about cpuset? Apparently on my system with cgroups2 (Ubuntu 22.04 - based) it has changed location to /sys/fs/cgroup/cpuset.cpus or cpuset.cpus.effective (idk which is right).
$ docker run --cpuset-cpus 1-3,8 -it ubuntu:22.04
root@f0e45a761cea:/# cat /sys/fs/cgroup/cpuset.cpus
1-3,8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a workaround for callers.
Because we could assign CPUs and also limit their usage:
docker run --rm --cpuset-cpus 1-3,8 --cpu-quota=300000 --cpu-period=100000 -it ubuntu:22.04
root@d4db947e6eba:/# cat /sys/fs/cgroup/cpuset.cpus
1-3,8
root@d4db947e6eba:/# cat /sys/fs/cgroup/cpu.max
300000 100000
opencv-alalek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thank you for contribution!
The parallel code works out how many CPUs are on the system by checking the quota it has been assigned in the Linux cgroup. The existing code works under cgroups v1 but the file structure changed in cgroups v2. From [1]:
which contains both quota and period.
This commit add support to parallel so it will read from the cgroups v2 location. v1 support is still retained.
Resolves #25284
[1] torvalds/linux@0d59363
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.