summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wiles <keith.wiles@intel.com>2017-09-18 08:44:09 -0500
committerKeith Wiles <keith.wiles@intel.com>2017-11-25 07:48:58 -0600
commitc513b28b2f9253624610b1eed551156d849f2eaa (patch)
tree1a6e15e0eacc85b407810af931dd3943b3882c92
parent01a35977326c2dcadd97e2ed2eaf5693469c50c4 (diff)
downloaddpdk-draft-cli-c513b28b2f9253624610b1eed551156d849f2eaa.zip
dpdk-draft-cli-c513b28b2f9253624610b1eed551156d849f2eaa.tar.gz
dpdk-draft-cli-c513b28b2f9253624610b1eed551156d849f2eaa.tar.xz
convert to cli
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
-rw-r--r--examples/vm_power_manager/guest_cli/vm_power_cli_guest.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
index 63f711e..7093f30 100644
--- a/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
+++ b/examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
@@ -37,12 +37,20 @@
#include <stdio.h>
#include <termios.h>
+#ifndef RTE_LIBRTE_CLI
#include <cmdline_rdline.h>
#include <cmdline_parse.h>
#include <cmdline_parse_string.h>
#include <cmdline_parse_num.h>
#include <cmdline_socket.h>
#include <cmdline.h>
+#else
+#include <cli.h>
+#include <cli_file.h>
+#include <cli_map.h>
+#include <cli_help.h>
+#include <cli_string_fns.h>
+#endif
#include <rte_log.h>
#include <rte_lcore.h>
#include <rte_ethdev.h>
@@ -58,6 +66,7 @@
#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+#ifndef RTE_LIBRTE_CLI
struct cmd_quit_result {
cmdline_fixed_string_t quit;
};
@@ -255,3 +264,172 @@ run_cli(__attribute__((unused)) void *arg)
cmdline_interact(cl);
cmdline_stdin_exit(cl);
}
+#else
+static struct cli_map cpu_map[] = {
+ { 10, "set_cpu_freq %d %|up|down|min|max" },
+ { 15, "set_cpu_freq_mask %D %|up|down|min|max"},
+ { 20, "show_cpu_freq %d" },
+ { 25, "show_cpu_freq_mask %d" },
+ {-1, NULL}
+};
+
+static int
+cpu_cmd(int argc, char **argv)
+{
+ struct cli_map *m;
+ uint64_t core_mask;
+ uint8_t core_num;
+ unsigned i;
+ char *cmd;
+ int ret = -1;
+ uint32_t freq;
+
+ m = cli_mapping(cpu_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10:
+ cmd = argv[2];
+ lcore_id = atoi(argv[1]);
+ if (!strcmp(cmd , "up"))
+ ret = rte_power_freq_up(res->lcore_id);
+ else if (!strcmp(cmd , "down"))
+ ret = rte_power_freq_down(res->lcore_id);
+ else if (!strcmp(cmd , "min"))
+ ret = rte_power_freq_min(res->lcore_id);
+ else if (!strcmp(cmd , "max"))
+ ret = rte_power_freq_max(res->lcore_id);
+ if (ret != 1)
+ cli_printf("Error sending message: %s\n", strerror(ret));
+ break;
+ case 15:
+ cmd = argv[2];
+ core_mask = strtoull(argv[1], NULL, 0);
+ if (!strcmp(cmd , "up"))
+ ret = power_manager_scale_mask_up(core_mask);
+ else if (!strcmp(cmd , "down"))
+ ret = power_manager_scale_mask_down(core_mask);
+ else if (!strcmp(cmd , "min"))
+ ret = power_manager_scale_mask_min(core_mask);
+ else if (!strcmp(cmd , "max"))
+ ret = power_manager_scale_mask_max(core_mask);
+ if (ret < 0) {
+ cli_printf("Error scaling core_mask(0x%"PRIx64
+ ") '%s' , not "
+ "all cores specified have been scaled\n",
+ core_mask, cmd);
+ };
+ break;
+ case 20: {
+ uint8_t core_num = atoi(argv[1]);
+ uint32_t curr_freq =
+ power_manager_get_current_frequency(core_num);
+
+ if (curr_freq == 0) {
+ cli_printf("Unable to get frequency for core %u\n",
+ core_num);
+ return 0;
+ }
+ cli_printf("Core %u frequency: %"PRId32"\n", core_num,
+ curr_freq);
+ }
+ break;
+ case 25:
+ core_mask = strtoull(argv[1], NULL, 0);
+ for (i = 0; core_mask; core_mask &= ~(1ULL << i++)) {
+ if ((core_mask >> i) & 1) {
+ freq = power_manager_get_current_frequency(i);
+ if (freq > 0)
+ cli_printf("Core %u: %"PRId32"\n",
+ i, freq);
+ }
+ }
+ break;
+ }
+
+ return 0;
+}
+
+static struct cli_map my_map[] = {
+ { 10, "exit" },
+ { 20, "help" },
+ {-1, NULL}
+};
+
+static int
+my_cmd(int argc, char **argv)
+{
+ struct cli_map *m;
+ unsigned lcore_id;
+
+ m = cli_mapping(my_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10:
+ RTE_LCORE_FOREACH(lcore_id) {
+ rte_power_exit(lcore_id);
+ }
+ cli_quit();
+ break;
+ case 20:
+ break;
+ }
+ return 0;
+}
+
+static struct cli_tree my_tree[] = {
+ c_dir("/bin"),
+ c_cmd("help", my_cmd, "print help"),
+ c_cmd("exit", my_cmd, "quit program"),
+ c_end()
+};
+
+static void
+my_prompt(int cont __rte_unused)
+{
+ char *str = cli_cwd_path();
+
+ if (strlen(str) > 1) /* trim the trailing '/' from string */
+ str[strlen(str) - 1] = '\0';
+
+ vt100_color(SCRN_GREEN, SCRN_NO_CHANGE, SCRN_BOLD);
+ cli_printf("%s:", (cont) ? " >> " : "vmpower(guest)");
+ vt100_color(SCRN_BLUE, SCRN_NO_CHANGE, SCRN_BOLD);
+ cli_printf("%s", str);
+ vt100_color(SCRN_DEFAULT_FG, SCRN_DEFAULT_BG, SCRN_OFF);
+ cli_printf("> ");
+}
+
+static int
+init_tree(void)
+{
+ /*
+ * Root is created already and using system default cmds and dirs, the
+ * developer is not required to use the system default cmds/dirs.
+ */
+ if (cli_default_tree_init())
+ return -1;
+
+ /* Using NULL here to start at root directory */
+ if (cli_add_tree(NULL, my_tree))
+ return -1;
+
+ cli_set_prompt(my_prompt);
+
+ return cli_add_bin_path("/bin");
+}
+
+/* prompt function, called from main on MASTER lcore */
+void
+run_cli(__attribute__((unused)) void *arg1)
+{
+ if (cli_create_with_tree(init_tree) == 0) {
+ cli_start(NULL);
+
+ cli_destroy();
+ }
+}
+#endif \ No newline at end of file