Re: [PATCH v5 07/10] module: Optimize __module_address() using a latched RB-tree

From: Peter Zijlstra
Date: Tue Apr 14 2015 - 08:31:24 EST


On Mon, Apr 13, 2015 at 06:49:49PM +0200, Ingo Molnar wrote:
> * Peter Zijlstra <peterz@xxxxxxxxxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/