Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/nick-nhusb]: src/sys/dev/usb Convert from spl(9)/tsleep(9) to mutex(9)/c...
details: https://anonhg.NetBSD.org/src/rev/d265217af6a1
branches: nick-nhusb
changeset: 334503:d265217af6a1
user: skrll <skrll%NetBSD.org@localhost>
date: Sat Apr 30 08:45:13 2016 +0000
description:
Convert from spl(9)/tsleep(9) to mutex(9)/condvar(9)
diffstat:
sys/dev/usb/if_otus.c | 50 ++++++++++++++++++++++++------------------------
sys/dev/usb/if_otusvar.h | 4 ++-
2 files changed, 28 insertions(+), 26 deletions(-)
diffs (192 lines):
diff -r 12bb85b6ba6d -r d265217af6a1 sys/dev/usb/if_otus.c
--- a/sys/dev/usb/if_otus.c Fri Apr 22 15:44:08 2016 +0000
+++ b/sys/dev/usb/if_otus.c Sat Apr 30 08:45:13 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_otus.c,v 1.25.6.5 2015/10/06 21:32:15 skrll Exp $ */
+/* $NetBSD: if_otus.c,v 1.25.6.6 2016/04/30 08:45:13 skrll Exp $ */
/* $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $ */
/*-
@@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.25.6.5 2015/10/06 21:32:15 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.25.6.6 2016/04/30 08:45:13 skrll Exp $");
#include <sys/param.h>
#include <sys/sockio.h>
@@ -626,6 +626,8 @@
aprint_normal_dev(sc->sc_dev, "%s\n", devinfop);
usbd_devinfo_free(devinfop);
+ cv_init(&sc->sc_task_cv, "otustsk");
+ cv_init(&sc->sc_cmd_cv, "otuscmd");
mutex_init(&sc->sc_cmd_mtx, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sc->sc_task_mtx, MUTEX_DEFAULT, IPL_NET);
mutex_init(&sc->sc_tx_mtx, MUTEX_DEFAULT, IPL_NONE);
@@ -674,8 +676,10 @@
DPRINTFN(DBG_FN, sc, "\n");
+ mutex_spin_enter(&sc->sc_task_mtx);
while (sc->sc_cmdq.queued > 0)
- tsleep(&sc->sc_cmdq, 0, "sc_cmdq", 0);
+ cv_wait(&sc->sc_task_cv, &sc->sc_task_mtx);
+ mutex_spin_exit(&sc->sc_task_mtx);
}
Static int
@@ -716,6 +720,9 @@
mutex_destroy(&sc->sc_tx_mtx);
mutex_destroy(&sc->sc_task_mtx);
mutex_destroy(&sc->sc_cmd_mtx);
+ cv_destroy(&sc->sc_task_cv);
+ cv_destroy(&sc->sc_cmd_cv);
+
return 0;
}
@@ -1234,34 +1241,29 @@
struct otus_softc *sc;
struct otus_host_cmd_ring *ring;
struct otus_host_cmd *cmd;
- int s;
sc = arg;
DPRINTFN(DBG_FN, sc, "\n");
/* Process host commands. */
- s = splusb();
mutex_spin_enter(&sc->sc_task_mtx);
ring = &sc->sc_cmdq;
while (ring->next != ring->cur) {
cmd = &ring->cmd[ring->next];
mutex_spin_exit(&sc->sc_task_mtx);
- splx(s);
/* Callback. */
DPRINTFN(DBG_CMD, sc, "cb=%p queued=%d\n", cmd->cb,
ring->queued);
cmd->cb(sc, cmd->data);
- s = splusb();
mutex_spin_enter(&sc->sc_task_mtx);
ring->queued--;
ring->next = (ring->next + 1) % OTUS_HOST_CMD_RING_COUNT;
}
+ cv_signal(&sc->sc_task_cv);
mutex_spin_exit(&sc->sc_task_mtx);
- wakeup(ring);
- splx(s);
}
Static void
@@ -1270,12 +1272,10 @@
{
struct otus_host_cmd_ring *ring;
struct otus_host_cmd *cmd;
- int s;
+ bool sched = false;
DPRINTFN(DBG_FN, sc, "cb=%p\n", cb);
-
- s = splusb();
mutex_spin_enter(&sc->sc_task_mtx);
ring = &sc->sc_cmdq;
cmd = &ring->cmd[ring->cur];
@@ -1286,13 +1286,12 @@
/* If there is no pending command already, schedule a task. */
if (++ring->queued == 1) {
- mutex_spin_exit(&sc->sc_task_mtx);
- usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
+ sched = true;
}
- else
- mutex_spin_exit(&sc->sc_task_mtx);
- wakeup(ring);
- splx(s);
+ cv_signal(&sc->sc_task_cv);
+ mutex_spin_exit(&sc->sc_task_mtx);
+ if (sched)
+ usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
}
Static int
@@ -1393,7 +1392,7 @@
{
struct otus_tx_cmd *cmd;
struct ar_cmd_hdr *hdr;
- int s, xferlen, error;
+ int xferlen, error;
DPRINTFN(DBG_FN, sc, "\n");
@@ -1419,14 +1418,12 @@
DPRINTFN(DBG_CMD, sc, "sending command code=0x%02x len=%d token=%d\n",
code, ilen, hdr->token);
- s = splusb();
cmd->odata = odata;
cmd->done = 0;
usbd_setup_xfer(cmd->xfer, cmd, cmd->buf, xferlen,
USBD_FORCE_SHORT_XFER, OTUS_CMD_TIMEOUT, NULL);
error = usbd_sync_transfer(cmd->xfer);
if (error != 0) {
- splx(s);
mutex_exit(&sc->sc_cmd_mtx);
#if defined(DIAGNOSTIC) || defined(OTUS_DEBUG) /* XXX: kill some noise */
aprint_error_dev(sc->sc_dev,
@@ -1436,9 +1433,8 @@
return EIO;
}
if (!cmd->done)
- error = tsleep(cmd, PCATCH, "otuscmd", hz);
+ error = cv_timedwait_sig(&sc->sc_cmd_cv, &sc->sc_cmd_mtx, hz);
cmd->odata = NULL; /* In case answer is received too late. */
- splx(s);
mutex_exit(&sc->sc_cmd_mtx);
if (error != 0) {
aprint_error_dev(sc->sc_dev,
@@ -1639,14 +1635,18 @@
if ((hdr->code & 0xc0) != 0xc0) {
DPRINTFN(DBG_RX, sc, "received reply code=0x%02x len=%d token=%d\n",
hdr->code, hdr->len, hdr->token);
+ mutex_enter(&sc->sc_cmd_mtx);
cmd = &sc->sc_tx_cmd;
- if (__predict_false(hdr->token != cmd->token))
+ if (__predict_false(hdr->token != cmd->token)) {
+ mutex_exit(&sc->sc_cmd_mtx);
return;
+ }
/* Copy answer into caller's supplied buffer. */
if (cmd->odata != NULL)
memcpy(cmd->odata, &hdr[1], hdr->len);
cmd->done = 1;
- wakeup(cmd);
+ cv_signal(&sc->sc_cmd_cv);
+ mutex_exit(&sc->sc_cmd_mtx);
return;
}
diff -r 12bb85b6ba6d -r d265217af6a1 sys/dev/usb/if_otusvar.h
--- a/sys/dev/usb/if_otusvar.h Fri Apr 22 15:44:08 2016 +0000
+++ b/sys/dev/usb/if_otusvar.h Sat Apr 30 08:45:13 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_otusvar.h,v 1.7.12.4 2016/03/20 08:42:19 skrll Exp $ */
+/* $NetBSD: if_otusvar.h,v 1.7.12.5 2016/04/30 08:45:13 skrll Exp $ */
/* $OpenBSD: if_otusreg.h,v 1.6 2009/04/06 18:17:01 damien Exp $ */
/*-
@@ -199,6 +199,8 @@
unsigned int sc_write_idx;
uint32_t sc_led_state;
+ kcondvar_t sc_task_cv;
+ kcondvar_t sc_cmd_cv;
kmutex_t sc_cmd_mtx;
kmutex_t sc_task_mtx;
kmutex_t sc_write_mtx;
Home |
Main Index |
Thread Index |
Old Index