RK3588 CPU GPU NPU DDR fixed frequency and performance mode setting method

When you need to change RK3588 CPU GPU DDR NPU performance

debian11 View the frequency voltage table of RK3588 CPU GPU DDR NPU

rk3588_armsom_w3:~# cat /sys/kernel/debug/opp/opp_summary
 device                rate(Hz)    target(uV)    min(uV)    max(uV)
-------------------------------------------------------------------
 platform-fdab0000.npu
                      300000000       675000      675000      850000
                                      675000      675000      850000
                      400000000       675000      675000      850000
                                      675000      675000      850000
                      500000000       675000      675000      850000
                                      675000      675000      850000
                      600000000       675000      675000      850000
                                      675000      675000      850000
                      700000000       675000      675000      850000
                                      675000      675000      850000
                      800000000       700000      700000      850000
                                      700000      700000      850000
                      900000000       737500      737500      850000
                                      737500      737500      850000
                     1000000000       787500      787500      850000
                                      787500      787500      850000
 platform-dmc
                      528000000       675000      675000      875000
                                      700000      700000      750000
                     1068000000       700000      700000      875000
                                      712500      712500      750000
                     1560000000       775000      775000      875000
                                      725000      725000      750000
                     2112000000       850000      850000      875000
                                      750000      750000      750000
 platform-fb000000.gpu
                      300000000       675000      675000      850000
                                      675000      675000      850000
                      400000000       675000      675000      850000
                                      675000      675000      850000
                      500000000       675000      675000      850000
                                      675000      675000      850000
                      600000000       675000      675000      850000
                                      675000      675000      850000
                      700000000       675000      675000      850000
                                      675000      675000      850000
                      800000000       700000      700000      850000
                                      700000      700000      850000
                      900000000       750000      750000      850000
                                      750000      750000      850000
                     1000000000       800000      800000      850000
                                      800000      800000      850000
 cpu6
                      408000000       675000      675000     1000000
                                      675000      675000     1000000
                      600000000       675000      675000     1000000
                                      675000      675000     1000000
                      816000000       675000      675000     1000000
                                      675000      675000     1000000
                     1008000000       675000      675000     1000000
                                      675000      675000     1000000
                     1200000000       675000      675000     1000000
                                      675000      675000     1000000
                     1416000000       675000      675000     1000000
                                      675000      675000     1000000
                     1608000000       700000      700000     1000000
                                      700000      700000     1000000
                     1800000000       775000      775000     1000000
                                      775000      775000     1000000
                     2016000000       850000      850000     1000000
                                      850000      850000     1000000
 cpu4
                      408000000       675000      675000     1000000
                                      675000      675000     1000000
                      600000000       675000      675000     1000000
                                      675000      675000     1000000
                      816000000       675000      675000     1000000
                                      675000      675000     1000000
                     1008000000       675000      675000     1000000
                                      675000      675000     1000000
                     1200000000       675000      675000     1000000
                                      675000      675000     1000000
                     1416000000       675000      675000     1000000
                                      675000      675000     1000000
                     1608000000       700000      700000     1000000
                                      700000      700000     1000000
                     1800000000       775000      775000     1000000
                                      775000      775000     1000000
                     2016000000       850000      850000     1000000
                                      850000      850000     1000000
 cpu0
                      408000000       675000      675000      950000
                                      675000      675000      950000
                      600000000       675000      675000      950000
                                      675000      675000      950000
                      816000000       675000      675000      950000
                                      675000      675000      950000
                     1008000000       675000      675000      950000
                                      675000      675000      950000
                     1200000000       675000      675000      950000
                                      675000      675000      950000
                     1416000000       725000      725000      950000
                                      725000      725000      950000
                     1608000000       800000      800000      950000
                                      800000      800000      950000

CPU fixed frequency
The cpu of RK3588 is 4 A55+4 A76, divided into 3 groups for separate management, the nodes are:

/sys/devices/system/cpu/cpufreq/policy0:(4 A55:CPU0-3)
affected_cpus     cpuinfo_max_freq  cpuinfo_transition_latency  scaling_available_frequencies  scaling_cur_freq  scaling_governor  scaling_min_freq  stats
cpuinfo_cur_freq  cpuinfo_min_freq  related_cpus                scaling_available_governors    scaling_driver    scaling_max_freq  scaling_setspeed

/sys/devices/system/cpu/cpufreq/policy4:(2 A76:CPU4-5)
affected_cpus     cpuinfo_max_freq  cpuinfo_transition_latency  scaling_available_frequencies  scaling_cur_freq  scaling_governor  scaling_min_freq  stats
cpuinfo_cur_freq  cpuinfo_min_freq  related_cpus                scaling_available_governors    scaling_driver    scaling_max_freq  scaling_setspeed

