linux设备驱动文件操作:有可能有竞争条件吗?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux设备驱动文件操作:有可能有竞争条件吗?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1839字,纯文字阅读大概需要3分钟。
内容图文
考虑一个实现open(),read(),write(),close(),unlocked_ioctl()和mmap()的linux设备驱动程序.
现在,假设多个(或相同的)进程同时打开同一设备(/ dev / device).
这些文件操作是否以任何方式保证是原子w.r.t.彼此或者每个open(),read(),write(),close()都应该使用互斥锁,以便它们中的一个在更改过程中不会抢占它们,例如缓冲区数据(通过相同的inode)?
如果内核保证彼此的原子性并且每个操作发现并使缓冲区/硬件保持一致状态,则不应该是必要的.
请重新引导我一些参考(如果你知道的话).
谢谢.
编辑:它在其中一条评论中,但我找到的最佳参考是:
http://www.makelinux.net/ldd3/chp-6-sect-6
它还显示了通过限制单个用户来缓解问题的策略,通过创建副本,强制用户等待等.
解决方法:
设备驱动程序代码在调用系统调用的进程中运行.在调用模块代码之前,内核没有隐藏的“模块锁”.当单独的进程调用最终在驱动程序代码中的系统调用时,并发驱动程序调用肯定是可能的.
正如您所料,内核更容易实现简单性和性能.在访问共享状态时,您可以获取必要的自旋锁和信号量.
参见Chapter 5的Chapter 5,其中详细讨论了并发性和竞争条件.
Concurrency and Its Management
In a modern Linux system, there are numerous sources of concurrency and, therefore, possible race conditions. Multiple user-space processes are running, and they
can access your code in surprising combinations of ways. SMP systems can be executing your code simultaneously on different processors. Kernel code is preemptible;
your driver’s code can lose the processor at any time, and the process that replaces it
could also be running in your driver. Device interrupts are asynchronous events that
can cause concurrent execution of your code. The kernel also provides various mechanisms for delayed code execution, such as workqueues, tasklets, and timers, which can cause your code to run at any time in ways unrelated to what the current process is doing. In the modern, hot-pluggable world, your device could simply disappear while you are in the middle of working with it.
内容总结
以上是互联网集市为您收集整理的linux设备驱动文件操作:有可能有竞争条件吗?全部内容,希望文章能够帮你解决linux设备驱动文件操作:有可能有竞争条件吗?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。