Skip to content

Commit 40c502b

Browse files
committed
Auto merge of #2184 - devnexen:dflybsd_affinity, r=JohnTitor
dragonflybsd cpu affinity api
2 parents 335b919 + 677a1b4 commit 40c502b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ fn test_dragonflybsd(target: &str) {
11461146
"sys/ptrace.h",
11471147
"sys/resource.h",
11481148
"sys/rtprio.h",
1149+
"sys/sched.h",
11491150
"sys/socket.h",
11501151
"sys/stat.h",
11511152
"sys/statvfs.h",

libc-test/semver/dragonfly.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ CMSG_LEN
137137
CMSG_NXTHDR
138138
CMSG_SPACE
139139
CODESET
140+
CPU_CLR
141+
CPU_ISSET
142+
CPU_SET
143+
CPU_ZERO
140144
CRNCYSTR
141145
CRTSCTS
142146
CRTS_IFLOW

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub type idtype_t = ::c_uint;
2222
pub type mqd_t = ::c_int;
2323
pub type sem_t = *mut sem;
2424

25+
pub type cpuset_t = cpumask_t;
26+
pub type cpu_set_t = cpumask_t;
27+
2528
#[cfg_attr(feature = "extra_traits", derive(Debug))]
2629
pub enum sem {}
2730
impl ::Copy for sem {}
@@ -184,6 +187,10 @@ s! {
184187
pub ss_size: ::size_t,
185188
pub ss_flags: ::c_int,
186189
}
190+
191+
pub struct cpumask_t {
192+
ary: [u64; 4],
193+
}
187194
}
188195

189196
s_no_extra_traits! {
@@ -1056,6 +1063,29 @@ f! {
10561063
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
10571064
_CMSG_ALIGN(length as usize)) as ::c_uint
10581065
}
1066+
1067+
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
1068+
for slot in cpuset.ary.iter_mut() {
1069+
*slot = 0;
1070+
}
1071+
}
1072+
1073+
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
1074+
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
1075+
cpuset.ary[idx] |= 1 << offset;
1076+
()
1077+
}
1078+
1079+
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
1080+
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
1081+
cpuset.ary[idx] &= !(1 << offset);
1082+
()
1083+
}
1084+
1085+
pub fn CPU_ISSET(cpu: usize, cpuset: &mut cpu_set_t) -> bool {
1086+
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
1087+
0 != cpuset.ary[idx] & (1 << offset)
1088+
}
10591089
}
10601090

10611091
safe_f! {
@@ -1098,6 +1128,9 @@ extern "C" {
10981128
needle: *const ::c_void,
10991129
needlelen: ::size_t,
11001130
) -> *mut ::c_void;
1131+
pub fn sched_getaffinity(pid: ::pid_t, cpusetsize: ::size_t, mask: *mut cpu_set_t) -> ::c_int;
1132+
pub fn sched_setaffinity(pid: ::pid_t, cpusetsize: ::size_t, mask: *const cpu_set_t)
1133+
-> ::c_int;
11011134
}
11021135

11031136
#[link(name = "rt")]

0 commit comments

Comments
 (0)