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;...@@ -13,10 +13,6 @@ pub const ARCH = linux.ARCH;
13pub const AT = linux.AT;13pub const AT = linux.AT;
14pub const CLOCK = linux.CLOCK;14pub const CLOCK = linux.CLOCK;
15pub const CPU_COUNT = linux.CPU_COUNT;15pub 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;
20pub const E = linux.E;16pub const E = linux.E;
21pub const Elf_Symndx = linux.Elf_Symndx;17pub const Elf_Symndx = linux.Elf_Symndx;
22pub const F = linux.F;18pub const F = linux.F;
...@@ -249,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_...@@ -249,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_
249245
250pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;246pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
251pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;247pub 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;
253pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;248pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
254pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;249pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
255pub extern "c" fn epoll_create1(flags: c_uint) c_int;250pub 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 {...@@ -5494,7 +5494,6 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
5494}5494}
54955495
5496pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;5496pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
5497pub const SchedSetAffinityError = error{ InvalidCpu, PermissionDenied } || UnexpectedError;
54985497
5499pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {5498pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
5500 var set: cpu_set_t = undefined;5499 var set: cpu_set_t = undefined;
...@@ -5522,26 +5521,6 @@ pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {...@@ -5522,26 +5521,6 @@ pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
5522 }5521 }
5523}5522}
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
5545/// Used to convert a slice to a null terminated slice on the stack.5524/// Used to convert a slice to a null terminated slice on the stack.
5546/// TODO https://github.com/ziglang/zig/issues/2875525/// TODO https://github.com/ziglang/zig/issues/287
5547pub fn toPosixPath(file_path: []const u8) ![MAX_PATH_BYTES - 1:0]u8 {5526pub 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...@@ -1536,12 +1536,6 @@ pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxno
1536 return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);1536 return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);
1537}1537}
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
1545pub fn epoll_create() usize {1539pub fn epoll_create() usize {
1546 return epoll_create1(0);1540 return epoll_create1(0);
1547}1541}
...@@ -3560,11 +3554,6 @@ pub const CPU_SETSIZE = 128;...@@ -3560,11 +3554,6 @@ pub const CPU_SETSIZE = 128;
3560pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;3554pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
3561pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));3555pub 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
3568pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {3557pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
3569 var sum: cpu_count_t = 0;3558 var sum: cpu_count_t = 0;
3570 for (set) |x| {3559 for (set) |x| {
...@@ -3573,32 +3562,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {...@@ -3573,32 +3562,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
3573 return sum;3562 return sum;
3574}3563}
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
3602pub const MINSIGSTKSZ = switch (native_arch) {3565pub const MINSIGSTKSZ = switch (native_arch) {
3603 .x86, .x86_64, .arm, .mipsel => 2048,3566 .x86, .x86_64, .arm, .mipsel => 2048,
3604 .aarch64 => 5120,3567 .aarch64 => 5120,