Interrupt handler and lock
It goes without saying that you are in an atomic context and must only use spinlock for concurrency. Whenever there is global data accessible by both user code (the user task, that is, the system call) and interrupt code, this shared data should be protected by spin_lock_irqsave() in the user code. Let's see why we can't just use spin_lock. An interrupt handler will always have priority on the user task, even if that task is holding a spinlock. Simply disabling IRQ is not sufficient. An interrupt may happen on another CPU. It would be a disaster if a user task updating the data were interrupted by an interrupt handler trying to access the same data. Using spin_lock_irqsave() will disable all interrupts on the local ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access