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

The “CONFIG_DEBUG_LOCK_ALLOC” is for debug purposes and if it is disabled, the spinlock structure collapses to “struct raw_spinlock rlock“. The raw_spinlock structure is also present in the “spinlock_types.h” file and is provided below

The “arch_spinlock_t” data type is the architecture dependent implementation of spinlock. Different versions of linux kernels also seem to have slightly different implementations of the same. For the interested reader, the relevant structure and details can be found in “qspinlock_types.h” or “spinlock_types.h” header file for a specific processor architecture. For e.g. – For Linux 4.15 kernel – the “arch_spinlock_t” structure is as shown below:

But in Linux kernel version 5.9, the same structure is defined as shown below.

The interested reader can check the relevant structure in the linux kernel version that he/she is working on.

What can be observed is that the basic lock falls down to an atomic_t variable. We will look at how spinlocks are initialized and some more properties of the same in the coming articles.  

Spinlock Initialization and Use

Comments

  1. Pingback: Linux Kernel Locking Mechanisms – spinlock | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *