From patchwork Fri Mar 9 18:24:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 35890 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 A0AB8AAC7; Fri, 9 Mar 2018 19:24:48 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 6F384726F for ; Fri, 9 Mar 2018 19:24:43 +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:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,446,1515484800"; d="scan'208";a="181382263" 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:41 -0800 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, Fan Zhang Date: Fri, 9 Mar 2018 18:24:01 +0000 Message-Id: <20180309182426.135278-13-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 12/37] ip_pipeline: add mempool object for pipeline 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 mempool object implementation to the application. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh Signed-off-by: Fan Zhang --- examples/ip_pipeline/Makefile | 1 + examples/ip_pipeline/cli.c | 109 ++++++++++++++++++++++++++++++++++++++- examples/ip_pipeline/common.h | 12 +++++ examples/ip_pipeline/main.c | 8 +++ examples/ip_pipeline/mempool.c | 81 +++++++++++++++++++++++++++++ examples/ip_pipeline/mempool.h | 40 ++++++++++++++ examples/ip_pipeline/meson.build | 1 + 7 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 examples/ip_pipeline/common.h create mode 100644 examples/ip_pipeline/mempool.c create mode 100644 examples/ip_pipeline/mempool.h diff --git a/examples/ip_pipeline/Makefile b/examples/ip_pipeline/Makefile index 0c5b6b1..fca28c5 100644 --- a/examples/ip_pipeline/Makefile +++ b/examples/ip_pipeline/Makefile @@ -8,6 +8,7 @@ APP = ip_pipeline SRCS-y := cli.c SRCS-y += conn.c SRCS-y += main.c +SRCS-y += mempool.c SRCS-y += parser.c #SRCS-y += thread.c diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c index 3e97b29..1c67749 100644 --- a/examples/ip_pipeline/cli.c +++ b/examples/ip_pipeline/cli.c @@ -10,6 +10,23 @@ #include #include "cli.h" +#include "mempool.h" +#include "parser.h" + +#ifndef CMD_MAX_TOKENS +#define CMD_MAX_TOKENS 256 +#endif + +#define MSG_OUT_OF_MEMORY "Not enough memory.\n" +#define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n" +#define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n" +#define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n" +#define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n" +#define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n" +#define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n" +#define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n" +#define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n" +#define MSG_CMD_FAIL "Command \"%s\" failed.\n" static int is_comment(char *in) @@ -22,12 +39,102 @@ is_comment(char *in) return 0; } +/** + * mempool + * buffer + * pool + * cache + * cpu + */ +static void +cmd_mempool(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct mempool_params p; + char *name; + struct mempool *mempool; + + if (n_tokens != 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + name = tokens[1]; + + if (strcmp(tokens[2], "buffer") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer"); + return; + } + + if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size"); + return; + } + + if (strcmp(tokens[4], "pool") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool"); + return; + } + + if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "pool_size"); + return; + } + + if (strcmp(tokens[6], "cache") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache"); + return; + } + + if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "cache_size"); + return; + } + + if (strcmp(tokens[8], "cpu") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu"); + return; + } + + if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id"); + return; + } + + mempool = mempool_create(name, &p); + if (mempool == NULL) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + void -cli_process(char *in, char *out __rte_unused, size_t out_size __rte_unused) +cli_process(char *in, char *out, size_t out_size) { + char *tokens[CMD_MAX_TOKENS]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; + if (is_comment(in)) return; + status = parse_tokenize_string(in, tokens, &n_tokens); + if (status) { + snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); + return; + } + + if (n_tokens == 0) + return; + + if (strcmp(tokens[0], "mempool") == 0) { + cmd_mempool(tokens, n_tokens, out, out_size); + return; + } + + snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); } int diff --git a/examples/ip_pipeline/common.h b/examples/ip_pipeline/common.h new file mode 100644 index 0000000..0886dfb --- /dev/null +++ b/examples/ip_pipeline/common.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#ifndef _INCLUDE_COMMON_H_ +#define _INCLUDE_COMMON_H_ + +#ifndef NAME_SIZE +#define NAME_SIZE 64 +#endif + +#endif /* _INCLUDE_COMMON_H_ */ diff --git a/examples/ip_pipeline/main.c b/examples/ip_pipeline/main.c index 60936f4..b53f623 100644 --- a/examples/ip_pipeline/main.c +++ b/examples/ip_pipeline/main.c @@ -12,6 +12,7 @@ #include "cli.h" #include "conn.h" +#include "mempool.h" static const char usage[] = "%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n"; @@ -159,6 +160,13 @@ main(int argc, char **argv) return status; }; + /* Mempool */ + status = mempool_init(); + if (status) { + printf("Error: Mempool initialization failed (%d)\n", status); + return status; + } + /* Script */ if (app.script_name) cli_script_process(app.script_name, diff --git a/examples/ip_pipeline/mempool.c b/examples/ip_pipeline/mempool.c new file mode 100644 index 0000000..33b9243 --- /dev/null +++ b/examples/ip_pipeline/mempool.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include +#include + +#include + +#include "mempool.h" + +#define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM) + +static struct mempool_list mempool_list; + +int +mempool_init(void) +{ + TAILQ_INIT(&mempool_list); + + return 0; +} + +struct mempool * +mempool_find(const char *name) +{ + struct mempool *mempool; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(mempool, &mempool_list, node) + if (strcmp(mempool->name, name) == 0) + return mempool; + + return NULL; +} + +struct mempool * +mempool_create(const char *name, struct mempool_params *params) +{ + struct mempool *mempool; + struct rte_mempool *m; + + /* Check input params */ + if ((name == NULL) || + mempool_find(name) || + (params == NULL) || + (params->buffer_size < BUFFER_SIZE_MIN) || + (params->pool_size == 0)) + return NULL; + + /* Resource create */ + m = rte_pktmbuf_pool_create( + name, + params->pool_size, + params->cache_size, + 0, + params->buffer_size - sizeof(struct rte_mbuf), + params->cpu_id); + + if (m == NULL) + return NULL; + + /* Node allocation */ + mempool = calloc(1, sizeof(struct mempool)); + if (mempool == NULL) { + rte_mempool_free(m); + return NULL; + } + + /* Node fill in */ + strncpy(mempool->name, name, sizeof(mempool->name)); + mempool->m = m; + mempool->buffer_size = params->buffer_size; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&mempool_list, mempool, node); + + return mempool; +} diff --git a/examples/ip_pipeline/mempool.h b/examples/ip_pipeline/mempool.h new file mode 100644 index 0000000..bd46a11 --- /dev/null +++ b/examples/ip_pipeline/mempool.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#ifndef _INCLUDE_MEMPOOL_H_ +#define _INCLUDE_MEMPOOL_H_ + +#include +#include + +#include + +#include "common.h" + +struct mempool { + TAILQ_ENTRY(mempool) node; + char name[NAME_SIZE]; + struct rte_mempool *m; + uint32_t buffer_size; +}; + +TAILQ_HEAD(mempool_list, mempool); + +int +mempool_init(void); + +struct mempool * +mempool_find(const char *name); + +struct mempool_params { + uint32_t buffer_size; + uint32_t pool_size; + uint32_t cache_size; + uint32_t cpu_id; +}; + +struct mempool * +mempool_create(const char *name, struct mempool_params *params); + +#endif /* _INCLUDE_MEMPOOL_H_ */ diff --git a/examples/ip_pipeline/meson.build b/examples/ip_pipeline/meson.build index a89cb30..f8a450f 100644 --- a/examples/ip_pipeline/meson.build +++ b/examples/ip_pipeline/meson.build @@ -11,5 +11,6 @@ sources = files( 'cli.c', 'conn.c', 'main.c', + 'mempool.c', 'parser.c', )