What's the right way to wait for an USB transfer to complete ?

Bernd Walter ticso at cicely12.cicely.de
Sat Mar 26 10:14:20 PST 2005


On Sat, Mar 26, 2005 at 03:58:20PM +0000, Sebastien B wrote:
> Hello,
> I'm trying to wait for an USB device to send me data over a bulk pipe. So I 
> set up the pipe and send an xfer to it with a callback. The callback function 
> then triggers a software interrupt handler which locks a mutex (required for 
> cv_broadcast()), calls cv_broadcast() to unblock threads waiting for the data 
> transfer and then unlocks the mutex.
> Is it the proper way to do, or is there a simpler solution ?

This is OK, but often just calling usbd_bulk_transfer for sync
transfers if enough.

> Locking the mutex in the software interrupt handler causes a kernel panic in 
> propagate_priority (it seems to occur only when the mutex is already held by 
> another thread, therefore mtx_lock() blocks) :
> 
> Fatal trap 12: page fault while in kernel mode
> fault virtual address     = 0x24

Likely you are using a NULL pointer as mutex.

> Other device drivers use wakeup() instead of cv_broadcast() (therefore there 
> is no need for software interrupt handlers, since wakeup() won't block) and 
> rely on the spl() function family to avoid race conditions. However, 
> according to the manual page, spl() is obsolete.

They rely on GIANT - most of USB is under GIANT right now.
spl calls are nop under 5.x and 6.x, but are still in the code to
reduce diffs with 4.x and other BSDs.
If you want your driver GIANT free that's fine, but don't forget
that calling USB layer requires you to acquire GIANT first.

-- 
B.Walter                   BWCT                http://www.bwct.de
bernd at bwct.de                                  info at bwct.de



More information about the freebsd-usb mailing list