-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
complete out the os.sched_getaffinity error set #6886
Conversation
komuw
commented
Oct 30, 2020
- complete out the os.sched_getaffinity error set
- add doc string for sched_getaffinity
- add test for os.sched_getaffinity
@@ -601,3 +601,7 @@ test "getrlimit and setrlimit" { | |||
const cpuLimit = try os.getrlimit(.CPU); | |||
try os.setrlimit(.CPU, cpuLimit); | |||
} | |||
|
|||
test "os.sched_getaffinity" { | |||
testing.expectError(error.NoThread, os.sched_getaffinity(std.math.maxInt(i32))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption here is that we will never have as many threads as maxInt(i32)
when running tests.
But there is a good probability that I'm wrong. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows and Osx, this is failing with
error: use of undeclared identifier 'cpu_set_t'
pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
Should I restrict this test to linux only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows and Osx, this is failing with
Welcome to the world of cross-platform non-posix abstractions (and yet another opportunity to plug #6600):
- NetBSD has
pthread_setaffinity_np
/pthread_getaffinity_np
- FreeBSD has
cpuset_getaffinity
/cpuset_setaffinity
- macOS has no direct equivalent,
thread_policy_get
/thread_policy_set
let you get/set the affinity tag for a given thread but that's it - OpenBSD has no such API (cc @semarie)
My assumption here is that we will never have as many threads as maxInt(i32) when running tests.
That's a pretty safe assumption (why are PIDs signed???), spawning that many threads requires an ungodly amount of memory heh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have skipped the test for non-linux OSes. I have also opened #6907 to implement sched_getaffinity
for other OSes. I'll attempt to do that in a follow up PR, if no one else will have done so already.
* OpenBSD has no such API (cc @semarie)
hep. I confirm that it doesn't exist on OpenBSD.
Depending your intent for `os.sched_getaffinity()` interface, such cases could be:
- a `@compileError`, but it means any use of it will break compilation on such platforms
- a nop (returning a constant on `os.sched_getaffinity`, and
silencious ignore value setting on `os.sched_setaffinity`).
the linux man page documents it as "setting the CPU affinity mask can
be used to obtain performance benefits". so I prefer a functional
program but with less performance instead of an unbuildable program.
|
The code is correct in master branch; those error codes are not reachable, except by programmer error. |