From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11501 Path: news.gmane.org!.POSTED!not-for-mail From: Jens Gustedt Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] a new lock algorithm with lock value and CS counts in the same atomic int Date: Sun, 18 Jun 2017 13:10:56 +0200 Organization: inria.fr Message-ID: <20170618131056.5df46232@inria.fr> References: <868874$8age42@mail2-relais-roc.national.inria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/DEVWBTYl6MWZNJ=FEYmD6lD"; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1497784275 31748 195.159.176.226 (18 Jun 2017 11:11:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Jun 2017 11:11:15 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11514-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jun 18 13:11:11 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dMY6n-0007zn-JW for gllmg-musl@m.gmane.org; Sun, 18 Jun 2017 13:11:09 +0200 Original-Received: (qmail 27782 invoked by uid 550); 18 Jun 2017 11:11:09 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 27761 invoked from network); 18 Jun 2017 11:11:08 -0000 X-IronPort-AV: E=Sophos;i="5.39,356,1493676000"; d="scan'208";a="279473359" In-Reply-To: X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) X-Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAACRQTFRFERslNjAsLTE9Ok9wUk9TaUs8iWhSrYZkj42Rz6aD3sGZ Xref: news.gmane.org gmane.linux.lib.musl.general:11501 Archived-At: --Sig_/DEVWBTYl6MWZNJ=FEYmD6lD Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hello Alexander, On Sun, 18 Jun 2017 13:01:18 +0300 (MSK) Alexander Monakov wrote: > On Fri, 16 Jun 2017, Jens Gustedt wrote: > > void __lock(volatile int *l) > > { > > - if (libc.threads_minus_1) > > - while (a_swap(l, 1)) __wait(l, l+1, 1, 1); > > + /* This test is mostly useless, now. Leaving it to the > > first CAS is > > + probably just as efficient. */ > > + if (libc.threads_minus_1) { =20 > [...] > > void __unlock(volatile int *l) > > { > > - if (l[0]) { > > - a_store(l, 0); > > - if (l[1]) __wake(l, 1, 1); > > + if (a_fetch_add(l, INT_MAX) !=3D -INT_MAX) { > > + __syscall(SYS_futex, l, FUTEX_WAKE|FUTEX_PRIVATE, > > 1); } > > } =20 >=20 > This looks wrong in single-threaded case, __lock doesn't touch the > lock, but __unlock modifies it unconditionally. Right, probably there should be the same test as for the lock case. Or we should drop that test all along. I don't think that it still serves much purpose here. This is just trading one memory access against another. Thanks Jens --=20 :: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS ::: :: ::::::::::::::: office Strasbourg : +33 368854536 :: :: :::::::::::::::::::::: gsm France : +33 651400183 :: :: ::::::::::::::: gsm international : +49 15737185122 :: :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt :: --Sig_/DEVWBTYl6MWZNJ=FEYmD6lD Content-Type: application/pgp-signature Content-Description: Digitale Signatur von OpenPGP -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSN9stI2OFN1pLljN0P0+hp2tU34gUCWUZfwAAKCRAP0+hp2tU3 4hKaAJ9oPclk13jJ8VcIkARzvDOE2afNDQCfTDVWzx6K5YreKdrd16sPSSbbQwQ= =1JQm -----END PGP SIGNATURE----- --Sig_/DEVWBTYl6MWZNJ=FEYmD6lD--