基于韦东山视频用于QT6410
poll机制分析
韦东山2009.12.10
所有的系统调用,基于都可以在它的名字前加上“sys_”前缀,这就是它在内核中对应的函数。比如系统调用open、read、write、poll,与之对应的内核函数为:sys_open、sys_read、sys_write、sys_poll。
一、内核框架:
对于系统调用poll或select,它们对应的内核函数都是sys_poll。分析sys_poll,即可理解poll机制。
1. sys_poll函数位于fs/select.c文件中,代码如下:
asmlinkagelong sys_poll(struct pollfd __user *ufds, unsigned int nfds,
long timeout_msecs)
{
s64 timeout_jiffies;
if (timeout_msecs > 0) {
#ifHZ > 1000
/* We can only overflow if HZ >1000 */
if (timeout_msecs / 1000 >(s64)0x7fffffffffffffffULL / (s64)HZ)
timeout_jiffies = -1;
else
#endif
timeout_jiffies =msecs_to_jiffies(timeout_msecs);
} else {
/* Infinite (< 0) or no (0)timeout */
timeout_jiffies = timeout_msecs;
}
return do_sys_poll(ufds,nfds, &timeout_jiffies);
}
它对超时参数稍作处理后,直接调用do_sys_poll。
2. do_sys_poll函数也位于位于fs/select.c文件中,我们忽略其他代码:
intdo_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout)
{