[英]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. 我有一个程序可以将GPIO引脚切换为高电平/低电平,并在高电平和低电平之间有延迟(使用
udelay
),然后对GPIO状态进行一段时间的采样。 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.
我在双核ARM系统上运行代码,所以它应该是SMP。 Is
Spin_Lock_IrqSave()
safe enough for such purpose? Spin_Lock_IrqSave()
是否足够安全用于此目的? I got a feeling my code is still somehow being interrupted occasionally but no proof yet. 我感觉我的代码仍然偶尔会被打断,但还没有证据。
Thanks a lot. 非常感谢。
If you want to disable preemption, use preempt_disable()
and preempt_enable()
. 如果要禁用抢占,请使用
preempt_disable()
和preempt_enable()
。 If you want to disable interrupts, use local_irq_disable()
and local_irq_enable()
如果要禁用中断,请使用
local_irq_disable()
和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. spin_lock_irqsave
通常会同时执行这两个操作,虽然一些“实时”增强功能有时会让自旋锁安排,所以最好说出你的意思。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.