From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5935 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Multi-threaded performance progress Date: Wed, 27 Aug 2014 12:47:46 -0400 Message-ID: <20140827164746.GP12888@brightrain.aerifal.cx> References: <1409036654.4835.14.camel@eris.loria.fr> <1409070919.8054.47.camel@eris.loria.fr> <20140826175304.GD12888@brightrain.aerifal.cx> <1409077839.8054.54.camel@eris.loria.fr> <20140826190507.GE12888@brightrain.aerifal.cx> <1409081653.8054.60.camel@eris.loria.fr> <20140826202643.GI12888@brightrain.aerifal.cx> <1409087756.4476.2.camel@eris.loria.fr> <20140826213625.GJ12888@brightrain.aerifal.cx> <1409133190.4476.28.camel@eris.loria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1409158090 15657 80.91.229.3 (27 Aug 2014 16:48:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Aug 2014 16:48:10 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5942-gllmg-musl=m.gmane.org@lists.openwall.com Wed Aug 27 18:48:03 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XMgO7-0005Qp-Po for gllmg-musl@plane.gmane.org; Wed, 27 Aug 2014 18:47:59 +0200 Original-Received: (qmail 5293 invoked by uid 550); 27 Aug 2014 16:47:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5285 invoked from network); 27 Aug 2014 16:47:59 -0000 Content-Disposition: inline In-Reply-To: <1409133190.4476.28.camel@eris.loria.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:5935 Archived-At: On Wed, Aug 27, 2014 at 11:53:10AM +0200, Jens Gustedt wrote: > Am Dienstag, den 26.08.2014, 17:36 -0400 schrieb Rich Felker: > > Fixing it should be trivial via the design I mentioned earlier: don't > > use a waiter flag like this, but instead offset the initial value of > > ref by +1 and a_dec it just before waiting. As in other places, of > > course, a wake to an invalid address is possible either way; this is > > "fixable" if necessary via FUTEX_WAKE_OP (having the kernel do the > > atomic dec after acquiring the futex bin locks). > > generally it would be nice to have such a lock functionality that > takes care of the waiters inside the int itself, this could perhaps be > used in other places Yes. My idea was to have a "__wake_store" function or similar that wraps FUTEX_WAKE_OP and does a fallback to FUTEX_WAKE if the kernel lacks FUTEX_WAKE_OP (if there are older kernels that lack it; not sure). Note that this is less powerful that what I mentioned above, but you can know before the above a_dec if it will write zero since, if the value is 1, you're the last thread to modify it. I think most places where FUTEX_WAKE_OP would be used fit this pattern -- you know in advance that you're not racing with other atomic writers (or if you are, they're using a_cas and their cas would fail with the value you're writing and with the value you're overwriting). Rich