From patchwork Mon Mar 14 05:22:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Turquette X-Patchwork-Id: 63789 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2287454lbc; Sun, 13 Mar 2016 22:26:59 -0700 (PDT) X-Received: by 10.66.66.198 with SMTP id h6mr34542371pat.112.1457933212270; Sun, 13 Mar 2016 22:26:52 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si7266643pfi.253.2016.03.13.22.26.51; Sun, 13 Mar 2016 22:26:52 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933575AbcCNF0l (ORCPT + 30 others); Mon, 14 Mar 2016 01:26:41 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:32908 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933479AbcCNF03 (ORCPT ); Mon, 14 Mar 2016 01:26:29 -0400 Received: by mail-pf0-f175.google.com with SMTP id 124so128814956pfg.0 for ; Sun, 13 Mar 2016 22:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DQDXdRxBUm3p6eN5mSnIyicw8e44ODVMIcz33wa1TNw=; b=Ylq6SaItanQLzLb7B7aDGPbTshq1UM/jo47MTHlcfpyJp1f+10NDr2MoTdUjykG/NC jzXDTW0oQr0h8SQ+ugfEEmfQtsqSdr/yfjz0SyPfEIJ2nry238cfUJ9TGUyOMO9aAbd1 WksamIQrUbomp7LYjWZ14J4SGkLphUD8FQU5XNDL9lk5/nHirQz6p0G4p7kTlPjlBnCf 3GXIUbr/16qrk6l87bVcl/RF9vBNfcFEZmxNIj/9zaoIyOTk5hqSBW90Gr+UG2GT+k3I JwTvFR9TdYVos1qYoXVW3SVNfts81qnecpIu7NSRcd4PblrZ3Rf3Yvr6Gaprqj3QJp69 1GnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DQDXdRxBUm3p6eN5mSnIyicw8e44ODVMIcz33wa1TNw=; b=VLx/zUvhjW8pT0F1PIW9MBWSZ4PsIjkQLl0pMUxZa7IKp+dM2UfyPt+p1XB08Yn93Q VjlyWYTIY8MEf21xrkC4XO2g/L8WW5fFy9t1pFzZOILP/zNNY5rW9/o2m+vmSKtQoSEI 6pGXQqUFwC3syTYI94x0UL5zQVsze3wk85kHLP731S0UX1F2Khq1xUEo8KLb86c0EIdR ljQ2/unQI3UPXPEVRhYXkJy2jvrCakftqYRI18TxXupWtJcIam0FkoLQubgQjZbzbzxT Rf8muV9UKdRR/FfDZ/8GYQjCT4I8tbQ4/lb/+cOYlLWlUYBQHVFR9edkSoVmpC+6L8Oj YnEw== X-Gm-Message-State: AD7BkJJ+mC3B/E9mYeP7sbc3iU2vt9Cm4RSZqD/3AUjSSchklbI2qou4CEpi2KSyP9l1QEJj X-Received: by 10.98.32.211 with SMTP id m80mr24886942pfj.3.1457933188236; Sun, 13 Mar 2016 22:26:28 -0700 (PDT) Received: from localhost (cpe-172-248-200-249.socal.res.rr.com. [172.248.200.249]) by smtp.gmail.com with ESMTPSA id ey7sm28622598pab.47.2016.03.13.22.26.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Mar 2016 22:26:27 -0700 (PDT) From: Michael Turquette X-Google-Original-From: Michael Turquette To: peterz@infradead.org, rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Juri.Lelli@arm.com, steve.muckle@linaro.org, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, vincent.guittot@linaro.org, Michael Turquette Subject: [PATCH 7/8] cpufreq: Frequency invariant scheduler load-tracking support Date: Sun, 13 Mar 2016 22:22:11 -0700 Message-Id: <1457932932-28444-8-git-send-email-mturquette+renesas@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457932932-28444-1-git-send-email-mturquette+renesas@baylibre.com> References: <1457932932-28444-1-git-send-email-mturquette+renesas@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dietmar Eggemann Implements cpufreq_scale_freq_capacity() to provide the scheduler with a frequency scaling correction factor for more accurate load-tracking. The factor is: current_freq(cpu) << SCHED_CAPACITY_SHIFT / max_freq(cpu) In fact, freq_scale should be a struct cpufreq_policy data member. But this would require that the scheduler hot path (__update_load_avg()) would have to grab the cpufreq lock. This can be avoided by using per-cpu data initialized to SCHED_CAPACITY_SCALE for freq_scale. Signed-off-by: Dietmar Eggemann Signed-off-by: Michael Turquette --- I'm not as sure about patches 7 & 8, but I included them since I needed frequency invariance while testing. As mentioned by myself in 2014 and Rafael last month, the arch_scale_freq_capacity hook is awkward, because this behavior may vary within an architecture. I re-introduce Dietmar's generic cpufreq implementation of the frequency invariance hook in this patch, and change the preprocessor magic in sched.h to favor the cpufreq implementation over arch- or platform-specific ones in the next patch. If run-time selection of ops is needed them someone will need to write that code. I think that this negates the need for the arm arch hooks[0-2], and hopefully Morten and Dietmar can weigh in on this. [0] lkml.kernel.org/r/1436293469-25707-2-git-send-email-morten.rasmussen@arm.com [1] lkml.kernel.org/r/1436293469-25707-6-git-send-email-morten.rasmussen@arm.com [2] lkml.kernel.org/r/1436293469-25707-8-git-send-email-morten.rasmussen@arm.com drivers/cpufreq/cpufreq.c | 29 +++++++++++++++++++++++++++++ include/linux/cpufreq.h | 3 +++ 2 files changed, 32 insertions(+) -- 2.1.4 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b1ca9c4..e67584f 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -306,6 +306,31 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) #endif } +/********************************************************************* + * FREQUENCY INVARIANT CPU CAPACITY * + *********************************************************************/ + +static DEFINE_PER_CPU(unsigned long, freq_scale) = SCHED_CAPACITY_SCALE; + +static void +scale_freq_capacity(struct cpufreq_policy *policy, struct cpufreq_freqs *freqs) +{ + unsigned long cur = freqs ? freqs->new : policy->cur; + unsigned long scale = (cur << SCHED_CAPACITY_SHIFT) / policy->max; + int cpu; + + pr_debug("cpus %*pbl cur/cur max freq %lu/%u kHz freq scale %lu\n", + cpumask_pr_args(policy->cpus), cur, policy->max, scale); + + for_each_cpu(cpu, policy->cpus) + per_cpu(freq_scale, cpu) = scale; +} + +unsigned long cpufreq_scale_freq_capacity(struct sched_domain *sd, int cpu) +{ + return per_cpu(freq_scale, cpu); +} + static void __cpufreq_notify_transition(struct cpufreq_policy *policy, struct cpufreq_freqs *freqs, unsigned int state) { @@ -409,6 +434,8 @@ wait: spin_unlock(&policy->transition_lock); + scale_freq_capacity(policy, freqs); + cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE); } EXPORT_SYMBOL_GPL(cpufreq_freq_transition_begin); @@ -2125,6 +2152,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_NOTIFY, new_policy); + scale_freq_capacity(new_policy, NULL); + policy->min = new_policy->min; policy->max = new_policy->max; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 0e39499..72833be 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -583,4 +583,7 @@ unsigned int cpufreq_generic_get(unsigned int cpu); int cpufreq_generic_init(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table, unsigned int transition_latency); + +struct sched_domain; +unsigned long cpufreq_scale_freq_capacity(struct sched_domain *sd, int cpu); #endif /* _LINUX_CPUFREQ_H */