Uh oh!
There was an error while loading. Please reload this page.
Reduce number of syscalls in rand - #53725
Conversation
In case that it is statically known that the OS doesn't support
`getrandom` (non-Linux) or becomes clear at runtime that `getrandom`
isn't available (`ENOSYS`), the opened fd ("/dev/urandom") isn't closed
after the function, so that future calls can reuse it. This saves
repeated `open`/`close` system calls at the cost of one permanently open
fd.
Additionally, this skips the initial zero-length `getrandom` call and
directly hands the user buffer to the operating system, saving one
`getrandom` syscall.rust-highfive
commented
Aug 26, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
Mark-Simulacrum
commented
Aug 26, 2018
tbu-
commented
Aug 27, 2018
Program: Without this PR: With this PR: The initial |
alexcrichton
commented
Aug 27, 2018
Thanks for the PR! The changes to |
tbu-
commented
Aug 29, 2018
Done. |
alexcrichton
commented
Aug 29, 2018
@bors: r+ |
bors
commented
Aug 29, 2018
📌 Commit 6d47737 has been approved by |
…richton Reduce number of syscalls in `rand` This skips the initial zero-length `getrandom` call and directly hands the user buffer to the operating system, saving one `getrandom` syscall.
emilyalbini
commented
Aug 29, 2018
@bors r- |
6d47737 to
d6d280bCompare| if err == libc::EINTR { | ||
| continue; | ||
| } else if err == libc::ENOSYS { | ||
| GETRANDOM_UNAVAILABLE.store(true, Ordering::Relaxed); |
There was a problem hiding this comment.
Would this not loop infinitely in the ENOSYS case?
alexcrichton
commented
Aug 31, 2018
alexcrichton
commented
Sep 2, 2018
@bors: r+ |
bors
commented
Sep 2, 2018
📌 Commit b95c491 has been approved by |
bors
commented
Sep 2, 2018
Reduce number of syscalls in `rand` This skips the initial zero-length `getrandom` call and directly hands the user buffer to the operating system, saving one `getrandom` syscall.
bors
commented
Sep 2, 2018
☀️ Test successful - status-appveyor, status-travis |
This skips the initial zero-length
getrandomcall anddirectly hands the user buffer to the operating system, saving one
getrandomsyscall.