From patchwork Thu Jul 14 09:14:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 9229475 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 0CDFA60574 for ; Thu, 14 Jul 2016 09:17:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF6092815E for ; Thu, 14 Jul 2016 09:17:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E20142818B; Thu, 14 Jul 2016 09:17:52 +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 519E22815E for ; Thu, 14 Jul 2016 09:17:52 +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 1bNcjt-00015p-E8; Thu, 14 Jul 2016 09:15:25 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNcjs-000155-BQ for xen-devel@lists.xen.org; Thu, 14 Jul 2016 09:15:24 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 08/06-09256-B2857875; Thu, 14 Jul 2016 09:15:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJIsWRWlGSWpSXmKPExsUSfTxjoa5WRHu 4welDshZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8avb4fYC2bJVxxraGFpYDwu2cXIySEk4CEx r3MNaxcjF5C9llHixaGVLBCJk4wSi167QNjuEt+ndjBBFK1mlHjacZsdJMEmoC1x7tA9JhBbR EBa4trny4wgNrOAv8SyQ71gcWGBIInf046ygtgsAqoST1ZPBYvzCrhK/P/7Caieg0NCQE5iwY V0kDCngJvEyvYeqBtcJd4//wrWKiGQI3F55nk2iHIpif+tSiDnSAgsZZH4O3sGC0SNjMSjiTf ZJjAKLWBkWMWoXpxaVJZapGukl1SUmZ5RkpuYmaNraGCml5taXJyYnpqTmFSsl5yfu4kRGIQM QLCDcdlfp0OMkhxMSqK82v1t4UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeBeGt4cLCRalpqdWp GXmAOMBJi3BwaMkwlseCpTmLS5IzC3OTIdInWJUlBLnzQfpEwBJZJTmwbXBYvASo6yUMC8j0C FCPAWpRbmZJajyrxjFORiVhHkdQabwZOaVwE1/BbSYCWixtTnY4pJEhJRUA2PDx18+vLOv9Gl annH35DulWRt2de1dlTn2XaeUJ7y5fpwh/jAD66M1Pz5HRDUXfA2aKMbBlCrRabD0vgd7zvmG dQbXp+5LEjVnWemsL3FKalHtrW2CzJubVNxmye5+ul88stLOo8foAnPn7WqrGfvFjFj+GCdcS 3MyPpser/zrtvvTijfyq5RYijMSDbWYi4oTAVWVIIy8AgAA X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1468487721!23318019!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 19248 invoked from network); 14 Jul 2016 09:15:22 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-3.tower-21.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 14 Jul 2016 09:15:22 -0000 Received: (qmail 24619 invoked from network); 14 Jul 2016 12:15:14 +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; 14 Jul 2016 12:15:14 +0300 Received: from smtp02.buh.bitdefender.net (unknown [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 88F747FC05 for ; Thu, 14 Jul 2016 12:15:14 +0300 (EEST) Received: (qmail 4845 invoked from network); 14 Jul 2016 12:15:14 +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; 14 Jul 2016 12:15:14 +0300 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Thu, 14 Jul 2016 12:14:57 +0300 Message-Id: <1468487697-12705-1-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468487370-12345-1-git-send-email-czuzu@bitdefender.com> References: <1468487370-12345-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.66314 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.911, Dats: 426410, Stamp: 3], Multi: [Enabled, t: (0.000009, 0.004470)], BW: [Enabled, t: (0.000007,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.003714), 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.011038)], URL: [Enabled, t: (0.000006)], RTDA: [Enabled, t: (0.017336), Hit: No, Details: v2.3.10; Id: 2m1ghm1.1an9ci7f8.ii5j], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH v3 8/8] asm-x86/atomic.h: implement missing, 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 - implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless() on X86 and also add prototypes for them in common - add missing macro atomic_xchg for X86 Signed-off-by: Corneliu ZUZU Reviewed-by: Andrew Cooper --- xen/include/asm-x86/atomic.h | 27 +++++++++++++++++++++++++++ xen/include/xen/atomic.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) 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__ */