Udemy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Development
Web Development Data Science Mobile Development Programming Languages Game Development Database Design & Development Software Testing Software Engineering Development Tools No-Code Development
Business
Entrepreneurship Communications Management Sales Business Strategy Operations Project Management Business Law Business Analytics & Intelligence Human Resources Industry E-Commerce Media Real Estate Other Business
Finance & Accounting
Accounting & Bookkeeping Compliance Cryptocurrency & Blockchain Economics Finance Finance Cert & Exam Prep Financial Modeling & Analysis Investing & Trading Money Management Tools Taxes Other Finance & Accounting
IT & Software
IT Certification Network & Security Hardware Operating Systems Other IT & Software
Office Productivity
Microsoft Apple Google SAP Oracle Other Office Productivity
Personal Development
Personal Transformation Personal Productivity Leadership Career Development Parenting & Relationships Happiness Esoteric Practices Religion & Spirituality Personal Brand Building Creativity Influence Self Esteem & Confidence Stress Management Memory & Study Skills Motivation Other Personal Development
Design
Web Design Graphic Design & Illustration Design Tools User Experience Design Game Design Design Thinking 3D & Animation Fashion Design Architectural Design Interior Design Other Design
Marketing
Digital Marketing Search Engine Optimization Social Media Marketing Branding Marketing Fundamentals Marketing Analytics & Automation Public Relations Advertising Video & Mobile Marketing Content Marketing Growth Hacking Affiliate Marketing Product Marketing Other Marketing
Lifestyle
Arts & Crafts Beauty & Makeup Esoteric Practices Food & Beverage Gaming Home Improvement Pet Care & Training Travel Other Lifestyle
Photography & Video
Digital Photography Photography Portrait Photography Photography Tools Commercial Photography Video Design Other Photography & Video
Health & Fitness
Fitness General Health Sports Nutrition Yoga Mental Health Dieting Self Defense Safety & First Aid Dance Meditation Other Health & Fitness
Music
Instruments Music Production Music Fundamentals Vocal Music Techniques Music Software Other Music
Teaching & Academics
Engineering Humanities Math Science Online Education Social Science Language Teacher Training Test Prep Other Teaching & Academics
AWS Certification Microsoft Certification AWS Certified Solutions Architect - Associate AWS Certified Cloud Practitioner CompTIA A+ Cisco CCNA Amazon AWS CompTIA Security+ Microsoft AZ-900
Graphic Design Photoshop Adobe Illustrator Drawing Digital Painting InDesign Character Design Canva Figure Drawing
Life Coach Training Neuro-Linguistic Programming Personal Development Mindfulness Personal Transformation Meditation Life Purpose Coaching Neuroscience
Web Development JavaScript React CSS Angular PHP WordPress Node.Js Python
Google Flutter Android Development iOS Development Swift React Native Dart Programming Language Mobile Development Kotlin SwiftUI
Digital Marketing Google Ads (Adwords) Social Media Marketing Google Ads (AdWords) Certification Marketing Strategy Internet Marketing YouTube Marketing Email Marketing Retargeting
SQL Microsoft Power BI Tableau Business Analysis Business Intelligence MySQL Data Analysis Data Modeling Data Science
Business Fundamentals Entrepreneurship Fundamentals Business Strategy Online Business Business Plan Startup Freelancing Blogging Home Business
Unity Game Development Fundamentals Unreal Engine C# 3D Game Development C++ Unreal Engine Blueprints 2D Game Development Blender
30-Day Money-Back Guarantee

This course includes:

  • 4.5 hours on-demand video
  • 1 article
  • 5 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
IT & Software Operating Systems Linux Kernel

Synchronization in Linux Kernel Programming

Linux Kernel Programming - Synchronization and Concurrency
Rating: 3.5 out of 53.5 (4 ratings)
93 students
Created by Linux Trainer
Last updated 11/2020
English
English [Auto]
30-Day Money-Back Guarantee

What you'll learn

  • Synchronization concepts in Linux Kernel

Requirements

  • Should be able to write/understand Hello World Linux Kernel Module
  • Should be able to write/understand Linux Kernel Modules for /proc filesystem

Description

Update: Sep 15: Added RCU Section

What you will learn in this course

  • Various concepts related to concurrency like: preemption, context switch, reentrancy, critical section, race condition

  • Various Synchronization techniques

    • Per CPU Variables

    • Atomic Variables

    • Spinlocks

    • Semaphores

    • Mutexes

    • Read Write Locks

    • Sequence Locks

    • Read Copy Update(RCU)


