全志Tina系统调频调压

全志Tina系统调压调频

1 模块功能介绍

​ 该模块主要负责CPU运行时的调频调压,达到节省功耗的目的。或者通过调整调频策略让CPU固定运行在某个频点,亦或者通过提高频率或者超频来完成某个功能需求(超频只能用来测试,不能用来量产产)。

2 DTS中的V-F表

​ 系统支持动态调频调压,则需要配置好V-F,即电压-频率对应关系,此表格需要大量测试此对应关系的稳定性后方可做产品量产。

2.1 DTS配置说明

	#### 2.1.1 芯片代号级配置,只要配置CPU使用那一份V-F表,在目录arch/arm/boot/dts/CHIP.dtsi,如V833为sun8iw19.dtsi
cpus {
		enable-method = "allwinner,sun8iw19p1";
		#address-cells = <1>;
		#size-cells = <0>;

		cpu0: cpu@0 {
			device_type = "cpu";
			compatible = "arm,cortex-a7";
			reg = <0x0>;
			enable-method = "psci";
			clocks = <&clk_pll_cpu>;
			clock-frequency = <1008000000>;
			clock-latency = <2000000>;
		/* if divide bin <&cpu_opp_l_table0 &cpu_opp_l_table1> */
			operating-points-v2 = <&cpu_opp_l_table0>;
			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0 &SYS_SLEEP_0>;
			cooling-min-level = <5>;
			cooling-max-level = <0>;
			#cooling-cells = <2>; /* min followed by max */
			dynamic-power-coefficient = <150>;
		};
		......
}
  • 此SOC为单核,所以只有一个cpu0节点,节点中有一个属性operating-points-v2就是对V-F表的引用

    • operating-points-v2 = <&cpu_opp_l_table0>

      此dts节点中记录了系统可以动态调节的几个频点

2.2 板级DTS配置

​ 在Tina系统中的板级dts配置,device/config/chips/CHIP/configs/板级型号/linux/board.dts,内容如下:

cpu_opp_l_table0: opp_l_table0 {
			/* compatible = "operating-points-v2"; */
			compatible = "allwinner,opp_l_table0";
			opp_count = <6>;
			opp-shared;

			op00 {
				opp-hz = /bits/ 64 <600000000>;
				opp-microvolt = <900000>;
				axi-bus-divide-ratio = <3>;
				clock-latency-ns = <2000000>;
			};

			opp01 {
				opp-hz = /bits/ 64 <816000000>;
				opp-microvolt = <900000>;
				axi-bus-divide-ratio = <3>;
				clock-latency-ns = <2000000>;
			};

			opp02 {
				opp-hz = /bits/ 64 <912000000>;
				opp-microvolt = <900000>;
				axi-bus-divide-ratio = <3>;
				clock-latency-ns = <2000000>;
			};

			opp03 {
				opp-hz = /bits/ 64 <1008000000>;
				opp-microvolt = <900000>;
				axi-bus-divide-ratio = <3>;
				clock-latency-ns = <2000000>;
			};

			opp04 {
				opp-hz = /bits/ 64 <1104000000>;
				opp-microvolt = <1000000>;
				axi-bus-divide-ratio = <3>;
				clock-latency-ns = <2000000>;
			};
};    

cpus {
    cpu@0 {
        cpu-supply = <&reg_dcdc3>;
    };
};

  • 此节点中记录了5个V-F电压频点,如需要增加频点则在opp04后面再增加即可,如增加12000MHz的频点:

    opp05 {
        opp-hz = /bits/ 64 <1200000000>;
        opp-microvolt = <1000000>;
        axi-bus-divide-ratio = <3>;
        clock-latency-ns = <2000000>;
    };
    
    
  • opp-hz : 为设置的频点,单位为HZ

  • opp-microvolt : 此频点对应的CPU电压

  • clock-latency-ns : 切换频率的延迟时间为2ms

  • cpu-supply : cpu接在pmu的哪路电压上

3 kernel选项配置

CPU Power Management  --->
    CPU Frequency scaling  --->
    	 [*] CPU Frequency scaling /*支持系统调频*/
    	 [*] CPU frequency time-in-state statistics
    		 Default CPUFreq governor (ondemand)  ---> /*该选项为选择系统启动后默认支持的调频策略*/
         -*-   'performance' governor
         < >   'powersave' governor /*此策略为系统以最小频率运行*/
         <*>   'userspace' governor for userspace frequency scaling /*user可以通过sysfs设置系统频率*/
         -*-   'ondemand' cpufreq policy governor  /*默认选择ondemand即系统动态调频*/
         < >   'conservative' cpufreq governor 	/**/
         < >   'interactive' cpufreq policy governor
             *** CPU frequency scaling drivers ***
         <*>   Generic DT based cpufreq driver /*在Linux自带的cpufreq driver基础上修改来实现调频*/
 	     [ ]   SUNXI CPUFreq support		   /*全志平台自己实现的cpufrq driver系统中只能存在一个cpufreq*/ 
         [ ]   SUNXI PWM CPUFreq support
         < >   CPU frequency scaling driver for Freescale QorIQ SoCs
  • 目前linux 4.9支持5种调频策略,如下:

    • performance governor: 最高性能,系统直接用最高频率,不考虑耗电。

    • powersave governor : 最低性能,系统直接用最低频率,以节省功耗。

    • userspace governor : 通过sysfs,用用户自行设置系统运行频率。

    • ondemand policy governor : 带调频策略,定时检查负载,然后根据负载来调节频率。

      ​ 负载低的时候降低 CPU 频率,这样省电,负载高的时候提高CPU 频率, 增加性能.

    • conservative policy governo: 和ondemand类似,ondemand会以最高或者对低的频率运行为主,而conservative会根据系统

      ​ 负载渐进式调整,直到找到系统比较适合的频率,这样会比较频繁的切换运行频率,延迟会比

      ​ ondemand跟严重。

    • interactive policy governor : 一开始直接用最高频率,然后根据 CPU 负载慢慢降低。

