I saw that fs/eventpoll.c
in the kernel source code is written like this:
我看到fs / eventpoll。c在内核源代码中是这样写的:
static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
int maxevents, long timeout)
{
....
init_waitqueue_entry(&wait, current);
__add_wait_queue_exclusive(&ep->wq, &wait); // *** NB
....
}
Does that "exclusive" mean that only one wait item (process or thread in userspace) will be waked up?
这是否意味着只有一个等待项(进程或用户空间中的线程)将被唤醒?
But when I wrote some test code, I saw that the thundering herd problem still exists.
但是,当我编写一些测试代码时,我发现仍然存在巨大的从众问题。
And WHY can't it be solved? Thanks!
为什么不能解决呢?谢谢!
2 个解决方案
#1
2
In the kernel code we can see in include/linux/wait.h
that __add_wait_queue_exclusive()
adds the entry to the head of the list:
在内核代码中,我们可以看到include/linux/wait。h __add_wait_queue_exclusive()将条目添加到列表的头部:
__add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
{
wait->flags |= WQ_FLAG_EXCLUSIVE;
__add_wait_queue(q, wait);
}
When it comes to waking up static void __wake_up_common()
in sched/wait.c
does wake only the first tasks that are not exclusive and the first exclusive one. So normally only one tasks gets woken up.
在sched/wait中唤醒静态void __wake_up_common()。c只唤醒了第一个不排他的任务和第一个排他的任务。通常只有一个任务被唤醒。
#2
0
It depends on whether you are using the same epfd. The flag WQ_FLAG_EXCLUSIVE is works only for the TASKs waiting on the same eventpoll.
这取决于你是否使用相同的epfd。标志WQ_FLAG_EXCLUSIVE是用于等待相同eventpoll的任务。
If your testing code use different epfd monitor on the same socket, YES, the issue exists.
如果您的测试代码在同一个套接字上使用不同的epfd监视器,是的,问题存在。
#1
2
In the kernel code we can see in include/linux/wait.h
that __add_wait_queue_exclusive()
adds the entry to the head of the list:
在内核代码中,我们可以看到include/linux/wait。h __add_wait_queue_exclusive()将条目添加到列表的头部:
__add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
{
wait->flags |= WQ_FLAG_EXCLUSIVE;
__add_wait_queue(q, wait);
}
When it comes to waking up static void __wake_up_common()
in sched/wait.c
does wake only the first tasks that are not exclusive and the first exclusive one. So normally only one tasks gets woken up.
在sched/wait中唤醒静态void __wake_up_common()。c只唤醒了第一个不排他的任务和第一个排他的任务。通常只有一个任务被唤醒。
#2
0
It depends on whether you are using the same epfd. The flag WQ_FLAG_EXCLUSIVE is works only for the TASKs waiting on the same eventpoll.
这取决于你是否使用相同的epfd。标志WQ_FLAG_EXCLUSIVE是用于等待相同eventpoll的任务。
If your testing code use different epfd monitor on the same socket, YES, the issue exists.
如果您的测试代码在同一个套接字上使用不同的epfd监视器,是的,问题存在。