From owner-freebsd-smp Thu Oct 5 14:31:27 2000 Delivered-To: freebsd-smp@freebsd.org Received: from pike.osd.bsdi.com (pike.osd.bsdi.com [204.216.28.222]) by hub.freebsd.org (Postfix) with ESMTP id E2E0737B671; Thu, 5 Oct 2000 14:31:10 -0700 (PDT) Received: from laptop.baldwin.cx (john@dhcp248.osd.bsdi.com [204.216.28.248]) by pike.osd.bsdi.com (8.11.0/8.9.3) with ESMTP id e95LUti15503; Thu, 5 Oct 2000 14:30:55 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Thu, 05 Oct 2000 14:31:07 -0700 (PDT) From: John Baldwin To: Boris Popov Subject: RE: Problems with kthread_exit() and SMPng Cc: freebsd-smp@FreeBSD.org, freebsd-current@FreeBSD.org Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On 05-Oct-00 Boris Popov wrote: > Hello, > > Currently I'm trying to make KLD which uses kernel threads > unloadable under recent -current. The prototype of functions looks like > this: > > void > my_thread(void*arg) > { > while(wearewanted) { > do_something(); > tsleep(); > } > exited = 1; > kthread_exit(0); > } You need to have Giant before you call kthread_exit(). > my_unload() function called from the module unload event which > issued from the kldunload() syscall. > > Unfortunately, kernel panics in the mtx_exit_hard() function. > After some examination I've found that two fields in the Giant mutex > structure set to unexpected values: Ah, I need to add a KASSERT() to the start of mtx_exit_hard() to verify that we own the mutex we are releasing. > ---- > empty mtx_blocked for mutex Giant > mtx_contested not in any list for mutex Giant > ---- > > These messages printed by added diagnostics code. With this patch > (see attachment) it is possible to load and unload KLD without any > problems on UP machine except that the above messages printed. However, > I'm don't know if they are correct. (btw, 4.1 doesn't have this problem). It is a bogus patch though. If you release a contested mutex, it should always have someone who is waiting to grab it. > Any ideas why this happened and how to fix it ? > -- > Boris Popov > http://www.butya.kz/~bp/ -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message