lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56C2673F.6070202@hpe.com>
Date:	Mon, 15 Feb 2016 19:03:11 -0500
From:	Waiman Long <waiman.long@....com>
To:	Davidlohr Bueso <dave@...olabs.net>
CC:	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	<linux-kernel@...r.kernel.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Ding Tianhong <dingtianhong@...wei.com>,
	Jason Low <jason.low2@....com>,
	"Paul E. McKenney" <paulmck@...ibm.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Will Deacon <Will.Deacon@....com>,
	Tim Chen <tim.c.chen@...ux.intel.com>,
	Waiman Long <Waiman.Long@...com>
Subject: Re: [PATCH v2 1/4] locking/mutex: Add waiter parameter to mutex_optimistic_spin()

On 02/12/2016 05:02 PM, Davidlohr Bueso wrote:
> On Fri, 12 Feb 2016, Waiman Long wrote:
>
>> This patch adds a new waiter parameter to the mutex_optimistic_spin()
>> function to prepare it to be used by a waiter-spinner that doesn't
>> need to go into the OSQ as there can only be one waiter-spinner which
>> is the head of the waiting queue.
>>
>> Signed-off-by: Waiman Long <Waiman.Long@...com>
>> ---
>> kernel/locking/mutex.c |   55 
>> ++++++++++++++++++++++++++++++++---------------
>> 1 files changed, 37 insertions(+), 18 deletions(-)
>>
>> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
>> index 0551c21..3c41448 100644
>> --- a/kernel/locking/mutex.c
>> +++ b/kernel/locking/mutex.c
>> @@ -273,11 +273,15 @@ static inline int 
>> mutex_can_spin_on_owner(struct mutex *lock)
>>
>> /*
>>  * Atomically try to take the lock when it is available
>> + *
>> + * For waiter-spinner, the count needs to be set to -1 first which 
>> will be
>> + * cleared to 0 later on if the list becomes empty. For regular 
>> spinner,
>> + * the count will be set to 0.
>>  */
>> -static inline bool mutex_try_to_acquire(struct mutex *lock)
>> +static inline bool mutex_try_to_acquire(struct mutex *lock, int waiter)
>> {
>>     return !mutex_is_locked(lock) &&
>> -        (atomic_cmpxchg_acquire(&lock->count, 1, 0) == 1);
>> +        (atomic_cmpxchg_acquire(&lock->count, 1, waiter ? -1 : 0) == 
>> 1);
>> }
>
> This can be a really hot path, could we get rid of the waiter check 
> and just
> introduce mutex_tro_to_acquire_waiter() or such and set the counter to 
> -1 there?
>
> Thanks,
> Davidlohr

It is hot in the sense that the lock cacheline is highly contested. On 
x86, the ?: statement will most likely be translated to a cmov 
instruction before doing the cmpxchg. The cmov instruction won't affect 
the amount of cacheline contention on that lock cacheline. So I don't 
see there is any problem here.

Cheers,
Longman

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