From patchwork Sun Aug 9 13:13:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 52096 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 69AAE2152A for ; Sun, 9 Aug 2015 13:24:29 +0000 (UTC) Received: by wilj18 with SMTP id j18sf30216168wil.0 for ; Sun, 09 Aug 2015 06:24:28 -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=PX+s3qfya4KKxDAS9euSXTXzfNKwH9BYn7gGKotpkhk=; b=PpXzbsxocB5ak8dqnMuu6bGnEoTfzCB7yBN2c21KFLKYksAs1Gb/o/xA4nqCRz3SLb gE1wtNlSyUaKruOyL1CntvxsA3BgvgFUyr2u02JY4AY0aP6Q8hddR8Wu5HLqzdSvvS+h ZJdlNf36n+LRYBkt41CYodynm1c4Ko4PW70gZ8Yij3zhQvVqetznfWQeoIW3QpU6YKw2 x3Z+iAaz2gIZxQ7/1Ekib7e6UZwRtMZ1Zti8ONAQHDrsCenqCjsxAf58C4v2FNYSmcqw n61zAZOIdX/xGHYSeJblV4LF/sfQMYbT5Cn7quHH/o4HNMliscacYv0yebv0Nf59tEPm zWeg== X-Gm-Message-State: ALoCoQn/kLVTF+fwUk6spnB5SuKxhlnCvYwvsL7Ns3K1m+Dl8BB1zyMfQwEHtFHnTpZU/FJdivOY X-Received: by 10.152.6.103 with SMTP id z7mr4895288laz.8.1439126668705; Sun, 09 Aug 2015 06:24:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.71 with SMTP id w7ls262147laj.109.gmail; Sun, 09 Aug 2015 06:24:28 -0700 (PDT) X-Received: by 10.112.234.163 with SMTP id uf3mr16054949lbc.37.1439126668155; Sun, 09 Aug 2015 06:24:28 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id kt9si10788878lac.26.2015.08.09.06.24.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Aug 2015 06:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbpo9 with SMTP id po9so82711550lbb.2 for ; Sun, 09 Aug 2015 06:24:28 -0700 (PDT) X-Received: by 10.152.164.130 with SMTP id yq2mr10081328lab.76.1439126667703; Sun, 09 Aug 2015 06:24:27 -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 l6csp1427109lba; Sun, 9 Aug 2015 06:24:26 -0700 (PDT) X-Received: by 10.140.145.83 with SMTP id 80mr31666643qhr.17.1439126666307; Sun, 09 Aug 2015 06:24:26 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b91si28745749qkh.116.2015.08.09.06.24.25; Sun, 09 Aug 2015 06:24:26 -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 7814461F63; Sun, 9 Aug 2015 13:24:25 +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_H2, 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 5EC21621CB; Sun, 9 Aug 2015 13:15:41 +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 061C161F64; Sun, 9 Aug 2015 13:15:35 +0000 (UTC) Received: from mail-ob0-f176.google.com (mail-ob0-f176.google.com [209.85.214.176]) by lists.linaro.org (Postfix) with ESMTPS id A6CAD61F68 for ; Sun, 9 Aug 2015 13:14:11 +0000 (UTC) Received: by obbfr1 with SMTP id fr1so70563583obb.1 for ; Sun, 09 Aug 2015 06:14:11 -0700 (PDT) X-Received: by 10.60.58.225 with SMTP id u1mr15157294oeq.75.1439126051195; Sun, 09 Aug 2015 06:14:11 -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 i3sm5012321oig.24.2015.08.09.06.14.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Aug 2015 06:14:10 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 9 Aug 2015 08:13:55 -0500 Message-Id: <1439126035-13656-14-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439126035-13656-1-git-send-email-bill.fischofer@linaro.org> References: <1439126035-13656-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv12 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.217.178 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 87ea364..682274d 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); +}