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 – sample code
The below code provides a few sample atomic operation functions used in the Linux Kernel. An interested reader can open the header file – “asm/atomic.h” for the specific architecture that his device is using (e.g x86/ ARM etc) to understand a lot more of the atomic APIs present. The below code is based on linux […]
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 […]
Linux-Locking Mechanisms – Concurrency and race conditions – part 2
The interested reader can check part 1 of this article in the link below <Linux – Need for Locking Mechanisms – Part 1> The below set of images provide an explanation on how concurrency and race conditions are handled in the computer. FIG 1 : Value read from shared resource by Process 2 is wrong […]
Linux – Need for locking mechanisms- Concurrency and race conditions – part 1
In this article, we try to understand why locking mechanisms are required in a computer system. Concurrent operations and race conditions occur when two or more processes attempt to access a shared resource. In real life as well, the same situations arise and we try and relate and understand the two via some real world […]