Skip to content

Commit 55c1d7f

Browse files
committed
start adding docs + changelog
1 parent e14de14 commit 55c1d7f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

changelog/2640.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added new api methods for working with PREEMPT_RT thread priorities.

src/sched.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,33 +359,57 @@ mod sched_priority {
359359

360360
libc_enum! {
361361
#[repr(i32)]
362+
/// The type of scheduler for use with [`sched_getscheduler`] and [`sched_setscheduler`].
363+
/// See [man_sched(7)](https://man7.org/linux/man-pages/man7/sched.7.html) for more details
364+
/// on the differences in behavior.
362365
pub enum Scheduler {
366+
/// The default scheduler on non-realtime linux - also known as SCHED_NORMAL.
363367
SCHED_OTHER,
368+
/// The realtime FIFO scheduler. All FIFO threads have priority higher than 0 and
369+
/// preempt SCHED_OTHER threads. Threads are executed in priority order, using
370+
/// first-in-first-out lists to handle two threads with the same priority.
364371
SCHED_FIFO,
372+
/// Round-robin scheduler
365373
SCHED_RR,
374+
/// Batch scheduler, similar to SCHED_OTHER but assumes the thread is CPU intensive.
375+
/// The kernel applies a mild penalty to switching to this thread.
376+
/// As of Linux 2.6.16, the only valid priority is 0.
366377
SCHED_BATCH,
378+
/// The idle scheduler only executes the thread when there are idle CPUs. SCHED_IDLE
379+
/// threads have no progress guarantees.
367380
SCHED_IDLE,
381+
/// Deadline scheduler, attempting to provide guaranteed latency for requests.
382+
/// See the [linux kernel docs](https://docs.kernel.org/scheduler/sched-deadline.html)
383+
/// for details.
368384
SCHED_DEADLINE,
369385
}
370386
impl TryFrom<libc::c_int>
371387
}
372388

389+
/// Get the highest priority value for a given scheduler.
373390
pub fn sched_get_priority_max(sched: Scheduler) -> Result<libc::c_int> {
374391
let res = unsafe { libc::sched_get_priority_max(sched as libc::c_int) };
375392
Errno::result(res).map(|int| int as libc::c_int)
376393
}
377394

395+
/// Get the lowest priority value for a given scheduler.
378396
pub fn sched_get_priority_min(sched: Scheduler) -> Result<libc::c_int> {
379397
let res = unsafe { libc::sched_get_priority_min(sched as libc::c_int) };
380398
Errno::result(res).map(|int| int as libc::c_int)
381399
}
382400

401+
/// 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.
383403
pub fn sched_getscheduler(pid: Pid) -> Result<Scheduler> {
384404
let res = unsafe { libc::sched_getscheduler(pid.into()) };
385405

386406
Errno::result(res).and_then(|sched| Scheduler::try_from(sched))
387407
}
388408

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+
///
389413
pub fn sched_setscheduler(
390414
pid: Pid,
391415
sched: Scheduler,

0 commit comments

Comments
 (0)