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 rte_power_channel_packet *policy;
52 unsigned short int hours[MAX_HOURS];
53 unsigned short int cores[RTE_POWER_MAX_VCPU_PER_VM];
54 unsigned short int ports[RTE_POWER_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,
73 RTE_POWER_VM_MAX_NAME_SZ);
74 printf("Setting VM Name to [%s]\n", policy->vm_name);
78 //printf("***Processing set using [%s]\n", optarg);
79 cnt = parse_set(optarg, hours, MAX_HOURS);
81 printf("Invalid value passed to quiet/busy hours - [%s]\n",
86 for (i = 0; i < MAX_HOURS; i++) {
89 printf("***Busy Hour %d\n", i);
90 policy->timer_policy.busy_hours
93 printf("***Quiet Hour %d\n", i);
94 policy->timer_policy.quiet_hours
101 cnt = parse_set(optarg, cores,
102 RTE_POWER_MAX_VCPU_PER_VM);
104 printf("Invalid value passed to vcpu-list - [%s]\n",
109 for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
111 printf("***Using core %d\n", i);
112 policy->vcpu_to_control[idx++] = i;
115 policy->num_vcpu = idx;
116 printf("Total cores: %d\n", idx);
119 cnt = parse_set(optarg, ports,
120 RTE_POWER_MAX_VCPU_PER_VM);
122 printf("Invalid value passed to port-list - [%s]\n",
127 for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
129 printf("***Using port %d\n", i);
130 if (set_policy_mac(i, idx++) != 0) {
131 printf("Cannot set policy MAC");
136 policy->nb_mac_to_monitor = idx;
137 printf("Total Ports: %d\n", idx);
140 if (!strcmp(optarg, "TRAFFIC"))
141 policy->policy_to_use =
142 RTE_POWER_POLICY_TRAFFIC;
143 else if (!strcmp(optarg, "TIME"))
144 policy->policy_to_use =
145 RTE_POWER_POLICY_TIME;
146 else if (!strcmp(optarg, "WORKLOAD"))
147 policy->policy_to_use =
148 RTE_POWER_POLICY_WORKLOAD;
149 else if (!strcmp(optarg, "BRANCH_RATIO"))
150 policy->policy_to_use =
151 RTE_POWER_POLICY_BRANCH_RATIO;
153 printf("Invalid policy specified: %s\n",
169 argv[optind-1] = prgname;
172 optind = 0; /* reset getopt lib */
177 main(int argc, char **argv)
182 ret = rte_eal_init(argc, argv);
184 rte_panic("Cannot init EAL\n");
186 signal(SIGINT, sig_handler);
187 signal(SIGTERM, sig_handler);
192 /* parse application arguments (after the EAL ones) */
193 ret = parse_args(argc, argv);
195 rte_exit(EXIT_FAILURE, "Invalid arguments\n");
197 rte_power_set_env(PM_ENV_KVM_VM);
198 RTE_LCORE_FOREACH(lcore_id) {
199 rte_power_init(lcore_id);
203 /* clean up the EAL */