Date: Mon, 30 Jan 2017 09:37:04 -0600 From: Justin Hibbits <jhibbits@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: src-committers <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r312973 - head/sys/powerpc/include Message-ID: <CAHSQbTCJpNf3sBCVRSLp5%2B%2BQq%2BBzT7VLd44RrNjEbhmjerq91g@mail.gmail.com> In-Reply-To: <CAHSQbTDdMm7rKXMXZ5hPL1VvxzLpqMTOmbYkM5opaGRua=St2w@mail.gmail.com> References: <201701300215.v0U2Fsl0006455@repo.freebsd.org> <20170130105345.GL3018@kib.kiev.ua> <CAHSQbTDdMm7rKXMXZ5hPL1VvxzLpqMTOmbYkM5opaGRua=St2w@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 30, 2017 at 9:32 AM, Justin Hibbits <jhibbits@freebsd.org> wrote: > On Mon, Jan 30, 2017 at 4:53 AM, Konstantin Belousov > <kostikbel@gmail.com> wrote: >>> +#ifdef __GNUCLIKE_ASM >>> + __asm __volatile ( >>> + "1:\tlwarx %0, 0, %3\n\t" /* load old value */ >>> + "cmplw %4, %0\n\t" /* compare */ >>> + "bne 2f\n\t" /* exit if not equal */ >>> + "stwcx. %5, 0, %3\n\t" /* attempt to store */ >>> + "bne- 1b\n\t" /* spin if failed */ >>> + "li %0, 1\n\t" /* success - retval = 1 */ >>> + "b 3f\n\t" /* we've succeeded */ >>> + "2:\n\t" >>> + "stwcx. %0, 0, %3\n\t" /* clear reservation (74xx) */ >>> + "stwx %0, 0, %7\n\t" >>> + "li %0, 0\n\t" /* failure - retval = 0 */ >>> + "3:\n\t" >>> + : "=&r" (ret), "=m" (*p), "=m" (*cmpval) >>> + : "r" (p), "r" (*cmpval), "r" (newval), "m" (*p), "r"(cmpval) >>> + : "cr0", "memory"); >>> +#endif >> >> It seems that in case of failed conditional store, the code retries. >> Note that this is not incorrect but also not a desirable behaviour >> with fcmpset: the function should return error and leave the retry >> to the caller. There is no point in having embedded loop. (stupid gmail web UI being so slow it registered me clicking Send when I clicked the ...) Thanks, Kib. I discussed this with mjg on IRC, and it was kind of a toss-up how to implement it, so I took the easiest route. I'll update it tonight and remove the loop. There is an instruction on newer ISAs that would reduce this inline asm even further, 'mfocrf', but it doesn't exist on all supported PowerPC architectures, so it will be just a minor tweak. - Justin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHSQbTCJpNf3sBCVRSLp5%2B%2BQq%2BBzT7VLd44RrNjEbhmjerq91g>