From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2093642AA0; Tue, 9 May 2023 08:10:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EDE6B410FA; Tue, 9 May 2023 08:10:09 +0200 (CEST) Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) by mails.dpdk.org (Postfix) with ESMTP id 0586E410D7 for ; Tue, 9 May 2023 08:10:07 +0200 (CEST) Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-77d0419750eso1381138241.2 for ; Mon, 08 May 2023 23:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683612607; x=1686204607; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kVsHemgKnqx9uGTbkL74puwDLnNgXUAq4cbA8gXNyQc=; b=YGQSVxliJe/vMo86uOb+l/S6DMjXfidF1VDp/y8yUtmfNmtCyD/DzHKCtag6nlXb/O Z9QEcVp+BVeNEUHQXUpsJkdF+5u+A3EpuYt2nsfsbepeKj4H4vb0XSSdxaceEvql2HSG AMruH+LYXim/gMleibcH93pAunhkfrtg6zfH7DMCNBw7uTfjeGB7e717XHBDNndSFatm BNN3+yM/PUnlSZqkxSQlsyrhs0quuHhClg2xre3u0hrPkqhdyOw118KtbGfjTrVyYirR 5ZIHknnQf5yHYVNsS8kS2u53+KdeLZmgRzjUB20F/8sAwEeQCJJwEQChL3kDx/U+nplr lYnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683612607; x=1686204607; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kVsHemgKnqx9uGTbkL74puwDLnNgXUAq4cbA8gXNyQc=; b=IsRWy03jB/dO41Pt+g0n7hxNjMcnuzoVBZmPOk76QfQ8wYbDCADG0S8h8k8j4vYjUi tn6iyNbQkECGDP19KwlgGJuzn+B+P2tj2UBKvIx9AKJC9DjDQRcpSNjZON52SCDK4Mkg EJ7maCSNREE707BXdp9LjhUsU4R2UBmEbQITfO0z5LT+UYexWcVwWPETnPNct+IDBAw4 5gHTqHSnSnFV/bLybkwtuQdWT2K9gUPefHq3xiOW1iOR35XcU504yX4P18iegTHKCZrs aEPA+3il4IBfQqBNMlWyy6P0QIvSWCeyaAj5U2qXr+cEHGKXc2MR5xk8NKLSK7DHKeyK hS5Q== X-Gm-Message-State: AC+VfDwnIHxv+4XZYHUV6SDDPUzvzsVThKYl9WkeekWyn8CQdXRBarjD tMaCA1nkdJ4Cqd03aQUQ0C83ZX55XqlAG8VGkn0= X-Google-Smtp-Source: ACHHUZ54c6uZvuc2YwyBlDbLZ1+T40u/HIklqEwxGE83WlkGyOqjb8ZKG1HwmZAeGcaZU3fxUt7wqdaY/Son5YF2d3E= X-Received: by 2002:a67:f3cb:0:b0:434:6b92:51b1 with SMTP id j11-20020a67f3cb000000b004346b9251b1mr3563096vsn.16.1683612606755; Mon, 08 May 2023 23:10:06 -0700 (PDT) MIME-Version: 1.0 References: <20230421060245.3136217-1-vattunuru@marvell.com> <20230421060245.3136217-5-vattunuru@marvell.com> In-Reply-To: <20230421060245.3136217-5-vattunuru@marvell.com> From: Jerin Jacob Date: Tue, 9 May 2023 11:39:40 +0530 Message-ID: Subject: Re: [PATCH 4/4] app: add testgraph application To: Vamsi Attunuru , Haiyue Wang , "Liang, Cunming" , Zhirun Yan Cc: dev@dpdk.org, jerinj@marvell.com, ndabilpuram@marvell.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Apr 21, 2023 at 11:33=E2=80=AFAM Vamsi Attunuru wrote: > > Patch adds test-graph application to validate graph > and node libraries. > > Signed-off-by: Vamsi Attunuru + haiyue.wang@intel.com cunming.liang@intel.com zhirun.yan@intel.com for review to align with new multi-core dispatch model. > --- > app/meson.build | 1 + > app/test-graph/cmdline.c | 212 ++++++ > app/test-graph/cmdline_graph.c | 297 ++++++++ > app/test-graph/cmdline_graph.h | 19 + > app/test-graph/meson.build | 17 + > app/test-graph/parameters.c | 157 ++++ > app/test-graph/testgraph.c | 1309 ++++++++++++++++++++++++++++++++ > app/test-graph/testgraph.h | 92 +++ > doc/guides/tools/index.rst | 1 + > doc/guides/tools/testgraph.rst | 131 ++++ > 10 files changed, 2236 insertions(+) > > diff --git a/app/meson.build b/app/meson.build > index 74d2420f67..6c7b24e604 100644 > --- a/app/meson.build > +++ b/app/meson.build > @@ -22,6 +22,7 @@ apps =3D [ > 'test-eventdev', > 'test-fib', > 'test-flow-perf', > + 'test-graph', > 'test-gpudev', > 'test-mldev', > 'test-pipeline', > diff --git a/app/test-graph/cmdline.c b/app/test-graph/cmdline.c > new file mode 100644 > index 0000000000..a07a8a24f9 > --- /dev/null > +++ b/app/test-graph/cmdline.c > @@ -0,0 +1,212 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "cmdline_graph.h" > +#include "testgraph.h" > + > +static struct cmdline *testgraph_cl; > +static cmdline_parse_ctx_t *main_ctx; > + > +/* *** Help command with introduction. *** */ > +struct cmd_help_brief_result { > + cmdline_fixed_string_t help; > +}; > + > +static void > +cmd_help_brief_parsed(__rte_unused void *parsed_result, struct cmdline *= cl, __rte_unused void *data) > +{ > + cmdline_printf(cl, > + "\n" > + "Help is available for the following sections:\n\n= " > + " help control : Start and s= top graph walk.\n" > + " help display : Displaying = port, stats and config " > + "information.\n" > + " help config : Configurati= on information.\n" > + " help all : All of the = above sections.\n\n"); > +} > + > +static cmdline_parse_token_string_t cmd_help_brief_help =3D > + TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "hel= p"); > + > +static cmdline_parse_inst_t cmd_help_brief =3D { > + .f =3D cmd_help_brief_parsed, > + .data =3D NULL, > + .help_str =3D "help: Show help", > + .tokens =3D { > + (void *)&cmd_help_brief_help, > + NULL, > + }, > +}; > + > +/* *** Help command with help sections. *** */ > +struct cmd_help_long_result { > + cmdline_fixed_string_t help; > + cmdline_fixed_string_t section; > +}; > + > +static void > +cmd_help_long_parsed(void *parsed_result, struct cmdline *cl, __rte_unus= ed void *data) > +{ > + int show_all =3D 0; > + struct cmd_help_long_result *res =3D parsed_result; > + > + if (!strcmp(res->section, "all")) > + show_all =3D 1; > + > + if (show_all || !strcmp(res->section, "control")) { > + > + cmdline_printf(cl, "\n" > + "Control forwarding:\n" > + "-------------------\n\n" > + > + "start graph_walk\n" > + " Start graph_walk on worker threads.\= n\n" > + > + "stop graph_walk\n" > + " Stop worker threads from running gra= ph_walk.\n\n" > + > + "quit\n" > + " Quit to prompt.\n\n"); > + } > + > + if (show_all || !strcmp(res->section, "display")) { > + > + cmdline_printf(cl, > + "\n" > + "Display:\n" > + "--------\n\n" > + > + "show node_list\n" > + " Display the list of supported nodes.\n\n= " > + > + "show graph_stats\n" > + " Display the node statistics of graph clu= ster.\n\n"); > + } > + > + if (show_all || !strcmp(res->section, "config")) { > + cmdline_printf(cl, "\n" > + "Configuration:\n" > + "--------------\n" > + "set lcore_config (port_id0,rxq0,lcore= _idX),..." > + ".....,(port_idX,rxqX,lcoreidY)\n" > + " Set lcore configuration.\n\n" > + > + "create_graph (node0_name,node1_name,.= ..,nodeX_name)\n" > + " Create graph instances using the pro= vided node details.\n\n" > + > + "destroy_graph\n" > + " Destroy the graph instances.\n\n"); > + } > +} > + > +static cmdline_parse_token_string_t cmd_help_long_help =3D > + TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help= "); > + > +static cmdline_parse_token_string_t cmd_help_long_section =3D TOKEN_STRI= NG_INITIALIZER( > + struct cmd_help_long_result, section, "all#control#display#config= "); > + > +static cmdline_parse_inst_t cmd_help_long =3D { > + .f =3D cmd_help_long_parsed, > + .data =3D NULL, > + .help_str =3D "help all|control|display|config: " > + "Show help", > + .tokens =3D { > + (void *)&cmd_help_long_help, > + (void *)&cmd_help_long_section, > + NULL, > + }, > +}; > + > +/* *** QUIT *** */ > +struct cmd_quit_result { > + cmdline_fixed_string_t quit; > +}; > + > +static void > +cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __= rte_unused void *data) > +{ > + cmdline_quit(cl); > + cl_quit =3D 1; > +} > + > +static cmdline_parse_token_string_t cmd_quit_quit =3D > + TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); > + > +static cmdline_parse_inst_t cmd_quit =3D { > + .f =3D cmd_quit_parsed, > + .data =3D NULL, > + .help_str =3D "quit: Exit application", > + .tokens =3D { > + (void *)&cmd_quit_quit, > + NULL, > + }, > +}; > + > +/* list of instructions */ > +static cmdline_parse_ctx_t builtin_ctx[] =3D { > + (cmdline_parse_inst_t *)&cmd_help_brief, > + (cmdline_parse_inst_t *)&cmd_help_long, > + (cmdline_parse_inst_t *)&cmd_quit, > + (cmdline_parse_inst_t *)&cmd_show_node_list, > + (cmdline_parse_inst_t *)&cmd_set_lcore_config, > + (cmdline_parse_inst_t *)&cmd_create_graph, > + (cmdline_parse_inst_t *)&cmd_destroy_graph, > + (cmdline_parse_inst_t *)&cmd_start_graph_walk, > + (cmdline_parse_inst_t *)&cmd_stop_graph_walk, > + (cmdline_parse_inst_t *)&cmd_show_graph_stats, > + NULL, > +}; > + > +int > +init_cmdline(void) > +{ > + unsigned int count; > + unsigned int i; > + > + count =3D 0; > + for (i =3D 0; builtin_ctx[i] !=3D NULL; i++) > + count++; > + > + /* cmdline expects a NULL terminated array */ > + main_ctx =3D calloc(count + 1, sizeof(main_ctx[0])); > + if (main_ctx =3D=3D NULL) > + return -1; > + > + count =3D 0; > + for (i =3D 0; builtin_ctx[i] !=3D NULL; i++, count++) > + main_ctx[count] =3D builtin_ctx[i]; > + > + return 0; > +} > + > +void > +prompt_exit(void) > +{ > + cmdline_quit(testgraph_cl); > +} > + > +/* prompt function, called from main on MAIN lcore */ > +void > +prompt(void) > +{ > + testgraph_cl =3D cmdline_stdin_new(main_ctx, "testgraph> "); > + if (testgraph_cl =3D=3D NULL) { > + fprintf(stderr, "Failed to create stdin based cmdline con= text\n"); > + return; > + } > + > + cmdline_interact(testgraph_cl); > + cmdline_stdin_exit(testgraph_cl); > +} > diff --git a/app/test-graph/cmdline_graph.c b/app/test-graph/cmdline_grap= h.c > new file mode 100644 > index 0000000000..1c9fd94355 > --- /dev/null > +++ b/app/test-graph/cmdline_graph.c > @@ -0,0 +1,297 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > +#include > + > +#include > +#include > +#include > + > +#include "cmdline_graph.h" > +#include "testgraph.h" > + > +/* *** Show supported node details *** */ > +struct cmd_show_node_list_result { > + cmdline_fixed_string_t show; > + cmdline_fixed_string_t node_list; > +}; > + > +static cmdline_parse_token_string_t cmd_show_node_list_show =3D > + TOKEN_STRING_INITIALIZER(struct cmd_show_node_list_result, show, = "show"); > +static cmdline_parse_token_string_t cmd_show_node_list_node_list =3D > + TOKEN_STRING_INITIALIZER(struct cmd_show_node_list_result, node_l= ist, "node_list"); > + > +static void > +cmd_show_node_list_parsed(__rte_unused void *parsed_result, __rte_unused= struct cmdline *cl, > + __rte_unused void *data) > +{ > + rte_node_t node_cnt =3D rte_node_max_count(); > + rte_node_t id; > + > + printf("\n**** Supported Graph Nodes ****\n"); > + for (id =3D 0; id < node_cnt; id++) > + printf("%s\n", rte_node_id_to_name(id)); > + > + printf("********************************\n"); > +} > + > +cmdline_parse_inst_t cmd_show_node_list =3D { > + .f =3D cmd_show_node_list_parsed, > + .data =3D NULL, > + .help_str =3D "show node_list", > + .tokens =3D { > + (void *)&cmd_show_node_list_show, > + (void *)&cmd_show_node_list_node_list, > + NULL, > + }, > +}; > + > +/* *** Set lcore config *** */ > +struct cmd_set_lcore_config_result { > + cmdline_fixed_string_t set; > + cmdline_fixed_string_t lcore_config; > + cmdline_multi_string_t token_string; > +}; > + > +static cmdline_parse_token_string_t cmd_set_lcore_config_set =3D > + TOKEN_STRING_INITIALIZER(struct cmd_set_lcore_config_result, set,= "set"); > +static cmdline_parse_token_string_t cmd_set_lcore_config_lcore_config = =3D > + TOKEN_STRING_INITIALIZER(struct cmd_set_lcore_config_result, lcor= e_config, "lcore_config"); > +static cmdline_parse_token_string_t cmd_set_lcore_config_token_string = =3D TOKEN_STRING_INITIALIZER( > + struct cmd_set_lcore_config_result, token_string, TOKEN_STRING_MU= LTI); > + > +static void > +cmd_set_lcore_config_parsed(void *parsed_result, __rte_unused struct cmd= line *cl, > + __rte_unused void *data) > +{ > + struct cmd_set_lcore_config_result *res =3D parsed_result; > + const char *t_str =3D res->token_string; > + int ret; > + > + /* Parse string */ > + ret =3D parse_config(t_str); > + if (ret) { > + printf(" lcore_config string parse error\n"); > + return; > + } > + > + validate_config(); > +} > + > +cmdline_parse_inst_t cmd_set_lcore_config =3D { > + .f =3D cmd_set_lcore_config_parsed, > + .data =3D NULL, > + .help_str =3D "set lcore_config " > + "(port,queue,lcore),[(port,queue,lcore) ... (port,que= ue,lcore)]", > + .tokens =3D { > + (void *)&cmd_set_lcore_config_set, > + (void *)&cmd_set_lcore_config_lcore_config, > + (void *)&cmd_set_lcore_config_token_string, > + NULL, > + }, > +}; > + > +/* *** Create graph *** */ > +struct cmd_create_graph_result { > + cmdline_fixed_string_t create_graph; > + cmdline_multi_string_t token_string; > +}; > + > +static cmdline_parse_token_string_t cmd_create_graph_create_graph =3D > + TOKEN_STRING_INITIALIZER(struct cmd_create_graph_result, create_g= raph, "create_graph"); > +static cmdline_parse_token_string_t cmd_create_graph_token_string =3D > + TOKEN_STRING_INITIALIZER(struct cmd_create_graph_result, token_st= ring, TOKEN_STRING_MULTI); > + > +static void > +cmd_create_graph_parsed(void *parsed_result, __rte_unused struct cmdline= *cl, > + __rte_unused void *data) > +{ > + struct cmd_create_graph_result *res =3D parsed_result; > + const char *t_str =3D res->token_string; > + uint64_t valid_nodes =3D 0; > + int ret; > + > + ret =3D parse_node_patterns(t_str); > + if (ret) { > + printf("parse_node_patterns failed\n"); > + cleanup_node_pattern(); > + return; > + } > + > + ret =3D validate_node_names(&valid_nodes); > + if (ret) { > + printf("validate_node_names() failed\n"); > + cleanup_node_pattern(); > + return; > + } > + > + nb_conf =3D ethdev_ports_setup(); > + > + ethdev_rxq_configure(); > + ethdev_txq_configure(); > + > + ret =3D configure_graph_nodes(valid_nodes); > + if (ret) { > + printf("configure_graph_nodes() failed\n"); > + cleanup_node_pattern(); > + return; > + } > + > + start_eth_ports(); > + check_all_ports_link_status(enabled_port_mask); > + > + ret =3D create_graph(node_pattern, num_patterns); > + if (ret) > + rte_exit(EXIT_FAILURE, "create_graph: err=3D%d\n", ret); > + > + stats =3D create_graph_cluster_stats(); > + if (stats =3D=3D NULL) > + rte_exit(EXIT_FAILURE, "create_graph_cluster_stats() fail= ed\n"); > +} > + > +cmdline_parse_inst_t cmd_create_graph =3D { > + .f =3D cmd_create_graph_parsed, > + .data =3D NULL, > + .help_str =3D "create_graph " > + "[node_name0,node_name1,node_name2 ... node_nameX]", > + .tokens =3D { > + (void *)&cmd_create_graph_create_graph, > + (void *)&cmd_create_graph_token_string, > + NULL, > + }, > +}; > + > +/**** Destroy graph ****/ > +struct cmd_destroy_graph_result { > + cmdline_fixed_string_t destroy_graph; > +}; > + > +static cmdline_parse_token_string_t cmd_destroy_graph_destroy_graph =3D > + TOKEN_STRING_INITIALIZER(struct cmd_destroy_graph_result, destroy= _graph, "destroy_graph"); > + > +static void > +cmd_destroy_graph_parsed(__rte_unused void *parsed_result, __rte_unused = struct cmdline *cl, > + __rte_unused void *data) > +{ > + uint32_t lcore_id; > + > + run_graph_walk =3D false; > + graph_walk_quit =3D true; > + > + RTE_LCORE_FOREACH_WORKER(lcore_id) > + rte_eal_wait_lcore(lcore_id); > + > + destroy_graph(); > + stop_eth_ports(); > +} > + > +cmdline_parse_inst_t cmd_destroy_graph =3D { > + .f =3D cmd_destroy_graph_parsed, > + .data =3D NULL, > + .help_str =3D "destroy_graph", > + .tokens =3D { > + (void *)&cmd_destroy_graph_destroy_graph, > + NULL, > + }, > +}; > + > +/**** Start graph_walk ****/ > +struct cmd_start_graph_walk_result { > + cmdline_fixed_string_t start; > + cmdline_fixed_string_t graph_walk; > +}; > + > +static cmdline_parse_token_string_t cmd_start_graph_walk_start =3D > + TOKEN_STRING_INITIALIZER(struct cmd_start_graph_walk_result, star= t, "start"); > +static cmdline_parse_token_string_t cmd_start_graph_walk_graph_walk =3D > + TOKEN_STRING_INITIALIZER(struct cmd_start_graph_walk_result, grap= h_walk, "graph_walk"); > + > +static void > +cmd_start_graph_walk_parsed(__rte_unused void *parsed_result, __rte_unus= ed struct cmdline *cl, > + __rte_unused void *data) > +{ > + static bool launch_graph_walk; > + > + if (!launch_graph_walk) { > + rte_eal_mp_remote_launch(graph_main_loop, NULL, SKIP_MAIN= ); > + launch_graph_walk =3D true; > + } > + > + run_graph_walk =3D true; > +} > + > +cmdline_parse_inst_t cmd_start_graph_walk =3D { > + .f =3D cmd_start_graph_walk_parsed, > + .data =3D NULL, > + .help_str =3D "start graph_walk", > + .tokens =3D { > + (void *)&cmd_start_graph_walk_start, > + (void *)&cmd_start_graph_walk_graph_walk, > + NULL, > + }, > +}; > + > +/**** Stop graph_walk ****/ > +struct cmd_stop_graph_walk_result { > + cmdline_fixed_string_t stop; > + cmdline_fixed_string_t graph_walk; > +}; > + > +static cmdline_parse_token_string_t cmd_stop_graph_walk_stop =3D > + TOKEN_STRING_INITIALIZER(struct cmd_stop_graph_walk_result, stop,= "stop"); > +static cmdline_parse_token_string_t cmd_stop_graph_walk_graph_walk =3D > + TOKEN_STRING_INITIALIZER(struct cmd_stop_graph_walk_result, graph= _walk, "graph_walk"); > + > +static void > +cmd_stop_graph_walk_parsed(__rte_unused void *parsed_result, __rte_unuse= d struct cmdline *cl, > + __rte_unused void *data) > +{ > + run_graph_walk =3D false; > +} > + > +cmdline_parse_inst_t cmd_stop_graph_walk =3D { > + .f =3D cmd_stop_graph_walk_parsed, > + .data =3D NULL, > + .help_str =3D "stop graph_walk", > + .tokens =3D { > + (void *)&cmd_stop_graph_walk_stop, > + (void *)&cmd_stop_graph_walk_graph_walk, > + NULL, > + }, > +}; > + > +/**** Show graph_stats ****/ > +struct cmd_show_graph_stats_result { > + cmdline_fixed_string_t show; > + cmdline_fixed_string_t graph_stats; > +}; > + > +static cmdline_parse_token_string_t cmd_show_graph_stats_show =3D > + TOKEN_STRING_INITIALIZER(struct cmd_show_graph_stats_result, show= , "show"); > +static cmdline_parse_token_string_t cmd_show_graph_stats_graph_stats =3D > + TOKEN_STRING_INITIALIZER(struct cmd_show_graph_stats_result, grap= h_stats, "graph_stats"); > + > +static void > +cmd_show_graph_stats_parsed(__rte_unused void *parsed_result, __rte_unus= ed struct cmdline *cl, > + __rte_unused void *data) > +{ > + if (rte_graph_has_stats_feature()) { > + if (stats) > + rte_graph_cluster_stats_get(stats, 0); > + } else { > + printf(" graph stats feature not enabled in rte_config.\n= "); > + } > +} > + > +cmdline_parse_inst_t cmd_show_graph_stats =3D { > + .f =3D cmd_show_graph_stats_parsed, > + .data =3D NULL, > + .help_str =3D "show graph_stats", > + .tokens =3D { > + (void *)&cmd_show_graph_stats_show, > + (void *)&cmd_show_graph_stats_graph_stats, > + NULL, > + }, > +}; > diff --git a/app/test-graph/cmdline_graph.h b/app/test-graph/cmdline_grap= h.h > new file mode 100644 > index 0000000000..2846ff5425 > --- /dev/null > +++ b/app/test-graph/cmdline_graph.h > @@ -0,0 +1,19 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#ifndef _CMDLINE_GRAPH_H_ > +#define _CMDLINE_GRAPH_H_ > + > +extern cmdline_parse_inst_t cmd_show_node_list; > +extern cmdline_parse_inst_t cmd_set_lcore_config; > + > +extern cmdline_parse_inst_t cmd_create_graph; > +extern cmdline_parse_inst_t cmd_destroy_graph; > + > +extern cmdline_parse_inst_t cmd_start_graph_walk; > +extern cmdline_parse_inst_t cmd_stop_graph_walk; > + > +extern cmdline_parse_inst_t cmd_show_graph_stats; > + > +#endif /* _CMDLINE_GRAPH_H_ */ > diff --git a/app/test-graph/meson.build b/app/test-graph/meson.build > new file mode 100644 > index 0000000000..a969a91183 > --- /dev/null > +++ b/app/test-graph/meson.build > @@ -0,0 +1,17 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(C) 2023 Marvell International Ltd. > + > +# override default name to drop the hyphen > +name =3D 'test-graph' > +cflags +=3D '-Wno-deprecated-declarations' > +sources =3D files( > + 'cmdline.c', > + 'cmdline_graph.c', > + 'parameters.c', > + 'testgraph.c', > +) > + > +deps +=3D ['ethdev', 'cmdline', 'graph', 'node', 'eal'] > + > +# Driver-specific commands are located in driver directories. > +includes =3D include_directories('.') > diff --git a/app/test-graph/parameters.c b/app/test-graph/parameters.c > new file mode 100644 > index 0000000000..b990ca4a1c > --- /dev/null > +++ b/app/test-graph/parameters.c > @@ -0,0 +1,157 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > +#include > + > +#include "testgraph.h" > + > +static const char short_options[] =3D "p:" /* portmask */ > + "P" /* promiscuous */ > + "i" /* interactive */ > + ; > + > +#define CMD_LINE_OPT_CONFIG "config" > +#define CMD_LINE_OPT_NODE_PATTERN "node-pattern" > +#define CMD_LINE_OPT_INTERACTIVE "interactive" > +#define CMD_LINE_OPT_NO_NUMA "no-numa" > +#define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool" > +enum { > + /* Long options mapped to a short option */ > + > + /* First long only option value must be >=3D 256, so that we won'= t > + * conflict with short options > + */ > + CMD_LINE_OPT_MIN_NUM =3D 256, > + CMD_LINE_OPT_CONFIG_NUM, > + CMD_LINE_OPT_NODE_PATTERN_NUM, > + CMD_LINE_OPT_INTERACTIVE_NUM, > + CMD_LINE_OPT_NO_NUMA_NUM, > + CMD_LINE_OPT_PARSE_PER_PORT_POOL, > +}; > + > +static const struct option lgopts[] =3D { > + {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM}, > + {CMD_LINE_OPT_NODE_PATTERN, 1, 0, CMD_LINE_OPT_NODE_PATTERN_NUM}, > + {CMD_LINE_OPT_INTERACTIVE, 0, 0, CMD_LINE_OPT_INTERACTIVE_NUM}, > + {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM}, > + {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_PO= OL}, > + {NULL, 0, 0, 0}, > +}; > + > +/* Display usage */ > +static void > +print_usage(const char *prgname) > +{ > + fprintf(stderr, > + "%s [EAL options] --" > + " -p PORTMASK" > + " [-P]" > + " [-i]" > + " --config (port,queue,lcore)[,(port,queue,lcore)]" > + " --node-pattern (node_name0,node_name1[,node_nameX)]" > + " [--no-numa]" > + " [--per-port-pool]" > + " [--interactive]" > + > + " -p PORTMASK: Hexadecimal bitmask of ports to configure= \n" > + " -P : Enable promiscuous mode\n" > + " -i : Enter interactive mode\n" > + " --config (port,queue,lcore): Rx queue configuration\n" > + " --node-pattern (node_names): node patterns to create g= raph\n" > + " --no-numa: Disable numa awareness\n" > + " --per-port-pool: Use separate buffer pool per port\n" > + " --interactive: Enter interactive mode\n", > + prgname); > +} > + > +static int > +parse_portmask(const char *portmask) > +{ > + char *end =3D NULL; > + unsigned long pm; > + > + /* Parse hexadecimal string */ > + pm =3D strtoul(portmask, &end, 16); > + if ((portmask[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D = '\0')) > + return 0; > + > + return pm; > +} > + > +/* Parse the argument given in the command line of the application */ > +int > +parse_cmdline_args(int argc, char **argv) > +{ > + char *prgname =3D argv[0]; > + int option_index; > + char **argvopt; > + int opt, ret; > + > + argvopt =3D argv; > + > + /* Error or normal output strings. */ > + while ((opt =3D getopt_long(argc, argvopt, short_options, lgopts,= &option_index)) !=3D EOF) { > + > + switch (opt) { > + /* Portmask */ > + case 'p': > + enabled_port_mask =3D parse_portmask(optarg); > + if (enabled_port_mask =3D=3D 0) { > + fprintf(stderr, "Invalid portmask\n"); > + print_usage(prgname); > + return -1; > + } > + break; > + > + case 'P': > + promiscuous_on =3D 1; > + break; > + > + /* Long options */ > + case CMD_LINE_OPT_CONFIG_NUM: > + ret =3D parse_config(optarg); > + if (ret) { > + fprintf(stderr, "Invalid config\n"); > + print_usage(prgname); > + return -1; > + } > + break; > + case CMD_LINE_OPT_NODE_PATTERN_NUM: > + ret =3D parse_node_patterns(optarg); > + if (ret) { > + fprintf(stderr, "Invalid node_patterns\n"= ); > + print_usage(prgname); > + return -1; > + } > + break; > + > + case CMD_LINE_OPT_INTERACTIVE_NUM: > + case 'i': > + printf("Interactive-mode selected\n"); > + interactive =3D 1; > + break; > + > + case CMD_LINE_OPT_NO_NUMA_NUM: > + numa_on =3D 0; > + break; > + > + case CMD_LINE_OPT_PARSE_PER_PORT_POOL: > + printf("Per port buffer pool is enabled\n"); > + per_port_pool =3D 1; > + break; > + > + default: > + print_usage(prgname); > + return -1; > + } > + } > + > + if (optind >=3D 0) > + argv[optind - 1] =3D prgname; > + ret =3D optind - 1; > + optind =3D 1; /* Reset getopt lib */ > + > + return ret; > +} > diff --git a/app/test-graph/testgraph.c b/app/test-graph/testgraph.c > new file mode 100644 > index 0000000000..b236b907c7 > --- /dev/null > +++ b/app/test-graph/testgraph.c > @@ -0,0 +1,1309 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "testgraph.h" > + > +/* Log type */ > +#define RTE_LOGTYPE_TEST_GRAPH RTE_LOGTYPE_USER1 > + > +/* > + * Configurable number of RX/TX ring descriptors > + */ > +#define RX_DESC_DEFAULT 1024 > +#define TX_DESC_DEFAULT 1024 > + > +#define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS > +#define MAX_RX_QUEUE_PER_PORT 128 > + > +#define MAX_RX_QUEUE_PER_LCORE 16 > + > +#define NB_SOCKETS 8 > + > +/* Static global variables used within this file. */ > +uint16_t nb_rxd =3D RX_DESC_DEFAULT; > +uint16_t nb_txd =3D TX_DESC_DEFAULT; > + > +static volatile bool force_quit; > +volatile bool graph_walk_quit; > + > +volatile bool run_graph_walk =3D true; > + > +uint8_t cl_quit; > + > +uint8_t interactive; /**< interactive mode is off by default */ > + > +const char **node_patterns; > + > +char node_pattern[MAX_NODE_PATTERNS][RTE_NODE_NAMESIZE] =3D {0}; > +uint8_t num_patterns; > + > +int promiscuous_on; /**< Ports set in promiscuous mode off by default. *= / > + > +int numa_on =3D 1; /**< NUMA is enabled by default. */ > +int per_port_pool; /**< Use separate buffer pools per port; disabled */ > + /**< by default */ > + > +int testgraph_logtype; /**< Log type for testpmd logs */ > + > +struct rte_graph_cluster_stats *stats; > + > +/* Mask of enabled ports */ > +uint32_t enabled_port_mask; > + > +uint32_t nb_conf; > + > +struct lcore_rx_queue { > + uint16_t port_id; > + uint8_t queue_id; > + char node_name[RTE_NODE_NAMESIZE]; > +}; > + > +struct lcore_tx_queue { > + char node_name[RTE_NODE_NAMESIZE]; > +}; > + > +/* Lcore conf */ > +struct lcore_conf { > + uint16_t n_rx_queue; > + struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE]; > + char punt_kernel_node_name[RTE_NODE_NAMESIZE]; > + > + struct rte_graph *graph; > + char name[RTE_GRAPH_NAMESIZE]; > + rte_graph_t graph_id; > +} __rte_cache_aligned; > + > +static struct lcore_conf lcore_conf[RTE_MAX_LCORE]; > + > +struct lcore_params lcore_params_array[MAX_LCORE_PARAMS]; > +static struct lcore_params lcore_params_array_default[] =3D { > + {0, 0, 2}, {1, 0, 2}, {2, 0, 2}, {0, 1, 3}, {1, 1, 3}, > + {2, 1, 3}, {0, 2, 4}, {1, 2, 4}, {2, 2, 4}, > +}; > + > +struct lcore_params *lcore_params =3D lcore_params_array_default; > +uint16_t nb_lcore_params =3D RTE_DIM(lcore_params_array_default); > + > +static struct rte_eth_conf port_conf =3D { > + .rxmode =3D { > + .mq_mode =3D RTE_ETH_MQ_RX_RSS, > + }, > + .rx_adv_conf =3D { > + .rss_conf =3D { > + .rss_key =3D NULL, > + .rss_hf =3D RTE_ETH_RSS_IP, > + }, > + }, > + .txmode =3D { > + .mq_mode =3D RTE_ETH_MQ_TX_NONE, > + }, > +}; > + > +static const struct node_list test_node_list[] =3D {{{"ethdev_rx", "ethd= ev_tx"}, 0, 2}, > + {{"ethdev_rx", "punt_kern= el"}, 0, 2} }; > + > +static const struct node_list supported_nodes[] =3D {{{"ethdev_rx"}, TES= T_GRAPH_ETHDEV_RX_NODE, 1}, > + {{"ethdev_tx"}, TEST_GRAP= H_ETHDEV_TX_NODE, 1}, > + {{"punt_kernel"}, TEST_GR= APH_PUNT_KERNEL_NODE, 1}, > + {{"kernel_recv"}, TEST_GR= APH_KERNEL_RECV_NODE, 1}, > + {{"ip4_lookup"}, TEST_GRA= PH_IP4_LOOKUP_NODE, 1}, > + {{"ip4_rewrite"}, TEST_GR= APH_IP4_REWRITE_NODE, 1}, > + {{"pkt_cls"}, TEST_GRAPH_= PKT_CLS_NODE, 1}, > + {{"pkt_drop"}, TEST_GRAPH= _PKT_DROP_NODE, 1}, > + {{"NULL"}, TEST_GRAPH_NUL= L_NODE, 1} }; > + > +static struct rte_mempool *pktmbuf_pool[RTE_MAX_ETHPORTS][NB_SOCKETS]; > + > +struct rte_node_ethdev_config ethdev_conf[RTE_MAX_ETHPORTS]; > + > +static int > +check_lcore_params(void) > +{ > + uint8_t queue, lcore; > + int socketid; > + uint16_t i; > + > + for (i =3D 0; i < nb_lcore_params; ++i) { > + queue =3D lcore_params[i].queue_id; > + if (queue >=3D MAX_RX_QUEUE_PER_PORT) { > + printf("Invalid queue number: %hhu\n", queue); > + return -1; > + } > + lcore =3D lcore_params[i].lcore_id; > + if (!rte_lcore_is_enabled(lcore)) { > + printf("Error: lcore %hhu is not enabled in lcore= mask\n", lcore); > + return -1; > + } > + > + if (lcore =3D=3D rte_get_main_lcore()) { > + printf("Error: lcore %u is main lcore\n", lcore); > + return -1; > + } > + socketid =3D rte_lcore_to_socket_id(lcore); > + if ((socketid !=3D 0) && (numa_on =3D=3D 0)) { > + printf("Warning: lcore %hhu is on socket %d with = numa off\n", lcore, > + socketid); > + } > + } > + > + return 0; > +} > + > +static int > +check_port_config(void) > +{ > + uint16_t portid; > + uint16_t i; > + > + for (i =3D 0; i < nb_lcore_params; ++i) { > + portid =3D lcore_params[i].port_id; > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) { > + printf("Port %u is not enabled in port mask\n", p= ortid); > + return -1; > + } > + if (!rte_eth_dev_is_valid_port(portid)) { > + printf("Port %u is not present on the board\n", p= ortid); > + return -1; > + } > + } > + > + return 0; > +} > + > +static uint8_t > +get_port_n_rx_queues(const uint16_t port) > +{ > + int queue =3D -1; > + uint16_t i; > + > + for (i =3D 0; i < nb_lcore_params; ++i) { > + if (lcore_params[i].port_id =3D=3D port) { > + if (lcore_params[i].queue_id =3D=3D queue + 1) > + queue =3D lcore_params[i].queue_id; > + else > + rte_exit(EXIT_FAILURE, > + "Queue ids of the port %d must b= e" > + " in sequence and must start wit= h 0\n", > + lcore_params[i].port_id); > + } > + } > + > + return (uint8_t)(++queue); > +} > + > +static int > +init_lcore_rx_queues(void) > +{ > + uint16_t i, nb_rx_queue; > + uint8_t lcore; > + > + for (i =3D 0; i < nb_lcore_params; ++i) { > + lcore =3D lcore_params[i].lcore_id; > + nb_rx_queue =3D lcore_conf[lcore].n_rx_queue; > + if (nb_rx_queue >=3D MAX_RX_QUEUE_PER_LCORE) { > + printf("Error: too many queues (%u) for lcore: %u= \n", > + (unsigned int)nb_rx_queue + 1, (unsigned i= nt)lcore); > + return -1; > + } > + > + lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =3D = lcore_params[i].port_id; > + lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =3D= lcore_params[i].queue_id; > + lcore_conf[lcore].n_rx_queue++; > + } > + > + return 0; > +} > + > +int > +validate_config(void) > +{ > + int rc =3D -1; > + > + if (check_lcore_params() < 0) { > + printf("check_lcore_params() failed\n"); > + goto exit; > + } > + > + if (init_lcore_rx_queues() < 0) { > + printf("init_lcore_rx_queues() failed\n"); > + goto exit; > + } > + > + if (check_port_config() < 0) { > + printf("check_port_config() failed\n"); > + goto exit; > + } > + > + return 0; > + > +exit: > + return rc; > +} > + > +#define MEMPOOL_CACHE_SIZE 256 > + > +/* > + * This expression is used to calculate the number of mbufs needed > + * depending on user input, taking into account memory for rx and > + * tx hardware rings, cache per lcore and mtable per port per lcore. > + * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum > + * value of 8192 > + */ > +#define NB_MBUF(nports) = \ > + RTE_MAX((nports * nb_rx_queue * nb_rxd + nports * nb_lcores * RTE= _GRAPH_BURST_SIZE + \ > + nports * nb_tx_queue * nb_txd + nb_lcores * MEMPOOL_CACH= E_SIZE), \ > + 8192u) > + > +static int > +init_mem(uint16_t portid, uint32_t nb_mbuf) > +{ > + uint32_t lcore_id; > + int socketid; > + char s[64]; > + > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + > + if (numa_on) > + socketid =3D rte_lcore_to_socket_id(lcore_id); > + else > + socketid =3D 0; > + > + if (socketid >=3D NB_SOCKETS) { > + rte_exit(EXIT_FAILURE, "Socket %d of lcore %u is = out of range %d\n", > + socketid, lcore_id, NB_SOCKETS); > + } > + > + if (pktmbuf_pool[portid][socketid] =3D=3D NULL) { > + snprintf(s, sizeof(s), "mbuf_pool_%d:%d", portid,= socketid); > + /* Create a pool with priv size of a cacheline */ > + pktmbuf_pool[portid][socketid] =3D rte_pktmbuf_po= ol_create( > + s, nb_mbuf, MEMPOOL_CACHE_SIZE, RTE_CACHE= _LINE_SIZE, > + RTE_MBUF_DEFAULT_BUF_SIZE, socketid); > + if (pktmbuf_pool[portid][socketid] =3D=3D NULL) > + rte_exit(EXIT_FAILURE, "Cannot init mbuf = pool on socket %d\n", > + socketid); > + else > + printf("Allocated mbuf pool on socket %d\= n", socketid); > + } > + } > + > + return 0; > +} > + > +void > +check_all_ports_link_status(uint32_t port_mask) > +{ > +#define CHECK_INTERVAL 100 /* 100ms */ > +#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ > + uint8_t count, all_ports_up, print_flag =3D 0; > + struct rte_eth_link link; > + uint16_t portid; > + int ret; > + char link_status_text[RTE_ETH_LINK_MAX_STR_LEN]; > + > + printf("\nChecking link status"); > + fflush(stdout); > + for (count =3D 0; count <=3D MAX_CHECK_TIME; count++) { > + if (force_quit) > + return; > + all_ports_up =3D 1; > + RTE_ETH_FOREACH_DEV(portid) { > + if (force_quit) > + return; > + if ((port_mask & (1 << portid)) =3D=3D 0) > + continue; > + memset(&link, 0, sizeof(link)); > + ret =3D rte_eth_link_get_nowait(portid, &link); > + if (ret < 0) { > + all_ports_up =3D 0; > + if (print_flag =3D=3D 1) > + printf("Port %u link get failed: = %s\n", portid, > + rte_strerror(-ret)); > + continue; > + } > + /* Print link status if flag set */ > + if (print_flag =3D=3D 1) { > + rte_eth_link_to_str(link_status_text, siz= eof(link_status_text), > + &link); > + printf("Port %d %s\n", portid, link_statu= s_text); > + continue; > + } > + /* Clear all_ports_up flag if any link down */ > + if (link.link_status =3D=3D RTE_ETH_LINK_DOWN) { > + all_ports_up =3D 0; > + break; > + } > + } > + /* After finally printing all link status, get out */ > + if (print_flag =3D=3D 1) > + break; > + > + if (all_ports_up =3D=3D 0) { > + printf("."); > + fflush(stdout); > + rte_delay_ms(CHECK_INTERVAL); > + } > + > + /* Set the print_flag if all ports up or timeout */ > + if (all_ports_up =3D=3D 1 || count =3D=3D (MAX_CHECK_TIME= - 1)) { > + print_flag =3D 1; > + printf("Done\n"); > + } > + } > +} > + > +static void > +signal_handler(int signum) > +{ > + if (signum =3D=3D SIGINT || signum =3D=3D SIGTERM) { > + printf("\n\nSignal %d received, preparing to exit...\n", = signum); > + force_quit =3D true; > + } > + prompt_exit(); > +} > + > +int > +graph_main_loop(void *conf) > +{ > + struct lcore_conf *qconf; > + struct rte_graph *graph; > + uint32_t lcore_id; > + > + RTE_SET_USED(conf); > + > + lcore_id =3D rte_lcore_id(); > + qconf =3D &lcore_conf[lcore_id]; > + graph =3D qconf->graph; > + > + if (!graph) { > + RTE_LOG(INFO, TEST_GRAPH, "Lcore %u has nothing to do\n",= lcore_id); > + return 0; > + } > + > + RTE_LOG(INFO, TEST_GRAPH, "Entering main loop on lcore %u, graph = %s(%p)\n", lcore_id, > + qconf->name, graph); > + > + while (likely(!force_quit & !graph_walk_quit)) { > + if (likely(run_graph_walk)) > + rte_graph_walk(graph); > + } > + > + return 0; > +} > + > +struct rte_graph_cluster_stats * > +create_graph_cluster_stats(void) > +{ > + struct rte_graph_cluster_stats_param s_param; > + struct rte_graph_cluster_stats *stat; > + const char *pattern =3D "worker_*"; > + > + /* Prepare stats object */ > + memset(&s_param, 0, sizeof(s_param)); > + s_param.f =3D stdout; > + s_param.socket_id =3D SOCKET_ID_ANY; > + s_param.graph_patterns =3D &pattern; > + s_param.nb_graph_patterns =3D 1; > + > + stat =3D rte_graph_cluster_stats_create(&s_param); > + if (stat =3D=3D NULL) > + rte_exit(EXIT_FAILURE, "Unable to create stats object\n")= ; > + > + return stat; > +} > + > +static void > +print_stats(void) > +{ > + const char topLeft[] =3D {27, '[', '1', ';', '1', 'H', '\0'}; > + const char clr[] =3D {27, '[', '2', 'J', '\0'}; > + > + while (!force_quit) { > + /* Clear screen and move to top left */ > + printf("%s%s", clr, topLeft); > + rte_graph_cluster_stats_get(stats, 0); > + rte_delay_ms(1E3); > + } > + > + rte_graph_cluster_stats_destroy(stats); > +} > + > +int > +parse_config(const char *q_arg) > +{ > + enum fieldnames { FLD_PORT =3D 0, FLD_QUEUE, FLD_LCORE, _NUM_FLD = }; > + unsigned long int_fld[_NUM_FLD]; > + const char *p, *p0 =3D q_arg; > + char *str_fld[_NUM_FLD]; > + uint32_t size; > + char s[256]; > + char *end; > + int i; > + > + nb_lcore_params =3D 0; > + > + while ((p =3D strchr(p0, '(')) !=3D NULL) { > + ++p; > + p0 =3D strchr(p, ')'); > + if (p0 =3D=3D NULL) > + goto exit; > + > + size =3D p0 - p; > + if (size >=3D sizeof(s)) > + goto exit; > + > + memcpy(s, p, size); > + s[size] =3D '\0'; > + if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != =3D _NUM_FLD) > + goto exit; > + for (i =3D 0; i < _NUM_FLD; i++) { > + errno =3D 0; > + int_fld[i] =3D strtoul(str_fld[i], &end, 0); > + if (errno !=3D 0 || end =3D=3D str_fld[i]) > + goto exit; > + } > + > + if (nb_lcore_params >=3D MAX_LCORE_PARAMS) { > + printf("Exceeded max number of lcore params: %hu\= n", nb_lcore_params); > + goto exit; > + } > + > + if (int_fld[FLD_PORT] >=3D RTE_MAX_ETHPORTS || int_fld[FL= D_LCORE] >=3D RTE_MAX_LCORE) { > + printf("Invalid port/lcore id\n"); > + goto exit; > + } > + > + lcore_params_array[nb_lcore_params].port_id =3D (uint8_t)= int_fld[FLD_PORT]; > + lcore_params_array[nb_lcore_params].queue_id =3D (uint8_t= )int_fld[FLD_QUEUE]; > + lcore_params_array[nb_lcore_params].lcore_id =3D (uint8_t= )int_fld[FLD_LCORE]; > + ++nb_lcore_params; > + } > + lcore_params =3D lcore_params_array; > + > + return 0; > +exit: > + /* Revert to default config */ > + lcore_params =3D lcore_params_array_default; > + nb_lcore_params =3D RTE_DIM(lcore_params_array_default); > + > + return -1; > +} > + > +int > +parse_node_patterns(const char *q_arg) > +{ > + const char *p, *p0 =3D q_arg; > + int ret =3D -EINVAL; > + uint32_t size; > + > + num_patterns =3D 0; > + > + p =3D strchr(p0, '('); > + if (p !=3D NULL) { > + ++p; > + while ((p0 =3D strchr(p, ',')) !=3D NULL) { > + size =3D p0 - p; > + if (size >=3D RTE_NODE_NAMESIZE) > + goto exit; > + > + if (num_patterns >=3D MAX_NODE_PATTERNS) { > + printf("Too many nodes passed.\n"); > + goto exit; > + } > + > + memcpy(node_pattern[num_patterns++], p, size); > + p =3D p0 + 1; > + } > + > + p0 =3D strchr(p, ')'); > + if (p0 !=3D NULL) { > + size =3D p0 - p; > + if (size >=3D RTE_NODE_NAMESIZE) > + goto exit; > + > + if (num_patterns >=3D MAX_NODE_PATTERNS) { > + printf("Too many nodes passed.\n"); > + goto exit; > + } > + > + memcpy(node_pattern[num_patterns++], p, size); > + } else { > + goto exit; > + } > + } else { > + goto exit; > + } > + > + return 0; > +exit: > + return ret; > +} > + > +static void > +set_default_node_pattern(void) > +{ > + uint16_t idx; > + > + for (idx =3D 0; idx < test_node_list[0].size; idx++) > + strcpy(node_pattern[num_patterns++], test_node_list[0].no= des[idx]); > +} > +int > +validate_node_names(uint64_t *valid_nodes) > +{ > + rte_node_t node_cnt =3D rte_node_max_count(); > + bool pattern_matched =3D false; > + rte_node_t id =3D 0; > + int ret =3D -EINVAL; > + uint16_t idx, i, j; > + > + for (idx =3D 0; idx < num_patterns; idx++) { > + for (id =3D 0; id < node_cnt; id++) { > + if (strncmp(node_pattern[idx], rte_node_id_to_nam= e(id), > + RTE_GRAPH_NAMESIZE) =3D=3D 0) > + break; > + } > + if (node_cnt =3D=3D id) { > + printf("Invalid node name passed\n"); > + return ret; > + } > + } > + > + printf("num_ptrn:: %u\n", num_patterns); > + for (i =3D 0; i < RTE_DIM(test_node_list); i++) { > + idx =3D 0; > + if (test_node_list[i].size =3D=3D num_patterns) { > + for (j =3D 0; j < num_patterns; j++) { > + if (strncmp(node_pattern[j], test_node_li= st[i].nodes[j], > + RTE_GRAPH_NAMESIZE) =3D=3D 0) > + idx++; > + } > + printf("idx::%u\n", idx); > + if (idx =3D=3D num_patterns) > + pattern_matched =3D true; > + } > + } > + > + if (!pattern_matched) { > + printf("Unsupported node pattern passed\n\n"); > + printf("Test supported node patterns are:\n"); > + for (i =3D 0; i < RTE_DIM(test_node_list); i++) { > + printf("("); > + for (j =3D 0; j < (test_node_list[i].size - 1); j= ++) > + printf("%s,", test_node_list[i].nodes[j])= ; > + printf("%s", test_node_list[i].nodes[j]); > + printf(")\n"); > + } > + > + return ret; > + } > + > + for (i =3D 0; i < RTE_DIM(supported_nodes); i++) { > + for (j =3D 0; j < num_patterns; j++) { > + if (strncmp(node_pattern[j], supported_nodes[i].n= odes[0], > + RTE_GRAPH_NAMESIZE) =3D=3D 0) { > + *valid_nodes |=3D supported_nodes[i].test= _id; > + break; > + } > + } > + } > + > + return 0; > +} > + > +void > +cleanup_node_pattern(void) > +{ > + while (num_patterns) { > + memset(node_pattern[num_patterns - 1], 0, RTE_GRAPH_NAMES= IZE); > + num_patterns--; > + } > +} > + > +static int > +ethdev_tx_node_configure(struct rte_node_ethdev_config *conf, uint16_t n= b_confs) > +{ > + struct ethdev_tx_node_main *tx_node_data; > + struct rte_node_register *tx_node; > + char name[RTE_NODE_NAMESIZE]; > + uint16_t port_id; > + uint32_t id; > + int i; > + > + tx_node_data =3D ethdev_tx_node_data_get(); > + tx_node =3D ethdev_tx_node_get(); > + > + for (i =3D 0; i < nb_confs; i++) { > + port_id =3D conf[i].port_id; > + > + if (!rte_eth_dev_is_valid_port(port_id)) > + return -EINVAL; > + > + /* Create a per port tx node from base node */ > + snprintf(name, sizeof(name), "%u", port_id); > + id =3D rte_node_clone(tx_node->id, name); > + tx_node_data->nodes[port_id] =3D id; > + > + printf("ethdev:: Tx node %s-%s: is at %u\n", tx_node->nam= e, name, id); > + } > + > + return 0; > +} > + > +static int > +punt_kernel_node_configure(void) > +{ > + struct rte_node_register *punt_node; > + char name[RTE_NODE_NAMESIZE]; > + struct lcore_conf *qconf; > + uint32_t lcore_id; > + uint32_t id; > + > + punt_node =3D punt_kernel_node_get(); > + > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + > + qconf =3D &lcore_conf[lcore_id]; > + > + /* Create a per lcore punt_kernel node from base node */ > + snprintf(name, sizeof(name), "%u", lcore_id); > + id =3D rte_node_clone(punt_node->id, name); > + strcpy(qconf->punt_kernel_node_name, rte_node_id_to_name(= id)); > + > + printf("punt_kernel node %s-%s: is at %u\n", punt_node->n= ame, name, id); > + } > + > + return 0; > +} > + > +static int > +ethdev_rx_node_configure(struct rte_node_ethdev_config *conf, uint16_t n= b_confs) > +{ > + char name[RTE_NODE_NAMESIZE]; > + uint16_t i, j, port_id; > + uint32_t id; > + > + for (i =3D 0; i < nb_confs; i++) { > + port_id =3D conf[i].port_id; > + > + if (!rte_eth_dev_is_valid_port(port_id)) > + return -EINVAL; > + > + /* Create node for each rx port queue pair */ > + for (j =3D 0; j < conf[i].num_rx_queues; j++) { > + struct ethdev_rx_node_main *rx_node_data; > + struct rte_node_register *rx_node; > + ethdev_rx_node_elem_t *elem; > + > + rx_node_data =3D ethdev_rx_get_node_data_get(); > + rx_node =3D ethdev_rx_node_get(); > + snprintf(name, sizeof(name), "%u-%u", port_id, j)= ; > + /* Clone a new rx node with same edges as parent = */ > + id =3D rte_node_clone(rx_node->id, name); > + if (id =3D=3D RTE_NODE_ID_INVALID) > + return -EIO; > + > + /* Add it to list of ethdev rx nodes for lookup *= / > + elem =3D malloc(sizeof(ethdev_rx_node_elem_t)); > + if (elem =3D=3D NULL) > + return -ENOMEM; > + memset(elem, 0, sizeof(ethdev_rx_node_elem_t)); > + elem->ctx.port_id =3D port_id; > + elem->ctx.queue_id =3D j; > + elem->nid =3D id; > + elem->next =3D rx_node_data->head; > + rx_node_data->head =3D elem; > + > + printf("ethdev:: Rx node %s-%s: is at %u\n", rx_n= ode->name, name, id); > + } > + } > + > + return 0; > +} > + > +static int > +update_ethdev_rx_node_next(rte_node_t id, const char *edge_name) > +{ > + struct ethdev_rx_node_main *rx_node_data; > + ethdev_rx_node_elem_t *elem; > + char *next_nodes[16]; > + rte_edge_t count; > + uint16_t i; > + > + count =3D rte_node_edge_count(id); > + rte_node_edge_get(id, next_nodes); > + > + for (i =3D 0; i < count; i++) { > + if (fnmatch(edge_name, next_nodes[i], 0) =3D=3D 0) { > + rx_node_data =3D ethdev_rx_get_node_data_get(); > + elem =3D rx_node_data->head; > + while (elem->next !=3D rx_node_data->head) { > + if (elem->nid =3D=3D id) > + break; > + elem =3D elem->next; > + } > + > + if (elem->nid =3D=3D id) > + elem->ctx.cls_next =3D i; > + break; > + } > + } > + > + return 0; > +} > + > +static int > +link_ethdev_rx_to_tx_node(struct rte_node_ethdev_config *conf, uint16_t = nb_confs) > +{ > + const char * const pattern[] =3D {"ethdev_tx-*"}; > + char name[RTE_NODE_NAMESIZE]; > + const char *next_node =3D name; > + uint16_t i, j, port_id; > + uint32_t rx_id; > + > + for (i =3D 0; i < nb_confs; i++) { > + port_id =3D conf[i].port_id; > + > + if (!rte_eth_dev_is_valid_port(port_id)) > + return -EINVAL; > + > + for (j =3D 0; j < conf[i].num_rx_queues; j++) { > + > + snprintf(name, sizeof(name), "ethdev_rx-%u-%u", p= ort_id, j); > + rx_id =3D rte_node_from_name(name); > + > + /* Fill node pattern */ > + strcpy(node_pattern[num_patterns++], name); > + > + /* Prepare the actual name of the cloned node */ > + snprintf(name, sizeof(name), "ethdev_tx-%u", port= _id); > + > + /* Update ethdev_rx node edges */ > + rte_node_edge_update(rx_id, RTE_EDGE_ID_INVALID, = &next_node, 1); > + > + /* Fill node pattern */ > + strcpy(node_pattern[num_patterns++], name); > + > + /* Update node_next details */ > + update_ethdev_rx_node_next(rx_id, pattern[0]); > + } > + } > + > + return 0; > +} > + > +static int > +link_ethdev_rx_to_punt_kernel_node(void) > +{ > + uint16_t queueid, portid, queue; > + char name[RTE_NODE_NAMESIZE]; > + const char *next_node =3D name; > + struct lcore_conf *qconf; > + uint32_t lcore_id; > + rte_node_t rx_id; > + const char * const pattern[] =3D {"punt_kernel-*"}; > + > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + qconf =3D &lcore_conf[lcore_id]; > + > + /* Init RX queues */ > + for (queue =3D 0; queue < qconf->n_rx_queue; ++queue) { > + > + portid =3D qconf->rx_queue_list[queue].port_id; > + queueid =3D qconf->rx_queue_list[queue].queue_id; > + > + snprintf(name, sizeof(name), "ethdev_rx-%u-%u", p= ortid, queueid); > + rx_id =3D rte_node_from_name(name); > + > + /* Fill node pattern */ > + strcpy(node_pattern[num_patterns++], name); > + > + next_node =3D qconf->punt_kernel_node_name; > + > + /* Fill node pattern */ > + strcpy(node_pattern[num_patterns++], next_node); > + > + /* Update ethdev_rx node edges */ > + rte_node_edge_update(rx_id, RTE_EDGE_ID_INVALID, = &next_node, 1); > + > + /* Update node_next details */ > + update_ethdev_rx_node_next(rx_id, pattern[0]); > + } > + } > + > + return 0; > +} > + > +uint32_t > +ethdev_ports_setup(void) > +{ > + struct rte_eth_dev_info dev_info; > + uint32_t nb_tx_queue, nb_lcores; > + uint32_t nb_ports, nb_conf =3D 0; > + uint8_t nb_rx_queue; > + uint16_t portid; > + int ret; > + > + nb_ports =3D rte_eth_dev_count_avail(); > + nb_lcores =3D rte_lcore_count(); > + > + RTE_ETH_FOREACH_DEV(portid) { > + struct rte_eth_conf local_port_conf =3D port_conf; > + > + /* Skip ports that are not enabled */ > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) { > + printf("\nSkipping disabled port %d\n", portid); > + continue; > + } > + > + /* Init port */ > + printf("Initializing port %d ... ", portid); > + fflush(stdout); > + > + nb_rx_queue =3D get_port_n_rx_queues(portid); > + nb_tx_queue =3D nb_lcores; > + if (nb_tx_queue > MAX_TX_QUEUE_PER_PORT) > + nb_tx_queue =3D MAX_TX_QUEUE_PER_PORT; > + printf("Creating queues: nb_rxq=3D%d nb_txq=3D%u...\n", n= b_rx_queue, nb_tx_queue); > + > + rte_eth_dev_info_get(portid, &dev_info); > + > + if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FA= ST_FREE) > + local_port_conf.txmode.offloads |=3D RTE_ETH_TX_O= FFLOAD_MBUF_FAST_FREE; > + > + local_port_conf.rx_adv_conf.rss_conf.rss_hf &=3D dev_info= .flow_type_rss_offloads; > + if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=3D > + port_conf.rx_adv_conf.rss_conf.rss_hf) { > + printf("Port %u modified RSS hash function based = on hardware support," > + "requested:%#" PRIx64 " configured:%#" PRI= x64 "\n", > + portid, port_conf.rx_adv_conf.rss_conf.rss= _hf, > + local_port_conf.rx_adv_conf.rss_conf.rss_h= f); > + } > + > + ret =3D rte_eth_dev_configure(portid, nb_rx_queue, nb_tx_= queue, &local_port_conf); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "Cannot configure device: = err=3D%d, port=3D%d\n", ret, > + portid); > + > + ret =3D rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,= &nb_txd); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, > + "Cannot adjust number of descriptors: er= r=3D%d," > + "port=3D%d\n", > + ret, portid); > + > + /* Init memory */ > + if (!per_port_pool) > + ret =3D init_mem(0, NB_MBUF(nb_ports)); > + else > + ret =3D init_mem(portid, NB_MBUF(1)); > + > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "init_mem() failed\n"); > + > + /* Setup ethdev node config */ > + ethdev_conf[nb_conf].port_id =3D portid; > + ethdev_conf[nb_conf].num_rx_queues =3D nb_rx_queue; > + ethdev_conf[nb_conf].num_tx_queues =3D nb_tx_queue; > + if (!per_port_pool) > + ethdev_conf[nb_conf].mp =3D pktmbuf_pool[0]; > + > + else > + ethdev_conf[nb_conf].mp =3D pktmbuf_pool[portid]; > + ethdev_conf[nb_conf].mp_count =3D NB_SOCKETS; > + > + nb_conf++; > + } > + > + return nb_conf; > +} > + > +void > +ethdev_rxq_configure(void) > +{ > + struct rte_eth_dev_info dev_info; > + uint16_t queueid, portid; > + struct lcore_conf *qconf; > + uint8_t queue, socketid; > + uint32_t lcore_id; > + int ret; > + > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + qconf =3D &lcore_conf[lcore_id]; > + printf("\nInitializing rx queues on lcore %u ... ", lcore= _id); > + fflush(stdout); > + > + /* Init RX queues */ > + for (queue =3D 0; queue < qconf->n_rx_queue; ++queue) { > + struct rte_eth_rxconf rxq_conf; > + > + portid =3D qconf->rx_queue_list[queue].port_id; > + queueid =3D qconf->rx_queue_list[queue].queue_id; > + > + if (numa_on) > + socketid =3D (uint8_t)rte_lcore_to_socket= _id(lcore_id); > + else > + socketid =3D 0; > + > + printf("rxq=3D%d,%d,%d ", portid, queueid, socket= id); > + fflush(stdout); > + > + rte_eth_dev_info_get(portid, &dev_info); > + rxq_conf =3D dev_info.default_rxconf; > + rxq_conf.offloads =3D port_conf.rxmode.offloads; > + if (!per_port_pool) > + ret =3D rte_eth_rx_queue_setup(portid, qu= eueid, nb_rxd, socketid, > + &rxq_conf, p= ktmbuf_pool[0][socketid]); > + else > + ret =3D rte_eth_rx_queue_setup(portid, qu= eueid, nb_rxd, socketid, > + &rxq_conf, > + pktmbuf_pool= [portid][socketid]); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_= setup: err=3D%d, port=3D%d\n", > + ret, portid); > + > + snprintf(qconf->rx_queue_list[queue].node_name, R= TE_NODE_NAMESIZE, > + "ethdev_rx-%u-%u", portid, queueid); > + } > + } > + printf("\n"); > +} > + > +void > +ethdev_txq_configure(void) > +{ > + struct rte_eth_dev_info dev_info; > + struct rte_eth_txconf *txconf; > + uint16_t queueid, portid; > + uint32_t lcore_id; > + uint8_t socketid; > + int ret; > + > + RTE_ETH_FOREACH_DEV(portid) { > + struct rte_eth_conf local_port_conf =3D port_conf; > + > + /* Skip ports that are not enabled */ > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) { > + printf("\nSkipping disabled port %d\n", portid); > + continue; > + } > + > + rte_eth_dev_info_get(portid, &dev_info); > + > + /* Init one TX queue per (lcore,port) pair */ > + queueid =3D 0; > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++= ) { > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + > + if (numa_on) > + socketid =3D (uint8_t)rte_lcore_to_socket= _id(lcore_id); > + else > + socketid =3D 0; > + > + printf("txq=3D%u,%d,%d ", lcore_id, queueid, sock= etid); > + fflush(stdout); > + > + txconf =3D &dev_info.default_txconf; > + txconf->offloads =3D local_port_conf.txmode.offlo= ads; > + ret =3D rte_eth_tx_queue_setup(portid, queueid, n= b_txd, socketid, txconf); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_= setup: err=3D%d, port=3D%d\n", > + ret, portid); > + queueid++; > + } > + } > + printf("\n"); > +} > + > +int > +configure_graph_nodes(uint64_t valid_nodes) > +{ > + int ret =3D 0; > + > + if (valid_nodes & TEST_GRAPH_ETHDEV_RX_NODE) { > + ret =3D ethdev_rx_node_configure(ethdev_conf, nb_conf); > + if (ret) { > + printf("ethdev_rx_node_configure: err=3D%d\n", re= t); > + goto exit; > + } > + } > + > + if (valid_nodes & TEST_GRAPH_ETHDEV_TX_NODE) { > + ret =3D ethdev_tx_node_configure(ethdev_conf, nb_conf); > + if (ret) { > + printf("ethdev_tx_node_configure: err=3D%d\n", re= t); > + goto exit; > + } > + } > + > + if (valid_nodes & TEST_GRAPH_PUNT_KERNEL_NODE) { > + ret =3D punt_kernel_node_configure(); > + if (ret) { > + printf("punt_kernel_node_configure: err=3D%d\n", = ret); > + goto exit; > + } > + } > + > + cleanup_node_pattern(); > + > + if (valid_nodes =3D=3D (TEST_GRAPH_ETHDEV_TX_NODE | TEST_GRAPH_ET= HDEV_RX_NODE)) { > + ret =3D link_ethdev_rx_to_tx_node(ethdev_conf, nb_conf); > + if (ret) { > + printf("link_ethdev_rx_to_tx_node: err=3D%d\n", r= et); > + goto exit; > + } > + } else if (valid_nodes =3D=3D (TEST_GRAPH_ETHDEV_RX_NODE | TEST_G= RAPH_PUNT_KERNEL_NODE)) { > + link_ethdev_rx_to_punt_kernel_node(); > + } else { > + printf("Invalid node map\n"); > + ret =3D -EINVAL; > + } > + > +exit: > + return ret; > +} > + > +void > +start_eth_ports(void) > +{ > + uint16_t portid; > + int ret; > + > + RTE_ETH_FOREACH_DEV(portid) { > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) > + continue; > + > + ret =3D rte_eth_dev_start(portid); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=3D= %d, port=3D%d\n", ret, portid); > + > + if (promiscuous_on) > + rte_eth_promiscuous_enable(portid); > + } > +} > + > +void > +stop_eth_ports(void) > +{ > + uint16_t portid; > + int ret; > + > + RTE_ETH_FOREACH_DEV(portid) { > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) > + continue; > + printf("Closing port %d...", portid); > + ret =3D rte_eth_dev_stop(portid); > + if (ret !=3D 0) > + printf("Failed to stop port %u: %s\n", portid, rt= e_strerror(-ret)); > + rte_eth_dev_close(portid); > + } > +} > + > +int > +create_graph(char pattern[][RTE_NODE_NAMESIZE], uint8_t num_patterns) > +{ > + struct rte_graph_param graph_conf; > + struct lcore_conf *qconf; > + uint32_t lcore_id; > + > + node_patterns =3D malloc(MAX_NODE_PATTERNS * sizeof(*node_pattern= s)); > + if (!node_patterns) > + return -ENOMEM; > + > + memset(&graph_conf, 0, sizeof(graph_conf)); > + graph_conf.node_patterns =3D node_patterns; > + > + for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { > + rte_graph_t graph_id; > + rte_edge_t i; > + > + if (rte_lcore_is_enabled(lcore_id) =3D=3D 0) > + continue; > + > + qconf =3D &lcore_conf[lcore_id]; > + > + /* Skip graph creation if no source exists */ > + if (!qconf->n_rx_queue) > + continue; > + > + for (i =3D 0; i < num_patterns; i++) > + graph_conf.node_patterns[i] =3D pattern[i]; > + > + graph_conf.nb_node_patterns =3D num_patterns; > + > + graph_conf.socket_id =3D rte_lcore_to_socket_id(lcore_id)= ; > + > + snprintf(qconf->name, sizeof(qconf->name), "worker_%u", l= core_id); > + > + graph_id =3D rte_graph_create(qconf->name, &graph_conf); > + if (graph_id =3D=3D RTE_GRAPH_ID_INVALID) > + rte_exit(EXIT_FAILURE, "rte_graph_create(): graph= _id invalid for lcore%u\n", > + lcore_id); > + > + qconf->graph_id =3D graph_id; > + qconf->graph =3D rte_graph_lookup(qconf->name); > + > + if (!qconf->graph) > + rte_exit(EXIT_FAILURE, "rte_graph_lookup(): graph= %s not found\n", > + qconf->name); > + } > + > + return 0; > +} > + > +int > +destroy_graph(void) > +{ > + uint32_t lcore_id; > + rte_graph_t id; > + int ret; > + > + RTE_LCORE_FOREACH_WORKER(lcore_id) > + { > + if (lcore_conf[lcore_id].graph) { > + id =3D rte_graph_from_name(lcore_conf[lcore_id].n= ame); > + if (rte_graph_destroy(id)) { > + printf("graph_id %u destroy failed.\n", i= d); > + ret =3D -1; > + } > + } > + } > + > + if (node_patterns) > + free(node_patterns); > + > + return ret; > +} > + > +int > +main(int argc, char **argv) > +{ > + uint64_t valid_nodes; > + uint32_t lcore_id; > + int ret; > + > + graph_walk_quit =3D false; > + force_quit =3D false; > + interactive =3D 0; > + > + node_patterns =3D NULL; > + > + signal(SIGINT, signal_handler); > + signal(SIGTERM, signal_handler); > + > + testgraph_logtype =3D rte_log_register("testgraph"); > + if (testgraph_logtype < 0) > + rte_exit(EXIT_FAILURE, "Cannot register log type"); > + > + set_default_node_pattern(); > + > + rte_log_set_level(testgraph_logtype, RTE_LOG_DEBUG); > + > + ret =3D rte_eal_init(argc, argv); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n", rte_strer= ror(rte_errno)); > + argc -=3D ret; > + argv +=3D ret; > + > + if (argc > 1) { > + ret =3D parse_cmdline_args(argc, argv); > + if (ret < 0) > + rte_exit(EXIT_FAILURE, "Invalid command line para= meters\n"); > + } > + > +#ifdef RTE_LIB_CMDLINE > + if (init_cmdline() !=3D 0) > + rte_exit(EXIT_FAILURE, "Could not initialise cmdline cont= ext.\n"); > + > + if (interactive =3D=3D 1) { > + prompt(); > + } else > +#endif > + { > + if (validate_config() < 0) > + rte_exit(EXIT_FAILURE, "Config validation failed.= \n"); > + > + ret =3D validate_node_names(&valid_nodes); > + if (ret) > + rte_exit(EXIT_FAILURE, "validate_node_names: err= =3D%d\n", ret); > + > + nb_conf =3D ethdev_ports_setup(); > + > + ethdev_rxq_configure(); > + > + ethdev_txq_configure(); > + > + ret =3D configure_graph_nodes(valid_nodes); > + if (ret) > + rte_exit(EXIT_FAILURE, "configure_graph_nodes: er= r=3D%d\n", ret); > + > + start_eth_ports(); > + > + check_all_ports_link_status(enabled_port_mask); > + > + ret =3D create_graph(node_pattern, num_patterns); > + if (ret) > + rte_exit(EXIT_FAILURE, "create_graph: err=3D%d\n"= , ret); > + > + stats =3D create_graph_cluster_stats(); > + if (stats =3D=3D NULL) > + rte_exit(EXIT_FAILURE, "create_graph_cluster_stat= s() failed\n"); > + > + /* Launch per-lcore init on every worker lcore */ > + rte_eal_mp_remote_launch(graph_main_loop, NULL, SKIP_MAIN= ); > + > + /* Accumulate and print stats on main until exit */ > + if (rte_graph_has_stats_feature()) > + print_stats(); > + > + /* Wait for worker cores to exit */ > + RTE_LCORE_FOREACH_WORKER(lcore_id) { > + ret =3D rte_eal_wait_lcore(lcore_id); > + if (ret < 0) > + break; > + } > + > + ret =3D destroy_graph(); > + > + stop_eth_ports(); > + } > + > + /* clean up the EAL */ > + ret =3D rte_eal_cleanup(); > + if (ret !=3D 0) > + rte_exit(EXIT_FAILURE, "EAL cleanup failed: %s\n", strerr= or(-ret)); > + > + return EXIT_SUCCESS; > +} > diff --git a/app/test-graph/testgraph.h b/app/test-graph/testgraph.h > new file mode 100644 > index 0000000000..b982d94781 > --- /dev/null > +++ b/app/test-graph/testgraph.h > @@ -0,0 +1,92 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#ifndef _TESTGRAPH_H_ > +#define _TESTGRAPH_H_ > + > +#include > + > +#include > +#include > +#include > + > +#include > +#include > + > + > +#define MAX_LCORE_PARAMS 1024 > +#define MAX_NODE_PATTERNS 128 > + > +#ifndef BIT_ULL > +#define BIT_ULL(nr) (1ULL << (nr)) > +#endif > + > +#define TEST_GRAPH_ETHDEV_RX_NODE BIT_ULL(0) > +#define TEST_GRAPH_ETHDEV_TX_NODE BIT_ULL(1) > +#define TEST_GRAPH_PUNT_KERNEL_NODE BIT_ULL(2) > +#define TEST_GRAPH_KERNEL_RECV_NODE BIT_ULL(3) > +#define TEST_GRAPH_IP4_LOOKUP_NODE BIT_ULL(4) > +#define TEST_GRAPH_IP4_REWRITE_NODE BIT_ULL(5) > +#define TEST_GRAPH_PKT_CLS_NODE BIT_ULL(6) > +#define TEST_GRAPH_PKT_DROP_NODE BIT_ULL(7) > +#define TEST_GRAPH_NULL_NODE BIT_ULL(8) > + > +extern uint8_t cl_quit; > +static volatile bool force_quit; > + > +extern struct rte_node_ethdev_config ethdev_conf[RTE_MAX_ETHPORTS]; > +extern uint32_t enabled_port_mask; > +extern uint32_t nb_conf; > + > +extern int promiscuous_on; /**< Ports set in promiscuous mode off= by default. */ > +extern uint8_t interactive; /**< interactive mode is disabled by d= efault. */ > +extern uint32_t enabled_port_mask; /**< Mask of enabled ports */ > +extern int numa_on; /**< NUMA is enabled by default. */ > +extern int per_port_pool; > + > +extern volatile bool graph_walk_quit; > +extern volatile bool run_graph_walk; > +extern struct rte_graph_cluster_stats *stats; > + > +extern char node_pattern[MAX_NODE_PATTERNS][RTE_NODE_NAMESIZE]; > +extern uint8_t num_patterns; > + > +struct node_list { > + const char *nodes[MAX_NODE_PATTERNS]; > + uint64_t test_id; > + uint8_t size; > +}; > + > +struct lcore_params { > + uint16_t port_id; > + uint8_t queue_id; > + uint8_t lcore_id; > +} __rte_cache_aligned; > + > +void prompt(void); > +void prompt_exit(void); > +int init_cmdline(void); > +int validate_config(void); > +int parse_cmdline_args(int argc, char **argv); > +uint32_t ethdev_ports_setup(void); > +void ethdev_rxq_configure(void); > +void ethdev_txq_configure(void); > +void start_eth_ports(void); > +void stop_eth_ports(void); > +int create_graph(char pattern[][RTE_NODE_NAMESIZE], uint8_t num_patterns= ); > +int destroy_graph(void); > +int graph_main_loop(void *conf); > +struct rte_graph_cluster_stats *create_graph_cluster_stats(void); > +void check_all_ports_link_status(uint32_t port_mask); > +int configure_graph_nodes(uint64_t valid_nodes); > + > +int parse_config(const char *q_arg); > +int parse_node_patterns(const char *q_arg); > +int validate_node_names(uint64_t *valid_nodes); > +void cleanup_node_pattern(void); > + > +#define TESTGRAPH_LOG(level, fmt, args...) = \ > + rte_log(RTE_LOG_##level, testgraph_logtype, "testgraph: " fmt, ##= args) > + > +#endif /* _TESTGRAPH_H_ */ > diff --git a/doc/guides/tools/index.rst b/doc/guides/tools/index.rst > index 6f84fc31ff..f18c508fa2 100644 > --- a/doc/guides/tools/index.rst > +++ b/doc/guides/tools/index.rst > @@ -20,6 +20,7 @@ DPDK Tools User Guides > cryptoperf > comp_perf > testeventdev > + testgraph > testregex > testmldev > dts > diff --git a/doc/guides/tools/testgraph.rst b/doc/guides/tools/testgraph.= rst > new file mode 100644 > index 0000000000..3c1e058724 > --- /dev/null > +++ b/doc/guides/tools/testgraph.rst > @@ -0,0 +1,131 @@ > +.. SPDX-License-Identifier: BSD-3-Clause > + Copyright(C) 2023 Marvell International Ltd. > + > +dpdk-test-graph Application > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > + > +The ``dpdk-test-graph`` tool is a Data Plane Development Kit (DPDK) appl= ication that allows > +exercising various graph library features. This application has a generi= c framework to add > +new test configurations and expand test coverage to verify the functiona= lity of graph nodes > +and observe the graph cluster statistics. > + > +Running the Application > +----------------------- > + > +The application has a number of command line options: > + > +.. code-block:: console > + > + dpdk-test-eventdev [EAL Options] -- [application options] > + > +EAL Options > +~~~~~~~~~~~ > + > +The following are the EAL command-line options that can be used in conju= nction > +with the ``dpdk-test-graph`` application. > +See the DPDK Getting Started Guides for more information on these option= s. > + > +* ``-c `` or ``-l `` > + > + Set the hexadecimal bitmask of the cores to run on. The corelist= is a > + list of cores to use. > + > +Application Options > +~~~~~~~~~~~~~~~~~~~ > + > +The following are the application command-line options: > + > +* ``-p `` > + > + Set the ethdev port mask. > + > +* ``-P`` > + > + Set the ethdev ports in promiscuous mode. > + > +* ``--config `` > + > + Set the Rxq configuration. > + (i.e. ``--config (port_id,rxq,lcore_id)[,(port_id,rxq,lcore_id)]= ``). > + > +* ``--node-pattern `` > + > + Set the node patterns to use in graph creation. > + (i.e. ``--node-pattern (node_name0,node_name1[,node_nameX])``). > + > +* ``--per-port-pool`` > + > + Use separate buffer pool per port. > + > +* ``--no-numa`` > + > + Disable numa awareness. > + > +* ``--interactive`` > + > + Switch to interactive mode. > + > +Running the Tool > +~~~~~~~~~~~~~~~~ > + > +Here is the sample command line to run simple iofwd test:: > + > + ./dpdk-test-graph -a 0002:03:00.0 -a 0002:04:00.0 -c 0xF -- -p 0= x3 -P \ > + --config "(0,0,2),(1,0,2)" --node-pattern "(ethdev_rx,ethdev_tx)" > + > +Below is a sample command line to punt rx packets to kernel:: > + > + ./dpdk-test-graph -a 0002:03:00.0 -a 0002:04:00.0 -c 0xF -- -p 0= x3 -P \ > + --config "(0,0,2),(1,0,2)" --node-pattern "(ethdev_rx,punt_kernel= )" > + > +Interactive mode > +~~~~~~~~~~~~~~~~ > + > +Tool uses ``--interactive`` command line option to enter interactive mod= e and use cmdline options > +to setup the required node configurations, create graph and than start g= raph_walk. > + > + > +testgraph> help > + > +Help is available for the following sections: > + > + help control : Start and stop graph walk. > + help display : Displaying port, stats and config = information. > + help config : Configuration information. > + help all : All of the above sections. > + > +testgraph> help all > + > +Control forwarding: > + > +start graph_walk > + Start graph_walk on worker threads. > + > +stop graph_walk > + Stop worker threads from running graph_walk. > + > +quit > + Quit to prompt. > + > + > +Display: > + > +show node_list > + Display the list of supported nodes. > + > +show graph_stats > + Display the node statistics of graph cluster. > + > + > +Configuration: > + > +set lcore_config (port_id0,rxq0,lcore_idX),........,(port_idX,rxqX,lcore= idY) > + Set lcore configuration. > + > +create_graph (node0_name,node1_name,...,nodeX_name) > + Create graph instances using the provided node details. > + > +destroy_graph > + Destroy the graph instances. > + > +testgraph> > -- > 2.25.1 >