From patchwork Tue May 17 18:58:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 68002 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2238678qge; Tue, 17 May 2016 11:59:13 -0700 (PDT) X-Received: by 10.55.75.14 with SMTP id y14mr3548386qka.33.1463511551974; Tue, 17 May 2016 11:59:11 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y133si3275604qha.49.2016.05.17.11.59.11; Tue, 17 May 2016 11:59:11 -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 9BBC86178C; Tue, 17 May 2016 18:59:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 0C6F561747; Tue, 17 May 2016 18:58:43 +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 A44C661735; Tue, 17 May 2016 18:58:39 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id 13967615CF for ; Tue, 17 May 2016 18:58:38 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id j8so10776108lfd.2 for ; Tue, 17 May 2016 11:58:38 -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=a+YDnZsigqdSx+NQ8o5SIJeug6QyU7kJEmJvKv4+T0k=; b=ee1wY+SKomwt0ls/S/xtm4jEnCKLXA7zg4bzTiaDWr9/LYUsN4emqMGQh0BSRZtmtj VgHtL7keyZaoUbvZJMXseICgzXbhu3wZi2NOj+Ot4e3NprAA/rrNIOaVcr/ejYsgXud/ 48QJIcO2sNQPGABFOnmUK4D0swKpZh9uoGrtHnHEq3ox2gvrWT9ABwg0Po2Q1tfxh057 oB+TwqoyuXV4pRcw2/7FNZdIwr1kd3Hfhaxoukv8vIdrK7+Y/GSiaLfmHVUaXIEEOrWs 7pCMWJLshAJafZ2ZZQ2Sf2+AG8ED2vwEBxe5ecKtmc0oBqT/EnSWoaNW189KiFFuoeq0 Pn2A== X-Gm-Message-State: AOPr4FX4kIFvRVw9+hAMrbLVi6yHYowwrwoVQtdDwbYL88R8OWUHPUzmsg1bd9pShUc61sVy0Bo= X-Received: by 10.25.15.77 with SMTP id e74mr1128699lfi.148.1463511516902; Tue, 17 May 2016 11:58:36 -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 v4sm758712lbi.20.2016.05.17.11.58.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 May 2016 11:58:36 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 17 May 2016 20:58:17 +0200 Message-Id: <1463511498-855-2-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463511498-855-1-git-send-email-ola.liljedahl@linaro.org> References: <1463511498-855-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 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. 128-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 c59d2d1..7cd6670 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,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 6b84309..41e7195 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)