From owner-cvs-src@FreeBSD.ORG Tue Sep 28 18:39:05 2004 Return-Path: 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 06ACB16A4CE; Tue, 28 Sep 2004 18:39:05 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED80D43D2F; Tue, 28 Sep 2004 18:39:04 +0000 (GMT) (envelope-from wpaul@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i8SId4V5003670; Tue, 28 Sep 2004 18:39:04 GMT (envelope-from wpaul@repoman.freebsd.org) Received: (from wpaul@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i8SId48U003669; Tue, 28 Sep 2004 18:39:04 GMT (envelope-from wpaul) Message-Id: <200409281839.i8SId48U003669@repoman.freebsd.org> From: Bill Paul Date: Tue, 28 Sep 2004 18:39:04 +0000 (UTC) To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Subject: cvs commit: src/sys/dev/usb ugen.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2004 18:39:05 -0000 wpaul 2004-09-28 18:39:04 UTC FreeBSD src repository Modified files: sys/dev/usb ugen.c Log: Arrgh. Recently I tried using ugen(4) in an application that uses select(2), and discovered to my horror that ugen(4)'s bulk in/out support is horribly lobotomized. Bulk transfers are done using the synchronous API instead of the asynchronous one. This causes the following broken behavior to occur: - You open the bulk in/out ugen device and get a descriptor - You create some other descriptor (socket, other device, etc...) - You select on both the descriptors waiting until either one has data ready to read - Because of ugen's brokenness, you block in usb_bulk_transfer() inside ugen_do_read() instead of blocking in select() - The non-USB descriptor becomes ready for reading, but you remain blocked on select() - The USB descriptor becomes ready for reading - Only now are you woken up so that you can ready data from either descriptor. The result is select() can only wake up when there's USB data pending. If any other descriptor becomes ready, you lose: until the USB descriptor becomes ready, you stay asleep. The correct approach is to use async bulk transfers, so I changed the read code to use the async bulk transfer API. I left the write side alone for now since it's less of an issue. Note that the uscanner driver has the same brokenness in it. Revision Changes Path 1.91 +122 -26 src/sys/dev/usb/ugen.c