From patchwork Fri Jul 15 10:46:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 9231661 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 0822760865 for ; Fri, 15 Jul 2016 10:49:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED691254F7 for ; Fri, 15 Jul 2016 10:49:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E24BE27BFC; Fri, 15 Jul 2016 10:49:33 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66DFB254F7 for ; Fri, 15 Jul 2016 10:49:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bO0eK-0003tg-2M; Fri, 15 Jul 2016 10:47:16 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bO0eI-0003sp-ML for xen-devel@lists.xen.org; Fri, 15 Jul 2016 10:47:14 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id CF/A0-28354-13FB8875; Fri, 15 Jul 2016 10:47:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJIsWRWlGSWpSXmKPExsUSfTxjoa7B/o5 wg3sfrS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyHF5vZCxaoVXxYMYOtgfGhfBcjJ4eQgIfE 3s8NjBD2WkaJq40JXYxcQPZJRomJt8+xwRT9XLKMBSKxmlFiytmFzCAJNgFtiXOH7jGB2CIC0 hLXPl9mBCliFljMKHHkXgdYkbBAoMTsSc1gk1gEVCVu/lwBto5XwFWiv+k5UJyDQ0JATmLBhX QQk1PATeJZrxbEXleJxc9ns4DYEgI5EndXLmWHqJaS+N+qBLJJQmAZi8TW7ScZIWpkJB5NvMk 2gVFoASPDKkb14tSistQiXSO9pKLM9IyS3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYzAIKxn YGDcwXiq2fkQoyQHk5Io78aUjnAhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErwe+4BygkWp6akVa Zk5wHiASUtw8CiJ8M4CSfMWFyTmFmemQ6ROMSpKifNagCQEQBIZpXlwbbAYvMQoKyXMy8jAwC DEU5BalJtZgir/ilGcg1FJmDcZZApPZl4J3PRXQIuZgBZbm7eDLC5JREhJNTA6tB//nXB+36f euLWCqpeu9LzP1b1ZLV+/177w8cocqW9pule17mxL1WSZxpWn2L7wNMvnDZMP722XSuU9Vnjg 4uZLxw12fD+w4ZkQ07G5UT//W/WvWmCiWOm4jG2Zje2SmJ43CUKNgmHvD2md4i9pz2N5IHfXf turj3Y32rgq9yyWDOc/+zBdiaU4I9FQi7moOBEAwudiZrwCAAA= X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1468579632!43190755!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58893 invoked from network); 15 Jul 2016 10:47:12 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-16.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 15 Jul 2016 10:47:12 -0000 Received: (qmail 23552 invoked from network); 15 Jul 2016 13:47:12 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 15 Jul 2016 13:47:12 +0300 Received: from smtp02.buh.bitdefender.net (unknown [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id CCA6C7FC07 for ; Fri, 15 Jul 2016 13:47:07 +0300 (EEST) Received: (qmail 21431 invoked from network); 15 Jul 2016 13:47:07 +0300 Received: from unknown (HELO czuzu-dev-vm.clj.bitdefender.biz) (czuzu@bitdefender.com@91.199.104.243) by smtp02.buh.bitdefender.net with SMTP; 15 Jul 2016 13:47:07 +0300 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Fri, 15 Jul 2016 13:46:46 +0300 Message-Id: <1468579606-20073-1-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468579290-19685-1-git-send-email-czuzu@bitdefender.com> References: <1468579290-19685-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.66331 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.911, Dats: 426567, Stamp: 3], Multi: [Enabled, t: (0.000010, 0.004575)], BW: [Enabled, t: (0.000007,0.000002)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.003951), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.011322)], URL: [Enabled, t: (0.000006)], RTDA: [Enabled, t: (0.018492), Hit: No, Details: v2.3.10; Id: 2m1ghic.1aml0sh1c.1p1kd], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Jan Beulich Subject: [Xen-devel] [PATCH v5 7/7] asm/atomic.h: implement missing and add common prototypes X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ARM (): * add atomic_add_unless() wrapper over __atomic_add_unless() (for common-code interface, i.e. ) X86 (): * implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless() * implement missing macro atomic_xchg() COMMON (): * add prototypes for the aforementioned newly implemented X86 functions in common Signed-off-by: Corneliu ZUZU Reviewed-by: Andrew Cooper Acked-by: Julien Grall --- Changed since v4: --- xen/include/asm-arm/atomic.h | 5 +++++ xen/include/asm-x86/atomic.h | 27 +++++++++++++++++++++++++++ xen/include/xen/atomic.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h index f060c5a..22a5036 100644 --- a/xen/include/asm-arm/atomic.h +++ b/xen/include/asm-arm/atomic.h @@ -170,6 +170,11 @@ static inline int atomic_add_negative(int i, atomic_t *v) return atomic_add_return(i, v) < 0; } +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + return __atomic_add_unless(v, a, u); +} + #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #endif /* __ARCH_ARM_ATOMIC__ */ diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index 1729e29..101eded 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -126,6 +126,11 @@ static inline void atomic_sub(int i, atomic_t *v) : "ir" (i), "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_sub_return(int i, atomic_t *v) +{ + return arch_fetch_and_add(&v->counter, -i) - i; +} + static inline int atomic_sub_and_test(int i, atomic_t *v) { unsigned char c; @@ -145,6 +150,11 @@ static inline void atomic_inc(atomic_t *v) : "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_inc_return(atomic_t *v) +{ + return atomic_add_return(1, v); +} + static inline int atomic_inc_and_test(atomic_t *v) { unsigned char c; @@ -164,6 +174,11 @@ static inline void atomic_dec(atomic_t *v) : "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_dec_return(atomic_t *v) +{ + return atomic_sub_return(1, v); +} + static inline int atomic_dec_and_test(atomic_t *v) { unsigned char c; @@ -186,4 +201,16 @@ static inline int atomic_add_negative(int i, atomic_t *v) return c; } +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + int c, old; + + c = atomic_read(v); + while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c) + c = old; + return c; +} + +#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) + #endif /* __ARCH_X86_ATOMIC__ */ diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h index 6827468..529213e 100644 --- a/xen/include/xen/atomic.h +++ b/xen/include/xen/atomic.h @@ -111,6 +111,15 @@ static inline int atomic_add_return(int i, atomic_t *v); static inline void atomic_sub(int i, atomic_t *v); /** + * atomic_sub_return - sub integer and return + * @i: integer value to sub + * @v: pointer of type atomic_t + * + * Atomically subtracts @i from @v and returns @v - @i. + */ +static inline int atomic_sub_return(int i, atomic_t *v); + +/** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic_t @@ -130,6 +139,14 @@ static inline int atomic_sub_and_test(int i, atomic_t *v); static inline void atomic_inc(atomic_t *v); /** + * atomic_inc_return - increment atomic variable and return + * @v: pointer of type atomic_t + * + * Atomically increments @v by 1 and returns @v + 1. + */ +static inline int atomic_inc_return(atomic_t *v); + +/** * atomic_inc_and_test - increment and test * @v: pointer of type atomic_t * @@ -148,6 +165,14 @@ static inline int atomic_inc_and_test(atomic_t *v); static inline void atomic_dec(atomic_t *v); /** + * atomic_dec_return - decrement atomic variable and return + * @v: pointer of type atomic_t + * + * Atomically decrements @v by 1 and returns @v - 1. + */ +static inline int atomic_dec_return(atomic_t *v); + +/** * atomic_dec_and_test - decrement and test * @v: pointer of type atomic_t * @@ -168,4 +193,15 @@ static inline int atomic_dec_and_test(atomic_t *v); */ static inline int atomic_add_negative(int i, atomic_t *v); +/** + * atomic_add_unless - add to atomic variable unless it has a specified value + * @v: pointer of type atomic_t + * @a: integer value to add + * @u: integer value @v must -not- be for the add to be performed + * + * If @v != @u, adds @a to @v and returns @v + @a. + * Otherwise returns @u (== @v). + */ +static inline int atomic_add_unless(atomic_t *v, int a, int u); + #endif /* __XEN_ATOMIC_H__ */