thermal: mediatek: Add cpu power cooling model
Subsystems (3)
v4 cover thermal: mediatek: Add cpu power cooling model
Use Intelligent Power Allocation (IPA) technical to add dynamic power model for binding CPU thermal zone. The power allocator governor allocates power budget to control CPU temperature.
Power Allocator governor is able to keep SOC temperature within a defined temperature range to avoid SOC overheat and keep it's performance. mt8173-cpufreq.c need to register its' own power model with power allocator thermal governor, so that power allocator governor can allocates suitable power budget to control CPU temperature.
Binging document is refer to this patchset
https://lkml.org/lkml/2015/11/17/251
Change since V1:
1. Include mt8171.h and sort header file for mt8173.dtsi
Change since V2:
1. Move dynamic/static power model in device tree
Change since V3:
1. Remove static power model.
2. Split V3's device tree in two for thermal zones and dynamic power models respectively.
Dawei Chien (3):
arm64: dts: mt8173: Add thermal zone node for mt8173 platform.
arm64: dts: mt8173: Add dynamic power node for mt8173 platform.
thermal: mediatek: Add cpu dynamic power cooling model.
arch/arm64/boot/dts/mediatek/mt8173.dtsi | 47 ++++++++++++++++++++++++++++++ drivers/cpufreq/mt8173-cpufreq.c | 28 +++++++++++++----- 2 files changed, 67 insertions(+), 8 deletions(-)
--
1.7.9.5
PATCH v4 1/3 arm64: dts: mt8173: Add thermal zone node.
This adds thermal zone node to Mediatek MT8173 dtsi file.
---
This patch is based on patchset:
https://lkml.org/lkml/2015/11/18/84
--- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +43 -0
@@ -188,6 +188,49 @@ clock-output-names = "cpum_ck"; }; + thermal-zones { + cpu_thermal: cpu_thermal { + polling-delay-passive = <1000>; /* milliseconds */ + polling-delay = <1000>; /* milliseconds */ + + thermal-sensors = <&thermal 0>; + sustainable-power = <1500>; /* milliwatts */ + + trips { + threshold: trip-point at 0 { + temperature = <68000>; + hysteresis = <2000>; + type = "passive"; + }; + + target: trip-point at 1 { + temperature = <85000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_crit: cpu_crit at 0 { + temperature = <115000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + cooling-maps { + map at 0 { + trip = <&target>; + cooling-device = <&cpu0 0 0>; + contribution = <1024>; + }; + map at 1 { + trip = <&target>; + cooling-device = <&cpu2 0 0>; + contribution = <2048>; + }; + }; + }; + }; + timer { compatible = "arm,armv8-timer"; interrupt-parent = <&gic>;
Signature · 1 line
1.7.9.5
PATCH v4 2/3 arm64: dts: mt8173: Add dynamic power node.
In reply to Dawei ChienThis device node is for calculating dynamic power in mW. Since mt8173 has two clusters, there are two dynamic power coefficient as well.
---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251
--- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +4 -0
@@ -71,6 +71,7 @@ #cooling-cells = <2>; #cooling-min-level = <0>; #cooling-max-level = <7>; + dynamic-power-coefficient = <263>; }; cpu1: cpu at 1 {
@@ -95,6 +96,7 @@ #cooling-cells = <2>; #cooling-min-level = <0>; #cooling-max-level = <7>; + dynamic-power-coefficient = <263>; }; cpu2: cpu at 100 {
@@ -119,6 +121,7 @@ #cooling-cells = <2>; #cooling-min-level = <0>; #cooling-max-level = <7>; + dynamic-power-coefficient = <530>; }; cpu3: cpu at 101 {
@@ -143,6 +146,7 @@ #cooling-cells = <2>; #cooling-min-level = <0>; #cooling-max-level = <7>; + dynamic-power-coefficient = <530>; }; idle-states {
Signature · 1 line
1.7.9.5
PATCH v4 3/3 thermal: mediatek: Add cpu dynamic power cooling model.
In reply to Dawei ChienMT8173 cpufreq driver use of_cpufreq_power_cooling_register registering cooling devices with dynamic power coefficient.
---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251
--- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
drivers/cpufreq/mt8173-cpufreq.c +19 -8
@@ -263,24 +263,34 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,return 0 ; } +#define DYNAMIC_POWER "dynamic-power-coefficient" +static void mtk_cpufreq_ready (struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;struct device_node *np =of_node_get (info->cpu_dev->of_node); +u32 capacitance;if (WARN_ON (!np))return ;if (of_find_property (np,"#cooling-cells" ,NULL )) { - info->cdev =of_cpufreq_cooling_register (np, - policy->related_cpus); +if (!info->cdev) { +of_property_read_u32 (np,DYNAMIC_POWER , &capacitance); + + info->cdev =of_cpufreq_power_cooling_register (np, + policy->related_cpus, + capacitance, +NULL ); -if (IS_ERR (info->cdev)) { -dev_err (info->cpu_dev, -"running cpufreq without cooling device: %ld\n" , -PTR_ERR (info->cdev)); +if (IS_ERR (info->cdev)) { +dev_err (info->cpu_dev, +"running cpufreq without cooling device: %ld\n" , +PTR_ERR (info->cdev)); - info->cdev =NULL ; + info->cdev =NULL ; + } } }
@@ -460,7 +470,9 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data; -cpufreq_cooling_unregister (info->cdev); +if (info->cdev) +cpufreq_cooling_unregister (info->cdev); +dev_pm_opp_free_cpufreq_table (info->cpu_dev, &policy->freq_table);mtk_cpu_dvfs_info_release (info);kfree (info);
Signature · 1 line
1.7.9.5
Viresh Kumar
maintainerRe: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 24 lines · Dawei Chien
MT8173 cpufreq driver use
of_cpufreq_power_cooling_registerregistering cooling devices with dynamic power coefficient.Signed-off-by Dawei Chien <[email protected]>---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251--- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)drivers/cpufreq/mt8173-cpufreq.c +2
-0@@ -263,24 +263,34 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,return 0 ; } +#define DYNAMIC_POWER "dynamic-power-coefficient" +static void mtk_cpufreq_ready (struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 278
Quoted 10 lines
drivers/cpufreq/mt8173-cpufreq.c +2
-2struct device_node *np =of_node_get (info->cpu_dev->of_node); +u32 capacitance;if (WARN_ON (!np))return ;if (of_find_property (np,"#cooling-cells" ,NULL )) { - info->cdev =of_cpufreq_cooling_register (np, - policy->related_cpus); +if (!info->cdev) {
Why will info->cdev be non-NULL here ?
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 279
Quoted 1 line
drivers/cpufreq/mt8173-cpufreq.c +1
-0+of_property_read_u32 (np,DYNAMIC_POWER , &capacitance);
This can fail, in which case capacitance will be used uninitialized. Fix that by initializing it with 0 at the beginning of this routine.
Quoted 21 lines
drivers/cpufreq/mt8173-cpufreq.c +10
-5+ info->cdev =of_cpufreq_power_cooling_register (np, + policy->related_cpus, + capacitance, +NULL ); -if (IS_ERR (info->cdev)) { -dev_err (info->cpu_dev, -"running cpufreq without cooling device: %ld\n" , -PTR_ERR (info->cdev)); +if (IS_ERR (info->cdev)) { +dev_err (info->cpu_dev, +"running cpufreq without cooling device: %ld\n" , +PTR_ERR (info->cdev)); - info->cdev =NULL ; + info->cdev =NULL ; + } } }
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_exit(struct cpufreq_policy *policy) · line 475
Quoted 7 lines
drivers/cpufreq/mt8173-cpufreq.c +3
-1@@ -460,7 +470,9 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data; -cpufreq_cooling_unregister (info->cdev); +if (info->cdev) +cpufreq_cooling_unregister (info->cdev); +
Why do you need to update this?
Quoted 5 lines
drivers/cpufreq/mt8173-cpufreq.c +0
-0dev_pm_opp_free_cpufreq_table (info->cpu_dev, &policy->freq_table);mtk_cpu_dvfs_info_release (info);kfree (info);Signature · 1 line
1.7.9.5
Signature · 1 line
viresh
Re: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 31 lines · Viresh Kumar
Quoted 30 lines · Dawei Chien
MT8173 cpufreq driver use
of_cpufreq_power_cooling_registerregistering cooling devices with dynamic power coefficient.Signed-off-by Dawei Chien <[email protected]>---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251--- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)drivers/cpufreq/mt8173-cpufreq.c +3
-0@@ -263,24 +263,34 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,return 0 ; } +#define DYNAMIC_POWER "dynamic-power-coefficient" +static void mtk_cpufreq_ready (struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;struct device_node *np =of_node_get (info->cpu_dev->of_node); +u32 capacitance;if (WARN_ON (!np))return ;
Quoted 6 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 278
Quoted 4 lines
drivers/cpufreq/mt8173-cpufreq.c +1
-2if (of_find_property (np,"#cooling-cells" ,NULL )) { - info->cdev =of_cpufreq_cooling_register (np, - policy->related_cpus); +if (!info->cdev) {Why will
info->cdevbe non-NULL here ?
This is a error-checking to avoid user or any script by command line hotplug CPU more than two times, we don't need to register cooling device on this case.
I will remove it if you don't agree it.
Quoted 4 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 279
Quoted 1 line
drivers/cpufreq/mt8173-cpufreq.c +1
-0+of_property_read_u32 (np,DYNAMIC_POWER , &capacitance);This can fail, in which case capacitance will be used uninitialized. Fix that by initializing it with 0 at the beginning of this routine.
Thank you, I will follow your comment to fix it on next version.
Quoted 24 lines
Quoted 24 lines
drivers/cpufreq/mt8173-cpufreq.c +10
-5+ info->cdev =of_cpufreq_power_cooling_register (np, + policy->related_cpus, + capacitance, +NULL ); -if (IS_ERR (info->cdev)) { -dev_err (info->cpu_dev, -"running cpufreq without cooling device: %ld\n" , -PTR_ERR (info->cdev)); +if (IS_ERR (info->cdev)) { +dev_err (info->cpu_dev, +"running cpufreq without cooling device: %ld\n" , +PTR_ERR (info->cdev)); - info->cdev =NULL ; + info->cdev =NULL ; + } } }@@ -460,7 +470,9 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;
Quoted 6 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_exit(struct cpufreq_policy *policy) · line 475
Quoted 4 lines
drivers/cpufreq/mt8173-cpufreq.c +3
-1-cpufreq_cooling_unregister (info->cdev); +if (info->cdev) +cpufreq_cooling_unregister (info->cdev); +Why do you need to update this?
This is a error-checking to avoid user or any script by command line unplug CPU more than two times, we don't need to unregister cooling device on this case.
I will remove it if you don't agree it.
Quoted 6 lines
Quoted 5 lines
drivers/cpufreq/mt8173-cpufreq.c +0
-0dev_pm_opp_free_cpufreq_table (info->cpu_dev, &policy->freq_table);mtk_cpu_dvfs_info_release (info);kfree (info);Signature · 1 line
1.7.9.5
Viresh Kumar
maintainerRe: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 39 lines · dawei chien
Quoted 31 lines · Viresh Kumar
Quoted 30 lines · Dawei Chien
MT8173 cpufreq driver use
of_cpufreq_power_cooling_registerregistering cooling devices with dynamic power coefficient.Signed-off-by Dawei Chien <[email protected]>---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251--- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)drivers/cpufreq/mt8173-cpufreq.c +3
-0@@ -263,24 +263,34 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,return 0 ; } +#define DYNAMIC_POWER "dynamic-power-coefficient" +static void mtk_cpufreq_ready (struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;struct device_node *np =of_node_get (info->cpu_dev->of_node); +u32 capacitance;if (WARN_ON (!np))return ;Quoted 6 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 278
Quoted 4 lines
drivers/cpufreq/mt8173-cpufreq.c +1
-2if (of_find_property (np,"#cooling-cells" ,NULL )) { - info->cdev =of_cpufreq_cooling_register (np, - policy->related_cpus); +if (!info->cdev) {Why will
info->cdevbe non-NULL here ?
Quoted 2 lines
This is a error-checking to avoid user or any script by command line hotplug CPU more than two times, we don't need to register cooling device on this case.
Why?
Quoted 1 line
I will remove it if you don't agree it.
No, my agreeing or not doesn't matter. If what you are doing is useful (and I am not able to understand it), then you should make me understand that and don't change your code.
But, I really do not get the reasoning behind the logic. Please elaborate that step by step.
Quoted 11 lines
Quoted 10 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_exit(struct cpufreq_policy *policy) · line 475
Quoted 8 lines
drivers/cpufreq/mt8173-cpufreq.c +3
-1@@ -460,7 +470,9 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data; -cpufreq_cooling_unregister (info->cdev); +if (info->cdev) +cpufreq_cooling_unregister (info->cdev); +Why do you need to update this?
Quoted 5 lines
This is a error-checking to avoid user or any script by command line unplug CPU more than two times, we don't need to unregister cooling device on this case.
I will remove it if you don't agree it.
Same here.
Signature · 1 line
viresh
Re: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 40 lines · Viresh Kumar
Quoted 39 lines · dawei chien
Quoted 37 lines · Viresh Kumar
Quoted 24 lines · Dawei Chien
MT8173 cpufreq driver use
of_cpufreq_power_cooling_registerregistering cooling devices with dynamic power coefficient.Signed-off-by Dawei Chien <[email protected]>---
This patch is base on patchset:
https://lkml.org/lkml/2015/11/17/251--- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)drivers/cpufreq/mt8173-cpufreq.c +2
-0@@ -263,24 +263,34 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,return 0 ; } +#define DYNAMIC_POWER "dynamic-power-coefficient" +static void mtk_cpufreq_ready (struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data;drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, · line 278
Quoted 10 lines
drivers/cpufreq/mt8173-cpufreq.c +2
-2struct device_node *np =of_node_get (info->cpu_dev->of_node); +u32 capacitance;if (WARN_ON (!np))return ;if (of_find_property (np,"#cooling-cells" ,NULL )) { - info->cdev =of_cpufreq_cooling_register (np, - policy->related_cpus); +if (!info->cdev) {Why will
info->cdevbe non-NULL here ?
Quoted 4 lines
Quoted 2 lines
This is a error-checking to avoid user or any script by command line hotplug CPU more than two times, we don't need to register cooling device on this case.
Why?
As far as I know, user or shell script has the right for using command online/offline cpu. Either user by console or shell script could make cpu2 online even cpu2 already onlined. That could cause of_cpufreq_cooling_register execute many times for the same cooling device.
"echo 1 > /sys/devices/system/cpu/cpu2/online"
With above hotplug command, mtk_cpufreq_ready will register cooling device again as well, but fail since the cooling device already created, so we might need not register cooling device again on this case.
Quoted 8 lines
Quoted 1 line
I will remove it if you don't agree it.
No, my agreeing or not doesn't matter. If what you are doing is useful (and I am not able to understand it), then you should make me understand that and don't change your code.
But, I really do not get the reasoning behind the logic. Please elaborate that step by step.
Please refer to above explaining, thank you.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/cpufreq/mt8173-cpufreq.c static int mtk_cpufreq_exit(struct cpufreq_policy *policy) · line 475
Quoted 8 lines
drivers/cpufreq/mt8173-cpufreq.c +3
-1@@ -460,7 +470,9 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy) {struct mtk_cpu_dvfs_info *info = policy->driver_data; -cpufreq_cooling_unregister (info->cdev); +if (info->cdev) +cpufreq_cooling_unregister (info->cdev); +Why do you need to update this?
Quoted 7 lines
Quoted 5 lines
This is a error-checking to avoid user or any script by command line unplug CPU more than two times, we don't need to unregister cooling device on this case.
I will remove it if you don't agree it.
Same here.
Please refer to the same reason as above. thank you.
Viresh Kumar
maintainerRe: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 1 line · dawei chien
As far as I know, user or shell script has the right for using command online/offline cpu.
Right.
Quoted 1 line
Either user by console or shell script could make cpu2 online even cpu2 already onlined.
Hey, no. You can't online that is already online. You can write '1' to the file /sys/devices/system/cpu/cpuX/online, but it wouldn't have any affect.
Quoted 2 lines
That could cause
of_cpufreq_cooling_registerexecute many times for the same cooling device.
No.
Quoted 5 lines
"echo 1 >
/sys/devices/system/cpu/cpu2/online"With above hotplug command,
mtk_cpufreq_readywill register cooling device again as well, but fail since the cooling device already created, so we might need not register cooling device again on this case.
Have you tested this yourself ?
Signature · 1 line
viresh
Re: [PATCH v4 3/3] thermal: mediatek: Add cpu dynamic power cooling model.
Quoted 7 lines · Viresh Kumar
Quoted 1 line · dawei chien
As far as I know, user or shell script has the right for using command online/offline cpu.
Right.
Quoted 1 line
Either user by console or shell script could make cpu2 online even cpu2 already onlined.
Quoted 8 lines
Hey, no. You can't online that is already online. You can write '1' to the file
/sys/devices/system/cpu/cpuX/online, but it wouldn't have any affect.Quoted 2 lines
That could cause
of_cpufreq_cooling_registerexecute many times for the same cooling device.No.
You are right. certainly no, it's my misunderstand.
Quoted 7 lines
Quoted 5 lines
"echo 1 >
/sys/devices/system/cpu/cpu2/online"With above hotplug command,
mtk_cpufreq_readywill register cooling device again as well, but fail since the cooling device already created, so we might need not register cooling device again on this case.Have you tested this yourself ?
Truly sorry for misunderstanding, so we don't need to add error checking code there.
(It seems whole of cluster offline, the cooling device unregister as well. If just one cpu online, cooling device register as well)
Three months ago, Once I used following command, cooling device can't create any more. err message will show once I echo online command. However, this bug already fixed in mainline by you.
echo 0 > /sys/devices/system/cpu/cpu2/online
echo 0 > /sys/devices/system/cpu/cpu3/online
echo 1 > /sys/devices/system/cpu/cpu2/online
commit 528464eaa46ae1bd319882e4dd3495802e55b8c4
Author: Viresh Kumar <[email protected]> Date: Thu Jul 23 14:32:32 2015 +0530
thermal: remove dangling 'weight_attr' device file