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;...@@ -13,6 +13,19 @@ pub const cpulevel_t = c_int;
13pub const cpuwhich_t = c_int;13pub const cpuwhich_t = c_int;
14pub const id_t = i64;14pub 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
16extern "c" fn __error() *c_int;29extern "c" fn __error() *c_int;
17pub const _errno = __error;30pub const _errno = __error;
1831
lib/std/os.zig+27-8
...@@ -141,7 +141,12 @@ pub const addrinfo = system.addrinfo;...@@ -141,7 +141,12 @@ pub const addrinfo = system.addrinfo;
141pub const blkcnt_t = system.blkcnt_t;141pub const blkcnt_t = system.blkcnt_t;
142pub const blksize_t = system.blksize_t;142pub const blksize_t = system.blksize_t;
143pub const clock_t = system.clock_t;143pub 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;
145pub const dev_t = system.dev_t;150pub const dev_t = system.dev_t;
146pub const dl_phdr_info = system.dl_phdr_info;151pub const dl_phdr_info = system.dl_phdr_info;
147pub const empty_sigset = system.empty_sigset;152pub const empty_sigset = system.empty_sigset;
...@@ -5518,13 +5523,27 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;...@@ -5518,13 +5523,27 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
55185523
5519pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {5524pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
5520 var set: cpu_set_t = undefined;5525 var set: cpu_set_t = undefined;
5521 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {5526 if (builtin.os.tag == .linux) {
5522 .SUCCESS => return set,5527 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5523 .FAULT => unreachable,5528 .SUCCESS => return set,
5524 .INVAL => unreachable,5529 .FAULT => unreachable,
5525 .SRCH => unreachable,5530 .INVAL => unreachable,
5526 .PERM => return error.PermissionDenied,5531 .SRCH => unreachable,
5527 else => |err| return unexpectedErrno(err),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");
5528 }5547 }
5529}5548}
55305549