From owner-freebsd-hackers@FreeBSD.ORG Tue May 31 20:59:48 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 18CD316A41C; Tue, 31 May 2005 20:59:48 +0000 (GMT) (envelope-from Maksim.Yevmenkin@savvis.net) Received: from mailgate1b.savvis.net (mailgate1b.savvis.net [216.91.182.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id AD17E43D1F; Tue, 31 May 2005 20:59:45 +0000 (GMT) (envelope-from Maksim.Yevmenkin@savvis.net) Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgate1b.savvis.net (Postfix) with ESMTP id 0E7833BE52; Tue, 31 May 2005 15:59:45 -0500 (CDT) Received: from mailgate1b.savvis.net ([127.0.0.1]) by localhost (mailgate1b.savvis.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31125-01-75; Tue, 31 May 2005 15:59:44 -0500 (CDT) Received: from out001.email.savvis.net (out001.apptix.savvis.net [216.91.32.44]) by mailgate1b.savvis.net (Postfix) with ESMTP id D69E03BE22; Tue, 31 May 2005 15:59:44 -0500 (CDT) Received: from s228130hz1ew171.apptix-01.savvis.net ([10.146.4.29]) by out001.email.savvis.net with Microsoft SMTPSVC(6.0.3790.211); Tue, 31 May 2005 15:59:12 -0500 Received: from [10.254.186.111] ([66.35.239.94]) by s228130hz1ew171.apptix-01.savvis.net with Microsoft SMTPSVC(6.0.3790.211); Tue, 31 May 2005 15:59:00 -0500 Message-ID: <429CD013.7070809@savvis.net> Date: Tue, 31 May 2005 13:58:59 -0700 From: Maksim Yevmenkin User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Alexander Kabaev References: <000001c565f6$d46b7720$4801a8c0@ws-ew-3.W2KDEMIG> <429C93AE.8060509@savvis.net> <20050531201908.GA77068@freefall.freebsd.org> In-Reply-To: <20050531201908.GA77068@freefall.freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 31 May 2005 20:59:00.0686 (UTC) FILETIME=[91DAEEE0:01C56623] X-Virus-Scanned: amavisd-new at savvis.net 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:59:48 -0000 Alexander Kabaev wrote: > 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. yes, you are correct. my bad :( thanks for catching this max