From patchwork Fri Mar 9 18:24:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 35892 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 030E0AAD0; Fri, 9 Mar 2018 19:24:51 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2CC87726F for ; Fri, 9 Mar 2018 19:24:45 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2018 10:24:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,446,1515484800"; d="scan'208";a="181382288" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga004.jf.intel.com with ESMTP; 09 Mar 2018 10:24:43 -0800 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, Kevin Laatz Date: Fri, 9 Mar 2018 18:24:03 +0000 Message-Id: <20180309182426.135278-15-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180309182426.135278-1-jasvinder.singh@intel.com> References: <20180309182426.135278-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH 14/37] ip_pipeline: add software queue object X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add swq object implementation to the application. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh Signed-off-by: Kevin Laatz --- examples/ip_pipeline/Makefile | 1 + examples/ip_pipeline/cli.c | 55 +++++++++++++++++++++++++++++ examples/ip_pipeline/main.c | 8 +++++ examples/ip_pipeline/meson.build | 1 + examples/ip_pipeline/swq.c | 74 ++++++++++++++++++++++++++++++++++++++++ examples/ip_pipeline/swq.h | 37 ++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 examples/ip_pipeline/swq.c create mode 100644 examples/ip_pipeline/swq.h diff --git a/examples/ip_pipeline/Makefile b/examples/ip_pipeline/Makefile index 3dab932..0dc8442 100644 --- a/examples/ip_pipeline/Makefile +++ b/examples/ip_pipeline/Makefile @@ -11,6 +11,7 @@ SRCS-y += link.c SRCS-y += main.c SRCS-y += mempool.c SRCS-y += parser.c +SRCS-y += swq.c #SRCS-y += thread.c # Build using pkg-config variables if possible diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c index 385470d..8e78a40 100644 --- a/examples/ip_pipeline/cli.c +++ b/examples/ip_pipeline/cli.c @@ -13,6 +13,7 @@ #include "link.h" #include "mempool.h" #include "parser.h" +#include "swq.h" #ifndef CMD_MAX_TOKENS #define CMD_MAX_TOKENS 256 @@ -227,6 +228,55 @@ cmd_link(char **tokens, } } +/** + * swq + * size + * cpu + */ +static void +cmd_swq(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct swq_params p; + char *name; + struct swq *swq; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + name = tokens[1]; + + if (strcmp(tokens[2], "size") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size"); + return; + } + + if (parser_read_uint32(&p.size, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "size"); + return; + } + + if (strcmp(tokens[4], "cpu") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu"); + return; + } + + if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id"); + return; + } + + swq = swq_create(name, &p); + if (swq == NULL) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + void cli_process(char *in, char *out, size_t out_size) { @@ -256,6 +306,11 @@ cli_process(char *in, char *out, size_t out_size) return; } + if (strcmp(tokens[0], "swq") == 0) { + cmd_swq(tokens, n_tokens, out, out_size); + return; + } + snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); } diff --git a/examples/ip_pipeline/main.c b/examples/ip_pipeline/main.c index edfb523..456f016 100644 --- a/examples/ip_pipeline/main.c +++ b/examples/ip_pipeline/main.c @@ -14,6 +14,7 @@ #include "conn.h" #include "link.h" #include "mempool.h" +#include "swq.h" static const char usage[] = "%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n"; @@ -175,6 +176,13 @@ main(int argc, char **argv) return status; } + /* SWQ */ + status = swq_init(); + if (status) { + printf("Error: SWQ initialization failed (%d)\n", status); + return status; + } + /* Script */ if (app.script_name) cli_script_process(app.script_name, diff --git a/examples/ip_pipeline/meson.build b/examples/ip_pipeline/meson.build index a2f9bb6..442f3e3 100644 --- a/examples/ip_pipeline/meson.build +++ b/examples/ip_pipeline/meson.build @@ -14,4 +14,5 @@ sources = files( 'main.c', 'mempool.c', 'parser.c', + 'swq.c', ) diff --git a/examples/ip_pipeline/swq.c b/examples/ip_pipeline/swq.c new file mode 100644 index 0000000..c11bbf2 --- /dev/null +++ b/examples/ip_pipeline/swq.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include +#include + +#include "swq.h" + +static struct swq_list swq_list; + +int +swq_init(void) +{ + TAILQ_INIT(&swq_list); + + return 0; +} + +struct swq * +swq_find(const char *name) +{ + struct swq *swq; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(swq, &swq_list, node) + if (strcmp(swq->name, name) == 0) + return swq; + + return NULL; +} + +struct swq * +swq_create(const char *name, struct swq_params *params) +{ + struct swq *swq; + struct rte_ring *r; + unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ; + + /* Check input params */ + if ((name == NULL) || + swq_find(name) || + (params == NULL) || + (params->size == 0)) + return NULL; + + /* Resource create */ + r = rte_ring_create( + name, + params->size, + params->cpu_id, + flags); + + if (r == NULL) + return NULL; + + /* Node allocation */ + swq = calloc(1, sizeof(struct swq)); + if (swq == NULL) { + rte_ring_free(r); + return NULL; + } + + /* Node fill in */ + strncpy(swq->name, name, sizeof(swq->name)); + swq->r = r; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&swq_list, swq, node); + + return swq; +} diff --git a/examples/ip_pipeline/swq.h b/examples/ip_pipeline/swq.h new file mode 100644 index 0000000..c8440ee --- /dev/null +++ b/examples/ip_pipeline/swq.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#ifndef _INCLUDE_SWQ_H_ +#define _INCLUDE_SWQ_H_ + +#include +#include + +#include + +#include "common.h" + +struct swq { + TAILQ_ENTRY(swq) node; + char name[NAME_SIZE]; + struct rte_ring *r; +}; + +TAILQ_HEAD(swq_list, swq); + +int +swq_init(void); + +struct swq * +swq_find(const char *name); + +struct swq_params { + uint32_t size; + uint32_t cpu_id; +}; + +struct swq * +swq_create(const char *name, struct swq_params *params); + +#endif /* _INCLUDE_SWQ_H_ */