From patchwork Tue Apr 7 02:10:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 46804 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20963214BA for ; Tue, 7 Apr 2015 02:11:40 +0000 (UTC) Received: by labgx2 with SMTP id gx2sf9682020lab.1 for ; Mon, 06 Apr 2015 19:11:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=qlZfQQoaaBzR77W29cvxlLUvMXfy38vzep1kSCkcPuk=; b=MIaxVlQYwkMpTO/Pv+2Rzkypq0fX1uomHkcYxD6X8O8S93Vl3BM92LJtnlIXjc2jze OQp+RffDFDtgl6U6O8//T1VUN1Dequc4rM1LIPdrg4graG1SHO2FXSV3EpoJylmIcqGt XPW8RWeWiduRXhQgU3lAwMgzJLF4Yr4AtCGdyOZAWbeZh1auzLmFeqy8ft8YoOEOQ2Bt 9560eokDz3Rgs4qzyrE+8Ll9NR1mVVlVKPUe84LxPoH6n9wWAvKAkWfvcVTD3+OAXc5l XGZXq6iKDbUyI7QIWPmhJwf0jRNrlagfnFZdOz0tIgaG5Gh4yer1Sc2Yu3mHNqOxfWpa SzZw== X-Gm-Message-State: ALoCoQmkmTv825TqYiWiHE+H5GyJgrN1SLtMYS7/TX0JWck4m8V7DmXVthkKJk6AMYSlKp3+6Ik/ X-Received: by 10.180.85.129 with SMTP id h1mr23108wiz.6.1428372699111; Mon, 06 Apr 2015 19:11:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.194 with SMTP id v2ls542365lag.59.gmail; Mon, 06 Apr 2015 19:11:38 -0700 (PDT) X-Received: by 10.152.6.197 with SMTP id d5mr15998777laa.121.1428372698917; Mon, 06 Apr 2015 19:11:38 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id l14si4800392lbh.59.2015.04.06.19.11.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 19:11:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lboc7 with SMTP id c7so32082480lbo.1 for ; Mon, 06 Apr 2015 19:11:38 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr1162621lbc.86.1428372698796; Mon, 06 Apr 2015 19:11:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp148999lbt; Mon, 6 Apr 2015 19:11:37 -0700 (PDT) X-Received: by 10.66.216.67 with SMTP id oo3mr31432751pac.133.1428372696732; Mon, 06 Apr 2015 19:11:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ko11si9005519pbd.90.2015.04.06.19.11.35; Mon, 06 Apr 2015 19:11:36 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753210AbbDGCLU (ORCPT + 27 others); Mon, 6 Apr 2015 22:11:20 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:36555 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752851AbbDGCLR (ORCPT ); Mon, 6 Apr 2015 22:11:17 -0400 Received: by pdea3 with SMTP id a3so62760569pde.3 for ; Mon, 06 Apr 2015 19:11:16 -0700 (PDT) X-Received: by 10.70.37.139 with SMTP id y11mr32622020pdj.115.1428372676493; Mon, 06 Apr 2015 19:11:16 -0700 (PDT) Received: from localhost ([122.167.118.120]) by mx.google.com with ESMTPSA id j2sm6086590pdn.44.2015.04.06.19.11.15 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 06 Apr 2015 19:11:15 -0700 (PDT) From: Viresh Kumar To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra Cc: linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, Preeti U Murthy , Viresh Kumar Subject: [PATCH V2 2/2] hrtimer: Iterate only over active clock-bases Date: Tue, 7 Apr 2015 07:40:53 +0530 Message-Id: X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , At several instances we iterate over all possible clock-bases for a particular cpu-base. Whereas, we only need to iterate over active bases. We already have per cpu-base 'active_bases' field, which is updated on addition/removal of hrtimers. This patch creates for_each_active_base(), which uses 'active_bases' to iterate only over active bases. This also updates code which iterates over clock-bases. Signed-off-by: Viresh Kumar --- kernel/time/hrtimer.c | 65 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 3152f327c988..9da63e9ee63b 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -110,6 +110,31 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id) } +static inline int __next_bit(unsigned int active_bases, int bit) +{ + do { + if (active_bases & (1 << bit)) + return bit; + } while (++bit < HRTIMER_MAX_CLOCK_BASES); + + /* We should never reach here */ + return 0; +} + +/* + * for_each_active_base: iterate over all active clock bases + * @_bit: 'int' variable for internal purpose + * @_base: holds pointer to a active clock base + * @_cpu_base: cpu base to iterate on + * @_active_bases: 'unsigned int' variable for internal purpose + */ +#define for_each_active_base(_bit, _base, _cpu_base, _active_bases) \ + for ((_active_bases) = (_cpu_base)->active_bases, (_bit) = -1; \ + (_active_bases) && \ + ((_bit) = __next_bit(_active_bases, ++_bit), \ + (_base) = (_cpu_base)->clock_base + _bit); \ + (_active_bases) &= ~(1 << (_bit))) + /* * Get the coarse grained time at the softirq based on xtime and * wall_to_monotonic. @@ -443,19 +468,15 @@ static inline void debug_deactivate(struct hrtimer *timer) #if defined(CONFIG_NO_HZ_COMMON) || defined(CONFIG_HIGH_RES_TIMERS) static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base) { - struct hrtimer_clock_base *base = cpu_base->clock_base; + struct hrtimer_clock_base *base; ktime_t expires, expires_next = { .tv64 = KTIME_MAX }; + struct hrtimer *timer; + unsigned int active_bases; int i; - for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { - struct timerqueue_node *next; - struct hrtimer *timer; - - next = timerqueue_getnext(&base->active); - if (!next) - continue; - - timer = container_of(next, struct hrtimer, node); + for_each_active_base(i, base, cpu_base, active_bases) { + timer = container_of(timerqueue_getnext(&base->active), + struct hrtimer, node); expires = ktime_sub(hrtimer_get_expires(timer), base->offset); if (expires.tv64 < expires_next.tv64) expires_next = expires; @@ -1245,6 +1266,8 @@ void hrtimer_interrupt(struct clock_event_device *dev) { struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); ktime_t expires_next, now, entry_time, delta; + struct hrtimer_clock_base *base; + unsigned int active_bases; int i, retries = 0; BUG_ON(!cpu_base->hres_active); @@ -1264,15 +1287,10 @@ void hrtimer_interrupt(struct clock_event_device *dev) */ cpu_base->expires_next.tv64 = KTIME_MAX; - for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { - struct hrtimer_clock_base *base; + for_each_active_base(i, base, cpu_base, active_bases) { struct timerqueue_node *node; ktime_t basenow; - if (!(cpu_base->active_bases & (1 << i))) - continue; - - base = cpu_base->clock_base + i; basenow = ktime_add(now, base->offset); while ((node = timerqueue_getnext(&base->active))) { @@ -1435,16 +1453,13 @@ void hrtimer_run_queues(void) struct timerqueue_node *node; struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); struct hrtimer_clock_base *base; + unsigned int active_bases; int index, gettime = 1; if (hrtimer_hres_active()) return; - for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) { - base = &cpu_base->clock_base[index]; - if (!timerqueue_getnext(&base->active)) - continue; - + for_each_active_base(index, base, cpu_base, active_bases) { if (gettime) { hrtimer_get_softirq_time(cpu_base); gettime = 0; @@ -1665,6 +1680,8 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, static void migrate_hrtimers(int scpu) { struct hrtimer_cpu_base *old_base, *new_base; + struct hrtimer_clock_base *clock_base; + unsigned int active_bases; int i; BUG_ON(cpu_online(scpu)); @@ -1680,9 +1697,9 @@ static void migrate_hrtimers(int scpu) raw_spin_lock(&new_base->lock); raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); - for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { - migrate_hrtimer_list(&old_base->clock_base[i], - &new_base->clock_base[i]); + for_each_active_base(i, clock_base, old_base, active_bases) { + migrate_hrtimer_list(clock_base, + &new_base->clock_base[clock_base->index]); } raw_spin_unlock(&old_base->lock);