public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hp.com>
To: Jason Low <jason.low2@hp.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	mingo@kernel.org, tglx@linutronix.de, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com,
	tim.c.chen@linux.intel.com, peter@hurleysoftware.com,
	riel@redhat.com, hpa@zytor.com, walken@google.com,
	davidlohr@hp.com, aswin@hp.com, scott.norton@hp.com,
	chegu_vinod@hp.com
Subject: Re: [RFC PATCH 1/3] locking/mutex: Try to acquire mutex only if it is unlocked
Date: Wed, 04 Jun 2014 23:24:14 -0400	[thread overview]
Message-ID: <538FE2DE.8080800@hp.com> (raw)
In-Reply-To: <1401917173.2232.14.camel@j-VirtualBox>

On 06/04/2014 05:26 PM, Jason Low wrote:
> On Wed, 2014-06-04 at 21:43 +0200, Peter Zijlstra wrote:
>> On Wed, Jun 04, 2014 at 12:08:29PM -0700, Jason Low wrote:
>>> Upon entering the slowpath in __mutex_lock_common(), we try once more
>>> to acquire the mutex. We only try to acquire it if MUTEX_SHOW_NO_WAITER
>>> (lock->count>= 0) is true in order to avoid using the atomic xchg()
>>> operation whenever it is not necessary. However, we really only need
>>> to try to acquire if the mutex is free (lock->count == 1).
>>>
>>> This patch changes it so that we only try-acquire the mutex upon
>>> entering the slowpath if it is unlocked, rather than if there are
>>> no waiters. This helps further reduce unncessary atomic xchg()
>>> operations. Furthermore, this patch introduces and uses a new
>>> MUTEX_IS_UNLOCKED() macro to improve readbability.
>>>
>>> Signed-off-by: Jason Low<jason.low2@hp.com>
>>> ---
>>>   kernel/locking/mutex.c |   10 ++++++----
>>>   1 files changed, 6 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
>>> index bc73d33..0925968 100644
>>> --- a/kernel/locking/mutex.c
>>> +++ b/kernel/locking/mutex.c
>>> @@ -48,9 +48,10 @@
>>>
>>>   /*
>>>    * A negative mutex count indicates that waiters are sleeping waiting for the
>>> - * mutex.
>>> + * mutex, and a count of one indicates the mutex is unlocked.
>>>    */
>>>   #define	MUTEX_SHOW_NO_WAITER(mutex)	(atomic_read(&(mutex)->count)>= 0)
>>> +#define	MUTEX_IS_UNLOCKED(mutex)	(atomic_read(&(mutex)->count) == 1)
>> So I recently saw that MUTEX_SHOW_NO_WAITER thing and cried a little;
>> and now you're adding more of that same nonsense.
>>
>> Please make them inline functions, also can we rename the SHOW_NO_WAITER
>> thing, because its not at all clear to me wtf it does; should it be
>> called: mutex_no_waiters() or somesuch?
> Okay, I can make them inline functions. I mainly added the macro to keep
> it consistent with the MUTEX_SHOW_NO_WAITER() check, but we can surely
> make this more clear. mutex_no_waiters() sounds fine, or perhaps
> something like mutex_has_no_waiters()?
>

You can remove the MUTEX_SHOW_NO_WAITER macro as all the call sites are 
to be replaced. I didn't check directly for unlocked count because of 
fairness concern in my original patch, but I think checking directly for 
unlocked count should be fine too.

-Longman

  parent reply	other threads:[~2014-06-05  3:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 19:08 [RFC PATCH 0/3] locking/mutex: Modifications to mutex Jason Low
2014-06-04 19:08 ` [RFC PATCH 1/3] locking/mutex: Try to acquire mutex only if it is unlocked Jason Low
2014-06-04 19:43   ` Peter Zijlstra
2014-06-04 20:57     ` Davidlohr Bueso
2014-06-04 20:58       ` Davidlohr Bueso
2014-06-09 17:38         ` Jason Low
2014-06-11 21:00           ` Long, Wai Man
2014-06-11 21:48             ` Jason Low
2014-06-12  1:25               ` Long, Wai Man
2014-06-04 21:53       ` Jason Low
2014-06-04 21:26     ` Jason Low
2014-06-04 21:54       ` Thomas Gleixner
2014-06-04 22:13         ` Jason Low
2014-06-05  3:24       ` Waiman Long [this message]
2014-06-05 19:21         ` Jason Low
2014-06-04 19:08 ` [RFC PATCH 2/3] locking/mutex: Correct documentation on mutex optimistic spinning Jason Low
2014-06-04 20:11   ` Davidlohr Bueso
2014-06-04 20:30     ` Jason Low
2014-06-04 19:08 ` [RFC PATCH 3/3] locking/mutex: Optimize mutex trylock slowpath Jason Low
2014-06-04 20:28   ` Davidlohr Bueso
2014-06-04 21:47     ` Jason Low
2014-06-05  1:10       ` Davidlohr Bueso
2014-06-05  3:08         ` Jason Low
2014-06-04 20:13 ` [RFC PATCH 0/3] locking/mutex: Modifications to mutex Davidlohr Bueso

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=538FE2DE.8080800@hp.com \
    --to=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=jason.low2@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peter@hurleysoftware.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=scott.norton@hp.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=walken@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox