public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH v4] nptl: Effectively skip CAS in spinlock loop
       [not found]   ` <YelevLkTZU5Kb4Xi@gmail.com>
@ 2022-09-11 20:23     ` Sunil Pandey
  2022-09-29  0:11       ` Noah Goldstein
  0 siblings, 1 reply; 2+ messages in thread
From: Sunil Pandey @ 2022-09-11 20:23 UTC (permalink / raw)
  To: H.J. Lu, Libc-stable Mailing List, Florian Weimer
  Cc: Jangwoong Kim, GNU C Library

On Thu, Jan 20, 2022 at 5:08 AM H.J. Lu via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> On Thu, Jan 20, 2022 at 04:53:27AM -0800, H.J. Lu wrote:
> > On Tue, Dec 14, 2021 at 4:31 AM Jangwoong Kim via Libc-alpha
> > <libc-alpha@sourceware.org> wrote:
> > >
> > > The commit:
> > > "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
> > > SHA1: d672a98a1af106bd68deb15576710cd61363f7a6
> > >
> > > introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop
> > > if atomic load fails. But, "continue" inside of do-while loop
> > > does not skip the evaluation of escape expression, thus CAS
> > > is not skipped.
> > >
> > > Replace do-while with while and skip LLL_MUTEX_TRYLOCK if
> > > LLL_MUTEX_READ_LOCK fails.
> > > ---
> > >  nptl/pthread_mutex_lock.c | 5 +----
> > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > >
> > > diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> > > index 47b88a6b5b..06274c68e4 100644
> > > --- a/nptl/pthread_mutex_lock.c
> > > +++ b/nptl/pthread_mutex_lock.c
> > > @@ -138,7 +138,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
> > >           int cnt = 0;
> > >           int max_cnt = MIN (max_adaptive_count (),
> > >                              mutex->__data.__spins * 2 + 10);
> > > -         do
> > > +         while (LLL_MUTEX_READ_LOCK (mutex) != 0 || LLL_MUTEX_TRYLOCK (mutex) != 0)
> > >             {
> > >               if (cnt++ >= max_cnt)
> > >                 {
> > > @@ -146,10 +146,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
> > >                   break;
> > >                 }
> > >               atomic_spin_nop ();
> > > -             if (LLL_MUTEX_READ_LOCK (mutex) != 0)
> > > -               continue;
> > >             }
> > > -         while (LLL_MUTEX_TRYLOCK (mutex) != 0);
> > >
> > >           mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
> > >         }
> > > --
> > > 2.25.1
> > >
> >
> > LGTM.
> >
> > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> >
> > Thanks.
> >
>
> This is the v4 patch I am checkinng in.
>
> H.J.
> ---
> From: Jangwoong Kim <6812skiii@gmail.com>
> Date: Tue, 14 Dec 2021 21:30:51 +0900
>
> The commit:
> "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
> SHA1: d672a98a1af106bd68deb15576710cd61363f7a6
>
> introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop
> if atomic load fails. But, "continue" inside of do-while loop
> does not skip the evaluation of escape expression, thus CAS
> is not skipped.
>
> Replace do-while with while and skip LLL_MUTEX_TRYLOCK if
> LLL_MUTEX_READ_LOCK fails.
>
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  nptl/pthread_mutex_lock.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> index 31dfc7f1d7..d2e652d151 100644
> --- a/nptl/pthread_mutex_lock.c
> +++ b/nptl/pthread_mutex_lock.c
> @@ -146,10 +146,9 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
>                   break;
>                 }
>               atomic_spin_nop ();
> -             if (LLL_MUTEX_READ_LOCK (mutex) != 0)
> -               continue;
>             }
> -         while (LLL_MUTEX_TRYLOCK (mutex) != 0);
> +         while (LLL_MUTEX_READ_LOCK (mutex) != 0
> +                || LLL_MUTEX_TRYLOCK (mutex) != 0);
>
>           mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
>         }
> --
> 2.34.1
>

I would like to backport this patch to release branch 2.33 and 2.34

Any comments/suggestions or objections on this.

commit 6b8dbbd03ac88f169b65b5c7d7278576a11d2e44
Author: Jangwoong Kim <6812skiii@gmail.com>
Date:   Tue Dec 14 21:30:51 2021 +0900

    nptl: Effectively skip CAS in spinlock loop

    The commit:
    "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
    SHA1: d672a98a1af106bd68deb15576710cd61363f7a6

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v4] nptl: Effectively skip CAS in spinlock loop
  2022-09-11 20:23     ` [PATCH v4] nptl: Effectively skip CAS in spinlock loop Sunil Pandey
