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);
233 cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
238 if (!cfg || !subport_params)
241 memset(app_pipe_to_profile, -1, sizeof(app_pipe_to_profile));
242 memset(active_queues, 0, sizeof(active_queues));
246 char sec_name[CFG_NAME_LEN];
247 struct rte_red_params red_params[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE][RTE_COLORS];
249 snprintf(sec_name, sizeof(sec_name), "red");
251 if (rte_cfgfile_has_section(cfg, sec_name)) {
253 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
256 /* Parse WRED min thresholds */
257 snprintf(str, sizeof(str), "tc %d wred min", i);
258 entry = rte_cfgfile_get_entry(cfg, sec_name, str);
261 /* for each packet colour (green, yellow, red) */
262 for (j = 0; j < RTE_COLORS; j++) {
263 red_params[i][j].min_th
264 = (uint16_t)strtol(entry, &next, 10);
271 /* Parse WRED max thresholds */
272 snprintf(str, sizeof(str), "tc %d wred max", i);
273 entry = rte_cfgfile_get_entry(cfg, "red", str);
276 /* for each packet colour (green, yellow, red) */
277 for (j = 0; j < RTE_COLORS; j++) {
278 red_params[i][j].max_th
279 = (uint16_t)strtol(entry, &next, 10);
286 /* Parse WRED inverse mark probabilities */
287 snprintf(str, sizeof(str), "tc %d wred inv prob", i);
288 entry = rte_cfgfile_get_entry(cfg, "red", str);
291 /* for each packet colour (green, yellow, red) */
292 for (j = 0; j < RTE_COLORS; j++) {
293 red_params[i][j].maxp_inv
294 = (uint8_t)strtol(entry, &next, 10);
302 /* Parse WRED EWMA filter weights */
303 snprintf(str, sizeof(str), "tc %d wred weight", i);
304 entry = rte_cfgfile_get_entry(cfg, "red", str);
307 /* for each packet colour (green, yellow, red) */
308 for (j = 0; j < RTE_COLORS; j++) {
309 red_params[i][j].wq_log2
310 = (uint8_t)strtol(entry, &next, 10);
318 #endif /* RTE_SCHED_RED */
320 for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
321 char sec_name[CFG_NAME_LEN];
322 snprintf(sec_name, sizeof(sec_name), "subport %d", i);
324 if (rte_cfgfile_has_section(cfg, sec_name)) {
325 entry = rte_cfgfile_get_entry(cfg, sec_name,
326 "number of pipes per subport");
328 subport_params[i].n_pipes_per_subport_enabled =
329 (uint32_t)atoi(entry);
331 entry = rte_cfgfile_get_entry(cfg, sec_name, "queue sizes");
335 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASS_BE; j++) {
336 subport_params[i].qsize[j] =
337 (uint16_t)strtol(entry, &next, 10);
338 if (subport_params[i].qsize[j] != 0) {
339 active_queues[n_active_queues] = j;
347 subport_params[i].qsize[RTE_SCHED_TRAFFIC_CLASS_BE] =
348 (uint16_t)strtol(entry, &next, 10);
350 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
351 active_queues[n_active_queues] =
352 RTE_SCHED_TRAFFIC_CLASS_BE + j;
357 int n_entries = rte_cfgfile_section_num_entries(cfg, sec_name);
358 struct rte_cfgfile_entry entries[n_entries];
360 rte_cfgfile_section_entries(cfg, sec_name, entries, n_entries);
362 for (j = 0; j < n_entries; j++) {
363 if (strncmp("pipe", entries[j].name, sizeof("pipe") - 1) == 0) {
365 char *tokens[2] = {NULL, NULL};
369 profile = atoi(entries[j].value);
370 n_tokens = rte_strsplit(&entries[j].name[sizeof("pipe")],
371 strnlen(entries[j].name, CFG_NAME_LEN), tokens, 2, '-');
373 begin = atoi(tokens[0]);
375 end = atoi(tokens[1]);
379 if (end >= MAX_SCHED_PIPES || begin > end)
382 for (k = begin; k <= end; k++) {
383 char profile_name[CFG_NAME_LEN];
385 snprintf(profile_name, sizeof(profile_name),
386 "pipe profile %d", profile);
387 if (rte_cfgfile_has_section(cfg, profile_name))
388 app_pipe_to_profile[i][k] = profile;
390 rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n",
397 for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; j++) {
398 for (k = 0; k < RTE_COLORS; k++) {
399 subport_params[i].red_params[j][k].min_th =
400 red_params[j][k].min_th;
401 subport_params[i].red_params[j][k].max_th =
402 red_params[j][k].max_th;
403 subport_params[i].red_params[j][k].maxp_inv =
404 red_params[j][k].maxp_inv;
405 subport_params[i].red_params[j][k].wq_log2 =
406 red_params[j][k].wq_log2;