Re: [PATCH 3/4] PM / devfreq: Add cpu based scaling support to passive governor
From: Matthias Kaehlcke <mka@chromium.org>
Date: 2021-06-22 18:36:45
Also in:
lkml
On Thu, Jun 17, 2021 at 03:05:45PM +0900, Chanwoo Choi wrote:
quoted hunk ↗ jump to hunk
From: Saravana Kannan <redacted> Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure that the cache is not a performance bottleneck that leads to poor performance and power. The same idea applies for RAM/DDR. To achieve this, this patch adds support for cpu based scaling to the passive governor. This is accomplished by taking the current frequency of each CPU frequency domain and then adjust the frequency of the cache (or any devfreq device) based on the frequency of the CPUs. It listens to CPU frequency transition notifiers to keep itself up to date on the current CPU frequency. To decide the frequency of the device, the governor does one of the following: * Derives the optimal devfreq device opp from required-opps property of the parent cpu opp_table. * Scales the device frequency in proportion to the CPU frequency. So, if the CPUs are running at their max frequency, the device runs at its max frequency. If the CPUs are running at their min frequency, the device runs at its min frequency. It is interpolated for frequencies in between. Signed-off-by: Saravana Kannan <redacted> [Sibi: Integrated cpu-freqmap governor into passive_governor] Signed-off-by: Sibi Sankar <redacted> [Chanwoo: Fix conflict with latest code and clean code up] Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> --- drivers/devfreq/governor.h | 22 +++ drivers/devfreq/governor_passive.c | 264 ++++++++++++++++++++++++++++- include/linux/devfreq.h | 16 +- 3 files changed, 293 insertions(+), 9 deletions(-)diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h index 9a9495f94ac6..3c36c92c89a9 100644 --- a/drivers/devfreq/governor.h +++ b/drivers/devfreq/governor.h@@ -47,6 +47,28 @@ #define DEVFREQ_GOV_ATTR_POLLING_INTERVAL BIT(0) #define DEVFREQ_GOV_ATTR_TIMER BIT(1) +/** + * struct devfreq_cpu_data - Hold the per-cpu data + * @dev: reference to cpu device. + * @first_cpu: the cpumask of the first cpu of a policy. + * @opp_table: reference to cpu opp table. + * @cur_freq: the current frequency of the cpu. + * @min_freq: the min frequency of the cpu. + * @max_freq: the max frequency of the cpu. + * + * This structure stores the required cpu_data of a cpu. + * This is auto-populated by the governor. + */ +struct devfreq_cpu_data { + struct device *dev; + unsigned int first_cpu; + + struct opp_table *opp_table; + unsigned int cur_freq; + unsigned int min_freq; + unsigned int max_freq; +}; + /** * struct devfreq_governor - Devfreq policy governor * @node: list node - contains registered devfreq governorsdiff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index fc09324a03e0..07e864509b7e 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c@@ -8,11 +8,84 @@ */ #include <linux/module.h> +#include <linux/cpu.h> +#include <linux/cpufreq.h> +#include <linux/cpumask.h> +#include <linux/slab.h> #include <linux/device.h> #include <linux/devfreq.h> #include "governor.h" -static int devfreq_passive_get_target_freq(struct devfreq *devfreq, +#define HZ_PER_KHZ 1000 + +static unsigned long get_taget_freq_by_required_opp(struct device *p_dev, + struct opp_table *p_opp_table, + struct opp_table *opp_table, + unsigned long freq) +{
s/get_taget_freq_by_required_opp/get_target_freq_by_required_opp/