From patchwork Tue May 17 19:21:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 68004 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2249682qge; Tue, 17 May 2016 12:22:24 -0700 (PDT) X-Received: by 10.141.45.135 with SMTP id w129mr1563167qhe.104.1463512944509; Tue, 17 May 2016 12:22:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x184si3335599qhe.101.2016.05.17.12.22.24; Tue, 17 May 2016 12:22:24 -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 ED1C461783; Tue, 17 May 2016 19:22:23 +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 D2E4C61747; Tue, 17 May 2016 19:21:54 +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 43C3B6172B; Tue, 17 May 2016 19:21:51 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id 8180D61614 for ; Tue, 17 May 2016 19:21:49 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id m64so11067762lfd.1 for ; Tue, 17 May 2016 12:21:49 -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=sIAwoXK00S8bAp+aDrwMKDykrSYyOM1NWzAibM5svOY=; b=RJVgM84uTbIP9xPk/Rdh6bg3wmkWMpNhbI3ejS3HMvNd+xNyfdl9c1J7YotVdlz91Q 6saQrcSFjr+a2YJZMxv1UNYYDUEet7XO4wGoiliDaqGfE+UMKtIx6/p313ghSH0l6JyR CbuS73q3fpMHSnfy3zQywknOFTEn2dR4wvzXcOcz8EadEqz2AsZq1GSlnr0dhzVYlQ7I 07v6hyDTmFIcJmiCfBRwqb9RFF+j2gh3a1qWjmcZdnyET7ZUmm59UESjI50jDBi1gXDl Nm1IsUB0XhjBWowGrbdyd3RBrTMZZLrVD93kBzhw2TYp8Mr50D/8/a1EZk5HvIywU0J7 6rNg== X-Gm-Message-State: AOPr4FU34vb4R1YuVMQCO8RRY4qZ890WdogjjlNZj15UNtwmJusLOlFKL8EgRKvVk3BzqDj25zw= X-Received: by 10.25.20.155 with SMTP id 27mr1025976lfu.90.1463512908389; Tue, 17 May 2016 12:21:48 -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 92sm749052lfw.25.2016.05.17.12.21.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 May 2016 12:21:47 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 17 May 2016 21:21:16 +0200 Message-Id: <1463512877-1218-2-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463512877-1218-1-git-send-email-ola.liljedahl@linaro.org> References: <1463512877-1218-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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" 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)