当前位置:网站首页>Epoll () whether it involves wait queue analysis

Epoll () whether it involves wait queue analysis

2022-07-06 18:25:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

event 1. epfd-file->eventpoll->wq:

struct eventpoll { … wait_queue_head_t wq; // be used for epoll_pwait() Waiting queue for events situation 1 analysis struct list_head rdllist; // Ready fd queue ready list struct rb_root rbr; // Red and black root ,epitem->rbn It is the node of red black tree structure struct file *file; //epoll Virtual files built in the file system … }; It is mainly used for epoll_pwait() When , determine epfd-file->eventpoll->rdlist( be ready fd) Is it empty . Suppose it is empty and epoll_pwait() Call for blocking . Then the current process will be hung to epfd-file->eventpoll->wq in , And the current process is blocked waiting , until rdlist Evoke when it is not empty epfd-file->eventpoll->poll_wait Processes in the linked list ( Mutually exclusive arousal and non mutually exclusive arousal ?) The callback function called silently feels wake_up_interruptible perhaps wake_up

situation 2. Monitored fd->poll_wait

Socket that will be monitored fd stay epoll Built during epitem and eppoll_entry epitem{ struct rb_node rbn; //epitem Hang on rbtree Node information on struct list_head rdllink; // hypothesis fd be ready , Hook in ready list struct eventpoll *ep; // Owner eventpoll( maintain rbtree rdllist poll_wait queue …) struct epoll_event event; //fd Events monitored on } struct eppoll_entry { struct list_head llink; struct epitem *base; // Belongs to epitem wait_queue_t wait; // Hook in as an element to be monitored fd Of wait In line wait_queue_head_t *whead; // Be monitored fd Waiting queue . hypothesis fd by socket. that whead by sock->sk_sleep }; eppoll_entry Mainly finished epitem and epitem At the time of the incident callback The relationship between functions . First of all, will eppoll_entry Of whead Point to fd Device waiting queue ( Same as select Medium wait_address). Then initialize eppoll_entry Of base Variable pointing to the epitem. Finally through add_wait_queue take epoll_entry Mount to fd On the device waiting queue . When the hardware data of the device arrives , When the hardware interrupt processing function wakes up the waiting process on the waiting queue , Will call the wake-up function ep_poll_callback(ep_poll_callback: When fd After the departure event . take epitem Medium rdllink Node added to readlist in (epfd-file->eventpoll->rdlist))

contrast :

1 and 2 contrast , The main reason is that the callback function of waiting queue is different ,1 The callback of is to wake up the process that is waiting for an event and is asleep ,2 The callback of is to put epitem Medium rdllink The structure is increased to ready list in .

Refer to : http://www.cnblogs.com/apprentice89/archive/2013/05/09/3068274.html http://www.cnblogs.com/apprentice89/p/3234677.html

Copyright notice : This article is an original blog article . Blog , Without consent , Shall not be reproduced .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117402.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061018310233.html