From nobody Wed Oct 06 19:46:52 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 399E917E4CAF; Wed, 6 Oct 2021 19:46:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPlMd0Q1Kz4ktC; Wed, 6 Oct 2021 19:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8BDDE25ED1; Wed, 6 Oct 2021 19:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 196JkqSu041600; Wed, 6 Oct 2021 19:46:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 196Jkq44041599; Wed, 6 Oct 2021 19:46:52 GMT (envelope-from git) Date: Wed, 6 Oct 2021 19:46:52 GMT Message-Id: <202110061946.196Jkq44041599@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 5bf3f2498ade - stable/12 - mips: fcmpset: do not spin on sc failure List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 5bf3f2498adea0087a3ac1e3eaffdfc412b9dfe3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=5bf3f2498adea0087a3ac1e3eaffdfc412b9dfe3 commit 5bf3f2498adea0087a3ac1e3eaffdfc412b9dfe3 Author: Kyle Evans AuthorDate: 2019-10-02 15:13:40 +0000 Commit: Kyle Evans CommitDate: 2021-10-06 19:46:06 +0000 mips: fcmpset: do not spin on sc failure For ll/sc architectures, atomic(9) allows failure modes where *old == val due to write failure and callers should compensate for this. Do not retry on failure, just leave 0 in ret and fail the operation if we couldn't sc it. This lets the caller determine if it should retry or not. (cherry picked from commit 22c2c971a614a72875787e0fd0001906451ee245) --- sys/mips/include/atomic.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/mips/include/atomic.h b/sys/mips/include/atomic.h index 9fe1439b721f..506c686169e4 100644 --- a/sys/mips/include/atomic.h +++ b/sys/mips/include/atomic.h @@ -411,18 +411,25 @@ atomic_fcmpset_32(__volatile uint32_t *p, uint32_t *cmpval, uint32_t newval) { int ret; + /* + * The following sequence (similar to that in atomic_fcmpset_64) will + * attempt to update the value of *p with newval if the comparison + * succeeds. Note that they'll exit regardless of whether the store + * actually succeeded, leaving *cmpval untouched. This is in line with + * the documentation of atomic_fcmpset_() in atomic(9) for ll/sc + * architectures. + */ __asm __volatile ( - "1:\n\t" "ll %0, %1\n\t" /* load old value */ - "bne %0, %4, 2f\n\t" /* compare */ + "bne %0, %4, 1f\n\t" /* compare */ "move %0, %3\n\t" /* value to store */ "sc %0, %1\n\t" /* attempt to store */ - "beqz %0, 1b\n\t" /* if it failed, spin */ - "j 3f\n\t" - "2:\n\t" + "j 2f\n\t" /* exit regardless of success */ + "nop\n\t" /* avoid delay slot accident */ + "1:\n\t" "sw %0, %2\n\t" /* save old value */ "li %0, 0\n\t" - "3:\n" + "2:\n" : "=&r" (ret), "+m" (*p), "=m" (*cmpval) : "r" (newval), "r" (*cmpval) : "memory"); @@ -522,17 +529,16 @@ atomic_fcmpset_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) int ret; __asm __volatile ( - "1:\n\t" "lld %0, %1\n\t" /* load old value */ - "bne %0, %4, 2f\n\t" /* compare */ + "bne %0, %4, 1f\n\t" /* compare */ "move %0, %3\n\t" /* value to store */ "scd %0, %1\n\t" /* attempt to store */ - "beqz %0, 1b\n\t" /* if it failed, spin */ - "j 3f\n\t" - "2:\n\t" + "j 2f\n\t" /* exit regardless of success */ + "nop\n\t" /* avoid delay slot accident */ + "1:\n\t" "sd %0, %2\n\t" /* save old value */ "li %0, 0\n\t" - "3:\n" + "2:\n" : "=&r" (ret), "+m" (*p), "=m" (*cmpval) : "r" (newval), "r" (*cmpval) : "memory");