Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6658227ybi; Wed, 31 Jul 2019 18:54:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkV5WhA0XLjP+nbMLHSV1TrRgoef1Yus6K+IX8BDEcUXDWqnhsCCQKTutD9Ss16htJbB6X X-Received: by 2002:a17:902:1004:: with SMTP id b4mr125326158pla.325.1564624443377; Wed, 31 Jul 2019 18:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564624443; cv=none; d=google.com; s=arc-20160816; b=wSl+7zhzc0dHT56vN91CkqkQ1gcDgrOCewveAwxkdA+WbUp5W3VuHQ2zH8ENo12eda B/8u02anAQhBQFN80ehgw+3cYDryjuK/+/+sgf4ysKs+T0+MSCwHVEVO87ChqrnQRl8J xngCOszxj9FhUilbOatM3IOv/B8Hy/WH1HRC0NnhIuvHRsx2p62wj6rE5oUtluGEsWI2 ZgbjebyPTGTAMDtM+qO31/bR3E6LC5Z0gQ1Nwg2UbF9s9+KKY+5B5dD7SxI6p0KFAgL+ k3zgiZf9k/TrvJaozNInN2WrXU/4fGEKTU1vcnmET3yCVoj11XGILCkvOOvP48qi3jLa 2THg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=ktBWQ7Dg2JkWHb4Wr0QSz+YEpRPFJ5RhEadMppEErJo=; b=T0GM7LQHOpFAx5K7Vl+tnfmEjA8xnPreG5RaAN2y6pr8Yzul7oBCHq56DA2trMfThR GxN3tjTWfEdFj4/yP2KsYJYVkFK1Ri/izwmGTRpeu2XHB5DaGP9Lsz/rcr+k2RKxbJCG 11RgOlGoxI7BuXFW2mRf28m4VDFG5x6fgIqNRL7MMIUfxQ+y3988YwiIWsWV4TWZnnXI 9cwzaqwWe6VKn2yzRI9L0THorhg8KP/9r4vyrBVxSgpnLKU1yxhJRjv/aFb9T/PAzxy8 50MDUvqreUOjkSJOUz8w2QtO2Epp9POo/eh6EdC9xfWIzUZSpxpJt01lGn8DPH7CJcX/ OQ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@valvesoftware.com header.s=mc20150811 header.b=jrFKxKzi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 83si35478643pgc.207.2019.07.31.18.53.47; Wed, 31 Jul 2019 18:54:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@valvesoftware.com header.s=mc20150811 header.b=jrFKxKzi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729293AbfHABvG (ORCPT + 99 others); Wed, 31 Jul 2019 21:51:06 -0400 Received: from us-smtp-delivery-172.mimecast.com ([216.205.24.172]:42799 "EHLO us-smtp-delivery-172.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbfHABvG (ORCPT ); Wed, 31 Jul 2019 21:51:06 -0400 X-Greylist: delayed 384 seconds by postgrey-1.27 at vger.kernel.org; Wed, 31 Jul 2019 21:51:04 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valvesoftware.com; s=mc20150811; t=1564624264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ktBWQ7Dg2JkWHb4Wr0QSz+YEpRPFJ5RhEadMppEErJo=; b=jrFKxKziF85H+lYERHXD33SZb7nLufuK4+GCMS15hFO38tkMYQ2REP/E30lqfDTlh0JfhK D87N1PZE+tBvkytr4IWzhcVFTO3xZ+PbZQQ4ei2b24jbv3eDYtLhKmO7/kuRBod+SYujx2 C9op+zia+Pv6sG8xTXxNeY3v0Vhlv/U= Received: from smtp01.valvesoftware.com (smtp01.valvesoftware.com [208.64.203.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-217-1Hghwc2rOtKf844kNt_97g-1; Wed, 31 Jul 2019 21:44:38 -0400 Received: from [172.16.1.107] (helo=antispam.valve.org) by smtp01.valvesoftware.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ht0ME-0004X6-PO for linux-kernel@vger.kernel.org; Wed, 31 Jul 2019 18:58:18 -0700 Received: from antispam.valve.org (127.0.0.1) id h8920a0171s3 for ; Wed, 31 Jul 2019 18:44:37 -0700 (envelope-from ) Received: from mail1.valvemail.org ([172.16.144.22]) by antispam.valve.org ([172.16.1.107]) (SonicWALL 9.0.5.2081 ) with ESMTP id o201908010144370011552-5; Wed, 31 Jul 2019 18:44:37 -0700 Received: from [172.18.23.31] (172.18.23.31) by mail1.valvemail.org (172.16.144.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Wed, 31 Jul 2019 18:43:32 -0700 Subject: Re: [PATCH RFC 2/2] futex: Implement mechanism to wait on any of several futexes To: Zebediah Figura , Thomas Gleixner , Gabriel Krisman Bertazi CC: , , , , , Steven Noonan References: <20190730220602.28781-1-krisman@collabora.com> <20190730220602.28781-2-krisman@collabora.com> <31ad0ada-ecc7-60b3-e204-898460254be3@gmail.com> From: "Pierre-Loup A. Griffais" Message-ID: <3af1586a-f5b8-9728-d140-4fc4709ba49c@valvesoftware.com> Date: Wed, 31 Jul 2019 18:42:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-ClientProxiedBy: mail1.valvemail.org (172.16.144.22) To mail1.valvemail.org (172.16.144.22) X-EXCLAIMER-MD-CONFIG: fe5cb8ea-1338-4c54-81e0-ad323678e037 X-Mlf-CnxnMgmt-Allow: 172.16.144.22 X-Mlf-Version: 9.0.5.2081 X-Mlf-License: BSVKCAP__ X-Mlf-UniqueId: o201908010144370011552 X-MC-Unique: 1Hghwc2rOtKf844kNt_97g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/31/19 6:32 PM, Zebediah Figura wrote: > On 7/31/19 8:22 PM, Zebediah Figura wrote: >> On 7/31/19 7:45 PM, Thomas Gleixner wrote: >>> If I assume a maximum of 65 futexes which got mentioned in one of the >>> replies then this will allocate 7280 bytes alone for the futex_q=20 >>> array with >>> a stock debian config which has no debug options enabled which would=20 >>> bloat >>> the struct. Adding the futex_wait_block array into the same allocation >>> becomes larger than 8K which already exceeds thelimit of SLUB kmem >>> caches and forces the whole thing into the page allocator directly. >>> >>> This sucks. >>> >>> Also I'm confused about the 64 maximum resulting in 65 futexes=20 >>> comment in >>> one of the mails. >>> >>> Can you please explain what you are trying to do exatly on the user=20 >>> space >>> side? >> >> The extra futex comes from the fact that there are a couple of, as it >> were, out-of-band ways to wake up a thread on Windows. [Specifically, a >> thread can enter an "alertable" wait in which case it will be woken up >> by a request from another thread to execute an "asynchronous procedure >> call".] It's easiest for us to just add another futex to the list in >> that case. >=20 > To be clear, the 64/65 distinction is an implementation detail that's=20 > pretty much outside the scope of this discussion. I should have just=20 > said 65 directly. Sorry about that. >=20 >> >> I'd also point out, for whatever it's worth, that while 64 is a hard >> limit, real applications almost never go nearly that high. By far the >> most common number of primitives to select on is one. >> Performance-critical code never tends to wait on more than three. The >> most I've ever seen is twelve. >> >> If you'd like to see the user-side source, most of the relevant code is >> at [1], in particular the functions __fsync_wait_objects() [line 712] >> and do_single_wait [line 655]. Please feel free to ask for further >> clarification. >> >> [1] >> https://github.com/ValveSoftware/wine/blob/proton_4.11/dlls/ntdll/fsync.= c In addition, here's an example of how I think it might be useful to=20 expose it to apps at large in a way that's compatible with existing=20 pthread mutexes: https://github.com/Plagman/glibc/commit/3b01145fa25987f2f93e7eda7f3e7d0f2f7= 7b290 This patch hasn't received nearly as much testing as the Wine fsync code=20 path, but that functionality would provide more CPU-efficient ways for=20 thread pool code to sleep in our game engine. We also use eventfd today. For this, I think the expected upper bound for the per-op futex count=20 would be in the same order of magnitude as the logical CPU count on the=20 target machine, similar as the Wine use-case. Thanks, - Pierre-Loup >> >> >> >>> >>> Thanks, >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0tglx >>> >> >=20