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
23 uint32_t active_queues[RTE_SCHED_QUEUES_PER_PIPE];
24 uint32_t n_active_queues;
27 cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params *port_params)
31 if (!cfg || !port_params)
34 entry = rte_cfgfile_get_entry(cfg, "port", "frame overhead");
36 port_params->frame_overhead = (uint32_t)atoi(entry);
38 entry = rte_cfgfile_get_entry(cfg, "port", "number of subports per port");
40 port_params->n_subports_per_port = (uint32_t)atoi(entry);
46 cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params *pipe_params)
53 if (!cfg || !pipe_params)
56 profiles = rte_cfgfile_num_sections(cfg, "pipe profile", sizeof("pipe profile") - 1);
57 subport_params[0].n_pipe_profiles = profiles;
59 for (j = 0; j < profiles; j++) {
61 snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", j);
63 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb rate");
65 pipe_params[j].tb_rate = (uint64_t)atoi(entry);
67 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tb size");
69 pipe_params[j].tb_size = (uint64_t)atoi(entry);
71 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc period");
73 pipe_params[j].tc_period = (uint64_t)atoi(entry);
75 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 rate");
77 pipe_params[j].tc_rate[0] = (uint64_t)atoi(entry);
79 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 rate");
81 pipe_params[j].tc_rate[1] = (uint64_t)atoi(entry);
83 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 rate");
85 pipe_params[j].tc_rate[2] = (uint64_t)atoi(entry);
87 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 rate");
89 pipe_params[j].tc_rate[3] = (uint64_t)atoi(entry);
91 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 4 rate");
93 pipe_params[j].tc_rate[4] = (uint64_t)atoi(entry);
95 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 5 rate");
97 pipe_params[j].tc_rate[5] = (uint64_t)atoi(entry);
99 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 6 rate");
101 pipe_params[j].tc_rate[6] = (uint64_t)atoi(entry);
103 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 7 rate");
105 pipe_params[j].tc_rate[7] = (uint64_t)atoi(entry);
107 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 8 rate");
109 pipe_params[j].tc_rate[8] = (uint64_t)atoi(entry);
111 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 9 rate");
113 pipe_params[j].tc_rate[9] = (uint64_t)atoi(entry);
115 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 10 rate");
117 pipe_params[j].tc_rate[10] = (uint64_t)atoi(entry);
119 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 11 rate");
121 pipe_params[j].tc_rate[11] = (uint64_t)atoi(entry);
123 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 rate");
125 pipe_params[j].tc_rate[12] = (uint64_t)atoi(entry);
127 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 oversubscription weight");
129 pipe_params[j].tc_ov_weight = (uint8_t)atoi(entry);
131 entry = rte_cfgfile_get_entry(cfg, pipe_name, "tc 12 wrr weights");
133 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
134 pipe_params[j].wrr_weights[i] =
135 (uint8_t)strtol(entry, &next, 10);
146 cfg_load_subport_profile(struct rte_cfgfile *cfg,
147 struct rte_sched_subport_profile_params *subport_profile)
153 if (!cfg || !subport_profile)
156 profiles = rte_cfgfile_num_sections(cfg, "subport profile",
157 sizeof("subport profile") - 1);
158 subport_params[0].n_pipe_profiles = profiles;
160 for (i = 0; i < profiles; i++) {
162 snprintf(sec_name, sizeof(sec_name), "subport profile %d", i);
164 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb rate");
166 subport_profile[i].tb_rate = (uint64_t)atoi(entry);
168 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb size");
170 subport_profile[i].tb_size = (uint64_t)atoi(entry);
172 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc period");
174 subport_profile[i].tc_period = (uint64_t)atoi(entry);
176 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 0 rate");
178 subport_profile[i].tc_rate[0] = (uint64_t)atoi(entry);
180 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 1 rate");
182 subport_profile[i].tc_rate[1] = (uint64_t)atoi(entry);
184 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 2 rate");
186 subport_profile[i].tc_rate[2] = (uint64_t)atoi(entry);
188 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 3 rate");
190 subport_profile[i].tc_rate[3] = (uint64_t)atoi(entry);
192 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 4 rate");
194 subport_profile[i].tc_rate[4] = (uint64_t)atoi(entry);
196 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 5 rate");
198 subport_profile[i].tc_rate[5] = (uint64_t)atoi(entry);
200 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 6 rate");
202 subport_profile[i].tc_rate[6] = (uint64_t)atoi(entry);
204 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 7 rate");
206 subport_profile[i].tc_rate[7] = (uint64_t)atoi(entry);
208 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 8 rate");
210 subport_profile[i].tc_rate[8] = (uint64_t)atoi(entry);
212 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 9 rate");
214 subport_profile[i].tc_rate[9] = (uint64_t)atoi(entry);
216 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 10 rate");
218 subport_profile[i].tc_rate[10] = (uint64_t)atoi(entry);
220 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 11 rate");
222 subport_profile[i].tc_rate[11] = (uint64_t)atoi(entry);
224 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 12 rate");
226 subport_profile[i].tc_rate[12] = (uint64_t)atoi(entry);
232 #ifdef RTE_SCHED_CMAN
233 void set_subport_cman_params(struct rte_sched_subport_params *subport_p,
234 struct rte_sched_cman_params cman_p)
237 subport_p->cman_params->cman_mode = cman_p.cman_mode;
239 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
240 if (subport_p->cman_params->cman_mode ==
241 RTE_SCHED_CMAN_RED) {
242 for (k = 0; k < RTE_COLORS; k++) {
243 subport_p->cman_params->red_params[j][k].min_th =
244 cman_p.red_params[j][k].min_th;
245 subport_p->cman_params->red_params[j][k].max_th =
246 cman_p.red_params[j][k].max_th;
247 subport_p->cman_params->red_params[j][k].maxp_inv =
248 cman_p.red_params[j][k].maxp_inv;
249 subport_p->cman_params->red_params[j][k].wq_log2 =
250 cman_p.red_params[j][k].wq_log2;
253 subport_p->cman_params->pie_params[j].qdelay_ref =
254 cman_p.pie_params[j].qdelay_ref;
255 subport_p->cman_params->pie_params[j].dp_update_interval =
256 cman_p.pie_params[j].dp_update_interval;
257 subport_p->cman_params->pie_params[j].max_burst =
258 cman_p.pie_params[j].max_burst;
259 subport_p->cman_params->pie_params[j].tailq_th =
260 cman_p.pie_params[j].tailq_th;
267 cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
272 if (!cfg || !subport_params)
275 memset(app_pipe_to_profile, -1, sizeof(app_pipe_to_profile));
276 memset(active_queues, 0, sizeof(active_queues));
279 #ifdef RTE_SCHED_CMAN
280 struct rte_sched_cman_params cman_params = {
281 .cman_mode = RTE_SCHED_CMAN_RED,
285 if (rte_cfgfile_has_section(cfg, "red")) {
286 cman_params.cman_mode = RTE_SCHED_CMAN_RED;
288 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
291 /* Parse RED min thresholds */
292 snprintf(str, sizeof(str), "tc %d red min", i);
293 entry = rte_cfgfile_get_entry(cfg, "red", str);
296 /* for each packet colour (green, yellow, red) */
297 for (j = 0; j < RTE_COLORS; j++) {
298 cman_params.red_params[i][j].min_th
299 = (uint16_t)strtol(entry, &next, 10);
306 /* Parse RED max thresholds */
307 snprintf(str, sizeof(str), "tc %d red max", i);
308 entry = rte_cfgfile_get_entry(cfg, "red", str);
311 /* for each packet colour (green, yellow, red) */
312 for (j = 0; j < RTE_COLORS; j++) {
313 cman_params.red_params[i][j].max_th
314 = (uint16_t)strtol(entry, &next, 10);
321 /* Parse RED inverse mark probabilities */
322 snprintf(str, sizeof(str), "tc %d red inv prob", i);
323 entry = rte_cfgfile_get_entry(cfg, "red", str);
326 /* for each packet colour (green, yellow, red) */
327 for (j = 0; j < RTE_COLORS; j++) {
328 cman_params.red_params[i][j].maxp_inv
329 = (uint8_t)strtol(entry, &next, 10);
337 /* Parse RED EWMA filter weights */
338 snprintf(str, sizeof(str), "tc %d red weight", i);
339 entry = rte_cfgfile_get_entry(cfg, "red", str);
342 /* for each packet colour (green, yellow, red) */
343 for (j = 0; j < RTE_COLORS; j++) {
344 cman_params.red_params[i][j].wq_log2
345 = (uint8_t)strtol(entry, &next, 10);
354 if (rte_cfgfile_has_section(cfg, "pie")) {
355 cman_params.cman_mode = RTE_SCHED_CMAN_PIE;
357 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
360 /* Parse Queue Delay Ref value */
361 snprintf(str, sizeof(str), "tc %d qdelay ref", i);
362 entry = rte_cfgfile_get_entry(cfg, "pie", str);
364 cman_params.pie_params[i].qdelay_ref =
365 (uint16_t) atoi(entry);
367 /* Parse Max Burst value */
368 snprintf(str, sizeof(str), "tc %d max burst", i);
369 entry = rte_cfgfile_get_entry(cfg, "pie", str);
371 cman_params.pie_params[i].max_burst =
372 (uint16_t) atoi(entry);
374 /* Parse Update Interval Value */
375 snprintf(str, sizeof(str), "tc %d update interval", i);
376 entry = rte_cfgfile_get_entry(cfg, "pie", str);
378 cman_params.pie_params[i].dp_update_interval =
379 (uint16_t) atoi(entry);
381 /* Parse Tailq Threshold Value */
382 snprintf(str, sizeof(str), "tc %d tailq th", i);
383 entry = rte_cfgfile_get_entry(cfg, "pie", str);
385 cman_params.pie_params[i].tailq_th =
386 (uint16_t) atoi(entry);
390 #endif /* RTE_SCHED_CMAN */
392 for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
393 char sec_name[CFG_NAME_LEN];
394 snprintf(sec_name, sizeof(sec_name), "subport %d", i);
396 if (rte_cfgfile_has_section(cfg, sec_name)) {
397 entry = rte_cfgfile_get_entry(cfg, sec_name,
398 "number of pipes per subport");
400 subport_params[i].n_pipes_per_subport_enabled =
401 (uint32_t)atoi(entry);
403 entry = rte_cfgfile_get_entry(cfg, sec_name, "queue sizes");
407 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASS_BE; j++) {
408 subport_params[i].qsize[j] =
409 (uint16_t)strtol(entry, &next, 10);
410 if (subport_params[i].qsize[j] != 0) {
411 active_queues[n_active_queues] = j;
419 subport_params[i].qsize[RTE_SCHED_TRAFFIC_CLASS_BE] =
420 (uint16_t)strtol(entry, &next, 10);
422 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
423 active_queues[n_active_queues] =
424 RTE_SCHED_TRAFFIC_CLASS_BE + j;
429 int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
430 struct rte_cfgfile_entry entries[n_entries];
432 rte_cfgfile_section_entries(cfg, sec_name, entries, n_entries);
434 for (j = 0; j < n_entries; j++) {
435 if (strncmp("pipe", entries[j].name, sizeof("pipe") - 1) == 0) {
437 char *tokens[2] = {NULL, NULL};
441 profile = atoi(entries[j].value);
442 n_tokens = rte_strsplit(&entries[j].name[sizeof("pipe")],
443 strnlen(entries[j].name, CFG_NAME_LEN), tokens, 2, '-');
445 begin = atoi(tokens[0]);
447 end = atoi(tokens[1]);
451 if (end >= MAX_SCHED_PIPES || begin > end)
454 for (k = begin; k <= end; k++) {
455 char profile_name[CFG_NAME_LEN];
457 snprintf(profile_name, sizeof(profile_name),
458 "pipe profile %d", profile);
459 if (rte_cfgfile_has_section(cfg, profile_name))
460 app_pipe_to_profile[i][k] = profile;
462 rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n",
468 #ifdef RTE_SCHED_CMAN
469 set_subport_cman_params(subport_params+i, cman_params);