Skip to contentSkip to conversation

PM / devfreq: Generic cpufreq governor

PATCH In review Saravana Kannan 3 participants 9 messages Jul 28, 2018 – Aug 1, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: Generic cpufreq governor

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically used for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP systems with heterogeneous CPUs with different OPPs)

OR

* 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. And interpolated for frequencies in between.

---
 .../bindings/devfreq/devfreq-cpufreq.txt           |  53 ++
 drivers/devfreq/Kconfig                            |   8 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/governor_cpufreq.c                 | 583 +++++++++++++++++++++
 4 files changed, 645 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq.txt
 create mode 100644 drivers/devfreq/governor_cpufreq.c
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq.txt new file +53 -0
new file mode 100644
index 0000000..6537538
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq is a parent device that contains one or more child devices.
+Each child device provides CPU frequency to device frequency mapping for a
+specific device. Examples of devices that could use this are: DDR, cache and
+CCI.
+
+Parent device name shall be "devfreq-cpufreq".
+
+Required child device properties:
+- cpu-to-dev-map, or cpu-to-dev-map-<X>:
+			A list of tuples where each tuple consists of a
+			CPU frequency (KHz) and the corresponding device
+			frequency. CPU frequencies not listed in the table
+			will use the device frequency that corresponds to the
+			next rounded up CPU frequency.
+			Use "cpu-to-dev-map" if all CPUs in the system should
+			share same mapping.
+			Use cpu-to-dev-map-<cpuid> to describe different
+			mappings for different CPUs. The property should be
+			listed only for the first CPU if multiple CPUs are
+			synchronous.
+- target-dev:		Phandle to device that this mapping applies to.
+
+Example:
+	devfreq-cpufreq {
+		cpubw-cpufreq {
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144 >,
+				<  422400  2288 >,
+				<  652800  3051 >,
+				<  883200  5996 >,
+				< 1190400  8056 >,
+				< 1497600 10101 >,
+				< 1728000 12145 >,
+				< 2649600 16250 >;
+		};
+
+		cache-cpufreq {
+			target-dev = <&cache>;
+			cpu-to-dev-map =
+				<  300000  300000 >,
+				<  422400  422400 >,
+				<  652800  499200 >,
+				<  883200  576000 >,
+				<  960000  960000 >,
+				< 1497600 1036800 >,
+				< 1574400 1574400 >,
+				< 1728000 1651200 >,
+				< 2649600 1728000 >;
+		};
+	};
drivers/devfreq/Kconfig +8 -0
index 8503018..5eeb33f 100644
@@ -73,6 +73,14 @@ config DEVFREQ_GOV_PASSIVE
 	  through sysfs entries. The passive governor recommends that
 	  devfreq device uses the OPP table to get the frequency/voltage.
 
+config DEVFREQ_GOV_CPUFREQ
+	tristate "CPUfreq"
+	depends on CPU_FREQ
+	help
+	  Chooses frequency based on the online CPUs' current frequency and a
+	  CPU frequency to device frequency mapping table(s). This governor
+	  can be useful for controlling devices such as DDR, cache, CCI, etc.
+
 comment "DEVFREQ Drivers"
 
 config ARM_EXYNOS_BUS_DEVFREQ
drivers/devfreq/Makefile +1 -0
index f1cc8990..cafe7c2 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE)	+= governor_performance.o
 obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE)	+= governor_powersave.o
 obj-$(CONFIG_DEVFREQ_GOV_USERSPACE)	+= governor_userspace.o
 obj-$(CONFIG_DEVFREQ_GOV_PASSIVE)	+= governor_passive.o
+obj-$(CONFIG_DEVFREQ_GOV_CPUFREQ)	+= governor_cpufreq.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
drivers/devfreq/governor_cpufreq.c new file +583 -0

583 lines not on this page · raw message

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 19 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically used for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP systems with heterogeneous CPUs with different OPPs)

Quoted 6 lines

OR

* 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. And interpolated for frequencies in between.

While not having looked at the details of the patch yet, I would change the name of the feature to "Generic cpufreq transition governor" to make it somewhat less ambiguous.

#2 lore raw
Quoted 33 lines · Rafael J. Wysocki
Quoted 24 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically
used
for system with homogeneous cores/clusters that have the same
OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

OR

Quoted 7 lines

* 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. And interpolated for frequencies in
between.

Quoted 3 lines

While not having looked at the details of the patch yet, I would change the name of the feature to "Generic cpufreq transition governor" to make it somewhat less ambiguous.

In my opinion it makes it look MORE like this is a cpufreq governor. How about the following? PM / devfreq: Generic cpufreq to devfreq mapping governor
Seem a lot more clear to me.

I'm open to suggestions for the devfreq governor name too. "cpufreq" has been very confusing so far. cpufreq-map maybe?

Thanks,
Saravana

#3 lore raw
Quoted 44 lines · On Mon, Jul 30, 2018 at 8:58 PM, <[email protected]> wrote:
Quoted 38 lines · Rafael J. Wysocki
Quoted 27 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs.
Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen
to the frequency transitions of each CPU frequency domain and then adjusts
the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically
used
for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

Quoted 6 lines

OR

* 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. And interpolated for frequencies in between.

Quoted 3 lines

While not having looked at the details of the patch yet, I would change the name of the feature to "Generic cpufreq transition governor" to make it somewhat less ambiguous.

Quoted 4 lines

In my opinion it makes it look MORE like this is a cpufreq governor. How about the following?
PM / devfreq: Generic cpufreq to devfreq mapping governor Seem a lot more clear to me.

Well, it's not just mapping, but also it triggers on cpufreq transitions AFAICS.

Which makes me wonder if the approach here is the right one at all.

Shouldn't the cpufreq driver be hooked up to the related HW through the OPP framework and sharing access with devfreq rather?

Quoted 3 lines

I'm open to suggestions for the devfreq governor name too. "cpufreq" has been very confusing so far.
cpufreq-map maybe?

It's more like "cpufreq drriven" IMO, but I don't really have any good names for it in mind ATM I'm afraid.

