From owner-freebsd-hackers@FreeBSD.ORG Tue May 31 20:19:09 2005 Return-Path: X-Original-To: freebsd-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 A0D3816A41F for ; Tue, 31 May 2005 20:19:09 +0000 (GMT) (envelope-from kan@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7841843D4C; Tue, 31 May 2005 20:19:09 +0000 (GMT) (envelope-from kan@FreeBSD.org) Received: from freefall.freebsd.org (kan@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j4VKJ9xv077363; Tue, 31 May 2005 20:19:09 GMT (envelope-from kan@freefall.freebsd.org) Received: (from kan@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j4VKJ8LU077362; Tue, 31 May 2005 20:19:09 GMT (envelope-from kan) Date: Tue, 31 May 2005 20:19:08 +0000 From: Alexander Kabaev To: Maksim Yevmenkin Message-ID: <20050531201908.GA77068@freefall.freebsd.org> References: <000001c565f6$d46b7720$4801a8c0@ws-ew-3.W2KDEMIG> <429C93AE.8060509@savvis.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <429C93AE.8060509@savvis.net> User-Agent: Mutt/1.4.2.1i Cc: Norbert Koch , freebsd-hackers@freebsd.org Subject: Re: mutual exclusion in vkbd X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2005 20:19:09 -0000 On Tue, May 31, 2005 at 09:41:18AM -0700, Maksim Yevmenkin wrote: > Norbert, > > >I am currently trying to backport vkbd to FreeBSD 4. > > ok > > >Maksim Yevmenkin uses mtx_lock()/mtx_unlock() for > >protecting access to data structures under FreeBSD 5/6 > >between the device functions and the kernel thread. > > > >How should I best do this under FreeBSD 4? > > > >Would something like splhigh() work in that context? > >Or should I use lockmgr with LK_EXCLUSIVE/LK_RELEASE? > >Is there any (pseudo)process context inside a kernel task? > > spltty() is what you probably need to use. you could just adjust the > following defines like > > #define VKBD_LOCK_DECL int > #define VKBD_LOCK_INIT(s) /* noop */ > #define VKBD_LOCK_DESTROY(s) /* noop */ > #define VKBD_LOCK(s) (s)->ks_lock = spltty() > #define VKBD_UNLOCK(s) splx((s)->ks_lock) > #define VKBD_LOCK_ASSERT(s, w) > #define VKBD_SLEEP(s, f, d, t) \ > tsleep(&(s)->f, PCATCH | (PZERO + 1), d, t) > The code above will probably crash the kernel in many spectacular and unpredictable ways. You will need to save interrupt flags locally to each VKBD_LOCK caller or they will end up restoring each other's flags. -- Alexander Kabaev