From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753647AbbCIRm4 (ORCPT ); Mon, 9 Mar 2015 13:42:56 -0400 Received: from g4t3425.houston.hp.com ([15.201.208.53]:25022 "EHLO g4t3425.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752035AbbCIRmz (ORCPT ); Mon, 9 Mar 2015 13:42:55 -0400 Message-ID: <1425922969.2475.394.camel@j-VirtualBox> Subject: Re: [PATCH] locking/rwsem: Fix lock optimistic spinning when owner is not running From: Jason Low To: Peter Zijlstra Cc: Linus Torvalds , Ingo Molnar , Davidlohr Bueso , Tim Chen , "Paul E. McKenney" , Michel Lespinasse , Sasha Levin , LKML , Dave Jones , Ming Lei , jason.low2@hp.com Date: Mon, 09 Mar 2015 10:42:49 -0700 In-Reply-To: <20150307092126.GO23367@worktop.ger.corp.intel.com> References: <1425714331.2475.388.camel@j-VirtualBox> <20150307092126.GO23367@worktop.ger.corp.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2015-03-07 at 10:21 +0100, Peter Zijlstra wrote: > On Fri, Mar 06, 2015 at 11:45:31PM -0800, Jason Low wrote: > > static noinline > > bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner) > > { > > long count; > > > > rcu_read_lock(); > > + while (sem->owner == owner) { > > + /* > > + * Ensure we emit the owner->on_cpu, dereference _after_ > > + * checking sem->owner still matches owner, if that fails, > > + * owner might point to free()d memory, if it still matches, > > + * the rcu_read_lock() ensures the memory stays valid. > > + */ > > + barrier(); > > + > > + /* abort spinning when need_resched or owner is not running */ > > + if (!owner->on_cpu || need_resched()) { > > rcu_read_unlock(); > > return false; > > } > > Thanks, looks good; do we want to change the mutex code (again) to more > closely resemble this too? It still has the while (true) instead of the > while(lock->owner != owner). Yeah, I wondered about the same thing, though I wasn't sure if you wanted an additional patch just for that change. Guess you answered it for me :)