From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: 'GNU C Library' <libc-alpha@sourceware.org>
Subject: [PATCH] Improve performance of libc locks
Date: Thu, 11 Aug 2022 16:22:56 +0000 [thread overview]
Message-ID: <AM5PR0801MB16680E6787BC0553E1847A0B83649@AM5PR0801MB1668.eurprd08.prod.outlook.com> (raw)
Improve performance of libc locks by adding a fast path for the
single-threaded case.
On Neoverse V1, a loop using rand() improved 3.6 times. Multithreaded
performance is unchanged.
Passes regress on AArch64, OK for commit?
---
diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
index d3a6837fd212f3f5dfd80f46d0e9ce365042ae0c..ccdb11fee6f14069d0b936be93d0f0fa6d8bc30b 100644
--- a/sysdeps/nptl/libc-lockP.h
+++ b/sysdeps/nptl/libc-lockP.h
@@ -108,7 +108,14 @@ _Static_assert (LLL_LOCK_INITIALIZER == 0, "LLL_LOCK_INITIALIZER != 0");
#define __libc_rwlock_fini(NAME) ((void) 0)
/* Lock the named lock variable. */
-#define __libc_lock_lock(NAME) ({ lll_lock (NAME, LLL_PRIVATE); 0; })
+#define __libc_lock_lock(NAME) \
+ ({ \
+ if (SINGLE_THREAD_P) \
+ (NAME) = LLL_LOCK_INITIALIZER_LOCKED; \
+ else \
+ lll_lock (NAME, LLL_PRIVATE); \
+ 0; \
+ })
#define __libc_rwlock_rdlock(NAME) __pthread_rwlock_rdlock (&(NAME))
#define __libc_rwlock_wrlock(NAME) __pthread_rwlock_wrlock (&(NAME))
@@ -116,7 +123,14 @@ _Static_assert (LLL_LOCK_INITIALIZER == 0, "LLL_LOCK_INITIALIZER != 0");
#define __libc_lock_trylock(NAME) lll_trylock (NAME)
/* Unlock the named lock variable. */
-#define __libc_lock_unlock(NAME) lll_unlock (NAME, LLL_PRIVATE)
+#define __libc_lock_unlock(NAME) \
+ ({ \
+ if (SINGLE_THREAD_P) \
+ (NAME) = LLL_LOCK_INITIALIZER; \
+ else \
+ lll_unlock (NAME, LLL_PRIVATE); \
+ 0; \
+ })
#define __libc_rwlock_unlock(NAME) __pthread_rwlock_unlock (&(NAME))
#if IS_IN (rtld)
next reply other threads:[~2022-08-11 16:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-11 16:22 Wilco Dijkstra [this message]
2022-08-15 14:07 ` Carlos O'Donell
2022-08-15 17:35 ` Wilco Dijkstra
2022-08-16 7:26 ` Noah Goldstein
2022-11-15 20:17 ` Cristian Rodríguez
2022-12-09 14:10 ` Wilco Dijkstra
2023-11-23 17:16 ` Cristian Rodríguez
2023-11-23 18:17 ` Florian Weimer
2023-11-24 13:47 ` Wilco Dijkstra
2023-11-24 16:29 ` Carlos O'Donell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM5PR0801MB16680E6787BC0553E1847A0B83649@AM5PR0801MB1668.eurprd08.prod.outlook.com \
--to=wilco.dijkstra@arm.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).