From patchwork Tue Dec 2 15:47:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 41815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8A6420672 for ; Tue, 2 Dec 2014 15:48:53 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf8514690wiv.1 for ; Tue, 02 Dec 2014 07:48:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state: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=v6q8pYik1qix5YSbVUzWg2raa/CQjC5LR4ymX5EycUQ=; b=FqVLHbaOoBcMDCZ3GV5cyOfoV91FmkYIfjBgdv2xObLFJLJypxr0tsvpKcWO+McQY4 s0vcexaU5BxMgmX8es4dNIDnSoyW98ucbky4Mzh5icAzthhu1CEE/eqr70Uf1d0wNcQX 0tcUcBpxnY9iIm2rtzIjtyy6M33yWsphAcxHRHD7Plr7V1kFXRNZGjKu9yI77v00jeXO 6DqCTw12eHZNSCYBqZ+rdS38thAGhctJLD/j/Srk1OjAWtPAcgNErXNBq4fUC0TBZL4O jadcRMdT8Ul5w9aWNjFZkC2MCUrSI+Z4RFFR+LDdfh3prFMWYgn6yO6szNUBI6tnIA/a psNQ== X-Gm-Message-State: ALoCoQnQoYrQN6RT7MYXmadMHt05ZcXMdG2S8ax5u7hbefosupCsUWEs1j+X2IgPgwJ4a9iX1szm X-Received: by 10.152.29.226 with SMTP id n2mr204781lah.9.1417535332943; Tue, 02 Dec 2014 07:48:52 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.130 with SMTP id d2ls59380laf.32.gmail; Tue, 02 Dec 2014 07:48:52 -0800 (PST) X-Received: by 10.112.171.136 with SMTP id au8mr39461274lbc.71.1417535332774; Tue, 02 Dec 2014 07:48:52 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id p9si20707519lap.51.2014.12.02.07.48.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Dec 2014 07:48:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id hv19so6341678lab.28 for ; Tue, 02 Dec 2014 07:48:52 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr62500393lbc.34.1417535332460; Tue, 02 Dec 2014 07:48:52 -0800 (PST) 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.184.201 with SMTP id ew9csp506463lbc; Tue, 2 Dec 2014 07:48:51 -0800 (PST) X-Received: by 10.224.21.133 with SMTP id j5mr96922792qab.83.1417535326624; Tue, 02 Dec 2014 07:48:46 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id w6si24717389qax.23.2014.12.02.07.48.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Dec 2014 07:48:46 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xvpgy-0001xv-OX; Tue, 02 Dec 2014 15:48:44 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xvpgs-0001wT-OE for lng-odp@lists.linaro.org; Tue, 02 Dec 2014 15:48:38 +0000 Received: by mail-la0-f50.google.com with SMTP id pn19so10278224lab.9 for ; Tue, 02 Dec 2014 07:48:33 -0800 (PST) X-Received: by 10.152.88.44 with SMTP id bd12mr47019002lab.88.1417535259981; Tue, 02 Dec 2014 07:47:39 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id l1sm5692968lbd.32.2014.12.02.07.47.38 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Dec 2014 07:47:39 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 2 Dec 2014 17:47:28 +0200 Message-Id: <1417535248-19398-3-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1417535248-19398-1-git-send-email-taras.kondratiuk@linaro.org> References: <1417535248-19398-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/2] platform: implement odp_queue_destroy() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@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.41 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: Taras Kondratiuk --- .../linux-generic/include/odp_queue_internal.h | 23 +++++-- platform/linux-generic/odp_queue.c | 72 +++++++++++++++++++- platform/linux-generic/odp_schedule.c | 3 +- 3 files changed, 92 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 8b6c517..501f727 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -34,10 +34,11 @@ extern "C" { #define QUEUE_MULTI_MAX 8 -#define QUEUE_STATUS_FREE 0 -#define QUEUE_STATUS_READY 1 -#define QUEUE_STATUS_NOTSCHED 2 -#define QUEUE_STATUS_SCHED 3 +#define QUEUE_STATUS_FREE 0 +#define QUEUE_STATUS_READY 1 +#define QUEUE_STATUS_NOTSCHED 2 +#define QUEUE_STATUS_SCHED 3 +#define QUEUE_STATUS_DESTROYED 4 /* forward declaration */ union queue_entry_u; @@ -89,6 +90,12 @@ odp_buffer_hdr_t *queue_deq(queue_entry_t *queue); int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); +int queue_enq_dummy(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr); +int queue_enq_multi_dummy(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], + int num); +int queue_deq_multi_destroy(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], + int num); + void queue_lock(queue_entry_t *queue); void queue_unlock(queue_entry_t *queue); @@ -113,6 +120,14 @@ static inline queue_entry_t *queue_to_qentry(odp_queue_t handle) return get_qentry(queue_id); } +static inline int queue_is_destroyed(odp_queue_t handle) +{ + queue_entry_t *queue; + + queue = queue_to_qentry(handle); + + return queue->s.status == QUEUE_STATUS_DESTROYED; +} #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 1318bcd..b87b354 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -192,6 +192,49 @@ odp_queue_t odp_queue_create(const char *name, odp_queue_type_t type, return handle; } +int odp_queue_destroy(odp_queue_t handle) +{ + queue_entry_t *queue; + queue = queue_to_qentry(handle); + + if (queue->s.status == QUEUE_STATUS_FREE) + return -1; /* Queue is alredy freed */ + + LOCK(&queue->s.lock); + if (queue->s.head != NULL) { + UNLOCK(&queue->s.lock); + return -1; /* Queue is not empty */ + } + + queue->s.enqueue = queue_enq_dummy; + queue->s.enqueue_multi = queue_enq_multi_dummy; + + if (queue->s.type == ODP_QUEUE_TYPE_POLL || + queue->s.type == ODP_QUEUE_TYPE_PKTOUT) { + queue->s.status = QUEUE_STATUS_FREE; + queue->s.head = NULL; + queue->s.tail = NULL; + } else if (queue->s.type == ODP_QUEUE_TYPE_SCHED) { + if (queue->s.status == QUEUE_STATUS_SCHED) { + /* + * Override dequeue_multi to destroy queue when it will + * be scheduled next time. + */ + queue->s.status = QUEUE_STATUS_DESTROYED; + queue->s.dequeue_multi = queue_deq_multi_destroy; + } else { + /* Queue won't be scheduled anymore */ + odp_buffer_free(queue->s.sched_buf); + queue->s.sched_buf = ODP_BUFFER_INVALID; + queue->s.status = QUEUE_STATUS_FREE; + queue->s.head = NULL; + queue->s.tail = NULL; + } + } + UNLOCK(&queue->s.lock); + + return 0; +} odp_buffer_t queue_sched_buf(odp_queue_t handle) { @@ -279,7 +322,6 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) return 0; } - int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { int sched = 0; @@ -314,6 +356,18 @@ int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) return 0; } +int queue_enq_dummy(queue_entry_t *queue ODP_UNUSED, + odp_buffer_hdr_t *buf_hdr ODP_UNUSED) +{ + return -1; +} + +int queue_enq_multi_dummy(queue_entry_t *queue ODP_UNUSED, + odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED, + int num ODP_UNUSED) +{ + return -1; +} int odp_queue_enq_multi(odp_queue_t handle, odp_buffer_t buf[], int num) { @@ -407,6 +461,22 @@ int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) return i; } +int queue_deq_multi_destroy(queue_entry_t *queue, + odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED, + int num ODP_UNUSED) +{ + LOCK(&queue->s.lock); + + odp_buffer_free(queue->s.sched_buf); + queue->s.sched_buf = ODP_BUFFER_INVALID; + queue->s.status = QUEUE_STATUS_FREE; + queue->s.head = NULL; + queue->s.tail = NULL; + + UNLOCK(&queue->s.lock); + + return 0; +} int odp_queue_deq_multi(odp_queue_t handle, odp_buffer_t buf[], int num) { diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index cc84e11..c2aeb28 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -302,7 +302,8 @@ static int schedule(odp_queue_t *out_queue, odp_buffer_t out_buf[], * except packet input queues */ if (odp_queue_type(queue) == - ODP_QUEUE_TYPE_PKTIN) + ODP_QUEUE_TYPE_PKTIN && + !queue_is_destroyed(queue)) odp_queue_enq(pri_q, desc_buf); continue;