From owner-svn-src-all@freebsd.org Mon May 18 09:11:42 2020 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 539F213C35F; Mon, 18 May 2020 09:11:42 +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.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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49QYDG1b5zz4TDX; Mon, 18 May 2020 09:11:42 +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 187C71F243; Mon, 18 May 2020 09:11:42 +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 04I9Bf8O055837; Mon, 18 May 2020 09:11:41 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04I9Bfvs055832; Mon, 18 May 2020 09:11:41 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202005180911.04I9Bfvs055832@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 18 May 2020 09:11:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361180 - stable/12/sys/compat/linuxkpi/common/include/asm X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/12/sys/compat/linuxkpi/common/include/asm X-SVN-Commit-Revision: 361180 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.33 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: Mon, 18 May 2020 09:11:42 -0000 Author: hselasky Date: Mon May 18 09:11:41 2020 New Revision: 361180 URL: https://svnweb.freebsd.org/changeset/base/361180 Log: MFC r360127: Implement the atomic fetch add unless functions for the LinuxKPI. Sponsored by: Mellanox Technologies Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon May 18 09:11:41 2020 (r361180) @@ -119,6 +119,20 @@ atomic_long_add_unless(atomic_long_t *v, long a, long } static inline long +atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u) +{ + long c = atomic_long_read(v); + + for (;;) { + if (unlikely(c == u)) + break; + if (likely(atomic_fcmpset_long(&v->counter, &c, c + a))) + break; + } + return (c); +} + +static inline long atomic_long_dec_and_test(atomic_long_t *v) { long i = atomic_long_add(-1, v); Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h Mon May 18 09:11:41 2020 (r361180) @@ -119,6 +119,20 @@ atomic_add_unless(atomic_t *v, int a, int u) return (c != u); } +static inline int +atomic_fetch_add_unless(atomic_t *v, int a, int u) +{ + int c = atomic_read(v); + + for (;;) { + if (unlikely(c == u)) + break; + if (likely(atomic_fcmpset_int(&v->counter, &c, c + a))) + break; + } + return (c); +} + static inline void atomic_clear_mask(unsigned int mask, atomic_t *v) { Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon May 18 09:11:41 2020 (r361180) @@ -104,6 +104,20 @@ atomic64_add_unless(atomic64_t *v, int64_t a, int64_t } static inline int64_t +atomic64_fetch_add_unless(atomic64_t *v, int64_t a, int64_t u) +{ + int64_t c = atomic64_read(v); + + for (;;) { + if (unlikely(c == u)) + break; + if (likely(atomic_fcmpset_64(&v->counter, &c, c + a))) + break; + } + return (c); +} + +static inline int64_t atomic64_xchg(atomic64_t *v, int64_t i) { #if !((defined(__mips__) && !(defined(__mips_n32) || defined(__mips_n64))) || \