使用wait_event_interruptible和wake_up_all在一起 [英] Using wait_event_interruptible and wake_up_all together

查看:638
本文介绍了使用wait_event_interruptible和wake_up_all在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于涉及使用阻塞和锁调度流程一类项目,我们应该使用两个内核函数:

  INT wait_event_interruptible(wait_queue_head_t Q,条件);
无效wake_up_all(wait_queue_head_t * Q);

wait_event_interruptible的解释是:


  

块一个等待队列,直到条件变为真正的当前任务。


  
  

这实际上是一个宏。它重复计算的条件,这是C code的片段,比如foo = =栏或功能()> 3.一旦条件为真,wait_event_interruptible返回0。如果条件为假,添加了当前任务与状态TASK_INTERRUPTIBLE的wait_queue_head_t名单;当前进程将阻塞,直到wake_up_all(安培; Q)被调用,那么它会重新检查条件。如果当前的任务接收到信号之前,条件成立时,宏返回-ERESTARTSYS。


和wake_up_all的解释是:


  

唤醒在等待队列中的所有任务,其状态设置为TASK_RUNNABLE。


我有一个很难搞清楚这些功能究竟是如何工作的,以及如何在一起使用。例如,当故障症状是否得到遏制?是否wait_event_interruptible连续轮询,或者它只是重新检查条件时wake_up_all叫?这个解释有点不清楚。

如果你能给如何使用这些功能结合在一起的例子,这将是非常有益的。


解决方案

  

是否wait_event_interruptible连续轮询,或者只是做它
  重新检查条件时wake_up_all叫?对此的解释是
  有点不清楚。


调度的整点是为了避免在这样的情况下投票。会发生什么事是你引述pcisely说明$ P $:的条件仅在复核WAKE_UP,即例如,如果给定的任务正在等待中产生的数据:


  • 消费数据是否可用


  • 如果不是(即条件为假),它进入睡眠状态
    并添加到一个等待队列


  • 在唤醒重试


虽然在生产者侧


  • 在数据产生时,设置一些标志,或添加一些东西到一个列表
    使得由消费者评估的条件变为真


  • 来电或WAKE_UP所有WAKE_UP在等待队列


现在,我建议你尝试使用它们,回来跟你尝试另一个问题,code,如果它不工作,你所希望的方式。

For a class project involving scheduling processes using blocking and locks, we're supposed to use two kernel functions:

int wait_event_interruptible(wait_queue_head_t q, CONDITION);
void wake_up_all(wait_queue_head_t *q); 

The explanation of wait_event_interruptible is:

Blocks the current task on a wait queue until a CONDITION becomes true.

This is actually a macro. It repeatedly evaluates the CONDITION, which is a fragment of C code such as foo == bar or function() > 3. Once the condition is true, wait_event_interruptible returns 0. If the condition is false, the current task is added to the wait_queue_head_t list with state TASK_INTERRUPTIBLE; the current process will block until wake_up_all(&q) is called, then it will re-check the CONDITION. If the current task receives a signal before CONDITION becomes true, the macro returns -ERESTARTSYS.

And the explanation of wake_up_all is:

Wake up all tasks in the wait queue by setting their states to TASK_RUNNABLE.

I'm having a hard time figuring out how exactly these functions work and how to use them together. For example, when does the CONDITION get checked? Does wait_event_interruptible continuously poll, or does it only recheck the condition when wake_up_all is called? This explanation is a little unclear.

If you could give an example of how to use these functions together that would be very helpful.

解决方案

Does wait_event_interruptible continuously poll, or does it only recheck the condition when wake_up_all is called? This explanation is a little unclear.

The whole point of a scheduler is to avoid polling in cases like this. What happens is precisely described in what you quoted : The condition is only rechecked on wake_up, ie for example if a given task is waiting for data to be produced :

  • consumer check if data is available

  • if not (ie condition false) it goes to sleep and is added to a wait queue

  • retry when waked up

While on the producer side

  • Once data is produced, set some flag, or add something to a list so that the condition evaluated by the consumer becomes true

  • call wake_up or wake_up all on a waitqueue

Now , I suggest you try to use them, and come back with another question AND code you tried if it does not work the way you want.

这篇关于使用wait_event_interruptible和wake_up_all在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