• twitter
  • facebook
  • rules
  • news
 
Page 1 of 8 1 2 3

[REF] Quasar kernel governors and I/O schedulers manual

  • Thread Tools: Tweet this thread
  • Vote for Thread to be Featured on the XDA Portal
Default [REF] Quasar kernel governors and I/O schedulers manual

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?

Code:
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 *&
  • Powersave *@
  • Userspace *
  • Conservative *
  • Performance *
  • Interactive +
  • InteractiveX +
  • Smartass +
  • Smoothass +
  • BrazilianWax +
  • SavagedZen +
  • Minmax +&
  • Scary +

Legend: & - default | @ - disabled by default | * - exists in stock kernel | + - added in Quasar kernel

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

Ondemand:
Code:
/*
 *  drivers/cpufreq/cpufreq_ondemand.c
 *
 *  Copyright (C)  2001 Russell King
 *            (C)  2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
 *                      Jun Nakajima <jun.nakajima@intel.com>
 *
 * 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:

Code:
/*
 *  linux/drivers/cpufreq/cpufreq_powersave.c
 *
 *  Copyright (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
 *
 *
 * 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:

Code:
/*
 *  linux/drivers/cpufreq/cpufreq_userspace.c
 *
 *  Copyright (C)  2001 Russell King
 *            (C)  2002 - 2004 Dominik Brodowski <linux@brodo.de>
 *
 * 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:

Code:
/*
 *  drivers/cpufreq/cpufreq_conservative.c
 *
 *  Copyright (C)  2001 Russell King
 *            (C)  2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
 *                      Jun Nakajima <jun.nakajima@intel.com>
 *            (C)  2009 Alexander Clouter <alex@digriz.org.uk>
 *
 * 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:

Code:
/*
 *  linux/drivers/cpufreq/cpufreq_performance.c
 *
 *  Copyright (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
 *
 *
 * 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:

Code:
/*
 * 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.
 *
 * Author: Mike Chan (mike@android.com)
 *
 */

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:

Code:
/*
 * 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.
 *
 * Author: Mike Chan (mike@android.com) - modified for suspend/wake by imoseyon
 *
 */

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:

Code:
/*
 * 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
 *
 * Based on the interactive governor By Mike Chan (mike@android.com)
 * which was adaptated to 2.6.29 kernel by Nadlabak (pavel@doshaska.net)
 *
 * 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:

Code:
/*
 * 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
 *
 * Based on the interactive governor By Mike Chan (mike@android.com)
 * which was adaptated to 2.6.29 kernel by Nadlabak (pavel@doshaska.net)
 * 
 * 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:

Code:
/*
 * 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
 *
 * Based on the interactive governor By Mike Chan (mike@android.com)
 * which was adaptated to 2.6.29 kernel by Nadlabak (pavel@doshaska.net)                     
 * 
 * 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:

Code:
/*
 * 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
 *
 * Based on the interactive governor By Mike Chan (mike@android.com)
 * which was adaptated to 2.6.29 kernel by Nadlabak (pavel@doshaska.net)
 * --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:

Code:
/*
 *  drivers/cpufreq/cpufreq_minmax.c
 *
 *  Copyright (C)  2001 Russell King
 *            (C)  2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
 *                      Jun Nakajima <jun.nakajima@intel.com>
 *            (C)  2004 Alexander Clouter <alex-kernel@digriz.org.uk>
 *
 * 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:

Code:
/*
        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

In attachment you can also find some benchmark's statistics for P500's franco.Kernel.


Attached Thumbnails
Click image for larger version

Name:	screenshotat20110808205.jpg
Views:	11628
Size:	65.2 KB
ID:	705301  

Last edited by knzo; 13th September 2011 at 01:10 PM.
The Following 233 Users Say Thank You to knzo For This Useful Post:  Show/Hide

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?

Code:
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 *
  • Anticipatory *@+
  • CFQ *&
  • Deadline *@+
  • VR +
  • Simple +&
  • BFQ #

Legend: & - default | @ - disabled by default | * - exists in stock kernel | + - added in Quasar kernel | # - not included in Quasar kernel

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

Noop:
Code:
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:

Code:
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:

Code:
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:

Code:
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:

Code:
/*
* V(R) I/O Scheduler
*
* Copyright (C) 2007 Aaron Carroll <aaronc@gelato.unsw.edu.au>
*
*
* 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:

Code:
/*
 * Simple IO scheduler
 * Based on Noop, Deadline and V(R) IO schedulers.
 *
 * Copyright (C) 2010 Miguel Boton <mboton@gmail.com>
 *
 *
 * 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:

Code:
/*
 * BFQ, or Budget Fair Queueing, disk scheduler.
 *
 * Based on ideas and code from CFQ:
 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
 *
 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
 *		      Paolo Valente <paolo.valente@unimore.it>
 *
 * 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


Last edited by knzo; 19th September 2011 at 06:39 PM.
The Following 157 Users Say Thank You to knzo For This Useful Post:  Show/Hide

Reserved for possible later use.

The Following User Says Thank You to knzo For This Useful Post:  Show/Hide

Reserved for possible later use.

The Following User Says Thank You to knzo For This Useful Post:  Show/Hide

Now don't you people dare ask me again about governors or whatever.

The Following 16 Users Say Thank You to knzo For This Useful Post:  Show/Hide

**** I'm going to steal you this "manual"... no more 65132 posts per day asking about schedulers and governors.

__________________

Peek
Nexus Display Control
franco.Kernel updater Free
franco.Kernel - Galaxy Nexus
franco.Kernel - Nexus 4
franco.Kernel - Nexus 5
franco.Kernel - Nexus 7
franco.Kernel - Nexus 7 2013
franco.Kernel - Nexus 10


Google+ | Twitter

You don't like my reply? Read this

However, if you put any trust in Quadrant scores you could use them to prove that dancing naked for 5 minutes in your garden affects device performance. By Chainfire

My applications translations are managed by:

The Following 2 Users Say Thank You to franciscofranco For This Useful Post:  Show/Hide

Wow thanks I personnally search with Google.
But, thanks ! It must had take some time to write it all.

Sent from my LG-P970 using xda premium

__________________
Sobralobo - Always trying to help

Do not forget : search for your answer before posting. Clean thread means a better clarity.

Perfect.

__________________
Give a try to my 3d battery icons here!



LG Optimus Black / ROM IZS v1 by Huexxx

DONATE PLEASE! HELP ME WITH MY MORTGAGE!

Knzo you have to many time. But thx for your great work.

Sent from my LG-P970 using XDA App

__________________
Technerd / TwitterJunkie / Google Plus Fan / Facebook

There is an ondemandX governor in p500 francos kernel

__________________
Thinking of posting your own cooked rom? Read here first!

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Rules
All times are GMT +1. The time now is 09:26 PM.