Skip to content

Commit

Permalink
Auto merge of #2184 - devnexen:dflybsd_affinity, r=JohnTitor
Browse files Browse the repository at this point in the history
dragonflybsd cpu affinity api
  • Loading branch information
bors committed May 23, 2021
2 parents 335b919 + 677a1b4 commit 40c502b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ fn test_dragonflybsd(target: &str) {
"sys/ptrace.h",
"sys/resource.h",
"sys/rtprio.h",
"sys/sched.h",
"sys/socket.h",
"sys/stat.h",
"sys/statvfs.h",
Expand Down
4 changes: 4 additions & 0 deletions libc-test/semver/dragonfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ CMSG_LEN
CMSG_NXTHDR
CMSG_SPACE
CODESET
CPU_CLR
CPU_ISSET
CPU_SET
CPU_ZERO
CRNCYSTR
CRTSCTS
CRTS_IFLOW
Expand Down
33 changes: 33 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub type idtype_t = ::c_uint;
pub type mqd_t = ::c_int;
pub type sem_t = *mut sem;

pub type cpuset_t = cpumask_t;
pub type cpu_set_t = cpumask_t;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum sem {}
impl ::Copy for sem {}
Expand Down Expand Up @@ -184,6 +187,10 @@ s! {
pub ss_size: ::size_t,
pub ss_flags: ::c_int,
}

pub struct cpumask_t {
ary: [u64; 4],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -1056,6 +1063,29 @@ f! {
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
_CMSG_ALIGN(length as usize)) as ::c_uint
}

pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.ary.iter_mut() {
*slot = 0;
}
}

pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
cpuset.ary[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
cpuset.ary[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &mut cpu_set_t) -> bool {
let (idx, offset) = ((cpu >> 6) & 3, cpu & 63);
0 != cpuset.ary[idx] & (1 << offset)
}
}

safe_f! {
Expand Down Expand Up @@ -1098,6 +1128,9 @@ extern "C" {
needle: *const ::c_void,
needlelen: ::size_t,
) -> *mut ::c_void;
pub fn sched_getaffinity(pid: ::pid_t, cpusetsize: ::size_t, mask: *mut cpu_set_t) -> ::c_int;
pub fn sched_setaffinity(pid: ::pid_t, cpusetsize: ::size_t, mask: *const cpu_set_t)
-> ::c_int;
}

#[link(name = "rt")]
Expand Down

0 comments on commit 40c502b

Please sign in to comment.