From patchwork Wed Aug 26 23:41:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 52750 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 4CCD122E9E for ; Wed, 26 Aug 2015 23:51:38 +0000 (UTC) Received: by wicne3 with SMTP id ne3sf2431055wic.1 for ; Wed, 26 Aug 2015 16:51: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=Hjq7LdM97DfvRqRdzsF0xnlmLkSSe+mTpvWGLXMOJ/E=; b=BLE4VKG8Aw1Ob3p7BxYbqGAmwrB7rJq/XnLV/Ead8EMG0UhdeWwa/Z+u3DrWRmtZFm HBiMQilOanMZ2NzgS1WfRBR28tQk/maMAgdBstAkfnJrK99qNCuOA0LJcgSUm0cHClk7 unAYD1fn+jRxAYN/h8y3mT5LyEZbJfP5Z4oa/kjdyBTkm/EWPz+bWtWVZmbYxIsDWxnT kroSq1yA44QJ2++lamPvvuUcuZFJgAvUIzJeVbWkNSjXfPObQKl+pN9omLNFXogv3C1X j339+gHMDS1DwkbGdcmoNHZLNpnCB7hnVIksExshHEk60sYbnJaoQ/XYacFFgjZWZEXH 0uUA== X-Gm-Message-State: ALoCoQmTnP+yV/kUM6UbYKUS7QAzGy67A5vbnB9dkmDLNmbas0meu6U+5I7IALj7y3nCRqbz/9T8 X-Received: by 10.180.11.178 with SMTP id r18mr1643107wib.5.1440633097583; Wed, 26 Aug 2015 16:51:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.65 with SMTP id r1ls17931lag.31.gmail; Wed, 26 Aug 2015 16:51:37 -0700 (PDT) X-Received: by 10.152.6.231 with SMTP id e7mr795598laa.78.1440633097432; Wed, 26 Aug 2015 16:51:37 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id o1si309288lbc.8.2015.08.26.16.51.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Aug 2015 16:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labns7 with SMTP id ns7so1820881lab.0 for ; Wed, 26 Aug 2015 16:51:37 -0700 (PDT) X-Received: by 10.152.21.196 with SMTP id x4mr723808lae.117.1440633097325; Wed, 26 Aug 2015 16:51: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 yc8csp4259812lbb; Wed, 26 Aug 2015 16:51:36 -0700 (PDT) X-Received: by 10.107.151.66 with SMTP id z63mr6890723iod.46.1440633095618; Wed, 26 Aug 2015 16:51:35 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c72si522002ioe.185.2015.08.26.16.51.34; Wed, 26 Aug 2015 16:51: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 9268A62132; Wed, 26 Aug 2015 23:51:34 +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_H2, 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 3159D6218B; Wed, 26 Aug 2015 23:43: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 1960162183; Wed, 26 Aug 2015 23:42:56 +0000 (UTC) Received: from mail-oi0-f47.google.com (mail-oi0-f47.google.com [209.85.218.47]) by lists.linaro.org (Postfix) with ESMTPS id 998226212C for ; Wed, 26 Aug 2015 23:41:46 +0000 (UTC) Received: by oiev193 with SMTP id v193so1768762oie.3 for ; Wed, 26 Aug 2015 16:41:46 -0700 (PDT) X-Received: by 10.202.89.132 with SMTP id n126mr1027634oib.0.1440632506075; Wed, 26 Aug 2015 16:41:46 -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 np9sm194060obb.14.2015.08.26.16.41.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Aug 2015 16:41:45 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 26 Aug 2015 18:41:33 -0500 Message-Id: <1440632493-31734-11-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440632493-31734-1-git-send-email-bill.fischofer@linaro.org> References: <1440632493-31734-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv3 10/10] 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.46 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 | 48 ++++++++++++++++++++++ platform/linux-generic/odp_schedule.c | 7 ++++ 4 files changed, 61 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 09b0398..1bd0de6 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); } @@ -599,6 +601,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; @@ -646,6 +649,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; @@ -960,3 +965,46 @@ int release_order(queue_entry_t *origin_qe, uint64_t order, UNLOCK(&origin_qe->s.lock); return 0; } + +/* This routine is a no-op in linux-generic */ +int odp_schedule_order_lock_init(odp_schedule_order_lock_t *lock ODP_UNUSED, + odp_queue_t queue ODP_UNUSED) +{ + return 0; +} + +void odp_schedule_order_lock(odp_schedule_order_lock_t *lock ODP_UNUSED) +{ + 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(odp_schedule_order_lock_t *lock ODP_UNUSED) +{ + 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 e80cec1..51f7adc 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)