Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp377350imm; Mon, 21 May 2018 07:28:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpSsilbiIVsjSMpoJmr0MiOGdAbyEiMEgP15ZXEkt0oG/f19L9l3A8OY7khhAIzW8d/9Wa0 X-Received: by 2002:a62:48d1:: with SMTP id q78-v6mr20448114pfi.70.1526912926199; Mon, 21 May 2018 07:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526912926; cv=none; d=google.com; s=arc-20160816; b=pX9J7bOu9XYxyinvIuGh4ko6TZnwxnnLUK6uRljYpYc4vvfMhobq7D2/FrvGXkhDfu w4unV+O7ENi4jUVzatMZjbSjvJU9evA02QFfkAB3656rIlF75w3yWV2VPdjCI7/Jvf72 csb+Dklc8/xBJ0wtUOwsTFleZ9fwlsqT6n6ckbVT2OFMUGZNntL9OwUQEYKN9fR94CpC TxKTErD6PU027Lov2bSnqX/ROQo7fE7eqbuuBQJXTXhYfaN4/NBi6VIFDJIbBovvU1Cy 67Esub+DKGdIwUZVFl9zPZzWeHv5ksCDLOyYWCbcgK7RXba6CFU/ZBz9CNDurjDZyBif ZuHg== 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=vWjYx94qMNh5oIjo/wc3KXpv3pUyo0hpuEh96fpLLzU=; b=Qk6fbAXVUbpNtuleuhGSJB9i0FiUiH/OQVL83NPgDu3r5pgDX6lOvTvCvQXdl3HZR8 QAq2VIfv7LbMtozJPaZNBCQFjF/z169YK8dElTeLOaADm2lGv41AA4yXJ+N58qY09U4P JwQLIRkHz+mO4RenhfJJGRGuv3db8pTciPtgeKujhWR3Viuig3suD7wNisRgg9rxQi0a OE2HlYVEagrIoGXj2S07hAdjNaBftzua0yBIeKgWa3smjLR0csflaKHe0J9oIqDTiMo7 1PLgM5NT378IlSihsYrfU9WzhuaPUioKdha5V8F9EmINsD021aq8tXNtRccOg5/F7UAA wZfQ== 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 a66-v6si14991904pfb.81.2018.05.21.07.28.31; Mon, 21 May 2018 07:28:46 -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 S1753126AbeEUO1q (ORCPT + 99 others); Mon, 21 May 2018 10:27:46 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50918 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbeEUOZb (ORCPT ); Mon, 21 May 2018 10:25:31 -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 46497165C; Mon, 21 May 2018 07:25:31 -0700 (PDT) Received: from e108498-lin.cambridge.arm.com (e108498-lin.cambridge.arm.com [10.1.210.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2FA733F577; Mon, 21 May 2018 07:25:27 -0700 (PDT) From: Quentin Perret To: peterz@infradead.org, rjw@rjwysocki.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: 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, joelaf@google.com, 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: [RFC PATCH v3 02/10] sched/cpufreq: Factor out utilization to frequency mapping Date: Mon, 21 May 2018 15:24:57 +0100 Message-Id: <20180521142505.6522-3-quentin.perret@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521142505.6522-1-quentin.perret@arm.com> References: <20180521142505.6522-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 63014cff76a5..4fdc6eb7c88b 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 { @@ -163,7 +164,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->next_freq != UINT_MAX) return sg_policy->next_freq; -- 2.17.0