From patchwork Tue May 17 14:46:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 67991 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2127501qge; Tue, 17 May 2016 08:05:58 -0700 (PDT) X-Received: by 10.140.81.167 with SMTP id f36mr1997714qgd.63.1463497557992; Tue, 17 May 2016 08:05:57 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t81si2490280qki.220.2016.05.17.08.05.57; Tue, 17 May 2016 08:05:57 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5729A61733; Tue, 17 May 2016 15:05:57 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9196361790; Tue, 17 May 2016 15:02:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 309A761788; Tue, 17 May 2016 15:01:40 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id 7B38B61789 for ; Tue, 17 May 2016 14:46:36 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id ww9so6844903lbc.2 for ; Tue, 17 May 2016 07:46:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=INP0t0z8Q4mbM9Xq79IocrGTBhaY1PlCKeSFXr/qWrk=; b=Di4nf/Vxfp+okCtqUnB7tmclVTEAP6T4UbH+QFEL1tCfAGvemdXzkCOETJ0X09C/O9 Tp89G48z8zstAN0s6MV/jvgwvkSP6SlOIUeoaN4l7/tiJSByHUdT1W1pxr5PWLBgyuZE kEWfHLIcoKPy6dR9Ri5kSQLmnKWLyXqlDbWutiAoal4VVzKhDvTe9tllFQ3OyLN2kS8W uiyoiQqht92ld9ixJ1+/mepfU981jr5H86NQd1mBPN/tiVPkenLdcFojlyGl8l7OYdgG laTY1EEMzloFGrWdbnIDupc8WEeaVZKJszpp8ZmDGIwtPmj1/iZ5dG6Z4zcU6AN+g/YW T7eQ== X-Gm-Message-State: AOPr4FWhi6tR63VnqsnbKkx0u7b/FpRZPw6fU5ZzyGN3PLYQ7RMfhPTWyUWI4UySfmWUw2UcisM= X-Received: by 10.112.145.70 with SMTP id ss6mr611008lbb.53.1463496395387; Tue, 17 May 2016 07:46:35 -0700 (PDT) Received: from localhost.localdomain (h-155-4-131-235.na.cust.bahnhof.se. [155.4.131.235]) by smtp.gmail.com with ESMTPSA id sg8sm562643lbb.28.2016.05.17.07.46.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 May 2016 07:46:34 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 17 May 2016 16:46:28 +0200 Message-Id: <1463496389-17373-2-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463496389-17373-1-git-send-email-ola.liljedahl@linaro.org> References: <1463496389-17373-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 1/2] linux-generic: odp_atomic_internal.h: add 128-bit atomics X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) Add detection of availability of the -mcx16 compiler flag to the configure script. This flag is necessary on x86-64 to enable cpmxchg16. Implement 128-bit atomics if natively supported by the platform. 28-bit atomics are used by linux-generic timer implementation on certain targets (e.g. x86-64) for lock-free implementation. Signed-off-by: Ola Liljedahl --- configure.ac | 13 +++++ .../linux-generic/include/odp_atomic_internal.h | 62 ++++++++++++++++++++++ platform/linux-generic/odp_timer.c | 4 +- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index a10e0f6..48dff6d 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,19 @@ ODP_CFLAGS="$ODP_CFLAGS -std=c99" # Extra flags for example to suppress certain warning types ODP_CFLAGS="$ODP_CFLAGS $ODP_CFLAGS_EXTRA" +######################################################################### +# Check if compiler supports cmpxchng16 +########################################################################## +my_save_cflags="$CFLAGS" +CFLAGS=-mcx16 +AC_MSG_CHECKING([whether CC supports -mcx16]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], + [AC_MSG_RESULT([yes])] + [ODP_CFLAGS="$ODP_CFLAGS -mcx16"], + [AC_MSG_RESULT([no])] +) +CFLAGS="$my_save_cflags" + ########################################################################## # Default include setup ########################################################################## diff --git a/platform/linux-generic/include/odp_atomic_internal.h b/platform/linux-generic/include/odp_atomic_internal.h index 093280f..3c5606c 100644 --- a/platform/linux-generic/include/odp_atomic_internal.h +++ b/platform/linux-generic/include/odp_atomic_internal.h @@ -587,6 +587,68 @@ static inline void _odp_atomic_flag_clear(_odp_atomic_flag_t *flag) __atomic_clear(flag, __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 Pointer to new value to write + * @param old 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, + _uint128_t *old, + _odp_memmodel_t mm) +{ + __atomic_exchange(&ptr->v, val, old, 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 Pointer to expected value (updated on failure) + * @param val 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 + * + * @retval 1 exchange successul + * @retval 0 exchange failed and '*exp' updated with current value + */ +static inline int _odp_atomic_u128_cmp_xchg_mm(_odp_atomic_u128_t *ptr, + _uint128_t *exp, + _uint128_t *val, + _odp_memmodel_t succ, + _odp_memmodel_t fail) +{ + return __atomic_compare_exchange(&ptr->v, exp, val, + false/*strong*/, succ, fail); +} +#endif + +/** + * @} + */ + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index ac72709..66a25b8 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -11,9 +11,7 @@ * */ -/* Check if compiler supports 16-byte atomics. GCC needs -mcx16 flag on x86 */ -/* Using spin lock actually seems faster on Core2 */ -#ifdef ODP_ATOMIC_U128 +#if __SIZEOF_POINTER__ != 8 /* TB_NEEDS_PAD defined if sizeof(odp_buffer_t) != 8 */ #define TB_NEEDS_PAD #define TB_SET_PAD(x) ((x).pad = 0)