linux内核的等待队列使用方法,wait_queue_head_t,进程休眠
来源:互联网 发布:淘宝女包品牌排行 编辑:程序博客网 时间:2024/06/11 22:11
阅读vhost的时候,发现使用了大量的等待队列和poll,这里温故而知新一下。
注:wait_queue_t是等待在wait_queue_head_t队列中的等待元素
当你在用户空间需要读写一大片数据的时候,这个就用上了。
interruptible_sleep_on( &wq ) 是用来将目前的 process,也就是要求写资料到buffer 的 process放到 wq 这个 wait_queue 里。在 interruptible_sleep_on 里,则是最后会呼叫 schedule() 来做 schedule 的动作,谁调用了schedule谁就趴下,让别人去运行,醒来就原地起来,执行schedule()后的代码。那个调用了schedule的家伙什么 醒过来呢?这时候就需要用到另一个函数了wake_up_interruptible()了。
linux中最简单的休眠方式是下面的宏,
wait_event(queue, condition) /* 进程将被置于非中断休眠(uninterruptible sleep)*/
wait_event_interruptible(queue, condition) /*进程可被信号中断休眠,返回非0值表示休眠被信号中断*/
wait_event_timeout(queue, condition, timeout) /*等待限定时间jiffy,condition满足其一返回0*/
wait_event_interruptible_timeout(queue, condition, timeout)
queue是等待队列头,传值方式
condition是任意一个布尔表达式,在休眠前后多次对condition求值,为真则唤醒
唤醒进程的基本函数是wake_up
void wake_up(wait_queue_head_t *queue); /*唤醒等待在给定queue上的所有进程*/
void wake_up_interruptible(wait_queue_head_t *queue);
实践中,一般是wait_event和 wake_up, wait_event_interruptible和 wake_up_interruptible 成对使用。
【补充】其实看了那么多,他们也没有给个立即可用的步骤,写blog嘛,就是分享心得。我基于2.6.24总结一下,希望对大家有帮助:
1、定义:wait_queue_head_t my_queue;
2、初始化 init_waitqueue_head(&my_queue);
3、在一个函数里面等待:wait_event(queue, condition) ;(别在中断里面搞)
4、在另一个函数里面唤醒:wake_up(wait_queue_head_t *queue); (这个可以在中断调用,去唤醒别的进程,特别是dma操作类的)
有好几个等待和唤醒函数,大家可以慢慢试。
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的等待队列使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- 等待队列wait_queue_head_t使用方法
- Linux内核等待队列探究-wait_queue_t-wait_queue_head_t
- linux进程的休眠(等待队列)
- linux进程的休眠(等待队列)
- linux进程的休眠(等待队列)
- linux进程的休眠(等待队列)
- linux进程的休眠(等待队列)
- Linux内核等待队列的使用方法总结
- Android电话号码无需拨号即可显示状态(空号、通话中、有空、欠费、不在服务区等),像QQ状态一样 小黄人软件原创
- 苹果开发 笔记(82)记录一些错误日志
- 如何有效沟通-1分钟原则
- host_notifier, 虚拟机通过VHOST发包流程(基于kernel3.10.0 && qemu 2.0.0)
- Vhost Architecture(基于kernel3.10.0 & qemu2.0.0)
- linux内核的等待队列使用方法,wait_queue_head_t,进程休眠
- linux poll 和 等待队列休眠的关系(基于kernel 3.10.0)
- [个人推荐] Linux poll机制分析(基于内核3.10.0)
- 安卓优化
- [个人推荐]理解poll_wait
- select(poll)实现代码实现分析(基于kernel 3.10.0)
- 新手对Bash环境变量解析漏洞的理解 http://www.linuxidc.com/Linux/2014-10/107984.htm
- select(poll)实现代码实现分析(基于kernel 3.10.0)
- KVM源代码分析1:基本工作原理