linux内核中sys_poll()的简化分析
app:poll or select;
kernel: sys_poll(); do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,struct timespec *end_time); poll_initwait(&table); init_poll_funcptr(&pwq->pt, __pollwait);>table->qproc =__pollwait; do_poll(nfds, head, &table, end_time); for (;;) { if (do_pollfd(pfd, pt)) { //mask = file->f_op->poll(file, pwait);return mask ----调用驱动中的poll函数 count++;//如果驱动的poll函数返回非零,那么count++ pt = NULL; } //break条件:count非零,超时,有信号等待处理 if (count || ! timed_out||signal_pending(current)) break; //休眠__timeout,期间没事发生,则timed_out减为零,再次循环,break //休眠期间被中断唤醒等待队列,则再次循环,执行驱动中的poll,返回非零mask, 则break __timeout=schedule_timeout(__timeout); }