From owner-svn-src-all@freebsd.org Wed Oct 2 15:13:41 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A360C1317A8; Wed, 2 Oct 2019 15:13:41 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46k05d3s6Mz4Xyw; Wed, 2 Oct 2019 15:13:41 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 508D72D5E9; Wed, 2 Oct 2019 15:13:41 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x92FDfrg013966; Wed, 2 Oct 2019 15:13:41 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x92FDf93013965; Wed, 2 Oct 2019 15:13:41 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201910021513.x92FDf93013965@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 2 Oct 2019 15:13:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353008 - head/sys/mips/include X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/mips/include X-SVN-Commit-Revision: 353008 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Oct 2019 15:13:41 -0000 Author: kevans Date: Wed Oct 2 15:13:40 2019 New Revision: 353008 URL: https://svnweb.freebsd.org/changeset/base/353008 Log: 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. Reviewed by: kib Looks ok: imp Differential Revision: https://reviews.freebsd.org/D21836 Modified: head/sys/mips/include/atomic.h Modified: head/sys/mips/include/atomic.h ============================================================================== --- head/sys/mips/include/atomic.h Wed Oct 2 13:46:40 2019 (r353007) +++ head/sys/mips/include/atomic.h Wed Oct 2 15:13:40 2019 (r353008) @@ -397,18 +397,25 @@ atomic_fcmpset_32(__volatile uint32_t *p, uint32_t *cm { 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"); @@ -508,17 +515,16 @@ atomic_fcmpset_64(__volatile uint64_t *p, uint64_t *cm 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");