[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZY/6YCNJ7tSCmiGo@gmail.com>
Date: Sat, 30 Dec 2023 12:09:20 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Waiman Long <longman@...hat.com>
Cc: David Laight <David.Laight@...lab.com>,
"'linux-kernel@...r.kernel.org'" <linux-kernel@...r.kernel.org>,
"'peterz@...radead.org'" <peterz@...radead.org>,
"'mingo@...hat.com'" <mingo@...hat.com>,
"'will@...nel.org'" <will@...nel.org>,
"'boqun.feng@...il.com'" <boqun.feng@...il.com>,
'Linus Torvalds' <torvalds@...ux-foundation.org>,
"'xinhui.pan@...ux.vnet.ibm.com'" <xinhui.pan@...ux.vnet.ibm.com>,
"'virtualization@...ts.linux-foundation.org'" <virtualization@...ts.linux-foundation.org>,
'Zeng Heng' <zengheng4@...wei.com>
Subject: Re: [PATCH next 4/5] locking/osq_lock: Optimise per-cpu data
accesses.
* Waiman Long <longman@...hat.com> wrote:
> On 12/29/23 15:57, David Laight wrote:
> > this_cpu_ptr() is rather more expensive than raw_cpu_read() since
> > the latter can use an 'offset from register' (%gs for x86-84).
> >
> > Add a 'self' field to 'struct optimistic_spin_node' that can be
> > read with raw_cpu_read(), initialise on first call.
> >
> > Signed-off-by: David Laight <david.laight@...lab.com>
> > ---
> > kernel/locking/osq_lock.c | 14 +++++++++-----
> > 1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
> > index 9bb3a077ba92..b60b0add0161 100644
> > --- a/kernel/locking/osq_lock.c
> > +++ b/kernel/locking/osq_lock.c
> > @@ -13,7 +13,7 @@
> > */
> > struct optimistic_spin_node {
> > - struct optimistic_spin_node *next, *prev;
> > + struct optimistic_spin_node *self, *next, *prev;
> > int locked; /* 1 if lock acquired */
> > int cpu; /* encoded CPU # + 1 value */
> > };
> > @@ -93,12 +93,16 @@ osq_wait_next(struct optimistic_spin_queue *lock,
> > bool osq_lock(struct optimistic_spin_queue *lock)
> > {
> > - struct optimistic_spin_node *node = this_cpu_ptr(&osq_node);
> > + struct optimistic_spin_node *node = raw_cpu_read(osq_node.self);
>
> My gcc 11 compiler produces the following x86-64 code:
>
> 92 struct optimistic_spin_node *node = this_cpu_ptr(&osq_node);
> 0x0000000000000029 <+25>: mov %rcx,%rdx
> 0x000000000000002c <+28>: add %gs:0x0(%rip),%rdx # 0x34
> <osq_lock+36>
>
> Which looks pretty optimized for me. Maybe older compiler may generate more
> complex code. However, I do have some doubt as to the benefit of this patch
> at the expense of making the code a bit more complex.
GCC-11 is plenty of a look-back window in terms of compiler efficiency:
latest enterprise distros use GCC-11 or newer, while recent desktop
distros use GCC-13. Anything older won't matter, because no major
distribution is going to use new kernels with old compilers.
Thanks,
Ingo
Powered by blists - more mailing lists