From owner-freebsd-threads@FreeBSD.ORG Sat Feb 28 11:19:33 2015 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0C3AEAA3; Sat, 28 Feb 2015 11:19:33 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 739FB846; Sat, 28 Feb 2015 11:19:32 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t1SBJQ0U071852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 28 Feb 2015 13:19:26 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t1SBJQ0U071852 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t1SBJQQK071851; Sat, 28 Feb 2015 13:19:26 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 28 Feb 2015 13:19:26 +0200 From: Konstantin Belousov To: Mark Johnston Subject: Re: ZFS port and thread_exit() Message-ID: <20150228111926.GR2379@kib.kiev.ua> References: <20150228043144.GQ2379@kib.kiev.ua> <20150228073625.GA2627@raichu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150228073625.GA2627@raichu> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: threads@freebsd.org, fs@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Feb 2015 11:19:33 -0000 On Fri, Feb 27, 2015 at 11:36:26PM -0800, Mark Johnston wrote: > On Sat, Feb 28, 2015 at 06:31:44AM +0200, Konstantin Belousov wrote: > > While looking for some change to thread_exit(), I noted that ZFS > > on FreeBSD directly calls thread_exit(). It simply cannot work, > > thread_exit() is the internal function which requires the thread and > > process state prepared for it call. Among most obvious things, process > > spin lock must be held, but also several cleanups and accounting have to > > be done before the call. > > > > I believe the function just happens to have the same name as the Solaris > > counterpart, and for some reasons it is never called. If this is true, > > kthread_exit() should be used instead. > > I'm not very familiar with the ZFS code, but: > > The opensolaris compat proc.h #defines thread_exit to kthread_exit after > FreeBSD's proc.h is included, so calls to thread_exit() in ZFS code should > be replaced. Also, zfs.ko contains no references to thread_exit, but does > reference kthread_exit. > > > > > Also, I noted that the userspace port defines thread_exit() as > > thr_exit(NULL). Again, the direct invocation of the syscall does not > > look right. The libthr library must do some cleanups on the thread exit, > > which are not done if syscall is invoked by an application code. Also, > > the thread itself gets no destructor calls. > > This is done in zfs_context.h, which includes > cddl/contrib/opensolaris/head/thread.h, which #defines thr_exit(r) to > pthread_exit(r). There is no other thread.h in the src tree, and > libzpool.so references only pthread_exit. So it seems to me that the > compat layer is doing the right thing. Thank you for the explanation. I realized why kthread_exit() did not popped up in my reading. Still, it is very confusing, probably at the same scale as our/Linux PAGE_MASK.