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>
46 #include <rte_config.h>
48 #include <rte_lcore.h>
50 #include <rte_power.h>
52 #include "vm_power_cli_guest.h"
55 #define CHANNEL_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
58 #define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
60 struct cmd_quit_result {
61 cmdline_fixed_string_t quit;
64 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
65 __attribute__((unused)) struct cmdline *cl,
66 __attribute__((unused)) void *data)
70 RTE_LCORE_FOREACH(lcore_id) {
71 rte_power_exit(lcore_id);
76 cmdline_parse_token_string_t cmd_quit_quit =
77 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
79 cmdline_parse_inst_t cmd_quit = {
80 .f = cmd_quit_parsed, /* function to call */
81 .data = NULL, /* 2nd arg of func */
82 .help_str = "close the application",
83 .tokens = { /* token list, NULL terminated */
84 (void *)&cmd_quit_quit,
89 /* *** VM operations *** */
91 struct cmd_set_cpu_freq_result {
92 cmdline_fixed_string_t set_cpu_freq;
94 cmdline_fixed_string_t cmd;
98 cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl,
99 __attribute__((unused)) void *data)
102 struct cmd_set_cpu_freq_result *res = parsed_result;
104 if (!strcmp(res->cmd , "up"))
105 ret = rte_power_freq_up(res->lcore_id);
106 else if (!strcmp(res->cmd , "down"))
107 ret = rte_power_freq_down(res->lcore_id);
108 else if (!strcmp(res->cmd , "min"))
109 ret = rte_power_freq_min(res->lcore_id);
110 else if (!strcmp(res->cmd , "max"))
111 ret = rte_power_freq_max(res->lcore_id);
113 cmdline_printf(cl, "Error sending message: %s\n", strerror(ret));
116 cmdline_parse_token_string_t cmd_set_cpu_freq =
117 TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
118 set_cpu_freq, "set_cpu_freq");
119 cmdline_parse_token_string_t cmd_set_cpu_freq_core_num =
120 TOKEN_NUM_INITIALIZER(struct cmd_set_cpu_freq_result,
122 cmdline_parse_token_string_t cmd_set_cpu_freq_cmd_cmd =
123 TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
124 cmd, "up#down#min#max");
126 cmdline_parse_inst_t cmd_set_cpu_freq_set = {
127 .f = cmd_set_cpu_freq_parsed,
129 .help_str = "set_cpu_freq <core_num> <up|down|min|max>, Set the current "
130 "frequency for the specified core by scaling up/down/min/max",
132 (void *)&cmd_set_cpu_freq,
133 (void *)&cmd_set_cpu_freq_core_num,
134 (void *)&cmd_set_cpu_freq_cmd_cmd,
139 cmdline_parse_ctx_t main_ctx[] = {
140 (cmdline_parse_inst_t *)&cmd_quit,
141 (cmdline_parse_inst_t *)&cmd_set_cpu_freq_set,
146 run_cli(__attribute__((unused)) void *arg)
150 cl = cmdline_stdin_new(main_ctx, "vmpower(guest)> ");
154 cmdline_interact(cl);
155 cmdline_stdin_exit(cl);