#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cfg_file.h"
#include "main.h"
#define CFG_ALLOC_SECTION_BATCH 8
#define CFG_ALLOC_ENTRY_BATCH 16
uint32_t n_active_queues;
struct rte_sched_cman_params cman_params;
int parse_u64(const char *entry, uint64_t *val)
{
char *endptr;
if (!entry || !val)
return -EINVAL;
errno = 0;
*val = strtoull(entry, &endptr, 0);
if (errno == EINVAL || errno == ERANGE || *endptr != '\0')
return -EINVAL;
return 0;
}
int
{
const char *entry;
if (!cfg || !port_params)
return -1;
if (entry)
port_params->frame_overhead = (uint32_t)atoi(entry);
if (entry)
port_params->n_subports_per_port = (uint32_t)atoi(entry);
return 0;
}
int
cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params *pipe_params)
{
int i, j, ret = 0;
char *next;
const char *entry;
int profiles;
if (!cfg || !pipe_params)
return -1;
subport_params[0].n_pipe_profiles = profiles;
for (j = 0; j < profiles; j++) {
char pipe_name[32];
snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", j);
ret = parse_u64(entry, &pipe_params[j].tb_rate);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tb_size);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_period);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[0]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[1]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[2]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[3]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[4]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[5]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[6]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[7]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[8]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[9]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[10]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[11]);
if (ret)
return ret;
ret = parse_u64(entry, &pipe_params[j].tc_rate[12]);
if (ret)
return ret;
if (entry)
pipe_params[j].tc_ov_weight = (uint8_t)atoi(entry);
if (entry) {
pipe_params[j].wrr_weights[i] =
(uint8_t)strtol(entry, &next, 10);
if (next == NULL)
break;
entry = next;
}
}
}
return 0;
}
int
cfg_load_subport_profile(struct rte_cfgfile *cfg,
struct rte_sched_subport_profile_params *subport_profile)
{
int i, ret = 0;
const char *entry;
int profiles;
if (!cfg || !subport_profile)
return -1;
sizeof("subport profile") - 1);
port_params.n_subport_profiles = profiles;
for (i = 0; i < profiles; i++) {
char sec_name[32];
snprintf(sec_name, sizeof(sec_name), "subport profile %d", i);
ret = parse_u64(entry, &subport_profile[i].tb_rate);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tb_size);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_period);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[0]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[1]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[2]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[3]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[4]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[5]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[6]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[7]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[8]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[9]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[10]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[11]);
if (ret)
return ret;
ret = parse_u64(entry, &subport_profile[i].tc_rate[12]);
if (ret)
return ret;
}
return 0;
}
int
cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_params *subport_params)
{
bool cman_enabled = false;
const char *entry;
int i, j, k;
if (!cfg || !subport_params)
return -1;
memset(app_pipe_to_profile, -1, sizeof(app_pipe_to_profile));
memset(active_queues, 0, sizeof(active_queues));
n_active_queues = 0;
cman_enabled = true;
char str[32];
snprintf(str, sizeof(str), "tc %d red min", i);
if (entry) {
char *next;
cman_params.red_params[i][j].min_th
= (uint16_t)strtol(entry, &next, 10);
if (next == NULL)
break;
entry = next;
}
}
snprintf(str, sizeof(str), "tc %d red max", i);
if (entry) {
char *next;
cman_params.red_params[i][j].max_th
= (uint16_t)strtol(entry, &next, 10);
if (next == NULL)
break;
entry = next;
}
}
snprintf(str, sizeof(str), "tc %d red inv prob", i);
if (entry) {
char *next;
cman_params.red_params[i][j].maxp_inv
= (uint8_t)strtol(entry, &next, 10);
if (next == NULL)
break;
entry = next;
}
}
snprintf(str, sizeof(str), "tc %d red weight", i);
if (entry) {
char *next;
cman_params.red_params[i][j].wq_log2
= (uint8_t)strtol(entry, &next, 10);
if (next == NULL)
break;
entry = next;
}
}
}
}
cman_enabled = true;
char str[32];
snprintf(str, sizeof(str), "tc %d qdelay ref", i);
if (entry)
cman_params.pie_params[i].qdelay_ref =
(uint16_t) atoi(entry);
snprintf(str, sizeof(str), "tc %d max burst", i);
if (entry)
cman_params.pie_params[i].max_burst =
(uint16_t) atoi(entry);
snprintf(str, sizeof(str), "tc %d update interval", i);
if (entry)
cman_params.pie_params[i].dp_update_interval =
(uint16_t) atoi(entry);
snprintf(str, sizeof(str), "tc %d tailq th", i);
if (entry)
cman_params.pie_params[i].tailq_th =
(uint16_t) atoi(entry);
}
}
for (i = 0; i < MAX_SCHED_SUBPORTS; i++) {
char sec_name[CFG_NAME_LEN];
snprintf(sec_name, sizeof(sec_name), "subport %d", i);
"number of pipes per subport");
if (entry)
subport_params[i].n_pipes_per_subport_enabled =
(uint32_t)atoi(entry);
if (entry) {
char *next;
subport_params[i].qsize[j] =
(uint16_t)strtol(entry, &next, 10);
if (subport_params[i].qsize[j] != 0) {
active_queues[n_active_queues] = j;
n_active_queues++;
}
if (next == NULL)
break;
entry = next;
}
(uint16_t)strtol(entry, &next, 10);
active_queues[n_active_queues] =
n_active_queues++;
}
}
for (j = 0; j < n_entries; j++) {
if (strncmp(
"pipe", entries[j].
name,
sizeof(
"pipe") - 1) == 0) {
int profile;
char *tokens[2] = {NULL, NULL};
int n_tokens;
int begin, end;
profile = atoi(entries[j].
value);
strnlen(entries[j].
name, CFG_NAME_LEN), tokens, 2,
'-');
begin = atoi(tokens[0]);
if (n_tokens == 2)
end = atoi(tokens[1]);
else
end = begin;
if (end >= MAX_SCHED_PIPES || begin > end)
return -1;
for (k = begin; k <= end; k++) {
char profile_name[CFG_NAME_LEN];
snprintf(profile_name, sizeof(profile_name),
"pipe profile %d", profile);
app_pipe_to_profile[i][k] = profile;
else
rte_exit(EXIT_FAILURE,
"Wrong pipe profile %s\n",
}
}
}
if (cman_enabled)
subport_params[i].cman_params = &cman_params;
}
}
return 0;
}
int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg, const char *sectionname)
const char * rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname, const char *entryname)
int rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname, struct rte_cfgfile_entry *entries, int max_entries)
int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname)
int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name, size_t length)
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
#define RTE_SCHED_QUEUES_PER_PIPE
#define RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE
#define RTE_SCHED_TRAFFIC_CLASS_BE
#define RTE_SCHED_BE_QUEUES_PER_PIPE
int rte_strsplit(char *string, int stringlen, char **tokens, int maxtokens, char delim)
char value[CFG_VALUE_LEN]