Linux 抢占式内核的影响?
Linux 内核抢占式的含义是什么,特别是对于创建设备驱动程序。我猜你需要更加注意资源锁定,但是还有什么其他的吗?
What are the implications of a linux kernel being preemptive, particularly for creating device drivers. I'm guessing you need to be more diligent about resource locking, but is there anything more to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所提到的,竞争条件的机会有很多,所以是的,您必须非常勤奋地使用锁。您还必须小心时机,例如何时启用/禁用中断或其他硬件资源等。您并不总是需要在这些情况下使用锁,但您可能必须重新排序代码。最后,它还会影响调度,使高优先级任务的响应速度更快,这反过来可能会对低优先级任务产生负面影响。
There are a lot more opportunities for race conditions as you had mentioned, so yes, you have to be very diligent with locks. You also have to be careful about timing, such as when you enable/disable interrupts or other hardware resources, etc. You don't always have to use locks for these situations, but you may have to reorder you code. Finally, it also effects scheduling, allowing high priority tasks to be much more responsive, which in turn may have a negative effect on the lower priority tasks.
如果不在 SMP 上,请确保需要应用此锁定补丁:“Gaurantee spinlocks 隐式屏障!PREEMPT_COUNT< /a>”,这是在 2013 年 4 月制作的。
请注意,每次代码运行“spin_unlock_”或“preemption_enable”时,都会发生抢占每当异常返回或中断返回时都是一样的。除了这些情况之外,应该没有其他问题。内核设计保证异常和中断以严格嵌入的方式处理,尽管使用 SMP 多个实例可以并行运行。
If not on SMP, make sure this lock patch need to be applied: "Gaurantee spinlocks implicit barrier for !PREEMPT_COUNT", that was made in Apr 2013.
Be aware that each time the code runs "spin_unlock_" or "preemption_enable", a preemption could kick in. It's the same whenever an exception returns or interrupt returns. Beyond those cases and the likes, there should be no other concerns. The kernel design guarantees exceptions and interrupts are handled in strictly embedded manner, though with SMP multiple instances may run in parallel.