diff options
author | Wilco Dijkstra <wilco.dijkstra@arm.com> | 2024-03-18 15:18:20 +0000 |
---|---|---|
committer | Wilco Dijkstra <wilco.dijkstra@arm.com> | 2025-02-24 14:13:43 +0000 |
commit | be0cfd848d9ad7378800d6302bc11467cf2b514f (patch) | |
tree | b4731831ffe54bf4dababa1f7071c8a3f43e5d1f /stdlib | |
parent | 4734d0f8adde573aeafe79ad0c71807833db1cae (diff) | |
download | glibc-be0cfd848d9ad7378800d6302bc11467cf2b514f.zip glibc-be0cfd848d9ad7378800d6302bc11467cf2b514f.tar.gz glibc-be0cfd848d9ad7378800d6302bc11467cf2b514f.tar.bz2 |
stdlib: Add single-threaded fast path to rand()
Improve performance of rand() and __random() by adding a single-threaded
fast path. Bench-random-lock shows about 5x speedup on Neoverse V1.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/random.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/stdlib/random.c b/stdlib/random.c index 17cc61b..5d482a8 100644 --- a/stdlib/random.c +++ b/stdlib/random.c @@ -51,6 +51,7 @@ SUCH DAMAGE.*/ #include <libc-lock.h> +#include <sys/single_threaded.h> #include <limits.h> #include <stddef.h> #include <stdlib.h> @@ -288,6 +289,12 @@ __random (void) { int32_t retval; + if (SINGLE_THREAD_P) + { + (void) __random_r (&unsafe_state, &retval); + return retval; + } + __libc_lock_lock (lock); (void) __random_r (&unsafe_state, &retval); |