Re: [PATCH v3 10/36] hrtimer: Switch for loop to _ffs() evaluation

From: Joe Perches
Date: Wed Nov 29 2017 - 11:06:12 EST


On Wed, 2017-11-29 at 16:30 +0100, Anna-Maria Gleixner wrote:
> Looping over all clock bases to find active bits is suboptimal if not all
> bases are active.
>
> Avoid this by converting it to a __ffs() evaluation. The functionallity is
> outsourced into an own function and is called via a macro as suggested by
> Peter Zijlstra.

style trivia: ignore at your pleasure...

> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
[]
> @@ -448,6 +448,23 @@ static inline void debug_deactivate(struct hrtimer *timer)
> trace_hrtimer_cancel(timer);
> }
>
> +static struct hrtimer_clock_base *
> +__next_base(struct hrtimer_cpu_base *cpu_base, unsigned int *active)
> +{
> + struct hrtimer_clock_base *base = NULL;
> +
> + if (*active) {
> + unsigned int idx = __ffs(*active);
> + *active &= ~(1U << idx);
> + base = &cpu_base->clock_base[idx];
> + }
> +
> + return base;
> +}

This might be nicer using an initial test and return like:

{
unsigned int idx;

if (!*active)
return NULL;

idx = __ffs(*active);
*active &= ~(1U << idx);

return &cpu_base->clock_base[idx];
}