From 552210613ff64d1f89422f09555a34f1b32f5c12 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 5 Jan 2024 15:15:47 +0100 Subject: [PATCH 1/2] Add more items from `include/linux/sched.h` header --- src/unix/linux_like/linux/mod.rs | 93 ++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 6579fbbd0699b..acb10c603f725 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -878,6 +878,17 @@ s_no_extra_traits! { pub d_type: ::c_uchar, pub d_name: [::c_char; 256], } + + pub struct sched_attr { + pub size: ::__u32, + pub sched_policy: ::__u32, + pub sched_flags: ::__u64, + pub sched_nice: ::__s32, + pub sched_priority: ::__u32, + pub sched_runtime: ::__u64, + pub sched_deadline: ::__u64, + pub sched_period: ::__u64, + } } s_no_extra_traits! { @@ -1343,6 +1354,46 @@ cfg_if! { self.rx_filter.hash(state); } } + + impl ::fmt::Debug for sched_attr { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sched_attr") + .field("size", &self.size) + .field("sched_policy", &self.sched_policy) + .field("sched_flags", &self.sched_flags) + .field("sched_nice", &self.sched_nice) + .field("sched_priority", &self.sched_priority) + .field("sched_runtime", &self.sched_runtime) + .field("sched_deadline", &self.sched_deadline) + .field("sched_period", &self.sched_period) + .finish() + } + } + impl PartialEq for sched_attr { + fn eq(&self, other: &sched_attr) -> bool { + self.size == other.size && + self.sched_policy == other.sched_policy && + self.sched_flags == other.sched_flags && + self.sched_nice == other.sched_nice && + self.sched_priority == other.sched_priority && + self.sched_runtime == other.sched_runtime && + self.sched_deadline == other.sched_deadline && + self.sched_period == other.sched_period + } + } + impl Eq for sched_attr {} + impl ::hash::Hash for sched_attr { + fn hash(&self, state: &mut H) { + self.size.hash(state); + self.sched_policy.hash(state); + self.sched_flags.hash(state); + self.sched_nice.hash(state); + self.sched_priority.hash(state); + self.sched_runtime.hash(state); + self.sched_deadline.hash(state); + self.sched_period.hash(state); + } + } } } @@ -2032,16 +2083,6 @@ pub const RENAME_NOREPLACE: ::c_uint = 1; pub const RENAME_EXCHANGE: ::c_uint = 2; pub const RENAME_WHITEOUT: ::c_uint = 4; -pub const SCHED_OTHER: ::c_int = 0; -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_RR: ::c_int = 2; -pub const SCHED_BATCH: ::c_int = 3; -pub const SCHED_IDLE: ::c_int = 5; - -pub const SCHED_RESET_ON_FORK: ::c_int = 0x40000000; - -pub const CLONE_PIDFD: ::c_int = 0x1000; - // netinet/in.h // NOTE: These are in addition to the constants defined in src/unix/mod.rs @@ -4588,6 +4629,38 @@ pub const PF_NO_SETAFFINITY: ::c_int = 0x04000000; pub const PF_MCE_EARLY: ::c_int = 0x08000000; pub const PF_MEMALLOC_PIN: ::c_int = 0x10000000; +pub const CSIGNAL: ::c_int = 0x000000ff; + +pub const SCHED_NORMAL: ::c_int = 0; +pub const SCHED_OTHER: ::c_int = 0; +pub const SCHED_FIFO: ::c_int = 1; +pub const SCHED_RR: ::c_int = 2; +pub const SCHED_BATCH: ::c_int = 3; +pub const SCHED_IDLE: ::c_int = 5; +pub const SCHED_DEADLINE: ::c_int = 6; + +pub const SCHED_RESET_ON_FORK: ::c_int = 0x40000000; + +pub const CLONE_PIDFD: ::c_int = 0x1000; + +pub const SCHED_FLAG_RESET_ON_FORK: ::c_int = 0x01; +pub const SCHED_FLAG_RECLAIM: ::c_int = 0x02; +pub const SCHED_FLAG_DL_OVERRUN: ::c_int = 0x04; +pub const SCHED_FLAG_KEEP_POLICY: ::c_int = 0x08; +pub const SCHED_FLAG_KEEP_PARAMS: ::c_int = 0x10; +pub const SCHED_FLAG_UTIL_CLAMP_MIN: ::c_int = 0x20; +pub const SCHED_FLAG_UTIL_CLAMP_MAX: ::c_int = 0x40; + +pub const SCHED_FLAG_KEEP_ALL: ::c_int = SCHED_FLAG_KEEP_POLICY | SCHED_FLAG_KEEP_PARAMS; + +pub const SCHED_FLAG_UTIL_CLAMP: ::c_int = SCHED_FLAG_UTIL_CLAMP_MIN | SCHED_FLAG_UTIL_CLAMP_MAX; + +pub const SCHED_FLAG_ALL: ::c_int = SCHED_FLAG_RESET_ON_FORK + | SCHED_FLAG_RECLAIM + | SCHED_FLAG_DL_OVERRUN + | SCHED_FLAG_KEEP_ALL + | SCHED_FLAG_UTIL_CLAMP; + f! { pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) From d2368e5bc9f3ba0fb6fd43d4369a7e10c21b185c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 5 Jan 2024 15:48:36 +0100 Subject: [PATCH 2/2] Ignore `sched_attr` type for linux test --- libc-test/build.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index a3dc1bc5b2e3c..1b65d65f95ec9 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3705,6 +3705,12 @@ fn test_linux(target: &str) { // https://github.com/torvalds/linux/commit/c05cd3645814724bdeb32a2b4d953b12bdea5f8c "xdp_umem_reg_v1" => true, + // Is defined in `` but if this file is included at the same time + // as ``, the `struct sched_param` is defined twice, causing the compilation to + // fail. The problem doesn't seem to be present in more recent versions of the linux + // kernel so we can drop this and test the type once this new version is used in CI. + "sched_attr" => true, + _ => false, } }); @@ -4123,6 +4129,14 @@ fn test_linux(target: &str) { | "PF_MCE_EARLY" | "PF_MEMALLOC_PIN" => true, + "SCHED_FLAG_KEEP_POLICY" + | "SCHED_FLAG_KEEP_PARAMS" + | "SCHED_FLAG_UTIL_CLAMP_MIN" + | "SCHED_FLAG_UTIL_CLAMP_MAX" + | "SCHED_FLAG_KEEP_ALL" + | "SCHED_FLAG_UTIL_CLAMP" + | "SCHED_FLAG_ALL" if musl => true, // Needs more recent linux headers. + _ => false, } });