Date: Thu, 26 Sep 2002 10:43:30 +0100 From: Mark Murray <mark@grondar.za> To: arch@freebsd.org Subject: [patch] module-with-thread exit routine. Message-ID: <200209260943.g8Q9hURP072845@grimreaper.grondar.org>
next in thread | raw e-mail | index | archive | help
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <72685.1033033378.1@grimreaper.grondar.org>
Hi
If an unloadable module has a thread (like random.ko has), then
unloading the module is problematic because of the race between
the module termination and the unload.
The thread must "die" in a part of the code that will not be
unloaded.
The random device has its own code to do this, but I think this
is better put with the kthread stuff.
Attached is a patch to the kthread code. I've been running this
for at least three months.
Comments?
M
-- 
o       Mark Murray
\_
O.\_    Warning: this .sig is umop ap!sdn
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <72685.1033033378.2@grimreaper.grondar.org>
Content-Description: kthread.diff
Index: kern/kern_kthread.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_kthread.c,v
retrieving revision 1.24
diff -u -d -r1.24 kern_kthread.c
--- kern/kern_kthread.c	11 Sep 2002 08:13:53 -0000	1.24
+++ kern/kern_kthread.c	11 Sep 2002 11:14:02 -0000
@@ -133,6 +133,19 @@
 	PROC_UNLOCK(p);
 	sx_xunlock(&proctree_lock);
 	exit1(td, W_EXITCODE(ecode, 0));
+	/* NOTREACHED */
+}
+
+
+/* Helper routine to enable kthread_exit() to work while a module is
+ * being (or has been) unloaded.
+ */
+void
+kthread_set_wakeup_exit(void *control)
+{
+	wakeup(control);
+	kthread_exit(0);
+	/* NOTREACHED */
 }
 
 /*
Index: sys/kthread.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/kthread.h,v
retrieving revision 1.7
diff -u -d -r1.7 kthread.h
--- sys/kthread.h	19 Mar 2002 20:18:36 -0000	1.7
+++ sys/kthread.h	19 Jul 2002 20:14:32 -0000
@@ -47,6 +47,7 @@
 int     kthread_create(void (*)(void *), void *, struct proc **,
 	    int flags, const char *, ...) __printflike(5, 6);
 void    kthread_exit(int) __dead2;
+void	kthread_set_wakeup_exit(void *) __dead2;
 int	kthread_resume(struct proc *); /* XXXKSE */
 int	kthread_suspend(struct proc *, int); /* XXXKSE */
 void	kthread_suspend_check(struct proc *); /* XXXKSE */
------- =_aaaaaaaaaa0--
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?200209260943.g8Q9hURP072845>
