Message ID | 3d358d5a-66eb-cf97-ad98-16061a838f1a@redhat.com |
---|---|
State | Superseded |
Headers |
Received: (qmail 71839 invoked by alias); 13 Feb 2017 13:29:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 71828 invoked by uid 89); 13 Feb 2017 13:29:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=948, rightly, states X-HELO: mail-qk0-f181.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:organization:message-id:date :user-agent:mime-version:content-transfer-encoding; bh=VLAeqjMyWT5XPocinOCKVNTOX0pNg5AqGwhc5nMyEvM=; b=RGE60/oFeOUC/peGNLe+MYvAxS5esR0mZGCSzA3or7AlU6peB4CFLNQBvRzevjj4SN WERHHD7YExezV0Jcpc5VvKRd2aD0NwDgEcEHDMXNrEnnf1fMcEVoXFFRweQTHm9WFbEo kAQl+Z1vVCSkSSM/VPmXqlkn2FUAfqRIQpJAq/FK4RZqjN0eXRXO/1UsX3VVA6EG5KOQ kl9ouPg0h++SsNxwpewWifprDyQoUv6hY5NYoz1EjybI3psoitWH3rl03Llf+WGycHSt FlMi2QQS/r1mbPUYMpcUid2iFQLnM1L+hLz6/GpoLx7WlKw529A7fDTCAilVXsTxX+qw iagg== X-Gm-Message-State: AMke39lQPHy0Ek3O6I9KWwNYF8/qEVTVW/BwMXTXDKDwrDF6JE3fB9wVi5yw6CTqpKH+zLAp X-Received: by 10.55.11.130 with SMTP id 124mr20672405qkl.27.1486992584109; Mon, 13 Feb 2017 05:29:44 -0800 (PST) To: GNU C Library <libc-alpha@sourceware.org>, Florian Weimer <fweimer@redhat.com> From: Carlos O'Donell <carlos@redhat.com> Subject: [PATCH] Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock. Message-ID: <3d358d5a-66eb-cf97-ad98-16061a838f1a@redhat.com> Date: Mon, 13 Feb 2017 08:29:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit |
Commit Message
Carlos O'Donell
Feb. 13, 2017, 1:29 p.m. UTC
Florian Weimer rightly pointed out to me that we use PD->lock in two distinct ways, at startup in a barrier-like fashion, and later in a mutex-like fashion. This should be clarified in the concurrency notes because it implies two different algorithms are at play using the same concurrency structure. Also note that a normal POSIX lock would not be valid to use in this case because it is not valid for another thread to unlock it (the barrier-like use-case at startup). OK to commit? 2017-02-13 Carlos O'Donell <carlos@redhat.com> [BZ #20116] * nptl/pthrad_create.c: Expand comments to describe barrier-like and mutex-like uses of PD->lock. ---
Comments
On 02/13/2017 02:29 PM, Carlos O'Donell wrote: > + It is important to point out that PD->lock is being used as a POSIX > + barrier and a POSIX mutex. The lock is taken in the parent to force > + the child to wait, and then the child releases the lock, in effect a > + barrier. However, this barrier-like effect is used only for > + synchronizing the parent and child. After startup the lock is used > + like a mutex to create a critical region during which a single owner > + modifies the thread parameters. I had missed that the lock was reused for the scheduler parameter. But the current code still does not make sense to me. Why do we need to keep a copy of the scheduler parameters at all? Is this just a cache to improve performance, similar to what we used to do for the PID? Thanks, Florian
On 02/13/2017 07:49 PM, Florian Weimer wrote: > On 02/13/2017 02:29 PM, Carlos O'Donell wrote: >> + It is important to point out that PD->lock is being used as a POSIX >> + barrier and a POSIX mutex. The lock is taken in the parent to force >> + the child to wait, and then the child releases the lock, in effect a >> + barrier. However, this barrier-like effect is used only for >> + synchronizing the parent and child. After startup the lock is used >> + like a mutex to create a critical region during which a single owner >> + modifies the thread parameters. > > I had missed that the lock was reused for the scheduler parameter. > > But the current code still does not make sense to me. Why do we need to > keep a copy of the scheduler parameters at all? Is this just a cache to > improve performance, similar to what we used to do for the PID? The cache is used in the implementation of PTHREAD_PRIO_PROTECT mutexes. There are data races: https://sourceware.org/bugzilla/show_bug.cgi?id=21160 I expect that the use of ->lock to protect these members will go away eventually. Thanks, Florian
On 02/14/2017 06:32 AM, Florian Weimer wrote: > On 02/13/2017 07:49 PM, Florian Weimer wrote: >> On 02/13/2017 02:29 PM, Carlos O'Donell wrote: >>> + It is important to point out that PD->lock is being used as a POSIX >>> + barrier and a POSIX mutex. The lock is taken in the parent to force >>> + the child to wait, and then the child releases the lock, in effect a >>> + barrier. However, this barrier-like effect is used only for >>> + synchronizing the parent and child. After startup the lock is used >>> + like a mutex to create a critical region during which a single owner >>> + modifies the thread parameters. >> >> I had missed that the lock was reused for the scheduler parameter. >> >> But the current code still does not make sense to me. Why do we need to >> keep a copy of the scheduler parameters at all? Is this just a cache to >> improve performance, similar to what we used to do for the PID? > > The cache is used in the implementation of PTHREAD_PRIO_PROTECT mutexes. There are data races: > > https://sourceware.org/bugzilla/show_bug.cgi?id=21160 > > I expect that the use of ->lock to protect these members will go away eventually. Yes, it's used in tpp. Given your current understand is the above additional text sufficient to clarify the situation?
On 03/14/2017 02:07 AM, Carlos O'Donell wrote: > On 02/14/2017 06:32 AM, Florian Weimer wrote: >> On 02/13/2017 07:49 PM, Florian Weimer wrote: >>> On 02/13/2017 02:29 PM, Carlos O'Donell wrote: >>>> + It is important to point out that PD->lock is being used as a POSIX >>>> + barrier and a POSIX mutex. The lock is taken in the parent to force >>>> + the child to wait, and then the child releases the lock, in effect a >>>> + barrier. However, this barrier-like effect is used only for >>>> + synchronizing the parent and child. After startup the lock is used >>>> + like a mutex to create a critical region during which a single owner >>>> + modifies the thread parameters. >>> >>> I had missed that the lock was reused for the scheduler parameter. >>> >>> But the current code still does not make sense to me. Why do we need to >>> keep a copy of the scheduler parameters at all? Is this just a cache to >>> improve performance, similar to what we used to do for the PID? >> >> The cache is used in the implementation of PTHREAD_PRIO_PROTECT mutexes. There are data races: >> >> https://sourceware.org/bugzilla/show_bug.cgi?id=21160 >> >> I expect that the use of ->lock to protect these members will go away eventually. > > Yes, it's used in tpp. > > Given your current understand is the above additional text sufficient > to clarify the situation? Yes, I'm mostly fine with it. I wouldn't call it a “POSIX barrier” and “POSIX mutex” though, it clearly is not. Maybe use “as a barrier (acquired and released by different threads and as a mutex (acquired and released by the same thread, providing mutual exclusion)”. Thanks, Florian
On Tue, 2017-03-14 at 07:58 +0100, Florian Weimer wrote: > On 03/14/2017 02:07 AM, Carlos O'Donell wrote: > > On 02/14/2017 06:32 AM, Florian Weimer wrote: > >> On 02/13/2017 07:49 PM, Florian Weimer wrote: > >>> On 02/13/2017 02:29 PM, Carlos O'Donell wrote: > >>>> + It is important to point out that PD->lock is being used as a POSIX > >>>> + barrier and a POSIX mutex. ... is being used both similar to a one-shot semaphore and, subsequently, as a mutex. > The lock is taken in the parent to force > >>>> + the child to wait, and then the child releases the lock, in effect a > >>>> + barrier. However, this barrier-like effect is used only for s/, in effect a barrier// s/barrier-like effect is used/semaphore-like use is employed/ > >>>> + synchronizing the parent and child. After startup the lock is used > >>>> + like a mutex to create a critical region during which a single owner critical section > >>>> + modifies the thread parameters. > >>> > >>> I had missed that the lock was reused for the scheduler parameter. > >>> > >>> But the current code still does not make sense to me. Why do we need to > >>> keep a copy of the scheduler parameters at all? Is this just a cache to > >>> improve performance, similar to what we used to do for the PID? > >> > >> The cache is used in the implementation of PTHREAD_PRIO_PROTECT mutexes. There are data races: > >> > >> https://sourceware.org/bugzilla/show_bug.cgi?id=21160 > >> > >> I expect that the use of ->lock to protect these members will go away eventually. > > > > Yes, it's used in tpp. > > > > Given your current understand is the above additional text sufficient > > to clarify the situation? > > Yes, I'm mostly fine with it. I wouldn't call it a “POSIX barrier” and > “POSIX mutex” though, it clearly is not. > > Maybe use “as a barrier (acquired and released by different threads and > as a mutex (acquired and released by the same thread, providing mutual > exclusion)”. It's not a barrier actually, but closer to a semaphore (the parent does not wait for the child to arrive, but continues immediately after posting...).
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 2ef2bcb..b522638 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -94,8 +94,17 @@ unsigned int __nptl_nthreads = 1; exactly which of the four ownership states we are in and therefore what actions can be taken. For example after (2) we cannot read or write from PD anymore since the thread may no longer exist and the - memory may be unmapped. The most complicated cases happen during - thread startup: + memory may be unmapped. + + It is important to point out that PD->lock is being used as a POSIX + barrier and a POSIX mutex. The lock is taken in the parent to force + the child to wait, and then the child releases the lock, in effect a + barrier. However, this barrier-like effect is used only for + synchronizing the parent and child. After startup the lock is used + like a mutex to create a critical region during which a single owner + modifies the thread parameters. + + The most complicated cases happen during thread startup: (a) If the created thread is in a detached (PTHREAD_CREATE_DETACHED), or joinable (default PTHREAD_CREATE_JOINABLE) state and