From owner-freebsd-embedded@FreeBSD.ORG Thu Dec 29 10:50:10 2011 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D6FFE1065678; Thu, 29 Dec 2011 10:50:10 +0000 (UTC) (envelope-from stb@lassitu.de) Received: from gilb.zs64.net (gilb.zs64.net [IPv6:2001:470:1f0b:105e::1ea]) by mx1.freebsd.org (Postfix) with ESMTP id 50FD58FC29; Thu, 29 Dec 2011 10:50:10 +0000 (UTC) Received: by gilb.zs64.net (Postfix, from stb@lassitu.de) id 93EE36D83F; Thu, 29 Dec 2011 10:50:09 +0000 (UTC) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=iso-8859-1 From: Stefan Bethke In-Reply-To: Date: Thu, 29 Dec 2011 11:50:09 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <9A1E9A46-BE00-4EBA-AC8A-2D61C3CCABE8@lassitu.de> References: <0F6CC18F-6973-42A2-AC03-F01BF59458AE@lassitu.de> <1100F70E-9DA9-4163-AC9A-423ECE5AA9A3@lassitu.de> <18CABB46-9B9A-41CB-8742-6723C5FF4D67@lassitu.de> <2CBD8651-E132-49DC-A082-37A8F5C626EA@bsdimp.com> <267FB3D6-830E-4A2F-8C1C-A96873EDCD31@lassitu.de> <12538AED-175C-4B1E-BF05-6FD05D14CE70@lassitu.de> <2135AD2B-76D4-4B3D-A009-8F3BEC836051@lassitu.de> <2BB71545-7DE9-493D-92FE-AD4CEDCBF2D1@lassitu.de> To: Adrian Chadd X-Mailer: Apple Mail (2.1251.1) Cc: "freebsd-embedded@freebsd.org" Subject: Re: Updated switch/glue patch? X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Dec 2011 10:50:11 -0000 Am 29.12.2011 um 11:18 schrieb Stefan Bethke: >> http://gitorious.org/~stb/freebsd/stb-adrianchadd-freebsd-work = (branch work/ath) >> http://www.lassitu.de/freebsd/etherswitch-adrian.patch (patch against = Adrians gitorious repo as of now) >> http://www.lassitu.de/freebsd/etherswitch.tbz (all files) >=20 > I've now gotten the panic again with the callout: > Sleeping on "rtl8366rbstart" with the following non-sleepable locks = held: > exclusive sleep mutex rtl8366rbcallout (rtl8366rbcallout) r =3D 0 = (0x80769114) locked @ = /home/stb/working/fe/stb-adrianchadd-freebsd-work/sys/kern/kern_mutex.c:14= 8 >=20 > callout_init_mtx() says >> The usable lock classes are currently limited to mutexes and rwlocks, = because callout handlers run in softclock swi, so they cannot sleep nor = acquire sleepable locks like sx or lockmgr. >=20 > The way I read that, any callout will be run in a way that does not = allow sleeping. I'm not sure how to handle this. Here's one way, replacing the callout with a thread: diff --git a/sys/dev/etherswitch/rtl8366rb.c = b/sys/dev/etherswitch/rtl8366rb.c index 599f5f0..2acb206 100644 --- a/sys/dev/etherswitch/rtl8366rb.c +++ b/sys/dev/etherswitch/rtl8366rb.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -60,13 +61,13 @@ =20 struct rtl8366rb_softc { struct mtx smi_mtx; /* serialize access to SMI/I2C = bus */ - struct mtx callout_mtx; /* serialize callout */ device_t dev; char *ifname[RTL8366RB_NUM_PHYS]; device_t miibus[RTL8366RB_NUM_PHYS]; struct ifnet *ifp[RTL8366RB_NUM_PHYS]; device_t etherswitch; - struct callout callout_tick; + struct thread *tickthread; + int ticking; }; =20 static etherswitch_info_t etherswitch_info =3D { @@ -171,7 +172,6 @@ rtl8366rb_attach(device_t dev) sc =3D device_get_softc(dev); sc->dev =3D dev; mtx_init(&sc->smi_mtx, "rtl8366rbsmi", NULL, MTX_DEF); - mtx_init(&sc->callout_mtx, "rtl8366rbcallout", NULL, MTX_DEF); =20 rtl8366rb_init(dev); smi_read(dev, RTL8366RB_CVCR, &rev); @@ -202,8 +202,9 @@ rtl8366rb_attach(device_t dev) if (err !=3D 0) return (err); =20 - callout_init_mtx(&sc->callout_tick, &sc->callout_mtx, 0); - rtl8366rb_tick(sc); + sc->ticking =3D 1; + kthread_add(rtl8366rb_tick, sc, NULL, &sc->tickthread, 0, 0, \ + "%s tick", device_get_nameunit(dev)); =20 return (err); } @@ -217,6 +218,11 @@ rtl8366rb_detach(device_t dev) sc =3D device_get_softc(dev); if (sc->etherswitch) device_delete_child(dev, sc->etherswitch); + if (sc->ticking) { + sc->ticking =3D 0; + wakeup_one(sc->tickthread); + tsleep(sc, 0, "tickexit", 0); + } for (i=3D0; i < RTL8366RB_NUM_PHYS; i++) { if (sc->miibus[i]) device_delete_child(dev, sc->miibus[i]); @@ -225,8 +231,6 @@ rtl8366rb_detach(device_t dev) free(sc->ifname[i], M_DEVBUF); } bus_generic_detach(dev); - callout_drain(&sc->callout_tick); - mtx_destroy(&sc->callout_mtx); mtx_destroy(&sc->smi_mtx); =20 return (0); @@ -295,8 +299,12 @@ rtl8366rb_tick(void *arg) { struct rtl8366rb_softc *sc =3D arg; =20 - rtl833rb_miipollstat(sc); - callout_reset(&sc->callout_tick, hz, rtl8366rb_tick, sc); + while (sc->ticking) { + rtl833rb_miipollstat(sc); + tsleep(sc->tickthread, 0, "tick", hz); + }; + wakeup_one(sc); + kthread_exit(); } =20 static int --=20 Stefan Bethke Fon +49 151 14070811