From owner-freebsd-arch@FreeBSD.ORG Fri Sep 22 13:25:23 2006 Return-Path: X-Original-To: freebsd-arch@FreeBSD.org Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6B9D416A49E; Fri, 22 Sep 2006 13:25:23 +0000 (UTC) (envelope-from is@rambler-co.ru) Received: from yam.park.rambler.ru (yam.park.rambler.ru [81.19.64.116]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6982943DB9; Fri, 22 Sep 2006 13:25:19 +0000 (GMT) (envelope-from is@rambler-co.ru) Received: from is.park.rambler.ru (is.park.rambler.ru [81.19.64.102]) by yam.park.rambler.ru (8.13.6/8.13.3) with ESMTP id k8MDPH6W078617; Fri, 22 Sep 2006 17:25:17 +0400 (MSD) (envelope-from is@rambler-co.ru) Date: Fri, 22 Sep 2006 17:25:37 +0400 (MSD) From: Igor Sysoev X-X-Sender: is@is.park.rambler.ru To: John-Mark Gurney In-Reply-To: <20060917210426.GI9421@funkthat.com> Message-ID: <20060922171542.G17859@is.park.rambler.ru> References: <20060917210426.GI9421@funkthat.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-current@FreeBSD.org, freebsd-arch@FreeBSD.org Subject: Re: kqueue disable on delivery... X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Sep 2006 13:25:23 -0000 On Sun, 17 Sep 2006, John-Mark Gurney wrote: > I have implemented a couple additional features to kqueue. These allow > kqueue to be a multithreaded event delivery system that can guarantee > that the event will only be active in one thread at any time. > > The first is EV_DOD, aka disable on delivery. When the event will be > delivered to userland, the knote is marked disabled so we don't > have to go through the expense of reallocing the knote each time. > (Reallocation of the knote is also lock intensive, and disabling is > cheap.) In my opinion, it's too implementation specific flag. > Even though this means that the event will only ever be active in a > thread at a time, (when you're done handling the event, you reenable > it), removing the event from the queue outside the event handler (say > a timeout handler for the connection) poses to be a problem. If you > simply close the socket, the event disappears, but then there is a > race between another event being created with the same socket, and > notification of the handler that you want the event to stop. > > In order to handle that situation, I have come up w/ EV_FORCEOS, aka > FORCE ONE_SHOT. EV_ONESHOT events have the advantage that once queued, > they don't care if they have been activated or not, they will be returned > the next round. This means that the timeout handler can safely set > EV_FORCEOS on the handler, and either if it's _DISABLED (handler running > and will reenable it), or it's _ENABLED, it will get dispatched, allowing > the handler to detect the EV_FORCEOS flag and teardown the connection. I think it should be EVFILT_USER event, allowing to EV_SET(&kev, fd, EVFILT_USER, 0, 0, 0, udata); and the event should automatically sets the EV_ONESHOT flag internally. Igor Sysoev http://sysoev.ru/en/