Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb use a pool instead of a linked list to avoid syn...
details: https://anonhg.NetBSD.org/src/rev/e387fe4df6a1
branches: trunk
changeset: 784464:e387fe4df6a1
user: christos <christos%NetBSD.org@localhost>
date: Tue Jan 29 00:00:15 2013 +0000
description:
use a pool instead of a linked list to avoid synchronization problems.
diffstat:
sys/dev/usb/ehci.c | 28 ++++++++--------------------
sys/dev/usb/ehcivar.h | 11 +++++++++--
sys/dev/usb/ohci.c | 30 ++++++++----------------------
sys/dev/usb/ohcivar.h | 11 +++++++++--
sys/dev/usb/uhci.c | 35 ++++++++---------------------------
sys/dev/usb/uhcivar.h | 11 +++++++++--
6 files changed, 51 insertions(+), 75 deletions(-)
diffs (truncated from 350 to 300 lines):
diff -r 9daa80c2fb03 -r e387fe4df6a1 sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c Mon Jan 28 23:49:12 2013 +0000
+++ b/sys/dev/usb/ehci.c Tue Jan 29 00:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ehci.c,v 1.203 2013/01/22 12:40:42 jmcneill Exp $ */
+/* $NetBSD: ehci.c,v 1.204 2013/01/29 00:00:15 christos Exp $ */
/*
* Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.203 2013/01/22 12:40:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.204 2013/01/29 00:00:15 christos Exp $");
#include "ohci.h"
#include "uhci.h"
@@ -353,6 +353,9 @@
cv_init(&sc->sc_softwake_cv, "ehciab");
cv_init(&sc->sc_doorbell, "ehcidi");
+ sc->sc_xferpool = pool_cache_init(sizeof(struct ehci_xfer), 0, 0, 0,
+ "ehcixfer", NULL, IPL_USB, NULL, NULL, NULL);
+
sc->sc_doorbell_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
ehci_doorbell, sc);
sc->sc_pcd_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
@@ -1143,7 +1146,6 @@
int
ehci_detach(struct ehci_softc *sc, int flags)
{
- usbd_xfer_handle xfer;
int rv = 0;
if (sc->sc_child != NULL)
@@ -1172,10 +1174,7 @@
mutex_destroy(&sc->sc_intr_lock);
#endif
- while ((xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers)) != NULL) {
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
- kmem_free(xfer, sizeof(struct ehci_xfer));
- }
+ pool_cache_destroy(sc->sc_xferpool);
EOWRITE4(sc, EHCI_CONFIGFLAG, 0);
@@ -1369,18 +1368,7 @@
struct ehci_softc *sc = bus->hci_private;
usbd_xfer_handle xfer;
- xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
- if (xfer != NULL) {
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
-#ifdef DIAGNOSTIC
- if (xfer->busy_free != XFER_FREE) {
- printf("ehci_allocx: xfer=%p not free, 0x%08x\n", xfer,
- xfer->busy_free);
- }
-#endif
- } else {
- xfer = kmem_alloc(sizeof(struct ehci_xfer), KM_SLEEP);
- }
+ xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
if (xfer != NULL) {
memset(xfer, 0, sizeof(struct ehci_xfer));
#ifdef DIAGNOSTIC
@@ -1406,7 +1394,7 @@
printf("ehci_freex: !isdone\n");
}
#endif
- SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
+ pool_cache_put(sc->sc_xferpool, xfer);
}
Static void
diff -r 9daa80c2fb03 -r e387fe4df6a1 sys/dev/usb/ehcivar.h
--- a/sys/dev/usb/ehcivar.h Mon Jan 28 23:49:12 2013 +0000
+++ b/sys/dev/usb/ehcivar.h Tue Jan 29 00:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ehcivar.h,v 1.40 2012/06/10 06:15:53 mrg Exp $ */
+/* $NetBSD: ehcivar.h,v 1.41 2013/01/29 00:00:15 christos Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -29,6 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _EHCIVAR_H_
+#define _EHCIVAR_H_
+
+#include <sys/pool.h>
+
typedef struct ehci_soft_qtd {
ehci_qtd_t qtd;
struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
@@ -162,7 +167,7 @@
u_int32_t sc_eintrs;
ehci_soft_qh_t *sc_async_head;
- SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
+ pool_cache_t sc_xferpool; /* free xfer pool */
struct callout sc_tmo_intrlist;
@@ -195,3 +200,5 @@
bool ehci_suspend(device_t, const pmf_qual_t *);
bool ehci_resume(device_t, const pmf_qual_t *);
bool ehci_shutdown(device_t, int);
+
+#endif /* _EHCIVAR_H_ */
diff -r 9daa80c2fb03 -r e387fe4df6a1 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c Mon Jan 28 23:49:12 2013 +0000
+++ b/sys/dev/usb/ohci.c Tue Jan 29 00:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci.c,v 1.231 2013/01/22 12:40:43 jmcneill Exp $ */
+/* $NetBSD: ohci.c,v 1.232 2013/01/29 00:00:15 christos Exp $ */
/*
* Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.231 2013/01/22 12:40:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.232 2013/01/29 00:00:15 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -359,7 +359,6 @@
ohci_detach(struct ohci_softc *sc, int flags)
{
int rv = 0;
- usbd_xfer_handle xfer;
if (sc->sc_child != NULL)
rv = config_detach(sc->sc_child, flags);
@@ -381,10 +380,7 @@
if (sc->sc_hcca != NULL)
usb_freemem(&sc->sc_bus, &sc->sc_hccadma);
- while((xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers)) != NULL) {
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
- kmem_free(xfer, sizeof(struct ohci_xfer));
- }
+ pool_cache_destroy(sc->sc_xferpool);
return (rv);
}
@@ -672,7 +668,8 @@
for (i = 0; i < OHCI_HASH_SIZE; i++)
LIST_INIT(&sc->sc_hash_itds[i]);
- SIMPLEQ_INIT(&sc->sc_free_xfers);
+ sc->sc_xferpool = pool_cache_init(sizeof(struct ohci_xfer), 0, 0, 0,
+ "ohcixfer", NULL, IPL_USB, NULL, NULL, NULL);
rev = OREAD4(sc, OHCI_REVISION);
aprint_normal("OHCI version %d.%d%s\n",
@@ -951,20 +948,9 @@
struct ohci_softc *sc = bus->hci_private;
usbd_xfer_handle xfer;
- xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+ xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
if (xfer != NULL) {
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
-#ifdef DIAGNOSTIC
- if (xfer->busy_free != XFER_FREE) {
- printf("ohci_allocx: xfer=%p not free, 0x%08x\n", xfer,
- xfer->busy_free);
- }
-#endif
- } else {
- xfer = kmem_alloc(sizeof(struct ohci_xfer), KM_SLEEP);
- }
- if (xfer != NULL) {
- memset(xfer, 0, sizeof (struct ohci_xfer));
+ memset(xfer, 0, sizeof(struct ohci_xfer));
#ifdef DIAGNOSTIC
xfer->busy_free = XFER_BUSY;
#endif
@@ -984,7 +970,7 @@
}
xfer->busy_free = XFER_FREE;
#endif
- SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
+ pool_cache_put(sc->sc_xferpool, xfer);
}
Static void
diff -r 9daa80c2fb03 -r e387fe4df6a1 sys/dev/usb/ohcivar.h
--- a/sys/dev/usb/ohcivar.h Mon Jan 28 23:49:12 2013 +0000
+++ b/sys/dev/usb/ohcivar.h Tue Jan 29 00:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ohcivar.h,v 1.53 2012/06/10 06:15:53 mrg Exp $ */
+/* $NetBSD: ohcivar.h,v 1.54 2013/01/29 00:00:15 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,6 +30,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _OHCIVAR_H_
+#define _OHCIVAR_H_
+
+#include <sys/pool.h>
+
typedef struct ohci_soft_ed {
ohci_ed_t ed;
struct ohci_soft_ed *next;
@@ -119,7 +124,7 @@
ohci_soft_td_t *sc_freetds;
ohci_soft_itd_t *sc_freeitds;
- SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
+ pool_cache_t sc_xferpool; /* free xfer pool */
usbd_xfer_handle sc_intrxfer;
@@ -151,3 +156,5 @@
int ohci_activate(device_t, enum devact);
bool ohci_resume(device_t, const pmf_qual_t *);
bool ohci_suspend(device_t, const pmf_qual_t *);
+
+#endif /* _OHCIVAR_H_ */
diff -r 9daa80c2fb03 -r e387fe4df6a1 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c Mon Jan 28 23:49:12 2013 +0000
+++ b/sys/dev/usb/uhci.c Tue Jan 29 00:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uhci.c,v 1.252 2013/01/22 12:40:43 jmcneill Exp $ */
+/* $NetBSD: uhci.c,v 1.253 2013/01/29 00:00:15 christos Exp $ */
/*
* Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.252 2013/01/22 12:40:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.253 2013/01/29 00:00:15 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -521,7 +521,8 @@
LIST_INIT(&sc->sc_intrhead);
- SIMPLEQ_INIT(&sc->sc_free_xfers);
+ sc->sc_xferpool = pool_cache_init(sizeof(struct uhci_xfer), 0, 0, 0,
+ "uhcixfer", NULL, IPL_USB, NULL, NULL, NULL);
callout_init(&sc->sc_poll_handle, CALLOUT_MPSAFE);
@@ -569,7 +570,6 @@
int
uhci_detach(struct uhci_softc *sc, int flags)
{
- usbd_xfer_handle xfer;
int rv = 0;
if (sc->sc_child != NULL)
@@ -578,14 +578,7 @@
if (rv != 0)
return (rv);
- /* Free all xfers associated with this HC. */
- for (;;) {
- xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
- if (xfer == NULL)
- break;
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
- kmem_free(xfer, sizeof(struct uhci_xfer));
- }
+ pool_cache_destroy(sc->sc_xferpool);
callout_halt(&sc->sc_poll_handle, NULL);
callout_destroy(&sc->sc_poll_handle);
@@ -654,21 +647,9 @@
struct uhci_softc *sc = bus->hci_private;
usbd_xfer_handle xfer;
- xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+ xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
if (xfer != NULL) {
- SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
-#ifdef DIAGNOSTIC
- if (xfer->busy_free != XFER_FREE) {
- printf("uhci_allocx: xfer=%p not free, 0x%08x\n", xfer,
- xfer->busy_free);
- }
-#endif
- } else {
- xfer = kmem_alloc(sizeof(struct uhci_xfer), KM_SLEEP);
- }
- if (xfer != NULL) {
- memset(xfer, 0, sizeof (struct uhci_xfer));
Home |
Main Index |
Thread Index |
Old Index