Adding Governors to your kernel

While building AOKP MM for my Samsung Galaxy S4, T-Mobile phone (SGH-M919 JFLTETMO), I made a rookie mistake. In my mind, AOKP users are the type to want the maximum performance out of their devices at all times. So, when I put AOKP 6 together, I figured that a good default parameter to set the governor to was Performance. This really makes AOKP MM pretty snappy. Not only does it make it snappy, but the CPU frequency is always near max while the screen is on, causing a tremendous waste of battery power. So, as an alternative, I set the CPU governor to Interactive, which was better, but still not very battery friendly.

In a constant quest to make things better, and to understand more about how things work, I decided to do something that I have never done before. I decided to add more governors to the kernel. Sure, I have compiled kernels before, it was part of my LPIC exams. To be honest, I was compiling kernels before I was compiling Android. Governors, however, was never something that I changed on a kernel before. For a desktop computer it is actually quite irrelevant in my opinion, because you are plugged in, you might as well use the best performance governor and disregard any sort of power saving settings. Of course, that doesn’t work very well for cell phones, and my inexperience showed in my last build.

So, on to the task at hand. The CPU frequency is set by the governor. A driver is needed to control the governor, so go to the proper folder:

$ cd ./kernel/samsung/jf/drivers/cpufreq

In this folder, you will do several things. The first is paste your new “.c” files for your new governor. You can find these files by breaking down or looking in source code for your kernel which is specific to your device (in the phone sense). In this case, I added BioShock and Yankactive governors to my system with these two files:


Then I modified the kconfig file from that same folder by adding these lines:

bool “BioShock”
Use the CPUFreq governor ‘BioShock’ as default.

bool “yankactive”
Use the CPUFreq governor ‘yankactive’ as default.

and these lines:

tristate “‘bioshock’ cpufreq bioshock”
depends on CPU_FREQ
‘bioshock’ – Mixing Lionheart and ConservitiveX

tristate “‘yankactive’ cpufreq policy governor”
depends on CPU_FREQ
‘yankactive’ – dynamic cpufreq policy governor

And edited the Makefile in that folder to say:

# CPUfreq governors
obj-$(CONFIG_CPU_FREQ_GOV_PERFORMANCE) += cpufreq_performance.o
obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o
obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o
obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o
obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o
obj-$(CONFIG_CPU_FREQ_GOV_INTERACTIVE) += cpufreq_interactive.o
obj-$(CONFIG_CPU_FREQ_GOV_YANKACTIVE) += cpufreq_yankactive.o
obj-$(CONFIG_CPU_FREQ_GOV_BIOSHOCK) += cpufreq_bioshock.o

And finaly, I added these lines to the ./kernel/samsung/jf/include/linux/cpufreq.h file:

extern struct cpufreq_governor cpufreq_gov_bioshock;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_bioshock)
extern struct cpufreq_governor cpufreq_gov_yankactive;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_yankactive)

The only thing left is to check your “.c” files to make sure that all dependencies are met! Lest you think that I am really, really smart, I will clue you in. While I have compiled kernels before, this was new to me. God graciously gave me a brain and fingers, which I used to look it up online. There are some really great guides about overclocking, under-volting, etc., and if you are interested, it will not take long to find them.

Bioshock is supposed to be a good “balance” between battery savings and performance, while yankactive is supposed to be even more battery conscious. Hopefully between these two kernel governors we can find one that will help with the battery consumption. For my next build, I set BioShock to be the new default kernel governor, as opposed to my old choice of Performance. Only time will tell if it actually makes a difference.

Linux – Keep it simple.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s