#4 lore raw
Quoted 50 lines · Rafael J. Wysocki
Quoted 49 lines · On Mon, Jul 30, 2018 at 8:58 PM, <[email protected]> wrote:
Quoted 46 lines · Rafael J. Wysocki
Quoted 31 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs.
Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen
to the frequency transitions of each CPU frequency domain and then adjusts
the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies
(typically
used
for system with homogeneous cores/clusters that have the same
OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

OR

Quoted 7 lines

* 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. And interpolated for frequencies in
between.

While not having looked at the details of the patch yet, I would change the name of the feature to "Generic cpufreq transition governor" to make it somewhat less ambiguous.

Quoted 6 lines
Quoted 4 lines

In my opinion it makes it look MORE like this is a cpufreq governor. How about the following?
PM / devfreq: Generic cpufreq to devfreq mapping governor Seem a lot more clear to me.

Well, it's not just mapping, but also it triggers on cpufreq transitions AFAICS.

Right, but I'm not sure that's the most important aspect of this governor.

Quoted 4 lines

Which makes me wonder if the approach here is the right one at all.

Shouldn't the cpufreq driver be hooked up to the related HW through the OPP framework and sharing access with devfreq rather?

Not sure what you mean here. This devfreq governor is orthogonal to what the cpufreq driver does with its HW. This is just trying to scale L3 or DDR or whatever other device based on current CPU frequency. Not all CPUfreq drivers support OPP. And even if they do, I don't see how it's relevant here.

Thanks,
Saravana

#6 lore raw
In reply to Saravana Kannan
Quoted 43 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically
used
for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

OR

* 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. And interpolated for frequencies in
between.

---
 .../bindings/devfreq/devfreq-cpufreq.txt           |  53 ++
 drivers/devfreq/Kconfig                            |   8 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/governor_cpufreq.c                 | 583 
+++++++++++++++++++++
 4 files changed, 645 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq.txt
 create mode 100644 drivers/devfreq/governor_cpufreq.c
Quoted 5 lines

diff --git a/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq.txt b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq.txt new file mode 100644
index 0000000..6537538

MyungJoo, Chanwoo,

Thoughts? Good enough to merge?

Rob,

DT review? I know this DT documentation should be a separate patch, but I've kept it here for context. I can split it up once the code and the binding have been agreed to.

Thanks,
Saravana

#5 lore raw
In reply to [email protected]
Quoted 64 lines · On Tue, Jul 31, 2018 at 9:21 PM, <[email protected]> wrote:
Quoted 63 lines · Rafael J. Wysocki
Quoted 59 lines · On Mon, Jul 30, 2018 at 8:58 PM, <[email protected]> wrote:
Quoted 47 lines · Rafael J. Wysocki
Quoted 31 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs.
Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen
to the frequency transitions of each CPU frequency domain and then adjusts
the frequency of the cache (or any devfreq device) based on the frequency
of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically
used
for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

OR

Quoted 8 lines

* 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. And interpolated for frequencies in
between.

Quoted 3 lines

While not having looked at the details of the patch yet, I would change the name of the feature to "Generic cpufreq transition governor" to make it somewhat less ambiguous.

In my opinion it makes it look MORE like this is a cpufreq governor. How about the following?
PM / devfreq: Generic cpufreq to devfreq mapping governor Seem a lot more clear to me.

Quoted 5 lines
Quoted 2 lines

Well, it's not just mapping, but also it triggers on cpufreq transitions AFAICS.

Right, but I'm not sure that's the most important aspect of this governor.

What are the other events triggering it, then?

Quoted 10 lines
Quoted 4 lines

Which makes me wonder if the approach here is the right one at all.

Shouldn't the cpufreq driver be hooked up to the related HW through the OPP framework and sharing access with devfreq rather?

Not sure what you mean here. This devfreq governor is orthogonal to what the cpufreq driver does with its HW. This is just trying to scale L3 or DDR or whatever other device based on current CPU frequency. Not all CPUfreq drivers support OPP. And even if they do, I don't see how it's relevant here.

OK, fair enough.

#7 lore raw
In reply to Saravana Kannan
Quoted 19 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically used for system with homogeneous cores/clusters that have the same OPPs.
- One mapping table per CPU freq policy (typically used for ASMP systems with heterogeneous CPUs with different OPPs)

Quoted 7 lines

OR

* 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. And interpolated for frequencies in between.

Is this solution for the old generation of SDM ?
I have seen newer ones have some kind of firmware interface/hardware to deal with CPUFreq. Do you need this solution for them too ?

If yes, why ? IMO firmware can arbitrate various requests for frequency scaling and do the *right thing* for the platform. Having OSPM sending separate requests for such bus/interconnect might end up with conflicts. No ?

Signature · 2 lines
Regards,
Sudeep
#8 lore raw
Quoted 34 lines · Sudeep Holla
Quoted 24 lines · Saravana Kannan

Many CPU architectures have caches that can scale independent of the CPUs. Frequency scaling of the caches is necessary to make sure 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 a generic devfreq governor that can listen to the frequency transitions of each CPU frequency domain and then adjusts the frequency of the cache (or any devfreq device) based on the frequency of the CPUs.

To decide the frequency of the device, the governor does one of the following:

* Uses a CPU frequency to device frequency mapping table
- Either one mapping table used for all CPU freq policies (typically
used
for system with homogeneous cores/clusters that have the same
OPPs.
- One mapping table per CPU freq policy (typically used for ASMP
systems
with heterogeneous CPUs with different OPPs)

OR

Quoted 8 lines

* 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. And interpolated for frequencies in
between.

Quoted 1 line

Is this solution for the old generation of SDM ?

This code isn't even specific to Qualcomm chips. Let alone a specific generation of SDM.

Quoted 2 lines

I have seen newer ones have some kind of firmware interface/hardware to deal with CPUFreq. Do you need this solution for them too ?

You are confusing two completely unrelated drivers. This is generic *devfreq* *governor* code. I'll be renaming the commit text like Rafael suggested.

Something like: CPU frequency to devfreq mapping governor.

Quoted 1 line

If yes, why ?

Read the commit text.

Quoted 2 lines

IMO firmware can arbitrate various requests for frequency scaling and do the *right thing* for the platform.

Firmware (if any) can arbitrate HW that it controls. DDR and interconnect is not something a firmware might control (or should control).

Quoted 3 lines

Having OSPM sending
separate requests for such bus/interconnect might end up with conflicts. No ?

If some chips have firmware that takes care of everything, then you obviously won't be enabling any power management code.

Thanks,
Saravana