Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Mar 2005 15:58:20 +0000
From:      Sebastien B <sebastien.b@swissinfo.org>
To:        freebsd-usb@freebsd.org
Subject:   What's the right way to wait for an USB transfer to complete ?
Message-ID:  <200503261558.21943.sebastien.b@swissinfo.org>

next in thread | raw e-mail | index | archive | help
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 ?

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
fault code                = supervisor read, page not present
instruction pointer       = 0x8:0xc05fa002
stack pointer             = 0x10:0xd4ca5c20
frame pointer             = 0x10:0xd4ca5c48
code segment              = base 0x0, limit 0xfffff, type 0x1b
= DPL 0, pres 1, def32 1, gran 1
processor eflags  = resume, IOPL = 0
current process           = 9747 (swi8: dev_tx_bh+++*)

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.
Thanks,
Sebastien



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200503261558.21943.sebastien.b>