Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is spinlock required for every interrupt handler?

In Chapter 5 of ULK the author states as follows:

"...each interrupt handler is serialized with respect to itself-that is, it cannot execute more than one concurrently. Thus, accessing the data struct does not require synchronization primitives"

I don't quite understand why interrupt handlers is "serialized" on modern CPUs with multiple cores. I'm thinking it could be possible that a same ISR can be run on different cores simultaneously, right? If that's the case, if you don't use spinlock to protect your data it can come to a race condition.

So my question is, on a modern system with multi-cpus, for every interrupt handler you are going to write that will read & write some data, is spinlock always needed?

like image 727
Jun Avatar asked Aug 24 '13 17:08

Jun


People also ask

Can we use spinlock in interrupt handler?

Spin locks can be used in interrupt handlers, whereas semaphores cannot be used because they sleep. If a lock is used in an interrupt handler, you must also disable local interrupts (interrupt requests on the current processor) before obtaining the lock.

Do interrupts need to be disabled when a spinlock is held?

Interrupt handlers do need to be fast & not be blocked though, so they just keep spinning while trying to acquire the lock, which would cause a deadlock (i.e. system freeze) since syscall foo never gets a chance to finish and release its lock.

Where is spinlock used?

SpinLock are typically used when working with interrupts to perform busy waiting inside a loop till the resource is made available. SpinLock don't cause the thread to be preempted, rather, it continues to spin till lock on the resource is released.

Why spinlocks are used in interrupt handler?

Because they usage in the IH can dramatically increases the interrupt handling latencies (in case of IH running in the context of low priority thread) and is able to produce deadlocks (in case of IH running in the context of thread which hold the lock).


1 Answers

While executing interrupt handlers, the kernel explicitly disables that particular interrupt line at the interrupt controller, so one interrupt handler cannot be executed more than once concurrently. (The handlers of other interrupts can run concurrently, though.)

like image 163
CL. Avatar answered Sep 24 '22 09:09

CL.