driver - Why linux disables kernel preemption after the kernel code holds a spinlock? -
i new linux , reading linux device drivers book rubini & corbet. confused @ 1 statement related spinlocks
; book states
if nonpreemptive uniprocessor system ever went spin on lock, spin forever; no other thread ever able obtain cpu release lock. reason, spinlock operations on uniprocessor systems without preemption enabled optimized nothing, exception of ones change irq masking status.
further book states
the kernel preemption case handled spinlock code itself. time kernel code holds spinlock, preemption disabled on relevant processor. uniprocessor systems must disable preemption in way avoid race conditions.
question : on uniprocessor system, if kernel preemption disabled whenever kernel code (executing on behalf of user process) holds spinlock, how process ever chance run , hence try @ acquring spinlock ? why linux kernel disables kernel preemption whenever kernel code holds spinlock?
the answer first question reasoning behind second.
spinlocks acquired kernel may implemented turning off preemption, because ensures kernel complete critical section without process interfering. entire point process not able run until kernel releases lock.
there no reason has implemented way; simple way implement , prevents process spinning on lock kernel holds. trick works case in kernel has acquired lock: user processes can not turn off preemption, , if kernel spinning (i.e. tries acquire spinlock process holds it) better leave preemption on! otherwise system hang since kernel waiting lock not released because process holding can not release it.
the kernel acquiring spinlock special case. if user level program acquires spinlock, preemption not disabled.
Comments
Post a Comment