在kernel中实现了两个driver,一个负责控制开关CPU的核数,叫做hot-plug驱动,另一个负责调整CPU的频率,叫做DVFS驱动。kernel中的driver会根据系统的负载,自动调整使用几个CPU和调整CPU频率。如果负载高了,提高频率,或者多开几个核,或者开大核。如果负载降下去了,就可以关大核,关核,降频。

以下是两个知名手机厂商开源的config配置文档:

60 CONFIG_CPU_FREQ=y                                                | 446 CONFIG_CPU_FREQ=y61 CONFIG_CPU_FREQ_STAT_DETAILS=y                                   | 447 CONFIG_CPU_FREQ_STAT=y62 CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE=y                        | 448 CONFIG_CPU_FREQ_STAT_DETAILS=y63 CONFIG_CPU_FREQ_GOV_PERFORMANCE=y                                | 449 # CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set64 CONFIG_CPU_FREQ_GOV_POWERSAVE=y                                  | 450 # CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set                                        65 CONFIG_CPU_FREQ_GOV_USERSPACE=y                                  | 451 # CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set66 CONFIG_CPU_FREQ_GOV_ONDEMAND=y  # CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set67 CONFIG_NET=y                                                     | 453 # CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set68 CONFIG_PACKET=y                                                  | 454 CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE=y69 CONFIG_UNIX=y                                                    | 455 # CONFIG_CPU_FREQ_GOV_PERFORMANCE is not set70 CONFIG_XFRM_MIGRATE=y                                            | 456 # CONFIG_CPU_FREQ_GOV_POWERSAVE is not set71 CONFIG_NET_KEY=y                                                 | 457 # CONFIG_CPU_FREQ_GOV_USERSPACE is not set72 CONFIG_INET=y                                                    | 458 # CONFIG_CPU_FREQ_GOV_ONDEMAND is not set73 CONFIG_IP_MULTICAST=y                                            | 459 CONFIG_CPU_FREQ_GOV_INTERACTIVE=y74 CONFIG_IP_ADVANCED_ROUTER=y                                      | 460 # CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set75 CONFIG_IP_MULTIPLE_TABLES=y                                      | 461 # CONFIG_CPUFREQ_DT is not set

在adb shell命令下,和cpu频率相关的目录:
/sys/devices/system/cpu/cpuX, X表示cpu number.
:/sys/devices/system/cpu/cpu0/cpufreq # ls
affected_cpus              related_cpus                  scaling_governor
cpuinfo_cur_freq           scaling_available_frequencies scaling_max_freq
cpuinfo_max_freq           scaling_available_governors   scaling_min_freq
cpuinfo_min_freq           scaling_cur_freq              scaling_setspeed
cpuinfo_transition_latency scaling_driver                stats

这些文件节点的读写属性:

cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);936 cpufreq_freq_attr_ro(cpuinfo_min_freq);937 cpufreq_freq_attr_ro(cpuinfo_max_freq);938 cpufreq_freq_attr_ro(cpuinfo_transition_latency);939 cpufreq_freq_attr_ro(scaling_available_governors);940 cpufreq_freq_attr_ro(scaling_driver);941 cpufreq_freq_attr_ro(scaling_cur_freq);942 cpufreq_freq_attr_ro(bios_limit);943 cpufreq_freq_attr_ro(related_cpus);944 cpufreq_freq_attr_ro(affected_cpus);945 cpufreq_freq_attr_rw(scaling_min_freq);946 cpufreq_freq_attr_rw(scaling_max_freq);                                                                                                                                                   947 cpufreq_freq_attr_rw(scaling_governor);948 cpufreq_freq_attr_rw(scaling_setspeed);

