From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547AbdHaM3G (ORCPT ); Thu, 31 Aug 2017 08:29:06 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:60529 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922AbdHaMXh (ORCPT ); Thu, 31 Aug 2017 08:23:37 -0400 Message-Id: <20170831105825.962810871@linutronix.de> User-Agent: quilt/0.63-1 Date: Thu, 31 Aug 2017 12:23:35 -0000 From: Anna-Maria Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Christoph Hellwig , keescook@chromium.org, John Stultz , Thomas Gleixner Subject: [PATCH 05/25] hrtimer: Switch for loop to _ffs() evaluation References: <20170831105725.809317030@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=hrtimer_Switch_for_loop_to__ffs()_evaluation.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anna-Maria Gleixner 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. Signed-off-by: Anna-Maria Gleixner --- kernel/time/hrtimer.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -465,17 +465,18 @@ static inline void hrtimer_update_next_t static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base) { - struct hrtimer_clock_base *base = cpu_base->clock_base; unsigned int active = cpu_base->active_bases; ktime_t expires, expires_next = KTIME_MAX; hrtimer_update_next_timer(cpu_base, NULL); - for (; active; base++, active >>= 1) { + while (active) { + unsigned int id = __ffs(active); + struct hrtimer_clock_base *base; struct timerqueue_node *next; struct hrtimer *timer; - if (!(active & 0x01)) - continue; + active &= ~(1U << id); + base = cpu_base->clock_base + id; next = timerqueue_getnext(&base->active); timer = container_of(next, struct hrtimer, node); @@ -1242,15 +1243,16 @@ static void __run_hrtimer(struct hrtimer static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now) { - struct hrtimer_clock_base *base = cpu_base->clock_base; unsigned int active = cpu_base->active_bases; - for (; active; base++, active >>= 1) { + while (active) { + unsigned int id = __ffs(active); + struct hrtimer_clock_base *base; struct timerqueue_node *node; ktime_t basenow; - if (!(active & 0x01)) - continue; + active &= ~(1U << id); + base = cpu_base->clock_base + id; basenow = ktime_add(now, base->offset);