From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id A215E3857818 for ; Wed, 10 Nov 2021 15:42:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A215E3857818 Received: by mail-pg1-x531.google.com with SMTP id e65so2612691pgc.5 for ; Wed, 10 Nov 2021 07:42:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FOlE49FUzNL0E3yLgv+/vjgQe5JK6HviRMuQTSX7IxI=; b=dvoBLG2v5DL9N+8ykM6oWNgxFY5lZts8CRkHehJJDMOtYekcYFvL81+6lzF3Q+IPMl Am2Zkb8cd1GaxXz6kQhEEQ9ULUkMADRJKBn2ZDveTbw8M/ufm4OXeOiUzhS/LwXqJ9jz RX+hDHQd/5a/fpFNIsOTu3Z7fbU5T51JSg95mgWuB84Bn/c7SNSVbL8IbQt6zJZIoA9u ICpz4KmXZp7lirKqqRymhXqNUnBkE7lkxnmCbGiqSfjlAjNpw3LqenGmYhGQHLj2/pkk 3m99ugmb2btwmlXkUZ4Wu6GSQoBajTCSJ2atDABE9xhe8TWzGKcX5uLxj3LY29UtY1zL TTcg== X-Gm-Message-State: AOAM531L9rtiu2gzsY2nRRIGYxo33styzyrCYC6kjU0IwWUMkLBiptPO Pp19S6DDMP3qGVXSyUquyJ8YF5vsqyH9/6vbHL8= X-Google-Smtp-Source: ABdhPJxkuvuTHxbwj0yfCL1nOoWjoGL7ygEVTmu8Xsrg0hdMFlkreq3hrEGbC/YPXUDWxVgD3aJkeyQ4JXXnQ4ijpwc= X-Received: by 2002:a63:2155:: with SMTP id s21mr529497pgm.20.1636558976759; Wed, 10 Nov 2021 07:42:56 -0800 (PST) MIME-Version: 1.0 References: <20211110001614.2087610-1-hjl.tools@gmail.com> <20211110153559.GC4930@li-24c3614c-2adc-11b2-a85c-85f334518bdb.ibm.com> In-Reply-To: <20211110153559.GC4930@li-24c3614c-2adc-11b2-a85c-85f334518bdb.ibm.com> From: "H.J. Lu" Date: Wed, 10 Nov 2021 07:42:20 -0800 Message-ID: Subject: Re: [PATCH v4 0/3] Optimize CAS [BZ #28537] To: "Paul A. Clarke" Cc: GNU C Library , Florian Weimer , Arjan van de Ven , Andreas Schwab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3023.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Nov 2021 15:42:59 -0000 On Wed, Nov 10, 2021 at 7:36 AM Paul A. Clarke wrote: > > On Tue, Nov 09, 2021 at 04:16:11PM -0800, H.J. Lu via Libc-alpha wrote: > > CAS instruction is expensive. From the x86 CPU's point of view, gettin= g > > a cache line for writing is more expensive than reading. See Appendix > > A.2 Spinlock in: > > > > https://www.intel.com/content/dam/www/public/us/en/documents/white-pape= rs/xeon-lock-scaling-analysis-paper.pdf > > > > The full compare and swap will grab the cache line exclusive and cause > > excessive cache line bouncing. > > > > Optimize CAS in low level locks and pthread_mutex_lock.c: > > > > 1. Do an atomic load and skip CAS if compare may fail to reduce cache > > line bouncing on contended locks. > > 2. Replace atomic_compare_and_exchange_bool_acq with > > atomic_compare_and_exchange_val_acq to avoid the extra load. > > 3. Drop __glibc_unlikely in __lll_trylock and lll_cond_trylock since we > > don't know if it's actually rare; in the contended case it is clearly n= ot > > rare. > > I see build errors: > > In file included from pthread_mutex_cond_lock.c:23: > ../nptl/pthread_mutex_lock.c: In function =E2=80=98__pthread_mutex_cond_l= ock_full=E2=80=99: > ../nptl/pthread_mutex_lock.c:442:6: error: a label can only be part of a = statement and a declaration is not a statement > int private =3D (robust > ^~~ > ../nptl/pthread_mutex_lock.c:445:6: error: expected expression before =E2= =80=98int=E2=80=99 > int e =3D __futex_lock_pi64 (&mutex->__data.__lock, 0 /* ununsed *= /, > ^~~ > ../nptl/pthread_mutex_lock.c:447:10: error: =E2=80=98e=E2=80=99 undeclare= d (first use in this function) > if (e =3D=3D ESRCH || e =3D=3D EDEADLK) > ^ > ../nptl/pthread_mutex_lock.c:447:10: note: each undeclared identifier is = reported only once for each function it appears in > In file included from ../include/assert.h:1, > from ../nptl/pthread_mutex_lock.c:18, > from pthread_mutex_cond_lock.c:23: > ../assert/assert.h:105:34: error: left-hand operand of comma expression h= as no effect [-Werror=3Dunused-value] > ((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \ > ^ > ../nptl/pthread_mutex_lock.c:449:3: note: in expansion of macro =E2=80=98= assert=E2=80=99 > assert (e !=3D EDEADLK > ^~~~~~ > ../assert/assert.h:105:34: error: left-hand operand of comma expression h= as no effect [-Werror=3Dunused-value] > ((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \ > ^ > ../nptl/pthread_mutex_lock.c:454:3: note: in expansion of macro =E2=80=98= assert=E2=80=99 > assert (e !=3D ESRCH || !robust); > ^~~~~~ > > PC On PPC? --=20 H.J.