authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-31 11:01:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-31 11:01:42-07:00
log182bec87718dda88406575f0dea18bf11954c88c
tree782b9bdeef18f97a4a8ac9c48b01c639dbd65916
parent86a5edca6238f4c9b861931e40d8cbe005568819

Revert "std.os: adding linux's sched_setaffinity and its wrapper"

This reverts commit c7bf8bab38f8b89c1371eedb9229e00a29b5ca5b.

3 files changed, 0 insertions(+), 63 deletions(-)

lib/std/c/linux.zig-5
......@@ -13,10 +13,6 @@ pub const ARCH = linux.ARCH;
1313pub const AT = linux.AT;
1414pub const CLOCK = linux.CLOCK;
1515pub const CPU_COUNT = linux.CPU_COUNT;
16pub const CPU_SET = linux.CPU_SET;
17pub const CPU_ISSET = linux.CPU_ISSET;
18pub const CPU_CLR = linux.CPU_CLR;
19pub const CPU_ZERO = linux.CPU_ZERO;
2016pub const E = linux.E;
2117pub const Elf_Symndx = linux.Elf_Symndx;
2218pub const F = linux.F;
......@@ -249,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_
249245
250246pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
251247pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
252pub extern "c" fn sched_setaffinity(pid: c_int, size: usize, set: *const cpu_set_t) c_int;
253248pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
254249pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
255250pub extern "c" fn epoll_create1(flags: c_uint) c_int;
lib/std/os.zig-21
......@@ -5494,7 +5494,6 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
54945494}
54955495
54965496pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
5497pub const SchedSetAffinityError = error{ InvalidCpu, PermissionDenied } || UnexpectedError;
54985497
54995498pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
55005499 var set: cpu_set_t = undefined;
......@@ -5522,26 +5521,6 @@ pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
55225521 }
55235522}
55245523
5525pub fn sched_setaffinity(pid: pid_t, cpus: []usize) SchedSetAffinityError!cpu_set_t {
5526 var set: cpu_set_t = undefined;
5527 if (builtin.os.tag == .linux) {
5528 system.CPU_ZERO(&set);
5529 for (cpus) |cpu| {
5530 system.CPU_SET(cpu, &set);
5531 }
5532 switch (errno(system.sched_setaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5533 .SUCCESS => return set,
5534 .FAULT => unreachable,
5535 .SRCH => unreachable,
5536 .INVAL => return error.InvalidCpu,
5537 .PERM => return error.PermissionDenied,
5538 else => |err| return unexpectedErrno(err),
5539 }
5540 } else {
5541 @compileError("unsupported platform");
5542 }
5543}
5544
55455524/// Used to convert a slice to a null terminated slice on the stack.
55465525/// TODO https://github.com/ziglang/zig/issues/287
55475526pub fn toPosixPath(file_path: []const u8) ![MAX_PATH_BYTES - 1:0]u8 {
lib/std/os/linux.zig-37
......@@ -1536,12 +1536,6 @@ pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxno
15361536 return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);
15371537}
15381538
1539pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize {
1540 const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1541 if (@as(isize, @bitCast(rc)) < 0) return rc;
1542 return 0;
1543}
1544
15451539pub fn epoll_create() usize {
15461540 return epoll_create1(0);
15471541}
......@@ -3560,11 +3554,6 @@ pub const CPU_SETSIZE = 128;
35603554pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
35613555pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
35623556
3563fn cpu_mask(s: usize) cpu_count_t {
3564 var x = s & (CPU_SETSIZE * 8);
3565 return @as(cpu_count_t, @intCast(1)) << @as(u4, @intCast(x));
3566}
3567
35683557pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
35693558 var sum: cpu_count_t = 0;
35703559 for (set) |x| {
......@@ -3573,32 +3562,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
35733562 return sum;
35743563}
35753564
3576pub fn CPU_ZERO(set: *cpu_set_t) void {
3577 @memset(set, 0);
3578}
3579
3580pub fn CPU_SET(cpu: usize, set: *cpu_set_t) void {
3581 const x = cpu / @sizeOf(usize);
3582 if (x < @sizeOf(cpu_set_t)) {
3583 (set.*)[x] |= cpu_mask(x);
3584 }
3585}
3586
3587pub fn CPU_ISSET(cpu: usize, set: cpu_set_t) bool {
3588 const x = cpu / @sizeOf(usize);
3589 if (x < @sizeOf(cpu_set_t)) {
3590 return set[x] & cpu_mask(x) != 0;
3591 }
3592 return false;
3593}
3594
3595pub fn CPU_CLR(cpu: usize, set: *cpu_set_t) void {
3596 const x = cpu / @sizeOf(usize);
3597 if (x < @sizeOf(cpu_set_t)) {
3598 (set.*)[x] &= !cpu_mask(x);
3599 }
3600}
3601
36023565pub const MINSIGSTKSZ = switch (native_arch) {
36033566 .x86, .x86_64, .arm, .mipsel => 2048,
36043567 .aarch64 => 5120,