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 […]

Linux Kernel Locking Mechanisms

In the following set of articles, we attempt to understand different aspects of  linux Kernel locking mechanisms and the need for locking mechanisms.  The following set of articles try and explain the different locking primitives and the way it prevents concurrency issues and race conditions. code examples and linux kernel snippets are provided in the […]