From patchwork Tue Dec 16 16:15:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42341 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7804626C54 for ; Tue, 16 Dec 2014 16:16:18 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf8808807wgh.10 for ; Tue, 16 Dec 2014 08:16:17 -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: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=0Ba1+WLGlgghBiapCzmVxiQ6lUkBjpS58tahOhEAuDk=; b=k67iSxUYKTcKGrPBoPs9xet5Udqd/N16CcJLmYE5KcEQ3pQWNeA4IvMLpI46hjhHlL oZ3fnC2shN/6AI81MtQ5NlvMaTDE7lm0QHErlMNp1WZfx6ndfaqA3NA8MTuasqYdBK4W DPB13UNtWzCCphyfNDF/to7i1p+xVhhjPn0YQ5nYtIUoXcsYSZp3yf9ZbwN22IJmuV7c ndysgvuYSL4Nai6xIzAs48bsZ9PRwLmmBCltDZXfC3dztmrJ6FOdHCZTucw3VTNWZbbB ZjE5NShf6sLus8WSo6HHmmtURS5A1dfF77vsCjqWYeuhaiBSXhWKdEi8ZM8s5t4xFXnp xjnA== X-Gm-Message-State: ALoCoQkF8ZcwvfU5y7VcHN1LfC9Qv6zhou94cBkcsGAc/5WCbtVYnFjWeT0ToN/9RZjebhBL+xYo X-Received: by 10.112.159.199 with SMTP id xe7mr10960lbb.21.1418746577707; Tue, 16 Dec 2014 08:16:17 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.165 with SMTP id x5ls912993lal.34.gmail; Tue, 16 Dec 2014 08:16:17 -0800 (PST) X-Received: by 10.152.45.65 with SMTP id k1mr13706677lam.14.1418746577446; Tue, 16 Dec 2014 08:16:17 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id j4si1284280lbd.15.2014.12.16.08.16.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 08:16:17 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id z11so11124380lbi.10 for ; Tue, 16 Dec 2014 08:16:17 -0800 (PST) X-Received: by 10.112.14.6 with SMTP id l6mr13763364lbc.91.1418746577321; Tue, 16 Dec 2014 08:16:17 -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.142.69 with SMTP id ru5csp1085819lbb; Tue, 16 Dec 2014 08:16:16 -0800 (PST) X-Received: by 10.140.33.226 with SMTP id j89mr62894641qgj.23.1418746575627; Tue, 16 Dec 2014 08:16:15 -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 u3si1364351qcs.19.2014.12.16.08.16.14 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 08:16:15 -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 1Y0unE-0005bv-3F; Tue, 16 Dec 2014 16:16:12 +0000 Received: from mail-lb0-f176.google.com ([209.85.217.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0un7-0005WQ-4y for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 16:16:05 +0000 Received: by mail-lb0-f176.google.com with SMTP id p9so11028729lbv.21 for ; Tue, 16 Dec 2014 08:15:59 -0800 (PST) X-Received: by 10.152.170.194 with SMTP id ao2mr37163276lac.12.1418746559405; Tue, 16 Dec 2014 08:15:59 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id b4sm300486lbp.17.2014.12.16.08.15.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 08:15:58 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 16 Dec 2014 18:15:54 +0200 Message-Id: <1418746554-12809-1-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv3] linux-generic: 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.217.179 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 Reviewed-by: Bill Fischofer --- v3: Move queue status check under a lock v2: Handle scheduled queues destroy .../linux-generic/include/odp_queue_internal.h | 23 ++++++-- platform/linux-generic/odp_queue.c | 69 +++++++++++++++++++++- platform/linux-generic/odp_schedule.c | 3 +- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 1254763..d5c8e4e 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -35,10 +35,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; @@ -90,6 +91,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); @@ -114,6 +121,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 a7c5e42..1462b41 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -193,6 +193,46 @@ 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); + + LOCK(&queue->s.lock); + if (queue->s.status == QUEUE_STATUS_FREE || queue->s.head != NULL) { + UNLOCK(&queue->s.lock); + return -1; /* Queue is already free or 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) { @@ -280,7 +320,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; @@ -315,6 +354,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) { @@ -408,6 +459,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 aa11b7b..385a914 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -294,7 +294,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;