8th October 2013, 02:51 AM
(Last edited by boyheadkick; 8th October 2013 at 03:01 AM.)
Thanks Meter 280
Join Date: Oct 2012
[GUIDE] Custom Kernels: A Guide on What you Need to Know
I was searching for info about MPDecision and stumbled upon this..it's a very good read specially for beginner and those that want to know more about kernel specifics and how they work..this was written back in 2012:
---What IS a kernel?---
The ELI5 answer: "An analogy: the Kernel is like the Engine, Electrical system and the Transmission to a car. The Library, Framework and the Apps [AKA ROM] are the body frame and the rest of the Car." - faux123
In other words, the kernel is the software that controls the hardware at a very low level.
---The Stock Kernel---
The "stock" kernel is the kernel that comes with your Nexus 4 out of the box. It's compiled directly from Google's kernel source code and shipped on your device with zero modifications. A custom kernel, on the other hand, compiles the stock kernel source and adds various modifications to that code.
What are those modifications that kernel devs employ?
To understand what they mean, you need to understand the features of the stock kernel first!
What are the stock kernel parameters?
CPU min frequency: 384 MHz
CPU max frequency: 1512 MHz
I/O Scheduler: CFQ
What does each parameter represent?
CPU frequency: you can simply think of this as the "speed" the CPU is running at
Governor: regulates the CPU frequency based on many different parameters such as load and time-in-state. Here is an excellent list of many of the most common CPU governors and how each works. Note that you will only see a couple of the CPU governors on this list in whatever kernel you use. Ondemand and Interactive are by far the most widely used, and are the ones you should look at.
I/O Scheduler: handles how the system makes disk access; Please refer to the previous linked thread and scroll down to the 4th post for a detailed list.
What else do you need to know?
PowerHAL is what makes Project Butter. The powerHAL is a ROM component that tells the kernel to BOOST the CPU frequency to higher values in response to UI inputs. The higher CPU frequencies can better respond to UI demands so the overall experience is smoother than without. - faux123
All Qualcomm based phones have Qualcomm prorprietary userspace binary called "mpdecision" aka m(ake)p(oor)decision. Instead of letting the kernel itself to decide what frequencies and how many cores to run, this "mpdecsion" binary polls the kernel run queue statistics and decides for the whole system the "optimal" frequency and the "optimal" number of cores to use. The concept is fine, except the decision making is done in userspace and it's 100% closed source so there's no way to tweak it and there's a latency (because all userspace binaries needs to "poll" the kernel for the latest information which is slightly delayed). - faux123
ELI5: mpdecision is a proprietary Qualcomm daemon that makes calls to the SoC (the entire chip your phone uses) to manage the cores. The OS (PowerHAL) makes a request to mpdecision and then mpdecision makes a request to the first two cores to ramp them up. - _motley
Why do kernel devs mess with these?
In practice, the PowerHAL ramping up trick successfully got rid of a lot of the UI lag since Android 4.1. However, this comes at the cost of battery life (and heat generation!) The reason for this is because the system ramps up its CPU on every touch input, rather than waiting for the kernel to calculate the load and ramp up accordingly. On the Nexus 4, when the PowerHAL makes a call to mpdecision it locks the minimum CPU to 1026 MHz upon touch input for the first two cores. While this DOES give you the buttery-smoothness you would expect, it's a bit overly aggressive. This is part of the reason why stock kernel tends to heat up your phone when you play around with it a lot.
What changes should I look out for?
Many kernel devs don't like Qualcomm's implementation, so they work around or get rid of it. Franco, Faux, Bricked, Matr1x, Motley, and Trinity have gotten rid of it/used their own implementations. Harsh and IntersectRaven's leave it intact. Every kernel dev implements things in their own way, and the only way to tell which is better for you is to try each one. This is by far the biggest change any kernel dev can make, as it completely alters how the system handles hotplugging and CPU scaling. In general, you'll find kernels without mpdecision running cooler, with greater battery life, but with a little more lag (made up for by other tweaks).
A binary that controls how to throttle your CPU based on CPU and battery temperatures. You can find the config file in /system/etc/thermald.conf. Stock configs lead to aggressive thermal throttling (battery temp. at 36 degrees C for example, which is easily achieved). You can look into the file and see the various thresholds and actions that the system takes to lower the temperature of the CPU and battery, but it isn't really necessary. Just know that some kernel devs may have changed this in order to allow your phone to run at higher frequencies for an extended period of time, or to further make your phone run cooler.
Quite straightforward, by limiting the max frequency your CPU can use, you use less power (higher frequency results in more power dissipated by the CPU).
P = C(V^2)f where C is capacitance, V is the voltage, and f is the current frequency
..gives you an idea of how underclocking (and undervolting) uses less power.
This is all the rage today, with many users trying to get as low as possible stable voltage. It's arguable how much undervolting saves battery life, but there's no doubt it reduces heat dissipated from the CPU (see: the above formula). Your CPU is located on the top half of your phone, which is likely where you've felt the heat before. How much your chip can successfully undervolt depends on what type of binned CPU you have. If you want to undervolt, I recommend checking if the voltages you set are stable by running the StabilityTest app and doing the Scaling Stability Test. The frequencies' voltages definitely don't scale linearly, so don't assume that doing global undervolts will be the best you can do. You'll have to apply voltages one by one if you truly want the lowest your chip can possible handle.
Bricked, Trinity, and Motley's kernel implement this, because it CAN be dangerous. Overclocking usually requires overvolting the processor (so the overclock is stable) but overvolting carries with it the risk of bricking your phone by frying the CPU. Know that doing this has some risks before you try it. Some kernels like Matr1x and Faux's also allow for the GPU to be overclocked if games run a little slowly for you.
Hotplugging is where the individual cores on your phone switch on/off depending on the load on the CPU. The advantage of hotplugging is a reduction in power used because the cores will only turn on when needed. Kernels that use the auto_hotplug binary by Thalamus (that would be Matr1x, Motley, Trinity, Bricked at the moment) allow you to fine tune the enabling and disabling thresholds. These parameters are generally for advanced users only as they require you to write scripts to control them.
Gives you the ability to change color multipliers and gamma settings to calibrate your display. If you feel your display is too yellow, or you miss the previous feel of your previous phone, then you can mess around with this to get better color reproduction. You can find some user examples here to give you a good idea of what can be done. Gamma control currently requires either Faux's control app or for certain kernels you can use scripts to control them.
Some kernels have reduced the msm_hsic_host wakelock duration so your phone enters deep sleep more often. How much improvement this makes is debatable, and whether or not this wakelock is even an issue is also debatable.
Some kernels make modifications to the low-level drivers that interact with the components of your phone. An explanation of what is commonly touched can be found here. You don't really have to worry about this, just know that something is being improved when a kernel dev mentions it.
---Installing a Custom Kernel---
Just flash the zip in your recovery of choice. No need for wiping cache or anything. However, one thing to note that might save you some headache in the future is: what exactly are you flashing? When you flash a kernel, you are not just flashing the kernel, you are writing to the entire boot partition. The boot partition is made up of the kernel AND the ramdisk (the ramdisk is an image that the kernel mounts read-only at boot, it is basically used by the kernel to mount the rest of the system images). Some kernel devs pack their own ramdisk into their boot.img that you are flashing, so when you try to flash a DIFFERENT kernel, you end up in a bootloop. (An example: flash Franco kernel --> flash Faux kernel on top = bootloop.) To solve this you need to reset the ramdisk by flashing a stock reset kernel with the stock ramdisk.
all content taken from a reddit post i found which was originally written
by reddit user IAmAN00bie