cpuinfo_cur_freq: 当前cpu正在运行的工作频率
cpuinfo_max_freq:该文件指定了处理器能够运行的最高工作频率 (单位: 千赫兹)
cpuinfo_min_freq :该文件指定了处理器能够运行的最低工作频率 (单位: 千赫兹)
cpuinfo_transition_latency:该文件定义了处理器在两个不同频率之间切换时所需要的时间  (单位: 纳秒)
scaling_available_frequencies:所有支持的主频率列表  (单位: 千赫兹)
scaling_available_governors:该文件显示当前内核中支持的所有cpufreq governor类型
scaling_cur_freq:被governor和cpufreq核决定的当前CPU工作频率。该频率是内核认为该CPU当前运行的主频率
scaling_driver:该文件显示该CPU正在使用何种cpufreq driver
scaling_governor:通过echo命令,能够改变当前处理器的governor类型
scaling_max_freq:显示当前policy的上下限  (单位: 千赫兹)需要注意的是,当改变cpu policy时,需要首先设置scaling_max_freq, 然后才是scaling_min_freq

scaling_setspeed:如果用户选择了“userspace” governor, 那么可以设置cpu工作主频率到某一个指定值。只需要这个值在scaling_min_freq 和 scaling_max_freq之间即可。

工作模式:cat scaling_available_governors
:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_governors
ondemand userspace powersave interactive performance
CPU的频率调节模式:
1. Performance.  不考虑耗电,只用最高频率。
2. Interactive.  直接上最高频率,然后看CPU负荷慢慢降低。
3. Powersave.    通常以最低频率运行,流畅度会受影响,一般不会用这个吧!
4. Userspace.    可以在用户空间手动调节频率。
5. Ondemand.    定期检查负载,根据负载来调节频率。

对于这项飞思卡尔的实现:
默认使用了performance,不过freescale在boot完成后改成了interactive.
device/fsl/tek_mx6/init.rc:
on property:sys.boot_completed=1
# Set default CPU frequency governor
# Set timer 40ms, min sample 60ms,hispeed at cpufreq MAX freq in freq_table at load 40%
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor interactive
最终可通过scaling_governor文件查看。

工作频率:
当前支持的cpu调节模式可通过 scaling_available_frequencies 查看。
:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequencies
1092000 988000 858000 793000 637000 494000 364000 221000

相关的数据结构:
kernel-4.4$ vi ./include/linux/cpufreq.h +59

struct cpufreq_policy {/* CPUs sharing clock, require sw coordination */cpumask_var_t        cpus;   /* Online CPUs only */cpumask_var_t     related_cpus; /* Online + Offline CPUs */cpumask_var_t     real_cpus; /* Related and present */unsigned int        shared_type; /* ACPI: ANY or ALL affected CPUsshould set cpufreq */unsigned int     cpu;    /* cpu managing this policy, must be online */struct clk        *clk;struct cpufreq_cpuinfo cpuinfo;/* see above */unsigned int     min;    /* in kHz */unsigned int        max;    /* in kHz */unsigned int        cur;    /* in kHz, only needed if cpufreq* governors are used */unsigned int        restore_freq; /* = policy->cur before transition */unsigned int     suspend_freq; /* freq to set during suspend */unsigned int      policy; /* see above */unsigned int     last_policy; /* policy before unplug */struct cpufreq_governor  *governor; /* see below */void          *governor_data;bool         governor_enabled; /* governor start/stop flag */char            last_governor[CPUFREQ_NAME_LEN]; /* last governor used */struct work_struct update; /* if update_policy() needs to be* called, but you're in IRQ context */struct cpufreq_user_policy user_policy;struct cpufreq_frequency_table   *freq_table;struct list_head        policy_list;struct kobject      kobj;struct completion  kobj_unregister;/** The rules for this semaphore:* - Any routine that wants to read from the policy structure will*   do a down_read on this semaphore.* - Any routine that will write to the policy structure and/or may take away*   the policy altogether (eg. CPU hotplug), will hold this lock in write*   mode before doing so.** Additional rules:* - Lock should not be held across*     __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT);*/struct rw_semaphore    rwsem;/** Fast switch flags:* - fast_switch_possible should be set by the driver if it can*   guarantee that frequency can be changed on any CPU sharing the*   policy and that the change will affect all of the policy CPUs then.* - fast_switch_enabled is to be set by governors that support fast*   freqnency switching with the help of cpufreq_enable_fast_switch().*/bool                    fast_switch_possible;bool                    fast_switch_enabled;/* Cached frequency lookup from cpufreq_driver_resolve_freq. */unsigned int cached_target_freq;int cached_resolved_idx;/* Synchronization for frequency transitions */bool           transition_ongoing; /* Tracks transition status */spinlock_t        transition_lock;wait_queue_head_t   transition_wait;struct task_struct  *transition_task; /* Task which is doing the transition *//* cpufreq-stats */struct cpufreq_stats   *stats;/* For cpufreq driver's internal use */void         *driver_data;
};

