Skip to content

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

@ianlancetaylor

Description

@ianlancetaylor
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions