From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id 081A0385B530 for ; Fri, 24 Feb 2023 15:46:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 081A0385B530 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-172afa7bee2so1470043fac.6 for ; Fri, 24 Feb 2023 07:46:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677253562; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=lHGXDpL3BGmc222RevVlljaw71uzmsLWAV+8DnATNPg=; b=o80ELDCQ9EgfnqbxW9ywf+WFTokBIAMjk52cBFBP7g41DDJIQKHC1vVajmzud49WcS t5wwBNNoXLHGvXouarItFeGr2meNsClWlZZrXK6cfmdMR8JZAxTCx/CGYKNSR5YANOCx Aja9yD31U1Ka9m+uq9AD/yhwOxvyMPK72NxWiyLW/eB1MkG8THgQ0AwxU7HhEyteLdNX whLXMiblFu7dgIRmpTwZwmmUnlxXtht/NmCqQtGqKiq2ACV9oAGZSjv67geV4MRcF2Cf FZt3dsgbteF/2JJditA107hnrCRmj4wfQmJ32wSwnZ/Ene5DOCMc87tysN4oE8Gw2Tl5 Yzxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677253562; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lHGXDpL3BGmc222RevVlljaw71uzmsLWAV+8DnATNPg=; b=l5jaEwJeFXC+E7PdcttuZhjxuOW13EtJ0M8uBzA0zqnW1sQMA8SqpmRonwyw5A1FVU 5YVTdMzPEHrcP8VxW9z759gujeGfzby1CMtUU2O4CJpBEoP3VlIHAg39EtYPZU7GiJFe ZOSJh0JO9LIPEurYGEoQ7ShSR6Ry4llbdcq8X3Zx1rOir0OxxYzJSj3OLI/aWLMfAqMG N7YW04YD1PLOCe/ID/NaMhKC4DPuNgdKDunFdJxQp/tasjJiHT0b5F3LkCGaM85i+Fwq W1mhW7nOz5SEgOgSyuTjHRY577BLLqSLMkGFvJ5e40aLhMFvf3lWfqWstOU+DpnWOdI2 ulVg== X-Gm-Message-State: AO0yUKXHSYdKQb6IVKWBnyeJJtXeaTNEVKA/7PxcVmXmoW0SHnVvy0fg QDpZW1Y8U2oH05DosBuqR+6pZg== X-Google-Smtp-Source: AK7set/eZDag4VLCmrtIWxaw51KI+OwWffLlkYCyR3/n69XL7XSGbPBpofgKFgTNByuuFxYCfo5RxQ== X-Received: by 2002:a05:6870:524a:b0:171:9702:8ec with SMTP id o10-20020a056870524a00b00171970208ecmr13465625oai.32.1677253562199; Fri, 24 Feb 2023 07:46:02 -0800 (PST) Received: from ?IPV6:2804:18:18f9:9546:7940:1bec:71f8:285? ([2804:18:18f9:9546:7940:1bec:71f8:285]) by smtp.gmail.com with ESMTPSA id g3-20020a056870a24300b001729072f759sm1206782oai.0.2023.02.24.07.46.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Feb 2023 07:46:01 -0800 (PST) Message-ID: Date: Fri, 24 Feb 2023 12:45:59 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH v2] i386: Use pthread_barrier for synchronization on tst-bz21269 Content-Language: en-US To: DJ Delorie Cc: libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 22/02/23 22:08, DJ Delorie wrote: > Adhemerval Zanella writes: > >> - - C11 atomics instead of plain access. >> + - Use pthread_barrier instead of atomic and futexes. > > Ok. > >> -#include >> - >> #include >> -#include > > Ok. > >> +#include >> + >> +#define NITER 5 > > Ok. > >> -static int >> -futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2, >> - int val3) >> -{ >> - return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3); >> -} >> - > > Ok. > >> - TEST_VERIFY_EXIT (sigaction (sig, &sa, 0) == 0); >> + xsigaction (sig, &sa, 0); > > Ok. > >> -/* Possible values of futex: >> - 0: thread is idle. >> - 1: thread armed. >> - 2: thread should clear LDT entry 0. >> - 3: thread should exit. */ >> -static atomic_uint ftx; >> +static pthread_barrier_t barrier; > > Ok. > >> - while (1) >> + for (int i = 0; i < NITER; i++) > > Matches the loop in main, ok. > >> - futex ((int *) &ftx, FUTEX_WAIT, 1, NULL, NULL, 0); >> - while (atomic_load (&ftx) != 2) >> - { >> - if (atomic_load (&ftx) >= 3) >> - return NULL; >> - } >> + xpthread_barrier_wait (&barrier); > > First barrier, ok. Both threads start here > >> /* clear LDT entry 0. */ >> const struct user_desc desc = { 0 }; >> xmodify_ldt (1, &desc, sizeof (desc)); > > While we're doing this, main thread is also modifying its ldt? > >> - /* If ftx == 2, set it to zero, If ftx == 100, quit. */ >> - if (atomic_fetch_add (&ftx, -2) != 2) >> - return NULL; >> + /* Wait for 'ss' set in main thread. */ >> + xpthread_barrier_wait (&barrier); > > Second barrier. Ok. After this, the main thread sets SS... > > I think the barriers are still in the wrong locations. > > the original code did this (wrt main): > > * wait for thread to be idle > * xmodify_ldt() > * set thread to "armed" > * set SS to something "funny" > * tell thread to run (=2) > - thread calls xmodify_ltd and goes idle (=0) > * wait for thread idle > > Then, it sets SS *before* the thread clears the LDT. > > So I think the barriers need to be placed like this: > > -main- -thread- > > for (;;) { > xmodify_ldt (set it) - > set SS - > -- barrier -- > - xmodify_ldt (clear it) > -- barrier -- > fail - > } > Ok I thint it works as well. I will update the patch.