From patchwork Tue Mar 18 10:56:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 26480 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4141C203C3 for ; Tue, 18 Mar 2014 10:56:25 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id cz12sf16781847veb.10 for ; Tue, 18 Mar 2014 03:56:25 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Cs/K4HdQkbnahjm5kgs7hpSzFVa+6lCyF22To3zHEEI=; b=EEQJ88uYZeFxUJgG6//seG6fsLIHyPqOrxsYo5U26BVS7hoYnZVn+XgdG3d58uV6aQ fg2puh3msfFDLq6m1cWvS3R9ts8Nntkn6+bXld8DJK8NbQbxiDOXnsT1EGqwZ+38Rmu4 XHawRT4i5Id5qUrHef1DjQdUVN1dsvF4429gGERsHfViNd1v3Tt2aASHcvRlfNmunakL GRTsiQVQyTbrr1G7iqAUj02lqW8iPAuYfKtBexAL0R4mpDIhUeqD7vcYHQWTfqwAFGX9 kbtKTxi/LvwIAfWnd+G3FbmXl4gdwD7/ZfpOpMQaKGb8CPva8aPjGgXPAetjWKlOepR+ b39w== X-Gm-Message-State: ALoCoQnukWHoPWY2arDUWo9gTE0aWgkRPhZwhgFLuxMcSJqhyo4W7YbGA9kYKH1IjZg5ba7+uUqJ X-Received: by 10.58.22.166 with SMTP id e6mr1946193vef.6.1395140185034; Tue, 18 Mar 2014 03:56:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.198 with SMTP id h64ls773687qgf.84.gmail; Tue, 18 Mar 2014 03:56:24 -0700 (PDT) X-Received: by 10.52.34.4 with SMTP id v4mr1036556vdi.42.1395140184955; Tue, 18 Mar 2014 03:56:24 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sq9si2532803vdc.161.2014.03.18.03.56.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Mar 2014 03:56:24 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so7062550vcb.15 for ; Tue, 18 Mar 2014 03:56:24 -0700 (PDT) X-Received: by 10.52.161.130 with SMTP id xs2mr367279vdb.49.1395140184834; Tue, 18 Mar 2014 03:56:24 -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.220.78.9 with SMTP id i9csp195437vck; Tue, 18 Mar 2014 03:56:24 -0700 (PDT) X-Received: by 10.66.66.135 with SMTP id f7mr32084437pat.22.1395140183655; Tue, 18 Mar 2014 03:56:23 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3si9860800pbo.92.2014.03.18.03.56.22; Tue, 18 Mar 2014 03:56:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755091AbaCRK4Q (ORCPT + 26 others); Tue, 18 Mar 2014 06:56:16 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:32782 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754587AbaCRK4O (ORCPT ); Tue, 18 Mar 2014 06:56:14 -0400 Received: by mail-wg0-f48.google.com with SMTP id l18so5797298wgh.19 for ; Tue, 18 Mar 2014 03:56:13 -0700 (PDT) X-Received: by 10.194.85.168 with SMTP id i8mr932899wjz.81.1395140173401; Tue, 18 Mar 2014 03:56:13 -0700 (PDT) Received: from localhost ([213.122.173.131]) by mx.google.com with ESMTPSA id q15sm46206412wjw.18.2014.03.18.03.56.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 18 Mar 2014 03:56:12 -0700 (PDT) From: Viresh Kumar To: tglx@linutronix.de Cc: linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, fweisbec@gmail.com, peterz@infradead.org, mingo@kernel.org, Viresh Kumar Subject: [PATCH] timer: remove code redundancy while calling get_nohz_timer_target() Date: Tue, 18 Mar 2014 16:26:07 +0530 Message-Id: <1e1b53537217d58d48c2d7a222a9c3ac47d5b64c.1395140107.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e 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=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , There are only two users of get_nohz_timer_target(): timer and hrtimer. Both call it under same circumstances, i.e. #ifdef CONFIG_NO_HZ_COMMON if (!pinned && get_sysctl_timer_migration() && idle_cpu(this_cpu)) return get_nohz_timer_target(); #endif So, it makes more sense to get all this as part of get_nohz_timer_target() instead of duplicating code at two places. For this another parameter is required to be passed to this routine, pinned. Signed-off-by: Viresh Kumar --- include/linux/sched.h | 6 +++++- kernel/hrtimer.c | 15 +-------------- kernel/sched/core.c | 5 ++++- kernel/timer.c | 7 +------ 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 6dbb9e5..9819f93 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -299,10 +299,14 @@ extern int runqueue_is_locked(int cpu); #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) extern void nohz_balance_enter_idle(int cpu); extern void set_cpu_sd_state_idle(void); -extern int get_nohz_timer_target(void); +extern int get_nohz_timer_target(int pinned); #else static inline void nohz_balance_enter_idle(int cpu) { } static inline void set_cpu_sd_state_idle(void) { } +static inline int get_nohz_timer_target(int pinned) +{ + return smp_processor_id(); +} #endif /* diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index f60dce8..7eef615 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c @@ -168,19 +168,6 @@ struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer, } } - -/* - * Get the preferred target CPU for NOHZ - */ -static int hrtimer_get_target(int this_cpu, int pinned) -{ -#ifdef CONFIG_NO_HZ_COMMON - if (!pinned && get_sysctl_timer_migration() && idle_cpu(this_cpu)) - return get_nohz_timer_target(); -#endif - return this_cpu; -} - /* * With HIGHRES=y we do not migrate the timer when it is expiring * before the next event on the target cpu because we cannot reprogram @@ -214,7 +201,7 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base, struct hrtimer_clock_base *new_base; struct hrtimer_cpu_base *new_cpu_base; int this_cpu = smp_processor_id(); - int cpu = hrtimer_get_target(this_cpu, pinned); + int cpu = get_nohz_timer_target(pinned); int basenum = base->index; again: diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6fde755..a58e24d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -556,12 +556,15 @@ void resched_cpu(int cpu) * selecting an idle cpu will add more delays to the timers than intended * (as that cpu's timer base may not be uptodate wrt jiffies etc). */ -int get_nohz_timer_target(void) +int get_nohz_timer_target(int pinned) { int cpu = smp_processor_id(); int i; struct sched_domain *sd; + if (pinned || !get_sysctl_timer_migration() || !idle_cpu(cpu)) + return cpu; + rcu_read_lock(); for_each_domain(cpu, sd) { for_each_cpu(i, sched_domain_span(sd)) { diff --git a/kernel/timer.c b/kernel/timer.c index e6868bf..2cf8616 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -760,12 +760,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, debug_activate(timer, expires); - cpu = smp_processor_id(); - -#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP) - if (!pinned && get_sysctl_timer_migration() && idle_cpu(cpu)) - cpu = get_nohz_timer_target(); -#endif + cpu = get_nohz_timer_target(pinned); new_base = per_cpu(tvec_bases, cpu); if (base != new_base) {