From: Rakesh Kudurumalla <rkuduruma...@marvell.com>

Adds mempool module which will be creating mempools.

Following commands are exposed:
 - mempool <mempool_name> size <mbuf_size> buffers <number_of_buffers> \
        cache <cache_size> numa <numa_id>
 - help mempool

User will add this command in .cli file according to its need.

Signed-off-by: Sunil Kumar Kori <sk...@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkuduruma...@marvell.com>
Acked-by: Jerin Jacob <jer...@marvell.com>
---
 app/graph/cli.c            |   2 +
 app/graph/mempool.c        | 140 +++++++++++++++++++++++++++++++++++++
 app/graph/mempool.h        |  24 +++++++
 app/graph/mempool_priv.h   |  34 +++++++++
 app/graph/meson.build      |   1 +
 app/graph/module_api.h     |   2 +
 doc/guides/tools/graph.rst |   7 ++
 7 files changed, 210 insertions(+)
 create mode 100644 app/graph/mempool.c
 create mode 100644 app/graph/mempool.h
 create mode 100644 app/graph/mempool_priv.h

diff --git a/app/graph/cli.c b/app/graph/cli.c
index df4f8fcbb8..cf544d5f8f 100644
--- a/app/graph/cli.c
+++ b/app/graph/cli.c
@@ -20,6 +20,8 @@
 #define MAX_LINE_SIZE 2048
 
 cmdline_parse_ctx_t modules_ctx[] = {
+       (cmdline_parse_inst_t *)&mempool_config_cmd_ctx,
+       (cmdline_parse_inst_t *)&mempool_help_cmd_ctx,
        NULL,
 };
 
diff --git a/app/graph/mempool.c b/app/graph/mempool.c
new file mode 100644
index 0000000000..9fd3f8460b
--- /dev/null
+++ b/app/graph/mempool.c
@@ -0,0 +1,140 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Marvell.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <cmdline_parse.h>
+#include <cmdline_parse_num.h>
+#include <cmdline_parse_string.h>
+#include <cmdline_socket.h>
+#include <rte_common.h>
+#include <rte_mbuf.h>
+
+#include "mempool_priv.h"
+#include "module_api.h"
+
+static const char
+cmd_mempool_help[] = "mempool <mempool_name> size <mbuf_size> buffers 
<number_of_buffers> "
+                    "cache <cache_size> numa <numa_id>";
+
+struct mempools mpconfig;
+
+int
+mempool_process(struct mempool_config *config)
+{
+       struct rte_mempool *mp;
+       uint8_t nb_pools;
+
+       nb_pools = mpconfig.nb_pools;
+       rte_strscpy(mpconfig.config[nb_pools].name, config->name, 
RTE_MEMPOOL_NAMESIZE);
+       mpconfig.config[nb_pools].pool_size = config->pool_size;
+       mpconfig.config[nb_pools].buffer_size = config->buffer_size;
+       mpconfig.config[nb_pools].cache_size = config->cache_size;
+       mpconfig.config[nb_pools].numa_node = config->numa_node;
+
+       mp = rte_pktmbuf_pool_create(config->name, config->pool_size, 
config->cache_size,
+               128, config->buffer_size, config->numa_node);
+       if (!mp)
+               return -EINVAL;
+
+       mpconfig.mp[nb_pools] = mp;
+       nb_pools++;
+       mpconfig.nb_pools = nb_pools;
+
+       return 0;
+}
+
+static void
+cli_mempool_help(__rte_unused void *parsed_result, __rte_unused struct cmdline 
*cl,
+                __rte_unused void *data)
+{
+       size_t len;
+
+       len = strlen(conn->msg_out);
+       conn->msg_out += len;
+       snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n",
+                "----------------------------- mempool command help 
-----------------------------",
+                cmd_mempool_help);
+
+       len = strlen(conn->msg_out);
+       conn->msg_out_len_max -= len;
+}
+
+static void
+cli_mempool(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused 
void *data)
+{
+       struct mempool_config_cmd_tokens *res = parsed_result;
+       struct mempool_config config;
+       int rc = -EINVAL;
+
+
+       rte_strscpy(config.name, res->name, RTE_MEMPOOL_NAMESIZE);
+       config.name[strlen(res->name)] = '\0';
+       config.pool_size = res->nb_bufs;
+       config.buffer_size = res->buf_sz;
+       config.cache_size = res->cache_size;
+       config.numa_node = res->node;
+
+       rc = mempool_process(&config);
+       if (rc < 0)
+               printf(MSG_CMD_FAIL, "mempool");
+}
+
+cmdline_parse_token_string_t mempool_config_add_mempool =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, mempool, 
"mempool");
+cmdline_parse_token_string_t mempool_config_add_name =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, name, NULL);
+cmdline_parse_token_string_t mempool_config_add_size =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, size, 
"size");
+cmdline_parse_token_num_t mempool_config_add_buf_sz =
+       TOKEN_NUM_INITIALIZER(struct mempool_config_cmd_tokens, buf_sz, 
RTE_UINT16);
+cmdline_parse_token_string_t mempool_config_add_buffers =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, buffers, 
"buffers");
+cmdline_parse_token_num_t mempool_config_add_nb_bufs =
+       TOKEN_NUM_INITIALIZER(struct mempool_config_cmd_tokens, nb_bufs, 
RTE_UINT16);
+cmdline_parse_token_string_t mempool_config_add_cache =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, cache, 
"cache");
+cmdline_parse_token_num_t mempool_config_add_cache_size =
+       TOKEN_NUM_INITIALIZER(struct mempool_config_cmd_tokens, cache_size, 
RTE_UINT16);
+cmdline_parse_token_string_t mempool_config_add_numa =
+       TOKEN_STRING_INITIALIZER(struct mempool_config_cmd_tokens, numa, 
"numa");
+cmdline_parse_token_num_t mempool_config_add_node =
+       TOKEN_NUM_INITIALIZER(struct mempool_config_cmd_tokens, node, 
RTE_UINT16);
+
+cmdline_parse_inst_t mempool_config_cmd_ctx = {
+       .f = cli_mempool,
+       .data = NULL,
+       .help_str = cmd_mempool_help,
+       .tokens = {
+               (void *)&mempool_config_add_mempool,
+               (void *)&mempool_config_add_name,
+               (void *)&mempool_config_add_size,
+               (void *)&mempool_config_add_buf_sz,
+               (void *)&mempool_config_add_buffers,
+               (void *)&mempool_config_add_nb_bufs,
+               (void *)&mempool_config_add_cache,
+               (void *)&mempool_config_add_cache_size,
+               (void *)&mempool_config_add_numa,
+               (void *)&mempool_config_add_node,
+               NULL,
+       },
+};
+
+cmdline_parse_token_string_t mempool_help_cmd =
+       TOKEN_STRING_INITIALIZER(struct mempool_help_cmd_tokens, help, "help");
+cmdline_parse_token_string_t mempool_help_mempool =
+       TOKEN_STRING_INITIALIZER(struct mempool_help_cmd_tokens, mempool, 
"mempool");
+
+cmdline_parse_inst_t mempool_help_cmd_ctx = {
+       .f = cli_mempool_help,
+       .data = NULL,
+       .help_str = "",
+       .tokens = {
+               (void *)&mempool_help_cmd,
+               (void *)&mempool_help_mempool,
+               NULL,
+       },
+};
diff --git a/app/graph/mempool.h b/app/graph/mempool.h
new file mode 100644
index 0000000000..0808c4259e
--- /dev/null
+++ b/app/graph/mempool.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Marvell.
+ */
+
+#ifndef APP_GRAPH_MEMPOOL_H
+#define APP_GRAPH_MEMPOOL_H
+
+#include <cmdline_parse.h>
+#include <rte_mempool.h>
+
+struct mempool_config {
+       char name[RTE_MEMPOOL_NAMESIZE];
+       int pool_size;
+       int cache_size;
+       int buffer_size;
+       int numa_node;
+};
+
+extern cmdline_parse_inst_t mempool_config_cmd_ctx;
+extern cmdline_parse_inst_t mempool_help_cmd_ctx;
+
+int mempool_process(struct mempool_config *config);
+
+#endif
diff --git a/app/graph/mempool_priv.h b/app/graph/mempool_priv.h
new file mode 100644
index 0000000000..3ce64702a9
--- /dev/null
+++ b/app/graph/mempool_priv.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Marvell.
+ */
+
+#ifndef APP_GRAPH_MEMPOOL_PRIV_H
+#define APP_GRAPH_MEMPOOL_PRIV_H
+
+#include "mempool.h"
+
+struct mempool_config_cmd_tokens {
+       cmdline_fixed_string_t mempool;
+       cmdline_fixed_string_t size;
+       cmdline_fixed_string_t buffers;
+       cmdline_fixed_string_t cache;
+       cmdline_fixed_string_t numa;
+       cmdline_fixed_string_t name;
+       uint16_t buf_sz;
+       uint16_t nb_bufs;
+       uint16_t cache_size;
+       uint16_t node;
+};
+
+struct mempool_help_cmd_tokens {
+       cmdline_fixed_string_t help;
+       cmdline_fixed_string_t mempool;
+};
+
+struct mempools {
+       struct mempool_config config[RTE_MAX_ETHPORTS];
+       struct rte_mempool *mp[RTE_MAX_ETHPORTS];
+       uint8_t nb_pools;
+};
+
+#endif
diff --git a/app/graph/meson.build b/app/graph/meson.build
index fd71036a95..5dc23c875b 100644
--- a/app/graph/meson.build
+++ b/app/graph/meson.build
@@ -13,5 +13,6 @@ sources = files(
         'cli.c',
         'conn.c',
         'main.c',
+        'mempool.c',
         'utils.c',
 )
