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>
16 #include <rte_string_fns.h>
18 #include "vm_power_cli_guest.h"
22 sig_handler(int signo)
24 printf("Received signal %d, exiting...\n", signo);
27 RTE_LCORE_FOREACH(lcore_id) {
28 rte_power_exit(lcore_id);
35 /* Parse the argument given in the command line of the application */
37 parse_args(int argc, char **argv)
42 char *prgname = argv[0];
43 const struct option lgopts[] = {
44 { "vm-name", required_argument, 0, 'n'},
45 { "busy-hours", required_argument, 0, 'b'},
46 { "quiet-hours", required_argument, 0, 'q'},
47 { "port-list", required_argument, 0, 'p'},
48 { "vcpu-list", required_argument, 0, 'l'},
49 { "policy", required_argument, 0, 'o'},
52 struct rte_power_channel_packet *policy;
53 unsigned short int hours[MAX_HOURS];
54 unsigned short int cores[RTE_POWER_MAX_VCPU_PER_VM];
55 unsigned short int ports[RTE_POWER_MAX_VCPU_PER_VM];
58 policy = get_policy();
59 ret = set_policy_defaults(policy);
61 printf("Failed to set policy defaults\n");
67 while ((opt = getopt_long(argc, argvopt, "n:b:q:p:",
68 lgopts, &option_index)) != EOF) {
73 strlcpy(policy->vm_name, optarg,
74 RTE_POWER_VM_MAX_NAME_SZ);
75 printf("Setting VM Name to [%s]\n", policy->vm_name);
79 //printf("***Processing set using [%s]\n", optarg);
80 cnt = parse_set(optarg, hours, MAX_HOURS);
82 printf("Invalid value passed to quiet/busy hours - [%s]\n",
87 for (i = 0; i < MAX_HOURS; i++) {
90 printf("***Busy Hour %d\n", i);
91 policy->timer_policy.busy_hours
94 printf("***Quiet Hour %d\n", i);
95 policy->timer_policy.quiet_hours
102 cnt = parse_set(optarg, cores,
103 RTE_POWER_MAX_VCPU_PER_VM);
105 printf("Invalid value passed to vcpu-list - [%s]\n",
110 for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
112 printf("***Using core %d\n", i);
113 policy->vcpu_to_control[idx++] = i;
116 policy->num_vcpu = idx;
117 printf("Total cores: %d\n", idx);
120 cnt = parse_set(optarg, ports,
121 RTE_POWER_MAX_VCPU_PER_VM);
123 printf("Invalid value passed to port-list - [%s]\n",
128 for (i = 0; i < RTE_POWER_MAX_VCPU_PER_VM; i++) {
130 printf("***Using port %d\n", i);
131 if (set_policy_mac(i, idx++) != 0) {
132 printf("Cannot set policy MAC");
137 policy->nb_mac_to_monitor = idx;
138 printf("Total Ports: %d\n", idx);
141 if (!strcmp(optarg, "TRAFFIC"))
142 policy->policy_to_use =
143 RTE_POWER_POLICY_TRAFFIC;
144 else if (!strcmp(optarg, "TIME"))
145 policy->policy_to_use =
146 RTE_POWER_POLICY_TIME;
147 else if (!strcmp(optarg, "WORKLOAD"))
148 policy->policy_to_use =
149 RTE_POWER_POLICY_WORKLOAD;
150 else if (!strcmp(optarg, "BRANCH_RATIO"))
151 policy->policy_to_use =
152 RTE_POWER_POLICY_BRANCH_RATIO;
154 printf("Invalid policy specified: %s\n",
170 argv[optind-1] = prgname;
173 optind = 0; /* reset getopt lib */
178 main(int argc, char **argv)
183 ret = rte_eal_init(argc, argv);
185 rte_panic("Cannot init EAL\n");
187 signal(SIGINT, sig_handler);
188 signal(SIGTERM, sig_handler);
193 /* parse application arguments (after the EAL ones) */
194 ret = parse_args(argc, argv);
196 rte_exit(EXIT_FAILURE, "Invalid arguments\n");
198 rte_power_set_env(PM_ENV_KVM_VM);
199 RTE_LCORE_FOREACH(lcore_id) {
200 rte_power_init(lcore_id);
204 /* clean up the EAL */