From owner-freebsd-current@FreeBSD.ORG Tue Dec 9 20:33:42 2008 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5C5AC1065672 for ; Tue, 9 Dec 2008 20:33:42 +0000 (UTC) (envelope-from scottl@samsco.org) Received: from pooker.samsco.org (pooker.samsco.org [168.103.85.57]) by mx1.freebsd.org (Postfix) with ESMTP id E8E398FC24 for ; Tue, 9 Dec 2008 20:33:41 +0000 (UTC) (envelope-from scottl@samsco.org) Received: from phobos.local ([192.168.254.200]) (authenticated bits=0) by pooker.samsco.org (8.14.2/8.14.2) with ESMTP id mB9KXbZl020578; Tue, 9 Dec 2008 13:33:38 -0700 (MST) (envelope-from scottl@samsco.org) Message-ID: <493ED621.5010006@samsco.org> Date: Tue, 09 Dec 2008 13:33:37 -0700 From: Scott Long User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 MIME-Version: 1.0 To: Marcel Moolenaar References: <200812081621.mB8GLMxB041498@lava.sentex.ca> <200812081906.mB8J6oha042222@lava.sentex.ca> <200812082049.mB8KnHSN042710@lava.sentex.ca> <84A7F176-5A74-48AC-859A-C0D4C7CBCB48@mac.com> <7.1.0.9.0.20081208173515.13f62e88@sentex.net> <200812091457.mB9EvLSD047534@lava.sentex.ca> <493EA759.4000504@samsco.org> <0E8F5AD4-A139-413E-A760-A1BEDDF44BAA@mac.com> In-Reply-To: <0E8F5AD4-A139-413E-A760-A1BEDDF44BAA@mac.com> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=3.8 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.1.8 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on pooker.samsco.org Cc: freebsd-current@freebsd.org, Mike Tancsa Subject: Re: uart vs sio differences ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Dec 2008 20:33:42 -0000 Marcel Moolenaar wrote: > > On Dec 9, 2008, at 9:14 AM, Scott Long wrote: > >> That aside, I think what needs to happen is for the driver to use the >> interrupt handler to pull the bytes out of the hardware and into an >> internal lockless ring buffer, then schedule the swi to process the ring >> buffer. > > The uart(4) driver is exactly doing what you describe. > Yup, my mistake. However, I think that the semaphore spinwait in uart_sched_softih() is the source of the problems here. Imagine a a timeline scenario like this (in 8-CURRENT): CPU0 CPU1 irq4 uart_intr() UART_RECEIVE() uart_sched_softih() check ttypend swi_sched() uart_swi uart_tty_intr() clear ttypend tty_lock() irq4 uart_intr() UART_RECEIVE() uart_sched_softih() check ttypend swi_sched() irq4 uart_intr() UART_RECEIVE() uart_sched_softif() check ttypend With FreeBSD 6 and 7, it's even worse because Giant can be contended on before ttypend is cleared. But in either case, what you've effectively done here is created a home-rolled spinlock that comes after a sleep lock, so the time-critical interrupt handler is now slaved to the slow swi handler, completely defeating the benefits of having a fast handler (and also defeating WITNESS checks against this kind of problem). You really don't need the home-rolled semaphore. You already atomically read and write the variable, so you can just have uart_tty_intr() continue to loop around to check if it changes. Or since you already have a nice lockless ring buffer, you could just extend it also store each pending flag update. Scott