From owner-freebsd-hackers Sun Jan 7 19: 7:52 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from rjlhome.sco.com (unknown [207.65.180.181]) by hub.freebsd.org (Postfix) with ESMTP id 0F7C037B400 for ; Sun, 7 Jan 2001 19:07:34 -0800 (PST) Received: by rjlhome.sco.com (8.9.3/SCO5) id VAA01996 for freebsd-hackers@FreeBSD.ORG; Sun, 7 Jan 2001 21:11:59 -0600 (CST) Date: Sun, 7 Jan 2001 21:11:59 -0600 From: Robert Lipe To: freebsd-hackers@FreeBSD.ORG Subject: kthread_exit & zombification Message-ID: <20010107211159.C1400@rjlhome.sco.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, Gang. In 4.1.1, I have a pretty simple need for a kernel thread or two, but I'm having problems with kthread_exit(). The problem is that the thread goes zombie after I kthread_exit in it, but it never gets reaped. Since I'm doing this during a MOD_UNLOAD phase, if I happen to do a `ps -ax' after the module has been unmapped, a panic results becuase it's trying to get the lwp name and wchan string from what is now unmapped memory. But that's a secondary problem; the primary one is that I am missing whatever it takes to get a ticket for the resulting kernel thread to go to Byte Heaven. After a couple of load/unload cycles, I see: $ ps -alx | grep mem 0 357 0 2 0 0 0 0 - ZL ?? 0:00.00 (udi_memd) 0 360 0 2 0 0 0 0 - ZL ?? 0:00.00 (udi_memd) 0 920 0 2 0 0 0 0 - ZL ?? 0:00.00 (udi_memd) 0 954 0 0 0 0 0 0 udi_os SL ?? 0:00.00 (udi_memd) The creation is pretty simple: if (kthread_create(my_daemon, NULL, &my_thread, "mydaemon")) { printf("kthread_create failed!\n"); } Once the interesting part is stripped away, the daemon itself is texbook: _udi_alloc_daemon(void *arg) { while (!kill_daemon_req) { /* do work */ } wakeup(&_udi_kill_daemon); kthread_exit(0); } And the code that does the teardown looks like: case MOD_UNLOAD: kill_daemon_req = TRUE; /* poke the daemon to awaken it's 'work' loop */ ... tsleep(&_udi_kill_daemon, PZERO, "udiallocdeath", 0); I can see the interlocks happening with the tsleep/wakeup, so I know we're not unloading prematurely. There aren't many users of the kthread facilities in the kernel and since they don't seem to be in modules, the teardown case might have been skipped. What am I missing? Thanx, RJL To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message