@@ -359,33 +359,57 @@ mod sched_priority {
359
359
360
360
libc_enum ! {
361
361
#[ 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.
362
365
pub enum Scheduler {
366
+ /// The default scheduler on non-realtime linux - also known as SCHED_NORMAL.
363
367
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.
364
371
SCHED_FIFO ,
372
+ /// Round-robin scheduler
365
373
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.
366
377
SCHED_BATCH ,
378
+ /// The idle scheduler only executes the thread when there are idle CPUs. SCHED_IDLE
379
+ /// threads have no progress guarantees.
367
380
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.
368
384
SCHED_DEADLINE ,
369
385
}
370
386
impl TryFrom <libc:: c_int>
371
387
}
372
388
389
+ /// Get the highest priority value for a given scheduler.
373
390
pub fn sched_get_priority_max ( sched : Scheduler ) -> Result < libc:: c_int > {
374
391
let res = unsafe { libc:: sched_get_priority_max ( sched as libc:: c_int ) } ;
375
392
Errno :: result ( res) . map ( |int| int as libc:: c_int )
376
393
}
377
394
395
+ /// Get the lowest priority value for a given scheduler.
378
396
pub fn sched_get_priority_min ( sched : Scheduler ) -> Result < libc:: c_int > {
379
397
let res = unsafe { libc:: sched_get_priority_min ( sched as libc:: c_int ) } ;
380
398
Errno :: result ( res) . map ( |int| int as libc:: c_int )
381
399
}
382
400
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.
383
403
pub fn sched_getscheduler ( pid : Pid ) -> Result < Scheduler > {
384
404
let res = unsafe { libc:: sched_getscheduler ( pid. into ( ) ) } ;
385
405
386
406
Errno :: result ( res) . and_then ( |sched| Scheduler :: try_from ( sched) )
387
407
}
388
408
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
+ ///
389
413
pub fn sched_setscheduler (
390
414
pid : Pid ,
391
415
sched : Scheduler ,
0 commit comments