From patchwork Fri Aug 7 11:47:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 52038 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id E2BF920539 for ; Fri, 7 Aug 2015 11:57:24 +0000 (UTC) Received: by labth1 with SMTP id th1sf38871796lab.2 for ; Fri, 07 Aug 2015 04:57:23 -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=sGwMNEdu52yznMUnxNjk/CusCKhxIn0/VUhQKsIf384=; b=On/qdUHq65xLD3nV8zG7VglxOgM7OvFQJmE49neJUoQSAb7FuSdrg0X8tLBxMRBFUv Jyr87nJURZLz9Y26QcPOhpVZHBUGbzwqk51NKnShtuP7CPkiWdMgjl2JfYxNKHyQDVi5 y+iN2pzoDymdZRDW3WZm+8lfZ6Ju6LfiMr8ZCxt+nydtIppBYDHLW5uu7ROdodaRnJF/ MgTR7TVS8/ql3FHl5UdAW/IEm38OhDHdOK+fSO0Gmfb/xqv/JyUNrUN6ZljGkXleNYNH FB+G3Ir0XOjkt+hFAq6B9wbAjJJUaM+elNRNW2urxFMCf9GV7P+XvTWjzkb1goxAFVkC 64UQ== X-Gm-Message-State: ALoCoQlydgyJdZI8yUARMena4VlfAdQNzupOhVFobKvaURBHGkso/7PG0Hhj9/57Wm+q+dPGj5Zw X-Received: by 10.112.139.137 with SMTP id qy9mr2014098lbb.17.1438948643876; Fri, 07 Aug 2015 04:57:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls400845lak.17.gmail; Fri, 07 Aug 2015 04:57:23 -0700 (PDT) X-Received: by 10.152.28.229 with SMTP id e5mr7085006lah.110.1438948643729; Fri, 07 Aug 2015 04:57:23 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id dh9si7318094lac.35.2015.08.07.04.57.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2015 04:57:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labjt7 with SMTP id jt7so48641897lab.0 for ; Fri, 07 Aug 2015 04:57:23 -0700 (PDT) X-Received: by 10.152.164.130 with SMTP id yq2mr1550342lab.76.1438948643478; Fri, 07 Aug 2015 04:57:23 -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 l6csp323738lba; Fri, 7 Aug 2015 04:57:22 -0700 (PDT) X-Received: by 10.55.20.134 with SMTP id 6mr4487885qku.57.1438948641914; Fri, 07 Aug 2015 04:57:21 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z89si17523079qge.29.2015.08.07.04.57.21; Fri, 07 Aug 2015 04:57:21 -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 260DB6206F; Fri, 7 Aug 2015 11:57:21 +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 308B362219; Fri, 7 Aug 2015 11:49:02 +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 002B06218A; Fri, 7 Aug 2015 11:48:54 +0000 (UTC) Received: from mail-ob0-f174.google.com (mail-ob0-f174.google.com [209.85.214.174]) by lists.linaro.org (Postfix) with ESMTPS id 0B86C620F4 for ; Fri, 7 Aug 2015 11:47:33 +0000 (UTC) Received: by obbop1 with SMTP id op1so77182716obb.2 for ; Fri, 07 Aug 2015 04:47:32 -0700 (PDT) X-Received: by 10.182.148.65 with SMTP id tq1mr6511118obb.12.1438948052510; Fri, 07 Aug 2015 04:47:32 -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 f128sm338865oig.2.2015.08.07.04.47.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Aug 2015 04:47:32 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Fri, 7 Aug 2015 06:47:16 -0500 Message-Id: <1438948036-31868-14-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438948036-31868-1-git-send-email-bill.fischofer@linaro.org> References: <1438948036-31868-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv9 13/13] linux-generic: schedule: implement odp_schedule_order_lock/unlock 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.42 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: Bill Fischofer --- .../include/odp/plat/schedule_types.h | 2 - .../linux-generic/include/odp_buffer_internal.h | 5 ++- .../linux-generic/include/odp_queue_internal.h | 2 + platform/linux-generic/odp_queue.c | 48 ++++++++++++++++++++-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/include/odp/plat/schedule_types.h b/platform/linux-generic/include/odp/plat/schedule_types.h index f13bfab..3665fec 100644 --- a/platform/linux-generic/include/odp/plat/schedule_types.h +++ b/platform/linux-generic/include/odp/plat/schedule_types.h @@ -52,8 +52,6 @@ typedef int odp_schedule_group_t; #define ODP_SCHED_GROUP_NAME_LEN 32 -typedef int odp_schedule_olock_t; - /** * @} */ diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index c9b8409..ddd2642 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -140,7 +140,10 @@ typedef struct odp_buffer_hdr_t { void *addr[ODP_BUFFER_MAX_SEG]; /* block addrs */ uint64_t order; /* sequence for ordered queues */ queue_entry_t *origin_qe; /* ordered queue origin */ - queue_entry_t *target_qe; /* ordered queue target */ + union { + queue_entry_t *target_qe; /* ordered queue target */ + uint64_t sync; /* for ordered synchronization */ + }; } odp_buffer_hdr_t; /** @internal Compile time assert that the diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 9cca552..aa36df5 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -81,6 +81,8 @@ struct queue_entry_s { uint64_t order_out; odp_buffer_hdr_t *reorder_head; odp_buffer_hdr_t *reorder_tail; + odp_atomic_u64_t sync_in; + odp_atomic_u64_t sync_out; }; typedef union queue_entry_u { diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index ec1f797..2d999aa 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef USE_TICKETLOCK #include @@ -122,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); } @@ -404,8 +407,10 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) } /* We're in order, so account for this and proceed with enq */ - if (!buf_hdr->flags.sustain) + if (!buf_hdr->flags.sustain) { origin_qe->s.order_out++; + odp_atomic_fetch_inc_u64(&origin_qe->s.sync_out); + } /* if this element is linked, restore the linked chain */ buf_tail = buf_hdr->link; @@ -524,6 +529,8 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) /* Reflect the above two in the output sequence */ origin_qe->s.order_out += release_count + placeholder_count; + odp_atomic_fetch_add_u64(&origin_qe->s.sync_out, + release_count + placeholder_count); /* Now handle any unblocked buffers destined for other queues */ UNLOCK(&queue->s.lock); @@ -689,7 +696,8 @@ odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) buf_hdr->next = NULL; if (queue->s.param.sched.sync == ODP_SCHED_SYNC_ORDERED) { buf_hdr->origin_qe = queue; - buf_hdr->order = queue->s.order_in++; + 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; @@ -737,6 +745,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; @@ -829,8 +839,10 @@ int odp_schedule_release_ordered(odp_event_t ev) */ if (buf_hdr->order <= origin_qe->s.order_out + 1) { buf_hdr->origin_qe = NULL; - if (!buf_hdr->flags.sustain) + if (!buf_hdr->flags.sustain) { origin_qe->s.order_out++; + odp_atomic_fetch_inc_u64(&origin_qe->s.sync_out); + } /* check if this release allows us to unblock waiters */ reorder_buf = origin_qe->s.reorder_head; @@ -911,8 +923,38 @@ int odp_schedule_order_copy(odp_event_t src_event, odp_event_t dst_event) dst->origin_qe = origin_qe; dst->order = src->order; + dst->sync = src->sync; src->flags.sustain = 1; 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); +}