From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932089AbbDNMbV (ORCPT ); Tue, 14 Apr 2015 08:31:21 -0400 Received: from casper.infradead.org ([85.118.1.10]:56528 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752908AbbDNMbO (ORCPT ); Tue, 14 Apr 2015 08:31:14 -0400 Date: Tue, 14 Apr 2015 14:31:02 +0200 From: Peter Zijlstra To: Ingo Molnar Cc: rusty@rustcorp.com.au, mathieu.desnoyers@efficios.com, oleg@redhat.com, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, andi@firstfloor.org, rostedt@goodmis.org, tglx@linutronix.de, laijs@cn.fujitsu.com, linux@horizon.com Subject: Re: [PATCH v5 07/10] module: Optimize __module_address() using a latched RB-tree Message-ID: <20150414123102.GK5029@twins.programming.kicks-ass.net> References: <20150413141126.756350256@infradead.org> <20150413141213.614514026@infradead.org> <20150413164949.GF6040@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150413164949.GF6040@gmail.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, Apr 13, 2015 at 06:49:49PM +0200, Ingo Molnar wrote: > * Peter Zijlstra wrote: > > +static __always_inline int > > +mod_tree_comp(void *key, struct latch_tree_node *n) > > +{ > > + unsigned long val = (unsigned long)key; > > + unsigned long start, end; > > + > > + end = start = __mod_tree_val(n); > > + end += __mod_tree_size(n); > > + > > + if (val < start) > > + return -1; > > + > > + if (val >= end) > > + return 1; > > + > > + return 0; > > So since we are counting nanoseconds, I suspect this could be written > more optimally as: > > { > unsigned long val = (unsigned long)key; > unsigned long start, end; > > start = __mod_tree_val(n); > if (val < start) > return -1; > > end = start + __mod_tree_size(n); > if (val >= end) > return 1; > > return 0; > } > > right? I was afraid it would rip apart the common bits of __mod_tree_{val,size}(), iow. it would end up doing the whole latch_tree_node -> mod_tree_node -> mod and mtn_init comparison dance twice. But GCC does the right thing, so yes.