#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <getopt.h>
#include <string.h>
#include "vm_power_cli_guest.h"
#include "parse.h"
static void
sig_handler(int signo)
{
printf("Received signal %d, exiting...\n", signo);
unsigned lcore_id;
}
}
#define MAX_HOURS 24
static int
parse_args(int argc, char **argv)
{
int opt, ret;
char **argvopt;
int option_index;
char *prgname = argv[0];
const struct option lgopts[] = {
{ "vm-name", required_argument, 0, 'n'},
{ "busy-hours", required_argument, 0, 'b'},
{ "quiet-hours", required_argument, 0, 'q'},
{ "port-list", required_argument, 0, 'p'},
{ "vcpu-list", required_argument, 0, 'l'},
{ "policy", required_argument, 0, 'o'},
{NULL, 0, 0, 0}
};
struct rte_power_channel_packet *policy;
unsigned short int hours[MAX_HOURS];
unsigned short int cores[RTE_POWER_MAX_VCPU_PER_VM];
unsigned short int ports[RTE_POWER_MAX_VCPU_PER_VM];
int i, cnt, idx;
policy = get_policy();
ret = set_policy_defaults(policy);
if (ret != 0) {
printf("Failed to set policy defaults\n");
return -1;
}
argvopt = argv;
while ((opt = getopt_long(argc, argvopt, "n:b:q:p:",
lgopts, &option_index)) != EOF) {
switch (opt) {
case 'n':
strlcpy(policy->vm_name, optarg,
RTE_POWER_VM_MAX_NAME_SZ);
printf("Setting VM Name to [%s]\n", policy->vm_name);
break;
case 'b':
case 'q':
cnt = parse_set(optarg, hours, MAX_HOURS);
if (cnt < 0) {
printf("Invalid value passed to quiet/busy hours - [%s]\n",
optarg);
break;
}
idx = 0;
for (i = 0; i < MAX_HOURS; i++) {
if (hours[i]) {
if (opt == 'b') {
printf("***Busy Hour %d\n", i);
policy->timer_policy.busy_hours
[idx++] = i;
} else {
printf("***Quiet Hour %d\n", i);
policy->timer_policy.quiet_hours
[idx++] = i;
}
}
}
break;
case 'l':
cnt = parse_set(optarg, cores,
RTE_POWER_MAX_VCPU_PER_VM);
if (cnt < 0) {
printf("Invalid value passed to vcpu-list - [%s]\n",
optarg);
break;
}
idx = 0;
for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
if (cores[i]) {
printf("***Using core %d\n", i);
policy->vcpu_to_control[idx++] = i;
}
}
policy->num_vcpu = idx;
printf("Total cores: %d\n", idx);
break;
case 'p':
cnt = parse_set(optarg, ports,
RTE_POWER_MAX_VCPU_PER_VM);
if (cnt < 0) {
printf("Invalid value passed to port-list - [%s]\n",
optarg);
break;
}
idx = 0;
for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
if (ports[i]) {
printf("***Using port %d\n", i);
if (set_policy_mac(i, idx++) != 0) {
printf("Cannot set policy MAC");
return -1;
}
}
}
policy->nb_mac_to_monitor = idx;
printf("Total Ports: %d\n", idx);
break;
case 'o':
if (!strcmp(optarg, "TRAFFIC"))
policy->policy_to_use =
RTE_POWER_POLICY_TRAFFIC;
else if (!strcmp(optarg, "TIME"))
policy->policy_to_use =
RTE_POWER_POLICY_TIME;
else if (!strcmp(optarg, "WORKLOAD"))
policy->policy_to_use =
RTE_POWER_POLICY_WORKLOAD;
else if (!strcmp(optarg, "BRANCH_RATIO"))
policy->policy_to_use =
RTE_POWER_POLICY_BRANCH_RATIO;
else {
printf("Invalid policy specified: %s\n",
optarg);
return -1;
}
break;
case 0:
break;
default:
return -1;
}
}
if (optind >= 0)
argv[optind-1] = prgname;
ret = optind-1;
optind = 0;
return ret;
}
int
main(int argc, char **argv)
{
int ret;
unsigned lcore_id;
if (ret < 0)
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
argc -= ret;
argv += ret;
ret = parse_args(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Invalid arguments\n");
}
run_cli(NULL);
return 0;
}
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
int rte_eal_init(int argc, char **argv)
int rte_eal_cleanup(void)
#define RTE_LCORE_FOREACH(i)
int rte_power_set_env(enum power_management_env env)
int rte_power_init(unsigned int lcore_id)
int rte_power_exit(unsigned int lcore_id)