@ 2022-09-29  0:11       ` Noah Goldstein
  0 siblings, 0 replies; 2+ messages in thread
From: Noah Goldstein @ 2022-09-29  0:11 UTC (permalink / raw)
  To: Sunil Pandey
  Cc: H.J. Lu, Libc-stable Mailing List, Florian Weimer, Jangwoong Kim,
	GNU C Library

On Sun, Sep 11, 2022 at 4:24 PM Sunil Pandey via Libc-stable
<libc-stable@sourceware.org> wrote:
>
> On Thu, Jan 20, 2022 at 5:08 AM H.J. Lu via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >
> > On Thu, Jan 20, 2022 at 04:53:27AM -0800, H.J. Lu wrote:
> > > On Tue, Dec 14, 2021 at 4:31 AM Jangwoong Kim via Libc-alpha
> > > <libc-alpha@sourceware.org> wrote:
> > > >
> > > > The commit:
> > > > "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
> > > > SHA1: d672a98a1af106bd68deb15576710cd61363f7a6
> > > >
> > > > introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop
> > > > if atomic load fails. But, "continue" inside of do-while loop
> > > > does not skip the evaluation of escape expression, thus CAS
> > > > is not skipped.
> > > >
> > > > Replace do-while with while and skip LLL_MUTEX_TRYLOCK if
> > > > LLL_MUTEX_READ_LOCK fails.
> > > > ---
> > > >  nptl/pthread_mutex_lock.c | 5 +----
> > > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > >
> > > > diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> > > > index 47b88a6b5b..06274c68e4 100644
> > > > --- a/nptl/pthread_mutex_lock.c
> > > > +++ b/nptl/pthread_mutex_lock.c
> > > > @@ -138,7 +138,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
> > > >           int cnt = 0;
> > > >           int max_cnt = MIN (max_adaptive_count (),
> > > >                              mutex->__data.__spins * 2 + 10);
> > > > -         do
> > > > +         while (LLL_MUTEX_READ_LOCK (mutex) != 0 || LLL_MUTEX_TRYLOCK (mutex) != 0)
> > > >             {
> > > >               if (cnt++ >= max_cnt)
> > > >                 {
> > > > @@ -146,10 +146,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
> > > >                   break;
> > > >                 }
> > > >               atomic_spin_nop ();
> > > > -             if (LLL_MUTEX_READ_LOCK (mutex) != 0)
> > > > -               continue;
> > > >             }
> > > > -         while (LLL_MUTEX_TRYLOCK (mutex) != 0);
> > > >
> > > >           mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
> > > >         }
> > > > --
> > > > 2.25.1
> > > >
> > >
> > > LGTM.
> > >
> > > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> > >
> > > Thanks.
> > >
> >
> > This is the v4 patch I am checkinng in.
> >
> > H.J.
> > ---
> > From: Jangwoong Kim <6812skiii@gmail.com>
> > Date: Tue, 14 Dec 2021 21:30:51 +0900
> >
> > The commit:
> > "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
> > SHA1: d672a98a1af106bd68deb15576710cd61363f7a6
> >
> > introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop
> > if atomic load fails. But, "continue" inside of do-while loop
> > does not skip the evaluation of escape expression, thus CAS
> > is not skipped.
> >
> > Replace do-while with while and skip LLL_MUTEX_TRYLOCK if
> > LLL_MUTEX_READ_LOCK fails.
> >
> > Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> > ---
> >  nptl/pthread_mutex_lock.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
> > index 31dfc7f1d7..d2e652d151 100644
> > --- a/nptl/pthread_mutex_lock.c
> > +++ b/nptl/pthread_mutex_lock.c
> > @@ -146,10 +146,9 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex)
> >                   break;
> >                 }
> >               atomic_spin_nop ();
> > -             if (LLL_MUTEX_READ_LOCK (mutex) != 0)
> > -               continue;
> >             }
> > -         while (LLL_MUTEX_TRYLOCK (mutex) != 0);
> > +         while (LLL_MUTEX_READ_LOCK (mutex) != 0
> > +                || LLL_MUTEX_TRYLOCK (mutex) != 0);
> >
> >           mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
> >         }
> > --
> > 2.34.1
> >
>
> I would like to backport this patch to release branch 2.33 and 2.34

Fine by me.
>
> Any comments/suggestions or objections on this.
>
> commit 6b8dbbd03ac88f169b65b5c7d7278576a11d2e44
> Author: Jangwoong Kim <6812skiii@gmail.com>
> Date:   Tue Dec 14 21:30:51 2021 +0900
>
>     nptl: Effectively skip CAS in spinlock loop
>
>     The commit:
>     "Add LLL_MUTEX_READ_LOCK [BZ #28537]"
>     SHA1: d672a98a1af106bd68deb15576710cd61363f7a6

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-29  0:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211214123051.800-1-6812skiii@gmail.com>
     [not found] ` <CAMe9rOpG1M8t3+dkJS5tYt-qzdW+rMmvQBW5rdExUOSCpFUbJg@mail.gmail.com>
     [not found]   ` <YelevLkTZU5Kb4Xi@gmail.com>
2022-09-11 20:23     ` [PATCH v4] nptl: Effectively skip CAS in spinlock loop Sunil Pandey
2022-09-29  0:11       ` Noah Goldstein

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).