/kernel-concurrency
Kernel concurrency skill for Linux locking and synchronization. Use when choosing spinlocks vs mutexes, using RCU, seqlocks, completions, or applying memory barriers in kernel code. Activates on queries about kernel spinlock, mutex, RCU, seqlock, memory barrier, or PREEMPT_RT
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill kernel-concurrency --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/kernel-concurrency
Context preview
The summary Claude sees to decide when to auto-load this skill.
Kernel concurrency skill for Linux locking and synchronization. Use when choosing spinlocks vs mutexes, using RCU, seqlocks, completions, or applying memory barriers in kernel code. Activates on queries about kernel spinlock, mutex, RCU, seqlock, memory barrier, or PREEMPT_RT
SKILL.md
kernel-concurrency.SKILL.mdname: kernel-concurrency
description: Kernel concurrency skill for Linux locking and synchronization. Use when choosing spinlocks vs mutexes, using RCU, seqlocks, completions, or applying memory barriers in kernel code. Activates on queries about kernel spinlock, mutex, RCU, seqlock, memory barrier, or PREEMPT_RT locking.
Kernel Concurrency
Purpose
Guide agents through synchronization in the Linux kernel: spinlocks, mutexes, semaphores, RCU, seqlocks, completions, and memory ordering rules — critical for correct drivers and subsystem patches.
When to Use
- IRQ handler shares data with process context
- Read-mostly data structures needing RCU
- Choosing lock type for `probe` vs `ioctl` paths
- Debugging deadlocks or `scheduling while atomic`
Workflow
1. Lock selection tree
Context can sleep?
├── No (IRQ, spinlock held, preempt disabled)
│ └── spin_lock_irqsave() / atomic_t
└── Yes
├── Exclusive long-held → mutex
├── Reader/writer → rw_semaphore or RCU (read-mostly)
└── One-shot signal → completion**Never sleep while holding a spinlock** (`kmalloc(GFP_KERNEL)`, `mutex_lock`).
2. Spinlock + IRQ
spinlock_t lock;
unsigned long flags;
spin_lock_irqsave(&lock, flags);
/* critical section — no blocking */
spin_unlock_irqrestore(&lock, flags);
Use `spin_lock_bh` when softirq/tasklet sharing is the concern.
3. Mutex in process context
struct mutex m;
mutex_lock(&m);
/* may allocate, may sleep */
mutex_unlock(&m);
4. RCU (read-copy update)
/* Readers — no lock */
rcu_read_lock();
p = rcu_dereference(ptr);
/* use p */
rcu_read_unlock();
/* Writer */
new = kmalloc(...);
rcu_assign_pointer(ptr, new);
synchronize_rcu();
kfree(old);
RCU readers must not block indefinitely. Grace period completes after all CPUs quiescent.
5. Seqlock (jiffies, timestamps)
unsigned seq;
do {
seq = read_seqbegin(&seqlock);
/* read shared data */
} while (read_seqretry(&seqlock, seq));Writer uses `write_seqlock` / `write_sequnlock`.
6. Completions
DECLARE_COMPLETION(done);
/* waiter */
wait_for_completion(&done);
/* signaller */
complete(&done);
7. Memory barriers
Kernel provides `smp_mb()`, `smp_wmb()`, `smp_rmb()`. Device MMIO uses `readl`/`writel` (ordered on most arches). See `skills/low-level-programming/memory-model` for userspace analogies.
8. Agent usage
/kernel-concurrency Protect shared ring buffer between IRQ and read() syscall
Common Problems
| Symptom | Cause | Fix | |---------|-------|-----| | `scheduling while atomic` | Sleep under spinlock | Use `GFP_ATOMIC` or defer work | | Deadlock | AB-BA mutex order | Global lock ordering | | RCU stall | Reader blocked too long | `rcu_read_lock` section minimal | | Lost wake | `complete` before `wait` | Use `INIT_COMPLETION` each cycle | | Corrupt counter | Non-atomic RMW in IRQ | `atomic_t` or lock |
Related Skills
- `skills/kernel/device-drivers` — threaded IRQ pattern
- `skills/low-level-programming/memory-model` — C11 atomics vs kernel
- `skills/debuggers/concurrency-debugging` — userspace TSan
- `skills/kernel/kernel-internals` — scheduler preemption
- `skills/profilers/linux-perf` — lock contention profiling
Read more
name: kernel-concurrency description: Kernel concurrency skill for Linux locking and synchronization. Use when choosing spinlocks vs mutexes, using RCU, seqlocks, completions, or applying memory barriers in kernel code. Activates on queries about kernel spinlock, mutex, RCU, seqlock, memory barrier, or PREEMPT_RT locking.
Kernel Concurrency
Purpose
Guide agents through synchronization in the Linux kernel: spinlocks, mutexes, semaphores, RCU, seqlocks, completions, and memory ordering rules — critical for correct drivers and subsystem patches.
When to Use
- IRQ handler shares data with process context
- Read-mostly data structures needing RCU
- Choosing lock type for `probe` vs `ioctl` paths
- Debugging deadlocks or `scheduling while atomic`
Workflow
1. Lock selection tree
Context can sleep?
├── No (IRQ, spinlock held, preempt disabled)
│ └── spin_lock_irqsave() / atomic_t
└── Yes
├── Exclusive long-held → mutex
├── Reader/writer → rw_semaphore or RCU (read-mostly)
└── One-shot signal → completion**Never sleep while holding a spinlock** (`kmalloc(GFP_KERNEL)`, `mutex_lock`).
2. Spinlock + IRQ
spinlock_t lock; unsigned long flags; spin_lock_irqsave(&lock, flags); /* critical section — no blocking */ spin_unlock_irqrestore(&lock, flags);
Use `spin_lock_bh` when softirq/tasklet sharing is the concern.
3. Mutex in process context
struct mutex m; mutex_lock(&m); /* may allocate, may sleep */ mutex_unlock(&m);
4. RCU (read-copy update)
/* Readers — no lock */ rcu_read_lock(); p = rcu_dereference(ptr); /* use p */ rcu_read_unlock(); /* Writer */ new = kmalloc(...); rcu_assign_pointer(ptr, new); synchronize_rcu(); kfree(old);
RCU readers must not block indefinitely. Grace period completes after all CPUs quiescent.
5. Seqlock (jiffies, timestamps)
unsigned seq;
do {
seq = read_seqbegin(&seqlock);
/* read shared data */
} while (read_seqretry(&seqlock, seq));Writer uses `write_seqlock` / `write_sequnlock`.
6. Completions
DECLARE_COMPLETION(done); /* waiter */ wait_for_completion(&done); /* signaller */ complete(&done);
7. Memory barriers
Kernel provides `smp_mb()`, `smp_wmb()`, `smp_rmb()`. Device MMIO uses `readl`/`writel` (ordered on most arches). See `skills/low-level-programming/memory-model` for userspace analogies.
8. Agent usage
/kernel-concurrency Protect shared ring buffer between IRQ and read() syscall
Common Problems
| Symptom | Cause | Fix | |---------|-------|-----| | `scheduling while atomic` | Sleep under spinlock | Use `GFP_ATOMIC` or defer work | | Deadlock | AB-BA mutex order | Global lock ordering | | RCU stall | Reader blocked too long | `rcu_read_lock` section minimal | | Lost wake | `complete` before `wait` | Use `INIT_COMPLETION` each cycle | | Corrupt counter | Non-atomic RMW in IRQ | `atomic_t` or lock |
Related Skills
- `skills/kernel/device-drivers` — threaded IRQ pattern
- `skills/low-level-programming/memory-model` — C11 atomics vs kernel
- `skills/debuggers/concurrency-debugging` — userspace TSan
- `skills/kernel/kernel-internals` — scheduler preemption
- `skills/profilers/linux-perf` — lock contention profiling
A curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /custom-allocators
Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

