[Sony Xperia M2] Umesh1041:
What is a CPU governor?

A CPU governor in Android controls how the CPU raises and lowers its frequency in response to the demands the user is placing on their device. Governors are especially important in smartphones and tablets because they have a large impact on the apparent fluidity of the interface and the battery life of the device over a charge.

NOTE: You cannot change your CPU governor unless your phone is rooted and you have a ROM or app that lets you make a change. Also, different kernels (the intermediary software between your phone's hardware and the operating system) offer different sets of governors.

Available CPU governors for the Xperia M2

NOTE:not all govenors listed will be available for every rom or every kernel

1) Ondemand

2) Interactive

3) Intellidemand

4) Userspace

5) Powersave

6) Performance

1) Ondemand:

Default governor in almost all stock kernels. One main goal of the ondemand governor is to switch to max frequency as soon as there is a CPU activity detected to ensure the responsiveness of the system. (You can change this behavior using smooth scaling parameters, refer Siyah tweaks at the end of 3rd post.) Effectively, it uses the CPU busy time as the answer to "how critical is performance right now" question. So Ondemand jumps to maximum frequency when CPU is busy and decreases the frequency gradually when CPU is less loaded/apporaching idle. Even though many of us consider this a reliable governor, it falls short on battery saving and performance on default settings. One potential reason for ondemand governor being not very power efficient is that the governor decide the next target frequency by instant requirement during sampling interval. The instant requirement can response quickly to workload change, but it does not usually reflect workload real CPU usage requirement in a small longer time and it possibly causes frequently change between highest and lowest frequency.

2) Interactive:

Can be considered a faster ondemand. So more snappier, less battery. Interactive is designed for latency-sensitive, interactive workloads. Instead of sampling at every interval like ondemand, it determines how to scale up when CPU comes out of idle. The governor has the following advantages: 1) More consistent ramping, because existing governors do their CPU load sampling in a workqueue context, but interactive governor does this in a timer context, which gives more consistent CPU load sampling. 2) Higher priority for CPU frequency increase, thus giving the remaining tasks the CPU performance benefit, unlike existing governors which schedule ramp-up work to occur after your performance starved tasks have completed. Interactive It's an intelligent Ondemand because of stability optimizations. Why?????Sampling the CPU load every X ms (like Ondemand) can lead to under-powering the CPU for X ms, leading to dropped frames, stuttering UI, etc. Instead of sampling the CPU at a specified rate, the interactive governor will check whether to scale the CPU frequency up soon after coming out of idle. When the CPU comes out of idle, a timer is configured to fire within 1-2 ticks. If the CPU is very busy between exiting idle and when the timer fires, then we assume the CPU is underpowered and ramp to max frequency.

3) Intellidemand:

Intellidemand aka Intelligent Ondemand from Faux is yet another governor that's based on ondemand. The original intellidemand behaves differently according to GPU usage. When GPU is really busy (gaming, maps, benchmarking, etc) intellidemand behaves like ondemand. When GPU is 'idling' (or moderately busy), intellidemand limits max frequency to a step depending on frequencies available in your device/kernel for saving battery. This is called browsing mode.

To sum up, this is an intelligent ondemand that enters browsing mode to limit max frequency when GPU is idling, and (exits browsing mode) by behaving like ondemand when GPU is busy; to deliver performance for gaming and such. Intellidemand does not jump to highest frequency when screen is off.

4) Userspace:

This governor, exceptionally rare for the world of mobile devices, allows any program executed by the user to set the CPU's operating frequency. This governor is more common amongst servers or desktop PCs where an application (like a power profile app) needs privileges to set the CPU clockspeed.

5) Powersave

Powersave governor locks the CPU frequency at the lowest frequency set by the user.Can not be used as a screen-on or even screen-off (if scaling min frequency is too low).

6) Performance

The performance governor locks the phone's CPU at maximum frequency(Used for benchmarking)

GOVERNOR TWEAKS

PARAMETERS & TWEAKS:

1.ONDEMAND

[ PARAMETERS ]

i) sampling_rate - Measured in uS , this is how often the kernel look at the CPU usage and make decisions on what to do about the frequency. Higher values means CPU polls less often. For lower frequencies, this could be considered an advantage since it might not jump to next frequency very often, but for higher frequencies, the scale-down time will be increased.

ii) up_threshold - Measured in percentage 1-100, When CPU load reaches this point, governor will scale CPU up. Higher value means less responsiveness and lower values corresponds to more responsiveness at the cost of battery.

iii) powersave_bias - Default value is 0. Setting a higher value will bias the governor towards lower frequency steps. Use this if you want CPU to spend less time on higher frequencies. A better alternative would be to underclock to a lower frequency than using powersave bias.

