Skip to content
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

Closed
wants to merge 17 commits into from

Conversation

komuw
Copy link

@komuw 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)));
Copy link
Author

@komuw komuw Oct 30, 2020

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?

Copy link
Author

@komuw komuw Oct 31, 2020

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?

Copy link
Contributor

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

Copy link
Author

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.

@komuw komuw marked this pull request as ready for review October 30, 2020 21:03
@semarie
Copy link
Contributor

semarie commented Oct 31, 2020 via email

@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label Dec 25, 2020
@andrewrk
Copy link
Member

The code is correct in master branch; those error codes are not reachable, except by programmer error.

@andrewrk andrewrk closed this Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants