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.129.124]) by sourceware.org (Postfix) with ESMTPS id 1209D3858D32 for ; Mon, 2 Jan 2023 00:54:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672620851; 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=OITllz5aNySiN4O3oaO0mx7ZOZmYay+CgoMWZihAKug=; b=HUF7kEVhVpcz/I2NaqrE85JmrtFS+WMOGqC5dBTG09zaU8eK7ORSHiIwzqGzYqI5T/YY7D k8yfC65aOdTArlX0Gzp8zpJWcZvroKqRMhhtc9f6Z2F3pGBDuMWqd1suCaLAIsHpQ8cazd rl2Te5JIvjs9jzmdf11oNH0Lepqyv9Y= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-487-zBgcJkcDOs6SJxyLsr8ymQ-1; Sun, 01 Jan 2023 19:54:04 -0500 X-MC-Unique: zBgcJkcDOs6SJxyLsr8ymQ-1 Received: by mail-pl1-f200.google.com with SMTP id h2-20020a170902f54200b0018e56572a4eso19154638plf.9 for ; Sun, 01 Jan 2023 16:54:03 -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=OITllz5aNySiN4O3oaO0mx7ZOZmYay+CgoMWZihAKug=; b=vV4+5iYUXsFYSUxXtZYwKvcKZMwOIgWkP9DGr5g2O4y8AWoRTXOZNnkAXvmxVGS+P1 925zEhGijw9jAVphYupv03gOeBLAODSwsQP8o+N2ri50KXbzad0WSHbldKBb9kJIf84t gLl1ViPDe9oGwiMmzw+fvOE2+IQjssPwukUN53MB4aClAipP2u+WvbHiAXH3Nd3EpA9U wnOlLQv0ge7DMEdjsHfCFcVqJeDpN+1Avif8Tn8UawounicyY3sUaLRMinF2aeGEJyvA tKLY0DtTalrC9cn3Azux4hIUcRTbv+7Mg2L6wfGF2fdx21qnkuPG9Ww0H5n8LMH9i17x e/Hg== X-Gm-Message-State: AFqh2kp71rBFJb4UcuDLcfk4WRAh5jafPa+S6gXp3XiaCxcZ8O8fXFdt RMzaM6MeDP55hv13TCkQqRCjVViiOW8sXSJrL8knw5EE82A+HqN6cP0Y182wmSg1BYnz8v27XXb pO73kA7EUH7JLis82WraUcxWITzgBYUw= X-Received: by 2002:aa7:924d:0:b0:577:62a8:f7a1 with SMTP id 13-20020aa7924d000000b0057762a8f7a1mr2297999pfp.2.1672620843040; Sun, 01 Jan 2023 16:54:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXsL+54D/wdw1Glb+0JB67OtrA4YUaiKUn8gW0KmlKEY22916bSFq9AOEYcYYsmU0SOHC0BvyvWreqGOHaqFl/s= X-Received: by 2002:aa7:924d:0:b0:577:62a8:f7a1 with SMTP id 13-20020aa7924d000000b0057762a8f7a1mr2297996pfp.2.1672620842744; Sun, 01 Jan 2023 16:54:02 -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> In-Reply-To: <645C69D4-8147-4EAF-BCD9-42CA0C84E28B@sandoe.co.uk> From: Thomas Rodgers Date: Sun, 1 Jan 2023 16:53:51 -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="0000000000002d171105f13d63d5" X-Spam-Status: No, score=-5.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: --0000000000002d171105f13d63d5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable __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 from 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. 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 con= dition .. > 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-ar= ound 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 subseq= uent > 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' l= ock-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 back > 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 > > --0000000000002d171105f13d63d5--