根据平台以及默认的最大频率来选择对应的频率列表。
所以降频有两种方法:
1. 直接编译静态修改频率列表。
2. 通过scaling_max_freq文件动态写入。

/ # cat /proc/cpufreq/cpufreq_ptpod_freq_volt
cat /proc/cpufreq/cpufreq_ptpod_freq_volt
[0] = { .cpufreq_khz = 1092000, .cpufreq_volt = 119375, .cpufreq_volt_org = 125000, },
[1] = { .cpufreq_khz = 988000,  .cpufreq_volt = 114375, .cpufreq_volt_org = 121875, },
[2] = { .cpufreq_khz = 858000,  .cpufreq_volt = 108125, .cpufreq_volt_org = 118750, },
[3] = { .cpufreq_khz = 793000,  .cpufreq_volt = 105000, .cpufreq_volt_org = 115000, },
[4] = { .cpufreq_khz = 637000,  .cpufreq_volt = 101250, .cpufreq_volt_org = 110000, },
[5] = { .cpufreq_khz = 494000,  .cpufreq_volt = 101250, .cpufreq_volt_org = 105000, },
[6] = { .cpufreq_khz = 364000,  .cpufreq_volt = 101250, .cpufreq_volt_org = 100000, },
[7] = { .cpufreq_khz = 221000,  .cpufreq_volt = 101250, .cpufreq_volt_org = 95000, },
/ # cat proc/cpufreq/cpufreq_oppidx
cat proc/cpufreq/cpufreq_oppidx
[MT_CPU_DVFS_LITTLE/0]
cpufreq_oppidx = 1
        OP(1092000, 119375),
        OP(988000, 114375),
        OP(858000, 108125),
        OP(793000, 105000),
        OP(637000, 101250),
        OP(494000, 101250),
        OP(364000, 101250),
        OP(221000, 101250),

