View Full Version : Quasar kernel governors and I/O schedulers manual



NOMIOMI
15th February 2012, 12:17
Due to popular demand, it's now time for a thread like this.

Post #1 - Governors
Post #2 - I/O Schedulers

#1 - Governors

So, what's a governor?


Consider a CPU, the processor of Optimus Black. Well, this CPU operates at
different frequencies (on stock: 300, 600, 800 and 1000 Mhz) and we usually
say it's a 1 Ghz (1000 Mhz) processor because that's the max frequency it
can go 100% stable.

Now, a governor is a CPUFreq driver. Like the name suggests, it is what
decides when to be on full speed at max frequency or when to be at min
or mid and how fast should it reach the max/min, should it be almost insta
and provide a good smoothness overall? Should it take longer and go 200
Mhz at a time and preserve battery? This and more is what a governor is.

There are many governors around, some for single-cores, some for dual-cores which I won't even refer to (jRCU). In stock you can find 5 governors, in Quasar kernel you can find much more. Most android and xda users don't even know half of governors I'll list as there is no android kernel out there with more governors than Quasar, only one has the same amount and this is a kernel made by my friend and fellow portuguese franciscofranco.

Listing of knzo-known governors:

Ondemand *&
[Only registered and activated users can see links]
Userspace *
Conservative *
Performance *
Interactive +
InteractiveX +
Smartass +
Smoothass +
BrazilianWax +
SavagedZen +
Minmax +&
Scary +
[Only registered and activated users can see links]

And now the official summary for each and brief comment by myself:

Ondemand:


/*
* drivers/cpufreq/cpufreq_ondemand.c
*
* Copyright (C) 2001 Russell King
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

Ondemand is the default choice due to its balanced settings which offers a good compromise between battery and performance. However, it has no suspend profiles and falls a bit short on performance in smartphones.

Powersave:


/*
* linux/drivers/cpufreq/cpufreq_powersave.c
*
[Only registered and activated users can see links]
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/

Powersave sets the max frequency at the same clock as the min frequency. Impossible for daily usage for obvious reasons. Used usually with SetCPU screen-off profiles in combo with Ondemand.

Userspace:


/*
* linux/drivers/cpufreq/cpufreq_userspace.c
*
* Copyright (C) 2001 Russell King
[Only registered and activated users can see links]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/

Userspace lets you manually set the frequencies. To be completely honest, I've never used it and I've never heard of anyone who uses it. I'm completely off on how it fares or if it even works or any of its kinks.

Conservative:


/*
* drivers/cpufreq/cpufreq_conservative.c
*
* Copyright (C) 2001 Russell King
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

Conservative is a slower Ondemand when it comes to ramping. For example, when you turn on the phone and start interacting with it, Ondemand will increase frequency until it reaches max at x speed. Conservative will do the same at x/2. Faster the ramping the more battery it consumes so conservative while a worse governor for performance it's also a good one for battery.

Performance:


/*
* linux/drivers/cpufreq/cpufreq_performance.c
*
[Only registered and activated users can see links]
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/

If Powersave governor is Yin, this one is Yang. It sets the min frequency the same as max frequency so the phone is always at max power. This is usually used with SetCPU profiles for when charging or plugged to computer. For obvious reasons can't be used in daily usage.

Interactive:


/*
* drivers/cpufreq/cpufreq_interactive.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
[Only registered and activated users can see links]
*
*/

While Conservative is a slower Ondemand, Interactive is a faster one. Ramping will be slightly faster so interaction will seem more snappy with battery comsumption just increasing a tiny bit. This has been the most popular governor for the past year.

InteractiveX:


/*
* drivers/cpufreq/cpufreq_interactive.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
[Only registered and activated users can see links]
*
*/

As you can see in the summary, this is Interactive with some modifications by imoseyon. Now instead of using the dirty SetCPU profiles method of locking the frequency to minimum when phone is asleep, the own governor will do that which is a cleaner method and with a better ramping management when coming out of sleep. Basically, it has Interactive's performance with better battery.

Smartass:


/*
* drivers/cpufreq/cpufreq_smartass2.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Author: Erasmux
*
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* SMP support based on mod by faux123
*
* requires to add
* EXPORT_SYMBOL_GPL(nr_running);
* at the end of kernel/sched.c
*
*/

This one has been increasingly popular and it's becoming the favorite one for Q3-4 2011. Smartass is based on Interactive but with some modifications, as well as built-in profiles. Recently, Erasmux released this v2 which by what people are saying it's very good. I suggest you go to this link for more informations. It's probably Quasar's best governor at the moment, along with Minmax.

Smoothass:


/*
* drivers/cpufreq/cpufreq_smoothass.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Author: Erasmux
*
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* requires to add
* EXPORT_SYMBOL_GPL(nr_running);
* at the end of kernel/sched.c
*
*/

