TechEuphoria


Printing the Linux kernel version

by Conrad Gomes on

The kernel version that a kernel module is built with can differ from the kernel version it is running on. The version of the kernel that the module is running on is shown in the first log and the version of the kernel is compiled with is shown in the second log in the version_init function:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/utsname.h>
#include <generated/utsrelease.h>

static int __init version_init(void)
{
        int i = 0;

        pr_alert("Kernel module running of version %s\n", utsname()->release);
        pr_alert("Kernel module compiled with version %s\n", UTS_RELEASE);
        return 0;
}

static void __exit version_exit(void)
{
        pr_alert("Over and out!\n");
}

module_init(version_init);
module_exit(version_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zeuzoix");
MODULE_DESCRIPTION("Kernel Module Version Example Module");

Caches

by Conrad Gomes on

Let’s talk about the cache and its requirement in a computing system. The word cache is derived from the french word cacher which means to hide.

In a nutshell it’s a memory subsystem which improves the speed of execution of a thread by providing faster access to instructions and data based on their temporal and spacial characteristics in the program.

With memory there’s typically a trade off between space and time. If speed is required then the storage capacity of the memory reduces particularly because the cost of the memory goes up with speed.

So system designers often incorporate a cache in between the processor and main memory which can significantly improve the speed at which memory access occurs.

The cache can be of different levels typically most processors these days have an inbuilt cache termed as L1 which is the smallest memory device in the hierarchy of memory in the system. Some processors like ARM Cortex’s A series have an in built L2 cache also.

There are several popular designs for caches. The following videos give a very nice description of the different types of caches:


Linux Linked Lists

by Conrad Gomes on

The linux kernel has a very peculiar implementation of the linked lists data structure. The linked list is actually a circular linked list. The following article is useful in understanding more about the design:
http://kernelnewbies.org/FAQ/LinkedLists

What’s interesting is that the entire implementation is conveniently located in one header file. This shows that the open source movement when done right gives you the best solution possible over time:
http://lxr.free-electrons.com/source/include/linux/list.h


Topics