API's/Macros/Structures:

  • spinlock_t, DEFINE_SPINLOCK, spin_lock, spin_unlock, spin_trylock, spin_lock_irqsave, spin_unlock_irqrestore,spin_lock_irq, spin_unlock_irq

  • atomic_t, atomic64_t, ATOMIC_INIT, atomic_inc, atomic_dec, atomic_set, atomic_read, atomic_add, atomic_sub,

    atomic_dec_and_test, atomic_inc_and_test, atomic_sub_and_test, atomic_add_negative,atomic_add_return, atomic_sub_return, atomic_inc_return, atomic_dec_return,atomic_fetch_add, atomic_fetch_sub, atomic_cmpxchg, atomic_xchg,set_bit, clear_bit, change_bit, test_and_set_bit, test_and_clear_bit, test_and_change_bit,

  • NR_CPUS,num_online_cpus,smp_processor_id,get_cpu,put_cpu,DEFINE_PER_CPU,get_cpu_var, put_cpu_var, per_cpu, for_each_online_cpu, alloc_percpu,  free_percpu, per_cpu_ptr

  • rcu_read_lock, rcu_read_unlock, synchronize_rcu, call_rcu, rcu_assign_pointer, rcu_dereference

  • seqlock_t, seqcount_t, DEFINE_SEQLOCK, seqlock_init, write_seqlock, write_sequnlock

  • struct rw_semaphore, DECLARE_RWSEM, init_rwsem, down_read, up_read, down_write, up_write, down_read_trylock, down_write_trylock, downgrade_write

  • struct rwlock_t, DEFINE_RWLOCK, rwlock_init, read_lock, read_unlock, write_lock, write_unlock

  • struct mutex, DEFINE_MUTEX, mutex_init, mutex_lock, mutex_unlock, mutex_trylock, mutex_lock_interruptible, mutex_unlock_interruptible, mutex_is_locked

  • struct semaphore, sema_init, DEFINE_SEMAPHORE, down, up, down_interruptible, down_trylock, down_timeout, down_killable


Commands used in the course

  • nproc

  • ps -eaF

  • ps aux

Who this course is for:

  • Linux Kernel Developers interested in learning various synchronization techniques

Course content

