Date: Fri, 27 Sep 2002 13:57:48 +0100 From: Mark Murray <mark@grondar.za> To: John Baldwin <jhb@FreeBSD.org> Cc: arch@FreeBSD.org Subject: Re: [patch] module-with-thread exit routine. Message-ID: <200209271257.g8RCvmwf032794@grimreaper.grondar.org> In-Reply-To: <XFMail.20020926110843.jhb@FreeBSD.org> ; from John Baldwin <jhb@FreeBSD.org> "Thu, 26 Sep 2002 11:08:43 EDT." References: <XFMail.20020926110843.jhb@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> > Attached is a patch to the kthread code. I've been running this
> > for at least three months.
> >
> > Comments?
>
> You don't need it. Look at the crash module I have. It has a thread
> and I committed an extra wakeup() inside of exit1() for kthread's a
> while ago to handle just this case. Here's an excerpt from the crash
> module code:
This looks good. But I have some questions:
> In the kthread's main loop (it usually gets events via a sysctl from
> userland):
>
> static void
> crash_thread(void *arg)
> {
> int ev;
>
> while (1) {
> mtx_lock(&event_mtx);
> while ((ev = event) == 0)
> cv_wait(&event_cv, &event_mtx);
> event = 0;
> mtx_unlock(&event_mtx);
What is the cv_wait for? For the random_kthread, can I just ignore it?
> ...
> switch (ev) {
> case -1:
> mtx_lock(&Giant);
> kthread_exit(0);
> break;
> ...
> }
This looks like I can just call kthread_exit() directly with no shenanigans.
Am I on the right track?
> Here's the unload() function that the module calls for MOD_UNLOAD:
>
> static int
> unload(void *arg)
> {
>
> mtx_lock(&event_mtx);
> event = -1;
> cv_signal(&event_cv);
> msleep(kthread, &event_mtx, PWAIT, "crshun", 0);
> mtx_unlock(&event_mtx);
> mtx_destroy(&event_mtx);
> cv_destroy(&event_cv);
I'm not sure of the event_cv relevance. Can I not just set the event (or
equivalent) variable and wait for event_mtx to become available?
> revision 1.129
> date: 2001/06/27 06:15:44; author: jhb; state: Exp; lines: +13 -16
> ...
> - When a kthread exits, do a wakeup() on its proc pointers. This can be
> used by kernel modules that have kthreads and want to ensure they have
> safely exited before completely the MOD_UNLOAD event.
This looks like its useful to me! :-)
M
--
o Mark Murray
\_
O.\_ Warning: this .sig is umop ap!sdn
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209271257.g8RCvmwf032794>
