Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3671599imm; Mon, 20 Aug 2018 02:46:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzRRpMuA4hdLBUy3WQJUryklS7eXxhArmgG/x57tWpqndDi9ygK5yUtfp4CvWG1GkyFSZb4 X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr45031698plo.61.1534758368765; Mon, 20 Aug 2018 02:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534758368; cv=none; d=google.com; s=arc-20160816; b=T+tzNNbV+uB1VGG8p9UQHaAtJ+kVB8dLJ9AgZWcOZsBO2AdgTUTRpqnD/vbc/aHF+z VCkxO2IV4kU8IKbTb4ZNNoLF5xJ8a/vLu1jOyF4SWI8/HyKsnKqHgJA6UMVapgjPMlFh dTJ5dGEVDWcVbz9eFkqcgmsJvETjroFU6Oj49Nx0+Rr0x4C4UARmNGZXb5/3B0Dp6H/7 QOWQ5agq0FI9PdwMKq+1HkBprgZrXSsHYB6PHt0lXbDiHL/UbvL3gLMrId0WYkdplExB mq1E6DU8PluCvUFQUu0j5hxL4OSUbnuq/79Q3mH/GkpIkQ05d+4j8Whmx8vPL8DbHRnp RF5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EbBrqZYAE3xC7R3h9+2wBBrgK+pDS7OJ6zIW1fW9XaA=; b=maNW6/lhU+dU7PwRCzYE77x+DF20a9INi5A2PCslRFF3tQ1vQ4mahbmPD/EITDhyHP RixXhx3QhM/ZYdN2vWFAMN1dWOyo8DTRml5mS63pnf1AKmqYVDKDIcA04s6e8CiAwn0a eFy49u8e63AU0EwLzgtsqmtO+p5VfraI3T2GdbxXMgPzmJ67potfMZfJwdJ7PUHwEuqA zavCRabryJlC3QnwlmOwsgdzYuUhUmJFguFrq15sQBJoKYO7Zqb70Jcj1dCHA+d9YiZ1 4Tkw/Ep1joFB2rpPD/5uTBnJGB9OoBZdfAWYnslxEfhejSJ2O7ONEDinC9nNMB+lngoF G5sQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si9580121pls.237.2018.08.20.02.45.53; Mon, 20 Aug 2018 02:46:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbeHTM7g (ORCPT + 99 others); Mon, 20 Aug 2018 08:59:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34844 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeHTM7g (ORCPT ); Mon, 20 Aug 2018 08:59:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0C6E215BE; Mon, 20 Aug 2018 02:44:42 -0700 (PDT) Received: from queper01-lin.local (queper01-lin.emea.arm.com [10.4.13.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E96D43F2EA; Mon, 20 Aug 2018 02:44:37 -0700 (PDT) From: Quentin Perret To: peterz@infradead.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: gregkh@linuxfoundation.org, mingo@redhat.com, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, patrick.bellasi@arm.com, valentin.schneider@arm.com, vincent.guittot@linaro.org, thara.gopinath@linaro.org, viresh.kumar@linaro.org, tkjos@google.com, joel@joelfernandes.org, smuckle@google.com, adharmap@codeaurora.org, skannan@codeaurora.org, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org, quentin.perret@arm.com Subject: [PATCH v6 02/14] sched/cpufreq: Factor out utilization to frequency mapping Date: Mon, 20 Aug 2018 10:44:08 +0100 Message-Id: <20180820094420.26590-3-quentin.perret@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180820094420.26590-1-quentin.perret@arm.com> References: <20180820094420.26590-1-quentin.perret@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The schedutil governor maps utilization values to frequencies by applying a 25% margin. Since this sort of mapping mechanism can be needed by other users (i.e. EAS), factor the utilization-to-frequency mapping code out of schedutil and move it to include/linux/sched/cpufreq.h to avoid code duplication. The new map_util_freq() function is inlined to avoid overheads. Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: Quentin Perret --- include/linux/sched/cpufreq.h | 6 ++++++ kernel/sched/cpufreq_schedutil.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index 59667444669f..afa940cd50dc 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -20,6 +20,12 @@ void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, void (*func)(struct update_util_data *data, u64 time, unsigned int flags)); void cpufreq_remove_update_util_hook(int cpu); + +static inline unsigned long map_util_freq(unsigned long util, + unsigned long freq, unsigned long cap) +{ + return (freq + (freq >> 2)) * util / cap; +} #endif /* CONFIG_CPU_FREQ */ #endif /* _LINUX_SCHED_CPUFREQ_H */ diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 3fffad3bc8a8..f5206c950143 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -13,6 +13,7 @@ #include "sched.h" +#include #include struct sugov_tunables { @@ -167,7 +168,7 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned int freq = arch_scale_freq_invariant() ? policy->cpuinfo.max_freq : policy->cur; - freq = (freq + (freq >> 2)) * util / max; + freq = map_util_freq(util, freq, max); if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) return sg_policy->next_freq; -- 2.17.1