From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751807AbcEUA7c (ORCPT ); Fri, 20 May 2016 20:59:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:50120 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbcEUA7b (ORCPT ); Fri, 20 May 2016 20:59:31 -0400 Date: Fri, 20 May 2016 17:59:21 -0700 From: Davidlohr Bueso To: Peter Zijlstra Cc: Waiman Long , manfred@colorfullife.com, mingo@kernel.org, torvalds@linux-foundation.org, ggherdovich@suse.com, mgorman@techsingularity.net, linux-kernel@vger.kernel.org Subject: Re: sem_lock() vs qspinlocks Message-ID: <20160521005921.GB28231@linux-uzut.site> References: <20160520053926.GC31084@linux-uzut.site> <20160520074946.GA3193@twins.programming.kicks-ass.net> <20160520150049.GB7086@linux-uzut.site> <573F77EF.3020409@hpe.com> <20160520205222.GI3193@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20160520205222.GI3193@twins.programming.kicks-ass.net> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 May 2016, Peter Zijlstra wrote: >On Fri, May 20, 2016 at 04:47:43PM -0400, Waiman Long wrote: > >> >Similarly, and I know you hate it, but afaict, then semantically >> >queued_spin_is_contended() ought to be: >> > >> >- return atomic_read(&lock->val) & ~_Q_LOCKED_MASK; >> >+ return atomic_read(&lock->val); >> > > >> Looking for contended lock, you need to consider the lock waiters also. So >> looking at the whole word is right. > >No, you _only_ need to look at the lock waiters. Is there anyway to do this in a single atomic_read? My thought is that otherwise we could further expand the race window of when the lock is and isn't contended (as returned to by the user). Ie avoiding crap like: atomic_read(&lock->val) && atomic_read(&lock->val) != _Q_LOCKED_VAL In any case, falsely returning for the 'locked, uncontended' case, vs completely ignoring waiters is probably the lesser evil :). Thanks, Davidlohr