Skip to content

Commit 928f2d6

Browse files
committed
Auto merge of #3515 - GuillaumeGomez:more-sched-items, r=JohnTitor
Add more items from `include/linux/sched.h` header More items coming from the header file `include/linux/sched.h`. Re-opening of #3513 because of a wrong push on my end (sorry). r? `@JohnTitor`
2 parents ab55aed + d2368e5 commit 928f2d6

File tree

2 files changed

+97
-10
lines changed

2 files changed

+97
-10
lines changed

libc-test/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,6 +3705,12 @@ fn test_linux(target: &str) {
37053705
// https://github.com/torvalds/linux/commit/c05cd3645814724bdeb32a2b4d953b12bdea5f8c
37063706
"xdp_umem_reg_v1" => true,
37073707

3708+
// Is defined in `<linux/sched/types.h>` but if this file is included at the same time
3709+
// as `<sched.h>`, the `struct sched_param` is defined twice, causing the compilation to
3710+
// fail. The problem doesn't seem to be present in more recent versions of the linux
3711+
// kernel so we can drop this and test the type once this new version is used in CI.
3712+
"sched_attr" => true,
3713+
37083714
_ => false,
37093715
}
37103716
});
@@ -4123,6 +4129,14 @@ fn test_linux(target: &str) {
41234129
| "PF_MCE_EARLY"
41244130
| "PF_MEMALLOC_PIN" => true,
41254131

4132+
"SCHED_FLAG_KEEP_POLICY"
4133+
| "SCHED_FLAG_KEEP_PARAMS"
4134+
| "SCHED_FLAG_UTIL_CLAMP_MIN"
4135+
| "SCHED_FLAG_UTIL_CLAMP_MAX"
4136+
| "SCHED_FLAG_KEEP_ALL"
4137+
| "SCHED_FLAG_UTIL_CLAMP"
4138+
| "SCHED_FLAG_ALL" if musl => true, // Needs more recent linux headers.
4139+
41264140
_ => false,
41274141
}
41284142
});

src/unix/linux_like/linux/mod.rs

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,17 @@ s_no_extra_traits! {
878878
pub d_type: ::c_uchar,
879879
pub d_name: [::c_char; 256],
880880
}
881+
882+
pub struct sched_attr {
883+
pub size: ::__u32,
884+
pub sched_policy: ::__u32,
885+
pub sched_flags: ::__u64,
886+
pub sched_nice: ::__s32,
887+
pub sched_priority: ::__u32,
888+
pub sched_runtime: ::__u64,
889+
pub sched_deadline: ::__u64,
890+
pub sched_period: ::__u64,
891+
}
881892
}
882893

883894
s_no_extra_traits! {
@@ -1343,6 +1354,46 @@ cfg_if! {
13431354
self.rx_filter.hash(state);
13441355
}
13451356
}
1357+
1358+
impl ::fmt::Debug for sched_attr {
1359+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1360+
f.debug_struct("sched_attr")
1361+
.field("size", &self.size)
1362+
.field("sched_policy", &self.sched_policy)
1363+
.field("sched_flags", &self.sched_flags)
1364+
.field("sched_nice", &self.sched_nice)
1365+
.field("sched_priority", &self.sched_priority)
1366+
.field("sched_runtime", &self.sched_runtime)
1367+
.field("sched_deadline", &self.sched_deadline)
1368+
.field("sched_period", &self.sched_period)
1369+
.finish()
1370+
}
1371+
}
1372+
impl PartialEq for sched_attr {
1373+
fn eq(&self, other: &sched_attr) -> bool {
1374+
self.size == other.size &&
1375+
self.sched_policy == other.sched_policy &&
1376+
self.sched_flags == other.sched_flags &&
1377+
self.sched_nice == other.sched_nice &&
1378+
self.sched_priority == other.sched_priority &&
1379+
self.sched_runtime == other.sched_runtime &&
1380+
self.sched_deadline == other.sched_deadline &&
1381+
self.sched_period == other.sched_period
1382+
}
1383+
}
1384+
impl Eq for sched_attr {}
1385+
impl ::hash::Hash for sched_attr {
1386+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1387+
self.size.hash(state);
1388+
self.sched_policy.hash(state);
1389+
self.sched_flags.hash(state);
1390+
self.sched_nice.hash(state);
1391+
self.sched_priority.hash(state);
1392+
self.sched_runtime.hash(state);
1393+
self.sched_deadline.hash(state);
1394+
self.sched_period.hash(state);
1395+
}
1396+
}
13461397
}
13471398
}
13481399

