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 set_policy_defaults(policy);
62 while ((opt = getopt_long(argc, argvopt, "n:b:q:p:",
63 lgopts, &option_index)) != EOF) {
68 strlcpy(policy->vm_name, optarg, VM_MAX_NAME_SZ);
69 printf("Setting VM Name to [%s]\n", policy->vm_name);
73 //printf("***Processing set using [%s]\n", optarg);
74 cnt = parse_set(optarg, hours, MAX_HOURS);
76 printf("Invalid value passed to quiet/busy hours - [%s]\n",
81 for (i = 0; i < MAX_HOURS; i++) {
84 printf("***Busy Hour %d\n", i);
85 policy->timer_policy.busy_hours
88 printf("***Quiet Hour %d\n", i);
89 policy->timer_policy.quiet_hours
96 cnt = parse_set(optarg, cores, MAX_VCPU_PER_VM);
98 printf("Invalid value passed to vcpu-list - [%s]\n",
103 for (i = 0; i < MAX_VCPU_PER_VM; i++) {
105 printf("***Using core %d\n", i);
106 policy->vcpu_to_control[idx++] = i;
109 policy->num_vcpu = idx;
110 printf("Total cores: %d\n", idx);
113 cnt = parse_set(optarg, ports, MAX_VCPU_PER_VM);
115 printf("Invalid value passed to port-list - [%s]\n",
120 for (i = 0; i < MAX_VCPU_PER_VM; i++) {
122 printf("***Using port %d\n", i);
123 set_policy_mac(i, idx++);
126 policy->nb_mac_to_monitor = idx;
127 printf("Total Ports: %d\n", idx);
130 if (!strcmp(optarg, "TRAFFIC"))
131 policy->policy_to_use = TRAFFIC;
132 else if (!strcmp(optarg, "TIME"))
133 policy->policy_to_use = TIME;
134 else if (!strcmp(optarg, "WORKLOAD"))
135 policy->policy_to_use = WORKLOAD;
136 else if (!strcmp(optarg, "BRANCH_RATIO"))
137 policy->policy_to_use = BRANCH_RATIO;
139 printf("Invalid policy specified: %s\n",
155 argv[optind-1] = prgname;
158 optind = 0; /* reset getopt lib */
163 main(int argc, char **argv)
168 ret = rte_eal_init(argc, argv);
170 rte_panic("Cannot init EAL\n");
172 signal(SIGINT, sig_handler);
173 signal(SIGTERM, sig_handler);
178 /* parse application arguments (after the EAL ones) */
179 ret = parse_args(argc, argv);
181 rte_exit(EXIT_FAILURE, "Invalid arguments\n");
183 rte_power_set_env(PM_ENV_KVM_VM);
184 RTE_LCORE_FOREACH(lcore_id) {
185 rte_power_init(lcore_id);