From owner-freebsd-arch Thu Sep 26 2:45:11 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 19E6837B401 for ; Thu, 26 Sep 2002 02:45:09 -0700 (PDT) Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.157.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 32ECE43E77 for ; Thu, 26 Sep 2002 02:45:08 -0700 (PDT) (envelope-from mark@grimreaper.grondar.org) Received: from storm.FreeBSD.org.uk (uucp@localhost [127.0.0.1]) by storm.FreeBSD.org.uk (8.12.5/8.12.5) with ESMTP id g8Q9j7Ln084191 for ; Thu, 26 Sep 2002 10:45:07 +0100 (BST) (envelope-from mark@grimreaper.grondar.org) Received: (from uucp@localhost) by storm.FreeBSD.org.uk (8.12.5/8.12.5/Submit) with UUCP id g8Q9j7p6084190 for arch@freebsd.org; Thu, 26 Sep 2002 10:45:07 +0100 (BST) Received: from grimreaper.grondar.org (localhost [127.0.0.1]) by grimreaper.grondar.org (8.12.6/8.12.5) with ESMTP id g8Q9hURP072845 for ; Thu, 26 Sep 2002 10:43:30 +0100 (BST) (envelope-from mark@grimreaper.grondar.org) Message-Id: <200209260943.g8Q9hURP072845@grimreaper.grondar.org> To: arch@freebsd.org Subject: [patch] module-with-thread exit routine. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <72685.1033033378.0@grimreaper.grondar.org> Date: Thu, 26 Sep 2002 10:43:30 +0100 From: Mark Murray Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG ------- =_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