/sys/devices/system/cpu/cpufreq/policy6:(2 A76:CPU6-7)
affected_cpus     cpuinfo_max_freq  cpuinfo_transition_latency  scaling_available_frequencies  scaling_cur_freq  scaling_governor  scaling_min_freq  stats
cpuinfo_cur_freq  cpuinfo_min_freq  related_cpus                scaling_available_governors    scaling_driver    scaling_max_freq  scaling_setspeed

The above 3 CPUs are independently controlled, the following takes setting CPU6-7 as an example to illustrate how to set the frequency of CPU6-7

Get the frequency supported by the current CPU

rk3588_armsom_w3:/ $ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_available_frequencies
408000 600000 816000 1008000 1200000 1416000 1608000 1800000
408000 600000 816000 1008000 1200000 1416000 1608000 1800000 2016000 2208000 2304000
408000 600000 816000 1008000 1200000 1416000 1608000 1800000 2016000 2208000 2352000

Get the operating mode of the cpu

rk3588_armsom_w3:/ $ cat /sys/devices/system/cpu/cpufreq/policy6/scaling_available_governors
interactive conservative ondemand userspace powersave performance schedutil

The default is the automatic frequency conversion mode: schedutil (if it is restored, it can be set to this mode)

Set manual fixed frequency mode: userspace

rk3588_armsom_w3:/ $ su
rk3588_armsom_w3:/ # echo userspace > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor

Set frequency to 2352000

rk3588_armsom_w3:/ # echo 2352000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_setspeed

Confirm whether the setting is successful

rk3588_armsom_w3:/ # cat /sys/devices/system/cpu/cpufreq/policy6/cpuinfo_cur_freq
2352000

The other two groups of CPUs are also set in a similar way, just operate the corresponding nodes.

GPU fixed frequency
GPU node path

rk3588_armsom_w3:/ # ls /sys/class/devfreq/fb000000.gpu/
available_frequencies  cur_freq  governor  max_freq  name              power      target_freq  trans_stat
available_governors    device    load      min_freq  polling_interval  subsystem  timer        uevent

Get the frequency supported by the GPU

rk3588_armsom_w3:/ # cat /sys/class/devfreq/fb000000.gpu/available_frequencies
1000000000 900000000 800000000 700000000 600000000 500000000 400000000 300000000

Get the mode the GPU is running in

rk3588_armsom_w3:/ # cat /sys/class/devfreq/fb000000.gpu/available_governors
rknpu_ondemand dmc_ondemand userspace powersave performance simple_ondemand

The default is the automatic frequency conversion mode: simple_ondemand (if it is restored, it can be set to this mode)

Set the frequency to 1000000000

# Set manual fixed frequency mode: userspace
rk3588_armsom_w3:/ # su
rk3588_armsom_w3:/ # echo userspace > /sys/class/devfreq/fb000000.gpu/governor
# Set the frequency to 1000000000
rk3588_armsom_w3:/ # echo 1000000000 > /sys/class/devfreq/fb000000.gpu/userspace/set_freq
# Confirm whether the setting is successful
rk3588_armsom_w3:/ # cat /sys/class/devfreq/fb000000.gpu/cur_freq
1000000000

View GPU load

# glmark2-es2
rk3588_armsom_w3:/ #  cat /sys/class/devfreq/fb000000.gpu/load
67@1000000000Hz

NPU fixed frequency
NPU node path

rk3588_armsom_w3:/ # ls /sys/class/devfreq/fdab0000.npu/
available_frequencies  cur_freq  governor  max_freq  name              power      target_freq  trans_stat
available_governors    device    load      min_freq  polling_interval  subsystem  timer        uevent

Get the frequency supported by the NPU

rk3588_armsom_w3:/ # cat /sys/class/devfreq/fdab0000.npu/available_frequencies
300000000 400000000 500000000 600000000 700000000 800000000 900000000 1000000000

Get the mode the NPU is running in

rk3588_armsom_w3:/ # cat /sys/class/devfreq/fdab0000.npu/available_governors
rknpu_ondemand dmc_ondemand userspace powersave performance simple_ondemand

The default is the automatic frequency conversion mode: simple_ondemand (if it is restored, it can be set to this mode)

Set the frequency to 1000000000

# Set manual fixed frequency mode: userspace
rk3588_armsom_w3:/ # su
rk3588_armsom_w3:/ # echo userspace > /sys/class/devfreq/fdab0000.npu/governor
# Set the frequency to 1000000000
rk3588_armsom_w3:/ # echo 1000000000 > /sys/class/devfreq/fdab0000.npu/userspace/set_freq
# Confirm whether the setting is successful
rk3588_armsom_w3:/ # cat /sys/class/devfreq/fdab0000.npu/cur_freq
1000000000

