From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752093AbcEUHkn (ORCPT ); Sat, 21 May 2016 03:40:43 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40699 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751910AbcEUHkf (ORCPT ); Sat, 21 May 2016 03:40:35 -0400 Date: Sat, 21 May 2016 09:40:21 +0200 From: Peter Zijlstra To: Waiman Long Cc: Davidlohr Bueso , 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: <20160521074021.GC15728@worktop.ger.corp.intel.com> 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> <20160521005921.GB28231@linux-uzut.site> <573FDD7C.8080102@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <573FDD7C.8080102@hpe.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 21, 2016 at 12:01:00AM -0400, Waiman Long wrote: > On 05/20/2016 08:59 PM, Davidlohr Bueso wrote: > >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 Its inherently racy, arrival of a contender is subject to timing. No point in trying to fix what can't be fixed. > The existing code is doing that, but I would argue that including the > locked, but uncontended case isn't a bad idea. It _IS_ a bad idea, you get unconditional lock-breaks. Its the same as: #define spin_is_contended(l) (true) Because the only reason you're using spin_is_conteded() is if you're holding it.