From patchwork Sun Aug 9 13:24:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 52108 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id A552A2152A for ; Sun, 9 Aug 2015 13:35:32 +0000 (UTC) Received: by lbsm2 with SMTP id m2sf17517261lbs.1 for ; Sun, 09 Aug 2015 06:35:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to: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=FpdeAHegyts4NwA82RLf1hAS7JHN/y9WIzBLPftIh90=; b=irVf2cRyiQN+JeHCnB3LGyjf8Ls6FffTliaDH7oyJ6vAmB8tPbPwkv7YiwiYXAWg4C I3n4mhvT0EU2/HQGcT8KN/X5hILxN26ATbAyhZHr42geR70a9pQ+KHaRPrzVl/EkHNqB HhItSmfqr2pXc3nc2YP0u2Z50hiarQl8LUWzvqxwoWBw8jbC1a20LKvt9N9dhAZ7CCzB oug2FHEM6Qrcxe1wLXqQc9ccl5WObwkwNOcr9lX5gsGTgxq/0exEK/9QVvDlQ1Xcogbq e3x1yD1H89uxQZ+wDFk7UjMc5EAoP2jFflwX6qYKYjTmE4i1JOzxZYPyqRwUKKRXRqN5 lMOQ== X-Gm-Message-State: ALoCoQkhxbNpCbZWPFO+F6kVs04Qkgg6j4RjAZD1uc0cwjZPk3ROzC833wAraBd46kS/qknMvmfz X-Received: by 10.152.27.130 with SMTP id t2mr4916091lag.2.1439127331571; Sun, 09 Aug 2015 06:35:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.74 with SMTP id k10ls648402laf.30.gmail; Sun, 09 Aug 2015 06:35:31 -0700 (PDT) X-Received: by 10.152.42.244 with SMTP id r20mr16505633lal.90.1439127331098; Sun, 09 Aug 2015 06:35:31 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id p5si3535907lap.96.2015.08.09.06.35.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Aug 2015 06:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labjt7 with SMTP id jt7so69940013lab.0 for ; Sun, 09 Aug 2015 06:35:31 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr16289613lbc.112.1439127330875; Sun, 09 Aug 2015 06:35:30 -0700 (PDT) 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.7.198 with SMTP id l6csp1431825lba; Sun, 9 Aug 2015 06:35:29 -0700 (PDT) X-Received: by 10.50.66.197 with SMTP id h5mr6374649igt.82.1439127329280; Sun, 09 Aug 2015 06:35:29 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id jn5si3763444igb.83.2015.08.09.06.35.26; Sun, 09 Aug 2015 06:35:29 -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; Received: by lists.linaro.org (Postfix, from userid 109) id 5966E61D27; Sun, 9 Aug 2015 13:35:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal 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 ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 98330621C8; Sun, 9 Aug 2015 13:27:15 +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 1A18961E69; Sun, 9 Aug 2015 13:27:02 +0000 (UTC) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by lists.linaro.org (Postfix) with ESMTPS id B64F261F77 for ; Sun, 9 Aug 2015 13:25:03 +0000 (UTC) Received: by obnw1 with SMTP id w1so107320263obn.3 for ; Sun, 09 Aug 2015 06:25:03 -0700 (PDT) X-Received: by 10.60.46.200 with SMTP id x8mr15986539oem.73.1439126703203; Sun, 09 Aug 2015 06:25:03 -0700 (PDT) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by smtp.gmail.com with ESMTPSA id rg1sm10096074oeb.11.2015.08.09.06.25.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Aug 2015 06:25:02 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 9 Aug 2015 08:24:47 -0500 Message-Id: <1439126687-19932-14-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439126687-19932-1-git-send-email-bill.fischofer@linaro.org> References: <1439126687-19932-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv13 13/13] linux-generic: schedule: implement ordered locks X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bill.fischofer@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.43 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 Implement the odp_schedule_order_lock() and odp_schedule_order_unlock() routines to enable ordered synchronization within parallel processing of ordered flows. Signed-off-by: Bill Fischofer --- .../linux-generic/include/odp_queue_internal.h | 1 + platform/linux-generic/odp_queue.c | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 11bc837..66aa887 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -173,6 +173,7 @@ static inline void reorder_enq(queue_entry_t *queue, static inline void order_release(queue_entry_t *origin_qe, int count) { origin_qe->s.order_out += count; + odp_atomic_fetch_add_u64(&origin_qe->s.sync_out, count); } static inline void reorder_deq(queue_entry_t *queue, diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 99829b9..122146c 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -123,6 +123,8 @@ int odp_queue_init_global(void) /* init locks */ queue_entry_t *queue = get_qentry(i); LOCK_INIT(&queue->s.lock); + odp_atomic_init_u64(&queue->s.sync_in, 0); + odp_atomic_init_u64(&queue->s.sync_out, 0); queue->s.handle = queue_from_id(i); } @@ -608,6 +610,7 @@ odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) if (queue->s.param.sched.sync == ODP_SCHED_SYNC_ORDERED) { buf_hdr->origin_qe = queue; buf_hdr->order = queue->s.order_in++; + buf_hdr->sync = odp_atomic_fetch_inc_u64(&queue->s.sync_in); buf_hdr->flags.sustain = 0; } else { buf_hdr->origin_qe = NULL; @@ -655,6 +658,8 @@ int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) if (queue->s.param.sched.sync == ODP_SCHED_SYNC_ORDERED) { buf_hdr[i]->origin_qe = queue; buf_hdr[i]->order = queue->s.order_in++; + buf_hdr[i]->sync = + odp_atomic_fetch_inc_u64(&queue->s.sync_in); buf_hdr[i]->flags.sustain = 0; } else { buf_hdr[i]->origin_qe = NULL; @@ -1007,3 +1012,32 @@ int odp_schedule_order_copy(odp_event_t src_event, odp_event_t dst_event) UNLOCK(&origin_qe->s.lock); return 0; } + +void odp_schedule_order_lock(odp_event_t ev) +{ + odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr(odp_buffer_from_event(ev)); + queue_entry_t *origin_qe = buf_hdr->origin_qe; + + /* Wait until we are in order. Note that sync_out will be incremented + * both by unlocks as well as order resolution, so we're OK if only + * some events in the ordered flow need to lock. + */ + while (buf_hdr->sync > odp_atomic_load_u64(&origin_qe->s.sync_out)) + odp_spin(); +} + +void odp_schedule_order_unlock(odp_event_t ev) +{ + odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr(odp_buffer_from_event(ev)); + queue_entry_t *origin_qe = buf_hdr->origin_qe; + + /* Get a new sync order for reusability, and release the lock. Note + * that this must be done in this sequence to prevent race conditions + * where the next waiter could lock and unlock before we're able to + * get a new sync order since that would cause order inversion on + * subsequent locks we may perform on this event in this ordered + * context. + */ + buf_hdr->sync = odp_atomic_fetch_inc_u64(&origin_qe->s.sync_in); + odp_atomic_fetch_inc_u64(&origin_qe->s.sync_out); +}