From owner-svn-src-stable-11@freebsd.org Thu Aug 16 08:12:38 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3DC491081AA3; Thu, 16 Aug 2018 08:12:38 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E6DDF73B02; Thu, 16 Aug 2018 08:12:37 +0000 (UTC) (envelope-from hselasky@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 C8C6C16BED; Thu, 16 Aug 2018 08:12:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7G8CbTU021091; Thu, 16 Aug 2018 08:12:37 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7G8Cbvl021088; Thu, 16 Aug 2018 08:12:37 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201808160812.w7G8Cbvl021088@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 16 Aug 2018 08:12:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337898 - in stable/11/sys/compat/linuxkpi/common/include: asm linux X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/11/sys/compat/linuxkpi/common/include: asm linux X-SVN-Commit-Revision: 337898 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 08:12:38 -0000 Author: hselasky Date: Thu Aug 16 08:12:36 2018 New Revision: 337898 URL: https://svnweb.freebsd.org/changeset/base/337898 Log: MFC r337527: Use atomic_fcmpset_XXX() instead of atomic_cmpset_XXX() when possible in the LinuxKPI. Suggested by: mjg @ Sponsored by: Mellanox Technologies Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h Thu Aug 16 08:11:17 2018 (r337897) +++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic-long.h Thu Aug 16 08:12:36 2018 (r337898) @@ -87,9 +87,8 @@ atomic_long_cmpxchg(atomic_long_t *v, long old, long n long ret = old; for (;;) { - if (atomic_cmpset_long(&v->counter, old, new)) + if (atomic_fcmpset_long(&v->counter, &ret, new)) break; - ret = READ_ONCE(v->counter); if (ret != old) break; } @@ -99,13 +98,12 @@ atomic_long_cmpxchg(atomic_long_t *v, long old, long n static inline int atomic_long_add_unless(atomic_long_t *v, long a, long u) { - long c; + long c = atomic_long_read(v); for (;;) { - c = atomic_long_read(v); if (unlikely(c == u)) break; - if (likely(atomic_cmpset_long(&v->counter, c, c + a))) + if (likely(atomic_fcmpset_long(&v->counter, &c, c + a))) break; } return (c != u); Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h Thu Aug 16 08:11:17 2018 (r337897) +++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h Thu Aug 16 08:12:36 2018 (r337898) @@ -108,13 +108,12 @@ atomic_dec(atomic_t *v) static inline int atomic_add_unless(atomic_t *v, int a, int u) { - int c; + int c = atomic_read(v); for (;;) { - c = atomic_read(v); if (unlikely(c == u)) break; - if (likely(atomic_cmpset_int(&v->counter, c, c + a))) + if (likely(atomic_fcmpset_int(&v->counter, &c, c + a))) break; } return (c != u); @@ -134,12 +133,10 @@ atomic_xchg(atomic_t *v, int i) defined(__powerpc__) return (atomic_swap_int(&v->counter, i)); #else - int ret; - for (;;) { - ret = READ_ONCE(v->counter); - if (atomic_cmpset_int(&v->counter, ret, i)) - break; - } + int ret = atomic_read(v); + + while (!atomic_fcmpset_int(&v->counter, &ret, i)) + ; return (ret); #endif } @@ -150,9 +147,8 @@ atomic_cmpxchg(atomic_t *v, int old, int new) int ret = old; for (;;) { - if (atomic_cmpset_int(&v->counter, old, new)) + if (atomic_fcmpset_int(&v->counter, &ret, new)) break; - ret = READ_ONCE(v->counter); if (ret != old) break; } Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h Thu Aug 16 08:11:17 2018 (r337897) +++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic64.h Thu Aug 16 08:12:36 2018 (r337898) @@ -92,13 +92,12 @@ atomic64_dec(atomic64_t *v) static inline int64_t atomic64_add_unless(atomic64_t *v, int64_t a, int64_t u) { - int64_t c; + int64_t c = atomic64_read(v); for (;;) { - c = atomic64_read(v); if (unlikely(c == u)) break; - if (likely(atomic_cmpset_64(&v->counter, c, c + a))) + if (likely(atomic_fcmpset_64(&v->counter, &c, c + a))) break; } return (c != u); @@ -112,12 +111,10 @@ atomic64_xchg(atomic64_t *v, int64_t i) defined(__powerpc64__) return (atomic_swap_64(&v->counter, i)); #else - int64_t ret; - for (;;) { - ret = READ_ONCE(v->counter); - if (atomic_cmpset_64(&v->counter, ret, i)) - break; - } + int64_t ret = atomic64_read(v); + + while (!atomic_fcmpset_64(&v->counter, &ret, i)) + ; return (ret); #endif } @@ -128,9 +125,8 @@ atomic64_cmpxchg(atomic64_t *v, int64_t old, int64_t n int64_t ret = old; for (;;) { - if (atomic_cmpset_64(&v->counter, old, new)) + if (atomic_fcmpset_64(&v->counter, &ret, new)) break; - ret = READ_ONCE(v->counter); if (ret != old) break; } Modified: stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h Thu Aug 16 08:11:17 2018 (r337897) +++ stable/11/sys/compat/linuxkpi/common/include/linux/bitops.h Thu Aug 16 08:12:36 2018 (r337898) @@ -282,10 +282,10 @@ test_and_clear_bit(long bit, volatile unsigned long *v var += BIT_WORD(bit); bit %= BITS_PER_LONG; bit = (1UL << bit); - do { - val = *var; - } while (atomic_cmpset_long(var, val, val & ~bit) == 0); + val = *var; + while (!atomic_fcmpset_long(var, &val, val & ~bit)) + ; return !!(val & bit); } @@ -312,10 +312,10 @@ test_and_set_bit(long bit, volatile unsigned long *var var += BIT_WORD(bit); bit %= BITS_PER_LONG; bit = (1UL << bit); - do { - val = *var; - } while (atomic_cmpset_long(var, val, val | bit) == 0); + val = *var; + while (!atomic_fcmpset_long(var, &val, val | bit)) + ; return !!(val & bit); }