Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if interrupts are disabled?

Tags:

c

linux-kernel

Is there any way (or a useful function) to know whether interrupts are disabled or not?

like image 286
Yuval Avatar asked Oct 24 '12 12:10

Yuval


People also ask

How are interrupts enabled and disabled?

Interrupts are disabled by changing the control bits in the PS (except in the case of edgetriggered interrupts). 4. The device is informed that its request has been recognized, and in response, it deactivates the interrupt-request signal.

How do I turn off interrupt?

Whenever disabling interrupts, the CPU will be unable to switch processes and processes can use shared variables without another process accessing it. The most obvious way to achieve mutual exclusion is to allow a process to disable interrupts before it enters critical sections.

How do I enable interrupts?

The Interrupt Enable register is programmed through two addresses. To set the enable bit, you need to write to the SETENA register address; to clear the enable bit, you need to write to the CLRENA register address. In this way, enabling or disabling an interrupt will not affect other interrupt enable states.

Why would a programmer disable interrupts?

You need to disable interrupts to ensure atomic access. You don't want any other process to access and potentially modify that variable while you're reading it.


1 Answers

You can use irqs_disabled() function:

#include <linux/irqflags.h>

int i = irqs_disabled();
like image 126
Serge Avatar answered Sep 28 '22 03:09

Serge