Skip to content

Commit

Permalink
fix: sched_setscheduler() gets EINVAL for normal policies
Browse files Browse the repository at this point in the history
In sched_setscheduler(2):
For each of the above policies (other batch rr),
param->sched_priority must be 0.
However, currently SchedPriority is set to 1 by default,
which causes sched_setscheduler() gets EINVAL errno.
  • Loading branch information
taoky committed Jul 31, 2023
1 parent 5c20d3d commit 5849c52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ impl FromStr for SchedPolicy {
}
}

impl SchedPolicy {
/// Whether the policy is realtime (FIFO or RR)
#[must_use]
pub fn is_realtime(self) -> bool {
matches!(self, Self::Fifo | Self::Rr)
}
}

/// A value between 1 and 99
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct SchedPriority(u8);
Expand Down
8 changes: 7 additions & 1 deletion daemon/src/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ pub fn set(buffer: &mut Buffer, process: u32, profile: &Profile) {

pub fn set_policy(pid: u32, policy: SchedPolicy, sched_priority: SchedPriority) {
let param = libc::sched_param {
sched_priority: libc::c_int::from(sched_priority.get()),
sched_priority: libc::c_int::from({
if policy.is_realtime() {
sched_priority.get()
} else {
0
}
}),
};

unsafe {
Expand Down

0 comments on commit 5849c52

Please sign in to comment.