Friday, December 27, 2013

How interrupt disabling works on Linux

In this post I am going to discuss how the Linux kernel API are used to disable interrupts on the platform. Let us look at an example.

I am going to discuss how an API like local_irq_disable() works on Linux. The definition of this API is in include/linux/irqflags.h. This eventually calls  raw_local_irq_disable() which calls arch_local_irq_disable().


The arch_local_irq_disable() function now has a definition based on the underlying architecture. For example the definition for different architectures would be like:

include/asm-generic/irqflags.h, line52
arch/microblaze/include/asm/irqflags.h, line 28
arch/h8300/include/asm/irqflags.h, line 11
arch/cris/include/arch-v10/arch/irqflags.h, line 13
arch/cris/include/arch-v32/arch/irqflags.h, line 14
arch/powerpc/include/asm/hw_irq.h, line 55


If we consider the powerpc architecture, eventually all that the function does is run assembly code that writes to registers on the platform to disable interrupts on the platform.


55 static inline unsigned long arch_local_irq_disable(void)
56 {
57 unsigned long flags, zero;
58
59 asm volatile(
60 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
61 : "=r" (flags), "=&r" (zero)
62 : "i" (offsetof(struct paca_struct, soft_enabled))
63 : "memory");
64
 65 return flags;
66 }

0 comments:

Post a Comment