From owner-svn-src-all@freebsd.org  Mon Dec  4 09:48:33 2017
Return-Path: <owner-svn-src-all@freebsd.org>
Delivered-To: svn-src-all@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 293C9DF6105;
 Mon,  4 Dec 2017 09:48:33 +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 mx1.freebsd.org (Postfix) with ESMTPS id E6E098031E;
 Mon,  4 Dec 2017 09:48:32 +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 vB49mVh7090511;
 Mon, 4 Dec 2017 09:48:31 GMT (envelope-from hselasky@FreeBSD.org)
Received: (from hselasky@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id vB49mVAO090510;
 Mon, 4 Dec 2017 09:48:31 GMT (envelope-from hselasky@FreeBSD.org)
Message-Id: <201712040948.vB49mVAO090510@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: hselasky set sender to
 hselasky@FreeBSD.org using -f
From: Hans Petter Selasky <hselasky@FreeBSD.org>
Date: Mon, 4 Dec 2017 09:48:31 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject: svn commit: r326517 - stable/9/sys/i386/include
X-SVN-Group: stable-9
X-SVN-Commit-Author: hselasky
X-SVN-Commit-Paths: stable/9/sys/i386/include
X-SVN-Commit-Revision: 326517
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.25
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
 user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/>
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Dec 2017 09:48:33 -0000

Author: hselasky
Date: Mon Dec  4 09:48:31 2017
New Revision: 326517
URL: https://svnweb.freebsd.org/changeset/base/326517

Log:
  MFC r326161:
  Implement atomic_fetchadd_64() for i386. This function is needed by the
  atomic64 header file in the LinuxKPI for i386.
  
  Reviewed by:	kib
  Sponsored by:	Mellanox Technologies

Modified:
  stable/9/sys/i386/include/atomic.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/i386/include/atomic.h
==============================================================================
--- stable/9/sys/i386/include/atomic.h	Mon Dec  4 09:47:42 2017	(r326516)
+++ stable/9/sys/i386/include/atomic.h	Mon Dec  4 09:48:31 2017	(r326517)
@@ -94,6 +94,7 @@ void		atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_
 
 int		atomic_cmpset_64(volatile uint64_t *, uint64_t, uint64_t);
 uint64_t	atomic_swap_64(volatile uint64_t *, uint64_t);
+uint64_t	atomic_fetchadd_64(volatile uint64_t *, uint64_t);
 
 #else /* !KLD_MODULE && __GNUCLIKE_ASM */
 
@@ -478,6 +479,17 @@ atomic_swap_64(volatile uint64_t *p, uint64_t v)
 		return (atomic_swap_64_i386(p, v));
 	else
 		return (atomic_swap_64_i586(p, v));
+}
+
+static __inline uint64_t
+atomic_fetchadd_64(volatile uint64_t *p, uint64_t v)
+{
+
+	for (;;) {
+		uint64_t t = *p;
+		if (atomic_cmpset_64(p, t, t + v))
+			return (t);
+	}
 }
 
 #endif /* _KERNEL */