From owner-cvs-src@FreeBSD.ORG Thu Sep 23 23:32:28 2004 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD6B516A4CE; Thu, 23 Sep 2004 23:32:28 +0000 (GMT) Received: from green.homeunix.org (pcp04368961pcs.nrockv01.md.comcast.net [69.140.212.7]) by mx1.FreeBSD.org (Postfix) with ESMTP id 16E3C43D41; Thu, 23 Sep 2004 23:32:28 +0000 (GMT) (envelope-from green@green.homeunix.org) Received: from green.homeunix.org (green@localhost [127.0.0.1]) by green.homeunix.org (8.13.1/8.13.1) with ESMTP id i8NNWRBD019664; Thu, 23 Sep 2004 19:32:27 -0400 (EDT) (envelope-from green@green.homeunix.org) Received: (from green@localhost) by green.homeunix.org (8.13.1/8.13.1/Submit) id i8NNWQjW019663; Thu, 23 Sep 2004 19:32:26 -0400 (EDT) (envelope-from green) Date: Thu, 23 Sep 2004 19:32:25 -0400 From: Brian Fundakowski Feldman To: Nate Lawson Message-ID: <20040923233225.GF959@green.homeunix.org> References: <200409232112.i8NLCLgQ065917@repoman.freebsd.org> <200409231748.19685.jhb@FreeBSD.org> <20040923224739.GE959@green.homeunix.org> <41535A06.7090809@root.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41535A06.7090809@root.org> User-Agent: Mutt/1.5.6i cc: cvs-src@FreeBSD.org cc: src-committers@FreeBSD.org cc: cvs-all@FreeBSD.org cc: John Baldwin cc: Joerg Wunsch Subject: Re: cvs commit: src/sys/dev/fdc fdc.c fdcvar.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2004 23:32:29 -0000 On Thu, Sep 23, 2004 at 04:19:34PM -0700, Nate Lawson wrote: > Brian Fundakowski Feldman wrote: > > >On Thu, Sep 23, 2004 at 05:48:19PM -0400, John Baldwin wrote: > > > >>On Thursday 23 September 2004 05:12 pm, Joerg Wunsch wrote: > >> > >>>joerg 2004-09-23 21:12:21 UTC > >>> > >>> FreeBSD src repository > >>> > >>> Modified files: > >>> sys/dev/fdc fdc.c fdcvar.h > >>> Log: > >>> Implement terminating the worker thread when the driver is about to > >>> be deregistered. > >>> > >>> Not yet tested, since by now, GEOM doesn't want us to deregister. PHK > >>> wants to fix that RSN. > >> > >>Note that relying on a wakeup from your own code is not safe if you > >>expect fdc to be a module since you could wakeup the thread doing the > >>kldunload (and thus detach) and then be interrupted for an interrupt and > >>it could unmap the memory backing that function before you get a chance > >>to run again resulting in a panic. There is a special wakeup on the proc > >>pointer in exit1() for kthreads to handle this case. I should likely > >>move that into kthread_exit() however (which wouldn't be a functional > >>change as far as you are concerned). > > > > > >For example, in pff(4), ignoring the unrelated lines of code: > > > >static void > >pff_per_device_kthread(void *argp) > >{ > > mtx_lock(&sc->sc_lock); > > while (!sck->sck_exit) { > > if (!sck->sck_update && !sck->sck_reset && > > STAILQ_EMPTY(&sck->sck_traps)) > > cv_wait(&sck->sck_needed, &sc->sc_lock); > > } > > mtx_unlock(&sc->sc_lock); > > kthread_exit(0); > >} > > > >static void > >pff_kill_kthread(struct pff_softc *sc) > >{ > > if (sc->sc_flags & SC_KTHREAD) { > > mtx_lock(&sc->sc_lock); > > sc->sc_kthread.sck_exit = 1; > > cv_signal(&sc->sc_kthread.sck_needed); > > msleep(sc->sc_kthread.sck_proc, &sc->sc_lock, PPAUSE | PDROP, > > "pffktc", 0); > > } > >} > > > > Or simpler: > > foo_kill(): > error = kthread_suspend(p, kproc_shutdown_wait * hz); > if (error == EWOULDBLOCK) > printf("timed out\n"); > > foo_thread(): > for (;;) { > mtx_unlock(&bdlock); > kthread_suspend_check(bufdaemonproc); > ... > mtx_lock(&bdlock); > if (numdirtybuffers <= lodirtybuffers) > msleep(&bd_request, &bdlock, PVM, "psleep", hz); I want to be able to detach my pff(4) device, not just have it able to stop running when the system is shut down. If you get this wrong, you'll also crash your system when kldunloading. -- Brian Fundakowski Feldman \'[ FreeBSD ]''''''''''\ <> green@FreeBSD.org \ The Power to Serve! \ Opinions expressed are my own. \,,,,,,,,,,,,,,,,,,,,,,\