From: Guo Ren <guoren@kernel.org> To: Waiman Long <longman@redhat.com> Cc: Palmer Dabbelt <palmer@rivosinc.com>, Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Boqun Feng <boqun.feng@gmail.com>, linux-riscv <linux-riscv@lists.infradead.org>, linux-arch <linux-arch@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Guo Ren <guoren@linux.alibaba.com>, Peter Zijlstra <peterz@infradead.org> Subject: Re: [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read Date: Wed, 29 Jun 2022 10:12:19 +0800 [thread overview] Message-ID: <CAJF2gTRBoAZzjWGJ0zAxv0eqBB-G=V3QHmp6+jXyznmuY6LhCQ@mail.gmail.com> (raw) In-Reply-To: <218522c9-97b9-7659-ce31-2dbc4b0c6a60@redhat.com> On Wed, Jun 29, 2022 at 2:06 AM Waiman Long <longman@redhat.com> wrote: > > On 6/28/22 04:17, guoren@kernel.org wrote: > > From: Guo Ren <guoren@linux.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. > > > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > > Signed-off-by: Guo Ren <guoren@kernel.org> > > Cc: Peter Zijlstra (Intel) <peterz@infradead.org> > > Cc: Arnd Bergmann <arnd@arndb.de> > > Cc: Palmer Dabbelt <palmer@rivosinc.com> > > --- > > include/asm-generic/spinlock.h | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > 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)); > > } > > > > #include <asm/qrwlock.h> > > lockref.c is the only current user of arch_spin_value_unlocked(). This > change is probably OK with this particular use case. Do you have any > performance data about the improvement due to this change? I don't have performance data and I just check the asm code, previous version has an additional unnecessary atomic_read. About this point, we've talked before, but I & palmer missed that point when we pick peter's patch again. https://lore.kernel.org/linux-riscv/YHbmXXvuG442ZDfN@hirez.programming.kicks-ass.net/ ---- > > +static __always_inline int ticket_value_unlocked(arch_spinlock_t lock) > > +{ > > + return !ticket_is_locked(&lock); > Are you sure to let ticket_is_locked->atomic_read(lock) again, the > lock has contained all information? > > return lock.tickets.owner == lock.tickets.next; Yeah, I wrote then the wrong way around. Couldn't be bothered to go back when I figured it out. --- It's just a small typo. > > You may have to document that we have to revisit that if another use > case shows up. > > Cheers, > Longman > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
WARNING: multiple messages have this Message-ID (diff)
From: Guo Ren <guoren@kernel.org> To: Waiman Long <longman@redhat.com> Cc: Palmer Dabbelt <palmer@rivosinc.com>, Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Boqun Feng <boqun.feng@gmail.com>, linux-riscv <linux-riscv@lists.infradead.org>, linux-arch <linux-arch@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Guo Ren <guoren@linux.alibaba.com>, Peter Zijlstra <peterz@infradead.org> Subject: Re: [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read Date: Wed, 29 Jun 2022 10:12:19 +0800 [thread overview] Message-ID: <CAJF2gTRBoAZzjWGJ0zAxv0eqBB-G=V3QHmp6+jXyznmuY6LhCQ@mail.gmail.com> (raw) In-Reply-To: <218522c9-97b9-7659-ce31-2dbc4b0c6a60@redhat.com> On Wed, Jun 29, 2022 at 2:06 AM Waiman Long <longman@redhat.com> wrote: > > On 6/28/22 04:17, guoren@kernel.org wrote: > > From: Guo Ren <guoren@linux.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. > > > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > > Signed-off-by: Guo Ren <guoren@kernel.org> > > Cc: Peter Zijlstra (Intel) <peterz@infradead.org> > > Cc: Arnd Bergmann <arnd@arndb.de> > > Cc: Palmer Dabbelt <palmer@rivosinc.com> > > --- > > include/asm-generic/spinlock.h | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > 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)); > > } > > > > #include <asm/qrwlock.h> > > lockref.c is the only current user of arch_spin_value_unlocked(). This > change is probably OK with this particular use case. Do you have any > performance data about the improvement due to this change? I don't have performance data and I just check the asm code, previous version has an additional unnecessary atomic_read. About this point, we've talked before, but I & palmer missed that point when we pick peter's patch again. https://lore.kernel.org/linux-riscv/YHbmXXvuG442ZDfN@hirez.programming.kicks-ass.net/ ---- > > +static __always_inline int ticket_value_unlocked(arch_spinlock_t lock) > > +{ > > + return !ticket_is_locked(&lock); > Are you sure to let ticket_is_locked->atomic_read(lock) again, the > lock has contained all information? > > return lock.tickets.owner == lock.tickets.next; Yeah, I wrote then the wrong way around. Couldn't be bothered to go back when I figured it out. --- It's just a small typo. > > You may have to document that we have to revisit that if another use > case shows up. > > Cheers, > Longman > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/ _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-06-29 2:12 UTC|newest] Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-06-28 8:17 [PATCH V7 0/5] riscv: Add qspinlock support with combo style guoren 2022-06-28 8:17 ` guoren 2022-06-28 8:17 ` [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read guoren 2022-06-28 8:17 ` guoren 2022-06-28 18:05 ` Waiman Long 2022-06-28 18:05 ` Waiman Long 2022-06-29 2:12 ` Guo Ren [this message] 2022-06-29 2:12 ` Guo Ren 2022-06-29 8:27 ` David Laight 2022-06-29 8:27 ` David Laight 2022-07-01 15:18 ` Guo Ren 2022-07-01 15:18 ` Guo Ren 2022-07-04 9:52 ` Peter Zijlstra 2022-07-04 9:52 ` Peter Zijlstra 2022-07-04 11:10 ` Guo Ren 2022-07-04 11:10 ` Guo Ren 2022-06-28 8:17 ` [PATCH V7 2/5] asm-generic: ticket-lock: Use the same struct definitions with qspinlock guoren 2022-06-28 8:17 ` guoren 2022-06-28 8:17 ` [PATCH V7 3/5] asm-generic: ticket-lock: Move into ticket_spinlock.h guoren 2022-06-28 8:17 ` guoren 2022-06-28 8:17 ` [PATCH V7 4/5] asm-generic: spinlock: Add combo spinlock (ticket & queued) guoren 2022-06-28 8:17 ` guoren 2022-06-28 18:13 ` Waiman Long 2022-06-28 18:13 ` Waiman Long 2022-06-29 1:17 ` Guo Ren 2022-06-29 1:17 ` Guo Ren 2022-06-29 1:34 ` Waiman Long 2022-06-29 1:34 ` Waiman Long 2022-06-29 2:29 ` Guo Ren 2022-06-29 2:29 ` Guo Ren 2022-06-29 7:08 ` Arnd Bergmann 2022-06-29 7:08 ` Arnd Bergmann 2022-06-29 8:24 ` Guo Ren 2022-06-29 8:24 ` Guo Ren 2022-06-29 8:29 ` Arnd Bergmann 2022-06-29 8:29 ` Arnd Bergmann 2022-07-01 12:18 ` Guo Ren 2022-07-01 12:18 ` Guo Ren 2022-06-29 12:53 ` Waiman Long 2022-06-29 12:53 ` Waiman Long 2022-07-04 9:57 ` Peter Zijlstra 2022-07-04 9:57 ` Peter Zijlstra 2022-07-04 13:13 ` Guo Ren 2022-07-04 13:13 ` Guo Ren 2022-07-04 13:45 ` Peter Zijlstra 2022-07-04 13:45 ` Peter Zijlstra 2022-06-28 8:17 ` [PATCH V7 5/5] riscv: Add qspinlock support guoren 2022-06-28 8:17 ` guoren
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='CAJF2gTRBoAZzjWGJ0zAxv0eqBB-G=V3QHmp6+jXyznmuY6LhCQ@mail.gmail.com' \ --to=guoren@kernel.org \ --cc=arnd@arndb.de \ --cc=boqun.feng@gmail.com \ --cc=guoren@linux.alibaba.com \ --cc=linux-arch@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ --cc=longman@redhat.com \ --cc=mingo@redhat.com \ --cc=palmer@rivosinc.com \ --cc=peterz@infradead.org \ --cc=will@kernel.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: linkBe 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.