4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <cmdline_rdline.h>
41 #include <cmdline_parse.h>
42 #include <cmdline_parse_string.h>
43 #include <cmdline_parse_num.h>
44 #include <cmdline_socket.h>
47 #include <rte_lcore.h>
48 #include <rte_ethdev.h>
50 #include <rte_power.h>
51 #include <guest_channel.h>
53 #include "vm_power_cli_guest.h"
56 #define CHANNEL_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
59 #define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
61 struct cmd_quit_result {
62 cmdline_fixed_string_t quit;
65 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
66 __attribute__((unused)) struct cmdline *cl,
67 __attribute__((unused)) void *data)
71 RTE_LCORE_FOREACH(lcore_id) {
72 rte_power_exit(lcore_id);
77 cmdline_parse_token_string_t cmd_quit_quit =
78 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
80 cmdline_parse_inst_t cmd_quit = {
81 .f = cmd_quit_parsed, /* function to call */
82 .data = NULL, /* 2nd arg of func */
83 .help_str = "close the application",
84 .tokens = { /* token list, NULL terminated */
85 (void *)&cmd_quit_quit,
90 /* *** VM operations *** */
92 struct cmd_set_cpu_freq_result {
93 cmdline_fixed_string_t set_cpu_freq;
95 cmdline_fixed_string_t cmd;
99 cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl,
100 __attribute__((unused)) void *data)
103 struct cmd_set_cpu_freq_result *res = parsed_result;
105 if (!strcmp(res->cmd , "up"))
106 ret = rte_power_freq_up(res->lcore_id);
107 else if (!strcmp(res->cmd , "down"))
108 ret = rte_power_freq_down(res->lcore_id);
109 else if (!strcmp(res->cmd , "min"))
110 ret = rte_power_freq_min(res->lcore_id);
111 else if (!strcmp(res->cmd , "max"))
112 ret = rte_power_freq_max(res->lcore_id);
113 else if (!strcmp(res->cmd, "enable_turbo"))
114 ret = rte_power_freq_enable_turbo(res->lcore_id);
115 else if (!strcmp(res->cmd, "disable_turbo"))
116 ret = rte_power_freq_disable_turbo(res->lcore_id);
118 cmdline_printf(cl, "Error sending message: %s\n", strerror(ret));
121 cmdline_parse_token_string_t cmd_set_cpu_freq =
122 TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
123 set_cpu_freq, "set_cpu_freq");
124 cmdline_parse_token_string_t cmd_set_cpu_freq_core_num =
125 TOKEN_NUM_INITIALIZER(struct cmd_set_cpu_freq_result,
127 cmdline_parse_token_string_t cmd_set_cpu_freq_cmd_cmd =
128 TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
129 cmd, "up#down#min#max#enable_turbo#disable_turbo");
131 cmdline_parse_inst_t cmd_set_cpu_freq_set = {
132 .f = cmd_set_cpu_freq_parsed,
134 .help_str = "set_cpu_freq <core_num> "
135 "<up|down|min|max|enable_turbo|disable_turbo>, "
136 "adjust the frequency for the specified core.",
138 (void *)&cmd_set_cpu_freq,
139 (void *)&cmd_set_cpu_freq_core_num,
140 (void *)&cmd_set_cpu_freq_cmd_cmd,
145 struct cmd_send_policy_result {
146 cmdline_fixed_string_t send_policy;
147 cmdline_fixed_string_t cmd;
151 struct ether_addr addr;
158 struct channel_packet pkt;
162 /* Use port MAC address as the vfid */
163 rte_eth_macaddr_get(0, &pfid.addr);
164 printf("Port %u MAC: %02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":"
165 "%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 "\n",
167 pfid.addr.addr_bytes[0], pfid.addr.addr_bytes[1],
168 pfid.addr.addr_bytes[2], pfid.addr.addr_bytes[3],
169 pfid.addr.addr_bytes[4], pfid.addr.addr_bytes[5]);
170 pkt.vfid[0] = pfid.pfid;
172 pkt.nb_mac_to_monitor = 1;
173 pkt.t_boost_status.tbEnabled = false;
175 pkt.vcpu_to_control[0] = 0;
176 pkt.vcpu_to_control[1] = 1;
178 /* Dummy Population. */
179 pkt.traffic_policy.min_packet_thresh = 96000;
180 pkt.traffic_policy.avg_max_packet_thresh = 1800000;
181 pkt.traffic_policy.max_max_packet_thresh = 2000000;
183 pkt.timer_policy.busy_hours[0] = 3;
184 pkt.timer_policy.busy_hours[1] = 4;
185 pkt.timer_policy.busy_hours[2] = 5;
186 pkt.timer_policy.quiet_hours[0] = 11;
187 pkt.timer_policy.quiet_hours[1] = 12;
188 pkt.timer_policy.quiet_hours[2] = 13;
190 pkt.timer_policy.hours_to_use_traffic_profile[0] = 8;
191 pkt.timer_policy.hours_to_use_traffic_profile[1] = 10;
194 pkt.policy_to_use = TIME;
195 pkt.command = PKT_POLICY;
196 strcpy(pkt.vm_name, "ubuntu2");
197 ret = rte_power_guest_channel_send_msg(&pkt, 1);
200 RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
201 ret > 0 ? strerror(ret) : "channel not connected");
206 cmd_send_policy_parsed(void *parsed_result, struct cmdline *cl,
207 __attribute__((unused)) void *data)
210 struct cmd_send_policy_result *res = parsed_result;
212 if (!strcmp(res->cmd, "now")) {
213 printf("Sending Policy down now!\n");
217 cmdline_printf(cl, "Error sending message: %s\n",
221 cmdline_parse_token_string_t cmd_send_policy =
222 TOKEN_STRING_INITIALIZER(struct cmd_send_policy_result,
223 send_policy, "send_policy");
224 cmdline_parse_token_string_t cmd_send_policy_cmd_cmd =
225 TOKEN_STRING_INITIALIZER(struct cmd_send_policy_result,
228 cmdline_parse_inst_t cmd_send_policy_set = {
229 .f = cmd_send_policy_parsed,
231 .help_str = "send_policy now",
233 (void *)&cmd_send_policy,
234 (void *)&cmd_send_policy_cmd_cmd,
239 cmdline_parse_ctx_t main_ctx[] = {
240 (cmdline_parse_inst_t *)&cmd_quit,
241 (cmdline_parse_inst_t *)&cmd_send_policy_set,
242 (cmdline_parse_inst_t *)&cmd_set_cpu_freq_set,
247 run_cli(__attribute__((unused)) void *arg)
251 cl = cmdline_stdin_new(main_ctx, "vmpower(guest)> ");
255 cmdline_interact(cl);
256 cmdline_stdin_exit(cl);