1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include <rte_string_fns.h>
10 #include <rte_sched.h>
16 /** when we resize a file structure, how many extra entries
17 * for new sections do we add in */
18 #define CFG_ALLOC_SECTION_BATCH 8
19 /** when we resize a section structure, how many extra entries
20 * for new entries do we add in */
21 #define CFG_ALLOC_ENTRY_BATCH 16
24 cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params)
29 if (!cfg || !port_params)
32 memset(active_queues, 0, sizeof(active_queues));
35 entry = rte_cfgfile_get_entry(cfg, "port", "frame overhead");
37 port_params->frame_overhead = (uint32_t)atoi(entry);
39 entry = rte_cfgfile_get_entry(cfg, "port", "number of subports per port");
41 port_params->n_subports_per_port = (uint32_t)atoi(entry);
43 entry = rte_cfgfile_get_entry(cfg, "port", "number of pipes per subport");
45 port_params->n_pipes_per_subport = (uint32_t)atoi(entry);
47 entry = rte_cfgfile_get_entry(cfg, "port", "queue sizes");
51 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
52 port_params->qsize[j] = (uint16_t)strtol(entry, &next, 10);
58 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASS_BE; j++)
59 if (port_params->qsize[j]) {
60 active_queues[n_active_queues] = j;
64 if (port_params->qsize[RTE_SCHED_TRAFFIC_CLASS_BE])
65 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
66 active_queues[n_active_queues] =
67 RTE_SCHED_TRAFFIC_CLASS_BE + j;
73 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
76 /* Parse WRED min thresholds */
77 snprintf(str, sizeof(str), "tc %d wred min", j);
78 entry = rte_cfgfile_get_entry(cfg, "red", str);
82 /* for each packet colour (green, yellow, red) */
83 for (k = 0; k < RTE_COLORS; k++) {
84 port_params->red_params[j][k].min_th
85 = (uint16_t)strtol(entry, &next, 10);
92 /* Parse WRED max thresholds */
93 snprintf(str, sizeof(str), "tc %d wred max", j);
94 entry = rte_cfgfile_get_entry(cfg, "red", str);
98 /* for each packet colour (green, yellow, red) */
99 for (k = 0; k < RTE_COLORS; k++) {
100 port_params->red_params[j][k].max_th
101 = (uint16_t)strtol(entry, &next, 10);
108 /* Parse WRED inverse mark probabilities */
109 snprintf(str, sizeof(str), "tc %d wred inv prob", j);
110 entry = rte_cfgfile_get_entry(cfg, "red", str);
114 /* for each packet colour (green, yellow, red) */
115 for (k = 0; k < RTE_COLORS; k++) {
116 port_params->red_params[j][k].maxp_inv
117 = (uint8_t)strtol(entry, &next, 10);
125 /* Parse WRED EWMA filter weights */
126 snprintf(str, sizeof(str), "tc %d wred weight", j);
127 entry = rte_cfgfile_get_entry(cfg, "red", str);
131 /* for each packet colour (green, yellow, red) */
132 for (k = 0; k < RTE_COLORS; k++) {
133 port_params->red_params[j][k].wq_log2
134 = (uint8_t)strtol(entry, &next, 10);
141 #endif /* RTE_SCHED_RED */
147 cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params *pipe_params)
154 if (!cfg || !pipe_params)
157 profiles = rte_cfgfile_num_sections(cfg, "pipe profile", sizeof("pipe profile") - 1);
158 port_params.n_pipe_profiles = profiles;
160 for (j = 0; j < profiles; j++) {
162 snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", j);
164 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb rate");
166 pipe_params[j].tb_rate = (uint32_t)atoi(entry);
168 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb size");
170 pipe_params[j].tb_size = (uint32_t)atoi(entry);
172 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc period");
174 pipe_params[j].tc_period = (uint32_t)atoi(entry);
176 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 rate");
178 pipe_params[j].tc_rate[0] = (uint32_t)atoi(entry);
180 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 rate");
182 pipe_params[j].tc_rate[1] = (uint32_t)atoi(entry);
184 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 rate");
186 pipe_params[j].tc_rate[2] = (uint32_t)atoi(entry);
188 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 rate");
190 pipe_params[j].tc_rate[3] = (uint32_t)atoi(entry);
192 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 4 rate");
194 pipe_params[j].tc_rate[4] = (uint32_t)atoi(entry);
196 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 5 rate");
198 pipe_params[j].tc_rate[5] = (uint32_t)atoi(entry);
200 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 6 rate");
202 pipe_params[j].tc_rate[6] = (uint32_t)atoi(entry);
204 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 7 rate");
206 pipe_params[j].tc_rate[7] = (uint32_t)atoi(entry);
208 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 8 rate");
210 pipe_params[j].tc_rate[8] = (uint32_t)atoi(entry);
212 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 9 rate");
214 pipe_params[j].tc_rate[9] = (uint32_t)atoi(entry);
216 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 10 rate");
218 pipe_params[j].tc_rate[10] = (uint32_t)atoi(entry);
220 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 11 rate");
222 pipe_params[j].tc_rate[11] = (uint32_t)atoi(entry);
224 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 rate");
226 pipe_params[j].tc_rate[12] = (uint32_t)atoi(entry);
228 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 oversubscription weight");
230 pipe_params[j].tc_ov_weight = (uint8_t)atoi(entry);
232 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 wrr weights");
234 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
235 pipe_params[j].wrr_weights[i] =
236 (uint8_t)strtol(entry, &next, 10);
247 cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
252 if (!cfg || !subport_params)
255 memset(app_pipe_to_profile, -1, sizeof(app_pipe_to_profile));
257 for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
258 char sec_name[CFG_NAME_LEN];
259 snprintf(sec_name, sizeof(sec_name), "subport %d", i);
261 if (rte_cfgfile_has_section(cfg, sec_name)) {
262 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb rate");
264 subport_params[i].tb_rate = (uint32_t)atoi(entry);
266 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb size");
268 subport_params[i].tb_size = (uint32_t)atoi(entry);
270 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc period");
272 subport_params[i].tc_period = (uint32_t)atoi(entry);
274 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 0 rate");
276 subport_params[i].tc_rate[0] = (uint32_t)atoi(entry);
278 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 1 rate");
280 subport_params[i].tc_rate[1] = (uint32_t)atoi(entry);
282 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 2 rate");
284 subport_params[i].tc_rate[2] = (uint32_t)atoi(entry);
286 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 3 rate");
288 subport_params[i].tc_rate[3] = (uint32_t)atoi(entry);
290 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 4 rate");
292 subport_params[i].tc_rate[4] = (uint32_t)atoi(entry);
294 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 5 rate");
296 subport_params[i].tc_rate[5] = (uint32_t)atoi(entry);
298 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 6 rate");
300 subport_params[i].tc_rate[6] = (uint32_t)atoi(entry);
302 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 7 rate");
304 subport_params[i].tc_rate[7] = (uint32_t)atoi(entry);
306 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 8 rate");
308 subport_params[i].tc_rate[8] = (uint32_t)atoi(entry);
310 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 9 rate");
312 subport_params[i].tc_rate[9] = (uint32_t)atoi(entry);
314 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 10 rate");
316 subport_params[i].tc_rate[10] = (uint32_t)atoi(entry);
318 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 11 rate");
320 subport_params[i].tc_rate[11] = (uint32_t)atoi(entry);
322 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 12 rate");
324 subport_params[i].tc_rate[12] = (uint32_t)atoi(entry);
326 int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
327 struct rte_cfgfile_entry entries[n_entries];
329 rte_cfgfile_section_entries(cfg, sec_name, entries, n_entries);
331 for (j = 0; j < n_entries; j++) {
332 if (strncmp("pipe", entries[j].name, sizeof("pipe") - 1) == 0) {
334 char *tokens[2] = {NULL, NULL};
338 profile = atoi(entries[j].value);
339 n_tokens = rte_strsplit(&entries[j].name[sizeof("pipe")],
340 strnlen(entries[j].name, CFG_NAME_LEN), tokens, 2, '-');
342 begin = atoi(tokens[0]);
344 end = atoi(tokens[1]);
348 if (end >= MAX_SCHED_PIPES || begin > end)
351 for (k = begin; k <= end; k++) {
352 char profile_name[CFG_NAME_LEN];
354 snprintf(profile_name, sizeof(profile_name),
355 "pipe profile %d", profile);
356 if (rte_cfgfile_has_section(cfg, profile_name))
357 app_pipe_to_profile[i][k] = profile;
359 rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n",