Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752204AbbDRTfI (ORCPT ); Sat, 18 Apr 2015 15:35:08 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:40134 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbbDRTfF (ORCPT ); Sat, 18 Apr 2015 15:35:05 -0400 Date: Sat, 18 Apr 2015 17:40:14 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Jason Low , Scott J Norton , Douglas Hatch Subject: Re: [PATCH] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write Message-ID: <20150418154014.GV27490@worktop.programming.kicks-ass.net> References: <1429322598-44362-1-git-send-email-Waiman.Long@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1429322598-44362-1-git-send-email-Waiman.Long@hp.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 Content-Length: 1553 Lines: 46 On Fri, Apr 17, 2015 at 10:03:18PM -0400, Waiman Long wrote: > @@ -478,7 +515,28 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem) > { > unsigned long flags; > > - raw_spin_lock_irqsave(&sem->wait_lock, flags); > + /* > + * If a spinner is present, it is not necessary to do the wakeup. > + * Try to do wakeup only if the trylock succeeds to minimize > + * spinlock contention which may introduce too much delay in the > + * unlock operation. > + * > + * In case the spinning writer is just going to break out of the > + * waiting loop, it will still do a trylock in > + * rwsem_down_write_failed() before sleeping. > + * IOW, if rwsem_has_spinner() is true, it will guarantee at least > + * one trylock attempt on the rwsem. successful trylock? I think we're having 'issues' on if failed trylocks (and cmpxchg) imply full barriers. > + * > + * spinning writer > + * --------------- > + * [S] osq_unlock() > + * MB > + * [RmW] rwsem_try_write_lock() > + */ Ordering comes in pairs, this is incomplete. > + if (!rwsem_has_spinner(sem)) > + raw_spin_lock_irqsave(&sem->wait_lock, flags); > + else if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags)) > + return sem; > > /* do nothing if list empty */ > if (!list_empty(&sem->wait_list)) > -- > 1.7.1 > -- 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/