Rockchip Developer Guide Linux4.4 Thermal CN

Rockchip-Developer-Guide-Linux4.4-Thermal-CN

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 14

Linux4.4
2019-01-22 V1.0
Thermal
1.0
finley.xiao@rock-chips.com
2019.01.22
thermal
Thermal
1
2
3
3.1 Menuconfig
3.2 Tsadc
3.3 Power allocator
3.3.1 CPU
3.3.2 GPU
3.3.3 Thermal Zone
3.3.4
4
5
5.1
5.2
1
Thermal governor Thermal
framework governor core cooling device sensor driver
Thermal governor cooling device Linux4.4
governor
power_allocator PID - - cooling device power
power
step_wise cooling device
fair share cooling device
userspace
Thermal core thermal governors thermal driver
Thermal sensor driver sensor tsadc
Thermal cooling device CPU GPU DDR
2
Governor
Cooling device
Core
Driver
3
3.1 Menuconfig
drivers/thermal/power_allocator.c /* power allocator */
drivers/thermal/step_wise.c      /* step wise */
drivers/thermal/fair_share.c    /* fair share */
drivers/thermal/user_space.c    /* userspace */
drivers/thermal/devfreq_cooling.c
drivers/thermal/cpu_cooling.c
drivers/thermal/thermal_core.c
drivers/thermal/rockchip_thermal.c  /* RK3368 tsadc */
drivers/thermal/rk3368_thermal.c   /* RK3368 tsadc */
<*> Generic Thermal sysfs driver--->
--- Generic Thermal sysfs driver
[*]  APIs to parse thermal data out of device tree
[*]  Enable writable trip points
Default Thermal governor (power_allocator) --->/* default thermal governor */
[ ]  Fair-share thermal governor
[ ]  Step_wise thermal governor           /* step_wise governor */
[ ]  Bang Bang thermal governor
[*]  User_space thermal governor           /* user_space governor */
-*-Power allocator thermal governor        /* power_allocator governor */
[*]  generic cpu cooling support           /* cooling device */
[ ]  Generic clock cooling support
[*]  Generic device cooling support         /* cooling device */
[ ]  Thermal emulation mode support
< >Temperature sensor driver for Freescale i.MX SoCs
<*>Rockchip thermal driver            /* thermal sensor driver */
< >   rk_virtual thermal driver
<*>   rk3368 thermal driver legacy         /* thermal sensor driver */
“Default Thermal governor”
3.2 Tsadc
Tsadc thermal sensor DTSI DTS
RK3399 DTSI
DTS CRU GPIO
GPIO tsadc PMIC CRU
tsadc: tsadc@ff260000 {
compatible = "rockchip,rk3399-tsadc";
reg = <0x0 0xff260000 0x0 0x100>;        /* */
interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH 0>; /* */
assigned-clocks = <&cru SCLK_TSADC>;       /* 750KHz */
assigned-clock-rates = <750000>;
clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>;  /* */
clock-names = "tsadc", "apb_pclk";
resets = <&cru SRST_TSADC>;           /* */
reset-names = "tsadc-apb";
rockchip,grf = <&grf>;              /* grf */
rockchip,hw-tshut-temp = <120000>;        /* 120 */
/* tsadc gpio otpout */
pinctrl-names = "gpio", "otpout";
pinctrl-0 = <&otp_gpio>;
pinctrl-1 = <&otp_out>;
/*
* thermal sensor tsadc thermal sensor
* tsadc
* SoC tsadc 0 1
*/
#thermal-sensor-cells = <1>;
status = "disabled";
};
/* IO */
pinctrl: pinctrl {
...
tsadc {
/* gpio */
otp_gpio: otp-gpio {
rockchip,pins = <1 6 RK_FUNC_GPIO &pcfg_pull_none>;
};
/* over temperature protection */
otp_out: otp-out {
rockchip,pins = <1 6 RK_FUNC_1 &pcfg_pull_none>;
};
};
....
}
"Documentation/devicetree/bindings/thermal/rockchip-thermal.txt"
3.3 Power allocator
Power allocator PID - - cooling device
power power power
3.3.1 CPU
CPU cooling device #cooling-cells dynamic-power-coefficient
RK3399
3.3.2 GPU
GPU cooling device #cooling-cells power_model
RK3399
&tsadc {
rockchip,hw-tshut-mode = <1>;   /* tshut mode 0:CRU 1:GPIO */
rockchip,hw-tshut-polarity = <1>; /* tshut polarity 0:LOW 1:HIGH */
status = "okay";
};
cpu_l0: cpu@0 {
device_type = "cpu";
compatible = "arm,cortex-a53", "arm,armv8";
reg = <0x0 0x0>;
enable-method = "psci";
#cooling-cells = <2>; /* cooling device cooling device */
clocks = <&cru ARMCLKL>;
cpu-idle-states = <&CPU_SLEEP &CLUSTER_SLEEP>;
dynamic-power-coefficient = <100>; /* C Pdyn=C*V^2*F */
};
...
cpu_b0: cpu@100 {
device_type = "cpu";
compatible = "arm,cortex-a72", "arm,armv8";
reg = <0x0 0x100>;
enable-method = "psci";
#cooling-cells = <2>; /* cooling device cooling device */
clocks = <&cru ARMCLKB>;
cpu-idle-states = <&CPU_SLEEP &CLUSTER_SLEEP>;
dynamic-power-coefficient = <436>; /* */
};
gpu: gpu@ff9a0000 {
compatible = "arm,malit860",
"arm,malit86x",
3.3.3 Thermal Zone
Termal zone
RK3399
"arm,malit8xx",
"arm,mali-midgard";
reg = <0x0 0xff9a0000 0x0 0x10000>;
interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH 0>,
<GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH 0>,
<GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH 0>;
interrupt-names = "GPU", "JOB", "MMU";
clocks = <&cru ACLK_GPU>;
clock-names = "clk_mali";
#cooling-cells = <2>; /* cooling device cooling device */
power-domains = <&power RK3399_PD_GPU>;
power-off-delay-ms = <200>;
status = "disabled";
gpu_power_model: power_model {
compatible = "arm,mali-simple-power-model";
static-coefficient = <411000>; /* */
dynamic-coefficient = <733>;  /* */
ts = <32000 4700 (-80) 2>;   /* */
thermal-zone = "gpu-thermal"; /* gpu-thermal */
};
};
thermal_zones: thermal-zones {
/* thermal zone */
soc_thermal: soc-thermal {
   /* trip-point-0 20ms */
polling-delay-passive = <20>; /* milliseconds */
   /* trip-point-0 1000ms */
polling-delay = <1000>; /* milliseconds */
   /* trip-point-1 cooling device */
sustainable-power = <1000>; /* milliwatts */
/* thermal zone tsadc0 */
thermal-sensors = <&tsadc 0>;
   /* trips */
trips {
     /*
      *
      * power
      */
threshold: trip-point-0 {
       /* 70 70 tsadc */
temperature = <70000>; /* millicelsius */
       /* temperature-hysteresis */
hysteresis = <2000>; /* millicelsius */
type = "passive"; /* polling-delay-passive */
};
     /* */
target: trip-point-1 {
       /* 85 85 tsadc */
temperature = <85000>; /* millicelsius */
        /* temperature-hysteresis */
hysteresis = <2000>; /* millicelsius */
type = "passive"; /* polling-delay-passive */
};
     /* */
soc_crit: soc-crit {
       /* 115 115 tsadc */
temperature = <115000>; /* millicelsius */
       /* temperature-hysteresis */
hysteresis = <2000>; /* millicelsius */
type = "critical"; /* */
};
};
   /* cooling device cooling device */
cooling-maps {
map0 {
       /*
        * target trip cooling device
        * power allocater target
        */
trip = <&target>;
       /* A53 cooloing device THERMAL_NO_LIMIT */
cooling-device =
<&cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>; /* 4096/1024 */
};
map1 {
       /*
        * target trip cooling device
        * power allocater target
        */
trip = <&target>;
       /* A72 cooloing device THERMAL_NO_LIMIT */
cooling-device =
<&cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <1024>;/* 1024/1024 */
};
map2 {
       /*
        * target trip cooling device
        * power allocater target
        */
trip = <&target>;
       /* GPU cooloing device THERMAL_NO_LIMIT */
"Documentation/devicetree/bindings/thermal/thermal.txt" "Documentation/thermal/power_allocator.txt
"
3.3.4
1
70 85 115
cooling-device =
<&gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>;/* 4096/1024 */
};
};
};
/* thermal zone thermal zone */
gpu_thermal: gpu-thermal {
   /* */
polling-delay-passive = <100>; /* milliseconds */
   /* 1000ms */
polling-delay = <1000>; /* milliseconds */
   /* thermal zone tsadc1 */
thermal-sensors = <&tsadc 1>;
};
};
thermal_zones: thermal-zones {
soc_thermal: soc-thermal {
....
trips {
threshold: trip-point-0 {
       /*
        * 70
        * sustainable-power
        */
temperature = <70000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
target: trip-point-1 {
       /* 85 */
temperature = <85000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
soc_crit: soc-crit {
       /* 115 */
temperature = <115000>; /* millicelsius */
2 cooling device
RK3399 CPU GPU
CPU
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
   ...
 }
};
thermal_zones: thermal-zones {
soc_thermal: soc-thermal {
...
   /* A53 A72 GPU cooling device */
cooling-maps {
map0 {
trip = <&target>;
cooling-device =
<&cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>;
};
map1 {
trip = <&target>;
cooling-device =
<&cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <1024>;
};
map2 {
trip = <&target>;
cooling-device =
<&gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>;
};
};
   ...
};
};
thermal_zones: thermal-zones {
soc_thermal: soc-thermal {
...
   /* A53 A72 cooling device */
cooling-maps {
map0 {
trip = <&target>;
cooling-device =
<&cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>;
3 sustainable-power
1 70 85 70 power
power power
70 sustainable
70 75
85 75 power cooling
device
RK3399 A53 A72 GPU 1416MHz 1125mV
1800MHz 1200mV 800MHz 1100mV
};
map1 {
trip = <&target>;
cooling-device =
<&cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <1024>;
};
};
   ...
};
};
/* a b c d C DTSI T V */
t_scale = (a * T^3) + (b * T^2) + (c * T) + d
 v_scale = V^3
 P(s)= C * T_scale * V_scale
/* C DTSI V F */
P(d)= C * V^2 * F
A53 C = 100 dynamic-power-coefficient 100 V = 1125mV F = 1416MHz
P_d_a53 = 100 * 1125 * 1125 * 1416 * 4 / 1000000000 = 716 mW
A72 C = 436 dynamic-power-coefficient 436 V = 1200mV F = 1800MHz
P_d_a72 = 436 * 1200 * 1200 * 1800 * 2 / 1000000000 = 2260 mW
GPU C = 733 dynamic-coefficient 733 V = 1100mV F = 800MHz
P_d_gpu = 733 * 1100 * 1100 * 800 / 1000000000 = 709 mW
GPU DTSI static-coefficient 411000 ts 32000 4700 -80 2C = 411000
a = 2b = -80 c = 4700 d = 32000 T = 75000mC V = 1100mV
t_scale = ( 2 * 75000 * 75000 * 75000 / 1000000 ) + ( -80 * 75000 * 75000 / 1000) +
 ( 4700 * 75000 ) + 32000 * 1000 =778250
v_scale = 1100 * 1100 * 1100 / 1000000 = 1331
75 75 power power sustainable
DTSI sustainable-power 1761 Antutu Geekbench trace
lisa
4 contribution
cooling device contribution 1024
A53 A72 A53 A72 A53
contribution
5 trace
menuconfig trace
P_s_gpu = 411000 * 778250 / 1000000 * 1331 / 1000000 = 425mW
P_max = P_d_a53 + P_d_a72 + P_d_gpu + P_s_gpu = 4110mW
GPU exel
sustainable + 2 * sustainable / (target- threshold) * (target- 75) = P_75
sustainable + 2 * sustainable / (85 - 70) * (85 - 75) = 4110
sustainable = 1761mW
thermal_zones: thermal-zones {
soc_thermal: soc-thermal {
...
cooling-maps {
map0 {
trip = <&target>;
cooling-device =
<&cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <4096>; /* 1024 4096 */
};
map1 {
trip = <&target>;
cooling-device =
<&cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
contribution = <1024>;
};
};
   ...
};
};
Kernel hacking--->
[*] Tracers--->
trace-cmd log lisa trace-cmd lisa lisa adb
trace-cmd push log
Ctrl+C log trace.dat
adb pull PC lisa trace.dat pull PC PC
trace-cmd trace.txt
trace-cmd log
trace
trace
adb pull
--- Tracers
[ ]  Kernel Function Tracer
[ ]  Enable trace events for preempt and irq disable/enable
[ ]  Interrupts-off Latency Tracer
[ ]  Preemption-off Latency Tracer
[ ]  Scheduling Latency Tracer
[*]  Trace process context switches and events
[ ]  Trace syscalls
[ ]  Create a snapshot trace buffer
Branch Profiling (No branch profiling) --->
[ ]  Trace max stack
[ ]  Support for tracing block IO actions
[ ]  Add tracepoint that benchmarks tracepoints
< >Ring buffer benchmark stress tester
[ ]  Ring buffer startup self test
[ ]  Show enum mappings for trace events
[*]  Trace gpio events
/* -b Kb DDR */
trace-cmd record -e thermal -e thermal_power_allocator -b 102400
trace-cmd report trace.dat > trace.txt
echo 1 > /sys/kernel/debug/tracing/events/thermal/enable
echo 1 > /sys/kernel/debug/tracing/events/thermal_power_allocator/enable
echo 1 > /sys/kernel/debug/tracing/tracing_on
cat /sys/kernel/debug/tracing/trace
/* trace.txt lisa */
adb pull /sys/kernel/debug/tracing/trace ./trace.txt
4
/sys/class/thermal/ DTSI thermal zone thermal
zone /sys/class/thermal/ thermal_zone0
/sys/class/thermal/ thermal_zone0 thermal_zone1
RK3399 /sys/class/thermal/thermal_zone0/
“Documentation/thermal/sysfs-api.txt”
5
5.1
menuconfig user_space
echo 0 > /sys/kernel/debug/tracing/tracing_on/* */
echo 0 > /sys/kernel/debug/tracing/trace    /* */
temp          /* */
available_policies /* */
policy /* */
sustainable_power /* power */
integral_cutoff /* PID I - <integral_cutoff */
k_d /* PID D */
k_i /* PID I */
k_po /* PID P */
k_pu /* PID P */
mode /* enabled disabled */
type /* thermal zone */
/* trips */
trip_point_0_hyst
trip_point_0_temp
trip_point_0_type
trip_point_1_hyst
trip_point_1_temp
trip_point_1_type
trip_point_2_hyst
trip_point_2_temp
trip_point_2_type
/* cooling devic cooling-maps */
cdev0 /* cooling devic cdev1 cdev2 */
cur_state /* cooling device */
max_state /* cooling device */
type /* cooling device */
cdev0_weight /* cooling devic power */
user_space policy user_space mode
disabled cdev cur_state 0
RK3399 user_space
mode disabled
5.2
thermal_zone0 thermal_zone1 temp
RK3399 CPU
GPU
<*> Generic Thermal sysfs driver--->
--- Generic Thermal sysfs driver
[*]  APIs to parse thermal data out of device tree
[*]  Enable writable trip points
Default Thermal governor (user_space) --->/* power_allocator user_space */
echo user_space > /sys/class/thermal/thermal_zone0/policy
echo disabled > /sys/class/thermal/thermal_zone0/mode
/* cdev */
echo 0 > /sys/class/thermal/thermal_zone0/cdev0/cur_state
echo 0 > /sys/class/thermal/thermal_zone0/cdev1/cur_state
echo 0 > /sys/class/thermal/thermal_zone0/cdev2/cur_state
cat /sys/class/thermal/thermal_zone0/temp
cat /sys/class/thermal/thermal_zone1/temp

Navigation menu