diff options
author | Haixiao Yan <haixiao.yan.cn@windriver.com> | 2025-04-02 10:22:08 +0800 |
---|---|---|
committer | Steve Sakoman <steve@sakoman.com> | 2025-05-14 09:08:58 -0700 |
commit | fa7bc4c1a8e1e59d57e6deeaf74f7784975ab9b4 (patch) | |
tree | 4602882d3bd734b47ccf943d472b772a06994536 /meta | |
parent | c418c7ec51a5556054d0deb56dce08268da1983f (diff) | |
download | poky-fa7bc4c1a8e1e59d57e6deeaf74f7784975ab9b4.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: 68ee8d16fa5419acba9111d3aca285be92bd93d3)
Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/recipes-core/glibc/glibc/0001-stdlib-Add-single-threaded-fast-path-to-rand.patch | 47 | ||||
-rw-r--r-- | meta/recipes-core/glibc/glibc_2.39.bb | 1 |
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 @@ | |||
1 | From 4f54b0dfc16dbe0df86afccb90e447df5f7f571e Mon Sep 17 00:00:00 2001 | ||
2 | From: Wilco Dijkstra <wilco.dijkstra@arm.com> | ||
3 | Date: Mon, 18 Mar 2024 15:18:20 +0000 | ||
4 | Subject: [PATCH] stdlib: Add single-threaded fast path to rand() | ||
5 | MIME-Version: 1.0 | ||
6 | Content-Type: text/plain; charset=UTF-8 | ||
7 | Content-Transfer-Encoding: 8bit | ||
8 | |||
9 | Improve performance of rand() and __random() by adding a single-threaded | ||
10 | fast path. Bench-random-lock shows about 5x speedup on Neoverse V1. | ||
11 | |||
12 | Upstream-Status: Backport [be0cfd848d9ad7378800d6302bc11467cf2b514f] | ||
13 | |||
14 | Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> | ||
15 | Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com> | ||
16 | --- | ||
17 | stdlib/random.c | 7 +++++++ | ||
18 | 1 file changed, 7 insertions(+) | ||
19 | |||
20 | diff --git a/stdlib/random.c b/stdlib/random.c | ||
21 | index 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 | -- | ||
46 | 2.34.1 | ||
47 | |||
diff --git a/meta/recipes-core/glibc/glibc_2.39.bb b/meta/recipes-core/glibc/glibc_2.39.bb index 8373db2c4f..e4e2a766d7 100644 --- a/meta/recipes-core/glibc/glibc_2.39.bb +++ b/meta/recipes-core/glibc/glibc_2.39.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-qemu-stale-process.patch \ | 55 | file://0023-qemu-stale-process.patch \ |
56 | file://0001-stdlib-Add-single-threaded-fast-path-to-rand.patch \ | ||
56 | " | 57 | " |
57 | S = "${WORKDIR}/git" | 58 | S = "${WORKDIR}/git" |
58 | B = "${WORKDIR}/build-${TARGET_SYS}" | 59 | B = "${WORKDIR}/build-${TARGET_SYS}" |