From patchwork Thu Nov 20 11:53:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41232 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CFB8D23C27 for ; Thu, 20 Nov 2014 11:54:26 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf1967998eek.6 for ; Thu, 20 Nov 2014 03:54:25 -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=e6pmKQWJDQZ3ohgaNFbyId3TgJzhoenJIxdCF7ZeXC0=; b=XryE84xF0kbN46CvbSvMnzbBZ4u+AHCta7lU7JulVeF8zF0RwLIF6iQp6ok12y+xUE Bqpes3NX5DMd/z/8Ef7eydir5IeDegudAU46c31B0Z8FKEL7E0ArUa5+w+BkuRrUXnVO K2I2dgxNUNR8rzUtr0wBIjkL3o6OJuL+lYDgkGXda/CwQnaJpcdoGtxvI8YMUCvXbYuh kIypAURC59DDRdzVo/PIndRCT3YVXCSkrr09W4mF66k+3Ct/sXt4iniUoksjN3bMNV/1 BfPprOx+YpFJFLYEAveVr6hY7OAa6gsiR9wG+AcLDn5MGtAttda3knlzVUQX0cIpd8hm dcCw== X-Gm-Message-State: ALoCoQmAJR0lyzMoT49TUFNp+EhW2q854coyjSVnjDoxfHvGZeYQXITo2kklTFgN5Qq+uYM/2cY0 X-Received: by 10.112.72.106 with SMTP id c10mr972399lbv.15.1416484465760; Thu, 20 Nov 2014 03:54:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.170 with SMTP id p10ls52816lal.35.gmail; Thu, 20 Nov 2014 03:54:25 -0800 (PST) X-Received: by 10.112.141.233 with SMTP id rr9mr1705060lbb.1.1416484465415; Thu, 20 Nov 2014 03:54:25 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id kw6si2024568lac.24.2014.11.20.03.54.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:25 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gq15so2293274lab.18 for ; Thu, 20 Nov 2014 03:54:25 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr10664801lbc.66.1416484465339; Thu, 20 Nov 2014 03:54:25 -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 ew9csp246765lbc; Thu, 20 Nov 2014 03:54:24 -0800 (PST) X-Received: by 10.224.160.69 with SMTP id m5mr58786109qax.34.1416484464098; Thu, 20 Nov 2014 03:54:24 -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 9si2462336qgp.54.2014.11.20.03.54.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:24 -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 1XrQJZ-00017a-Sw; Thu, 20 Nov 2014 11:54:21 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrQJO-00014r-Th for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 11:54:11 +0000 Received: by mail-lb0-f179.google.com with SMTP id l4so2100661lbv.38 for ; Thu, 20 Nov 2014 03:54:05 -0800 (PST) X-Received: by 10.112.210.100 with SMTP id mt4mr10883823lbc.31.1416484445388; Thu, 20 Nov 2014 03:54:05 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id bb3sm534566lab.7.2014.11.20.03.54.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 03:54:04 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 12:53:43 +0100 Message-Id: <1416484428-23849-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> References: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/7] api: odp_barrier.h: signature change, use odp_atomic.h, atomic wrap-around fix 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.215.45 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 --- platform/linux-generic/include/api/odp_barrier.h | 2 +- platform/linux-generic/odp_barrier.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/include/api/odp_barrier.h b/platform/linux-generic/include/api/odp_barrier.h index 1790ea3..03e889d 100644 --- a/platform/linux-generic/include/api/odp_barrier.h +++ b/platform/linux-generic/include/api/odp_barrier.h @@ -42,7 +42,7 @@ typedef struct odp_barrier_t { * @param barrier Barrier * @param count Thread count */ -void odp_barrier_init(odp_barrier_t *barrier, int count); +void odp_barrier_init(odp_barrier_t *barrier, uint32_t count); /** diff --git a/platform/linux-generic/odp_barrier.c b/platform/linux-generic/odp_barrier.c index 87be2a1..2f14e2f 100644 --- a/platform/linux-generic/odp_barrier.c +++ b/platform/linux-generic/odp_barrier.c @@ -8,11 +8,10 @@ #include #include -void odp_barrier_init(odp_barrier_t *barrier, int count) +void odp_barrier_init(odp_barrier_t *barrier, uint32_t count) { barrier->count = count; - barrier->bar = 0; - odp_sync_stores(); + odp_atomic_init_u32(&barrier->bar, 0); } /* @@ -33,16 +32,18 @@ void odp_barrier_wait(odp_barrier_t *barrier) uint32_t count; int wasless; - odp_sync_stores(); - wasless = barrier->bar < barrier->count; + __atomic_thread_fence(__ATOMIC_SEQ_CST); count = odp_atomic_fetch_inc_u32(&barrier->bar); + wasless = count < barrier->count; if (count == 2*barrier->count-1) { - barrier->bar = 0; + /* Wrap around *atomically* */ + odp_atomic_sub_u32(&barrier->bar, 2 * barrier->count); } else { - while ((barrier->bar < barrier->count) == wasless) + while ((odp_atomic_load_u32(&barrier->bar) < barrier->count) + == wasless) odp_spin(); } - odp_mem_barrier(); + __atomic_thread_fence(__ATOMIC_SEQ_CST); }