CPU频率调节模式以及降频方法简介相关推荐

  1. Linux:CPU频率调节模式以及降频方法简介

    概述 cpufreq的核心功能,是通过调整CPU的电压和频率,来兼顾系统的性能和功耗.在不需要高性能时,降低电压和频率,以降低功耗:在需要高性能时,提高电压和频率,以提高性能. cpufreq 是一个 ...

  2. android 调整cpu频率,[IMX6DL][Android4.4] CPU频率调节模式以及降频方法

    Kernel branch: 3.0.35 CPU的频率调节模式: 1. Performance.  不考虑耗电,只用最高频率. 2. Interactive.  直接上最高频率,然后看CPU负荷慢慢 ...

  3. Android系统(MT6797)CPU频率工作模式以及调整频率的方法

    声明: 最近在做一款MT6797架构的Android平板的系统优化工作,公司总觉得平板运行不是很流畅,考虑到的一点是是不是平板的CPU被降频影响的性能上的损失太大,CPU降频这种操作一般就是为了能够省 ...

  4. ubuntu-CPU频率调节

    ubuntu - CPU 频率 调节(转) 选择并启用与CPU 相对应的内核模块 为确保接下来的工作是有意义的,首先确保您的CPU 频率 调节功能还没有启用~ # cd /sys/devices/sy ...

  5. IBM 客户拜访模式及特色销售方法简介

    IBM 客户拜访模式及特色销售方法简介 IBM 客户拜访模式及特色销售方法简介 在最近对合作伙伴的拜访中, 许多公司老总都会提到销售队伍缺乏经验, 如何培养和锻炼这些年轻的销售人员, 不再事无巨细, ...

  6. 关闭自动降频 linux,iPhone如何关闭降频?iPhone手动关闭降频方法[多图]

    iPhone手机最大的特点就是流畅,长时间流畅.这点就取决于他的系统了,但是前段时间爆出来的降频让大家很失望.现在ios11.3出来了,把选择权给了用户,今天我们就来教大家怎么手动关闭降频. 打开手机 ...

  7. 【Verilog基础】分频器(分频(频率变小,周期变大)、倍频(频率变大,周期变小)、体会降频方法)

    文章目录 一.分频器要点总结 二.偶数分频器 三.奇数分频器 一.分频器要点总结 1.为啥要有分频.倍频? (1)时钟通常由板载晶振或**PLL(锁相环)**产生 (2)板载晶振提供的时钟信号频率固定 ...

  8. Android 省电模式 降频吗,开启省电模式会降频吗

    满意答案 siyangjz 2017.02.01 采纳率:42%    等级:7 已帮助:61人 手机电量节省方法: 一.调低屏幕亮度 手机耗电最大的是屏幕,所以省电从调低屏幕亮度开始,不用担心把亮度 ...

  9. 华擎主板bios设置图解_【华擎Z170评测】BIOS设置及超频方法简介_华擎 Z170 超频方程式_主板评测-中关村在线...

    由于本次使用了是Intel酷睿i5-6600K处理器,默认频率为3.5GHz-3.9GHz,因此我们首先将处理器超频至4.5GHz,为了确定平台的稳定性,此时需要将处理器的电压调整到1.35V.具体操 ...

最新文章

  1. 计算机的医学应用,计算机在医学中的应用
  2. python调用接口实例化_python 类静态方法实例化另一个类对象的问题?
  3. Scala控制抽象:将一段代码作为参数传递给高阶函数去执行
  4. 一段文字,写给合唱团即将分别的我们
  5. 线上lnmp环境快速安装
  6. python mobile-hi.codemao.cn_使用thrift做c++,java和python的相互调用
  7. 数据库可视化工具Navicat
  8. http报文格式详解!
  9. 做本地服务业O2O要点有哪些 O2O营销模式未来发展趋势是什么?
  10. 搜狐CEO张朝阳决定分拆网游业务单独上市
  11. 台式电脑怎么调出计算机,台式电脑连接笔记本显示器的方法步骤
  12. 普通最小二乘法讲解OLS线性回归
  13. RFID在固定资产盘点系统中的应用
  14. 最全Visual Studio版本号对应表VisualStudioVersion
  15. BI PUBLISHER RTF模板制作PIVOT表和重分组
  16. 深入理解异或运算 xor 的含义——再探不使用加减乘除实现加法运算、不使用额外空间交换两个变量的值
  17. nbu还原oracle,NBU异机恢复ORACLE成功版本
  18. edge无法登录账户_系统天地教你解决win10 microsoft edge浏览器无法开的问题
  19. java如何给pdf加水印_java pdf加水印的方法
  20. 如何查看MindSpore的IR图

热门文章

  1. DMCTF writeup
  2. 肿瘤免疫疗法 | 细胞治疗和PD1/PDL1 | Tumor immunotherapy | cell therapy
  3. 十一. MySQL InnoDB 三大特性之 BufferPool
  4. swift 苹果登录
  5. 图形验证码接口及其重构思想
  6. 计算机进去pe怎么设置用户,电脑如何进入winpe模式?进入winpe模式的方法
  7. 【Unity国际版下载地址】
  8. int、time和timestamp区别
  9. oracle rebuild online,alter index rebuild
  10. android textview svg,Android中使用SVG与WebFont矢量图标