introduction of kqueue/kevent

2009-05-13 07:58:50来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


                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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:FreeBSD环境下SSH的相关阅读笔记

下一篇:BSD下虚拟机qemu 入门详解