iv) sampling_down_factor - In the simplest form, sampling_down_factor determines how often CPU should stay at higher frequencies when truly busy. Default behavior is fast switching to lower frequencies (1). Having sampling_down_factor set to 1 makes no changes from existing behavior (for the non-modified ondemand), but having sampling_down_factor set to a value greater than 1 causes it to act as a multiplier for the scheduling interval for re-evaluating the load when the CPU is at its highest clock frequency (which is scaling_max_freq) due to high load. This improves performance by reducing the overhead of load evaluation and helping the CPU stay at its highest clock frequency when it is truly busy, rather than shifting back and forth in speed. This tunable has no effect on behavior at lower frequencies/lower CPU loads.

v) down_differential - This factor indirectly calculate the 'down-threshold' of Ondemand. After completing sampling-down-factor*sampling-rate at max frequency because of high load, governor samples the load again to calculate an estimate of the new target frequency in a way that the lowest frequency will be chosen that would not trigger up_threshold in the next sample. Because triggering up-threshold will again cause CPU to scale up to max frequency. During this choice down_differential is taken into account as a breathing room value. Target frequency is calculated as max_load_freq / (up_threshold - down_differential). The obtained value might be a non-existent value in the freq_table and CPU driver will round it off to a value in freq_table. max_load_freq is the theoretical frequency at which CPU can handle 100% workload. It is usually a value below scaling_max_freq. See this post by AndereiLux for more info.

vi) freq_step - Whenever up-scaling logic is triggered the governor instructs the CPU to raise its frequency by freq_step

percentage of max allowed frequency. (max policy * (freq step / 100)). Ex: max policy is 1600 and freq step 21%, it will scale 1600 * 21% = 336. We have a 100MHz grained frequency table so it rounds up to the next 100MHz, hence 336 becomes 400. So say we're idling at 200MHz and the up-scaling logic gets triggered with the above settings, the next frequency will be 600MHz. Note that freq_step and smooth_scaling does pretty much the same thing.

[ SAMPLE TWEAKS ]

i) For battery:-

To bias ondemand towards battery saving, set high up-thresholds and higher sampling-rate. This way, governor polls less often and scales up less often.

up_threshold : 95

sampling_rate : 120000

sampling_down_factor : 1

down_differential : 5

ii) For performance:-

To bias ondemand towards performance, set low up-thresholds and lower sampling-rate. This way, governor polls more often and scales up quite often.

up_threshold : 70

sampling_rate : 50000

sampling_down_factor : 2

down_differential : 15

2.INTERACTIVE

[ PARAMETERS ]

i) hispeed_freq - Hi speed to bump to from lo speed when load burst. (Default value is scaling max freq)

ii) go_hispeed_load - Go to hi speed when CPU load at or above this value. (Similar to Up-Threshold in other governors)

iii) min_sample_time - The minimum amount of time to spend at a frequency before we can ramp down. (Sounds like Lazy governor?!)

iv) timer_rate - The sample rate of the timer used to increase frequency.

[ SAMPLE TWEAKS ]

i) For battery:-

go_hispeed_load : 95

hispeed_freq : 1000000

min_sample_time : 10000

timer_rate : 40000

For performance:-

Assuming your scaling_max_freq is equal to or above 1400 MHz

go_hispeed_load : 80

hispeed_freq : 1400000

min_sample_time : 40000

timer_rate : 20000

Additional Info:

Hotplugging drivers:

mpdecision: Qualcomm's default hotplugging driver. One of the most widely used hotplug drivers in all android devices.

msm_hotplug: Great battery life, a custom qualcomm based hotplugging driver by myflux. It is a popular choice for many users.

intelliplug: Great balance between battery life and performance. It is also a popular hotplug driver from faux123

Hotplug tunables guide

1) msm_mpdecision

[ PARAMETERS ]

startdelay = time until mpdecision starts doing it's magic (20000)

delay = time between checks (70)

pause = if something else plugs in the cpu, fall asleep for 10000ms (10 secs)

scroff_single_core = if the screen is off, don't plug in cpu1/2/3. Additionally: Unplug all cpus except cpu0 when screen is turned off (1)

enabled = enable(1) or disable(0) mpdecision. This does not affect scroff_single_core!

min_cpus = min cpus to be online, cannot be < 1.

max_cpus = max cpus to be online (if you set it to 2 and min_cpus to 1 you will basically have a dualcore)

idle_freq = a value against that will be checked if a core +/- is requested.

nwns_threshold_x = runqueue threshold, if this is reached cpuX will be hot/unplugged

twts_threshold_x = time threshold, this amount of time must have passed for the related action to be taken (hot/unplug)

I/O Schedulers:

Available I/O Schedulers for the Xperia M2:

1.Deadline

2.Noop

3.SIO (Simple I/O)

4.ROW

Deadline:

The goal of the Deadline scheduler is to attempt to guarantee a start service time for a request. It does that by imposing a deadline on all I/O operations to prevent starvation of requests. It also maintains two deadline queues, in addition to the sorted queues (both read and write). Deadline queues are basically sorted by their deadline (the expiration time), while the sorted queues are sorted by the sector number.