4 自行增加的频点不支持

​ 可能自己增加的V-F表,增加的频率太高,系统未能跑到设置的频点,可能是clk驱动限制的最高频率设置,可查看clk驱动确认当前系统所支持的最高频率,

通过查看此文件:drivers/clk/sunxi/clk-CHIP_tbl.c(如sun8iw19):

struct sunxi_clk_factor_freq factor_pllcpu_tbl[] = {
    ......
    PLLCPU(196,     0,     2,     1182000000U),
    PLLCPU(98,     0,     1,     1188000000U),
    PLLCPU(198,     0,     2,     1194000000U),
    PLLCPU(49,     0,     0,     1200000000U),
    PLLCPU(200,     0,     2,     1206000000U),
    PLLCPU(100,     0,     1,     1212000000U),
    PLLCPU(202,     0,     2,     1218000000U),
    PLLCPU(50,     0,     0,     1224000000U),
    PLLCPU(204,     0,     2,     1230000000U),
    PLLCPU(102,     0,     1,     1236000000U),
    PLLCPU(206,     0,     2,     1242000000U),
    PLLCPU(51,     0,     0,     1248000000U),
    PLLCPU(208,     0,     2,     1254000000U),
    PLLCPU(104,     0,     1,     1260000000U),
    PLLCPU(52,     0,     0,     1272000000U),
    PLLCPU(106,     0,     1,     1284000000U),
    PLLCPU(53,     0,     0,     1296000000U),
    /*
    PLLCPU(108,     0,     1,     1308000000U),
    PLLCPU(54,     0,     0,     1320000000U),
    PLLCPU(110,     0,     1,     1332000000U),
    PLLCPU(55,     0,     0,     1344000000U),
    PLLCPU(112,     0,     1,     1356000000U),
    PLLCPU(56,     0,     0,     1368000000U),
    PLLCPU(114,     0,     1,     1380000000U),
    PLLCPU(57,     0,     0,     1392000000U),
    PLLCPU(116,     0,     1,     1404000000U),
    PLLCPU(58,     0,     0,     1416000000U),
    PLLCPU(118,     0,     1,     1428000000U),
    ......
    */
}
  • factor_pllcpu_tbl :此数组列出了当前cpu支持的频率点,可以看到最高支持1296MH在
  • 如需要支持更高的频率,则需要在注释掉的频点放开。

##4 源码结构

drivers/cpufreq/
├── cpufreq-dt.c
└── cpufreq-dt-platdev.c

​ 这里只列出与cpufreq driver相关的代码:

  • cpufreq-dt.c : 为cpufreq driver,主要实现调频调压功能
  • cpufreq-dt-platdev.c : 注册一个cpufreq platform dev

5 调频sysfs节点说明

以下节点都位于此节点下:/sys/devices/system/cpu/cpufreq/policy0:

sysfs节点权限说明
affected_cpusR只显示online受此控制的CPU
related_cpusR显示online/offline受此控制的CPU
cpuinfo_cur_freqR当前系统运行频率
cpuinfo_max_freqR系统支持的最大运行频率
cpuinfo_min_freqR系统支持的最小运行频率
cpuinfo_transition_latencyR切换频率的延迟时间
scaling_available_frequenciesR系统支持的频率列表
scaling_available_governorsR系统支持的调频策略
scaling_cur_freqR系统当前设置的频率,可能会和cpuinfo_cur_freq,如此值高于系统限制的频率时,则cpuinfo_cur_freq为最高频率值
scaling_driverR调频驱动的名字
scaling_governorR/W调频策略
scaling_max_freqR/W软件最大调频频率,设置此值后,会限制系统的最大频率
scaling_min_freqR/W软件最小调频评率,设置此值后,会限制系统的最小频率
scaling_setspeedR/W用于userspace governor策略时,用户可对节点写入需要的频率,进行系统调频

6 获取电压频率表

6.1 挂载debugfs节点
mount -t debugfs none /sys/kernel/debug/

6.2 使用linux原生节点查看

  • 查看系统支持的所有的频率

     cat /sys/kernel/debug/opp/cpu0/opp*/rate_hz
    1008000000
    1104000000
    1200000000
    1400000000
    1500000000
    1800000000
    600000000
    816000000
    912000000
    
  • 查看V-F对应关系

    cat /sys/kernel/debug/opp/cpu0/opp*/u_volt_target
    900000
    1000000
    1000000
    1200000
    1200000
    1200000
    900000
    900000
    900000
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值