Skip to content

Commit a42c5d1

Browse files
committed
sched interface completion
1 parent ae75995 commit a42c5d1

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

header/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub mod syscalls {
8484
MqTimedReceive,
8585
MqGetSetAttr,
8686
Ioctl,
87+
SchedGetPriorityMax,
88+
SchedGetPriorityMin,
89+
SchedRrGetInterval,
8790
LastNR,
8891
}
8992
}

kernel/src/syscall_handlers/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use libc::{
4141
sigset_t, size_t, sockaddr, socklen_t, timespec, EBUSY, EINVAL, ESRCH,
4242
};
4343

44+
pub const SCHED_RR: c_int = 1;
4445
#[cfg(not(enable_vfs))]
4546
mod vfs_syscalls {
4647
use super::*;
@@ -505,6 +506,39 @@ define_syscall_handler!(sched_yield() -> c_long {
505506
scheduler::yield_me();
506507
0
507508
});
509+
510+
define_syscall_handler!(sched_get_priority_max(policy: c_int) -> c_long {
511+
// Only SCHED_RR is supported.
512+
if policy != SCHED_RR {
513+
return -(libc::EINVAL as c_long);
514+
}
515+
config::MAX_THREAD_PRIORITY as c_long
516+
});
517+
518+
define_syscall_handler!(sched_get_priority_min(policy: c_int) -> c_long {
519+
// Only SCHED_RR is supported.
520+
if policy != SCHED_RR {
521+
return -(libc::EINVAL as c_long);
522+
}
523+
0
524+
});
525+
526+
define_syscall_handler!(sched_rr_get_interval(pid: c_int, interval: *mut timespec) -> c_long {
527+
let _ = pid;
528+
if interval.is_null() {
529+
return -(libc::EINVAL as c_long);
530+
}
531+
532+
unsafe {
533+
(*interval).tv_sec = 0;
534+
let ns: i64 = (time::tick_to_millisecond(blueos_kconfig::CONFIG_ROBIN_SLICE as usize)
535+
as i64)
536+
.saturating_mul(1_000_000);
537+
let clamped: i64 = core::cmp::min(ns, 999_999_999);
538+
(*interval).tv_nsec = clamped as c_int;
539+
}
540+
0
541+
});
508542
define_syscall_handler!(
509543
rmdir(path: *const c_char) -> c_int {
510544
vfs_syscalls::rmdir(path)
@@ -896,6 +930,9 @@ syscall_table! {
896930
(MqTimedReceive, mq_timedreceive),
897931
(MqGetSetAttr, mq_getsetattr),
898932
(Ioctl, ioctl),
933+
(SchedGetPriorityMax, sched_get_priority_max),
934+
(SchedGetPriorityMin, sched_get_priority_min),
935+
(SchedRrGetInterval, sched_rr_get_interval),
899936
}
900937

901938
#[cfg(not(enable_syscall))]

0 commit comments

Comments
 (0)