Skip to content

runtime: use sched_getaffinity for getproccount on GNU/Linux #3921

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

Closed
ianlancetaylor opened this issue Aug 7, 2012 · 5 comments
Closed

runtime: use sched_getaffinity for getproccount on GNU/Linux #3921

ianlancetaylor opened this issue Aug 7, 2012 · 5 comments

Comments

@ianlancetaylor
Copy link
Member

On GNU/Linux it might be slightly more efficient to use the sched_getaffinity system
call to get the number of virtual processors.  It would be one system call instead of
three or more, and it would not touch the filesystem.  The function, getproccount in
runtime/thread_linux.c, is called at the start of every program.

But note that if the system is actually using CPU affinity, this will cause
runtime.NumCPU to return the number of virtual processors that the process is permitted
to run on, rather than the number of virtual processors on the system.
@davecheney
Copy link
Contributor

Comment 1:

I think this is an excellent idea.
> But note that if the system is actually using CPU affinity, this will cause
runtime.NumCPU to return the number of virtual processors that the process is permitted
to run on, rather than the number of virtual processors on the system.
Having worked in environments where affinity/cpu isolation is used, this is the
behaviour I would want. The opposite, where most of the cpus are isolated from the
general scheduler, yet the process believes it has access to all the CPUs leads to
surprising results.

@rsc
Copy link
Contributor

rsc commented Aug 8, 2012

Comment 2:

SGTM

@minux
Copy link
Member

minux commented Aug 9, 2012

Comment 3:

@iant, have you started woking on this yet?

@ianlancetaylor
Copy link
Member Author

Comment 4:

No, I haven't done anything about this.  I created the issue so that I didn't forget.

@minux
Copy link
Member

minux commented Aug 10, 2012

Comment 5:

This issue was closed by revision 4f308ed.

Status changed to Fixed.

minux added a commit that referenced this issue May 11, 2015
…U() on Linux

««« backport 3532ab6bf5be
runtime: use sched_getaffinity for runtime.NumCPU() on Linux
        Fixes #3921.

R=iant
CC=golang-dev
https://golang.org/cl/6448132

»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants