From: Jason Low <jason.low2@hp.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: peterz@infradead.org, torvalds@linux-foundation.org,
paulmck@linux.vnet.ibm.com, mingo@kernel.org, Waiman.Long@hp.com,
davidlohr@hp.com, linux-kernel@vger.kernel.org,
tglx@linutronix.de, riel@redhat.com, akpm@linux-foundation.org,
hpa@zytor.com, tim.c.chen@linux.intel.com,
konrad.wilk@oracle.com, aswin@hp.com, scott.norton@hp.com,
chegu_vinod@hp.com
Subject: Re: [PATCH 2/4] MCS spinlocks: Convert osq lock to atomic_t to reduce overhead
Date: Tue, 08 Jul 2014 09:44:30 -0700 [thread overview]
Message-ID: <1404837870.2448.9.camel@j-VirtualBox> (raw)
In-Reply-To: <20140708093826.32a734f3@gandalf.local.home>
On Tue, 2014-07-08 at 09:38 -0400, Steven Rostedt wrote:
> On Mon, 7 Jul 2014 11:50:17 -0700
> Jason Low <jason.low2@hp.com> wrote:
> > #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
> > @@ -33,7 +32,7 @@ struct rw_semaphore {
> > * if the owner is running on the cpu.
> > */
> > struct task_struct *owner;
> > - struct optimistic_spin_node *osq; /* spinner MCS lock */
> > + struct optimistic_spin_queue osq; /* spinner MCS lock */
> > #endif
> > #ifdef CONFIG_DEBUG_LOCK_ALLOC
> > struct lockdep_map dep_map;
> > @@ -70,7 +69,7 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
> > __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
> > LIST_HEAD_INIT((name).wait_list), \
> > NULL, /* owner */ \
> > - NULL /* mcs lock */ \
> > + { ATOMIC_INIT(OSQ_UNLOCKED_VAL) } /* osq */ \
>
> This should probably be a macro, similar to the __RWSEM_DEP_MAP_INIT()
> below. Open coded inits are evil.
>
> OSQ_LOCK_INIT() ?
I agree that we should use a macro here for the lock instead of directly
initializing it. Same with using a macro instead of directly calling the
atomic_sets in the later parts of this patch.
>
> > __RWSEM_DEP_MAP_INIT(name) }
> > #else
> > #define __RWSEM_INITIALIZER(name) \
> > diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
> > index e9866f7..124a3bb 100644
> > --- a/kernel/locking/mcs_spinlock.c
> > +++ b/kernel/locking/mcs_spinlock.c
> > @@ -17,18 +17,43 @@
> > static DEFINE_PER_CPU_SHARED_ALIGNED(struct optimistic_spin_node, osq_node);
> >
> > /*
> > + * We use the value 0 to represent "no CPU", thus the encoded value
> > + * will be the CPU number incremented by 1.
> > + */
> > +static inline int encode_cpu(int cpu_nr)
> > +{
> > + return (cpu_nr + 1);
>
> return is not a function, remove the parenthesis (checkpatch should
> point that out to you too).
I ran checkpatch and it didn't seem to be an issue. I was using the
parenthesis as "operator precedence" rather than a function call.
However, those parenthesis aren't necessary so we can delete them
anyway.
> > +}
> > +
> > +static inline struct optimistic_spin_node *decode_cpu(int encoded_cpu_val)
> > +{
> > + int cpu_nr = encoded_cpu_val - 1;
> > +
> > + return per_cpu_ptr(&osq_node, cpu_nr);
> > +}
> > +
> > +/*
> > * Get a stable @node->next pointer, either for unlock() or unqueue() purposes.
> > * Can return NULL in case we were the last queued and we updated @lock instead.
> > */
> > static inline struct optimistic_spin_node *
> > -osq_wait_next(struct optimistic_spin_node **lock,
> > +osq_wait_next(struct optimistic_spin_queue *lock,
> > struct optimistic_spin_node *node,
> > struct optimistic_spin_node *prev)
> > {
> > struct optimistic_spin_node *next = NULL;
> > + int curr = encode_cpu(smp_processor_id()), old;
>
> Add a second line for "int old". Having it after an initialization is
> weird and confusing.
Sure. Thanks!
next prev parent reply other threads:[~2014-07-08 16:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 18:50 [PATCH 0/4] MCS spinlocks: Cancellable MCS spinlock rework Jason Low
2014-07-07 18:50 ` [PATCH 1/4] MCS spinlocks: Rename optimistic_spin_queue to optimistic_spin_node Jason Low
2014-07-07 18:50 ` [PATCH 2/4] MCS spinlocks: Convert osq lock to atomic_t to reduce overhead Jason Low
2014-07-08 13:38 ` Steven Rostedt
2014-07-08 16:44 ` Jason Low [this message]
2014-07-07 18:50 ` [PATCH 3/4] MCS spinlocks: Micro-optimize osq_unlock() Jason Low
2014-07-07 18:50 ` [PATCH 4/4] rwsem: Reduce the size of struct rw_semaphore Jason Low
2014-07-11 9:29 ` Peter Zijlstra
2014-07-07 19:06 ` [PATCH 0/4] MCS spinlocks: Cancellable MCS spinlock rework Peter Zijlstra
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=1404837870.2448.9.camel@j-VirtualBox \
--to=jason.low2@hp.com \
--cc=Waiman.Long@hp.com \
--cc=akpm@linux-foundation.org \
--cc=aswin@hp.com \
--cc=chegu_vinod@hp.com \
--cc=davidlohr@hp.com \
--cc=hpa@zytor.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=rostedt@goodmis.org \
--cc=scott.norton@hp.com \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.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: link
Be 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.