One more jewel from Erasmux. As far as I know this is a Smartass v1 tuned for a more aggressive ramping, which means, more performance and snappiness, less battery.

BrazilianWax:



/*
* drivers/cpufreq/cpufreq_brazilianwax.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Author: Erasmux
*
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* requires to add
* EXPORT_SYMBOL_GPL(nr_running);
* at the end of kernel/sched.c
*
*/

Someone correct me if I'm wrong but this is basically the same as Smoothass.

SavagedZen:



/*
* drivers/cpufreq/cpufreq_savagedzen.c
*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Author: Joshua Seidel

* Based on the smartass governor by Erasmux
*
[Only registered and activated users can see links]
[Only registered and activated users can see links]
* --Modifications by arescode--
* adapted to stock (1 GHz) frequency by zacharias.maladroit
*
* requires to add
* EXPORT_SYMBOL_GPL(nr_running);
* at the end of kernel/sched.c
*
*/

Another Smartass-based kernel with many modifications aiming to attain both better battery and performance. And it succeeds in my opinion. I've used it in past devices, it's a very good overall governor, a balanced option.

Minmax:



/*
* drivers/cpufreq/cpufreq_minmax.c
*
* Copyright (C) 2001 Russell King
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This governor is an adapatation of the conservative governor.
* See the Documentation/cpu-freq/governors.txt for more information.
*
* Adapatation from conservative by Erasmux.
*/

This governor was a very pleasant surprise. Although an adaptation of Conservative governor it has probably the best performance of them all. Might fall shorter on battery than Smartass v2 but I owe it my best experiences in terms of snappiness so far, reason why I selected it as default governor for Nova. My personal favorite until I can draw a conclusion from using Smartass v2.

Scary:



/*
Scary governor based off of conservatives source with some
of smartasses features

For devs - If you're going to port this driver to other devices,
make sure to edit the default sleep frequencies & prev frequencies
or else you might be going outside your devices hardware limits.
*/

This is just a weird governor. It's based on Conservative which has a slower ramping than Ondemand but then again it has Smartass elements which is a governor with one the fastest rampings. I've heard some people like it but alas I never tried it myself.

To sum up:
(in my humble opinion)

Battery: 1st place - InteractiveX | 2nd place - Smartass | 3rd place - SavagedZen
Performance: 1st place - Minmax | 2nd place - Smartass2 | 3rd place - SavagedZen

NOMIOMI
15th February 2012, 12:22
Due to popular demand, it's now time for a thread like this.

Post #1 - Governors
Post #2 - I/O Schedulers

#2 - I/O Schedulers

So, what's a I/O Scheduler?



Input/output (I/O) scheduling is a term used to describe the method computer
operating systems decide the order that block I/O operations will be submitted
to storage volumes. I/O Scheduling is sometimes called 'disk scheduling'.

I/O schedulers can have many purposes depending on the goal of the I/O
scheduler, some common goals are:

- To minimize time wasted by hard disk seeks.
- To prioritize a certain processes' I/O requests.
- To give a share of the disk bandwidth to each running process.
- To guarantee that certain requests will be issued before a particular deadline.

There is not so much offer when it comes to I/O Schedulers and the improvements aren't nearly as visible as choosing a gung ho governor but trust me they are there. Just to name one improvement you could see is for example the opening and closing of applications.

Listing of knzo-known I/O Schedulers:

Noop *
[Only registered and activated users can see links]
CFQ *&
[Only registered and activated users can see links]
VR +
Simple +&
BFQ #


[Only registered and activated users can see links]

And now a summary for each and brief comment by myself:

Noop:



The NOOP scheduler inserts all incoming I/O requests into a simple, unordered
FIFO queue and implements request merging.

The scheduler assumes I/O performance optimization will be handled at some
other layer of the I/O hierarchy; e.g., at the block device; by an intelligent HBA
such as a Serial Attached SCSI (SAS) RAID controller or by an externally
attached controller such as a storage subsystem accessed through a switched
Storage Area Network).

NOOP scheduler is best used with solid state devices such as flash memory
or in general with devices that do not depend on mechanical movement to
access data (meaning typical "hard disk" drive technology consisting of seek
time primarily, plus rotational latency). Such non-mechanical devices do not
require re-ordering of multiple I/O requests, a technique that groups together
I/O requests that are physically close together on the disk, thereby reducing
average seek time and the variability of I/O service time.

Noop isn't actually that bad. It's a simple I/O Scheduler and when it comes to Android, the simplest the better.
I think in G1 one known "tweak" was to set Noop as default I/O Scheduler.

Anticipatory:



Anticipatory scheduling is an algorithm for scheduling hard disk input/output.
It seeks to increase the efficiency of disk utilization by "anticipating"
synchronous read operations.

