Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6912270imm; Tue, 24 Jul 2018 05:26:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeJKMbrQNDJgQ+ENYKnta/xiU6l73GPsysBAHtx3QRBgM2B1G4H03dfTA4YQJSUFbYcEKgw X-Received: by 2002:a63:8f53:: with SMTP id r19-v6mr15891315pgn.17.1532435213358; Tue, 24 Jul 2018 05:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532435213; cv=none; d=google.com; s=arc-20160816; b=sXYecdbqS95Q1H/TZumM6wQfLtdcxJ8+Pug581wofhGlBjkMJJtXTMQMyiVNwi86+D meDakioFhagf1tjV5EniHt2e27Lzp9DHUStgCCJ+9dMLk0oS5qNdzEc1S2aAkR0YSJ6t VlXnFtqGcNvNbF+aAnrQwwl9Lbuh0DHvi6B1b+geZH0NNM/olf0bQKatX3siT5JWLtK8 sZQNCV8SJXEM1IRNtHyzl5GGkENerkSmWBk+5HdDJkMpAUTBiA+GiFG/eY6TlW7ZF2YU G/Wb0iZLMQjE3i60v3WdRq5B837lHw89a2CmHfIU35gZ20CelUQYEByfLjGXv+hwhPo2 ZxKQ== 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=XeBCqOl5ezO9wJ3Dho4b27LHww5uLNDNMG0U4Ha0aZE=; b=QgionM6z229IyIkUVbgUt83dC09nSfv5DescE1hq74o+ABmhgpc/NXr7PnXrqF95an b5NP13zZjXLp/E9rQcHNIc6jjH3NzD9nMpjxuM6kPUL3x33dM65Kb/bRbt3mQpUxAYkz dF1FDB8qTXAp1g/tzzj3W7KRMusJa6Aykjc5lCRfagkIIk45oxi5UBHswNqU0YlCvzN7 L1IDaKiPEzmpRYlaCnTTmaZ78rX4DThkh8Gqk3VOZWiQTSwiYjpzYIDKFneSCl6dN9I6 HE+zlJMetqhd3DCAy9rcxFL5MFDgzcjfbTQcGsmyyFe+aO/A49sm1yxqhfyYCUqo/kaH cNFg== 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 s23-v6si11537240pga.563.2018.07.24.05.26.38; Tue, 24 Jul 2018 05:26:53 -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 S2388403AbeGXNb4 (ORCPT + 99 others); Tue, 24 Jul 2018 09:31:56 -0400 Received: from foss.arm.com ([217.140.101.70]:49894 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXNb4 (ORCPT ); Tue, 24 Jul 2018 09:31:56 -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 9ECDF15AB; Tue, 24 Jul 2018 05:25:41 -0700 (PDT) Received: from e108498-lin.Emea.Arm.com (e108498-lin.emea.arm.com [10.4.13.130]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 857253F6A8; Tue, 24 Jul 2018 05:25: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@quicinc.com, skannan@quicinc.com, 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 v5 02/14] sched/cpufreq: Factor out utilization to frequency mapping Date: Tue, 24 Jul 2018 13:25:09 +0100 Message-Id: <20180724122521.22109-3-quentin.perret@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724122521.22109-1-quentin.perret@arm.com> References: <20180724122521.22109-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 97dcd4472a0e..810193c8e4cd 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.18.0