Move from workqueue to an explicit kthread for setting the multicast

filter, as suggested by cube@. Actual code review by cube@.
This way, a backport of the fix to netbsd-4 is possible.
This commit is contained in:
is 2008-01-16 12:33:54 +00:00
parent 76e0b9a57a
commit 257a88e757
2 changed files with 56 additions and 40 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_aue.c,v 1.107 2008/01/12 22:32:51 cube Exp $ */
/* $NetBSD: if_aue.c,v 1.108 2008/01/16 12:33:54 is Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.107 2008/01/12 22:32:51 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.108 2008/01/16 12:33:54 is Exp $");
#if defined(__NetBSD__)
#include "opt_inet.h"
@ -141,7 +141,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.107 2008/01/12 22:32:51 cube Exp $");
#include <dev/usb/usbdevs.h>
#if defined(__NetBSD__)
#include <sys/workqueue.h>
#include <sys/condvar.h>
#include <sys/kthread.h>
#endif
#include <dev/usb/if_auereg.h>
@ -234,7 +235,7 @@ Static const struct aue_type aue_devs[] = {
USB_DECLARE_DRIVER(aue);
#if defined(__NetBSD__)
Static void aue_multiwork(struct work *wkp, void *arg);
Static void aue_multithread(void *);
#endif
Static void aue_reset_pegasus_II(struct aue_softc *sc);
@ -780,17 +781,21 @@ USB_ATTACH(aue)
USB_ATTACH_ERROR_RETURN;
}
#if defined(__NetBSD__)
err = workqueue_create(&sc->wqp, USBDEVNAME(sc->aue_dev),
aue_multiwork, sc, 0, IPL_NET, 0);
sc->aue_closing = 0;
mutex_init(&sc->aue_mcmtx, MUTEX_DRIVER, IPL_NET);
cv_init(&sc->aue_domc, "auemc");
cv_init(&sc->aue_closemc, "auemccl");
err = kthread_create(PRI_NONE, 0, NULL,
aue_multithread, sc, &sc->aue_thread,
"%s-mc", USBDEVNAME(sc->aue_dev));
if (err) {
printf("%s: creating multicast configuration work queue\n",
printf("%s: creating multicast configuration thread\n",
USBDEVNAME(sc->aue_dev));
USB_ATTACH_ERROR_RETURN;
}
sc->wksem = 0;
mutex_init(&sc->wkmtx, MUTEX_DRIVER, IPL_NET);
cv_init(&sc->wkdone, "auewk");
#endif
sc->aue_flags = aue_lookup(uaa->vendor, uaa->product)->aue_flags;
@ -906,15 +911,6 @@ USB_DETACH(aue)
return (0);
}
mutex_enter(&sc->wkmtx);
while (sc->wksem != 0)
cv_wait(&sc->wkdone, &sc->wkmtx);
sc->wksem = 1;
mutex_exit(&sc->wkmtx);
/* It is now safe to terminate the worker */
workqueue_destroy(sc->wqp);
usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
/*
* Remove any pending tasks. They cannot be executing because they run
@ -923,6 +919,17 @@ USB_DETACH(aue)
usb_rem_task(sc->aue_udev, &sc->aue_tick_task);
usb_rem_task(sc->aue_udev, &sc->aue_stop_task);
sc->aue_closing = 1;
cv_signal(&sc->aue_domc);
mutex_enter(&sc->aue_mcmtx);
cv_wait(&sc->aue_closemc,&sc->aue_mcmtx);
mutex_exit(&sc->aue_mcmtx);
mutex_destroy(&sc->aue_mcmtx);
cv_destroy(&sc->aue_domc);
cv_destroy(&sc->aue_closemc);
s = splusb();
if (ifp->if_flags & IFF_RUNNING)
@ -959,8 +966,9 @@ USB_DETACH(aue)
USBDEV(sc->aue_dev));
mutex_destroy(&sc->aue_mii_lock);
#if 0
mutex_destroy(&sc->wkmtx);
#endif
return (0);
}
@ -1650,10 +1658,7 @@ aue_ioctl(struct ifnet *ifp, u_long command, void *data)
if ((error = ether_ioctl(ifp, command, data)) == ENETRESET) {
if (ifp->if_flags & IFF_RUNNING) {
#if defined(__NetBSD__)
mutex_enter(&sc->wkmtx);
if (sc->wksem == 0)
workqueue_enqueue(sc->wqp,&sc->wk, NULL);
mutex_exit(&sc->wkmtx);
cv_signal(&sc->aue_domc);
#else
aue_init(sc);
aue_setmulti(sc);
@ -1795,18 +1800,29 @@ aue_stop(struct aue_softc *sc)
#if defined(__NetBSD__)
Static void
aue_multiwork(struct work *wkp, void *arg) {
struct aue_softc *sc;
aue_multithread(void *arg) {
struct aue_softc *sc;
int s;
sc = (struct aue_softc *)arg;
sc = (struct aue_softc *)arg;
aue_init(sc);
/* XXX called by aue_init, but rc ifconfig hangs without it: */
aue_setmulti(sc);
while (1) {
mutex_enter(&sc->aue_mcmtx);
cv_wait(&sc->aue_domc,&sc->aue_mcmtx);
mutex_exit(&sc->aue_mcmtx);
mutex_enter(&sc->wkmtx);
sc->wksem = 0;
cv_signal(&sc->wkdone);
mutex_exit(&sc->wkmtx);
if (sc->aue_closing)
break;
s = splnet();
aue_init(sc);
/* XXX called by aue_init, but rc ifconfig hangs without it: */
aue_setmulti(sc);
splx(s);
}
cv_signal(&sc->aue_closemc);
kthread_exit(0);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_auereg.h,v 1.19 2008/01/12 22:32:51 cube Exp $ */
/* $NetBSD: if_auereg.h,v 1.20 2008/01/16 12:33:54 is Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
@ -237,11 +237,11 @@ struct aue_softc {
#if NRND > 0
rndsource_element_t rnd_source;
#endif
struct workqueue *wqp;
struct work wk;
u_int wksem;
kcondvar_t wkdone;
kmutex_t wkmtx;
struct lwp *aue_thread;
int aue_closing;
kcondvar_t aue_domc;
kcondvar_t aue_closemc;
kmutex_t aue_mcmtx;
#define GET_IFP(sc) (&(sc)->aue_ec.ec_if)
#define GET_MII(sc) (&(sc)->aue_mii)
#elif defined(__OpenBSD__)