[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJF2gTTWO-HxQNME=YN4pvEeFD5fT0dUx9pQhLujMk1V008U5A@mail.gmail.com>
Date: Fri, 1 Jul 2022 23:18:25 +0800
From: Guo Ren <guoren@...nel.org>
To: David Laight <David.Laight@...lab.com>
Cc: "palmer@...osinc.com" <palmer@...osinc.com>,
"arnd@...db.de" <arnd@...db.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"will@...nel.org" <will@...nel.org>,
"longman@...hat.com" <longman@...hat.com>,
"boqun.feng@...il.com" <boqun.feng@...il.com>,
"linux-riscv@...ts.infradead.org" <linux-riscv@...ts.infradead.org>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Guo Ren <guoren@...ux.alibaba.com>,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read
On Wed, Jun 29, 2022 at 4:27 PM David Laight <David.Laight@...lab.com> wrote:
>
> From: guoren@...nel.org
> > Sent: 28 June 2022 09:17
> >
> > From: Guo Ren <guoren@...ux.alibaba.com>
> >
> > Remove unnecessary atomic_read in arch_spin_value_unlocked(lock),
> > because the value has been in lock. This patch could prevent
> > arch_spin_value_unlocked contend spin_lock data again.
>
> I'm confused (as usual).
> Isn't atomic_read() pretty much free?
When a cache line is shared with multi-harts, not as free as you think.
Preventing touching contended data is the basic principle.
atomic_read in alpha is heavy, It could be a potential user of ticket-lock.
>
> ..
> > diff --git a/include/asm-generic/spinlock.h b/include/asm-generic/spinlock.h
> > index fdfebcb050f4..f1e4fa100f5a 100644
> > --- a/include/asm-generic/spinlock.h
> > +++ b/include/asm-generic/spinlock.h
> > @@ -84,7 +84,9 @@ static __always_inline int arch_spin_is_contended(arch_spinlock_t *lock)
> >
> > static __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock)
> > {
> > - return !arch_spin_is_locked(&lock);
> > + u32 val = lock.counter;
> > +
> > + return ((val >> 16) == (val & 0xffff));
>
> That almost certainly needs a READ_ONCE().
>
> The result is also inherently stale.
> So the uses must be pretty limited.
The previous read_once could get 64bit, use the API to check the 32bit
atomic data part.
>
> David
>
> > }
> >
> > #include <asm/qrwlock.h>
> > --
> > 2.36.1
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
Powered by blists - more mailing lists