mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #25285 from johnteslade:cgroupsv2-support
core: Add cgroupsv2 support to parallel.cpp
This commit is contained in:
commit
9f123f8d74
@ -870,7 +870,22 @@ int getNumberOfCPUsImpl(const char *filename)
|
|||||||
|
|
||||||
#if defined CV_HAVE_CGROUPS
|
#if defined CV_HAVE_CGROUPS
|
||||||
static inline
|
static inline
|
||||||
unsigned getNumberOfCPUsCFS()
|
unsigned getNumberOfCPUsCFSv2()
|
||||||
|
{
|
||||||
|
int cfs_quota = 0;
|
||||||
|
int cfs_period = 0;
|
||||||
|
|
||||||
|
std::ifstream ss_cpu_max("/sys/fs/cgroup/cpu.max", std::ios::in | std::ios::binary);
|
||||||
|
ss_cpu_max >> cfs_quota >> cfs_period;
|
||||||
|
|
||||||
|
if (ss_cpu_max.fail() || cfs_quota < 1 || cfs_period < 1) /* values must not be 0 or negative */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return (unsigned)max(1, cfs_quota/cfs_period);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
unsigned getNumberOfCPUsCFSv1()
|
||||||
{
|
{
|
||||||
int cfs_quota = 0;
|
int cfs_quota = 0;
|
||||||
{
|
{
|
||||||
@ -966,8 +981,11 @@ int getNumberOfCPUs_()
|
|||||||
static unsigned ncpus_impl_cpuset = (unsigned)getNumberOfCPUsImpl("/sys/fs/cgroup/cpuset/cpuset.cpus");
|
static unsigned ncpus_impl_cpuset = (unsigned)getNumberOfCPUsImpl("/sys/fs/cgroup/cpuset/cpuset.cpus");
|
||||||
ncpus = minNonZero(ncpus, ncpus_impl_cpuset);
|
ncpus = minNonZero(ncpus, ncpus_impl_cpuset);
|
||||||
|
|
||||||
static unsigned ncpus_impl_cfs = getNumberOfCPUsCFS();
|
static unsigned ncpus_impl_cfs_v1 = getNumberOfCPUsCFSv1();
|
||||||
ncpus = minNonZero(ncpus, ncpus_impl_cfs);
|
ncpus = minNonZero(ncpus, ncpus_impl_cfs_v1);
|
||||||
|
|
||||||
|
static unsigned ncpus_impl_cfs_v2 = getNumberOfCPUsCFSv2();
|
||||||
|
ncpus = minNonZero(ncpus, ncpus_impl_cfs_v2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned ncpus_impl_devices = (unsigned)getNumberOfCPUsImpl("/sys/devices/system/cpu/online");
|
static unsigned ncpus_impl_devices = (unsigned)getNumberOfCPUsImpl("/sys/devices/system/cpu/online");
|
||||||
|
Loading…
Reference in New Issue
Block a user