From: Florian Weimer <fweimer@redhat.com>
To: Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org>
Cc: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Subject: Re: [PATCH] Improve performance of libc locks
Date: Thu, 23 Nov 2023 19:17:24 +0100 [thread overview]
Message-ID: <87h6lcbah7.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <AM5PR0801MB16680E6787BC0553E1847A0B83649@AM5PR0801MB1668.eurprd08.prod.outlook.com> (Wilco Dijkstra via Libc-alpha's message of "Thu, 11 Aug 2022 16:22:56 +0000")
* Wilco Dijkstra via Libc-alpha:
> 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; \
> + })
We already have SINGLE_THREAD_P checks around locking in several places.
This makes the __libc_lock_lock check redudant in those cases. I
believe this was done deliberately because in many cases, we can also to
skip cancellation handling at the same time.
The rand performance issue could be addressed with a similar localized
change. I believe that would be far less controversial.
Thanks,
Florian
next prev parent reply other threads:[~2023-11-23 18:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-11 16:22 Wilco Dijkstra
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 [this message]
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=87h6lcbah7.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=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).