From owner-svn-src-all@freebsd.org Fri Nov 15 04:33:08 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 742281BC4E4; Fri, 15 Nov 2019 04:33:08 +0000 (UTC) (envelope-from jhibbits@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 47DlpD0J2Nz3xcR; Fri, 15 Nov 2019 04:33:08 +0000 (UTC) (envelope-from jhibbits@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 D8520B70F; Fri, 15 Nov 2019 04:33:07 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xAF4X7xi086204; Fri, 15 Nov 2019 04:33:07 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAF4X72Z086202; Fri, 15 Nov 2019 04:33:07 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201911150433.xAF4X72Z086202@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Fri, 15 Nov 2019 04:33:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354723 - in head/sys: powerpc/include sys X-SVN-Group: head X-SVN-Commit-Author: jhibbits X-SVN-Commit-Paths: in head/sys: powerpc/include sys X-SVN-Commit-Revision: 354723 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: Fri, 15 Nov 2019 04:33:08 -0000 Author: jhibbits Date: Fri Nov 15 04:33:07 2019 New Revision: 354723 URL: https://svnweb.freebsd.org/changeset/base/354723 Log: atomic: Add atomic_cmpset_masked to powerpc and use it Summary: This is a more optimal way of doing atomic_compset_masked() than the fallback in sys/_atomic_subword.h. There's also an override for _atomic_fcmpset_masked_word(), which may or may not be necessary, and is unused for powerpc. Reviewed by: kevans, kib Differential Revision: https://reviews.freebsd.org/D22359 Modified: head/sys/powerpc/include/atomic.h head/sys/sys/_atomic_subword.h Modified: head/sys/powerpc/include/atomic.h ============================================================================== --- head/sys/powerpc/include/atomic.h Fri Nov 15 03:40:02 2019 (r354722) +++ head/sys/powerpc/include/atomic.h Fri Nov 15 04:33:07 2019 (r354723) @@ -608,6 +608,38 @@ atomic_cmpset_short(volatile u_short *p, u_short cmpva return (ret); } +#else +static __inline int +atomic_cmpset_masked(uint32_t *p, uint32_t cmpval, uint32_t newval, + uint32_t mask) +{ + int ret; + uint32_t tmp; + + __asm __volatile ( + "1:\tlwarx %2, 0, %2\n\t" /* load old value */ + "and %0, %2, %7\n\t" + "cmplw %4, %0\n\t" /* compare */ + "bne- 2f\n\t" /* exit if not equal */ + "andc %2, %2, %7\n\t" + "or %2, %2, %5\n\t" + "stwcx. %2, 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. %2, 0, %3\n\t" /* clear reservation (74xx) */ + "li %0, 0\n\t" /* failure - retval = 0 */ + "3:\n\t" + : "=&r" (ret), "=m" (*p), "+&r" (tmp) + : "r" (p), "r" (cmpval), "r" (newval), "m" (*p), + "r" (mask) + : "cr0", "memory"); + + return (ret); +} + +#define _atomic_cmpset_masked_word(a,o,v,m) atomic_cmpset_masked(a, o, v, m) #endif static __inline int Modified: head/sys/sys/_atomic_subword.h ============================================================================== --- head/sys/sys/_atomic_subword.h Fri Nov 15 03:40:02 2019 (r354722) +++ head/sys/sys/_atomic_subword.h Fri Nov 15 04:33:07 2019 (r354723) @@ -63,6 +63,7 @@ ((((__uintptr_t)(p) % 4)) * NBBY) #endif +#ifndef _atomic_cmpset_masked_word /* * Pass these bad boys a couple words and a mask of the bits you care about, * they'll loop until we either succeed or fail because of those bits rather @@ -92,7 +93,9 @@ _atomic_cmpset_masked_word(uint32_t *addr, uint32_t ol return (ret); } +#endif +#ifndef _atomic_fcmpset_masked_word static __inline int _atomic_fcmpset_masked_word(uint32_t *addr, uint32_t *old, uint32_t val, uint32_t mask) @@ -108,6 +111,7 @@ _atomic_fcmpset_masked_word(uint32_t *addr, uint32_t * *old = (*addr & ~mask) | *old; return (atomic_fcmpset_32(addr, old, (*old & ~mask) | val)); } +#endif static __inline int atomic_cmpset_8(__volatile uint8_t *addr, uint8_t old, uint8_t val)