From patchwork Fri Dec 30 08:55:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9491911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EAE1860417 for ; Fri, 30 Dec 2016 08:57:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D73901FF65 for ; Fri, 30 Dec 2016 08:57:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBC8D1FFB9; Fri, 30 Dec 2016 08:57:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7F90D1FF65 for ; Fri, 30 Dec 2016 08:57:02 +0000 (UTC) Received: from localhost ([::1]:38936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMszl-0008M1-HF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 03:57:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMsz9-0008KK-3B for qemu-devel@nongnu.org; Fri, 30 Dec 2016 03:56:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMsz8-0008Db-DN for qemu-devel@nongnu.org; Fri, 30 Dec 2016 03:56:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cMsz8-0008D3-7g for qemu-devel@nongnu.org; Fri, 30 Dec 2016 03:56:22 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 484B081F07; Fri, 30 Dec 2016 08:56:21 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-4-51.pek2.redhat.com [10.72.4.51]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBU8u2Lt011949; Fri, 30 Dec 2016 03:56:18 -0500 From: Peter Xu To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Fri, 30 Dec 2016 16:55:55 +0800 Message-Id: <1483088160-6714-4-git-send-email-peterx@redhat.com> In-Reply-To: <1483088160-6714-1-git-send-email-peterx@redhat.com> References: <1483088160-6714-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 30 Dec 2016 08:56:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [kvm-unit-tests PATCH 3/8] lib/asm-generic: add atomic.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , peterx@redhat.com, agordeev@redhat.com, Jan Kiszka , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provide some gcc-builtin atomic ops. Signed-off-by: Peter Xu --- lib/asm-generic/atomic.h | 21 +++++++++++++++++++++ lib/x86/atomic.h | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 lib/asm-generic/atomic.h diff --git a/lib/asm-generic/atomic.h b/lib/asm-generic/atomic.h new file mode 100644 index 0000000..26b645a --- /dev/null +++ b/lib/asm-generic/atomic.h @@ -0,0 +1,21 @@ +#ifndef __ASM_GENERIC_ATOMIC_H__ +#define __ASM_GENERIC_ATOMIC_H__ + +/* From QEMU include/qemu/atomic.h */ +#define atomic_fetch_inc(ptr) __sync_fetch_and_add(ptr, 1) +#define atomic_fetch_dec(ptr) __sync_fetch_and_add(ptr, -1) +#define atomic_fetch_add(ptr, n) __sync_fetch_and_add(ptr, n) +#define atomic_fetch_sub(ptr, n) __sync_fetch_and_sub(ptr, n) +#define atomic_fetch_and(ptr, n) __sync_fetch_and_and(ptr, n) +#define atomic_fetch_or(ptr, n) __sync_fetch_and_or(ptr, n) +#define atomic_fetch_xor(ptr, n) __sync_fetch_and_xor(ptr, n) + +#define atomic_inc_fetch(ptr) __sync_add_and_fetch(ptr, 1) +#define atomic_dec_fetch(ptr) __sync_add_and_fetch(ptr, -1) +#define atomic_add_fetch(ptr, n) __sync_add_and_fetch(ptr, n) +#define atomic_sub_fetch(ptr, n) __sync_sub_and_fetch(ptr, n) +#define atomic_and_fetch(ptr, n) __sync_and_and_fetch(ptr, n) +#define atomic_or_fetch(ptr, n) __sync_or_and_fetch(ptr, n) +#define atomic_xor_fetch(ptr, n) __sync_xor_and_fetch(ptr, n) + +#endif diff --git a/lib/x86/atomic.h b/lib/x86/atomic.h index de2f033..c9ce489 100644 --- a/lib/x86/atomic.h +++ b/lib/x86/atomic.h @@ -1,6 +1,8 @@ #ifndef __ATOMIC_H #define __ATOMIC_H +#include "asm-generic/atomic.h" + typedef struct { volatile int counter; } atomic_t;