From patchwork Mon Apr 14 11:55:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 28318 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0686420F46 for ; Mon, 14 Apr 2014 11:58:07 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf14271095obc.5 for ; Mon, 14 Apr 2014 04:58:07 -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:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=82lcHMsViEqnIe2EKBjVPqxidPDAT5vJtIPRhMYM2uw=; b=C9OLqm6Z6gYRdom8h8IlXAl3Qx8DP7DZVUurxsT1ZX8SXtIUautYZrCWQVk2KTLdbX eK5woBs0+ThZCPsaRHYyH/S29wn05YBYmiYJtMAUp8utfn5Iq48ybcx5hLWQ5LK5M9TS SJUmORl2GGFTaytOJBU7QygNs/4vbpWfvrn1nh96OMkAmwcLKl/jbhKCfxb1xFv7Ka6y xj9NTsaS0ebOG9JTahXzZOMQmx8r6F2POe4HGL9Tf7q1IoBOp0URCVkAmSxlF6K3sJmS 2cTxJ2U2UTA1QbAnvnC79gZpV6/JFpRFFvXY5busKqISy9wqI/y4w3TurJC4eT0vMngw J5Gw== X-Gm-Message-State: ALoCoQmK4B9t33cvs0A5GzjaNFBKH7MOW1gd5tIX4GcyXyuHMUeP0NOzWvHCnGhW+IO7P8ALpZhj X-Received: by 10.50.43.161 with SMTP id x1mr7264419igl.0.1397476687326; Mon, 14 Apr 2014 04:58:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.225 with SMTP id r88ls2808893qgr.2.gmail; Mon, 14 Apr 2014 04:58:07 -0700 (PDT) X-Received: by 10.58.219.233 with SMTP id pr9mr38197042vec.10.1397476687167; Mon, 14 Apr 2014 04:58:07 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id tl10si2703890vcb.103.2014.04.14.04.58.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Apr 2014 04:58:07 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id im17so7249022vcb.37 for ; Mon, 14 Apr 2014 04:58:07 -0700 (PDT) X-Received: by 10.58.220.161 with SMTP id px1mr38136018vec.13.1397476687062; Mon, 14 Apr 2014 04:58:07 -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.220.221.72 with SMTP id ib8csp141327vcb; Mon, 14 Apr 2014 04:58:06 -0700 (PDT) X-Received: by 10.140.81.112 with SMTP id e103mr2264717qgd.99.1397476686637; Mon, 14 Apr 2014 04:58:06 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id v6si6592828qas.22.2014.04.14.04.58.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 14 Apr 2014 04:58:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WZfWP-0001nv-Uy; Mon, 14 Apr 2014 11:57:58 +0000 Received: from mail-la0-f54.google.com ([209.85.215.54]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WZfUU-0001k3-Jb for lng-odp@lists.linaro.org; Mon, 14 Apr 2014 11:55:58 +0000 Received: by mail-la0-f54.google.com with SMTP id mc6so5629207lab.13 for ; Mon, 14 Apr 2014 04:56:00 -0700 (PDT) X-Received: by 10.152.116.43 with SMTP id jt11mr1353716lab.41.1397476560200; Mon, 14 Apr 2014 04:56:00 -0700 (PDT) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id bm3sm14022014lbb.12.2014.04.14.04.55.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Apr 2014 04:55:59 -0700 (PDT) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Mon, 14 Apr 2014 14:55:29 +0300 Message-Id: <1397476530-20816-10-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1397476530-20816-1-git-send-email-taras.kondratiuk@linaro.org> References: <1397476530-20816-1-git-send-email-taras.kondratiuk@linaro.org> Cc: Filip Moerman Subject: [lng-odp] [PATCH 09/10] Keystone2: Add initial HW queues support 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=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 Each odp_queue maps to hw queue for now. odp_queue_enq/deq() translates to hw queue enq/que. Signed-off-by: Taras Kondratiuk --- .../linux-keystone2/include/odp_buffer_internal.h | 2 +- .../include/odp_buffer_pool_internal.h | 2 +- .../linux-keystone2/include/odp_queue_internal.h | 20 +++ platform/linux-keystone2/source/odp_buffer_pool.c | 11 +- platform/linux-keystone2/source/odp_queue.c | 173 +++++++++----------- 5 files changed, 106 insertions(+), 102 deletions(-) diff --git a/platform/linux-keystone2/include/odp_buffer_internal.h b/platform/linux-keystone2/include/odp_buffer_internal.h index 044da4e..030b107 100644 --- a/platform/linux-keystone2/include/odp_buffer_internal.h +++ b/platform/linux-keystone2/include/odp_buffer_internal.h @@ -58,7 +58,7 @@ typedef union odp_buffer_bits_t { typedef struct odp_buffer_hdr_t { Cppi_HostDesc desc; void *buf_vaddr; - odp_queue_t free_queue; + uint32_t free_queue; int type; struct odp_buffer_hdr_t *next; /* next buf in a list */ odp_buffer_bits_t handle; /* handle */ diff --git a/platform/linux-keystone2/include/odp_buffer_pool_internal.h b/platform/linux-keystone2/include/odp_buffer_pool_internal.h index 6ee3eb0..a77331c 100644 --- a/platform/linux-keystone2/include/odp_buffer_pool_internal.h +++ b/platform/linux-keystone2/include/odp_buffer_pool_internal.h @@ -57,7 +57,7 @@ struct pool_entry_s { size_t payload_size; size_t payload_align; int buf_type; - odp_queue_t free_queue; + uint32_t free_queue; uintptr_t buf_base; size_t buf_size; diff --git a/platform/linux-keystone2/include/odp_queue_internal.h b/platform/linux-keystone2/include/odp_queue_internal.h index 8b6c517..c7c84d6 100644 --- a/platform/linux-keystone2/include/odp_queue_internal.h +++ b/platform/linux-keystone2/include/odp_queue_internal.h @@ -22,6 +22,7 @@ extern "C" { #include #include #include +#include #define USE_TICKETLOCK @@ -72,6 +73,7 @@ struct queue_entry_s { odp_queue_param_t param; odp_pktio_t pktin; odp_pktio_t pktout; + uint32_t hw_queue; char name[ODP_QUEUE_NAME_LEN]; }; @@ -113,6 +115,24 @@ static inline queue_entry_t *queue_to_qentry(odp_queue_t handle) return get_qentry(queue_id); } +static inline void _ti_hw_queue_push_desc(uint32_t hw_queue, + odp_buffer_hdr_t *buf_hdr) +{ + ti_em_osal_hw_queue_push_size(hw_queue, + (void *)&buf_hdr->desc, + sizeof(Cppi_HostDesc), + TI_EM_MEM_PUBLIC_DESC); +} + +static inline odp_buffer_hdr_t *_ti_hw_queue_pop_desc(uint32_t hw_queue) +{ + return ti_em_osal_hw_queue_pop(hw_queue, + TI_EM_MEM_PUBLIC_DESC); +} + +odp_queue_t _odp_queue_create(const char *name, odp_queue_type_t type, + odp_queue_param_t *param, uint32_t hw_queue); + #ifdef __cplusplus } #endif diff --git a/platform/linux-keystone2/source/odp_buffer_pool.c b/platform/linux-keystone2/source/odp_buffer_pool.c index fe39fad..5170433 100644 --- a/platform/linux-keystone2/source/odp_buffer_pool.c +++ b/platform/linux-keystone2/source/odp_buffer_pool.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -218,10 +219,7 @@ static int link_bufs(pool_entry_t *pool) &tag); odp_sync_stores(); - ti_em_osal_hw_queue_push_size(pool->s.free_queue, - (void*)hdr, - sizeof(Cppi_HostDesc), - TI_EM_MEM_PUBLIC_DESC); + _ti_hw_queue_push_desc(pool->s.free_queue, hdr); buf_addr.v += buf_size; buf_addr.p += buf_size; desc_index++; @@ -303,10 +301,7 @@ odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_id) void odp_buffer_free(odp_buffer_t buf) { odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf); - ti_em_osal_hw_queue_push_size(hdr->free_queue, - (void*)hdr, - sizeof(Cppi_HostDesc), - TI_EM_MEM_PUBLIC_DESC); + _ti_hw_queue_push_desc(hdr->free_queue, hdr); } void odp_buffer_pool_print(odp_buffer_pool_t pool_id) diff --git a/platform/linux-keystone2/source/odp_queue.c b/platform/linux-keystone2/source/odp_queue.c index 7c1fffe..a8768c2 100644 --- a/platform/linux-keystone2/source/odp_queue.c +++ b/platform/linux-keystone2/source/odp_queue.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,12 @@ int odp_queue_init_global(void) queue_entry_t *queue = get_qentry(i); LOCK_INIT(&queue->s.lock); queue->s.handle = queue_from_id(i); + queue->s.status = QUEUE_STATUS_FREE; + /* + * TODO: HW queue is mapped dirrectly to queue_entry_t + * instance. It may worth to allocate HW queue on open. + */ + queue->s.hw_queue = TI_ODP_PUBLIC_QUEUE_BASE_IDX + i; } ODP_DBG("done\n"); @@ -132,8 +139,8 @@ odp_queue_type_t odp_queue_type(odp_queue_t handle) return queue->s.type; } -odp_queue_t odp_queue_create(const char *name, odp_queue_type_t type, - odp_queue_param_t *param) +odp_queue_t _odp_queue_create(const char *name, odp_queue_type_t type, + odp_queue_param_t *param, uint32_t hw_queue) { uint32_t i; queue_entry_t *queue; @@ -147,6 +154,18 @@ odp_queue_t odp_queue_create(const char *name, odp_queue_type_t type, LOCK(&queue->s.lock); if (queue->s.status == QUEUE_STATUS_FREE) { + if (hw_queue) + queue->s.hw_queue = hw_queue; + /* + * Don't open hw queue if its number is specified + * as it is most probably opened by Linux kernel + */ + else if (ti_em_osal_hw_queue_open(queue->s.hw_queue) + != EM_OK) { + UNLOCK(&queue->s.lock); + continue; + } + queue_init(queue, name, type, param); if (type == ODP_QUEUE_TYPE_SCHED || @@ -179,6 +198,12 @@ odp_queue_t odp_queue_create(const char *name, odp_queue_type_t type, return handle; } +odp_queue_t odp_queue_create(const char *name, odp_queue_type_t type, + odp_queue_param_t *param) +{ + return _odp_queue_create(name, type, param, 0); +} + odp_buffer_t queue_sched_buf(odp_queue_t handle) { @@ -223,65 +248,51 @@ odp_queue_t odp_queue_lookup(const char *name) int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) { - int sched = 0; + _ti_hw_queue_push_desc(queue->s.hw_queue, buf_hdr); - LOCK(&queue->s.lock); - if (queue->s.head == NULL) { - /* Empty queue */ - queue->s.head = buf_hdr; - queue->s.tail = buf_hdr; - buf_hdr->next = NULL; - } else { - queue->s.tail->next = buf_hdr; - queue->s.tail = buf_hdr; - buf_hdr->next = NULL; - } - - if (queue->s.status == QUEUE_STATUS_NOTSCHED) { - queue->s.status = QUEUE_STATUS_SCHED; - sched = 1; /* retval: schedule queue */ + if (queue->s.type == ODP_QUEUE_TYPE_SCHED) { + int sched = 0; + LOCK(&queue->s.lock); + if (queue->s.status == QUEUE_STATUS_NOTSCHED) { + queue->s.status = QUEUE_STATUS_SCHED; + sched = 1; + } + UNLOCK(&queue->s.lock); + /* Add queue to scheduling */ + if (sched) + odp_schedule_queue(queue->s.handle, + queue->s.param.sched.prio); } - UNLOCK(&queue->s.lock); - - /* Add queue to scheduling */ - if (sched == 1) - odp_schedule_queue(queue->s.handle, queue->s.param.sched.prio); - return 0; } int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { - int sched = 0; int i; - odp_buffer_hdr_t *tail; - for (i = 0; i < num - 1; i++) - buf_hdr[i]->next = buf_hdr[i+1]; - - tail = buf_hdr[num-1]; - buf_hdr[num-1]->next = NULL; - - LOCK(&queue->s.lock); - /* Empty queue */ - if (queue->s.head == NULL) - queue->s.head = buf_hdr[0]; - else - queue->s.tail->next = buf_hdr[0]; - - queue->s.tail = tail; - - if (queue->s.status == QUEUE_STATUS_NOTSCHED) { - queue->s.status = QUEUE_STATUS_SCHED; - sched = 1; /* retval: schedule queue */ + /* + * TODO: Should this series of buffers be enqueued atomically? + * Can another buffer be pushed in this queue in the middle? + */ + for (i = 0; i < num; i++) { + /* TODO: Implement multi dequeue a lower level */ + _ti_hw_queue_push_desc(queue->s.hw_queue, buf_hdr[i]); } - UNLOCK(&queue->s.lock); - - /* Add queue to scheduling */ - if (sched == 1) - odp_schedule_queue(queue->s.handle, queue->s.param.sched.prio); + if (queue->s.type == ODP_QUEUE_TYPE_SCHED) { + int sched = 0; + LOCK(&queue->s.lock); + if (queue->s.status == QUEUE_STATUS_NOTSCHED) { + queue->s.status = QUEUE_STATUS_SCHED; + sched = 1; + } + UNLOCK(&queue->s.lock); + /* Add queue to scheduling */ + if (sched) + odp_schedule_queue(queue->s.handle, + queue->s.param.sched.prio); + } return 0; } @@ -318,63 +329,41 @@ int odp_queue_enq(odp_queue_t handle, odp_buffer_t buf) odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) { - odp_buffer_hdr_t *buf_hdr = NULL; + odp_buffer_hdr_t *buf_hdr; - LOCK(&queue->s.lock); + buf_hdr = (odp_buffer_hdr_t *)ti_em_osal_hw_queue_pop(queue->s.hw_queue, + TI_EM_MEM_PUBLIC_DESC); - if (queue->s.head == NULL) { - /* Already empty queue */ - if (queue->s.status == QUEUE_STATUS_SCHED && - queue->s.type != ODP_QUEUE_TYPE_PKTIN) + if (!buf_hdr && queue->s.type == ODP_QUEUE_TYPE_SCHED) { + LOCK(&queue->s.lock); + if (!buf_hdr && queue->s.status == QUEUE_STATUS_SCHED) queue->s.status = QUEUE_STATUS_NOTSCHED; - } else { - buf_hdr = queue->s.head; - queue->s.head = buf_hdr->next; - buf_hdr->next = NULL; - - if (queue->s.head == NULL) { - /* Queue is now empty */ - queue->s.tail = NULL; - } + UNLOCK(&queue->s.lock); } - UNLOCK(&queue->s.lock); - return buf_hdr; } int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) { - int i = 0; - - LOCK(&queue->s.lock); - - if (queue->s.head == NULL) { - /* Already empty queue */ - if (queue->s.status == QUEUE_STATUS_SCHED && - queue->s.type != ODP_QUEUE_TYPE_PKTIN) - queue->s.status = QUEUE_STATUS_NOTSCHED; - } else { - odp_buffer_hdr_t *hdr = queue->s.head; - - for (; i < num && hdr; i++) { - buf_hdr[i] = hdr; - /* odp_prefetch(hdr->addr); */ - hdr = hdr->next; - buf_hdr[i]->next = NULL; - } - - queue->s.head = hdr; - - if (hdr == NULL) { - /* Queue is now empty */ - queue->s.tail = NULL; + int i; + for (i = 0; i < num; i++) { + /* TODO: Implement multi dequeue a lower level */ + buf_hdr[i] = (odp_buffer_hdr_t *)ti_em_osal_hw_queue_pop( + queue->s.hw_queue, + TI_EM_MEM_PUBLIC_DESC); + if (!buf_hdr[i]) { + if (queue->s.type != ODP_QUEUE_TYPE_SCHED) + break; + LOCK(&queue->s.lock); + if (queue->s.status == QUEUE_STATUS_SCHED) + queue->s.status = QUEUE_STATUS_NOTSCHED; + UNLOCK(&queue->s.lock); + break; } } - UNLOCK(&queue->s.lock); - return i; }