diff --git a/app/graph/module_api.h b/app/graph/module_api.h
index ad4fb50989..b45419811b 100644
--- a/app/graph/module_api.h
+++ b/app/graph/module_api.h
@@ -10,11 +10,13 @@
 
 #include "cli.h"
 #include "conn.h"
+#include "mempool.h"
 #include "utils.h"
 /*
  * Externs
  */
 extern volatile bool force_quit;
+extern struct conn *conn;
 
 bool app_graph_exit(void);
 #endif
diff --git a/doc/guides/tools/graph.rst b/doc/guides/tools/graph.rst
index 943f915049..6009b0c291 100644
--- a/doc/guides/tools/graph.rst
+++ b/doc/guides/tools/graph.rst
@@ -71,6 +71,13 @@ file to express the requested use case configuration.
    
+--------------------------------------+-----------------------------------+---------+----------+
    |               Command                |             Description           
| Dynamic | Optional |
    
+======================================+===================================+=========+==========+
+   | | mempool <mempool_name> size        | | Command to create mempool which 
|   No    |    No    |
+   | | <mbuf_size> buffers                | | will be further associated to   
|         |          |
+   | | <number_of_buffers>                | | RxQ to dequeue the packets.     
|         |          |
+   | | cache <cache_size> numa <numa_id>  |                                   
|         |          |
+   
+--------------------------------------+-----------------------------------+---------+----------+
+   | help mempool                         | | Command to dump mempool help    
|   Yes   |    Yes   |
+   |                                      | | message.                        
|         |          |
    |                                      |                                   
|         |          |
    
+--------------------------------------+-----------------------------------+---------+----------+
 
-- 
2.25.1

Reply via email to