⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux设备驱动程序学习(5)-高级字符驱动程序操作[(2)阻塞型i-o和休眠] - linux设备驱动程序 - tekkaman ninja.htm

📁 Linux设备驱动程序学习(5)-高级字符驱动程序操作[(2)阻塞型I-O和休眠] - Linux设备驱动程序.rar
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                                style="COLOR: rgb(0,0,204)">[</SPAN>kseriod<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;77 
                                root SW <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;78 
                                root SW <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;79 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kswapd0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;80 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>aio<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;707 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>mtdblockd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;708 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>nftld<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;709 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>inftld<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;710 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>rfdd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;742 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kpsmoused<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;751 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kmmcd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;769 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>rpciod<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;778 
                                root 1752 S <SPAN 
                                style="COLOR: rgb(0,0,204)">-</SPAN>sh<BR>&nbsp;&nbsp;779 
                                root 1744 S init<BR>&nbsp;&nbsp;781 root 1744 S 
                                init<BR>&nbsp;&nbsp;783 root 1744 S 
                                init<BR>&nbsp;&nbsp;787 root 1744 S 
                                init<BR>&nbsp;<SPAN 
                                style="COLOR: rgb(255,1,2)">&nbsp;799 root 1336 
                                S ./sleepy_testr</SPAN><BR>&nbsp;&nbsp;804 root 
                                1744 R ps<BR><SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>sleepy_testw<BR><SPAN 
                                style="COLOR: rgb(255,0,0)">write</SPAN> 
                                code<SPAN 
                                style="COLOR: rgb(0,0,204)">=</SPAN>0<BR><SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN><SPAN 
                                style="COLOR: rgb(255,0,0)">read</SPAN> 
                                code<SPAN 
                                style="COLOR: rgb(0,0,204)">=</SPAN>0<BR><BR><SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>1<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">+</SPAN> Done <SPAN 
                                style="COLOR: rgb(0,0,204)">.</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>sleepy_testr<BR><SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>Tekkaman2440@SBC2440V4<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><SPAN 
                                style="COLOR: rgb(0,0,204)">#</SPAN>ps<BR>&nbsp;&nbsp;PID 
                                Uid VSZ Stat 
                                Command<BR>&nbsp;&nbsp;&nbsp;&nbsp;1 root 1744 S 
                                init<BR>&nbsp;&nbsp;&nbsp;&nbsp;2 root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kthreadd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;3 
                                root SWN <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>ksoftirqd<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;4 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>watchdog<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;5 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>events<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;6 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>khelper<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;59 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kblockd<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;60 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>ksuspend_usbd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;63 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>khubd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;65 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kseriod<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;77 
                                root SW <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;78 
                                root SW <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>pdflush<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;79 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kswapd0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;&nbsp;80 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>aio<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;707 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>mtdblockd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;708 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>nftld<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;709 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>inftld<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;710 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>rfdd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;742 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kpsmoused<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;751 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>kmmcd<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;769 
                                root SW<SPAN 
                                style="COLOR: rgb(0,0,204)">&lt;</SPAN> <SPAN 
                                style="COLOR: rgb(0,0,204)">[</SPAN>rpciod<SPAN 
                                style="COLOR: rgb(0,0,204)">/</SPAN>0<SPAN 
                                style="COLOR: rgb(0,0,204)">]</SPAN><BR>&nbsp;&nbsp;778 
                                root 1752 S <SPAN 
                                style="COLOR: rgb(0,0,204)">-</SPAN>sh<BR>&nbsp;&nbsp;779 
                                root 1744 S init<BR>&nbsp;&nbsp;781 root 1744 S 
                                init<BR>&nbsp;&nbsp;783 root 1744 S 
                                init<BR>&nbsp;&nbsp;787 root 1744 S 
                                init<BR>&nbsp;&nbsp;806 root 1744 R 
                                ps</SPAN></CODE></P></TD></TR></TBODY></TABLE>
                              <P>
                              <HR id=null>
                              <BR><FONT color=#0000ff 
                              size=4><STRONG>阻塞和非阻塞操作</STRONG></FONT><BR>
                              <P></P>
                              <P>全功能的 read 和 write 方法涉及到进程可以决定是进行非阻塞 I/O还是阻塞 
                              I/O操作。明确的非阻塞 I/O 由 filp-&gt;f_flags 中的 O_NONBLOCK 
                              标志来指示(定义再 <FONT 
                              color=#0000ff>&lt;linux/fcntl.h&gt;</FONT> ,被 
                              <FONT 
                              color=#0000ff>&lt;linux/fs.h&gt;</FONT>自动包含)。浏览源码,会发现O_NONBLOCK 
                              的另一个名字:O_NDELAY ,这是为了兼容 System V 代码。O_NONBLOCK 
                              标志缺省地被清除,因为等待数据的进程的正常行为只是睡眠. </P>
                              <P>其实不一定只有read 和 write 
                              方法有阻塞操作,open也可以有阻塞操作。后面会见到。而我的项目有一个和CPLD的接口的驱动,我决定要在ioctl 
                              中使用阻塞。</P>
                              <P>以下是后面的scullpipe实验的有关阻塞的代码,我觉得写得很好,先结合书上的介绍看看吧:</P>
                              <TABLE style="B

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -