@@ -330,11 +330,15 @@ mod sched_priority {
330
330
331
331
#[ repr( C ) ]
332
332
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
333
+ /// Schedule parameters for a thread (currently only priority is supported).
333
334
pub struct SchedParam {
335
+ /// Priority of the current schedule.
334
336
pub sched_priority : libc:: c_int ,
335
337
}
336
338
337
339
impl SchedParam {
340
+ /// Create schedule parameters with a given priority. Priority must be between
341
+ /// min and max for the chosen schedule type.
338
342
pub fn from_priority ( priority : libc:: c_int ) -> Self {
339
343
SchedParam {
340
344
sched_priority : priority,
@@ -399,17 +403,22 @@ mod sched_priority {
399
403
}
400
404
401
405
/// 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.
403
407
pub fn sched_getscheduler ( pid : Pid ) -> Result < Scheduler > {
404
408
let res = unsafe { libc:: sched_getscheduler ( pid. into ( ) ) } ;
405
409
406
410
Errno :: result ( res) . and_then ( |sched| Scheduler :: try_from ( sched) )
407
411
}
408
412
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.
413
422
pub fn sched_setscheduler (
414
423
pid : Pid ,
415
424
sched : Scheduler ,
@@ -423,6 +432,8 @@ mod sched_priority {
423
432
Errno :: result ( res) . map ( drop)
424
433
}
425
434
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.
426
437
pub fn sched_getparam ( pid : Pid ) -> Result < SchedParam > {
427
438
let mut param: MaybeUninit < libc:: sched_param > = MaybeUninit :: uninit ( ) ;
428
439
let res =
@@ -431,6 +442,11 @@ mod sched_priority {
431
442
Errno :: result ( res) . map ( |_| unsafe { param. assume_init ( ) } . into ( ) )
432
443
}
433
444
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.
434
450
pub fn sched_setparam ( pid : Pid , param : SchedParam ) -> Result < ( ) > {
435
451
let param: libc:: sched_param = param. into ( ) ;
436
452
let res = unsafe { libc:: sched_setparam ( pid. into ( ) , & param) } ;
0 commit comments