Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030746AbbD1R7Z (ORCPT ); Tue, 28 Apr 2015 13:59:25 -0400 Received: from g4t3427.houston.hp.com ([15.201.208.55]:56803 "EHLO g4t3427.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030577AbbD1R7Y (ORCPT ); Tue, 28 Apr 2015 13:59:24 -0400 Message-ID: <1430243958.4463.10.camel@j-VirtualBox> Subject: Re: [PATCH v3] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write From: Jason Low To: Peter Zijlstra Cc: Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso , Scott J Norton , Douglas Hatch , jason.low2@hp.com Date: Tue, 28 Apr 2015 10:59:18 -0700 In-Reply-To: <1430243401.4463.4.camel@j-VirtualBox> References: <1429898069-28907-1-git-send-email-Waiman.Long@hp.com> <20150428171734.GH23123@twins.programming.kicks-ass.net> <1430243401.4463.4.camel@j-VirtualBox> 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 Content-Length: 1673 Lines: 74 On Tue, 2015-04-28 at 10:50 -0700, Jason Low wrote: > On Tue, 2015-04-28 at 19:17 +0200, Peter Zijlstra wrote: > > > To me it makes more sense to reverse these two branches (identical code > > wise of course) and put the special case first. > > > > Alternatively we could also do something like the below, which to my > > eyes looks a little better still, but I don't care too much. > > > > if (rwsem_has_spinner(sem)) { > > /* > > * comment ... > > */ > > smp_rmb(); > > if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags)) > > return sem; > > goto locked; > > } > > > > raw_spin_lock_irqsave(&sem->wait_lock, flags); > > locked: > > How about putting this into its own function: > > static inline bool __rwsem_wake_acquire_wait_lock(sem) > { > /* > * > * Comments > * > */ > if (unlikely(rwsem_has_spinner(sem))) { > /* > * Comments > */ > smp_rmb(); > if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags)) > return false; > } > > return true; > } That is, with the raw_spin_lock_irqsave() too :) static inline bool __rwsem_wake_acquire_wait_lock(sem) { /* * * Comments * */ if (unlikely(rwsem_has_spinner(sem))) { /* * Comments */ smp_rmb(); if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags)) return false; /* trylock successful */ return true; } raw_spin_lock_irqsave(&sem->wait_lock, flags); return true; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/