summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wiles <keith.wiles@intel.com>2017-09-11 18:34:05 -0500
committerKeith Wiles <keith.wiles@intel.com>2017-11-25 07:48:58 -0600
commita85878759683cdbdc2718fc4fe4ae03d390f5ecb (patch)
tree6f7d86706b11b0736c047c71d42522d0f93eb303
parent1ac2a7fa6cb155df9348e0adf9fa441305a7dde4 (diff)
downloaddpdk-draft-cli-a85878759683cdbdc2718fc4fe4ae03d390f5ecb.zip
dpdk-draft-cli-a85878759683cdbdc2718fc4fe4ae03d390f5ecb.tar.gz
dpdk-draft-cli-a85878759683cdbdc2718fc4fe4ae03d390f5ecb.tar.xz
vm_power_manager: add cli code
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
-rw-r--r--examples/vm_power_manager/vm_power_cli.c412
1 files changed, 412 insertions, 0 deletions
diff --git a/examples/vm_power_manager/vm_power_cli.c b/examples/vm_power_manager/vm_power_cli.c
index 6f234fb..fb388d0 100644
--- a/examples/vm_power_manager/vm_power_cli.c
+++ b/examples/vm_power_manager/vm_power_cli.c
@@ -39,12 +39,22 @@
#include <termios.h>
#include <errno.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 <rte_string_fns.h>
+
+#include <cli.h>
+#include <cli_file.h>
+#include <cli_map.h>
+#include <cli_help.h>
+#include <cli_string_fns.h>
+#endif
#include "vm_power_cli.h"
#include "channel_manager.h"
@@ -52,6 +62,7 @@
#include "power_manager.h"
#include "channel_commands.h"
+#ifndef RTE_LIBRTE_CLI
struct cmd_quit_result {
cmdline_fixed_string_t quit;
};
@@ -677,3 +688,404 @@ run_cli(__attribute__((unused)) void *arg)
cmdline_interact(cl);
cmdline_stdin_exit(cl);
}
+#else
+static struct cli_map vm_map[] = {
+ { 10, "show_vm %s" },
+ { 20, "add_vm %s" },
+ { 30, "rm_vm %s" },
+ {-1, NULL}
+};
+
+static int
+vm_cmd(int argc, char **argv)
+{
+ struct cli_map *m;
+
+ m = cli_mapping(vm_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10: {
+ struct vm_info info;
+ unsigned i;
+
+ if (get_info_vm(argv[1], &info) != 0)
+ return 0;
+ cli_printf("VM: '%s', status = ", info.name);
+ if (info.status == CHANNEL_MGR_VM_ACTIVE)
+ cli_printf("ACTIVE\n");
+ else
+ cli_printf("INACTIVE\n");
+ cli_printf("Channels %u\n", info.num_channels);
+ for (i = 0; i < info.num_channels; i++) {
+ cli_printf(" [%u]: %s, status = ", i,
+ info.channels[i].channel_path);
+ switch (info.channels[i].status) {
+ case CHANNEL_MGR_CHANNEL_CONNECTED:
+ cli_printf("CONNECTED\n");
+ break;
+ case CHANNEL_MGR_CHANNEL_DISCONNECTED:
+ cli_printf("DISCONNECTED\n");
+ break;
+ case CHANNEL_MGR_CHANNEL_DISABLED:
+ cli_printf("DISABLED\n");
+ break;
+ case CHANNEL_MGR_CHANNEL_PROCESSING:
+ cli_printf("PROCESSING\n");
+ break;
+ default:
+ cli_printf("UNKNOWN\n");
+ break;
+ }
+ }
+ cli_printf("Virtual CPU(s): %u\n", info.num_vcpus);
+ for (i = 0; i < info.num_vcpus; i++) {
+ cli_printf(" [%u]: Physical CPU Mask 0x%"PRIx64"\n", i,
+ info.pcpu_mask[i]);
+ }
+ }
+ break;
+ case 20:
+ case 30:
+ if (!strcmp(argv[0], "add_vm")) {
+ if (add_vm(argv[1]) < 0)
+ cli_printf("Unable to add VM '%s'\n", argv[1]);
+ } else if (remove_vm(argv[1]) < 0)
+ cli_printf("Unable to remove VM '%s'\n", argv[1]);
+ break;
+ }
+ return 0;
+}
+
+static struct cli_map channel_map[] = {
+ { 10, "add_channels %s %s"},
+ { 20, "set_channel_status %s %s %|enable|disable"},
+ {-1, NULL}
+};
+
+static int
+channel_cmd(int argc, char **argv)
+{
+ struct cli_map *m;
+
+ m = cli_mapping(channel_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10: {
+ unsigned num_channels = 0, channel_num, i;
+ int channels_added;
+ unsigned channel_list[CHANNEL_CMDS_MAX_VM_CHANNELS];
+ char *token, *remaining, *tail_ptr;
+
+ if (!strcmp(argv[2], "all")) {
+ channels_added = add_all_channels(argv[1]);
+ cli_printf("Added %d channels for VM '%s'\n",
+ channels_added, argv[1]);
+ return 0;
+ }
+
+ remaining = argv[2];
+ while (1) {
+ if (remaining == NULL || remaining[0] == '\0')
+ break;
+
+ token = strsep(&remaining, ",");
+ if (token == NULL)
+ break;
+ errno = 0;
+ channel_num = (unsigned)strtol(token, &tail_ptr, 10);
+ if ((errno != 0) || tail_ptr == NULL || (*tail_ptr != '\0'))
+ break;
+
+ if (channel_num == CHANNEL_CMDS_MAX_VM_CHANNELS) {
+ cli_printf("Channel number '%u' exceeds the maximum number "
+ "of allowable channels(%u) for VM '%s'\n", channel_num,
+ CHANNEL_CMDS_MAX_VM_CHANNELS, argv[1]);
+ return 0;
+ }
+ channel_list[num_channels++] = channel_num;
+ }
+ for (i = 0; i < num_channels; i++)
+ cli_printf("[%u]: Adding channel %u\n", i, channel_list[i]);
+
+ channels_added = add_channels(argv[1], channel_list,
+ num_channels);
+ cli_printf("Enabled %d channels for '%s'\n", channels_added,
+ argv[1]);
+ }
+ break;
+ case 20: {
+ unsigned num_channels = 0, channel_num;
+ int changed;
+ unsigned channel_list[CHANNEL_CMDS_MAX_VM_CHANNELS];
+ char *token, *remaining, *tail_ptr;
+ enum channel_status status;
+
+ if (!strcmp(argv[3], "enabled"))
+ status = CHANNEL_MGR_CHANNEL_CONNECTED;
+ else
+ status = CHANNEL_MGR_CHANNEL_DISABLED;
+
+ if (!strcmp(argv[2], "all")) {
+ changed = set_channel_status_all(argv[1], status);
+ cli_printf("Updated status of %d channels "
+ "for VM '%s'\n", changed, argv[1]);
+ return 0;
+ }
+ remaining = argv[2];
+ while (1) {
+ if (remaining == NULL || remaining[0] == '\0')
+ break;
+ token = strsep(&remaining, ",");
+ if (token == NULL)
+ break;
+ errno = 0;
+ channel_num = (unsigned)strtol(token, &tail_ptr, 10);
+ if ((errno != 0) || tail_ptr == NULL || (*tail_ptr != '\0'))
+ break;
+
+ if (channel_num == CHANNEL_CMDS_MAX_VM_CHANNELS) {
+ cli_printf("%u exceeds the maximum number of allowable "
+ "channels(%u) for VM '%s'\n", channel_num,
+ CHANNEL_CMDS_MAX_VM_CHANNELS, argv[1]);
+ return 0;
+ }
+ channel_list[num_channels++] = channel_num;
+ }
+ changed = set_channel_status(argv[1], channel_list, num_channels,
+ status);
+ cli_printf("Updated status of %d channels "
+ "for VM '%s'\n", changed, argv[1]);
+ }
+ break;
+ }
+ return 0;
+}
+
+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];
+ core_num = atoi(argv[1]);
+ if (!strcmp(cmd , "up"))
+ ret = power_manager_scale_core_up(core_num);
+ else if (!strcmp(cmd , "down"))
+ ret = power_manager_scale_core_down(core_num);
+ else if (!strcmp(cmd , "min"))
+ ret = power_manager_scale_core_min(core_num);
+ else if (!strcmp(cmd , "max"))
+ ret = power_manager_scale_core_max(core_num);
+ if (ret < 0) {
+ cli_printf("Error scaling core(%u) '%s'\n",
+ core_num, cmd);
+ }
+ 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 pcpu_map[] = {
+ { 10, "set_pcpu_mask %s %d %D" },
+ { 20, "set_pcpu %s %d %D"},
+ {-1, NULL}
+};
+
+static int
+pcpu_cmd(int argc, char **argv)
+{
+ struct cli_map *m;
+ uint8_t vcpu;
+ uint64_t mask;
+
+ m = cli_mapping(pcpu_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10:
+ vcpu = atoi(argv[2]);
+ mask = strtoull(argv[3], NULL, 0);
+ if (set_pcpus_mask(argv[1], vcpu, mask) == 0)
+ cli_printf("Pinned vCPU(%"PRId8") to pCPU core "
+ "mask(0x%"PRIx64")\n", vcpu, mask);
+ else
+ cli_printf("Unable to pin vCPU(%"PRId8") to pCPU core "
+ "mask(0x%"PRIx64")\n", vcpu, mask);
+ break;
+ case 20:
+ vcpu = atoi(argv[2]);
+ mask = strtoull(argv[3], NULL, 0);
+ if (set_pcpu(argv[1], vcpu, mask) == 0)
+ cli_printf("Pinned vCPU(%"PRId8") to pCPU core "
+ "%"PRId64")\n", vcpu, mask);
+ else
+ cli_printf("Unable to pin vCPU(%"PRId8") to pCPU core "
+ "%"PRId64")\n", vcpu, mask);
+ 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;
+
+ m = cli_mapping(my_map, argc, argv);
+ if (!m)
+ return -1;
+
+ switch (m->index) {
+ case 10:
+ channel_monitor_exit();
+ channel_manager_exit();
+ power_manager_exit();
+ cli_quit();
+ break;
+ case 20:
+ break;
+ }
+ return 0;
+}
+
+static struct cli_tree my_tree[] = {
+ c_dir("/bin"),
+ c_cmd("add_vm", vm_cmd, "add a VM"),
+ c_cmd("rm_vm", vm_cmd, "remove a VM"),
+ c_cmd("show_vm", vm_cmd, "show a VM"),
+
+ c_cmd("add_channels", channel_cmd, "add channels"),
+ c_cmd("set_channel_status", channel_cmd, "set channel status"),
+
+ c_cmd("show_cpu_freq_mask", cpu_cmd, "show cpu freq mask"),
+ c_cmd("set_cpu_freq", cpu_cmd, "set cpu freq mask"),
+ c_cmd("show_cpu_freq", cpu_cmd, "show cpu freq"),
+ c_cmd("set_pcpu_mask", pcpu_cmd, "set pcpu mask"),
+ c_cmd("set_pcpu", pcpu_cmd, "set pcpu"),
+
+ 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");
+ 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