@@ -2032,16 +2083,6 @@ pub const RENAME_NOREPLACE: ::c_uint = 1;
20322083
pub const RENAME_EXCHANGE: ::c_uint = 2;
20332084
pub const RENAME_WHITEOUT: ::c_uint = 4;
20342085

2035-
pub const SCHED_OTHER: ::c_int = 0;
2036-
pub const SCHED_FIFO: ::c_int = 1;
2037-
pub const SCHED_RR: ::c_int = 2;
2038-
pub const SCHED_BATCH: ::c_int = 3;
2039-
pub const SCHED_IDLE: ::c_int = 5;
2040-
2041-
pub const SCHED_RESET_ON_FORK: ::c_int = 0x40000000;
2042-
2043-
pub const CLONE_PIDFD: ::c_int = 0x1000;
2044-
20452086
// netinet/in.h
20462087
// NOTE: These are in addition to the constants defined in src/unix/mod.rs
20472088

@@ -4588,6 +4629,38 @@ pub const PF_NO_SETAFFINITY: ::c_int = 0x04000000;
45884629
pub const PF_MCE_EARLY: ::c_int = 0x08000000;
45894630
pub const PF_MEMALLOC_PIN: ::c_int = 0x10000000;
45904631

4632+
pub const CSIGNAL: ::c_int = 0x000000ff;
4633+
4634+
pub const SCHED_NORMAL: ::c_int = 0;
4635+
pub const SCHED_OTHER: ::c_int = 0;
4636+
pub const SCHED_FIFO: ::c_int = 1;
4637+
pub const SCHED_RR: ::c_int = 2;
4638+
pub const SCHED_BATCH: ::c_int = 3;
4639+
pub const SCHED_IDLE: ::c_int = 5;
4640+
pub const SCHED_DEADLINE: ::c_int = 6;
4641+
4642+
pub const SCHED_RESET_ON_FORK: ::c_int = 0x40000000;
4643+
4644+
pub const CLONE_PIDFD: ::c_int = 0x1000;
4645+
4646+
pub const SCHED_FLAG_RESET_ON_FORK: ::c_int = 0x01;
4647+
pub const SCHED_FLAG_RECLAIM: ::c_int = 0x02;
4648+
pub const SCHED_FLAG_DL_OVERRUN: ::c_int = 0x04;
4649+
pub const SCHED_FLAG_KEEP_POLICY: ::c_int = 0x08;
4650+
pub const SCHED_FLAG_KEEP_PARAMS: ::c_int = 0x10;
4651+
pub const SCHED_FLAG_UTIL_CLAMP_MIN: ::c_int = 0x20;
4652+
pub const SCHED_FLAG_UTIL_CLAMP_MAX: ::c_int = 0x40;
4653+
4654+
pub const SCHED_FLAG_KEEP_ALL: ::c_int = SCHED_FLAG_KEEP_POLICY | SCHED_FLAG_KEEP_PARAMS;
4655+
4656+
pub const SCHED_FLAG_UTIL_CLAMP: ::c_int = SCHED_FLAG_UTIL_CLAMP_MIN | SCHED_FLAG_UTIL_CLAMP_MAX;
4657+
4658+
pub const SCHED_FLAG_ALL: ::c_int = SCHED_FLAG_RESET_ON_FORK
4659+
| SCHED_FLAG_RECLAIM
4660+
| SCHED_FLAG_DL_OVERRUN
4661+
| SCHED_FLAG_KEEP_ALL
4662+
| SCHED_FLAG_UTIL_CLAMP;
4663+
45914664
f! {
45924665
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
45934666
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)

0 commit comments

Comments
 (0)