Skip to content

Commit fc8f48f

Browse files
committed
freebsd update adding cpu affinity api subset
1 parent d56360a commit fc8f48f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

libc-test/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ fn test_freebsd(target: &str) {
17241724
"stdio.h",
17251725
"stdlib.h",
17261726
"string.h",
1727+
"sys/cpuset.h",
17271728
"sys/event.h",
17281729
"sys/extattr.h",
17291730
"sys/file.h",

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

+56
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub type key_t = ::c_long;
1414
pub type msglen_t = ::c_ulong;
1515
pub type msgqnum_t = ::c_ulong;
1616

17+
pub type cpulevel_t = ::c_int;
18+
pub type cpuwhich_t = ::c_int;
19+
1720
pub type mqd_t = *mut ::c_void;
1821
pub type posix_spawnattr_t = *mut ::c_void;
1922
pub type posix_spawn_file_actions_t = *mut ::c_void;
@@ -121,6 +124,13 @@ s! {
121124
pub pve_fsid: u32,
122125
pub pve_path: *mut ::c_char,
123126
}
127+
128+
pub struct cpuset_t {
129+
#[cfg(target_pointer_width = "64")]
130+
__bits: [::c_long; 4],
131+
#[cfg(target_pointer_width = "32")]
132+
__bits: [::c_long; 8],
133+
}
124134
}
125135

126136
s_no_extra_traits! {
@@ -1265,6 +1275,38 @@ f! {
12651275
pub fn uname(buf: *mut ::utsname) -> ::c_int {
12661276
__xuname(256, buf as *mut ::c_void)
12671277
}
1278+
1279+
pub fn CPU_ZERO(cpuset: &mut cpuset_t) -> () {
1280+
for slot in cpuset.__bits.iter_mut() {
1281+
*slot = 0;
1282+
}
1283+
}
1284+
1285+
pub fn CPU_FILL(cpuset: &mut cpuset_t) -> () {
1286+
for slot in cpuset.__bits.iter_mut() {
1287+
*slot = !0;
1288+
}
1289+
}
1290+
1291+
pub fn CPU_SET(cpu: usize, cpuset: &mut cpuset_t) -> () {
1292+
let bitset_bits = ::mem::size_of::<::c_long>();
1293+
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
1294+
cpuset.__bits[idx] |= 1 << offset;
1295+
()
1296+
}
1297+
1298+
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpuset_t) -> () {
1299+
let bitset_bits = ::mem::size_of::<::c_long>();
1300+
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
1301+
cpuset.__bits[idx] &= !(1 << offset);
1302+
()
1303+
}
1304+
1305+
pub fn CPU_ISSET(cpu: usize, cpuset: &mut cpuset_t) -> bool {
1306+
let bitset_bits = ::mem::size_of::<::c_long>();
1307+
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
1308+
0 != cpuset.__bits[idx] & (1 << offset)
1309+
}
12681310
}
12691311

12701312
safe_f! {
@@ -1527,6 +1569,20 @@ extern "C" {
15271569
) -> *mut ::c_void;
15281570

15291571
pub fn nmount(iov: *mut ::iovec, niov: ::c_uint, flags: ::c_int) -> ::c_int;
1572+
pub fn cpuset_getaffinity(
1573+
level: cpulevel_t,
1574+
which: cpuwhich_t,
1575+
id: ::id_t,
1576+
setsize: ::size_t,
1577+
mask: *mut cpuset_t,
1578+
) -> ::c_int;
1579+
pub fn cpuset_setaffinity(
1580+
level: cpulevel_t,
1581+
which: cpuwhich_t,
1582+
id: ::id_t,
1583+
setsize: ::size_t,
1584+
mask: *const cpuset_t,
1585+
) -> ::c_int;
15301586
}
15311587

15321588
#[link(name = "util")]

0 commit comments

Comments
 (0)