Posts

Showing posts from July, 2019

RCU Kernel Implementation

Image
In our last session, we learned how to use RCU API as a synchronization mechanism using a sample driver. Please visit the  last session  if you missed. In this blog, we will be going through Kernel Implementation of RCU API. The below diagram depicts the overall RCU API used for synchronization. rcu_read_lock() -  The kernel implementation is as follows - static inline void rcu_read_lock(void) {         __rcu_read_lock();         __acquire(RCU);         rcu_lock_acquire(&rcu_lock_map);         rcu_lockdep_assert(rcu_is_watching(),                            "rcu_read_lock() used illegally while idle"); } Basically the above function disables the preemption on the particular cpu on which it is running. So that no other process can preempt this process and the process completes its execution without interruption. After holding rcu_read_lock() it is illegal for the process to explicitly call sleep. rcu_read_unlock()- static inline void rcu_read_unlock

Linux RCU Synchronization Mechanism

Image
In this post, we will get to know the insight about Linux Synchronization mechanism – RCU(Read Copy Update). RCU (Read Copy Update ) is one of the synchronization mechanism found under Linux for both User Space and Kernel Space. In this blog, I’ll be explaining about Kernel Space RCU implementation with a sample code. Read -Copy- Update is used as a synchronization mechanism when performance is pivotal for a system. Using RCU performance of "Read" operation can be made significantly more compared with other synchronization mechanisms like a semaphore.   As the name says Read-the list, Copy-the node, Update-update the list for writing  into the linked list.  Then what about read operation ?. Using RCU for reading a linked list is almost lock-free. In non-preempt Kernel, it is almost equal to nops.  Below is the sample that explains RCU implementation using the miscellaneous driver and is compiled under GPL license. #include <linux/module.h> #include <li