authorgravatar for devnexen@gmail.comDavid Carlier <devnexen@gmail.com> 2023-04-19 22:49:14+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-04-22 13:54:57+03:00
logdbdafb6cc503ce5820713dfa79cc956438b7957a
tree568c04a877a05c9f2ad26d1e7af09034de775675
parent0282c2a924054472ccc8d82325e8393442381760

os: expand sched_getaffinity wrapper and update freebsd's cpuset api flags.


2 files changed, 40 insertions(+), 8 deletions(-)

lib/std/c/freebsd.zig+13
......@@ -13,6 +13,19 @@ pub const cpulevel_t = c_int;
1313pub const cpuwhich_t = c_int;
1414pub const id_t = i64;
1515
16pub const CPU_LEVEL_ROOT: cpulevel_t = 1;
17pub const CPU_LEVEL_CPUSET: cpulevel_t = 2;
18pub const CPU_LEVEL_WHICH: cpulevel_t = 3;
19pub const CPU_WHICH_TID: cpuwhich_t = 1;
20pub const CPU_WHICH_PID: cpuwhich_t = 2;
21pub const CPU_WHICH_CPUSET: cpuwhich_t = 3;
22pub const CPU_WHICH_IRQ: cpuwhich_t = 4;
23pub const CPU_WHICH_JAIL: cpuwhich_t = 5;
24pub const CPU_WHICH_DOMAIN: cpuwhich_t = 6;
25pub const CPU_WHICH_INTRHANDLER: cpuwhich_t = 7;
26pub const CPU_WHICH_ITHREAD: cpuwhich_t = 8;
27pub const CPU_WHICH_TIDPID: cpuwhich_t = 8;
28
1629extern "c" fn __error() *c_int;
1730pub const _errno = __error;
1831
lib/std/os.zig+27-8
......@@ -141,7 +141,12 @@ pub const addrinfo = system.addrinfo;
141141pub const blkcnt_t = system.blkcnt_t;
142142pub const blksize_t = system.blksize_t;
143143pub const clock_t = system.clock_t;
144pub const cpu_set_t = system.cpu_set_t;
144pub const cpu_set_t = if (builtin.os.tag == .linux)
145 system.cpu_set_t
146else if (builtin.os.tag == .freebsd)
147 freebsd.cpuset_t
148else
149 u32;
145150pub const dev_t = system.dev_t;
146151pub const dl_phdr_info = system.dl_phdr_info;
147152pub const empty_sigset = system.empty_sigset;
......@@ -5518,13 +5523,27 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
55185523
55195524pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
55205525 var set: cpu_set_t = undefined;
5521 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5522 .SUCCESS => return set,
5523 .FAULT => unreachable,
5524 .INVAL => unreachable,
5525 .SRCH => unreachable,
5526 .PERM => return error.PermissionDenied,
5527 else => |err| return unexpectedErrno(err),
5526 if (builtin.os.tag == .linux) {
5527 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5528 .SUCCESS => return set,
5529 .FAULT => unreachable,
5530 .INVAL => unreachable,
5531 .SRCH => unreachable,
5532 .PERM => return error.PermissionDenied,
5533 else => |err| return unexpectedErrno(err),
5534 }
5535 } else if (builtin.os.tag == .freebsd) {
5536 switch (errno(freebsd.cpuset_getaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
5537 .SUCCESS => return set,
5538 .FAULT => unreachable,
5539 .INVAL => unreachable,
5540 .SRCH => unreachable,
5541 .EDEADLK => unreachable,
5542 .PERM => return error.PermissionDenied,
5543 else => |err| return unexpectedErrno(err),
5544 }
5545 } else {
5546 @compileError("unsupported platform");
55285547 }
55295548}
55305549