introduction of kqueue/kevent
2009-05-13 07:58:50来源:未知 阅读 ()
Here is a brief introduction about kqueue/kevent mechanism in FreeBSD. It is just my note. The Operating System I use during this note.
[amd64box:~]$uname -a
FreeBSD amd64box 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Mon Apr 23 21:42:50 CST 2007 root@:/usr/src/sys/amd64/compile/AMD64MP amd64
A kqueue is a container of state for kevent calls.
int kevent(int kq, const struct kevent *changelist, int nchanges,
/* register these kevents on this kqueue */ struct kevent *eventlist, int nevents,
/* get ready kevents from this kqueue */ const struct timespec *timeout);
A kqueue dispatches those kevents in changelist to files they point to, and he knows which ones have been dispatched or not. Every file will report to this kqueue if its status changed (if this kqueue is interested in it). The kqueue will keep these reports and send them to user via kevent when requested.
kqueue_register tell the kqueue to dispatch this kevent (called knote in kernel) to corresponding file, and kqueue will keep this kevent in a private list, so that there are at most one (ident, filter) in one kqueue for any ident and/or filter.
kqueue_scan scan the pending kevents on a kqueue if any and msleep on it if there are no kevents pending on the kqueue
KNOTE_ACTIVATE a kevent is triggered. Insert the kevent into its kqueue's list and tell any monitor that the kqueue is OK. to avoid deadlock, use taskqueue to activate kevents on si_note asynchronously.
This is a common scene.
A registers kevents kev0, kev1 on a kqueue kq1, kq1 dispatches these kevents to files f0, f1, and A msleeps on kq1. B triggers kev0, puts kev0 on the active list of kq1 and wakeups A from kq1 asynchronously. A finds that kev0 is triggered and returns to user mode.
Locks
KQ_LOCK protects the kqueue and knotes on it.
kq_global acquired if we need lock multiple kqueues
KN_INFLUX protects a knote when its kqueue is unlocked
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10543/showart_290779.html
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:BSD下虚拟机qemu 入门详解
- Freebsd oracle 10g 2009-05-13
- freebsd7 RAID0, Geom方式 成功 2009-05-13
- netbsd启动gnome失败! 2009-05-13
- KDE/FreeBSD 测试 QT-4.5.1. 2009-05-13
- 提示:bad kernel: arp : 内网IP地址 is on em0 but got rep 2009-05-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash