Skip to content

Commit 6f418c1

Browse files
devnexenVexu
authored andcommitted
linux adding some NUMA support
1 parent cceadf5 commit 6f418c1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/std/c/linux.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,19 @@ pub const dirent64 = struct {
371371
d_type: u8,
372372
d_name: [256]u8,
373373
};
374+
375+
pub const MPOL = struct {
376+
pub const F_NODE = 1 << 0;
377+
pub const F_ADDR = 1 << 1;
378+
pub const F_MEMS_ALLOWED = 1 << 2;
379+
/// flags for SYS_mbind
380+
pub const MF_STRICT = 1 << 0;
381+
pub const MF_MOVE = 1 << 1;
382+
pub const MF_MOVE_ALL = 1 << 2;
383+
pub const MF_LAZY = 1 << 3;
384+
pub const MF_INTERNAL = 1 << 4;
385+
pub const MF_VALID = MPOL.MF_STRICT | MPOL.MF_MOVE | MPOL.MOVE_ALL;
386+
};
387+
388+
pub extern "c" fn getcpu(cpu: *c_uint, node: *c_uint) c_int;
389+
pub extern "c" fn sched_getcpu() c_int;

lib/std/os/linux.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,22 @@ pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
15191519
return 0;
15201520
}
15211521

1522+
pub fn getcpu(cpu: *u32, node: *u32) usize {
1523+
return syscall3(.getcpu, cpu, node, null);
1524+
}
1525+
1526+
pub fn sched_getcpu() usize {
1527+
var cpu: u32 = undefined;
1528+
const rc = syscall3(.getcpu, &cpu, null, null);
1529+
if (@bitCast(isize, rc) < 0) return rc;
1530+
return @intCast(usize, cpu);
1531+
}
1532+
1533+
/// libc has no wrapper for this syscall
1534+
pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize {
1535+
return syscall6(.mbind, addr, len, mode, nodemask, maxnode, flags);
1536+
}
1537+
15221538
pub fn epoll_create() usize {
15231539
return epoll_create1(0);
15241540
}

0 commit comments

Comments
 (0)