Skip to content

Commit ca02090

Browse files
committed
nproc: Reject quota with some schedulers
1 parent 686bf6a commit ca02090

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/uu/nproc/src/nproc.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr sysconf
6+
// spell-checker:ignore (ToDO) NPROCESSORS SCHED getscheduler nprocs numstr sched sysconf
77

88
use clap::{Arg, ArgAction, Command};
99
use std::io::{Write, stdout};
@@ -67,7 +67,23 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6767
}
6868
// the variable 'OMP_NUM_THREADS' doesn't exist
6969
// fallback to the regular CPU detection
70-
Err(_) => available_parallelism(),
70+
Err(_) => {
71+
// ignore quota under some schedulers
72+
#[cfg(any(target_os = "linux", target_os = "android"))]
73+
{
74+
let policy = unsafe { libc::sched_getscheduler(0) };
75+
if policy == libc::SCHED_FIFO
76+
|| policy == libc::SCHED_RR
77+
|| policy == libc::SCHED_DEADLINE
78+
{
79+
num_cpus_all()
80+
} else {
81+
available_parallelism()
82+
}
83+
}
84+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
85+
available_parallelism()
86+
}
7187
}
7288
};
7389

0 commit comments

Comments
 (0)