From patchwork Thu Mar 9 04:04:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95058 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp184193qgd; Wed, 8 Mar 2017 20:05:05 -0800 (PST) X-Received: by 10.99.168.76 with SMTP id i12mr11056590pgp.73.1489032305514; Wed, 08 Mar 2017 20:05:05 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si5176006pgg.234.2017.03.08.20.05.05; Wed, 08 Mar 2017 20:05:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750781AbdCIEFD (ORCPT + 13 others); Wed, 8 Mar 2017 23:05:03 -0500 Received: from mail-pg0-f47.google.com ([74.125.83.47]:32916 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750747AbdCIEFC (ORCPT ); Wed, 8 Mar 2017 23:05:02 -0500 Received: by mail-pg0-f47.google.com with SMTP id 25so21231655pgy.0 for ; Wed, 08 Mar 2017 20:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=zoIHPyUxCLHwY/OP9+wWM86QBjv57cGQu+O6kUbOEIc=; b=DzKD0+71GoHqUgXCVP16t1+BNlGMcfAGbNgWvK14tRaKqw62JPJr5eju1J2tXP3cXE IKkn3v2xmEAac6QGUyM6VRCn8l5uzXsgYcvLo/WrkESlNmXyaL+/hGWNxDrm7WUc4NHS swM8p57OHwJUyyBDS7OJbfl+e8yjJYO/mKOJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zoIHPyUxCLHwY/OP9+wWM86QBjv57cGQu+O6kUbOEIc=; b=kUpHEboGkdRSSrB8gLs6x6eiBqRafZOybR1+kk1w1dunsgjTpr3Ke49qlGUx8i59c2 hYvuSVyWt2m0k+u5qFN/R6BHrRfIsV4OkETIZ7WNaZ2jser4XuU+VrG1Qz2uKLt6dH2E +GF/6xDXcRRC3A5PrgjRNckPLdEUu9wDHrT6oYOnrNuIvv9Gi8TvF/Bmj7wPu6co4wQt nkVL/nbRUKUjwtpU87LGv9LpxIaSoP7kosGwi5AgNJ8iCaboRtqOJIk4c/OYvP9YS/t+ wte+NTVrWSWkc51m94u/ZDREYrkZcp3TGbL17nwI1BghB1SLQhtvfl5XROkdBa1H1tot Qq5w== X-Gm-Message-State: AMke39kpKEyS6aeUUJHNEVL0wqsty0oULKED+7/WHsGwEuh24QZO189acFt4pdLPEaN5+qna X-Received: by 10.84.237.22 with SMTP id s22mr13911404plk.145.1489032300229; Wed, 08 Mar 2017 20:05:00 -0800 (PST) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id q194sm8831200pfq.43.2017.03.08.20.04.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 20:04:58 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Ingo Molnar , Peter Zijlstra Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH V2] cpufreq: schedutil: refactor sugov_next_freq_shared() Date: Thu, 9 Mar 2017 09:34:54 +0530 Message-Id: <8ae8af9aea79c8ee58c1dffd90881b3a7039c179.1489032147.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The loop in sugov_next_freq_shared() contains an if block to skip the loop for the current CPU. This turns out to be an unnecessary conditional in the scheduler's hot-path for every CPU in the policy. It would be better to drop the conditional and make the loop treat all the CPUs in the same way. That would eliminate the need of calling sugov_iowait_boost() at the top of the routine. To keep the code optimized to return early if the current CPU has RT/DL flags set, move the flags check to sugov_update_shared() instead in order to avoid the function call entirely. Signed-off-by: Viresh Kumar --- V1->V2: - Keep the flags check separately for the current CPU, but move it to the parent routine. - Improved commit log. kernel/sched/cpufreq_schedutil.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 78468aa051ab..f5ffe241812e 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -217,30 +217,19 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, sugov_update_commit(sg_policy, time, next_f); } -static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, - unsigned long util, unsigned long max, - unsigned int flags) +static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu) { struct sugov_policy *sg_policy = sg_cpu->sg_policy; struct cpufreq_policy *policy = sg_policy->policy; - unsigned int max_f = policy->cpuinfo.max_freq; u64 last_freq_update_time = sg_policy->last_freq_update_time; + unsigned long util = 0, max = 1; unsigned int j; - if (flags & SCHED_CPUFREQ_RT_DL) - return max_f; - - sugov_iowait_boost(sg_cpu, &util, &max); - for_each_cpu(j, policy->cpus) { - struct sugov_cpu *j_sg_cpu; + struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j); unsigned long j_util, j_max; s64 delta_ns; - if (j == smp_processor_id()) - continue; - - j_sg_cpu = &per_cpu(sugov_cpu, j); /* * If the CPU utilization was last updated before the previous * frequency update and the time elapsed between the last update @@ -254,7 +243,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, continue; } if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL) - return max_f; + return policy->cpuinfo.max_freq; j_util = j_sg_cpu->util; j_max = j_sg_cpu->max; @@ -289,7 +278,11 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sg_cpu->last_update = time; if (sugov_should_update_freq(sg_policy, time)) { - next_f = sugov_next_freq_shared(sg_cpu, util, max, flags); + if (flags & SCHED_CPUFREQ_RT_DL) + next_f = sg_policy->policy->cpuinfo.max_freq; + else + next_f = sugov_next_freq_shared(sg_cpu); + sugov_update_commit(sg_policy, time, next_f); }