Mutex API

The Mutex API can be defined statically using the “DEFINE_MUTEX” MACRO. It can be dynamically defined during process/thread run using the “mutex_init” MACRO. Both methods are shown below DEFINE_MUTEX(mutex_name); /*statically assign mutex by name- mutex_name*/ mutex_init(mutex); /* dynamically assign the mutex */ Both these Macros are placed in the header file – mutex.h. The code […]

Linux Kernel – Debug File System

The Linux Debug File System is a virtual memory File system that was developed so that debug kernel information can be accessed in user space whenever desired. It is a RAM based File system. The Debug File system will be enabled in the Linux kernel build if “CONFIG_DEBUG_FS” is enabled in the kernel config. The […]

Spin lock Initialization and Use

The interested reader can refer the following articles on spinlocks. http://www.hitchhikersguidetolearning.com/2021/01/03/linux-kernel-locking-mechanisms-spinlock/ The Spinlock can be initialized via “DEFINE_SPINLOCK” MACRO or  by invoking the “spin_lock_init” MACRO. The “DEFINE_SPINLOCK” MACRO is usually used when the spinlock is statically assigned. The “spin_lock_init” MACRO is usually used when the spinlock variable is part of a structure which is dynamically […]

spinlock structure in Linux kernel

The interested reader can look at the below post before reading the current article. Linux Kernel Locking Mechanisms – spinlock spinlock data type is defined as a structure by name “spinlock_t“. This structure can be seen in the header file “spinlock_types.h“. The definition of the spinlock data type as in Linux 4.15 is provided below […]

Linux Kernel Locking Mechanisms – spinlock

In this Article, we discuss the memory locking mechanism that is commonly seen in the linux kernel – Spinlock Spinlock:Spinlocks are kernel locking mechanism wherein if the lock is not obtained, the code attempting to get the lock just keeps spinning at that instance trying to acquire the lock. Hence the name “spin”lock. The fact that […]

Linux Kernel – atomic operations – bit operations – sample code

The below sample code provides a sample implementation to the reader on different atomic operations that are available.  The following sample code merely provides a simple illustration of a few atomic bit operations. There are more atomic bit operations and the interested reader can look at “asm/bitops.h” for the specific architecture that he/she is working […]

Linux Kernel – atomic operations

Non-atomic operations on a memory usually perform a read from memory and later modify/write to the memory to complete a memory update. This can lead to race conditions to occur for a shared resource Atomic operations on the other hand provide instructions which complete in one instruction cycle. Since atomic instructions complete in one single […]