[Issue 19513] New: Use sched_getaffinity(2) to get the number of CPU cores if available
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 25 10:56:33 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19513
Issue ID: 19513
Summary: Use sched_getaffinity(2) to get the number of CPU
cores if available
Product: D
Version: D2
Hardware: All
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: kubo39 at gmail.com
Currently std.parallelism.totalCPUs is implemented by
sysconf(_SC_NPROCESSORS_ONLN).
However, on GNU/Linux, usable number of processoes may be restricted if a
process runs in containers.
In case it's better to use sched_getaffinity(2).
How to implement:
1. std.parallelism.totalCPUs uses sched_getaffinity(2) internally.
2. Add new API (and considering function name).
- std.parallelism.sched_getaffinity(pid, mask)? (Like Python)
- std.parallelism.nprocessors? (Like Ruby)
- or berrer name
Libraries exposing sched_getaffinity:
- Python >= 3.3 provides os.get_affinity(pid, mask) function.
- Ruby >= 2.2 provides Etc.nprocessors function.
- GNU coreutils provides nproc(1) command.
- Rust's num_cpus crate provides num_cpus::get() function.
Links:
- https://github.com/golang/go/issues/3921
- https://docs.python.org/3/library/os.html#os.sched_getaffinity
- https://bugs.ruby-lang.org/issues/10267
- http://man7.org/linux/man-pages/man1/nproc.1.html
--
More information about the Digitalmars-d-bugs
mailing list