How to add a CPU Governor
suggest changeThe CPU governor itself is one C file, located in kernel_source/drivers/cpufreq/, for example cpufreq_smartass2.c. You are responsible for finding the governor in an existing kernel repo for your device. To compile that file into your kernel, make the following changes:
- Copy your governor file (cpufreq_govname.c) and browse to kernel_source/drivers/cpufreq, now paste it.
- Open
Kconfig(the config menu layout). Add a choice so the governor shows up in the config menu.
config CPU_FREQ_GOV_GOVNAMEHERE
tristate "'gov_name_lowercase' cpufreq governor"
depends on CPU_FREQ
help
'govname' - a custom governor!
for example, for smartassV2.
config CPU_FREQ_GOV_SMARTASS2
tristate "'smartassV2' cpufreq governor"
depends on CPU_FREQ
help
'smartassV2' - a "smart" optimized governor!
next to adding the choice, you also must declare the possibility that the governor gets chosen as default governor.
config CPU_FREQ_DEFAULT_GOV_GOVNAMEHERE
bool "gov_name_lowercase"
select CPU_FREQ_GOV_GOVNAMEHERE
help
Use the CPUFreq governor 'govname' as default.
for example, for smartassV2.
config CPU_FREQ_DEFAULT_GOV_SMARTASS2
bool "smartass2"
select CPU_FREQ_GOV_SMARTASS2
help
Use the CPUFreq governor 'smartassV2' as default.
If the right place is unclear, search for CPU_FREQ_GOV_CONSERVATIVE and place the new choice beneath it. Do the same for CPU_FREQ_DEFAULT_GOV_CONSERVATIVE.
Now that Kconfig is finished you can save and close the file. 3. While still in the /drivers/cpufreq folder, open Makefile. In Makefile, add the line corresponding to your CPU Governor. for example:
obj-$(CONFIG_CPU_FREQ_GOV_SMARTASS2) += cpufreq_smartass2.o
The Makefile names the object file, cpufreq_smartass2.o, not the .c file. Save the file. 4. Open kernel_source/include/linux/cpufreq.h. Scroll down until you see something like:
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
extern struct cpufreq_governor cpufreq_gov_ondemand;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
(other cpu governors are also listed there)
Now add your entry with the selected CPU Governor, example:
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_SMARTASS2)
extern struct cpufreq_governor cpufreq_gov_smartass2;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_smartass2)
Save the file and close it.
The initial CPU governor setup is now complete. When these steps are done, the governor can be chosen from menuconfig, xconfig, gconfig, or nconfig. Once it is checked in the menu, it is built into the kernel.
Commit that is nearly the same as above instructions: Add smartassV2 and lulzactive governor commit