!629 Optimizing __random for single-threaded scenarios

From: @jiangyingxin1 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
This commit is contained in:
openeuler-ci-bot 2023-07-14 06:13:38 +00:00 committed by Gitee
commit f192c942cd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,44 @@
From f54e1ddea12343991b402abf28be2b94ffbac2c5 Mon Sep 17 00:00:00 2001
From: Tian Tao <tiantao6@hisilicon.com>
Date: Tue, 11 Jul 2023 08:42:56 +0800
Subject: [PATCH] Optimizing __random for single-threaded scenarios
The __random function does not need to be locked by __libc_lock_lock and
unlocked by __libc_lock_unlock in a single-threaded scenario, so we can
remove these locks in a single-threaded scenario to improve performance.
Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
stdlib/random.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/stdlib/random.c b/stdlib/random.c
index 62f22fac8d..9035df8d18 100644
--- a/stdlib/random.c
+++ b/stdlib/random.c
@@ -288,11 +288,19 @@ __random (void)
{
int32_t retval;
- __libc_lock_lock (lock);
+ if (__libc_single_threaded) {
- (void) __random_r (&unsafe_state, &retval);
+ (void) __random_r (&unsafe_state, &retval);
- __libc_lock_unlock (lock);
+ } else {
+
+ __libc_lock_lock (lock);
+
+ (void) __random_r (&unsafe_state, &retval);
+
+ __libc_lock_unlock (lock);
+
+ }
return retval;
}
--
2.33.0

View File

@ -65,7 +65,7 @@
############################################################################## ##############################################################################
Name: glibc Name: glibc
Version: 2.36 Version: 2.36
Release: 17 Release: 18
Summary: The GNU libc libraries Summary: The GNU libc libraries
License: %{all_license} License: %{all_license}
URL: http://www.gnu.org/software/glibc/ URL: http://www.gnu.org/software/glibc/
@ -114,6 +114,7 @@ Patch9013: x86-use-total-l3cache-for-non_temporal_threshold.patch
Patch9014: strcmp-delete-align-for-loop_aligned.patch Patch9014: strcmp-delete-align-for-loop_aligned.patch
Patch9015: add-pthread_cond_clockwait-GLIBC_2_28.patch Patch9015: add-pthread_cond_clockwait-GLIBC_2_28.patch
Patch9016: add-GB18030-2022-charmap-BZ-30243.patch Patch9016: add-GB18030-2022-charmap-BZ-30243.patch
Patch9017: 0001-Optimizing-__random-for-single-threaded-scenarios.patch
Provides: ldconfig rtld(GNU_HASH) bundled(gnulib) Provides: ldconfig rtld(GNU_HASH) bundled(gnulib)
@ -1273,6 +1274,9 @@ fi
%endif %endif
%changelog %changelog
* Tue Jul 11 2023 jiangyingxin<jiangyingxin1@huawei.com> - 2.36-18
- Optimizing __random for single-threaded scenarios
* Tue Jul 11 2023 lijianglin<lijianglin2@huawei.com> - 2.36-17 * Tue Jul 11 2023 lijianglin<lijianglin2@huawei.com> - 2.36-17
- add the test of the entire GB18030 charmap - add the test of the entire GB18030 charmap