diff options
| -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.35.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.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb index d9cae79ac2..9073e04537 100644 --- a/meta/recipes-core/glibc/glibc_2.35.bb +++ b/meta/recipes-core/glibc/glibc_2.35.bb | |||
| @@ -65,6 +65,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ | |||
| 65 | file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ | 65 | file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ |
| 66 | file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ | 66 | file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ |
| 67 | file://0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch \ | 67 | file://0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch \ |
| 68 | file://0001-stdlib-Add-single-threaded-fast-path-to-rand.patch \ | ||
| 68 | " | 69 | " |
| 69 | S = "${WORKDIR}/git" | 70 | S = "${WORKDIR}/git" |
| 70 | B = "${WORKDIR}/build-${TARGET_SYS}" | 71 | B = "${WORKDIR}/build-${TARGET_SYS}" |
