From owner-svn-src-all@freebsd.org Wed Nov 9 17:05:31 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2622FC38B48; Wed, 9 Nov 2016 17:05:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0505EE16; Wed, 9 Nov 2016 17:05:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by mail.baldwin.cx (Postfix) with ESMTPSA id DD7F610A727; Wed, 9 Nov 2016 12:05:28 -0500 (EST) From: John Baldwin To: Hans Petter Selasky Cc: Oleksandr Tymoshenko , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r308424 - head/sys/arm/broadcom/bcm2835 Date: Wed, 09 Nov 2016 08:32:25 -0800 Message-ID: <2064206.nvhhXHc9vW@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.0-PRERELEASE; KDE/4.14.10; amd64; ; ) In-Reply-To: <5c170b6b-1189-4712-ffdd-653cc6b8c59e@selasky.org> References: <201611071738.uA7HceYu045944@repo.freebsd.org> <3214848.geWV8qu7rM@ralph.baldwin.cx> <5c170b6b-1189-4712-ffdd-653cc6b8c59e@selasky.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Wed, 09 Nov 2016 12:05:28 -0500 (EST) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2016 17:05:31 -0000 On Wednesday, November 09, 2016 05:10:09 PM Hans Petter Selasky wrote: > Hi, > > On 11/09/16 16:02, John Baldwin wrote: > > On the other hand, doing the wakeup outside of the lock > > avoids preempting during the wakeup only to immediately block on the lock and > > switch back to the thread that did the wakeup. > > This can be predicted and avoided by the turnstiles iff cv_signal() is > used under a lock. Else not. It isn't predicted and avoided by turnstiles. In particular, the cv_signal has no idea what lock is associated, so it can't try to do something "smart" and move the thread from the sleepq to the lockq. You will pay the double context switch. > Won't doing the wakeup outside the lock cause double preemtion? First at > mtx_unlock() and then inside cv_signal()/cv_broadcast(). No. The other thread can't be blocked on both the mutex and cv. If the thread is blocked on the mutex and you preempt to it, then it won't ever bother sleeping on the cv anyway (and the cv_signal will be a nop once the awakening thread resumes). -- John Baldwin