From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933278AbdK2QGI (ORCPT ); Wed, 29 Nov 2017 11:06:08 -0500 Received: from smtprelay0003.hostedemail.com ([216.40.44.3]:42878 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753153AbdK2QGH (ORCPT ); Wed, 29 Nov 2017 11:06:07 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:541:599:960:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3867:3868:3871:3872:4321:5007:7903:10004:10400:10848:11026:11232:11658:11914:12438:12679:12740:12760:12895:13069:13311:13357:13439:14659:14721:21080:21324:21433:21451:21627:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: cream81_522f212da8822 X-Filterd-Recvd-Size: 2144 Message-ID: <1511971563.19952.63.camel@perches.com> Subject: Re: [PATCH v3 10/36] hrtimer: Switch for loop to _ffs() evaluation From: Joe Perches To: Anna-Maria Gleixner , LKML Cc: Thomas Gleixner , Peter Zijlstra , Ingo Molnar , keescook@chromium.org, Christoph Hellwig , John Stultz Date: Wed, 29 Nov 2017 08:06:03 -0800 In-Reply-To: <20171129153101.27297-11-anna-maria@linutronix.de> References: <20171129153101.27297-1-anna-maria@linutronix.de> <20171129153101.27297-11-anna-maria@linutronix.de> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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]; }