Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more items from include/linux/sched.h header #3515

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3705,6 +3705,12 @@ fn test_linux(target: &str) {
// https://github.com/torvalds/linux/commit/c05cd3645814724bdeb32a2b4d953b12bdea5f8c
"xdp_umem_reg_v1" => true,

// Is defined in `<linux/sched/types.h>` but if this file is included at the same time
// as `<sched.h>`, 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,
}
});
Expand Down Expand Up @@ -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,
}
});
Expand Down
93 changes: 83 additions & 10 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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<H: ::hash::Hasher>(&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);
}
}
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down