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(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
151 if (!cfg || !subport_params)
154 memset(app_pipe_to_profile, -1, sizeof(app_pipe_to_profile));
155 memset(active_queues, 0, sizeof(active_queues));
159 char sec_name[CFG_NAME_LEN];
160 struct rte_red_params red_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
162 snprintf(sec_name, sizeof(sec_name), "red");
164 if (rte_cfgfile_has_section(cfg, sec_name)) {
166 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
169 /* Parse WRED min thresholds */
170 snprintf(str, sizeof(str), "tc %d wred min", i);
171 entry = rte_cfgfile_get_entry(cfg, sec_name, str);
174 /* for each packet colour (green, yellow, red) */
175 for (j = 0; j < RTE_COLORS; j++) {
176 red_params[i][j].min_th
177 = (uint16_t)strtol(entry, &next, 10);
184 /* Parse WRED max thresholds */
185 snprintf(str, sizeof(str), "tc %d wred max", i);
186 entry = rte_cfgfile_get_entry(cfg, "red", str);
189 /* for each packet colour (green, yellow, red) */
190 for (j = 0; j < RTE_COLORS; j++) {
191 red_params[i][j].max_th
192 = (uint16_t)strtol(entry, &next, 10);
199 /* Parse WRED inverse mark probabilities */
200 snprintf(str, sizeof(str), "tc %d wred inv prob", i);
201 entry = rte_cfgfile_get_entry(cfg, "red", str);
204 /* for each packet colour (green, yellow, red) */
205 for (j = 0; j < RTE_COLORS; j++) {
206 red_params[i][j].maxp_inv
207 = (uint8_t)strtol(entry, &next, 10);
215 /* Parse WRED EWMA filter weights */
216 snprintf(str, sizeof(str), "tc %d wred weight", i);
217 entry = rte_cfgfile_get_entry(cfg, "red", str);
220 /* for each packet colour (green, yellow, red) */
221 for (j = 0; j < RTE_COLORS; j++) {
222 red_params[i][j].wq_log2
223 = (uint8_t)strtol(entry, &next, 10);
231 #endif /* RTE_SCHED_RED */
233 for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
234 char sec_name[CFG_NAME_LEN];
235 snprintf(sec_name, sizeof(sec_name), "subport %d", i);
237 if (rte_cfgfile_has_section(cfg, sec_name)) {
238 entry = rte_cfgfile_get_entry(cfg, sec_name,
239 "number of pipes per subport");
241 subport_params[i].n_pipes_per_subport_enabled =
242 (uint32_t)atoi(entry);
244 entry = rte_cfgfile_get_entry(cfg, sec_name, "queue sizes");
248 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASS_BE; j++) {
249 subport_params[i].qsize[j] =
250 (uint16_t)strtol(entry, &next, 10);
251 if (subport_params[i].qsize[j] != 0) {
252 active_queues[n_active_queues] = j;
260 subport_params[i].qsize[RTE_SCHED_TRAFFIC_CLASS_BE] =
261 (uint16_t)strtol(entry, &next, 10);
263 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
264 active_queues[n_active_queues] =
265 RTE_SCHED_TRAFFIC_CLASS_BE + j;
270 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb rate");
272 subport_params[i].tb_rate = (uint64_t)atoi(entry);
274 entry = rte_cfgfile_get_entry(cfg, sec_name, "tb size");
276 subport_params[i].tb_size = (uint64_t)atoi(entry);
278 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc period");
280 subport_params[i].tc_period = (uint64_t)atoi(entry);
282 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 0 rate");
284 subport_params[i].tc_rate[0] = (uint64_t)atoi(entry);
286 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 1 rate");
288 subport_params[i].tc_rate[1] = (uint64_t)atoi(entry);
290 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 2 rate");
292 subport_params[i].tc_rate[2] = (uint64_t)atoi(entry);
294 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 3 rate");
296 subport_params[i].tc_rate[3] = (uint64_t)atoi(entry);
298 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 4 rate");
300 subport_params[i].tc_rate[4] = (uint64_t)atoi(entry);
302 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 5 rate");
304 subport_params[i].tc_rate[5] = (uint64_t)atoi(entry);
306 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 6 rate");
308 subport_params[i].tc_rate[6] = (uint64_t)atoi(entry);
310 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 7 rate");
312 subport_params[i].tc_rate[7] = (uint64_t)atoi(entry);
314 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 8 rate");
316 subport_params[i].tc_rate[8] = (uint64_t)atoi(entry);
318 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 9 rate");
320 subport_params[i].tc_rate[9] = (uint64_t)atoi(entry);
322 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 10 rate");
324 subport_params[i].tc_rate[10] = (uint64_t)atoi(entry);
326 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 11 rate");
328 subport_params[i].tc_rate[11] = (uint64_t)atoi(entry);
330 entry = rte_cfgfile_get_entry(cfg, sec_name, "tc 12 rate");
332 subport_params[i].tc_rate[12] = (uint64_t)atoi(entry);
334 int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
335 struct rte_cfgfile_entry entries[n_entries];
337 rte_cfgfile_section_entries(cfg, sec_name, entries, n_entries);
339 for (j = 0; j < n_entries; j++) {
340 if (strncmp("pipe", entries[j].name, sizeof("pipe") - 1) == 0) {
342 char *tokens[2] = {NULL, NULL};
346 profile = atoi(entries[j].value);
347 n_tokens = rte_strsplit(&entries[j].name[sizeof("pipe")],
348 strnlen(entries[j].name, CFG_NAME_LEN), tokens, 2, '-');
350 begin = atoi(tokens[0]);
352 end = atoi(tokens[1]);
356 if (end >= MAX_SCHED_PIPES || begin > end)
359 for (k = begin; k <= end; k++) {
360 char profile_name[CFG_NAME_LEN];
362 snprintf(profile_name, sizeof(profile_name),
363 "pipe profile %d", profile);
364 if (rte_cfgfile_has_section(cfg, profile_name))
365 app_pipe_to_profile[i][k] = profile;
367 rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n",
374 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
375 for (k = 0; k < RTE_COLORS; k++) {
376 subport_params[i].red_params[j][k].min_th =
377 red_params[j][k].min_th;
378 subport_params[i].red_params[j][k].max_th =
379 red_params[j][k].max_th;
380 subport_params[i].red_params[j][k].maxp_inv =
381 red_params[j][k].maxp_inv;
382 subport_params[i].red_params[j][k].wq_log2 =
383 red_params[j][k].wq_log2;