Modify the ip_pipeline application to build the hierarchical scheduler
with default subport bandwidth profile. It also allows to update
a subport with different subport rates dynamically

Signed-off-by: Savinay Dharmappa <savinay.dharma...@intel.com>
---
 examples/ip_pipeline/cli.c  |  68 ++++++++------------
 examples/ip_pipeline/tmgr.c | 121 ++++++++++++++++++++++++++++++------
 examples/ip_pipeline/tmgr.h |   5 +-
 3 files changed, 134 insertions(+), 60 deletions(-)

diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c
index dafc95ae9..6b62a3271 100644
--- a/examples/ip_pipeline/cli.c
+++ b/examples/ip_pipeline/cli.c
@@ -393,12 +393,7 @@ static const char cmd_tmgr_subport_profile_help[] =
 "   <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
 "        <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
 "        <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
-"   <tc_period>\n"
-"   pps <n_pipes_per_subport>\n"
-"   qsize <qsize_tc0> <qsize_tc1> <qsize_tc2>"
-"       <qsize_tc3> <qsize_tc4> <qsize_tc5> <qsize_tc6>"
-"       <qsize_tc7> <qsize_tc8> <qsize_tc9> <qsize_tc10>"
-"       <qsize_tc11> <qsize_tc12>";
+"   <tc_period>\n";
 
 static void
 cmd_tmgr_subport_profile(char **tokens,
@@ -406,57 +401,37 @@ cmd_tmgr_subport_profile(char **tokens,
        char *out,
        size_t out_size)
 {
-       struct rte_sched_subport_params p;
+       struct rte_sched_subport_profile_params subport_profile;
        int status, i;
 
-       if (n_tokens != 35) {
+       if (n_tokens != 21) {
                snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
                return;
        }
 
-       if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
+       if (parser_read_uint64(&subport_profile.tb_rate, tokens[3]) != 0) {
                snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
                return;
        }
 
-       if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
+       if (parser_read_uint64(&subport_profile.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_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
+               if (parser_read_uint64(&subport_profile.tc_rate[i],
+                               tokens[5 + i]) != 0) {
                        snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
                        return;
                }
 
-       if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
+       if (parser_read_uint64(&subport_profile.tc_period, tokens[18]) != 0) {
                snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
                return;
        }
 
-       if (strcmp(tokens[19], "pps") != 0) {
-               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
-               return;
-       }
-
-       if (parser_read_uint32(&p.n_pipes_per_subport_enabled, tokens[20]) != 
0) {
-               snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
-               return;
-       }
-
-       if (strcmp(tokens[21], "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[22 + i]) != 0) {
-                       snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
-                       return;
-               }
-
-       status = tmgr_subport_profile_add(&p);
+       status = tmgr_subport_profile_add(&subport_profile);
        if (status != 0) {
                snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
                return;
@@ -530,6 +505,7 @@ static const char cmd_tmgr_help[] =
 "tmgr <tmgr_name>\n"
 "   rate <rate>\n"
 "   spp <n_subports_per_port>\n"
+"   pps <n_pipes_per_subport>\n"
 "   fo <frame_overhead>\n"
 "   mtu <mtu>\n"
 "   cpu <cpu_id>\n";
@@ -544,7 +520,7 @@ cmd_tmgr(char **tokens,
        char *name;
        struct tmgr_port *tmgr_port;
 
-       if (n_tokens != 12) {
+       if (n_tokens != 14) {
                snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
                return;
        }
@@ -571,32 +547,42 @@ cmd_tmgr(char **tokens,
                return;
        }
 
-       if (strcmp(tokens[6], "fo") != 0) {
+       if (strcmp(tokens[6], "pps") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
+               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], "fo") != 0) {
                snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
                return;
        }
 
-       if (parser_read_uint32(&p.frame_overhead, tokens[7]) != 0) {
+       if (parser_read_uint32(&p.frame_overhead, tokens[9]) != 0) {
                snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
                return;
        }
 
-       if (strcmp(tokens[8], "mtu") != 0) {
+       if (strcmp(tokens[10], "mtu") != 0) {
                snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
                return;
        }
 
-       if (parser_read_uint32(&p.mtu, tokens[9]) != 0) {
+       if (parser_read_uint32(&p.mtu, tokens[11]) != 0) {
                snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
                return;
        }
 
-       if (strcmp(tokens[10], "cpu") != 0) {
+       if (strcmp(tokens[12], "cpu") != 0) {
                snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
                return;
        }
 
-       if (parser_read_uint32(&p.cpu_id, tokens[11]) != 0) {
+       if (parser_read_uint32(&p.cpu_id, tokens[13]) != 0) {
                snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
                return;
        }
diff --git a/examples/ip_pipeline/tmgr.c b/examples/ip_pipeline/tmgr.c
index 46c6a83a4..ef8c30bdf 100644
--- a/examples/ip_pipeline/tmgr.c
+++ b/examples/ip_pipeline/tmgr.c
@@ -4,11 +4,12 @@
 
 #include <stdlib.h>
 
+#include <rte_common.h>
 #include <rte_string_fns.h>
 
 #include "tmgr.h"
 
-static struct rte_sched_subport_params
+static struct rte_sched_subport_profile_params
        subport_profile[TMGR_SUBPORT_PROFILE_MAX];
 
 static uint32_t n_subport_profiles;
@@ -18,6 +19,82 @@ static struct rte_sched_pipe_params
 
 static uint32_t n_pipe_profiles;
 
+static const struct rte_sched_subport_params subport_params_default = {
+       .n_pipes_per_subport_enabled = 0, /* filled at runtime */
+       .qsize = {64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
+       .pipe_profiles = pipe_profile,
+       .n_pipe_profiles = 0, /* filled at run time */
+       .n_max_pipe_profiles = RTE_DIM(pipe_profile),
+#ifdef RTE_SCHED_RED
+.red_params = {
+       /* Traffic Class 0 Colors Green / Yellow / Red */
+       [0][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [0][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [0][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 1 - Colors Green / Yellow / Red */
+       [1][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [1][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [1][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 2 - Colors Green / Yellow / Red */
+       [2][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [2][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [2][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 3 - Colors Green / Yellow / Red */
+       [3][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [3][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [3][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 4 - Colors Green / Yellow / Red */
+       [4][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [4][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [4][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 5 - Colors Green / Yellow / Red */
+       [5][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [5][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [5][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 6 - Colors Green / Yellow / Red */
+       [6][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [6][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [6][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 7 - Colors Green / Yellow / Red */
+       [7][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [7][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [7][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 8 - Colors Green / Yellow / Red */
+       [8][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [8][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [8][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 9 - Colors Green / Yellow / Red */
+       [9][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [9][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [9][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 10 - Colors Green / Yellow / Red */
+       [10][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [10][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [10][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 11 - Colors Green / Yellow / Red */
+       [11][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [11][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [11][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+
+       /* Traffic Class 12 - Colors Green / Yellow / Red */
+       [12][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [12][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       [12][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
+       },
+#endif /* RTE_SCHED_RED */
+};
+
 static struct tmgr_port_list tmgr_port_list;
 
 int
@@ -44,17 +121,16 @@ tmgr_port_find(const char *name)
 }
 
 int
-tmgr_subport_profile_add(struct rte_sched_subport_params *p)
+tmgr_subport_profile_add(struct rte_sched_subport_profile_params *params)
 {
        /* Check input params */
-       if (p == NULL ||
-               p->n_pipes_per_subport_enabled == 0)
+       if (params == NULL)
                return -1;
 
        /* Save profile */
        memcpy(&subport_profile[n_subport_profiles],
-               p,
-               sizeof(*p));
+               &params,
+               sizeof(params));
 
        n_subport_profiles++;
 
@@ -81,6 +157,7 @@ tmgr_pipe_profile_add(struct rte_sched_pipe_params *p)
 struct tmgr_port *
 tmgr_port_create(const char *name, struct tmgr_port_params *params)
 {
+       struct rte_sched_subport_params subport_params;
        struct rte_sched_port_params p;
        struct tmgr_port *tmgr_port;
        struct rte_sched_port *s;
@@ -91,6 +168,7 @@ tmgr_port_create(const char *name, struct tmgr_port_params 
*params)
                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))
@@ -103,15 +181,22 @@ tmgr_port_create(const char *name, struct 
tmgr_port_params *params)
        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 = TMGR_PIPE_SUBPORT_MAX;
+       p.n_subport_profiles = n_subport_profiles;
+       p.subport_profiles = subport_profile;
+       p.n_max_subport_profiles = TMGR_SUBPORT_PROFILE_MAX;
+       p.n_pipes_per_subport = params->n_pipes_per_subport;
+
 
        s = rte_sched_port_config(&p);
        if (s == NULL)
                return NULL;
 
-       subport_profile[0].pipe_profiles = pipe_profile;
-       subport_profile[0].n_pipe_profiles = n_pipe_profiles;
-       subport_profile[0].n_max_pipe_profiles = TMGR_PIPE_PROFILE_MAX;
+       memcpy(&subport_params, &subport_params_default,
+               sizeof(subport_params_default));
+
+       subport_params.n_pipe_profiles = n_pipe_profiles;
+       subport_params.n_pipes_per_subport_enabled =
+                                               params->n_pipes_per_subport;
 
        for (i = 0; i < params->n_subports_per_port; i++) {
                int status;
@@ -119,7 +204,7 @@ tmgr_port_create(const char *name, struct tmgr_port_params 
*params)
                status = rte_sched_subport_config(
                        s,
                        i,
-                       &subport_profile[0],
+                       &subport_params,
                        0);
 
                if (status) {
@@ -127,7 +212,8 @@ tmgr_port_create(const char *name, struct tmgr_port_params 
*params)
                        return NULL;
                }
 
-               for (j = 0; j < subport_profile[0].n_pipes_per_subport_enabled; 
j++) {
+               for (j = 0; j < params->n_pipes_per_subport; j++) {
+
                        status = rte_sched_pipe_config(
                                s,
                                i,
@@ -152,6 +238,7 @@ tmgr_port_create(const char *name, struct tmgr_port_params 
*params)
        strlcpy(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);
@@ -181,8 +268,8 @@ tmgr_subport_config(const char *port_name,
        status = rte_sched_subport_config(
                port->s,
                subport_id,
-               &subport_profile[subport_profile_id],
-               0);
+               NULL,
+               subport_profile_id);
 
        return status;
 }
@@ -204,10 +291,8 @@ tmgr_pipe_config(const char *port_name,
        port = tmgr_port_find(port_name);
        if ((port == NULL) ||
                (subport_id >= port->n_subports_per_port) ||
-               (pipe_id_first >=
-                       
subport_profile[subport_id].n_pipes_per_subport_enabled) ||
-               (pipe_id_last >=
-                       
subport_profile[subport_id].n_pipes_per_subport_enabled) ||
+               (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;
diff --git a/examples/ip_pipeline/tmgr.h b/examples/ip_pipeline/tmgr.h
index ee50cf7cc..1994c55bc 100644
--- a/examples/ip_pipeline/tmgr.h
+++ b/examples/ip_pipeline/tmgr.h
@@ -9,6 +9,7 @@
 #include <sys/queue.h>
 
 #include <rte_sched.h>
+#include <rte_red.h>
 
 #include "common.h"
 
@@ -29,6 +30,7 @@ struct tmgr_port {
        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);
@@ -42,13 +44,14 @@ tmgr_port_find(const char *name);
 struct tmgr_port_params {
        uint64_t rate;
        uint32_t n_subports_per_port;
+       uint32_t n_pipes_per_subport;
        uint32_t frame_overhead;
        uint32_t mtu;
        uint32_t cpu_id;
 };
 
 int
-tmgr_subport_profile_add(struct rte_sched_subport_params *p);
+tmgr_subport_profile_add(struct rte_sched_subport_profile_params *sp);
 
 int
 tmgr_pipe_profile_add(struct rte_sched_pipe_params *p);
-- 
2.17.1

Reply via email to