examples/qos_sched: add TC and queue config flexibility
[dpdk.git] / examples / qos_sched / cfg_file.c
index 94a1a22..45bf599 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 
 #include <stdio.h>
@@ -58,6 +29,9 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
        if (!cfg || !port_params)
                return -1;
 
+       memset(active_queues, 0, sizeof(active_queues));
+       n_active_queues = 0;
+
        entry = rte_cfgfile_get_entry(cfg, "port", "frame overhead");
        if (entry)
                port_params->frame_overhead = (uint32_t)atoi(entry);
@@ -74,12 +48,25 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
        if (entry) {
                char *next;
 
-               for(j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
+               for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
                        port_params->qsize[j] = (uint16_t)strtol(entry, &next, 10);
                        if (next == NULL)
                                break;
                        entry = next;
                }
+
+               for (j = 0; j < RTE_SCHED_TRAFFIC_CLASS_BE; j++)
+                       if (port_params->qsize[j]) {
+                               active_queues[n_active_queues] = j;
+                               n_active_queues++;
+                       }
+
+               if (port_params->qsize[RTE_SCHED_TRAFFIC_CLASS_BE])
+                       for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
+                               active_queues[n_active_queues] =
+                                       RTE_SCHED_TRAFFIC_CLASS_BE + j;
+                               n_active_queues++;
+                       }
        }
 
 #ifdef RTE_SCHED_RED
@@ -93,7 +80,7 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
                        char *next;
                        int k;
                        /* for each packet colour (green, yellow, red) */
-                       for (k = 0; k < e_RTE_METER_COLORS; k++) {
+                       for (k = 0; k < RTE_COLORS; k++) {
                                port_params->red_params[j][k].min_th
                                        = (uint16_t)strtol(entry, &next, 10);
                                if (next == NULL)
@@ -109,7 +96,7 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
                        char *next;
                        int k;
                        /* for each packet colour (green, yellow, red) */
-                       for (k = 0; k < e_RTE_METER_COLORS; k++) {
+                       for (k = 0; k < RTE_COLORS; k++) {
                                port_params->red_params[j][k].max_th
                                        = (uint16_t)strtol(entry, &next, 10);
                                if (next == NULL)
@@ -125,7 +112,7 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
                        char *next;
                        int k;
                        /* for each packet colour (green, yellow, red) */
-                       for (k = 0; k < e_RTE_METER_COLORS; k++) {
+                       for (k = 0; k < RTE_COLORS; k++) {
                                port_params->red_params[j][k].maxp_inv
                                        = (uint8_t)strtol(entry, &next, 10);
 
@@ -142,7 +129,7 @@ cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params
                        char *next;
                        int k;
                        /* for each packet colour (green, yellow, red) */
-                       for (k = 0; k < e_RTE_METER_COLORS; k++) {
+                       for (k = 0; k < RTE_COLORS; k++) {
                                port_params->red_params[j][k].wq_log2
                                        = (uint8_t)strtol(entry, &next, 10);
                                if (next == NULL)
@@ -202,46 +189,50 @@ cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params *pipe_params
                if (entry)
                        pipe_params[j].tc_rate[3] = (uint32_t)atoi(entry);
 
-#ifdef RTE_SCHED_SUBPORT_TC_OV
-               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 oversubscription weight");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 4 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[4] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 5 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[5] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 6 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[6] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 7 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[7] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 8 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[8] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 9 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[9] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 10 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[10] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 11 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[11] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 rate");
+               if (entry)
+                       pipe_params[j].tc_rate[12] = (uint32_t)atoi(entry);
+
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 oversubscription weight");
                if (entry)
                        pipe_params[j].tc_ov_weight = (uint8_t)atoi(entry);
-#endif
 
-               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 wrr weights");
-               if (entry) {
-                       for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
-                               pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*0 + i] =
-                                       (uint8_t)strtol(entry, &next, 10);
-                               if (next == NULL)
-                                       break;
-                               entry = next;
-                       }
-               }
-               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 wrr weights");
-               if (entry) {
-                       for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
-                               pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*1 + i] =
-                                       (uint8_t)strtol(entry, &next, 10);
-                               if (next == NULL)
-                                       break;
-                               entry = next;
-                       }
-               }
-               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 wrr weights");
-               if (entry) {
-                       for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
-                               pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*2 + i] =
-                                       (uint8_t)strtol(entry, &next, 10);
-                               if (next == NULL)
-                                       break;
-                               entry = next;
-                       }
-               }
-               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 wrr weights");
+               entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 wrr weights");
                if (entry) {
-                       for(i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
-                               pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE*3 + i] =
+                       for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
+                               pipe_params[j].wrr_weights[i] =
                                        (uint8_t)strtol(entry, &next, 10);
                                if (next == NULL)
                                        break;
@@ -296,6 +287,42 @@ cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subpo
                        if (entry)
                                subport_params[i].tc_rate[3] = (uint32_t)atoi(entry);
 
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 4 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[4] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 5 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[5] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 6 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[6] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 7 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[7] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 8 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[8] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 9 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[9] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 10 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[10] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 11 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[11] = (uint32_t)atoi(entry);
+
+                       entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 12 rate");
+                       if (entry)
+                               subport_params[i].tc_rate[12] = (uint32_t)atoi(entry);
+
                        int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
                        struct rte_cfgfile_entry entries[n_entries];