Skip to contentSkip to conversation

PM / devfreq: Generic CPU frequency to device frequency mapping governor

PATCH In review Saravana Kannan 5 participants 10 messages Aug 2, 2018 – Sep 10, 2018

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

PATCH v3 1/2 PM / devfreq: Generic CPU frequency to device frequency mapping 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 takes the current frequency of each CPU frequency domain and then adjusts 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:

* 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-map.txt       |  53 ++
 drivers/devfreq/Kconfig                            |   8 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/governor_cpufreq_map.c             | 583 +++++++++++++++++++++
 4 files changed, 645 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
 create mode 100644 drivers/devfreq/governor_cpufreq_map.c
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +53 -0
new file mode 100644
index 0000000..982a30b
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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-map".
+
+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-map {
+		cpubw-cpufreq {
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;
+		};
+
+		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 6a172d3..3d9ae68 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_MAP
+	tristate "CPUfreq Map"
+	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 32b8d4d..e9dc3e9 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_MAP)	+= governor_cpufreq_map.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
drivers/devfreq/governor_cpufreq_map.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
maintainer
#1 lore raw
Quoted 5 lines

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.

Quoted 8 lines

To achieve this, this patch adds a generic devfreq governor that takes the current frequency of each CPU frequency domain and then adjusts 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:

This exactly has the same purpose with "passive" governor except for the single part: passive governor depends on another devfreq driver, not cpufreq driver.

If both governors have many features in common, can you merge them into one? Passive governor also has "get_target_freq", which allows driver authors to define the mapping.

Probably, you will need to add one more notifier call to get events from cpufreq instead of devfreq.

Quoted 7 lines

* 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.

If you want to satisfy these two cases to the "modified" passive governors, you may need to supply two "preloaded" get_target_freq functions for struct devfreq_passive_data. If that's impossible, requiring a bit more modifications, you may need to write alternative routines in update_devfreq_passive().

Cheers,
MyungJoo

Quoted 11 lines

---

.../bindings/devfreq/devfreq-cpufreq-map.txt       |  53 ++
drivers/devfreq/Kconfig                            |   8 +
drivers/devfreq/Makefile                           |   1 +
drivers/devfreq/governor_cpufreq_map.c             | 583 +++++++++++++++++++++
4 files changed, 645 insertions(+)

create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt create mode 100644 drivers/devfreq/governor_cpufreq_map.c

[]

drivers/devfreq/governor_cpufreq_map.c line 4

Quoted 10 lines
drivers/devfreq/governor_cpufreq_map.c new file +4 -0
new file mode 100644
index 0000000..084a3ff
@@ -0,0 +1,583 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014-2015, 2018, The Linux Foundation. All rights reserved.
+ */

Is this boilerplate fine? ( using // )

#2 lore raw
Quoted 14 lines · MyungJoo Ham
Quoted 5 lines

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.

Quoted 8 lines

To achieve this, this patch adds a generic devfreq governor that takes the current frequency of each CPU frequency domain and then adjusts 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:

Quoted 7 lines

This exactly has the same purpose with "passive" governor except for the single part: passive governor depends on another devfreq driver, not cpufreq driver.

If both governors have many features in common, can you merge them into one? Passive governor also has "get_target_freq", which allows driver authors to define the mapping.

Thanks for the review and pointing me to the passive governor. I agree that at a high level they are both doing the same. I can certainly stuff this CPU freq to dev freq mapping into passive governor, but I think it'll just make one huge set of code that's harder to understand and maintain because it trying to do different things under the hood.

There are also a bunch of complexities and optimizations that come with the cpufreq-map governor that don't fit with the passive governor.

1. It's not one CPU who's frequency we have to listen to. There are multiple CPUs/policies we have to aggregate across.
2. We have to deal with big vs little having different needs/mappings.
3. Since it's always just CPUfreq, I can optimize the handling in the transition notifiers. If I have 4 different devices that are scaled based on CPU freq, I still use only 1 transition notifier. It becomes a bit harder to do with the passive governor.
4. It requires that the device explicitly support the passive governor and pick a mapping function. With cpufreq-map governor, the device drivers don't need to make any changes. Whoever is making a device/board can choose what devices to scale up base on CPU freq based on their board and their needs. Even an end user can say, scale the GPU based on my CPU based on interpolation if they choose to.
5. If a device has some other use for the private data, it can't work with passive governor, but can work with cpufreq-map governor.
6. I also want to improve cpufreq-map governor to handle hotplug correctly in later patches (needs more discussion) and that'll add more complexity.

I think for these reasons we shouldn't combine these two governors. Let me know what you think.

Quoted 23 lines

Probably, you will need to add one more notifier call to get events from cpufreq instead of devfreq.

Quoted 12 lines

* 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 6 lines

If you want to satisfy these two cases to the "modified" passive governors, you may need to supply two "preloaded" get_target_freq functions for struct devfreq_passive_data. If that's impossible, requiring a bit more modifications, you may need to write alternative routines in update_devfreq_passive().

Thanks for the pointers. I understood what you mean here.

Quoted 5 lines
Quoted 5 lines
drivers/devfreq/governor_cpufreq_map.c new file +0 -0
new file mode 100644
index 0000000..084a3ff
Quoted 8 lines
Quoted 6 lines
drivers/devfreq/governor_cpufreq_map.c new file +3 -0
@@ -0,0 +1,583 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014-2015, 2018, The Linux Foundation. All rights 

reserved.
+ */

Is this boilerplate fine? ( using // )

I was just following what I thought was the new standard. checkpatch even complains about not having this.

Thanks,
Saravana

#3 lore raw
Quoted 52 lines · On 2018-08-02 14:00, [email protected] wrote:
Quoted 14 lines · MyungJoo Ham
Quoted 5 lines

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.

Quoted 8 lines

To achieve this, this patch adds a generic devfreq governor that takes the current frequency of each CPU frequency domain and then adjusts 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:

Quoted 7 lines

This exactly has the same purpose with "passive" governor except for the single part: passive governor depends on another devfreq driver, not cpufreq driver.

If both governors have many features in common, can you merge them into one? Passive governor also has "get_target_freq", which allows driver authors to define the mapping.

Thanks for the review and pointing me to the passive governor. I agree that at a high level they are both doing the same. I can certainly stuff this CPU freq to dev freq mapping into passive governor, but I think it'll just make one huge set of code that's harder to understand and maintain because it trying to do different things under the hood.

There are also a bunch of complexities and optimizations that come with the cpufreq-map governor that don't fit with the passive governor.

1. It's not one CPU who's frequency we have to listen to. There are multiple CPUs/policies we have to aggregate across.
2. We have to deal with big vs little having different needs/mappings.
3. Since it's always just CPUfreq, I can optimize the handling in the transition notifiers. If I have 4 different devices that are scaled based on CPU freq, I still use only 1 transition notifier. It becomes a bit harder to do with the passive governor.
4. It requires that the device explicitly support the passive governor and pick a mapping function. With cpufreq-map governor, the device drivers don't need to make any changes. Whoever is making a device/board can choose what devices to scale up base on CPU freq based on their board and their needs. Even an end user can say, scale the GPU based on my CPU based on interpolation if they choose to.
5. If a device has some other use for the private data, it can't work with passive governor, but can work with cpufreq-map governor.
6. I also want to improve cpufreq-map governor to handle hotplug correctly in later patches (needs more discussion) and that'll add more complexity.

Quoted 2 lines

I think for these reasons we shouldn't combine these two governors. Let me know what you think.

Friendly reminder.

Thanks,
Saravana

maintainer
#5 lore raw
In reply to Saravana Kannan
Quoted 22 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 takes the current frequency of each CPU frequency domain and then adjusts 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:

* 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.

---
 .../bindings/devfreq/devfreq-cpufreq-map.txt       |  53 ++

Bindings should be a separate patch.

Quoted 40 lines
 drivers/devfreq/Kconfig                            |   8 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/governor_cpufreq_map.c             | 583 +++++++++++++++++++++
 4 files changed, 645 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
 create mode 100644 drivers/devfreq/governor_cpufreq_map.c
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +27 -0
new file mode 100644
index 0000000..982a30b
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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-map".
+
+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-map {
+		cpubw-cpufreq {

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt line 37

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +10 -0
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;

Now we have frequencies listed in multiple places, the OPP tables and here? Perhaps it is grouping OPPs that should be done.

This all looks bolted on and very much Linux specifc.

Rob

#6 lore raw
Quoted 91 lines · Rob Herring
Quoted 33 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 takes the current frequency of each CPU frequency domain and then adjusts 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:

* 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.

Quoted 3 lines
---
 .../bindings/devfreq/devfreq-cpufreq-map.txt       |  53 ++

Bindings should be a separate patch.

Quoted 51 lines
 drivers/devfreq/Kconfig                            |   8 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/governor_cpufreq_map.c             | 583 
+++++++++++++++++++++
 4 files changed, 645 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
 create mode 100644 drivers/devfreq/governor_cpufreq_map.c
(quoted diff) +0 -0
new file mode 100644
index 0000000..982a30b

b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +3 -0
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +27 -0
+CCI.
+
+Parent device name shall be "devfreq-cpufreq-map".
+
+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-map {
+		cpubw-cpufreq {
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
Quoted 8 lines

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +5 -0
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;

Now we have frequencies listed in multiple places, the OPP tables and here? Perhaps it is grouping OPPs that should be done.

This doesn't list all OPPs (it can if necessary). This is listing the minimum frequency needed to give good performance/power for a device/product.

AFAIK, OPP grouping isn't something that's supported in OPP framework or in DT. Is there something specific you had in mind? Also, I'd like for this to work even with devices that don't have OPPs listed in DT.

Thanks,
Saravana

#7 lore raw
Quoted 105 lines · On Tue, Aug 07, 2018 at 12:37:07PM -0700, [email protected] wrote:
Quoted 95 lines · Rob Herring
Quoted 36 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 takes the
current frequency of each CPU frequency domain and then adjusts 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:

* 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.

Quoted 3 lines

---
.../bindings/devfreq/devfreq-cpufreq-map.txt | 53 ++

Bindings should be a separate patch.

Quoted 52 lines
drivers/devfreq/Kconfig                            |   8 +
drivers/devfreq/Makefile                           |   1 +
drivers/devfreq/governor_cpufreq_map.c             | 583
+++++++++++++++++++++
4 files changed, 645 insertions(+)

create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt create mode 100644 drivers/devfreq/governor_cpufreq_map.c

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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +3 -0
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +27 -0
+CCI.
+
+Parent device name shall be "devfreq-cpufreq-map".
+
+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-map {
+		cpubw-cpufreq {
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
Quoted 8 lines

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +5 -0
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;

Now we have frequencies listed in multiple places, the OPP tables and here? Perhaps it is grouping OPPs that should be done.

Quoted 4 lines

This doesn't list all OPPs (it can if necessary). This is listing the minimum frequency needed to give good performance/power for a device/product.

Shouldn't the "status" property be used to disable OPPs you don't need on a particular platform ?

Duplicating values is highly prone to errors and should be avoided.

Quoted 4 lines

AFAIK, OPP grouping isn't something that's supported in OPP framework or in DT. Is there something specific you had in mind? Also, I'd like for this to work even with devices that don't have OPPs listed in DT.

Also what's the solution you have for platforms with new *QCom FW Cpufreq* ? IIUC the frequency is obtained from the firmware. TBH this should ideally be handled in firmware if cpufreq is also handled by the firmware. I guess this platform doesn't have that ?

--
Regards,
Sudeep

#8 lore raw
Quoted 106 lines · Sudeep Holla
Quoted 105 lines · On Tue, Aug 07, 2018 at 12:37:07PM -0700, [email protected] wrote:
Quoted 103 lines · Rob Herring
Quoted 36 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 takes the
current frequency of each CPU frequency domain and then adjusts 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:

* 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.

Quoted 3 lines

---
.../bindings/devfreq/devfreq-cpufreq-map.txt | 53 ++

Bindings should be a separate patch.

Quoted 47 lines
drivers/devfreq/Kconfig                            |   8 +
drivers/devfreq/Makefile                           |   1 +
drivers/devfreq/governor_cpufreq_map.c             | 583
+++++++++++++++++++++
4 files changed, 645 insertions(+)

create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt create mode 100644 drivers/devfreq/governor_cpufreq_map.c

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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +3 -0
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +22 -0
+CCI.
+
+Parent device name shall be "devfreq-cpufreq-map".
+
+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-map {
+		cpubw-cpufreq {

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt line 37

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +10 -0
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;

Now we have frequencies listed in multiple places, the OPP tables and here? Perhaps it is grouping OPPs that should be done.

Quoted 7 lines
Quoted 4 lines

This doesn't list all OPPs (it can if necessary). This is listing the minimum frequency needed to give good performance/power for a device/product.

Shouldn't the "status" property be used to disable OPPs you don't need on a particular platform ?

But that's not the point here? We aren't trying to disable any OPPs here? Not sure what you mean.

Quoted 10 lines

Duplicating values is highly prone to errors and should be avoided.

Quoted 4 lines

AFAIK, OPP grouping isn't something that's supported in OPP framework or in DT. Is there something specific you had in mind? Also, I'd like for this to work even with devices that don't have OPPs listed in DT.

Also what's the solution you have for platforms with new *QCom FW Cpufreq* ? IIUC the frequency is obtained from the firmware. TBH this should ideally be handled in firmware if cpufreq is also handled by the firmware. I guess this platform doesn't have that ?

All QC platforms would use this.

As a personal (non-Qcom) opinion, I'd rather the kernel control this than have some black magic FW manage this. I've a really bitter taste in my mouth for FW hiding this because of a broken ACPI implementation in one of my x86 motherboards prevented CPUfreq from working (this was well before I worked on CPUfreq). Pushing stuff to FW seems to beat the ideal behind an opensource OS. In a few cases it's elegant or more robust, so maybe in those cases its okay to use a FW. But I'd rather not for simpler stuff like this.

-Saravana

#9 lore raw
Quoted 112 lines · On Wed, Aug 08, 2018 at 02:18:18PM -0700, [email protected] wrote:
Quoted 111 lines · Sudeep Holla
Quoted 109 lines · On Tue, Aug 07, 2018 at 12:37:07PM -0700, [email protected] wrote:
Quoted 95 lines · Rob Herring
Quoted 36 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 takes the
current frequency of each CPU frequency domain and then adjusts 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:

* 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.

Quoted 3 lines

---
.../bindings/devfreq/devfreq-cpufreq-map.txt | 53 ++

Bindings should be a separate patch.

Quoted 52 lines
drivers/devfreq/Kconfig                            |   8 +
drivers/devfreq/Makefile                           |   1 +
drivers/devfreq/governor_cpufreq_map.c             | 583
+++++++++++++++++++++
4 files changed, 645 insertions(+)

create mode 100644 Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt create mode 100644 drivers/devfreq/governor_cpufreq_map.c

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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +3 -0
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map 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

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +27 -0
+CCI.
+
+Parent device name shall be "devfreq-cpufreq-map".
+
+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-map {
+		cpubw-cpufreq {
+			target-dev = <&cpubw>;
+			cpu-to-dev-map =
+				<  300000  1144000 >,
+				<  422400  2288000 >,
+				<  652800  3051000 >,
Quoted 8 lines

Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt new file +5 -0
+				<  883200  5996000 >,
+				< 1190400  8056000 >,
+				< 1497600 10101000 >,
+				< 1728000 12145000 >,
+				< 2649600 16250000 >;

Now we have frequencies listed in multiple places, the OPP tables and here? Perhaps it is grouping OPPs that should be done.

This doesn't list all OPPs (it can if necessary). This is listing the minimum frequency needed to give good performance/power for a device/product.

Quoted 6 lines
Quoted 2 lines

Shouldn't the "status" property be used to disable OPPs you don't need on a particular platform ?

But that's not the point here? We aren't trying to disable any OPPs here? Not sure what you mean.

OK, I misunderstood, but my main concern was about duplication.

Quoted 2 lines
Quoted 2 lines

Duplicating values is highly prone to errors and should be avoided.

IIUC, opp entries are nodes themselves with v2 bindings, can't you use phandles to avoid duplication.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

AFAIK, OPP grouping isn't something that's supported in OPP framework or in
DT. Is there something specific you had in mind? Also, I'd like for this to
work even with devices that don't have OPPs listed in DT.

Quoted 8 lines
Quoted 5 lines

Also what's the solution you have for platforms with new *QCom FW Cpufreq* ?
IIUC the frequency is obtained from the firmware. TBH this should ideally be handled in firmware if cpufreq is also handled by the firmware. I guess this platform doesn't have that ?

All QC platforms would use this.

How about the ones that get OPPs from firmware ? I thought that was the case with new *QCom FW Cpufreq*

Quoted 2 lines

As a personal (non-Qcom) opinion, I'd rather the kernel control this than have some black magic FW manage this.

Indeed every OS person having to find/debug the firmware bug may feel that. But that doesn't change the fact that the embedded space is evolving. Firmware is inevitable for good or bad, we need to accept that fact and move on TBH.

Quoted 4 lines

I've a really bitter taste in my mouth
for FW hiding this because of a broken ACPI implementation in one of my x86 motherboards prevented CPUfreq from working (this was well before I worked on CPUfreq).

Alternate way to look at this is that embedded developers(at least me) are new to this space and feel that.

Quoted 1 line

Pushing stuff to FW seems to beat the ideal behind an opensource OS.

Not always. Even the recent security fixes(spectre/meltdown) had some dependencies on f/w to deal with the issues. So finding the ways to co-exist is more helpful than dismissing it.

Quoted 2 lines

In a few cases it's elegant or more robust, so maybe in those cases its okay to use a FW. But I'd rather not for simpler stuff like this.

But there are instances where such simple stuffs also open up for security exploits(clkscrew)

--
Regards,
Sudeep

#4 lore raw
In reply to [email protected]

Hi Saravana,

Quoted 7 lines · On 2018-08-07 11:19, [email protected] wrote:
Quoted 6 lines · On 2018-08-02 14:00, [email protected] wrote:
Quoted 5 lines · MyungJoo Ham
Quoted 5 lines

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.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

To achieve this, this patch adds a generic devfreq governor that takes the current frequency of each CPU frequency domain and then adjusts 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.

With the cpu-freq driver for SDM845 SoC supporting fast_switch and schedutil supporting dynamic switching wouldn't this governor be incompatible due to its reliance on transition notifiers? Is it planned to be used only with ondemand/performance governors?

Quoted 47 lines
Quoted 40 lines
Quoted 10 lines
Quoted 2 lines

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

This exactly has the same purpose with "passive" governor except for the single part: passive governor depends on another devfreq driver, not cpufreq driver.

If both governors have many features in common, can you merge them into one? Passive governor also has "get_target_freq", which allows driver authors to define the mapping.

Thanks for the review and pointing me to the passive governor. I agree that at a high level they are both doing the same. I can certainly stuff this CPU freq to dev freq mapping into passive governor, but I think it'll just make one huge set of code that's harder to understand and maintain because it trying to do different things under the hood.

There are also a bunch of complexities and optimizations that come with the cpufreq-map governor that don't fit with the passive governor.

1. It's not one CPU who's frequency we have to listen to. There are multiple CPUs/policies we have to aggregate across.
2. We have to deal with big vs little having different needs/mappings.
3. Since it's always just CPUfreq, I can optimize the handling in the transition notifiers. If I have 4 different devices that are scaled based on CPU freq, I still use only 1 transition notifier. It becomes a bit harder to do with the passive governor.
4. It requires that the device explicitly support the passive governor and pick a mapping function. With cpufreq-map governor, the device drivers don't need to make any changes. Whoever is making a device/board can choose what devices to scale up base on CPU freq based on their board and their needs. Even an end user can say, scale the GPU based on my CPU based on interpolation if they choose to.
5. If a device has some other use for the private data, it can't work with passive governor, but can work with cpufreq-map governor.
6. I also want to improve cpufreq-map governor to handle hotplug correctly in later patches (needs more discussion) and that'll add more complexity.

Quoted 2 lines

I think for these reasons we shouldn't combine these two governors. Let me know what you think.

Friendly reminder.

Thanks,
Saravana

Signature · 3 lines
-- Sibi Sankar --
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project.