From owner-freebsd-usb@FreeBSD.ORG Sat May 28 13:30:32 2005 Return-Path: X-Original-To: freebsd-usb@freebsd.org Delivered-To: freebsd-usb@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB3DC16A41C for ; Sat, 28 May 2005 13:30:32 +0000 (GMT) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe10.swipnet.se [212.247.155.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4781743D1D for ; Sat, 28 May 2005 13:30:31 +0000 (GMT) (envelope-from hselasky@c2i.net) X-T2-Posting-ID: Y1QAsIk9O44SO+J/q9KNyQ== Received: from mp-216-46-229.daxnet.no ([193.216.46.229] verified) by mailfe10.swip.net (CommuniGate Pro SMTP 4.3c5) with ESMTP id 170450821; Sat, 28 May 2005 15:30:29 +0200 From: Hans Petter Selasky To: Seb Date: Sat, 28 May 2005 15:31:10 +0200 User-Agent: KMail/1.7 References: <200505252120.22408.sebastien.b@swissinfo.org> <200505261925.38744.hselasky@c2i.net> <200505271331.05132.sebastien.b@swissinfo.org> In-Reply-To: <200505271331.05132.sebastien.b@swissinfo.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200505281531.14351.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org Subject: Re: usbd_bulk_transfer returns 1 (USBD_IN_PROGRESS) ?! X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: hselasky@c2i.net List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2005 13:30:32 -0000 On Friday 27 May 2005 13:31, Seb wrote: > Ok, I understood the problem. > But I didn't fix it with mutexes, I used semaphores instead. > I initialize a semaphore with a value equal to 1 and then, before the USB > transfers, I do : while(entered) { > mtx_unlock(&Giant); > sema_wait(&sc->usb_tx_sema); > mtx_lock(&Giant); } entered = 1; > And after the USB transfers : > sema_post(&sc->usb_tx_sema); entered = 0; > Is this OK ? I think it is better you use "sx_xlock", "sx_xunlock" and "sx_init". See "man sx". > Apparently it has solved the problem, the driver now sustains > heavy network load :) > I wouln't like to use asynchronous transfers, they make the code hard to > read and would require all users to recompile their kernels to install your > USB driver... You, can do asynchronous transfers with the existing USB driver too. But to do what you want to do, the code will be a little more complicated, because the existing USB-API wasn't designed to handle that. Just make a wrapper for "usbd_bulk_transfer()": my_bulk_transfer(sc, xfer): { if(started == 0) { m = dequeue packet; if(m == NULL) return; prepend m; started = 1; err = usbd_transfer(); if(err) { started = 0; } } } your_callback(xfer,...,error): { started = 0; if(error == 0) { my_bulk_transfer(sc, xfer); /* calling usbd_transfer() * from callback is allowed */ } } If you do things via callback you can remove "sc->tx_queues[]" and associated functions. I think you will get better performance using callbacks. And most importantly, you are no longer blocking the callers of those functions that send packets. --HPS