参考内核5.x,代码路径是在drivers/devfreq/,devfreq的代码定义是:Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework for Non-CPU Devices。而CPU动态调频是drivers/cpufreq,devfreq是基于cpufreq而来。
第一次引入这个特性描述:
PM: Introduce devfreq: generic DVFS framework with device-specific OPPs
With OPPs, a device may have multiple operable frequency and voltage sets. However, there can be multiple possible operable sets and a system will need to choose one from them. In order to reduce the power consumption (by reducing frequency and voltage) without affecting the performance too much, a Dynamic Voltage and Frequency Scaling (DVFS) scheme may be used.
This patch introduces the DVFS capability to non-CPU devices with OPPs. DVFS is a techique whereby the frequency and supplied voltage of a device is adjusted on-the-fly. DVFS usually sets the frequency as low as possible with given conditions (such as QoS assurance) and adjusts voltage according to the chosen frequency in order to reduce power consumption and heat dissipation.
The generic DVFS for devices, devfreq, may appear quite similar with /drivers/cpufreq. However, cpufreq does not allow to have multiple devices registered and is not suitable to have multiple heterogenous devices with different (but simple) governors.
Normally, DVFS mechanism controls frequency based on the demand for the device, and then, chooses voltage based on the chosen frequency. devfreq also controls the frequency based on the governor's frequency recommendation and let OPP pick up the pair of frequency and voltage based on the recommended frequency. Then, the chosen OPP is passed to device driver's "target" callback.
OPP是Operating Performance Point缩写,定义如下:
Complex SoCs of today consists of a multiple sub-modules working in conjunction. In an operational system executing varied use cases, not all modules in the SoC need to function at their highest performing frequency all the time. To facilitate this, sub-modules in a SoC are grouped into domains, allowing some domains to run at lower voltage and frequency while other domains run at voltage/frequency pairs that are higher.
The set of discrete tuples consisting of frequency and voltage pairs that the device will support per domain are called Operating Performance Points or OPPs.
简单说比如DDR有2个OPPs,分别是{1.8G, 1.3V},{1G, 1V},任君选择。
ok,基于OOPs,为了降低功耗而又不影响太多性能,DVFS由此而生。
devfreq和cpufreq的区别就是:
cpufreq does not allow to have multiple devices registered and is not suitable to have multiple heterogenous devices with different (but simple) governors.
Note that these are given only as basic examples for governors and any devices with devfreq may implement their own governors with the drivers and use them.
passive governor是后来加入的,看下提交原因:
The following governors are independently used for one device driver which don't give the influence to other device drviers and also don't receive the effect from other device drivers.
ok,下面主要看下devfreq.c governor相关:
structdevfreq_governor { structlist_headnode;
constchar name[DEVFREQ_NAME_LEN]; constunsignedint immutable; int (*get_target_freq)(struct devfreq *this, unsignedlong *freq); int (*event_handler)(struct devfreq *devfreq, unsignedint event, void *data); };
immutable如果是1就是governor运行时不能再变了。
/* The list of all device-devfreq governors */ staticLIST_HEAD(devfreq_governor_list);