I hope you are having a wonderful time on Mi Community. In the previous Tech Class thread we learned about Rooting. In this Tech Class thread I am going to explain what a kernel is and how it functions.
Here we start.
What Is A Kernel?
We have heard the term around quite a bit, but we haven’t really tried to understand what it is and what it means, and why is it called that?
The term doesn’t derive from a rank in the military like “colonel”, instead, it refers to fruits and nuts.
In the practical world, the kernel is the softer, usually edible part of a nut, or seed and is contained within its hard shell.
When talking about smartphones, tablets, and even computers, the kernel isn’t that much different… though I wouldn’t recommend you eat it. :P
Think of it like popcorn.
You’ll chip a tooth if you try to eat a popcorn kernel without cooking it! The outside shell is hard and protects the inside. You can unlock all the goodness that’s inside that hard shell if you’ve got the right mixture of oil and heat .
In android, the kernel isn’t all that different. Wikipedia sums it up fairly well:
The kernel provides the lowest-level abstraction layer for the resources (processors and I/O devices) and is responsible for managing the system’s resources. Apps can talk through the kernel to the various hardware components in the system.
What Does A Kernel do?
Android devices use the Linux kernel, but it's not the exact same kernel other Linux-based operating systems use. There's a lot of Android specific code built in, and Google's Android kernel maintainers have their work cut out for them.
OEMs (Original Equipment Manufacturers) have to contribute as well, because they need to develop hardware drivers for the parts they're using for the kernel version they're using.
This is why it takes a while for independent Android developers and enthusiasts to port new versions to older devices and get everything working.
Drivers written to work with the Lollipop kernel on a device won't necessarily work with the Marshmallow kernel. And that's important, because to control hardware is one of the main functions of a Kernel.
It's a whole lot of source code, with more options while building it than you can imagine, but in the end it's just the intermediary between the hardware and the software.
When software needs the hardware to do anything, it sends a request to the kernel, and by anything, I literally mean anything. From the rotation of the screen, to the unlocking of device, to initiating a call through the radio, even what's drawn on the display is ultimately controlled by the kernel.
For example, when you tap the rotate button on your phone, you tell the software to rotate the screen. What happens is that you tell the software that you've touched the screen at those coordinates by touching a certain point on the digitizer.
The software knows that when that particular spot is touched, the screen is supposed to rotate. The difgitizer takes order from kernel to look (or listen, events are "listened" :lol) for touches, helps figure out where you touched, and tells the system you touched it.
In turn, when the system receives a touch event at a specific point from the kernel (through the driver) it knows what to draw on your screen. Your phone knows when to do something when both the hardware and the software communicate both ways with the kernel. Input from one side is sent as output to the other, whether it's you playing Angry Birds, or connecting to your car's Bluetooth.
It sounds complicated, doesn't it? Well it is dicey :P. But it's also pretty simple computer logic, for every event there's an specific action generated. Developers would have to write code for every single event for every single piece of hardware in your device if the Kernel doesn't accept & send information. With the kernel, all they have to do is communicate with it through the Android system API's (Application Program Interface), and hardware developers only have to make the device hardware communicate with the kernel.
What Is Kernel Version?
The Linux Kernel version that Android is based on is called as Kernel Version. It's the core of the operating system which handles requests to and from the hardware, memory and process management and all the low-level stuff that is necessary for Android to be able to run.
The kernel is not updated very frequently because there are many things to keep in mind and many things that can go wrong. A Kernel upgrade means making sure everything that is in the old version of Android works correctly on the new version.
Below are the versions of Kernel from their initial build to the latest build.
New And Improved Kernels
This is where the Android community comes in. There are developers who contribute by making custom kernel for a specific device. They do it just because they like to contribute their work to the community.
The advantage of custom one is that is able to grant more control over parameters and it is tweaked to perform differently that affect the performance of a device. For example, you can underclock the device to save the battery. When you tell the kernel to run the processor on a lower frequency to save power it is called as Underclocking.
Underclocking does make your phone lag quite a bit, but its ability to save battery is very good. A phone modified in this way with a custom kernel can seriously work like a charm.
Alternatively, you can Overclock a phone. This is when the kernel allows the processor to run at max. frequency outputs large amounts of power (higher than the phone usually uses). This will eat through a battery extremely quickly (like hot knife through butter), but it is great beacause it doesn't let various apps to lag (like Ashphalt 8). Not to mention, when a phone is Overclocked everything loads extremely quickly.
There are a few risks to installing a new kernel. If you tell it to use an amount of battery that’s too small, there is a chance that the phone won’t be able to turn on.
Finding The Right KernelXDA Developer Forum is the best place where you can search for a custom kernel, specifically the section for your particular device. It is very important that we choose a kernel that is not only compatible to the Android version we are running in our device, but also the device that we own.
If you are unsure if a kernel is compatible with your device, ask in the forums or on the specific Kernel Thread. Flashing the wrong kernel might get your device into bootloop or brick your device.
How A Replacement Of Kernel Benefits YouUsing a Custom kernel with more parameters to tweak sounds pretty cool, but what can a custom kernel do for you? You’ll have a lot of options to choose from as there are many different custom kernels available for every Android device that exists. You can pick kernels that are optimized for power savings, or the ones that are optimized for performance depending on your needs. There are other kernels too which have a good balance of both.
There are some developers who switch out some drivers with others (for varying reasons), or develop their own patches for problems they identify. A lot of developers also try to include upstream Linux kernel patches, or use their own toolkits for compilation. For example, for Nexus 5, there’s one developer who uses his own toolkit, which includes the latest version of GCC, a Linaro toolchain with optimizations specifically for the CPU architecture used, and maximum optimization flags for the compiler.
Developers can even add some additional features from other kernels that don’t officially exist for your device. For example, there are some kernels for the Redmi 1s that include the “double tap to wake” feature that first appeared on the LG G2.
Most of all, a handful of kernels allow you to access the configurable variables yourself, so that you can use the code that the kernel developers release but tweak it to adjust its behavior to your liking. However, you’ll want to research some of the options available before you actually start to change values for them. In other words, a custom kernel can provide improvements, extra features, specialization, and extreme configurability.
Customization Options Of A KernelThe kernel, in this regard, is extremely customizable. Not only does the manufacturer have to plug in the necessary drivers to get all of the hardware to work correctly, but there are a lot of variables that they need to set. They can mess with all sorts of things.
A few variables that we can mess with are:
• The minimum and maximum frequencies that the CPU can scale up or down to
• The frequency the CPU should boost to whenever it detects touch input (to ensure a smoother wake up)
• How busy the CPU should be before it enables extra cores that it normally has disabled to save battery
• The CPU governor (which determines how quickly it tends to ramp up the frequency or not) that should be used
• Enable USB fast charge (for USB 3.0 ports)
• Change the voltage of the CPU during all possible frequencies
• The maximum frequency of the GPU
• Configure the I/O scheduler that is used
Apps For Kernel ManagementThe custom kernel can work its magic once it’s installed. However, we have to tell the kernel what it has to do. You can manually control it from the settings with certain ROMs like MIUI. Everyone else will need third-party apps like Kernel Adiutor, Synapse, etc. Make sure you install the apps which are supported by the kernel that allows you to make changes in the kernel. The most common app used is Kernel Adiutor.
These apps let you tweak settings like:
CPU (Frequency, Governor)
GPU (Frequency, Governor)
Screen (Color Calibration [RGB])
Wake controls (DT2W, S2W)
Sound (Faux Sound, TA-Mod)
Battery (Fast Charge)
Kernel Samepage Merging
Low Memory Killer (Minfree settings)
Build prop Editor
Final ThoughtKernel is the most important component to run a device as it is a bridge between hardware and software of a device. Without kernel it is not possible for a device to run. Installing a new kernel can be a bit dicey, but when done correctly there’s really a minimal risk. But, it is not necessary to flash a Custom Kernel in your device unless you want some additional features because the Stock Kernel provided by OEMs works out of the box and without any issues.
Previous Tech Class Lessons:
Chapter 1: Introduction to Smartphone Specifications
Chapter 3: All You Need To Know About Augmented Reality
Chapter 4: All You Need To Know About Charging Cycle
Chapter 5: All About Activity Tracker & Fitness Band
Chapter 6: Internet of Things & Mi Home
Chapter 7: Infrared Blaster
Chapter 8: CPU Architecture, CPU,GPU
Chapter 9: Megapixels and Photo Quality
Chapter 10: PDAF and its difference with CDAF
Chapter 11: All About Network Bands
Chapter 12: All About Rooting
[Tips] [Device Team] [Tech Class] Chapter 13: All About Kernel