From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DA9313858D32 for ; Tue, 3 Jan 2023 01:13:18 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672708398; 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: in-reply-to:in-reply-to:references:references; bh=Zb3zZdkNNX4BghFSoqb/Lu1hi3u4mxA+YTGCqkWkk+I=; b=Umc6ZSMU4SQoo3+tq03rxyzTnOCYnL2Ac2zMYpcPkWDIzjwej1Curwuf1ZPZCvqJoRYKQ+ /SPffrETRNp/9akRpvQpOwDYCoPWcY+Wg8DpPEE+1usN7Crb2khagtQm0Nulb2jz+GvU/M ijfzktf7j1dcGmjwgZNEDy2c6Oak6Zo= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-618-EFKNAq9TPi6CIB5fAa9_UQ-1; Mon, 02 Jan 2023 20:13:17 -0500 X-MC-Unique: EFKNAq9TPi6CIB5fAa9_UQ-1 Received: by mail-pg1-f197.google.com with SMTP id r22-20020a63ce56000000b00478f1cfb0fbso13144842pgi.0 for ; Mon, 02 Jan 2023 17:13:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zb3zZdkNNX4BghFSoqb/Lu1hi3u4mxA+YTGCqkWkk+I=; b=bY/wwCeRHv58qAJJAgqTQscOMrMeHEWTDD1ZraIHotqEtzXeDkteta6K+8ZEb8Gp6D 9oWDv8GwSlp4DdpmBaCc8nanhc8JyK/K+92hc5JLxl2i2EN8/j+jXrBF95albqBIg8/B ALf5QptCLmuSa37sQIBxgTdpMrw/PFoPexsYPkA5HNn/C5f2LReTtbRAi0tWWFWr6XaY zQm4wZkXkaBi+7kRQQpr6TC/ZRsgqwVKLPIkarDIFVTcbjEO7FR9tKTBmrqB8lPnVyhz jUXY1k33MY6nwS390g9z84UYG+L92meV0S6FpXZcBW2y77ikkn53iAcBtGDzNDJm7Kju A2Tw== X-Gm-Message-State: AFqh2koieeZLEU7vEIY0kU23DvF0yQkbTHhlfvsq1GOMSG/Qqtytc3V/ pxJIntqIL9YS4auTu7DRW5wQpa/tcMxQVbfO71cPp4zXJwTJFjjGAF/OavWy0Q+EDKh3RIjh5cK YRy9OR/c5+WSmvRfONtuEP+8jh4vTKeM= X-Received: by 2002:a63:1b53:0:b0:479:52c0:2e7a with SMTP id b19-20020a631b53000000b0047952c02e7amr1771565pgm.51.1672708396250; Mon, 02 Jan 2023 17:13:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFqbekeN1MU2VmYJHJoAVbowODc1T+WuIz1SEEEFbtl7e8NpUrSN/NSVT6jIi6HgnKlrOrNbyD4cMYauCRpxo= X-Received: by 2002:a63:1b53:0:b0:479:52c0:2e7a with SMTP id b19-20020a631b53000000b0047952c02e7amr1771564pgm.51.1672708395785; Mon, 02 Jan 2023 17:13:15 -0800 (PST) MIME-Version: 1.0 References: <6640F26B-F267-40E0-9223-2F0F45462176@sandoe.co.uk> <05A9C1EF-7EC9-4276-BA11-8922A66B3D3A@sandoe.co.uk> <645C69D4-8147-4EAF-BCD9-42CA0C84E28B@sandoe.co.uk> <100B3504-8A57-42C0-B607-758374766869@sandoe.co.uk> In-Reply-To: <100B3504-8A57-42C0-B607-758374766869@sandoe.co.uk> From: Thomas Rodgers Date: Mon, 2 Jan 2023 17:13:04 -0800 Message-ID: Subject: Re: [RFA] choosing __platform_wait_t on targets without lock-free 64 atomics To: Iain Sandoe Cc: Jonathan Wakely , "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000be825605f151c540" X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000be825605f151c540 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jan 1, 2023 at 11:47 PM Iain Sandoe wrote: > > > > On 2 Jan 2023, at 00:53, Thomas Rodgers wrote: > > > > __platform_wait_t should be whatever the platform supports lock free > natively. The use of a 64 bit int there in the fall through was copied fr= om > Olivier's original implementation for libc++, which uses __ulock_wait/wake > on Darwin which takes a unit64_t, because I had intended to add support > Darwin, but haven't done so yet. > > In general, libc++ supports fewer versions of Darwin than GCC does (I > don=E2=80=99t know right now which versions/archs we support have the > __ulock_wait/wake). Of course, I would very much like to see an efficient > solution for Darwin - so please let me know/share patches with me when you > get to it - I can test on older supported versions. > I *think* it's supported for 10.12 onward, for anything older the mutex/condvar implementation would have to be used. > > However, the issue here is not really Darwin-specific - it will effect any > target that does not have either a futex or a 64b lock-free atomic. > > I agree. I was just relating the back-story of why it was 64b in the not-Linux case. > thanks > Iain > > > > > On Fri, Dec 30, 2022 at 2:51 AM Iain Sandoe wrote: > > > > > > > On 29 Dec 2022, at 17:02, Jonathan Wakely > wrote: > > > > > > > > > > > > On Thu, 29 Dec 2022, 16:22 Iain Sandoe, wrote: > > > > > > > > > > On 29 Dec 2022, at 15:44, Jonathan Wakely > wrote: > > > > > > > > > > > > > > > > On Thu, 29 Dec 2022, 15:30 Iain Sandoe, wrote: > > > > Hi Folks, > > > > > > > > > On 29 Dec 2022, at 12:09, Jonathan Wakely > wrote: > > > > > > > > > On Thu, 29 Dec 2022, 11:29 Iain Sandoe, wrote: > > > > > > > > >> The recent addition of the tz handling has pulled in a dependency > on > > > > >> > > > > >> This currently specifies __platform_wait_t as a 64bit quatity on > platforms without _GLIBCXX_HAVE_LINUX_FUTEX. > > > > >> > > > > >> PowerPC does not have a 64b atomic without library support - so > that this causes a bootstrap > > > > >> fail on powerpc-darwin (and I guess any other 32b powerpc > non-futex target). > > > > >> > > > > >> Rather than contrive to build and add libatomic (which is not at > present available at the point > > > > >> that libstdc++ is built), I wonder if there is any specific > reason that __platform_wait_t needs > > > > >> to be 64 bits on these platforms? (Especially since the futex > case uses an int.) > > > > >> > > > > > I think we do want the generic case's _M_wait atomic variable to > be lock free, otherwise we use two locks for every operation, the one in > libatomic and the waiter mutex. That's more important than it being any > specific width. > > > > > > > > Definitely, that=E2=80=99s probably a recipe for some subtle race c= ondition > .. nested locks etc. > > > > > > > > I didn't see any nested cases from a quick look, but it would still > be better to avoid two locks. > > > > > > > > > > > > >> Advice on the right way to fix this welcome =E2=80=94 as a work-= around to > allow bootstrap to complete > > > > >> I applied the patch below - but that seems unlikely to be the > right thing generically . > > > > >> > > > > > Rather than __lp64__ I think we should check the > ATOMIC_LONG_LOCK_FREE macro and use long if it's lock free and int > otherwise. But Tom needs to confirm that. That would be approximately the > same as your patch in practice. > > > > > > > > OK.. that makes sense here=E2=80=99s a proposed patch (pending subs= equent > input from Tom). > > > > > > > > I am using =E2=80=9Clock free always=E2=80=9D as the criterion, =E2= =80=9Csometimes=E2=80=9D does not > seem useful here. > > > > > > > > Agreed. > > > > > > > > > > > > Although we normally build libstdc++ with the just-built GCC... > > > > .. AFAIK the __SIZEOF_* are available from any version of GCC or > clang that would > > > > be capable of building the sources. > > > > > > > > Yep, but do we need the size checks at all? > > > > > > > > I was thinking we could just use 'unsigned long' or 'unsigned int' > directly, instead of a uintN_t typedef. Using the typedef just seems to > complicate things. > > > > > > That=E2=80=99s fine by me - I was just copying what was there :) > > > > > > In this patch I made it so that a target without a =E2=80=98suitable' > lock-free size would fail to > > > compile the source, which seems better than a link fail later =E2=80= =94 I > could make it more > > > specific (e.g. # fail clause) or we could test for smaller lock-free > entities=E2=80=A6 > > > > > > I think we can just eschew atomics altogether in that case, and just > use the mutex for all accesses. I can do that after the break when I'm ba= ck > online. > > > > Great, thanks! > > cheers > > Iain > > > > I=E2=80=99m using this locally in the meantime: > > > > # if ATOMIC_LONG_LOCK_FREE =3D=3D 2 > > using __platform_wait_t =3D long; > > # elif ATOMIC_INT_LOCK_FREE =3D=3D 2 > > using __platform_wait_t =3D int; > > # elif ATOMIC_SHORT_LOCK_FREE =3D=3D 2 > > using __platform_wait_t =3D short; > > # elif ATOMIC_CHAR_LOCK_FREE =3D=3D 2 > > using __platform_wait_t =3D char; > > # else > > # fail No suitable lock-free type found. > > # endif > > > > --000000000000be825605f151c540--