How to add a CPU Governor

suggest change

The CPU governor itself is just 1 C file, which is located in kernel_source/drivers/cpufreq/, for example: cpufreq_smartass2.c. You are responsible yourself for find the governor (look in an existing kernel repo for your device) But in order to successfully call and compile this file into your kernel you will have to make the following changes:

  1. Copy your governor file (cpufreq_govname.c) and browse to kernel_source/drivers/cpufreq, now paste it.
  2. and open Kconfig (this is the interface of the config menu layout) when adding a kernel, you want it to show up in your config. You can do that by adding the choice of governor.
config CPU_FREQ_GOV_GOVNAMEHERE
tristate "'gov_name_lowercase' cpufreq governor"
depends on CPU_FREQ
help
governor' - 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.

– can’t find the right place to put it? Just search for “CPU_FREQ_GOV_CONSERVATIVE”, and place the code beneath, same thing counts 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

Be ware that you do not call the native C file, but the O file! which is the compiled C file. Save the file. 4. Move to: kernel_source/includes/linux. Now open 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 you’ve done all steps successfully, you should be able to choose your governor from the menu (menuconfig, xconfig, gconfig, nconfig). Once checked in the menu it will be included to the kernel.

Commit that is nearly the same as above instructions: Add smartassV2 and lulzactive governor commit

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents