1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 #include <rte_lcore.h>
12 #include <rte_power.h>
13 #include <rte_debug.h>
17 #include "vm_power_cli_guest.h"
21 sig_handler(int signo)
23 printf("Received signal %d, exiting...\n", signo);
26 RTE_LCORE_FOREACH(lcore_id) {
27 rte_power_exit(lcore_id);
34 /* Parse the argument given in the command line of the application */
36 parse_args(int argc, char **argv)
41 char *prgname = argv[0];
42 const struct option lgopts[] = {
43 { "vm-name", required_argument, 0, 'n'},
44 { "busy-hours", required_argument, 0, 'b'},
45 { "quiet-hours", required_argument, 0, 'q'},
46 { "port-list", required_argument, 0, 'p'},
47 { "vcpu-list", required_argument, 0, 'l'},
48 { "policy", required_argument, 0, 'o'},
51 struct channel_packet *policy;
52 unsigned short int hours[MAX_HOURS];
53 unsigned short int cores[MAX_VCPU_PER_VM];
54 unsigned short int ports[MAX_VCPU_PER_VM];
57 policy = get_policy();
58 ret = set_policy_defaults(policy);
60 printf("Failed to set policy defaults\n");
66 while ((opt = getopt_long(argc, argvopt, "n:b:q:p:",
67 lgopts, &option_index)) != EOF) {
72 strlcpy(policy->vm_name, optarg, VM_MAX_NAME_SZ);
73 printf("Setting VM Name to [%s]\n", policy->vm_name);
77 //printf("***Processing set using [%s]\n", optarg);
78 cnt = parse_set(optarg, hours, MAX_HOURS);
80 printf("Invalid value passed to quiet/busy hours - [%s]\n",
85 for (i = 0; i < MAX_HOURS; i++) {
88 printf("***Busy Hour %d\n", i);
89 policy->timer_policy.busy_hours
92 printf("***Quiet Hour %d\n", i);
93 policy->timer_policy.quiet_hours
100 cnt = parse_set(optarg, cores, MAX_VCPU_PER_VM);
102 printf("Invalid value passed to vcpu-list - [%s]\n",
107 for (i = 0; i < MAX_VCPU_PER_VM; i++) {
109 printf("***Using core %d\n", i);
110 policy->vcpu_to_control[idx++] = i;
113 policy->num_vcpu = idx;
114 printf("Total cores: %d\n", idx);
117 cnt = parse_set(optarg, ports, MAX_VCPU_PER_VM);
119 printf("Invalid value passed to port-list - [%s]\n",
124 for (i = 0; i < MAX_VCPU_PER_VM; i++) {
126 printf("***Using port %d\n", i);
127 if (set_policy_mac(i, idx++) != 0) {
128 printf("Cannot set policy MAC");
133 policy->nb_mac_to_monitor = idx;
134 printf("Total Ports: %d\n", idx);
137 if (!strcmp(optarg, "TRAFFIC"))
138 policy->policy_to_use = TRAFFIC;
139 else if (!strcmp(optarg, "TIME"))
140 policy->policy_to_use = TIME;
141 else if (!strcmp(optarg, "WORKLOAD"))
142 policy->policy_to_use = WORKLOAD;
143 else if (!strcmp(optarg, "BRANCH_RATIO"))
144 policy->policy_to_use = BRANCH_RATIO;
146 printf("Invalid policy specified: %s\n",
162 argv[optind-1] = prgname;
165 optind = 0; /* reset getopt lib */
170 main(int argc, char **argv)
175 ret = rte_eal_init(argc, argv);
177 rte_panic("Cannot init EAL\n");
179 signal(SIGINT, sig_handler);
180 signal(SIGTERM, sig_handler);
185 /* parse application arguments (after the EAL ones) */
186 ret = parse_args(argc, argv);
188 rte_exit(EXIT_FAILURE, "Invalid arguments\n");
190 rte_power_set_env(PM_ENV_KVM_VM);
191 RTE_LCORE_FOREACH(lcore_id) {
192 rte_power_init(lcore_id);