From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 1 20:06:46 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CC84116A400 for ; Sat, 1 Apr 2006 20:06:46 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.FreeBSD.org (Postfix) with ESMTP id 20DE743D53 for ; Sat, 1 Apr 2006 20:06:45 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (ki9e7ab78prkoqq2@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.4/8.13.3) with ESMTP id k31K6eoF086179; Sat, 1 Apr 2006 12:06:41 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.4/8.13.3/Submit) id k31K6dpI086178; Sat, 1 Apr 2006 12:06:39 -0800 (PST) (envelope-from jmg) Date: Sat, 1 Apr 2006 12:06:39 -0800 From: John-Mark Gurney To: =?iso-8859-1?Q?V=E1clav?= Haisman Message-ID: <20060401200639.GD53811@funkthat.com> Mail-Followup-To: =?iso-8859-1?Q?V=E1clav?= Haisman , Dan Nelson , hackers@freebsd.org References: <442E9354.5010700@sh.cvut.cz> <20060401180311.GA83967@dan.emsphone.com> <442EC7F7.3000608@sh.cvut.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <442EC7F7.3000608@sh.cvut.cz> User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html Cc: hackers@freebsd.org, Dan Nelson Subject: Re: kqueue oddity X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John-Mark Gurney List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Apr 2006 20:06:46 -0000 Vclav Haisman wrote this message on Sat, Apr 01, 2006 at 20:35 +0200: > Dan Nelson wrote: > > In the last episode (Apr 01), Vclav Haisman said: > >> Hi, > >> I have a little problem with kqueue/kevent. I am getting somewhat > >> strange events from kevent(). The struct kevent's contents looks like this: > >> > >> kevent {.ident = 1, .filter = 0xfffffffe, .flags = 0x0001, > >> .fflags = 0x00000000, .data = 0x000084c6} > >> > >> .ident == 1 is stdout. > >> .filter == 0x fffffffe is -2 is EVFILT_WRITE which makes sense for stdout. > >> .fflags is empty, nothing out of ordinary for EVFILT_WRITE. > >> And here comes the oddity: .flags == 0x0001 means EV_ADD which totally > >> doesn't make sense to me and neither does according to man kqueue. The > >> code that exhibits this behaviour is io_loop_handler_run() in > >> ioloop-kqueue.c of Dovecot IMAP server. > > > > It's a kqueue bug, but a minor one. The problem is that the same > > "flags" field is used to pass "actions" from the client, and return > > status from the kernel. When you call kqueue with EV_ADD, the kernel > > never clears the flags when creating the internal object, so it's > > always visible when events fire. This can get annoying when trussing > > kqueue-using programs because very single event has the EV_ADD flag :) > > Apply the following diff to have the kernel strip EV_ADD: > > > > Index: kern_event.c > > =================================================================== > > RCS file: /home/ncvs/src/sys/kern/kern_event.c,v > > retrieving revision 1.79.2.9 > > diff -u -p -r1.79.2.9 kern_event.c > > --- kern_event.c 29 Jun 2005 18:08:31 -0000 1.79.2.9 > > +++ kern_event.c 7 Jul 2005 18:51:29 -0000 > > @@ -864,6 +864,7 @@ findkn: > > kev->fflags = 0; > > kev->data = 0; > > kn->kn_kevent = *kev; > > + kn->kn_kevent.flags &= ~EV_ADD; > > kn->kn_status = KN_INFLUX|KN_DETACHED; > > > > error = knote_attach(kn, kq); > > > > > Thanks. Why isn't this fix applied? From the patch's time stamp it seems > like it is known for quite some time now. Because I was never informed of the patch, so had no clue that it was necessary... I'll commit a similar patch shortly... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."