From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754442AbbFVXKf (ORCPT ); Mon, 22 Jun 2015 19:10:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42495 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbbFVXJs (ORCPT ); Mon, 22 Jun 2015 19:09:48 -0400 Date: Tue, 23 Jun 2015 01:08:32 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: paulmck@linux.vnet.ibm.com, tj@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, der.herr@hofr.at, dave@stgolabs.net, riel@redhat.com, viro@ZenIV.linux.org.uk, torvalds@linux-foundation.org Subject: Re: [RFC][PATCH 06/13] percpu-rwsem: Provide percpu_down_read_trylock() Message-ID: <20150622230832.GC5582@redhat.com> References: <20150622121623.291363374@infradead.org> <20150622122256.161153855@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150622122256.161153855@infradead.org> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/22, Peter Zijlstra wrote: > > +static inline bool percpu_down_read_trylock(struct percpu_rw_semaphore *sem) > +{ > + bool ret = true; > + > + preempt_disable(); > + __this_cpu_inc(*sem->refcount); > + if (unlikely(!rcu_sync_is_idle(&sem->rss))) > + ret = __percpu_down_read_trylock(sem); > + preempt_enable(); > + > + if (ret) > + rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 1, _RET_IP_); > + > + return ret; > +} ... > +bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem) > +{ > + smp_mb(); /* A matches D */ > + > + if (likely(smp_load_acquire(&sem->state) != readers_block)) > + return true; > + > + __percpu_up_read(sem); > + > + return false; > +} Looks like we can slightly refactor this code to avoid the code duplication. But this is minor too and we can do this later. Reviewed-by: Oleg Nesterov -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Please read the FAQ at http://www.tux.org/lkml/