11 sections • 120 lectures • 4h 31m total length

  • Preview01:01
  • Preview03:01
  • Preview07:53
  • Preview03:43
  • Preview02:47
  • When can kernel preemption happen
    00:46
  • Example of kernel preemption
    02:12
  • Reentrancy
    03:12
  • Synchronization Race Condition and critical regions
    02:10
  • Causes of concurrency
    01:02
  • Solution for concurrency
    02:11
  • Find out maximum number of processors in Kernel
    02:23
  • Find out which processor is running kernel control path
    01:37
  • Linux Kernel Module Example of processor id of Kernel Thread
    01:39
  • Linux Kernel Module Example of processor id on uniprocessor system
    02:54

  • Introduction
    01:01
  • Example of Per CPU variables
    04:58
  • New Interface of Per CPU Variables
    03:48
  • Example of new interface of Per CPU Variables
    00:58
  • Example of per cpu
    01:40
  • Example of for_each_online_cpu
    00:44
  • Allocating per cpu data at runtime
    02:04
  • Problems with Per CPU Variables
    01:19

  • Problem Read Modify Write
    05:16
  • Introduction to Atomic Operators
    03:15
  • Example of Atomic Operators
    02:58
  • Common uses of Atomic Operations
    01:54
  • Atomic Operation and test
    04:34
  • Atomic add subtract and return
    01:14
  • More Atomic Operations
    04:02
  • 64-bit Atomic Operations
    01:48
  • Atomic bitwise operations
    04:02
  • Atomic bitwise operations with return value
    01:14
  • Non Atomic bitwise operations
    00:36

  • Introduction
    02:49
  • Spinlock API's
    03:19
  • Initializing spinlock
    00:51
  • Spinlock Example of two kernel threads
    01:16
  • What happens if i acquire a lock which is already held by CPU
    03:40
  • Implement busyloop using spinlock in char drivers
    02:59
  • spin_trylock
    01:16
  • Can i use spinlock if resource is shared between process and interrupt context
    04:42
  • Is kernel preemption disabled when spinlock is acquired
    02:34
  • Important points to consider while using spinlock
    01:29
  • Example of calling msleep in critical section
    02:49
  • Will spinlock exists on uniprocessor system
    01:29
  • Implementation of spinlock
    04:58

  • Introduction
    00:55
  • Implementation of semaphore
    01:44
  • Types of semaphores
    01:05
  • Can I use counting semaphores in critical section
    00:56
  • Semaphore API
    02:34
  • Linux Kernel Module Example using semaphore API
    00:48
  • Linux Kernel Module Example using down and up
    01:32
  • Linux Kernel Module Example calling down twice
    04:28
  • Linux Kernel Module Example of producer consumer
    03:02
  • down_interruptible
    02:55
  • down_trylock
    01:05
  • down_timeout
    02:14
  • down_killable
    02:32
  • Important points while using semaphore
    01:49
  • spinlock vs semaphore`
    01:29

  • Introduction
    02:25
  • Mutex vs semaphore
    03:41
  • Mutex Implementation in Linux Kernel
    01:00
  • Mutex API
    02:00
  • Linux Kernel Module Example using mutex API dynamic initialization
    00:30
  • Linux Kernel Module Example using mutex API static initialization
    00:20
  • Linux Kernel Module Example demonstrating calling sleep in critical section
    01:30
  • mutex_trylock
    00:42
  • What happens when other thread calls unlock mutex
    05:54
  • Trying recursive mutex locks
    01:33
  • mutex_is_locked
    01:15
  • Which one do you choose between semaphore and mutex
    01:09
  • Which one do you choose between spinlock and mutex
    01:06

  • Problem Statement
    03:08
  • Solution
    01:31
  • Introduction to ReadWrite Spinlock
    01:21
  • Linux Kernel Module Example using RW Spinlock API
    04:06
  • What happens when we call read lock and write lock one after another
    01:28
  • Recursive read locks
    01:24
  • What happens when writer is waiting and reader arrives
    03:16
  • Linux Kernel Module Example using RWLOCKS with 3 kernel threads
    01:42
  • Linux Kernel Module Example using RWLOCKS with 4 kernel threads
    02:14

  • Introduction to ReadWrite Semaphores
    01:51
  • ReadWrite Semaphore API
    01:46
  • down_read_trylock and down_write_trylock
    00:33
  • downgrade_write
    06:15
  • Recursive write locks
    00:38
  • Linux Kernel Module Example using multiple threads
    01:58

  • Problem
    01:08
  • Solution
    00:48
  • Sequence Locks
    03:06
  • How Sequence Locks works
    01:20
  • Write operation in sequence lock
    01:09
  • Read operation in sequence lock
    02:10
  • Linux Kernel Module Example using sequence lock
    01:31
  • Is Kernel Preemption Disabled using sequence lock
    01:12
  • Limitation of sequence locks
    01:09
  • Sequence Locks in Linux kernel
    00:25
  • Sequence locks in interrupts
    00:20

  • Introduction
    07:31
  • Linkedlist example of how to delete node lock free
    03:21
  • RCU Design
    02:38
  • Why should i use rcu_assign_pointer
    01:22
  • Read operation in RCU
    02:52
  • Why should i use rcu_dereference
    01:31
  • Linux Kernel Module example 1 of read and write threads
    01:28
  • Linux Kernel Module example 2 of read and write threads
    04:54
  • When should we free memory
    01:34
  • synchronize_rcu
    03:38
  • call_rcu
    02:12
  • Can rcu read side critical sections be nested
    01:11
  • How does synchronize_rcu works internally
    02:22
  • RCU Terminology
    02:06
  • RCU variants for Linked Lists
    05:01
  • Linux Kernel Module example of rcu linked lists
    01:52
  • Advantages of RCU
    00:39
  • Question and Answer
    04:59

Instructor

Linux Trainer
Trainer at Linux Weekend Learning
Linux Trainer
  • 4.0 Instructor Rating
  • 390 Reviews
  • 7,023 Students
  • 16 Courses

I have been working on Linux for more than 7 years. I have seen many people still lack their skills on Linux. So, i am working on courses for Linux which will make them Learn Linux in an easy way. The agenda of my courses will be more practical and less theoretical. Show more examples and you will easily grab the concepts.

  • Udemy for Business
  • Teach on Udemy
  • Get the app
  • About us
  • Contact us
  • Careers
  • Blog
  • Help and Support
  • Affiliate
  • Terms
  • Privacy policy
  • Cookie settings
  • Sitemap
  • Featured courses
Udemy
© 2021 Udemy, Inc.