diff options
| author | Haixiao Yan <haixiao.yan.cn@windriver.com> | 2025-03-31 17:05:17 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-04-03 11:06:20 +0100 |
| commit | 26336dd47bc9f4cf9e61b79c728446d4e5701794 (patch) | |
| tree | 84a4ba21df8884b6ceb793354f7af0f7a82fc668 | |
| parent | 61bfdcd5ebba45d9656c95bb8c545a9bd5356820 (diff) | |
| download | poky-26336dd47bc9f4cf9e61b79c728446d4e5701794.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: b0ded4df5f2d3bb3319978d1a549c72f5daf238e)
Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -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.41.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.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 | " |
| 57 | S = "${WORKDIR}/git" | 58 | S = "${WORKDIR}/git" |
| 58 | B = "${WORKDIR}/build-${TARGET_SYS}" | 59 | B = "${WORKDIR}/build-${TARGET_SYS}" |
