From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932784AbcDTOS1 (ORCPT ); Wed, 20 Apr 2016 10:18:27 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38102 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932107AbcDTOS0 (ORCPT ); Wed, 20 Apr 2016 10:18:26 -0400 Date: Wed, 20 Apr 2016 16:18:19 +0200 From: Peter Zijlstra To: Pan Xinhui Cc: Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Scott J Norton , Douglas Hatch Subject: Re: [PATCH v2] locking/pvqspinlock: Add lock holder CPU argument to pv_wait() Message-ID: <20160420141819.GD3430@twins.programming.kicks-ass.net> References: <1460659318-53312-1-git-send-email-Waiman.Long@hpe.com> <20160420120805.GB3408@twins.programming.kicks-ass.net> <57178EED.1060207@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57178EED.1060207@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 20, 2016 at 10:15:09PM +0800, Pan Xinhui wrote: > >> +static struct pv_node *pv_lookup_hash(struct qspinlock *lock) > >> +{ > >> + unsigned long offset, hash = hash_ptr(lock, pv_lock_hash_bits); > >> + struct pv_hash_entry *he; > >> + > >> + for_each_hash_entry(he, offset, hash) { > >> + struct qspinlock *l = READ_ONCE(he->lock); > >> + > >> + if (l == lock) > > > > The other loop writes: > > > > if (READ_ONCE(he->lock) == lock) > > > Maybe because we check l is NULL or not later. So save one load. Ah duh, yes. > >> + return READ_ONCE(he->node); > >> + /* > >> + * Presence of an empty slot signal the end of search. We > >> + * may miss the entry, but that will limit the amount of > >> + * time doing the search when the desired entry isn't there. > >> + */ > >> + else if (!l) > >> + break; > > > > That 'else' is entirely pointless. Also, why isn't this: return NULL; > > > >> + } > >> + return NULL; > > > > and this BUG() ? > > > It's not a bug, the lock might not be stored in the hashtable. in unlock function, we will unhash the lock, then what will happen is: It should be if the above becomes a return NULL, no? If we can iterate the _entire_ hashtable, this lookup can be immensely expensive and we should not be doing it inside of a wait-loop.