Recently, I am reading about linux locking,from https://www.kernel.org/doc/html/latest/locking/locktypes.html#local-lock when I read this :
local_lock on RT The mapping of local_lock to spinlock_t on PREEMPT_RT kernels has a few implications. For example, on a non-PREEMPT_RT kernel the following code sequence works as expected:
local_lock_irq(&local_lock);
raw_spin_lock(&lock);
and is fully equivalent to:
raw_spin_lock_irq(&lock);
On a PREEMPT_RT kernel this code sequence breaks because local_lock_irq() is mapped to a per-CPU spinlock_t which neither disables interrupts nor preemption. The following code sequence works perfectly correct on both PREEMPT_RT and non-PREEMPT_RT kernels:
local_lock_irq(&local_lock);
spin_lock(&lock);
I'm confused by this description, as I know,
- local_lock_irq on PREEMPT_RT is implemented by migrate_disable and a percpu spinlock, it means , neither disables interrupts nor preemption
- spin_lock on PREEMPT_RT is implemented by RT_MUTEX
- IRQ is implemented by interrupt thread
so,on the first sample, on PREEMPT_RT kernel, since after local_lock_irq it may be preempted by another thread(interrupt thread), so here said "this code sequence breaks" right?
local_lock_irq(&local_lock);
raw_spin_lock(&lock);
but on the second sample,we know on a NON-PREEMPT_RT kernel, since spin_lock equals raw_spin_lock, I think it's code sequence equals the first sample, But on a PREEMPT_RT, after local_lock_irq,it still can be preempted by another thread(interrupt thread), why does it says "code sequence works perfectly correct on both PREEMPT_RT and non-PREEMPT_RT kernels" ??????
local_lock_irq(&local_lock);
spin_lock(&lock);
spin_lock is just a kind of SMP concurrency protection mechanism, whatever I use raw_spin_lock or spin_lock, on a PREEMPT_RT, It just affects whether I can be preempted