From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 27 06:51:46 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 4706C16A41F for ; Wed, 27 Jul 2005 06:51:46 +0000 (GMT) (envelope-from NKoch@demig.de) Received: from server.absolute-media.de (server.absolute-media.de [213.239.231.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id 988BA43D48 for ; Wed, 27 Jul 2005 06:51:45 +0000 (GMT) (envelope-from NKoch@demig.de) Received: from localhost (unknown [127.0.0.1]) by server.absolute-media.de (Postfix) with ESMTP id A4F148C500; Wed, 27 Jul 2005 08:51:44 +0200 (CEST) Received: from server.absolute-media.de ([127.0.0.1]) by localhost (server [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27648-09; Wed, 27 Jul 2005 08:51:39 +0200 (CEST) Received: from firewall.demig (p50839235.dip0.t-ipconnect.de [80.131.146.53]) by server.absolute-media.de (Postfix) with ESMTP id 002C88C4FE; Wed, 27 Jul 2005 08:51:38 +0200 (CEST) Received: from ws-ew-3 (ws-ew-3.w2kdemig [192.168.1.72]) by firewall.demig (8.13.4/8.13.1) with SMTP id j6R6mwFo068916; Wed, 27 Jul 2005 08:48:58 +0200 (CEST) (envelope-from NKoch@demig.de) From: "Norbert Koch" To: "Scott Long" Date: Wed, 27 Jul 2005 08:48:57 +0200 Message-ID: <001801c59277$432fd960$4801a8c0@ws-ew-3.W2KDEMIG> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 In-Reply-To: <42E65A9F.4010504@samsco.org> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2120.0 Importance: Normal X-Virus-Scanned: by amavisd-new X-Virus-Scanned: by amavisd-new at absolute-media.de Cc: "Freebsd-Hackers@Freebsd. Org" Subject: RE: await & asleep 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: Wed, 27 Jul 2005 06:51:46 -0000 > > The functions await() and asleep() in kern_synch.c > > are marked as EXPERIMENTAL/UNTESTED. > > Is this comment still valid? Does anyone have used > > those functions successfully? Should I better not > > use them in my device driver code for RELENG_4? > > How do I correctly cancel a request (as I should do > > according to the man page): "asleep (NULL, 0, NULL, 0)"? > > The await family was removed in 5.x and beyond, so trying to > use them in 4.x will make your driver very unportable. There > are better ways than await to handle delayed events. Ok, my [classical] situation is this: 1. an interrupt handler writes into a queue 2. a read function reading from the queue pseudo code using asleep()/await() (no error handling): read() { forever { while ! empty_queue() { uiomove(&uio, ...); if (uio->uio_resid == 0) { return 0; } } asleep(& read_queue, ...); if (empty_queue ()) { error = await (...); } else { asleep (NULL, ...); } } } If I want to do that with plain tsleep() I have to use spl??() to lock the empty_queue() call and not lose a wakeup() from the interrupt handler. But if I add error checks the code becomes very ugly compared to the solution above. I never wrote a driver under 5.X. As I understand I would use a mutex to access the queue and call msleep() to sleep with the mutex unlocked. (That seems to simulate pthread_cond_timedwait(), doesn't it?) pseudo code: read() { forever { while ! empty_queue() { uiomove(&uio, ...); if (uio->uio_resid == 0) { return 0; } } mtx_lock (&mutex); if (empty_queue ()) { error = msleep (&queue, &mutex, ...); }; mtx_unlock (&mutex); } } How would you suggest to do that under 4.X in an _elegant_ way w/o asleep/await? Norbert