From owner-freebsd-arch Fri Sep 27 6: 0:15 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 5A49237B401; Fri, 27 Sep 2002 06:00:13 -0700 (PDT) Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.157.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7A04443E6E; Fri, 27 Sep 2002 06:00:12 -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 g8RD0BLn000526; Fri, 27 Sep 2002 14:00:11 +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 g8RD0BDa000525; Fri, 27 Sep 2002 14:00:11 +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 g8RCvmwf032794; Fri, 27 Sep 2002 13:57:48 +0100 (BST) (envelope-from mark@grimreaper.grondar.org) Message-Id: <200209271257.g8RCvmwf032794@grimreaper.grondar.org> To: John Baldwin Cc: arch@FreeBSD.org Subject: Re: [patch] module-with-thread exit routine. References: In-Reply-To: ; from John Baldwin "Thu, 26 Sep 2002 11:08:43 EDT." Date: Fri, 27 Sep 2002 13:57:48 +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 > > 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