From patchwork Tue Aug 25 00:14:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 52663 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 0D4A122DD4 for ; Tue, 25 Aug 2015 00:24:38 +0000 (UTC) Received: by wicja10 with SMTP id ja10sf32255967wic.2 for ; Mon, 24 Aug 2015 17:24:37 -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=amfSsANXrjxYNsxQr7UjAfzLqkNiiubzqkrWoNUTgNg=; b=KfCwqQYpJs7V73m/HSdhlnnHwaiZp8Zsf4LlhplUlBJoA6pC72niuBuuwCqh/Xw+zL cMtODheoW2KV0zSSe9UM2Z6eMO3HzzYd37HrR5rFkmsXqsZ0HuVrC/R6Y1NrcGijbtfM 9dCRom3dx7LrOD0YexavhXz1Psnw6IU28ALwTW73ZLjKiWUr+xEhyp5Rry6sHNPrHIg+ P0UBqDW0Mi/5fvCO5N1UHACNzqh5oBB+CJbI6qcXxYy2wf1HoER/+rjj7HChz7Bw7w16 8+f8AL030hrY37K3+CvdmWlR6UXI1FxeAK9OQ/ccka80hgfKHTAHxDLPPlVCBeEWqZ3x D0bw== X-Gm-Message-State: ALoCoQlnS7QiwdpIK9yqPw615hS1d+bkdumzJ08ljtpTkOKG+BwkU/5amNiQSX0tkyV/e9PCWic7 X-Received: by 10.112.227.105 with SMTP id rz9mr7566419lbc.8.1440462277375; Mon, 24 Aug 2015 17:24:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.73 with SMTP id b9ls647977laf.43.gmail; Mon, 24 Aug 2015 17:24:37 -0700 (PDT) X-Received: by 10.112.138.199 with SMTP id qs7mr22632600lbb.21.1440462277222; Mon, 24 Aug 2015 17:24:37 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id sc4si14635688lbb.99.2015.08.24.17.24.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2015 17:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by labia3 with SMTP id ia3so23585418lab.3 for ; Mon, 24 Aug 2015 17:24:37 -0700 (PDT) X-Received: by 10.152.37.104 with SMTP id x8mr10119606laj.29.1440462277126; Mon, 24 Aug 2015 17:24:37 -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.162.200 with SMTP id yc8csp2814922lbb; Mon, 24 Aug 2015 17:24:35 -0700 (PDT) X-Received: by 10.55.27.27 with SMTP id b27mr51108277qkb.4.1440462275050; Mon, 24 Aug 2015 17:24:35 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 19si30766309qhc.39.2015.08.24.17.24.34; Mon, 24 Aug 2015 17:24:35 -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 0101661F1B; Tue, 25 Aug 2015 00:24:33 +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 B5A2061F3C; Tue, 25 Aug 2015 00:15:59 +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 B021161F3C; Tue, 25 Aug 2015 00:15:54 +0000 (UTC) Received: from mail-oi0-f52.google.com (mail-oi0-f52.google.com [209.85.218.52]) by lists.linaro.org (Postfix) with ESMTPS id A7C5C61F06 for ; Tue, 25 Aug 2015 00:14:45 +0000 (UTC) Received: by oiey141 with SMTP id y141so91013055oie.1 for ; Mon, 24 Aug 2015 17:14:45 -0700 (PDT) X-Received: by 10.202.88.7 with SMTP id m7mr12515474oib.52.1440461685192; Mon, 24 Aug 2015 17:14:45 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by smtp.gmail.com with ESMTPSA id p10sm11084442oev.0.2015.08.24.17.14.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Aug 2015 17:14:44 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 24 Aug 2015 19:14:29 -0500 Message-Id: <1440461669-18578-12-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440461669-18578-1-git-send-email-bill.fischofer@linaro.org> References: <1440461669-18578-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 11/11] 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.48 as permitted sender) smtp.mailfrom=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 --- .../linux-generic/include/odp_buffer_internal.h | 3 ++ .../linux-generic/include/odp_queue_internal.h | 3 ++ platform/linux-generic/odp_queue.c | 41 ++++++++++++++++++++++ platform/linux-generic/odp_schedule.c | 7 ++++ 4 files changed, 54 insertions(+) diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index ca4d314..6badeba 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 */ + 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 163172c..4cee9b6 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -82,6 +82,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 { @@ -120,6 +122,7 @@ int queue_sched_atomic(odp_queue_t handle); int release_order(queue_entry_t *origin_qe, uint64_t order, odp_pool_t pool, int enq_called); void get_sched_order(queue_entry_t **origin_qe, uint64_t *order); +void get_sched_sync(queue_entry_t **origin_qe, uint64_t **sync); void sched_enq_called(void); void sched_order_resolved(odp_buffer_hdr_t *buf_hdr); diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 0227236..0de3aa6 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); } @@ -629,6 +631,7 @@ odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) if (queue_is_ordered(queue)) { 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; @@ -676,6 +679,8 @@ int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) if (queue_is_ordered(queue)) { 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; @@ -990,3 +995,39 @@ int release_order(queue_entry_t *origin_qe, uint64_t order, UNLOCK(&origin_qe->s.lock); return 0; } + +void odp_schedule_order_lock(void) +{ + queue_entry_t *origin_qe; + uint64_t *sync; + + get_sched_sync(&origin_qe, &sync); + if (!origin_qe) + return; + + /* 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 (*sync > odp_atomic_load_u64(&origin_qe->s.sync_out)) + odp_spin(); +} + +void odp_schedule_order_unlock(void) +{ + queue_entry_t *origin_qe; + uint64_t *sync; + + get_sched_sync(&origin_qe, &sync); + if (!origin_qe) + return; + + /* 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 in this ordered context. + */ + *sync = odp_atomic_fetch_inc_u64(&origin_qe->s.sync_in); + odp_atomic_fetch_inc_u64(&origin_qe->s.sync_out); +} diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index a01a79b..41e3865 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -84,6 +84,7 @@ typedef struct { queue_entry_t *qe; queue_entry_t *origin_qe; uint64_t order; + uint64_t sync; odp_pool_t pool; int enq_called; int num; @@ -796,6 +797,12 @@ void get_sched_order(queue_entry_t **origin_qe, uint64_t *order) *order = sched_local.order; } +void get_sched_sync(queue_entry_t **origin_qe, uint64_t **sync) +{ + *origin_qe = sched_local.origin_qe; + *sync = &sched_local.sync; +} + void sched_order_resolved(odp_buffer_hdr_t *buf_hdr) { if (buf_hdr)