Skip to content

Commit

Permalink
Auto merge of #2166 - devnexen:cpu_affinity_fbsd, r=JohnTitor
Browse files Browse the repository at this point in the history
freebsd update adding cpu affinity api subset
  • Loading branch information
bors committed May 13, 2021
2 parents 065b22c + fc8f48f commit d02ce7f
Show file tree
Hide file tree
Showing 2 changed files with 57 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 @@ -1724,6 +1724,7 @@ fn test_freebsd(target: &str) {
"stdio.h",
"stdlib.h",
"string.h",
"sys/cpuset.h",
"sys/event.h",
"sys/extattr.h",
"sys/file.h",
Expand Down
56 changes: 56 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub type key_t = ::c_long;
pub type msglen_t = ::c_ulong;
pub type msgqnum_t = ::c_ulong;

pub type cpulevel_t = ::c_int;
pub type cpuwhich_t = ::c_int;

pub type mqd_t = *mut ::c_void;
pub type posix_spawnattr_t = *mut ::c_void;
pub type posix_spawn_file_actions_t = *mut ::c_void;
Expand Down Expand Up @@ -121,6 +124,13 @@ s! {
pub pve_fsid: u32,
pub pve_path: *mut ::c_char,
}

pub struct cpuset_t {
#[cfg(target_pointer_width = "64")]
__bits: [::c_long; 4],
#[cfg(target_pointer_width = "32")]
__bits: [::c_long; 8],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -1265,6 +1275,38 @@ f! {
pub fn uname(buf: *mut ::utsname) -> ::c_int {
__xuname(256, buf as *mut ::c_void)
}

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

pub fn CPU_FILL(cpuset: &mut cpuset_t) -> () {
for slot in cpuset.__bits.iter_mut() {
*slot = !0;
}
}

pub fn CPU_SET(cpu: usize, cpuset: &mut cpuset_t) -> () {
let bitset_bits = ::mem::size_of::<::c_long>();
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
cpuset.__bits[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpuset_t) -> () {
let bitset_bits = ::mem::size_of::<::c_long>();
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
cpuset.__bits[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &mut cpuset_t) -> bool {
let bitset_bits = ::mem::size_of::<::c_long>();
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
0 != cpuset.__bits[idx] & (1 << offset)
}
}

safe_f! {
Expand Down Expand Up @@ -1527,6 +1569,20 @@ extern "C" {
) -> *mut ::c_void;

pub fn nmount(iov: *mut ::iovec, niov: ::c_uint, flags: ::c_int) -> ::c_int;
pub fn cpuset_getaffinity(
level: cpulevel_t,
which: cpuwhich_t,
id: ::id_t,
setsize: ::size_t,
mask: *mut cpuset_t,
) -> ::c_int;
pub fn cpuset_setaffinity(
level: cpulevel_t,
which: cpuwhich_t,
id: ::id_t,
setsize: ::size_t,
mask: *const cpuset_t,
) -> ::c_int;
}

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

0 comments on commit d02ce7f

Please sign in to comment.