From patchwork Sun Nov 8 20:25:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 56157 Delivered-To: patch@linaro.org Received: by 10.112.1.169 with SMTP id 9csp122371lbn; Sun, 8 Nov 2015 12:28:11 -0800 (PST) X-Received: by 10.55.82.196 with SMTP id g187mr21360828qkb.63.1447014491548; Sun, 08 Nov 2015 12:28:11 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n10si8537155qhb.62.2015.11.08.12.28.11; Sun, 08 Nov 2015 12:28:11 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 2BC426195B; Sun, 8 Nov 2015 20:28:11 +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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 094D9619AD; Sun, 8 Nov 2015 20:26:00 +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 F09D46196D; Sun, 8 Nov 2015 20:25:48 +0000 (UTC) Received: from mail-yk0-f180.google.com (mail-yk0-f180.google.com [209.85.160.180]) by lists.linaro.org (Postfix) with ESMTPS id 9C4E36193F for ; Sun, 8 Nov 2015 20:25:46 +0000 (UTC) Received: by ykdv3 with SMTP id v3so146179125ykd.0 for ; Sun, 08 Nov 2015 12:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IWjqaP0iSOSnx8P5OOiMEXOJP+cgdK3QRY3yinF+mJo=; b=T/VWMdAFBplUOGwilWzFnurDy6DSw0OAKqRzUJ/yfexm8Y1BU9y1B0I1JW/G0Nmmuy 5zj8R1YqSyf6q2Nxbub3CcG59wP0h2BO+G7X/uf8E1kQ4aOPj+uKb2X/LbMLMkOSQ8SH KlenYOaCcG2E5WP0FrxToxDKXEznc/3/FP4a2lBxtMBA/eS++8wTkSzybRRMZiXM8I1J hJcuezNQG2bsWHPJ6HRk06Iq8mLT/aq83ewDYQhFGmo+V9V2HttJRNuOE2CTDhIHl+zo TtK9/Q69fSd3I13UIWY3wxrs/QQ9TkKpcEKG9epbMQXO+2mzkiTT+M6SbQTq35U8bGSm 199w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IWjqaP0iSOSnx8P5OOiMEXOJP+cgdK3QRY3yinF+mJo=; b=biywiLPN7Nh9y62otTsT866KfECoQU6T8LAw7fcOFq5j1kY/Fgl/NuRw3nIIcGKIxS 4jrDsTtb+u79AFLV8cypb0Q1FSnHHxVByYKjQF2ptT5iEfTYGOJcey81s4xyhCl0+SmS WOipO3HAZVxwmrB7zRybsRjmIp8NqG6LFsoH5Q6KgcOfZdRIUSBfzseiZWqeX4C9+j/Y hVzs9df2tFV7yp7m6VXo29a7g+YVIE5LZkN0n7VfyK/LnMqfq/CeVmCC3nuqUbd/9l9G t9WlJvskwBVO+Z4ZG7j/OJFSDW1omgJcwUIKd3Z90isRNMCbGoBemMGskNx5f11mgBfh mfgQ== X-Gm-Message-State: ALoCoQnB834SbvmOdHISdrx40fCLvX6tZLEiAz8vWBvhJB7iBlVEEqRAs2oUycj7XfQwMVqxElYg X-Received: by 10.13.251.66 with SMTP id l63mr19289288ywf.279.1447014346333; Sun, 08 Nov 2015 12:25:46 -0800 (PST) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id h83sm7362134ywc.6.2015.11.08.12.25.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Nov 2015 12:25:45 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 8 Nov 2015 14:25:36 -0600 Message-Id: <1447014338-6409-5-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447014338-6409-1-git-send-email-bill.fischofer@linaro.org> References: <1447014338-6409-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 4/6] linux-generic: queue: add ordered_queue_enq() routine - part 2 X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Restructure queue_enq() to streamline it while using the new ordered_queue_enq() routine to handle ordered queues. This change is made in two parts to make the diffs easier to follow. Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_queue.c | 134 ++++--------------------------------- 1 file changed, 13 insertions(+), 121 deletions(-) diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index a545927..d9be4b3 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -386,146 +386,37 @@ odp_queue_t odp_queue_lookup(const char *name) return ODP_QUEUE_INVALID; } - int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain) { - int sched = 0; queue_entry_t *origin_qe; uint64_t order; - odp_buffer_hdr_t *buf_tail; get_queue_order(&origin_qe, &order, buf_hdr); - /* Need two locks for enq operations from ordered queues */ - if (origin_qe) { - get_qe_locks(origin_qe, queue); - if (odp_unlikely(origin_qe->s.status < QUEUE_STATUS_READY)) { - UNLOCK(&queue->s.lock); - if (origin_qe != queue) - UNLOCK(&origin_qe->s.lock); - ODP_ERR("Bad origin queue status\n"); - ODP_ERR("queue = %s, origin q = %s, buf = %p\n", - queue->s.name, origin_qe->s.name, buf_hdr); - return -1; - } - } else { - LOCK(&queue->s.lock); - } + /* Handle enqueues from ordered queues separately */ + if (origin_qe) + return ordered_queue_enq(queue, buf_hdr, sustain, + origin_qe, order); + + LOCK(&queue->s.lock); if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) { UNLOCK(&queue->s.lock); - if (origin_qe && origin_qe != queue) - UNLOCK(&origin_qe->s.lock); ODP_ERR("Bad queue status\n"); return -1; } - /* We can only complete the enq if we're in order */ - if (origin_qe) { - sched_enq_called(); - if (order > origin_qe->s.order_out) { - reorder_enq(queue, order, origin_qe, buf_hdr, sustain); - - /* This enq can't complete until order is restored, so - * we're done here. - */ - UNLOCK(&queue->s.lock); - if (origin_qe != queue) - UNLOCK(&origin_qe->s.lock); - return 0; - } - - /* We're in order, so account for this and proceed with enq */ - if (!sustain) { - order_release(origin_qe, 1); - sched_order_resolved(buf_hdr); - } - - /* if this element is linked, restore the linked chain */ - buf_tail = buf_hdr->link; - - if (buf_tail) { - buf_hdr->next = buf_tail; - buf_hdr->link = NULL; - - /* find end of the chain */ - while (buf_tail->next) - buf_tail = buf_tail->next; - } else { - buf_tail = buf_hdr; - } - } else { - buf_tail = buf_hdr; - } - - if (!queue->s.head) { - /* Empty queue */ - queue->s.head = buf_hdr; - queue->s.tail = buf_tail; - buf_tail->next = NULL; - } else { - queue->s.tail->next = buf_hdr; - queue->s.tail = buf_tail; - buf_tail->next = NULL; - } + queue_add(queue, buf_hdr); if (queue->s.status == QUEUE_STATUS_NOTSCHED) { queue->s.status = QUEUE_STATUS_SCHED; - sched = 1; /* retval: schedule queue */ - } - - /* - * If we came from an ordered queue, check to see if our successful - * enq has unblocked other buffers in the origin's reorder queue. - */ - if (origin_qe) { - odp_buffer_hdr_t *reorder_buf; - odp_buffer_hdr_t *next_buf; - odp_buffer_hdr_t *reorder_prev; - odp_buffer_hdr_t *placeholder_buf; - int deq_count, release_count, placeholder_count; - - deq_count = reorder_deq(queue, origin_qe, &reorder_buf, - &reorder_prev, &placeholder_buf, - &release_count, &placeholder_count); - - /* Add released buffers to the queue as well */ - if (deq_count > 0) { - queue->s.tail->next = origin_qe->s.reorder_head; - queue->s.tail = reorder_prev; - origin_qe->s.reorder_head = reorder_prev->next; - reorder_prev->next = NULL; - } - - /* Reflect resolved orders in the output sequence */ - order_release(origin_qe, release_count + placeholder_count); - - /* Now handle any unblocked complete buffers destined for - * other queues, appending placeholder bufs as needed. - */ - if (origin_qe != queue) - UNLOCK(&queue->s.lock); - reorder_complete(origin_qe, &reorder_buf, &placeholder_buf, - 1, 0); - UNLOCK(&origin_qe->s.lock); - - if (reorder_buf) - queue_enq_internal(reorder_buf); - - /* Free all placeholder bufs that are now released */ - while (placeholder_buf) { - next_buf = placeholder_buf->next; - odp_buffer_free(placeholder_buf->handle.handle); - placeholder_buf = next_buf; - } - } else { UNLOCK(&queue->s.lock); + if (schedule_queue(queue)) + ODP_ABORT("schedule_queue failed\n"); + return 0; } - /* Add queue to scheduling */ - if (sched && schedule_queue(queue)) - ODP_ABORT("schedule_queue failed\n"); - + UNLOCK(&queue->s.lock); return 0; } @@ -667,7 +558,8 @@ int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], get_queue_order(&origin_qe, &order, buf_hdr[0]); if (origin_qe) { buf_hdr[0]->link = buf_hdr[0]->next; - rc = queue_enq(queue, buf_hdr[0], sustain); + rc = ordered_queue_enq(queue, buf_hdr[0], sustain, + origin_qe, order); return rc == 0 ? num : rc; }