From patchwork Thu Apr 17 11:56:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 28563 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 585C720674 for ; Thu, 17 Apr 2014 11:57:51 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f10sf1130175yha.7 for ; Thu, 17 Apr 2014 04:57:51 -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=DblHAdZTMNg9lNAlxd70MTYIWpFtL8CMPTsVj5WXdEw=; b=DCUFMwLDQgAZwuLC/zsm9wKK0SukrsugPdjkE4YczO0mFt+rjb4SfRp1iAGLj50IWl FIAmKT1ZgOkI7c8sWlVllFftHpLAhiLgcX9HnITV7g06EXtEH/tCP5wbwkTMqUoMFFnB /bEZ6bfVMezzHohRtT8zhkkmfrO8y+agynnYOmY5UJOK+hG9E+Zotc3IKZ2ejdHglYsI bjHt2D7b/exagnc8RaLpY8NxSNt/iufK7aKFnkUtft4XC9nIbl5iBypQjNOEdwHHQQ4h E4WPA12jk3LHWTkOatekGtvnA8aMQiWhCDDpZw01EZC+Dk7WRgDpqke5kd+DzKQ14XZx qyfg== X-Gm-Message-State: ALoCoQk/2hVQJCxe5Hl7TtCAmK+jf2YH563MGcsruvezN6m/ZJ2MZUnumN7dTTDp2XxpW1zzkdpZ X-Received: by 10.236.43.14 with SMTP id k14mr5624413yhb.37.1397735871053; Thu, 17 Apr 2014 04:57:51 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.200 with SMTP id x66ls1033773qgx.46.gmail; Thu, 17 Apr 2014 04:57:50 -0700 (PDT) X-Received: by 10.58.171.229 with SMTP id ax5mr7581244vec.24.1397735870916; Thu, 17 Apr 2014 04:57:50 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id u1si4411936vcs.86.2014.04.17.04.57.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Apr 2014 04:57:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 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.177; Received: by mail-vc0-f177.google.com with SMTP id if17so354279vcb.8 for ; Thu, 17 Apr 2014 04:57:50 -0700 (PDT) X-Received: by 10.58.202.106 with SMTP id kh10mr974554vec.31.1397735870831; Thu, 17 Apr 2014 04:57:50 -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 ib8csp29033vcb; Thu, 17 Apr 2014 04:57:50 -0700 (PDT) X-Received: by 10.224.13.7 with SMTP id z7mr12082917qaz.4.1397735870411; Thu, 17 Apr 2014 04:57:50 -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 u12si92497qge.94.2014.04.17.04.57.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 17 Apr 2014 04:57:50 -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 1Wakwj-00068Y-91; Thu, 17 Apr 2014 11:57:37 +0000 Received: from mail-ee0-f46.google.com ([74.125.83.46]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wakvp-00064m-7z for lng-odp@lists.linaro.org; Thu, 17 Apr 2014 11:56:41 +0000 Received: by mail-ee0-f46.google.com with SMTP id t10so567047eei.5 for ; Thu, 17 Apr 2014 04:56:47 -0700 (PDT) X-Received: by 10.15.53.135 with SMTP id r7mr1474356eew.102.1397735807464; Thu, 17 Apr 2014 04:56:47 -0700 (PDT) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id z48sm66742553eel.27.2014.04.17.04.56.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Apr 2014 04:56:46 -0700 (PDT) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Thu, 17 Apr 2014 14:56:20 +0300 Message-Id: <1397735782-31924-10-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1397735782-31924-1-git-send-email-taras.kondratiuk@linaro.org> References: <1397735782-31924-1-git-send-email-taras.kondratiuk@linaro.org> Cc: Filip Moerman Subject: [lng-odp] [PATCH v2 09/11] 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.177 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 ee29b41..de837d8 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 7e10689..9a2f6cb 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; }