From owner-freebsd-threads@FreeBSD.ORG Fri Oct 17 16:52:24 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7EA595CF; Fri, 17 Oct 2014 16:52:24 +0000 (UTC) Received: from bigwig.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 5972FFE0; Fri, 17 Oct 2014 16:52:24 +0000 (UTC) Received: from ralph.baldwin.cx (pool-173-70-85-31.nwrknj.fios.verizon.net [173.70.85.31]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id DB028B945; Fri, 17 Oct 2014 12:52:22 -0400 (EDT) From: John Baldwin To: freebsd-threads@freebsd.org Subject: Re: sem_post() performance Date: Fri, 17 Oct 2014 12:48:54 -0400 Message-ID: <7085436.G0Uv0KIisk@ralph.baldwin.cx> User-Agent: KMail/4.12.5 (FreeBSD/10.1-BETA2; KDE/4.12.5; amd64; ; ) In-Reply-To: <201410141731.42666.jhb@freebsd.org> References: <20140921213742.GA46868@stack.nl> <20141014203638.GA23965@stack.nl> <201410141731.42666.jhb@freebsd.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.2.7 (bigwig.baldwin.cx); Fri, 17 Oct 2014 12:52:22 -0400 (EDT) Cc: adrian@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: Fri, 17 Oct 2014 16:52:24 -0000 On Tuesday, October 14, 2014 05:31:42 PM John Baldwin wrote: > On Tuesday, October 14, 2014 4:36:38 pm Jilles Tjoelker wrote: > > On Mon, Oct 13, 2014 at 05:35:09PM -0400, John Baldwin wrote: > > > On Sunday, September 21, 2014 11:37:42 PM Jilles Tjoelker wrote: > > > > It has been reported that POSIX semaphores are slow, in contexts such > > > > as > > > > Python. Note that POSIX semaphores are the only synchronization > > > > objects > > > > that support use by different processes in shared memory; this does > > > > not > > > > work for mutexes and condition variables because they are pointers to > > > > the actual data structure. > > > > > > > > In fact, sem_post() unconditionally performs an umtx system call. > > > > > > > > To avoid both lost wakeups and possible writes to a destroyed > > > > semaphore, > > > > an uncontested sem_post() must check the _has_waiters flag atomically > > > > with incrementing _count. > > > > > > > > The proper way to do this would be to take one bit from _count and use > > > > it for the _has_waiters flag; the definition of SEM_VALUE_MAX permits > > > > this. However, this would require a new set of umtx semaphore > > > > operations > > > > and will break ABI of process-shared semaphores (things may break if > > > > an > > > > old and a new libc access the same semaphore over shared memory). > > > > > > Have you thought more about pursuing this option? I think there was a > > > general consensus from earlier in the thread to just break the ABI (at > > > least adjust SEM_MAGIC to give some protection) and fix it. > > > > I think this is a good direction but I haven't gotten around to it yet. > > Ok, I might take a stab at it. I have an implementation of this at https://reviews.freebsd.org/D961 -- John Baldwin