From patchwork Fri Mar 9 18:24:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 35893 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 16038AAD5; Fri, 9 Mar 2018 19:24:52 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3D2DD726F for ; Fri, 9 Mar 2018 19:24:46 +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:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,446,1515484800"; d="scan'208";a="181382312" 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:45 -0800 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 9 Mar 2018 18:24:04 +0000 Message-Id: <20180309182426.135278-16-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 15/37] ip_pipeline: add traffic manager 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 traffic manager object implementation to the application. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- examples/ip_pipeline/Makefile | 1 + examples/ip_pipeline/cli.c | 360 +++++++++++++++++++++++++++++++++++++++ examples/ip_pipeline/main.c | 8 + examples/ip_pipeline/meson.build | 1 + examples/ip_pipeline/tmgr.c | 227 ++++++++++++++++++++++++ examples/ip_pipeline/tmgr.h | 70 ++++++++ 6 files changed, 667 insertions(+) create mode 100644 examples/ip_pipeline/tmgr.c create mode 100644 examples/ip_pipeline/tmgr.h diff --git a/examples/ip_pipeline/Makefile b/examples/ip_pipeline/Makefile index 0dc8442..35e4302 100644 --- a/examples/ip_pipeline/Makefile +++ b/examples/ip_pipeline/Makefile @@ -12,6 +12,7 @@ SRCS-y += main.c SRCS-y += mempool.c SRCS-y += parser.c SRCS-y += swq.c +SRCS-y += tmgr.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 8e78a40..99e42c9 100644 --- a/examples/ip_pipeline/cli.c +++ b/examples/ip_pipeline/cli.c @@ -14,6 +14,7 @@ #include "mempool.h" #include "parser.h" #include "swq.h" +#include "tmgr.h" #ifndef CMD_MAX_TOKENS #define CMD_MAX_TOKENS 256 @@ -277,6 +278,331 @@ cmd_swq(char **tokens, } } +/** + * tmgr subport profile + * + * + * + */ +static void +cmd_tmgr_subport_profile(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct rte_sched_subport_params p; + int status, i; + + if (n_tokens != 10) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate"); + return; + } + + if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_size"); + return; + } + + for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) + if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate"); + return; + } + + if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tc_period"); + return; + } + + status = tmgr_subport_profile_add(&p); + if (status != 0) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + +/** + * tmgr pipe profile + * + * + * + * + * + */ +static void +cmd_tmgr_pipe_profile(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct rte_sched_pipe_params p; + int status, i; + + if (n_tokens != 27) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate"); + return; + } + + if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_size"); + return; + } + + for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) + if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate"); + return; + } + + if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tc_period"); + return; + } + +#ifdef RTE_SCHED_SUBPORT_TC_OV + if (parser_read_uint32(&p.tc_ov_weight, tokens[10]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight"); + return; + } +#endif + + for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) + if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights"); + return; + } + + status = tmgr_pipe_profile_add(&p); + if (status != 0) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + +/** + * tmgr + * rate + * spp + * pps + * qsize + * fo + * mtu + * cpu + */ +static void +cmd_tmgr(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct tmgr_port_params p; + char *name; + struct tmgr_port *tmgr_port; + int i; + + if (n_tokens != 19) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + name = tokens[1]; + + if (strcmp(tokens[2], "rate") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate"); + return; + } + + if (parser_read_uint32(&p.rate, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "rate"); + return; + } + + if (strcmp(tokens[4], "spp") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp"); + return; + } + + if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port"); + return; + } + + if (strcmp(tokens[6], "pps") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps"); + return; + } + + if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport"); + return; + } + + if (strcmp(tokens[8], "qsize") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize"); + return; + } + + for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) + if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "qsize"); + return; + } + + if (strcmp(tokens[13], "fo") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo"); + return; + } + + if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead"); + return; + } + + if (strcmp(tokens[15], "mtu") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu"); + return; + } + + if (parser_read_uint32(&p.mtu, tokens[16]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "mtu"); + return; + } + + if (strcmp(tokens[17], "cpu") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu"); + return; + } + + if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id"); + return; + } + + tmgr_port = tmgr_port_create(name, &p); + if (tmgr_port == NULL) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + +/** + * tmgr subport + * profile + */ +static void +cmd_tmgr_subport(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + uint32_t subport_id, subport_profile_id; + int status; + char *name; + + if (n_tokens != 6) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + name = tokens[1]; + + if (parser_read_uint32(&subport_id, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "subport_id"); + return; + } + + if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id"); + return; + } + + status = tmgr_subport_config(name, subport_id, subport_profile_id); + if (status) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + +/** + * tmgr subport pipe + * from to + * profile + */ +static void +cmd_tmgr_subport_pipe(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id; + int status; + char *name; + + if (n_tokens != 11) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + name = tokens[1]; + + if (parser_read_uint32(&subport_id, tokens[3]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "subport_id"); + return; + } + + if (strcmp(tokens[4], "pipe") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe"); + return; + } + + if (strcmp(tokens[5], "from") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); + return; + } + + if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first"); + return; + } + + if (strcmp(tokens[7], "to") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); + return; + } + + if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last"); + return; + } + + if (strcmp(tokens[9], "profile") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); + return; + } + + if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id"); + return; + } + + status = tmgr_pipe_config(name, subport_id, pipe_id_first, + pipe_id_last, pipe_profile_id); + if (status) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + void cli_process(char *in, char *out, size_t out_size) { @@ -311,6 +637,40 @@ cli_process(char *in, char *out, size_t out_size) return; } + if (strcmp(tokens[0], "tmgr") == 0) { + if ((n_tokens >= 3) && + (strcmp(tokens[1], "subport") == 0) && + (strcmp(tokens[2], "profile") == 0)) { + cmd_tmgr_subport_profile(tokens, n_tokens, + out, out_size); + return; + } + + if ((n_tokens >= 3) && + (strcmp(tokens[1], "pipe") == 0) && + (strcmp(tokens[2], "profile") == 0)) { + cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size); + return; + } + + if ((n_tokens >= 5) && + (strcmp(tokens[2], "subport") == 0) && + (strcmp(tokens[4], "profile") == 0)) { + cmd_tmgr_subport(tokens, n_tokens, out, out_size); + return; + } + + if ((n_tokens >= 5) && + (strcmp(tokens[2], "subport") == 0) && + (strcmp(tokens[4], "pipe") == 0)) { + cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size); + return; + } + + cmd_tmgr(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 456f016..490991f 100644 --- a/examples/ip_pipeline/main.c +++ b/examples/ip_pipeline/main.c @@ -15,6 +15,7 @@ #include "link.h" #include "mempool.h" #include "swq.h" +#include "tmgr.h" static const char usage[] = "%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n"; @@ -183,6 +184,13 @@ main(int argc, char **argv) return status; } + /* Traffic Manager */ + status = tmgr_init(); + if (status) { + printf("Error: TMGR 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 442f3e3..cb2154c 100644 --- a/examples/ip_pipeline/meson.build +++ b/examples/ip_pipeline/meson.build @@ -15,4 +15,5 @@ sources = files( 'mempool.c', 'parser.c', 'swq.c', + 'tmgr.c' ) diff --git a/examples/ip_pipeline/tmgr.c b/examples/ip_pipeline/tmgr.c new file mode 100644 index 0000000..b46ca96 --- /dev/null +++ b/examples/ip_pipeline/tmgr.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include + +#include "tmgr.h" + +static struct rte_sched_subport_params + subport_profile[TMGR_SUBPORT_PROFILE_MAX]; + +static uint32_t n_subport_profiles; + +static struct rte_sched_pipe_params + pipe_profile[TMGR_PIPE_PROFILE_MAX]; + +static uint32_t n_pipe_profiles; + +static struct tmgr_port_list tmgr_port_list; + +int +tmgr_init(void) +{ + TAILQ_INIT(&tmgr_port_list); + + return 0; +} + +struct tmgr_port * +tmgr_port_find(const char *name) +{ + struct tmgr_port *tmgr_port; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(tmgr_port, &tmgr_port_list, node) + if (strcmp(tmgr_port->name, name) == 0) + return tmgr_port; + + return NULL; +} + +int +tmgr_subport_profile_add(struct rte_sched_subport_params *p) +{ + /* Check input params */ + if (p == NULL) + return -1; + + /* Save profile */ + memcpy(&subport_profile[n_subport_profiles], + p, + sizeof(*p)); + + n_subport_profiles++; + + return 0; +} + +int +tmgr_pipe_profile_add(struct rte_sched_pipe_params *p) +{ + /* Check input params */ + if (p == NULL) + return -1; + + /* Save profile */ + memcpy(&pipe_profile[n_pipe_profiles], + p, + sizeof(*p)); + + n_pipe_profiles++; + + return 0; +} + +struct tmgr_port * +tmgr_port_create(const char *name, struct tmgr_port_params *params) +{ + struct rte_sched_port_params p; + struct tmgr_port *tmgr_port; + struct rte_sched_port *s; + uint32_t i, j; + + /* Check input params */ + if ((name == NULL) || + tmgr_port_find(name) || + (params == NULL) || + (params->n_subports_per_port == 0) || + (params->n_pipes_per_subport == 0) || + (params->cpu_id >= RTE_MAX_NUMA_NODES) || + (n_subport_profiles == 0) || + (n_pipe_profiles == 0)) + return NULL; + + /* Resource create */ + p.name = name; + p.socket = (int) params->cpu_id; + p.rate = params->rate; + p.mtu = params->mtu; + p.frame_overhead = params->frame_overhead; + p.n_subports_per_port = params->n_subports_per_port; + p.n_pipes_per_subport = params->n_pipes_per_subport; + + for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) + p.qsize[i] = params->qsize[i]; + + p.pipe_profiles = pipe_profile; + p.n_pipe_profiles = n_pipe_profiles; + + s = rte_sched_port_config(&p); + if (s == NULL) + return NULL; + + for (i = 0; i < params->n_subports_per_port; i++) { + int status; + + status = rte_sched_subport_config( + s, + i, + &subport_profile[0]); + + if (status) { + rte_sched_port_free(s); + return NULL; + } + + for (j = 0; j < params->n_pipes_per_subport; j++) { + status = rte_sched_pipe_config( + s, + i, + j, + 0); + + if (status) { + rte_sched_port_free(s); + return NULL; + } + } + } + + /* Node allocation */ + tmgr_port = calloc(1, sizeof(struct tmgr_port)); + if (tmgr_port == NULL) { + rte_sched_port_free(s); + return NULL; + } + + /* Node fill in */ + strncpy(tmgr_port->name, name, sizeof(tmgr_port->name)); + tmgr_port->s = s; + tmgr_port->n_subports_per_port = params->n_subports_per_port; + tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&tmgr_port_list, tmgr_port, node); + + return tmgr_port; +} + +int +tmgr_subport_config(const char *port_name, + uint32_t subport_id, + uint32_t subport_profile_id) +{ + struct tmgr_port *port; + int status; + + /* Check input params */ + if (port_name == NULL) + return -1; + + port = tmgr_port_find(port_name); + if ((port == NULL) || + (subport_id >= port->n_subports_per_port) || + (subport_profile_id >= n_subport_profiles)) + return -1; + + /* Resource config */ + status = rte_sched_subport_config( + port->s, + subport_id, + &subport_profile[subport_profile_id]); + + return status; +} + +int +tmgr_pipe_config(const char *port_name, + uint32_t subport_id, + uint32_t pipe_id_first, + uint32_t pipe_id_last, + uint32_t pipe_profile_id) +{ + struct tmgr_port *port; + uint32_t i; + + /* Check input params */ + if (port_name == NULL) + return -1; + + port = tmgr_port_find(port_name); + if ((port == NULL) || + (subport_id >= port->n_subports_per_port) || + (pipe_id_first >= port->n_pipes_per_subport) || + (pipe_id_last >= port->n_pipes_per_subport) || + (pipe_id_first > pipe_id_last) || + (pipe_profile_id >= n_pipe_profiles)) + return -1; + + /* Resource config */ + for (i = pipe_id_first; i <= pipe_id_last; i++) { + int status; + + status = rte_sched_pipe_config( + port->s, + subport_id, + i, + (int) pipe_profile_id); + + if (status) + return status; + } + + return 0; +} diff --git a/examples/ip_pipeline/tmgr.h b/examples/ip_pipeline/tmgr.h new file mode 100644 index 0000000..0b497e7 --- /dev/null +++ b/examples/ip_pipeline/tmgr.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#ifndef _INCLUDE_TMGR_H_ +#define _INCLUDE_TMGR_H_ + +#include +#include + +#include + +#include "common.h" + +#ifndef TMGR_SUBPORT_PROFILE_MAX +#define TMGR_SUBPORT_PROFILE_MAX 256 +#endif + +#ifndef TMGR_PIPE_PROFILE_MAX +#define TMGR_PIPE_PROFILE_MAX 256 +#endif + +struct tmgr_port { + TAILQ_ENTRY(tmgr_port) node; + char name[NAME_SIZE]; + struct rte_sched_port *s; + uint32_t n_subports_per_port; + uint32_t n_pipes_per_subport; +}; + +TAILQ_HEAD(tmgr_port_list, tmgr_port); + +int +tmgr_init(void); + +struct tmgr_port * +tmgr_port_find(const char *name); + +struct tmgr_port_params { + uint32_t rate; + uint32_t n_subports_per_port; + uint32_t n_pipes_per_subport; + uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE]; + uint32_t frame_overhead; + uint32_t mtu; + uint32_t cpu_id; +}; + +int +tmgr_subport_profile_add(struct rte_sched_subport_params *p); + +int +tmgr_pipe_profile_add(struct rte_sched_pipe_params *p); + +struct tmgr_port * +tmgr_port_create(const char *name, struct tmgr_port_params *params); + +int +tmgr_subport_config(const char *port_name, + uint32_t subport_id, + uint32_t subport_profile_id); + +int +tmgr_pipe_config(const char *port_name, + uint32_t subport_id, + uint32_t pipe_id_first, + uint32_t pipe_id_last, + uint32_t pipe_profile_id); + +#endif /* _INCLUDE_TMGR_H_ */