From owner-freebsd-arch@FreeBSD.ORG Mon Oct 8 21:37:25 2007 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 02BF516A41A for ; Mon, 8 Oct 2007 21:37:25 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from webaccess-cl.virtdom.com (webaccess-cl.virtdom.com [216.240.101.25]) by mx1.freebsd.org (Postfix) with ESMTP id C5A7B13C448 for ; Mon, 8 Oct 2007 21:37:24 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from [192.168.1.103] (c-67-160-44-208.hsd1.wa.comcast.net [67.160.44.208]) (authenticated bits=0) by webaccess-cl.virtdom.com (8.13.6/8.13.6) with ESMTP id l98LbMJq006480 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO) for ; Mon, 8 Oct 2007 17:37:23 -0400 (EDT) (envelope-from jroberson@chesapeake.net) Date: Mon, 8 Oct 2007 14:40:00 -0700 (PDT) From: Jeff Roberson X-X-Sender: jroberson@10.0.0.1 To: arch@freebsd.org Message-ID: <20071008142928.Y912@10.0.0.1> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Subject: Abolishing sleeps in issignal() X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Oct 2007 21:37:25 -0000 During the work on thread lock I observed that there is a significant amount of locking involved in our signal paths right now. And these locks also show up contended in many workloads. Furthermore, requiring a DEF mutex complicates sleep queues by forcing them to drop the spinlock to check for signals and then check for races. The current issignal() code will actually msleep in the case of a stopevent() requested by the debugger. This is fine for signals that would normally abort the sleep anyway, but SIGSTOP actually leaves the thread on the sleep queue and tries to resume the sleep after the stop has cleared. So SIGSTOP combined with a stopevent() actually breaks because the stopevent() removes the thread from the sleep queue. I'm not certain what the failure mode is currently, but I'm certain that it's wrong. What I'd like to do is stop sleeping in issignal() all together. For regular restartable syscalls this would mean failing back out to ast() where we'd then handle the signals including SIGSTOP. After SIGCONT we'd then restart the syscall. For non-restartable syscalls we could have a special issignal variant that is called when msleep/cv_timedwait_sig return interrupted that would check for SIGSTOP/debugger events and sleep within a loop retrying the operation. This would preserve the behavior of debugging events and SIGSTOP not aborting non-restartable syscalls as they do now. Once we have moved the location of the sleeps it will be possible to check for signals using a spinlock without dropping the sleep queue lock in sleepq_catch_signals(). What I'd like from readers on arch@ is for you to consider if there are other cases than non-restartable syscalls that will break if msleep/sleepqs return EINTR from SIGSTOP and debug events. Also, is there an authoritative list of non-restartable syscalls anywhere? It's just those involving timevals right? nanosleep/poll/select/kqueue.. others? I intend to do this work for 8.0 and hopefully very early on so we have plenty of time to shake out bugs as this signal code tends to be very delicate. Thanks, Jeff