summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaixiao Yan <haixiao.yan.cn@windriver.com>2025-03-31 17:05:17 +0800
committerSteve Sakoman <steve@sakoman.com>2025-05-14 08:33:40 -0700
commit753f400c0bcbf5e34dbd0ddda6873f85eb7c75b9 (patch)
treeee458b8afa49a88f1e9ac6f64b824be9f20ea38e
parent9d264e0817f6fb0069c8bade251930cfe129d931 (diff)
downloadpoky-753f400c0bcbf5e34dbd0ddda6873f85eb7c75b9.tar.gz
glibc: Add single-threaded fast path to rand()
Backport a patch [1] to improve performance of rand() and __random()[2] by adding a single-threaded fast path. [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=be0cfd848d9ad7378800d6302bc11467cf2b514f [2] https://sourceware.org/bugzilla/show_bug.cgi?id=32777 (From OE-Core rev: 09e2d663246d7335a9e33dd1a86dfe4630e4489a) Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit b0ded4df5f2d3bb3319978d1a549c72f5daf238e) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-core/glibc/glibc/0001-stdlib-Add-single-threaded-fast-path-to-rand.patch47
-rw-r--r--meta/recipes-core/glibc/glibc_2.41.bb1
2 files changed, 48 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0001-stdlib-Add-single-threaded-fast-path-to-rand.patch b/meta/recipes-core/glibc/glibc/0001-stdlib-Add-single-threaded-fast-path-to-rand.patch
new file mode 100644
index 0000000000..736fc51f38
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0001-stdlib-Add-single-threaded-fast-path-to-rand.patch
@@ -0,0 +1,47 @@
1From 4f54b0dfc16dbe0df86afccb90e447df5f7f571e Mon Sep 17 00:00:00 2001
2From: Wilco Dijkstra <wilco.dijkstra@arm.com>
3Date: Mon, 18 Mar 2024 15:18:20 +0000
4Subject: [PATCH] stdlib: Add single-threaded fast path to rand()
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Improve performance of rand() and __random() by adding a single-threaded
10fast path. Bench-random-lock shows about 5x speedup on Neoverse V1.
11
12Upstream-Status: Backport [be0cfd848d9ad7378800d6302bc11467cf2b514f]
13
14Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
15Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com>
16---
17 stdlib/random.c | 7 +++++++
18 1 file changed, 7 insertions(+)
19
20diff --git a/stdlib/random.c b/stdlib/random.c
21index 17cc61ba8f55..5d482a857065 100644
22--- a/stdlib/random.c
23+++ b/stdlib/random.c
24@@ -51,6 +51,7 @@
25 SUCH DAMAGE.*/
26
27 #include <libc-lock.h>
28+#include <sys/single_threaded.h>
29 #include <limits.h>
30 #include <stddef.h>
31 #include <stdlib.h>
32@@ -288,6 +289,12 @@ __random (void)
33 {
34 int32_t retval;
35
36+ if (SINGLE_THREAD_P)
37+ {
38+ (void) __random_r (&unsafe_state, &retval);
39+ return retval;
40+ }
41+
42 __libc_lock_lock (lock);
43
44 (void) __random_r (&unsafe_state, &retval);
45--
462.34.1
47
diff --git a/meta/recipes-core/glibc/glibc_2.41.bb b/meta/recipes-core/glibc/glibc_2.41.bb
index 71b89ac9ff..d707e1a677 100644
--- a/meta/recipes-core/glibc/glibc_2.41.bb
+++ b/meta/recipes-core/glibc/glibc_2.41.bb
@@ -53,6 +53,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
53 file://0021-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ 53 file://0021-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \
54 file://0022-Avoid-hardcoded-build-time-paths-in-the-output-binar.patch \ 54 file://0022-Avoid-hardcoded-build-time-paths-in-the-output-binar.patch \
55 file://0023-tests-Skip-2-qemu-tests-that-can-hang-in-oe-selftest.patch \ 55 file://0023-tests-Skip-2-qemu-tests-that-can-hang-in-oe-selftest.patch \
56 file://0001-stdlib-Add-single-threaded-fast-path-to-rand.patch \
56" 57"
57S = "${WORKDIR}/git" 58S = "${WORKDIR}/git"
58B = "${WORKDIR}/build-${TARGET_SYS}" 59B = "${WORKDIR}/build-${TARGET_SYS}"