Before serving the next request, the Deadline scheduler decides which queue to use. Read queues are given a higher priority, because processes usually block on read operations. Next, the Deadline scheduler checks if the first request in the deadline queue has expired. Otherwise, the scheduler serves a batch of requests from the sorted queue. In both cases, the scheduler also serves a batch of requests following the chosen request in the sorted queue.

Benefits:

- Nearly a real-time scheduler.

- Excels in reducing latency of any given single I/O

- Best scheduler for database access and queries.

- Does quite well in benchmarks, most likely the best

- Like noop, a good scheduler for solid state/flash drives

Disadvantages:

- If the phone is overloaded, crashing or unexpected closure of processes can occur

The bottom line: A good all-round scheduler. If you want good performance

Noop:

Inserts all the incoming I/O requests to a First In First Out queue and implements request merging. Best used with storage devices that does not depend on mechanical movement to access data (yes, like our flash drives). Advantage here is that flash drives does not require reordering of multiple I/O requests unlike in normal hard drives.

Benefits:

- Serves I/O requests with least number of CPU cycles.

- Best for flash drives since there is no seeking penalty.

- Good data throughput on db systems

- Does great in benchmarks

- Is very reliable

Disadvantages:

- Reducing the number of CPU cycles corresponds to a simultaneous decline in performance

- Not the most responsive I/O scheduler

- Not very good at multitasking (especially heavy workloads)

The bottom line: Modern smartphones now use noop as the default scheduler due to the fact that it works quite well with flash based storage. However older devices may experience slower performance when selected. If you want a very simple I/O scheduler algorithm (because of battery life or latency reasons).

SIO (Simple I/O):

Simple I/O aims to keep minimum overhead to achieve low latency to serve I/O requests. No priority queue concepts, but only basic merging. SIO is a mix between noop & deadline. No reordering or sorting of requests.

Benefits:

- It is simple and stable.

- Minimized starvation for inquiries

- Not the best scheduler for benchmarks

Disadvantages:

- Slow random write speeds on flash drives as opposed to other schedulers.

- Sequential read speeds on flash drives are not as good as other IO schedulers

The bottom line: One of my favourite schedulers, it is a good all-round scheduler. People who want better performance should avoid using this.

ROW:

The ROW I/O scheduler was developed with the mobile devices needs in mind. In mobile devices, we favor user experience upon everything else, thus we want to give READ I/O requests as much priority as possible. In mobile devices we won't have as much parallel threads as on desktops. Usually it's a single thread or at most 2 simultaneous working threads for read & write. Favoring READ requests over WRITEs decreases the READ latency greatly. The main idea of the ROW scheduling policy is: If there are READ requests in pipe - dispatch them but don't starve the WRITE requests too much.

Benefits:

- Faster UI navigation and better overall phone experience

- Faster boot times and app launch times

Disadvantages:

- Not great for heavy multitasking

- Slower write speeds

The bottom line: Most phones will get a nice I/O boost, however experience varies between devices.

I/O Read Ahead Cache :

If you've used a custom kernel, you probably have heard of a term called Read Ahead cache or size. It's basically a cache for files that have been opened recently on your mobile device, so that they can be quickly accessed again if needed. By android default, this value has been set to 128kB. Usually having more cache means that more files can be cached, this can mean higher read and write speeds, but also this can result in more i/o latency. There is a point where increasing the I/O read ahead will have no benefit to read/write speeds.

Have a look at the graph below:

Recommendations:

For stability:

Use 128kB read-head value

For performance:

Use 2048kB read-head value

For any internal storage:

Use 128kB read-ahead value

For external SD cards with less than 8GB:

Use 128kB read-head value

For 16GB external SD cards:

Use 1024kB read-head value

For 32GB external SD cards:

Use 2048kB read-head value

For 64GB+ external SD cards:

Use 2048kB read-head value

What to remember:

- More isn't always better!

- Some SD cards can't handle high read ahead cache values, so make sure you have a genuine high quality SD card

- Default is good enough for most people, but isn't the best for performance

- Not all kernels allow users to change the I/O read ahead

- Performance difference varies between devices

In simple, a 1024kB read ahead should suit most devices today. 2048kB and 512kB are also good options I recommend too.

GPU Governors

MSM-Adreno: The default GPU governor used by qualcomm for their adreno GPUs. It is more performance orientated than ondemand therefore it gives better performance in games but less battery life. It is still a balanced governor for everyday usage.

Ondemand: Much like the CPU governor, Ondemand will ramp up the frequency when a load is detected. A good balance between performance and battery savings. This is a widely used governor in qualcomm devices.

Performance: As the name suggests, this keeps your GPU running at the max frequency. This is a governor if you want the best possible experience in games but you don't care about your battery life.

Powersave: Like the CPU governor, this keeps your GPU running at the lowest possible frequency. Best battery life, extreme lag in games.

I have spent many hours compiling all of the info on CPU governors and I/O schedulers.If you want to use the descriptions and info in your own thread, make sure to give me credit for gathering this info and also mention the others for their descriptions too. Remember that this info is for free and can be used for your own help and for others if you follow XDA rules

https://www.youtube.com/user/UmeshCahill