From owner-cvs-src Tue Mar 11 12:20:46 2003 Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8B70537B404 for ; Tue, 11 Mar 2003 12:20:42 -0800 (PST) Received: from mail.speakeasy.net (mail15.speakeasy.net [216.254.0.215]) by mx1.FreeBSD.org (Postfix) with ESMTP id E52F143FF9 for ; Tue, 11 Mar 2003 12:20:39 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: (qmail 10109 invoked from network); 11 Mar 2003 20:20:45 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail15.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 11 Mar 2003 20:20:45 -0000 Received: from laptop.baldwin.cx (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.6/8.12.6) with ESMTP id h2BKGqhT069590; Tue, 11 Mar 2003 15:16:52 -0500 (EST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200303112017.h2BKH0NB073797@repoman.freebsd.org> Date: Tue, 11 Mar 2003 15:20:55 -0500 (EST) From: John Baldwin To: John Baldwin Subject: RE: cvs commit: src/sys/kern subr_eventhandler.c src/sys/sys eve Cc: cvs-all@FreeBSD.org, cvs-src@FreeBSD.org, src-committers@FreeBSD.org Sender: owner-cvs-src@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 11-Mar-2003 John Baldwin wrote: > jhb 2003/03/11 12:17:00 PST > > FreeBSD src repository > > Modified files: > sys/kern subr_eventhandler.c > sys/sys eventhandler.h > Log: > Rework the eventhandler locking for hopefully the last time. The scheme > used popped into my head during my morning commute a few weeks ago, but > it is also very similar (though a bit simpler) to a patch that mini@ > developed a while ago. Basically, each eventhandler list has a mutex and > a run count. During an eventhandler invocation, the mutex is held while > we traverse the list but is dropped while we execute actual handlers. Also, > a runcount counter is incremented at the start of an invocation and > decremented at the end of an invocation. Adding to the list is not a big > deal since the reference of a thread currently executing the handlers > remains valid across an add operation. Whether or not new handlers are > executed by threads currently executing the handlers for a given list is > indeterminate however. The harder case is when a handler is removed from > the list. If the runcount is zero, the handler is simply removed from the > list directly. If the runcount is not zero, then another thread is > currently executing the handlers of this list, so the priority of this > handler is set to a magic value (currently -1) to mark it as dead. Dead > handlers are not executed during an invocation. If the runcount is zero > after it is decremented at the end of an invocation, then a new > eventhandler_prune_list() function is called to remove dead handlers from > the list. > > Additional minor notes: > - All the common parts of EVENTHANDLER_INVOKE() and > EVENTHANDLER_FAST_INVOKE() have been merged into a common > _EVENTHANDLER_INVOKE() macro to reduce duplication and ease maintenance. > - KTR logging for eventhandlers is now available via the KTR_EVH mask. > - The global eventhander_mutex is no longer recursive. > > Tested by: scottl (SMP i386) I also tested this extensively using a hacked up kernel module that lives in the smpng p4 tree under modules/evtest. Unfortunately it's not real pretty at the moment. Eventually I plan to generalize it and merge it and the crash module (another testing module for lock things). Even then, you can't script all the tests since the correct behavior for some of them is to panic. :) -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-src" in the body of the message