#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>
#include <rte_service_component.h>
#define PROFILE_CORES_MAX 8
#define PROFILE_SERVICE_PER_CORE 5
static int32_t service_func(void *args)
{
return 0;
}
{"service_1", service_func, NULL, 0, 0},
{"service_2", service_func, NULL, 0, 0},
{"service_3", service_func, NULL, 0, 0},
{"service_4", service_func, NULL, 0, 0},
{"service_5", service_func, NULL, 0, 0},
};
#define NUM_SERVICES RTE_DIM(services)
struct profile_for_core {
uint32_t mapped_services[PROFILE_SERVICE_PER_CORE];
};
struct profile {
char name[64];
uint32_t num_cores;
struct profile_for_core cores[PROFILE_CORES_MAX];
};
static struct profile profiles[] = {
{
.name = "High Performance",
.num_cores = 5,
.cores[0] = {.mapped_services = {1, 0, 0, 0, 0} },
.cores[1] = {.mapped_services = {0, 1, 0, 0, 0} },
.cores[2] = {.mapped_services = {0, 0, 1, 0, 0} },
.cores[3] = {.mapped_services = {0, 0, 0, 1, 0} },
.cores[4] = {.mapped_services = {0, 0, 0, 0, 1} },
},
{
.name = "Mid-High Performance",
.num_cores = 3,
.cores[0] = {.mapped_services = {1, 1, 0, 0, 0} },
.cores[1] = {.mapped_services = {0, 0, 1, 1, 0} },
.cores[2] = {.mapped_services = {0, 0, 0, 0, 1} },
.cores[3] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[4] = {.mapped_services = {0, 0, 0, 0, 0} },
},
{
.name = "Mid-Low Performance",
.num_cores = 2,
.cores[0] = {.mapped_services = {1, 1, 1, 0, 0} },
.cores[1] = {.mapped_services = {1, 1, 0, 1, 1} },
.cores[2] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[3] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[4] = {.mapped_services = {0, 0, 0, 0, 0} },
},
{
.name = "Scale down performance",
.num_cores = 1,
.cores[0] = {.mapped_services = {1, 1, 1, 1, 1} },
.cores[1] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[2] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[3] = {.mapped_services = {0, 0, 0, 0, 0} },
.cores[4] = {.mapped_services = {0, 0, 0, 0, 0} },
},
};
#define NUM_PROFILES RTE_DIM(profiles)
static void
apply_profile(int profile_id)
{
uint32_t i;
uint32_t s;
int ret;
struct profile *p = &profiles[profile_id];
const uint8_t core_off = 1;
printf("insufficent cores to run (%s)",
p->name);
return;
}
for (i = 0; i < p->num_cores; i++) {
uint32_t core = i + core_off;
if (ret && ret != -EALREADY)
printf("core %d added ret %d\n", core, ret);
if (ret && ret != -EALREADY)
printf("core %d start ret %d\n", core, ret);
for (s = 0; s < NUM_SERVICES; s++) {
p->cores[i].mapped_services[s]))
printf("failed to map lcore %d\n", core);
}
}
for ( ; i < PROFILE_CORES_MAX; i++) {
uint32_t core = i + core_off;
for (s = 0; s < NUM_SERVICES; s++) {
if (ret && ret != -EINVAL) {
printf("%s %d: map lcore set = %d\n", __func__,
__LINE__, ret);
}
}
if (ret && ret != -EALREADY) {
printf("%s %d: lcore stop = %d\n", __func__,
__LINE__, ret);
}
if (ret && ret != -EINVAL) {
printf("%s %d: lcore del = %d\n", __func__,
__LINE__, ret);
}
}
}
int
main(int argc, char **argv)
{
int ret;
if (ret < 0)
uint32_t i;
for (i = 0; i < NUM_SERVICES; i++) {
uint32_t id;
ret = rte_service_component_register(&services[i], &id);
if (ret)
rte_exit(-1,
"service register() failed");
rte_service_component_runstate_set(id, 1);
if (ret)
return -ENOEXEC;
}
i = 0;
while (1) {
const char clr[] = { 27, '[', '2', 'J', '\0' };
const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
printf("%s%s", clr, topLeft);
apply_profile(i);
printf("\n==> Profile: %s\n\n", profiles[i].name);
i++;
if (i >= NUM_PROFILES)
i = 0;
}
return 0;
}