From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751231AbcEJHC1 (ORCPT ); Tue, 10 May 2016 03:02:27 -0400 Received: from merlin.infradead.org ([205.233.59.134]:58035 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750954AbcEJHC0 (ORCPT ); Tue, 10 May 2016 03:02:26 -0400 Date: Tue, 10 May 2016 09:02:19 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso , Jason Low , Dave Chinner , Scott J Norton , Douglas Hatch Subject: Re: [PATCH v2] locking/rwsem: Add reader-owned state to the owner field Message-ID: <20160510070219.GG3408@twins.programming.kicks-ass.net> References: <1462580424-40333-1-git-send-email-Waiman.Long@hpe.com> <20160509082741.GF3430@twins.programming.kicks-ass.net> <57314650.5050206@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57314650.5050206@hpe.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 Mon, May 09, 2016 at 10:24:16PM -0400, Waiman Long wrote: > >>+static inline void rwsem_set_reader_owned(struct rw_semaphore *sem) > >>+{ > >>+ /* > >>+ * We check the owner value first to make sure that we will only > >>+ * do a write to the rwsem cacheline when it is really necessary > >>+ * to minimize cacheline contention. > >>+ */ > >>+ if (sem->owner != (struct task_struct *)RWSEM_READER_OWNED) > >>+ sem->owner = (struct task_struct *)RWSEM_READER_OWNED; > >How much if anything did this optimization matter? > > I hadn't run any performance test to verify the effective of this change. > For a reader-heavy rwsem, this change should be able to save quite a lot of > needless write to the rwsem cacheline. Right; I was just wondering. > >>+static inline bool rwsem_is_writer_owned(struct task_struct *owner) > >>+{ > >>+ return (unsigned long)owner> RWSEM_READER_OWNED; > >>+} > >Tad too clever that; what does GCC generate if you write the obvious: > > > > return owner&& owner != RWSEM_READER_OWNER; > > You are right. GCC is intelligent enough to make the necessary optimization. > I will revert it to this form which is more obvious. Yay! thanks for checking. Sometimes GCC throws a wobbly and does something unexpected, but it tends to get these 'simple' things right.