From owner-freebsd-current@freebsd.org Fri Mar 10 15:21:33 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 94973D06EC9 for ; Fri, 10 Mar 2017 15:21:33 +0000 (UTC) (envelope-from alexandre.martins@stormshield.eu) Received: from work.stormshield.eu (gwlille.netasq.com [91.212.116.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3C48262C for ; Fri, 10 Mar 2017 15:21:31 +0000 (UTC) (envelope-from alexandre.martins@stormshield.eu) Received: from work.stormshield.eu (localhost [127.0.0.1]) by work.stormshield.eu (Postfix) with ESMTPS id 7B5C93760A9A; Fri, 10 Mar 2017 16:18:55 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by work.stormshield.eu (Postfix) with ESMTP id 6E37F3760A02; Fri, 10 Mar 2017 16:18:55 +0100 (CET) Received: from work.stormshield.eu ([127.0.0.1]) by localhost (work.stormshield.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nwKmgRiXZOxD; Fri, 10 Mar 2017 16:18:55 +0100 (CET) Received: from pc-alex.localnet (fwlabo.stormshield.eu [10.2.0.1]) by work.stormshield.eu (Postfix) with ESMTP id 4CCFF3760750; Fri, 10 Mar 2017 16:18:55 +0100 (CET) From: Alexandre Martins To: Konstantin Belousov Cc: freebsd-current Subject: Re: smp_rendezvous_action: Are atomics correctly used ? Date: Fri, 10 Mar 2017 16:23:02 +0100 Message-ID: <2689552.NsBHWcFoDC@pc-alex> Organization: STORMSHIELD User-Agent: KMail/4.14.10 (FreeBSD/10.3-RELEASE-p7; KDE/4.14.10; amd64; ; ) In-Reply-To: <20170310144626.GL16105@kib.kiev.ua> References: <2092905.6A8RAGlt18@pc-alex> <1881786.W3Fpph0Tg6@pc-alex> <20170310144626.GL16105@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1654324.CXniCo5d1m"; micalg="sha256"; protocol="application/pkcs7-signature" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Mar 2017 15:21:33 -0000 --nextPart1654324.CXniCo5d1m Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Le vendredi 10 mars 2017, 16:46:26 Konstantin Belousov a =E9crit : > On Fri, Mar 10, 2017 at 03:30:21PM +0100, Alexandre Martins wrote: > > Le vendredi 10 mars 2017, 15:57:16 Konstantin Belousov a ?crit : > > > On Fri, Mar 10, 2017 at 02:24:52PM +0100, Alexandre Martins wrote= : > > > > Le jeudi 9 mars 2017, 16:25:17 Konstantin Belousov a ?crit : > > > > > On Thu, Mar 09, 2017 at 02:52:09PM +0100, Alexandre Martins w= rote: > > > > > > Le jeudi 9 mars 2017, 15:07:54 Konstantin Belousov a ?crit = : > > > > > > > On Thu, Mar 09, 2017 at 10:59:27AM +0100, Alexandre Marti= ns=20 wrote: > > > > > > > > I have the save question for the cpu_ipi_pending here: > > > > > > > >=20 > > > > > > > > https://svnweb.freebsd.org/base/head/sys/x86/x86/mp_x86= .c?view > > > > > > > > =3Dann > > > > > > > > otat > > > > > > > > e#l1 > > > > > > > > 080> > > > > > > > >=20 > > > > > > > > Le jeudi 9 mars 2017, 10:43:14 Alexandre Martins a ?cri= t : > > > > > > > > > Hello, > > > > > > > > >=20 > > > > > > > > > I'm curently reading the code of the function > > > > > > > > > smp_rendezvous_action, > > > > > > > > > in > > > > > > > > > kern/subr_smp.c file. In that function, i see that th= e > > > > > > > > > variable > > > > > > > > > smp_rv_waiters is read in some while() loop in a non-= atomic > > > > > > > > > way. > > > > > > > > >=20 > > > > > > > > > https://svnweb.freebsd.org/base/head/sys/kern/subr_sm= p.c?vie > > > > > > > > > w=3Dan > > > > > > > > > nota > > > > > > > > > te#l > > > > > > > > > 412 > > > > > > > > > https://svnweb.freebsd.org/base/head/sys/kern/subr_sm= p.c?vie > > > > > > > > > w=3Dan > > > > > > > > > nota > > > > > > > > > te#l > > > > > > > > > 458 > > > > > > > > > https://svnweb.freebsd.org/base/head/sys/kern/subr_sm= p.c?vie > > > > > > > > > w=3Dan > > > > > > > > > nota > > > > > > > > > te#l > > > > > > > > > 472 > > > > > > > > >=20 > > > > > > > > > I suspect one of my freeze to be due by that. > > > > > > >=20 > > > > > > > You should provide either evidence or, at least, some rea= soning > > > > > > > supporting > > > > > > > your claims. > > > > > >=20 > > > > > > I curently have a software watchdog that triger and does a > > > > > > coredump. > > > > > > In > > > > > > the > > > > > > coredumps, I always see a CPU trying to write-lock a "rm lo= ck". > > > > > > Every > > > > > > time, > > > > > > that CPU is spinning into the smp_rendezvous_action, in the= first > > > > > > while > > > > > > loop) while the others are into the idle threads. > > > > > >=20 > > > > > > The fact is that freeze is not clear and I start to search > > > > > > "exotic" > > > > > > causes > > > > > > to explain it. > > > > >=20 > > > > > This sounds as the 'usual' deadlock, where some other thread = owns > > > > > rmlock > > > > > in > > > > > read mode. I recommend you to follow the > > > > > https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-= handboo > > > > > k/ke > > > > > rnel debug-deadlocks.html > > > >=20 > > > > Just a last question, for my personnal knowledge. > > > >=20 > > > > In ARM >=3D 6, for atomic acces, the code should (?) use LDREX = and STREX > > > > for, I quote : "Use LDREX and STREX to implement interprocess > > > > communication in multiple-processor and shared-memory systems."= (see > > > > here > > > >=20 > > > > http://infocenter.arm.com/help/index.jsp?topic=3D/com.arm.doc.d= ui0489e/C > > > > ihbg > > > > hef.html > > >=20 > > > In my previous response to you, I explicitely defined what 'atomi= c' > > > means when adjected to the term 'load'. The *EX instructions are = used on > > > ll/sc architectures to implement read/modify/write atomic operati= ons, > > > which are different from load (read) operations. > >=20 > > Ok ! Because we just want to read the value, there is no need to us= e the > > *EX version. *EX is intended to be use when a modification will be = done > > thereafter.>=20 > > > > But, in that while loop, it's a standard "LDR" that is used. Is= it > > > > correct > > > > too, and why ? > > >=20 > > > Which 'that while loop' ? > > >=20 > > > =09while (atomic_load_acq_int(&smp_rv_waiters[3]) < ncpus) > > > =09 > > > =09=09cpu_spinwait(); > > >=20 > > > This one ? > >=20 > > No, I point the one at line 412, 458 and 472: > >=20 > > 412: while (smp_rv_waiters[0] < smp_rv_ncpus) > >=20 > > cpu_spinwait(); > >=20 > > 458: while (smp_rv_waiters[1] < smp_rv_ncpus) > >=20 > > cpu_spinwait(); > >=20 > > 472: while (smp_rv_waiters[2] < smp_rv_ncpus) > >=20 > > cpu_spinwait(); > > >=20 > > > Because the semantic of the normal load + DMB barrier provides th= e > > > expected > > > semantic of atomic_load_acq(), as explained in atomic(9) and util= ized by > > > the author of the code. > >=20 > > So, the writer must use LDREX/STREX to modify the value and use dmb= to > > make > > visible to other CPU the write. >=20 > No, this is false statement on all/many counts. ll/sc is only needed= for > atomic modification, not for a write. If you need to assign a given = value > to the variable, STR instruction does just that. LDREX/STREX provide= a > way to ensure that a modification done atomically. E.g., if your int= ent > is to add 1 to the word in memory, you need to ensure that the memory= > is not modified, when writing out the modified read value. >=20 > Next, DMB does not 'make visible' the modification. DMB separates > externally visible effects of executed instructions before and after = it. > From the whole guarantees provided by this separation, atomic_load_ac= q() > only needs the effect of not allowing later memory accesses to occur > earlier than the DMB instruction was executed (the acquire semantic).= > ARMv8 provides loads and stores with the reduced barriers to implemen= t > _acq/_rel without excess overhead of full barrier. >=20 > DMB does not make any store instruction more effective than it alread= y is. OK, that why I didn't understand well the use of atomics. It's related to the function "atomic_load_xxx/atomic_store_xxx" that ma= de me=20 think that it's THIS store or THIS load is atomic, but no. The loads an= d=20 stores are already atomic. Thoses functions just do a barrier (if neede= d)=20 before for "acq" and after for the "rel". The barrier does not "flush" = anything=20 in memory but prevent loads and stores reordering. I realy need to practice more the use of atomic _correctly_ (^_^) >=20 > > The readers can read simply the value without the barrier because c= ache > > coherancy protcol will update the value automaticaly. >=20 > Same is true for stores. This is why plain loads and stores are atom= ic. >=20 > > I think I finally got it ! > > Thank you so much ! > >=20 > > Best regards, =2D-=20 Alexandre Martins STORMSHIELD --nextPart1654324.CXniCo5d1m Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Disposition: attachment; filename="smime.p7s" Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCCCOUw ggSGMIICbqADAgECAgUA28zw7TANBgkqhkiG9w0BAQsFADBIMQswCQYDVQQGEwJGUjEUMBIGA1UE CgwLU1RPUk1TSElFTEQxIzAhBgNVBAMMGlN0b3Jtc2hpZWxkIFJvb3QgQXV0aG9yaXR5MB4XDTE0 MDkwNDE1MDcxMFoXDTI0MDkwMTE1MDcxMFowSTELMAkGA1UEBhMCRlIxFDASBgNVBAoMC1NUT1JN U0hJRUxEMSQwIgYDVQQDDBtTdG9ybXNoaWVsZCBVc2VycyBBdXRob3JpdHkwggEiMA0GCSqGSIb3 DQEBAQUAA4IBDwAwggEKAoIBAQDChwWgC/6VWKL7jgWI3eA2sVvRdOwuHcXsRAAXVWdlMC0ygg7u 45E78GhAnpdl8QbIu7x/Q2zOq6KttspwDEIjkoMLTZngLLlGjYJZPfuSoC6hl9R7vRd5f8Fhu3v0 xQ/7vzKYz4C836IGCrk31gmrPO0H0fxkyxCMfhoTTzue3oXW1IsmQwCrOPOu2Y82QANDhbifWLjI WJetnj58YRKR82KBs3Flbqxtp0mi9+IswMvCCRSoT+ORB73Cl6URt7Qm7BcD+qnkJ9uwlUC94dIl T2hX4ybY/w/ssA17Ew418fgyRCWQXzgjZgZ/XUcw2WP9dIggA7Pg+c/xeROJH1zvAgMBAAGjdjB0 MB0GA1UdDgQWBBShbYRsooCFBXx8dXWANMETW5fXgTAfBgNVHSMEGDAWgBS4Qqn6Z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