Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In linux, how to make sure a sequence of code is executed without any interruption

I have a routine that toggles the GPIO pin high/low, and have delay between the highs and lows (using udelay), and then samples the GPIO state for some period. I need to make sure this part of the code is executed without being pre-empted by the scheduler or by any possible interrupts. I am running the code on a dual core ARM system so it should be SMP. Is Spin_Lock_IrqSave() safe enough for such purpose? I got a feeling my code is still somehow being interrupted occasionally but no proof yet.

Thanks a lot.

like image 537
user1697356 Avatar asked Oct 07 '22 12:10

user1697356


1 Answers

If you want to disable preemption, use preempt_disable() and preempt_enable(). If you want to disable interrupts, use local_irq_disable() and local_irq_enable()

spin_lock_irqsave will normally do both of these, though some "real-time" enhancements sometimes allow spinlocks to schedule, so it is always best to say what you mean.

like image 154
user1699045 Avatar answered Oct 10 '22 02:10

user1699045