#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <termios.h>
#include <cmdline_rdline.h>
#include <cmdline_parse.h>
#include <cmdline_parse_string.h>
#include <cmdline_parse_num.h>
#include <cmdline_socket.h>
#include "vm_power_cli_guest.h"
#define CHANNEL_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
struct cmd_quit_result {
cmdline_fixed_string_t quit;
};
static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
__attribute__((unused)) struct cmdline *cl,
__attribute__((unused)) void *data)
{
unsigned lcore_id;
}
cmdline_quit(cl);
}
cmdline_parse_token_string_t cmd_quit_quit =
TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
cmdline_parse_inst_t cmd_quit = {
.f = cmd_quit_parsed,
.data = NULL,
.help_str = "close the application",
.tokens = {
(void *)&cmd_quit_quit,
NULL,
},
};
struct cmd_set_cpu_freq_result {
cmdline_fixed_string_t set_cpu_freq;
uint8_t lcore_id;
cmdline_fixed_string_t cmd;
};
static void
cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl,
__attribute__((unused)) void *data)
{
int ret = -1;
struct cmd_set_cpu_freq_result *res = parsed_result;
if (!strcmp(res->cmd , "up"))
else if (!strcmp(res->cmd , "down"))
else if (!strcmp(res->cmd , "min"))
else if (!strcmp(res->cmd , "max"))
if (ret != 1)
cmdline_printf(cl, "Error sending message: %s\n", strerror(ret));
}
cmdline_parse_token_string_t cmd_set_cpu_freq =
TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
set_cpu_freq, "set_cpu_freq");
cmdline_parse_token_string_t cmd_set_cpu_freq_core_num =
TOKEN_NUM_INITIALIZER(struct cmd_set_cpu_freq_result,
lcore_id, UINT8);
cmdline_parse_token_string_t cmd_set_cpu_freq_cmd_cmd =
TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_result,
cmd, "up#down#min#max");
cmdline_parse_inst_t cmd_set_cpu_freq_set = {
.f = cmd_set_cpu_freq_parsed,
.data = NULL,
.help_str = "set_cpu_freq <core_num> <up|down|min|max>, Set the current "
"frequency for the specified core by scaling up/down/min/max",
.tokens = {
(void *)&cmd_set_cpu_freq,
(void *)&cmd_set_cpu_freq_core_num,
(void *)&cmd_set_cpu_freq_cmd_cmd,
NULL,
},
};
cmdline_parse_ctx_t main_ctx[] = {
(cmdline_parse_inst_t *)&cmd_quit,
(cmdline_parse_inst_t *)&cmd_set_cpu_freq_set,
NULL,
};
void
run_cli(__attribute__((unused)) void *arg)
{
struct cmdline *cl;
cl = cmdline_stdin_new(main_ctx, "vmpower(guest)> ");
if (cl == NULL)
return;
cmdline_interact(cl);
cmdline_stdin_exit(cl);
}