From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Darren Hart <darren@dvhart.com>, Ingo Molnar <mingo@kernel.org>,
Michael Kerrisk <mtk.manpages@googlemail.com>,
Davidlohr Bueso <dave@stgolabs.net>, Chris Mason <clm@fb.com>,
"Carlos O'Donell" <carlos@redhat.com>,
Torvald Riegel <triegel@redhat.com>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [RFC patch 7/7] [PATCH] glibc: nptl: Add support for attached pthread_mutexes
Date: Sat, 2 Apr 2016 18:30:59 +0200 [thread overview]
Message-ID: <20160402163059.GS3448@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20160402110036.173191836@linutronix.de>
On Sat, Apr 02, 2016 at 11:09:20AM -0000, Thomas Gleixner wrote:
> pthread_mutexes on Linux are based on the futex mechanism. The standard futex
> mechanism in the Linux kernel uses a global hash to store transient
> state. Collisions on that hash can lead to performance degradation and on
> real-time enabled kernels even to priority inversions.
>
> To guarantee futexes without collisions on the global kernel hash, the kernel
> provides a mechanism to attach to a futex. This creates futex private state
> which avoids hash collisions and on NUMA systems also cross node memory
> access.
>
> To utilize this mechanism each thread has to attach to the futex before any
> other operations on that futex which involve kernel interaction.
>
> At pthread_mutex_init() the pthread_mutex attribute needs to be initialized
> for attached mode via:
>
> pthread_mutexattr_setattached_np(&attr, 1);
>
> All threads which are using the mutex - including the one which called
> pthread_mutex_init() - must invoke
>
> pthread_mutex_attach_np(&mutex);
>
> before any other pthread_mutex related operations.
>
> Example:
> pthread_mutexattr_t attr;
> pthread_mutex_t lock;
>
> pthread_mutexattr_init(&attr);
> pthread_mutexattr_setattached_np(&attr, 1);
> pthread_mutex_init(&lock, &attr);
>
> pthread_mutex_attach_np(&lock);
>
> pthread_mutex_lock(&lock);
>
> In ptrace this should look like this:
>
> futex(<addr>, 0x280 /* FUTEX_??? */, 1, NULL <unfinished ...>
>
> 0x280: FUTEX_ATTACHED | FUTEX_PRIVATE | FUTEX_WAIT
>
> To undo the attachment each involved thread needs to call
>
> pthread_mutex_detach_np(&mutex);
>
> When the last user detaches the kernel state is destroyed.
So I was fully expecting pthread_mutex_{at,de}tach_np() to not exist and
be internal to pthread_mutex_{init,destroy}().
Is there a reason this is not so?
next prev parent reply other threads:[~2016-04-02 16:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-02 11:09 [RFC patch 0/7] futex: Add support for attached futexes Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 1/7] futex: Provide helpers for hash bucket add/remove Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 2/7] futex: Add some more function commentry Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 3/7] futex: Make key init a helper function Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 4/7] futex: Add support for attached futexes Thomas Gleixner
2016-04-02 16:26 ` Peter Zijlstra
2016-04-02 18:01 ` Thomas Gleixner
2016-04-02 16:29 ` Peter Zijlstra
2016-04-03 9:59 ` Thomas Gleixner
2016-04-02 18:19 ` Andy Lutomirski
2016-04-03 9:57 ` Thomas Gleixner
2016-04-03 13:18 ` Andy Lutomirski
2016-04-03 15:56 ` Thomas Gleixner
2016-04-03 16:11 ` Andy Lutomirski
2016-04-02 23:48 ` Rasmus Villemoes
2016-04-03 10:05 ` Thomas Gleixner
2016-04-03 11:16 ` Ingo Molnar
2016-04-03 11:30 ` Linus Torvalds
2016-04-05 7:44 ` Torvald Riegel
2016-04-05 15:58 ` Carlos O'Donell
2016-04-02 11:09 ` [RFC patch 5/7] perf/bench/futex-hash: Support " Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 7/7] [PATCH] glibc: nptl: Add support for attached pthread_mutexes Thomas Gleixner
2016-04-02 16:30 ` Peter Zijlstra [this message]
2016-04-02 16:32 ` Peter Zijlstra
2016-04-03 10:08 ` Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 6/7] futex.2: Document attached mode Thomas Gleixner
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=20160402163059.GS3448@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=carlos@redhat.com \
--cc=clm@fb.com \
--cc=darren@dvhart.com \
--cc=dave@stgolabs.net \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mtk.manpages@googlemail.com \
--cc=tglx@linutronix.de \
--cc=triegel@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.