Skip to content

Commit f68a980

Browse files
committed
docs
1 parent 55c1d7f commit f68a980

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/sched.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,15 @@ mod sched_priority {
330330

331331
#[repr(C)]
332332
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
333+
/// Schedule parameters for a thread (currently only priority is supported).
333334
pub struct SchedParam {
335+
/// Priority of the current schedule.
334336
pub sched_priority: libc::c_int,
335337
}
336338

337339
impl SchedParam {
340+
/// Create schedule parameters with a given priority. Priority must be between
341+
/// min and max for the chosen schedule type.
338342
pub fn from_priority(priority: libc::c_int) -> Self {
339343
SchedParam {
340344
sched_priority: priority,
@@ -399,17 +403,22 @@ mod sched_priority {
399403
}
400404

401405
/// Get the current scheduler in use for a given process or thread.
402-
/// Using `Pid::from_raw(0)` will fetch the scheduler for the current thread.
406+
/// Using `Pid::from_raw(0)` will fetch the scheduler for the calling thread.
403407
pub fn sched_getscheduler(pid: Pid) -> Result<Scheduler> {
404408
let res = unsafe { libc::sched_getscheduler(pid.into()) };
405409

406410
Errno::result(res).and_then(|sched| Scheduler::try_from(sched))
407411
}
408412

409-
/// Set the scheduler for a given process or thread.
410-
/// Using `Pid::from_raw(0)` will set the scheduler for the current thread.
411-
///
412-
///
413+
/// Set the scheduler and parameters for a given process or thread.
414+
/// Using `Pid::from_raw(0)` will set the scheduler for the calling thread.
415+
///
416+
/// SCHED_OTHER, SCHED_IDLE and SCHED_BATCH only support a priority of `0`, and can be used
417+
/// outside a Linux PREEMPT_RT context.
418+
///
419+
/// SCHED_FIFO and SCHED_RR allow priorities between the min and max inclusive.
420+
///
421+
/// SCHED_DEADLINE cannot be set with this function, libc::sched_setattr must be used instead.
413422
pub fn sched_setscheduler(
414423
pid: Pid,
415424
sched: Scheduler,
@@ -423,6 +432,8 @@ mod sched_priority {
423432
Errno::result(res).map(drop)
424433
}
425434

435+
/// Get the schedule parameters (currently only priority) for a given thread.
436+
/// Using `Pid::from_raw(0)` will return the parameters for the calling thread.
426437
pub fn sched_getparam(pid: Pid) -> Result<SchedParam> {
427438
let mut param: MaybeUninit<libc::sched_param> = MaybeUninit::uninit();
428439
let res =
@@ -431,6 +442,11 @@ mod sched_priority {
431442
Errno::result(res).map(|_| unsafe { param.assume_init() }.into())
432443
}
433444

445+
/// Set the schedule parameters (currently only priority) for a given thread.
446+
/// Using `Pid::from_raw(0)` will return the parameters for the calling thread.
447+
///
448+
/// Changing the priority to something other than `0` requires using a SCHED_FIFO or SCHED_RR
449+
/// and using a Linux kernel with PREEMPT_RT enabled.
434450
pub fn sched_setparam(pid: Pid, param: SchedParam) -> Result<()> {
435451
let param: libc::sched_param = param.into();
436452
let res = unsafe { libc::sched_setparam(pid.into(), &param) };

0 commit comments

Comments
 (0)