From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932224AbcEKSiQ (ORCPT ); Wed, 11 May 2016 14:38:16 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:41876 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836AbcEKSiP (ORCPT ); Wed, 11 May 2016 14:38:15 -0400 Date: Wed, 11 May 2016 20:38:09 +0200 From: Peter Zijlstra To: Jason Low Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso , Scott J Norton , Waiman Long , peter@hurleysoftware.com, jason.low2@hpe.com Subject: Re: [PATCH] locking/rwsem: Optimize write lock slowpath Message-ID: <20160511183809.GJ3192@twins.programming.kicks-ass.net> References: <1462821397.2701.16.camel@j-VirtualBox> <20160511114918.GG3190@twins.programming.kicks-ass.net> <1462991162.2488.23.camel@j-VirtualBox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1462991162.2488.23.camel@j-VirtualBox> 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, May 11, 2016 at 11:26:02AM -0700, Jason Low wrote: > On Wed, 2016-05-11 at 13:49 +0200, Peter Zijlstra wrote: > > > static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem) > > > { > > > /* > > > + * Avoid trying to acquire write lock if count isn't RWSEM_WAITING_BIAS. > > > */ > > > + if (count != RWSEM_WAITING_BIAS) > > > + return false; > > > + > > > + /* > > > + * Acquire the lock by trying to set it to ACTIVE_WRITE_BIAS. If there > > > + * are other tasks on the wait list, we need to add on WAITING_BIAS. > > > + */ > > > + count = list_is_singular(&sem->wait_list) ? > > > + RWSEM_ACTIVE_WRITE_BIAS : > > > + RWSEM_ACTIVE_WRITE_BIAS + RWSEM_WAITING_BIAS; > > > + > > > + if (cmpxchg_acquire(&sem->count, RWSEM_WAITING_BIAS, count) == RWSEM_WAITING_BIAS) { > > > rwsem_set_owner(sem); > > > return true; > > > } > > > > Right; so that whole thing works because we're holding sem->wait_lock. > > Should we clarify that someplace? > > Yup, we can mention that the rwsem_try_write_lock() function must be > called with the wait_lock held. Also try to explain _why_ it must be held. Thanks!