From patchwork Thu Nov 27 23:54:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41655 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AA78D25E18 for ; Thu, 27 Nov 2014 23:55:07 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf3502908wgh.5 for ; Thu, 27 Nov 2014 15:55:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=KaTMErbTkqaMPU8Fav6vkxIiG8W60Ekewl5PmEKf0cI=; b=hjthnBD8Bh0GIPMW/uCxotBYq3DT36YgYiOsTIsgd+keq5+0OFZPw8DtKtW+LQFZ6W v6asIANwySVggsx+1sn+D7LKK6E+ClQN+9Q40yWbvX1H8GL5NZ4PYA0Ex2NxbRR/Didg /wtcLslN3gWXQGpgVzZTMEDsCk/dEYA2+er/cEY57tMi1VP0OpeNqFGQu0vqCvfGjd5q RuZALfAythURL6Bs3cX3w1I7XsQmeXQhRApVOZmC/rOEt373WlP+Tc8NEbbNpClmP5K+ 7olP5yg/bwjLg1DX1clH+6omTQI9BCk2l3yXA88pXhixU9qmsF21iJ5DK8H1QpxLZ1F9 Qd0w== X-Gm-Message-State: ALoCoQknhcPT0LKBSDMjoP/NlEkmlg7l5l21PyJM9/jBwSBOIiO6yGLR/heOfhovbuLHkNwulkbx X-Received: by 10.180.206.77 with SMTP id lm13mr2996326wic.4.1417132506983; Thu, 27 Nov 2014 15:55:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.5 with SMTP id o5ls821404lah.84.gmail; Thu, 27 Nov 2014 15:55:06 -0800 (PST) X-Received: by 10.152.9.7 with SMTP id v7mr41285476laa.40.1417132506739; Thu, 27 Nov 2014 15:55:06 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id x8si8443895laj.94.2014.11.27.15.55.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 15:55:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id w7so4875326lbi.1 for ; Thu, 27 Nov 2014 15:55:06 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr41133999lbc.34.1417132506642; Thu, 27 Nov 2014 15:55:06 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp7807lbc; Thu, 27 Nov 2014 15:55:05 -0800 (PST) X-Received: by 10.140.22.83 with SMTP id 77mr7166755qgm.19.1417132504549; Thu, 27 Nov 2014 15:55:04 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id i7si10057171qan.31.2014.11.27.15.54.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Nov 2014 15:55:04 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xu8tk-0001OZ-O6; Thu, 27 Nov 2014 23:54:56 +0000 Received: from mail-lb0-f169.google.com ([209.85.217.169]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xu8tX-0001Mu-Oq for lng-odp@lists.linaro.org; Thu, 27 Nov 2014 23:54:43 +0000 Received: by mail-lb0-f169.google.com with SMTP id p9so4776521lbv.14 for ; Thu, 27 Nov 2014 15:54:38 -0800 (PST) X-Received: by 10.152.207.37 with SMTP id lt5mr21140498lac.66.1417132478175; Thu, 27 Nov 2014 15:54:38 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id w3sm2184314law.36.2014.11.27.15.54.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 15:54:37 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Fri, 28 Nov 2014 00:54:31 +0100 Message-Id: <1417132472-23039-2-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417132472-23039-1-git-send-email-ola.liljedahl@linaro.org> References: <1417132472-23039-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 1/2] linux-generic: odp_atomic_internal.h: more atomic types X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) odp_atomic_internal.h is updated with operations (e.g. exchange, compare-and- exchange) on 16-byte atomics (_odp_atomic_u128_t atomic type with corresponding _uint128_t scalar type). GCC on x86-64 requires the compiler flag -mcx16 to enable support for 16-byte atomics. Some minor changes to the comments. .../linux-generic/include/odp_atomic_internal.h | 72 ++++++++++++++++++++-- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/include/odp_atomic_internal.h b/platform/linux-generic/include/odp_atomic_internal.h index 38b0de0..25da2cd 100644 --- a/platform/linux-generic/include/odp_atomic_internal.h +++ b/platform/linux-generic/include/odp_atomic_internal.h @@ -320,9 +320,10 @@ static inline uint64_t _odp_atomic_u64_xchg_mm(odp_atomic_u64_t *ptr, * @param ptr Pointer to a 64-bit atomic variable * @param exp_p Pointer to expected value (updated on failure) * @param val New value to write - * @param succ Memory model associated with a successful compare-and-swap + * @param succ Memory model associated with a successful compare-and-swap + * operation + * @param fail Memory model associated with a failed compare-and-swap * operation - * @param fail Memory model associated with a failed compare-and-swap operation * * @return 1 (true) if exchange successful, 0 (false) if not successful (and * '*exp_p' updated with current value) @@ -511,9 +512,9 @@ static inline void *_odp_atomic_ptr_xchg(_odp_atomic_ptr_t *ptr, * @param ptr Pointer to a pointer atomic variable * @param exp_p Pointer to expected value (updated on failure) * @param val New value to write - * @param succ Memory model associated with a successful compare-and-swap + * @param succ Memory model associated with a successful compare-and-swap * operation - * @param fail Memory model associated with a failed compare-and-swap + * @param fail Memory model associated with a failed compare-and-swap * operation * * @return 1 (true) if exchange successful, 0 (false) if not successful (and @@ -541,7 +542,7 @@ static inline int _odp_atomic_ptr_cmp_xchg_strong(_odp_atomic_ptr_t *ptr, *****************************************************************************/ /** - * Initialize a flag atomic variable + * Initialize an atomic flag variable * * @param ptr Pointer to a flag atomic variable * @param val The initial value (true or false) of the variable @@ -568,7 +569,8 @@ static inline int _odp_atomic_flag_load(_odp_atomic_flag_t *ptr) /** * Test-and-set of atomic flag variable * @Note Operation has acquire memory model. It pairs with a later - * release operation in some thread. + * release operation in some thread. It does not provide release or + * acquire/release semantics. * * @param ptr Pointer to a flag atomic variable * @return The old value (true or false) of the variable @@ -591,6 +593,64 @@ static inline void _odp_atomic_flag_clear(_odp_atomic_flag_t *ptr) __atomic_clear(ptr, __ATOMIC_RELEASE); } +/* Check if target and compiler supports 128-bit scalars and corresponding + * exchange and CAS operations */ +/* GCC on x86-64 needs -mcx16 compiler option */ +#if defined __SIZEOF_INT128__ && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 + +/** Preprocessor symbol that indicates support for 128-bit atomics */ +#define ODP_ATOMIC_U128 + +/** An unsigned 128-bit (16-byte) scalar type */ +typedef __int128 _uint128_t; + +/** Atomic 128-bit type */ +typedef struct { + _uint128_t v; /**< Actual storage for the atomic variable */ +} _odp_atomic_u128_t ODP_ALIGNED(16); + +/** + * 16-byte atomic exchange operation + * + * @param ptr Pointer to a 16-byte atomic variable + * @param val_p Pointer to new value to write + * @param old_p Pointer to location for old value + * @param mmodel Memory model associated with the exchange operation + */ +static inline void _odp_atomic_u128_xchg_mm(_odp_atomic_u128_t *ptr, + _uint128_t *val_p, + _uint128_t *old_p, + _odp_memmodel_t mm) +{ + __atomic_exchange(&ptr->v, val_p, old_p, mm); +} + +/** + * Atomic compare and exchange (swap) of 16-byte atomic variable + * "Strong" semantics, will not fail spuriously. + * + * @param ptr Pointer to a 16-byte atomic variable + * @param exp_p Pointer to expected value (updated on failure) + * @param val_p Pointer to new value to write + * @param succ Memory model associated with a successful compare-and-swap + * operation + * @param fail Memory model associated with a failed compare-and-swap + * operation + * + * @return 1 (true) if exchange successful, 0 (false) if not successful (and + * '*exp_p' updated with current value) + */ +static inline int _odp_atomic_u128_cmp_xchg_mm(_odp_atomic_u128_t *ptr, + _uint128_t *exp_p, + _uint128_t *val_p, + _odp_memmodel_t succ, + _odp_memmodel_t fail) +{ + return __atomic_compare_exchange(&ptr->v, exp_p, val_p, + false/*strong*/, succ, fail); +} +#endif + /** * @} */