"Deceptive idleness" is a situation where a process appears to be finished
reading from the disk when it is actually processing data in preparation of
the next read operation. This will cause a normal work-conserving I/O
scheduler to switch to servicing I/O from an unrelated process. This situation
is detrimental to the throughput of synchronous reads, as it degenerates into
a seeking workload. Anticipatory scheduling overcomes deceptive idleness
by pausing for a short time (a few milliseconds) after a read operation in
anticipation of another close-by read requests.

I have no idea if this fares well in Android devices. It's disabled in stock kernel and also in Quasar kernel since I've never heard of anyone using it or even recommending it. I read it's more in servers and what nots.

CFQ:



CFQ, also known as "Completely Fair Queuing", is an I/O scheduler for the
Linux kernel which was written in 2003 by Jens Axboe.

CFQ works by placing synchronous requests submitted by processes into
a number of per-process queues and then allocating timeslices for each of the
queues to access the disk. The length of the time slice and the number of
requests a queue is allowed to submit depends on the IO priority of the given
process. Asynchronous requests for all processes are batched together in fewer
queues, one per priority. While CFQ does not do explicit anticipatory IO
scheduling, it achieves the same effect of having good aggregate throughput for
the system as a whole, by allowing a process queue to idle at the end of
synchronous IO thereby "anticipating" further close IO from that process. It can
be considered a natural extension of granting IO time slices to a process.

Well, like Ondemand is to governors, CFQ is to I/O Schedulers. It's the most balanced one, aiming to perform well in most scenarios. However, in Android since things work differently, it's not the most suitable I/O Schedulers. There are many tweaks spreaded throughout XDA for improving this baby.

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.

Deadline is actually quite popular along with BFQ. It is used in some known kernels for example Netarchy's for Nexus S. However, even though it's better than CFQ for Android devices it still falls short in comparison with VR.

VR:



/*
* V(R) I/O Scheduler
*
[Only registered and activated users can see links]
*
*
* The algorithm:
*
* The next request is decided based on its distance from the last
* request, with a multiplicative penalty of `rev_penalty' applied
* for reversing the head direction. A rev_penalty of 1 means SSTF
* behaviour. As this variable is increased, the algorithm approaches
* pure SCAN. Setting rev_penalty to 0 forces SCAN.
*
* Async and synch requests are not treated seperately. Instead we
* rely on deadlines to ensure fairness.
*
*/

VR is a very good I/O Scheduler with Deadline elements. Probably the best for MTD Android devices and it's used also in known kernels such as IntersectRaven's for Nexus One. It's probably the one who can score the most in benchmarks but it's also one of the most... unstable. Its performance fluctuates, it can peak above average or it can go below it. But when it peaks... it's the best.

Simple:



/*
* Simple IO scheduler
* Based on Noop, Deadline and V(R) IO schedulers.
*
[Only registered and activated users can see links]
*
*
* This algorithm does not do any kind of sorting, as it is aimed for
* aleatory access devices, but it does some basic merging. We try to
* keep minimum overhead to achieve low latency.
*
* Asynchronous and synchronous requests are not treated separately, but
* we relay on deadlines to ensure fairness.
*
*/

Like the name suggests, Simple I/O is a simple one. Remember me saying that I/O Schedulers for Android devices, the simpler the better? This is such a case. Especially for EMMC devices. It's reliable and while not as good as VR when it peaks, it's still one of the best performance-wise. It's at the moment the default one in Quasar kernel.

BFQ:



/*
* BFQ, or Budget Fair Queueing, disk scheduler.
*
* Based on ideas and code from CFQ:
[Only registered and activated users can see links]
*
[Only registered and activated users can see links]
[Only registered and activated users can see links]
*
* Licensed under the GPL-2 as detailed in the accompanying COPYING.BFQ file.
*
* BFQ is a proportional share disk scheduling algorithm based on the
* slice-by-slice service scheme of CFQ. But BFQ assigns budgets,
* measured in number of sectors, to tasks instead of time slices.
* The disk is not granted to the active task for a given time slice,
* but until it has exahusted its assigned budget. This change from
* the time to the service domain allows BFQ to distribute the disk
* bandwidth among tasks as desired, without any distortion due to
* ZBR, workload fluctuations or other factors. BFQ uses an ad hoc
* internal scheduler, called B-WF2Q+, to schedule tasks according to
* their budgets. Thanks to this accurate scheduler, BFQ can afford
* to assign high budgets to disk-bound non-seeky tasks (to boost the
* throughput), and yet guarantee low latencies to interactive and
* soft real-time applications.
*
*/


Here it is, the wrongly assumed best I/O Scheduler which happens to be the most popular one. It's based in CFQ but it has an inferior performance than VR or Simple, even if it's BFQv2 (although it seems to perform well in USB transfers rate).

To sum up:
(in my humble opinion)

Performance: 1st place - VR
Reliability: 1st place - Simple