View NPU load

rk3588_armsom_w3:/ #  cat /sys/kernel/debug/rknpu/load
NPU load:  Core0:  0%, Core1:  0%, Core2:  0%,

DDR fixed frequency
DDR node path

rk3588_armsom_w3:/ # ls /sys/class/devfreq/dmc/
available_frequencies  governor  polling_interval  timer
available_governors    load      power             trans_stat
cur_freq               max_freq  subsystem         uevent
device                 min_freq  system_status     upthreshold
downdifferential       name      target_freq

Get the frequency supported by the DDR

rk3588_armsom_w3:/ # cat /sys/class/devfreq/dmc/available_frequencies
528000000 1068000000 1560000000 2112000000

Get the mode the DDR is running in

rk3588_armsom_w3:/ # cat /sys/class/devfreq/dmc/available_governors
rknpu_ondemand dmc_ondemand userspace powersave performance simple_ondemand

The default is the automatic frequency conversion mode: dmc_ondemand (if it is restored, it can be set to this mode)

Set the frequency to 1000000000

# Set manual fixed frequency mode: userspace
rk3588_armsom_w3:/ # su
rk3588_armsom_w3:/ # echo userspace > /sys/class/devfreq/dmc/governor
# Set the frequency to 2112000000 
rk3588_armsom_w3:/ # echo 2112000000 > /sys/class/devfreq/dmc/userspace/set_freq
# Confirm whether the setting is successful
rk3588_armsom_w3:/ # cat /sys/class/devfreq/dmc/cur_freq     
2112000000 

View DDR load

rk3588_armsom_w3:/ # cat /sys/class/devfreq/dmc/load
57@2112000000Hz

CPU,GPU,NPU,DDR Performance Mode

rk3588_armsom_w3:/ # su
rk3588_armsom_w3:/ # echo performance > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
rk3588_armsom_w3:/ # echo performance > sys/class/devfreq/fb000000.gpu/governor
rk3588_armsom_w3:/ # echo performance > /sys/class/devfreq/dmc/governor
rk3588_armsom_w3:/ # echo performance > /sys/class/devfreq/fdab0000.npu/governor

Or add to startup script /etc/rc.local

The Power allocator temperature control strategy introduces PID (proportional-integral-derivative) control, and dynamically allocates to each cooling device according to the current temperature
power, when the temperature is low, the power that can be allocated is relatively large, that is, the frequency that can be run is high. As the temperature rises, the power that can be allocated gradually increases.
Gradually decreases, the operable frequency also gradually decreases, so as to reach the limit frequency according to the temperature.
If you want to turn off the temperature control, you need to add this patch

	thermal_zones: thermal-zones {
		soc_thermal: soc-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			sustainable-power = <2100>; /* milliwatts */

			thermal-sensors = <&tsadc 0>;
			trips {
				threshold: trip-point-0 {
-					temperature = <75000>;
+ 					temperature = <115000>;                                  
					hysteresis = <2000>;
					type = "passive";
				};
				target: trip-point-1 {
-					temperature = <85000>;
+ 					temperature = <115000>; 
					hysteresis = <2000>;
					type = "passive";
				};
				soc_crit: soc-crit {
					/* millicelsius */
					temperature = <115000>;
					/* millicelsius */
					hysteresis = <2000>;
					type = "critical";
				};
			};
			cooling-maps {
				map0 {
					trip = <&target>;
					cooling-device = <&cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
					contribution = <1024>;
				};
				map1 {
					trip = <&target>;
					cooling-device = <&cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
					contribution = <1024>;
				};
				map2 {
					trip = <&target>;
					cooling-device = <&cpu_b2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
					contribution = <1024>;
				};
				map3 {
					trip = <&target>;
					cooling-device = <&gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
					contribution = <1024>;
				};
			};
		};

		bigcore0_thermal: bigcore0-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 1>;
		};

		bigcore1_thermal: bigcore1-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 2>;
		};

		little_core_thermal: littlecore-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 3>;
		};

		center_thermal: center-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 4>;
		};

		gpu_thermal: gpu-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 5>;
		};

		npu_thermal: npu-thermal {
			polling-delay-passive = <20>; /* milliseconds */
			polling-delay = <1000>; /* milliseconds */
			thermal-sensors = <&tsadc 6>;
		};
	};

The maximum CPU frequency of RK3588 can reach 2.4G, and the main frequency of RK3588J and RK3588M will be reduced.
The device tree in the kernel is configured with 2256000000, 2304000000, 2352000000 and 2400000000 frequencies. However, the code will choose a suitable maximum frequency in 2.2-2.4G according to the PVTM information of the current master