X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvm_power_manager%2Fvm_power_cli.c;h=5f64b83fb0cb772c83c760fd8fc048b8ff57099e;hb=e1143d7dbbf484837f3eefb077a9b0af0f7e1c45;hp=e7f4469170905b44ba9cacaf5a0a4c9e2e919875;hpb=3842bf2424e27d4092fafcab000e10935c5d47f3;p=dpdk.git diff --git a/examples/vm_power_manager/vm_power_cli.c b/examples/vm_power_manager/vm_power_cli.c index e7f4469170..5f64b83fb0 100644 --- a/examples/vm_power_manager/vm_power_cli.c +++ b/examples/vm_power_manager/vm_power_cli.c @@ -1,34 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation */ #include @@ -45,7 +16,6 @@ #include #include #include -#include #include "vm_power_cli.h" #include "channel_manager.h" @@ -125,8 +95,8 @@ cmd_show_vm_parsed(void *parsed_result, struct cmdline *cl, } cmdline_printf(cl, "Virtual CPU(s): %u\n", info.num_vcpus); for (i = 0; i < info.num_vcpus; i++) { - cmdline_printf(cl, " [%u]: Physical CPU Mask 0x%"PRIx64"\n", i, - info.pcpu_mask[i]); + cmdline_printf(cl, " [%u]: Physical CPU %d\n", i, + info.pcpu_map[i]); } } @@ -154,55 +124,8 @@ cmdline_parse_inst_t cmd_show_vm_set = { }; /* *** vCPU to pCPU mapping operations *** */ -struct cmd_set_pcpu_mask_result { - cmdline_fixed_string_t set_pcpu_mask; - cmdline_fixed_string_t vm_name; - uint8_t vcpu; - uint64_t core_mask; -}; - -static void -cmd_set_pcpu_mask_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) -{ - struct cmd_set_pcpu_mask_result *res = parsed_result; - - if (set_pcpus_mask(res->vm_name, res->vcpu, res->core_mask) == 0) - cmdline_printf(cl, "Pinned vCPU(%"PRId8") to pCPU core " - "mask(0x%"PRIx64")\n", res->vcpu, res->core_mask); - else - cmdline_printf(cl, "Unable to pin vCPU(%"PRId8") to pCPU core " - "mask(0x%"PRIx64")\n", res->vcpu, res->core_mask); -} - -cmdline_parse_token_string_t cmd_set_pcpu_mask = - TOKEN_STRING_INITIALIZER(struct cmd_set_pcpu_mask_result, - set_pcpu_mask, "set_pcpu_mask"); -cmdline_parse_token_string_t cmd_set_pcpu_mask_vm_name = - TOKEN_STRING_INITIALIZER(struct cmd_set_pcpu_mask_result, - vm_name, NULL); -cmdline_parse_token_num_t set_pcpu_mask_vcpu = - TOKEN_NUM_INITIALIZER(struct cmd_set_pcpu_mask_result, - vcpu, UINT8); -cmdline_parse_token_num_t set_pcpu_mask_core_mask = - TOKEN_NUM_INITIALIZER(struct cmd_set_pcpu_mask_result, - core_mask, UINT64); -cmdline_parse_inst_t cmd_set_pcpu_mask_set = { - .f = cmd_set_pcpu_mask_parsed, - .data = NULL, - .help_str = "set_pcpu_mask , Set the binding " - "of Virtual CPU on VM to the Physical CPU mask.", - .tokens = { - (void *)&cmd_set_pcpu_mask, - (void *)&cmd_set_pcpu_mask_vm_name, - (void *)&set_pcpu_mask_vcpu, - (void *)&set_pcpu_mask_core_mask, - NULL, - }, -}; - struct cmd_set_pcpu_result { cmdline_fixed_string_t set_pcpu; cmdline_fixed_string_t vm_name; @@ -302,7 +225,7 @@ cmd_channels_op_parsed(void *parsed_result, struct cmdline *cl, { unsigned num_channels = 0, channel_num, i; int channels_added; - unsigned channel_list[CHANNEL_CMDS_MAX_VM_CHANNELS]; + unsigned int channel_list[RTE_MAX_LCORE]; char *token, *remaining, *tail_ptr; struct cmd_channels_op_result *res = parsed_result; @@ -323,13 +246,13 @@ cmd_channels_op_parsed(void *parsed_result, struct cmdline *cl, break; errno = 0; channel_num = (unsigned)strtol(token, &tail_ptr, 10); - if ((errno != 0) || (*tail_ptr != '\0') || tail_ptr == NULL) + if ((errno != 0) || tail_ptr == NULL || (*tail_ptr != '\0')) break; - if (channel_num == CHANNEL_CMDS_MAX_VM_CHANNELS) { + if (channel_num == RTE_MAX_LCORE) { cmdline_printf(cl, "Channel number '%u' exceeds the maximum number " "of allowable channels(%u) for VM '%s'\n", channel_num, - CHANNEL_CMDS_MAX_VM_CHANNELS, res->vm_name); + RTE_MAX_LCORE, res->vm_name); return; } channel_list[num_channels++] = channel_num; @@ -370,6 +293,53 @@ cmdline_parse_inst_t cmd_channels_op_set = { }, }; +struct cmd_set_query_result { + cmdline_fixed_string_t set_query; + cmdline_fixed_string_t vm_name; + cmdline_fixed_string_t query_status; +}; + +static void +cmd_set_query_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_query_result *res = parsed_result; + + if (!strcmp(res->query_status, "enable")) { + if (set_query_status(res->vm_name, true) < 0) + cmdline_printf(cl, "Unable to allow query for VM '%s'\n", + res->vm_name); + } else if (!strcmp(res->query_status, "disable")) { + if (set_query_status(res->vm_name, false) < 0) + cmdline_printf(cl, "Unable to disallow query for VM '%s'\n", + res->vm_name); + } +} + +cmdline_parse_token_string_t cmd_set_query = + TOKEN_STRING_INITIALIZER(struct cmd_set_query_result, + set_query, "set_query"); +cmdline_parse_token_string_t cmd_set_query_vm_name = + TOKEN_STRING_INITIALIZER(struct cmd_set_query_result, + vm_name, NULL); +cmdline_parse_token_string_t cmd_set_query_status = + TOKEN_STRING_INITIALIZER(struct cmd_set_query_result, + query_status, "enable#disable"); + +cmdline_parse_inst_t cmd_set_query_set = { + .f = cmd_set_query_parsed, + .data = NULL, + .help_str = "set_query , allow or disallow queries" + " for the specified VM", + .tokens = { + (void *)&cmd_set_query, + (void *)&cmd_set_query_vm_name, + (void *)&cmd_set_query_status, + NULL, + }, +}; + struct cmd_channels_status_op_result { cmdline_fixed_string_t op; cmdline_fixed_string_t vm_name; @@ -383,7 +353,7 @@ cmd_channels_status_op_parsed(void *parsed_result, struct cmdline *cl, { unsigned num_channels = 0, channel_num; int changed; - unsigned channel_list[CHANNEL_CMDS_MAX_VM_CHANNELS]; + unsigned int channel_list[RTE_MAX_LCORE]; char *token, *remaining, *tail_ptr; struct cmd_channels_status_op_result *res = parsed_result; enum channel_status status; @@ -408,13 +378,13 @@ cmd_channels_status_op_parsed(void *parsed_result, struct cmdline *cl, break; errno = 0; channel_num = (unsigned)strtol(token, &tail_ptr, 10); - if ((errno != 0) || (*tail_ptr != '\0') || tail_ptr == NULL) + if ((errno != 0) || tail_ptr == NULL || (*tail_ptr != '\0')) break; - if (channel_num == CHANNEL_CMDS_MAX_VM_CHANNELS) { + if (channel_num == RTE_MAX_LCORE) { cmdline_printf(cl, "%u exceeds the maximum number of allowable " "channels(%u) for VM '%s'\n", channel_num, - CHANNEL_CMDS_MAX_VM_CHANNELS, res->vm_name); + RTE_MAX_LCORE, res->vm_name); return; } channel_list[num_channels++] = channel_num; @@ -458,102 +428,6 @@ cmdline_parse_inst_t cmd_channels_status_op_set = { }; /* *** CPU Frequency operations *** */ -struct cmd_show_cpu_freq_mask_result { - cmdline_fixed_string_t show_cpu_freq_mask; - uint64_t core_mask; -}; - -static void -cmd_show_cpu_freq_mask_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) -{ - struct cmd_show_cpu_freq_mask_result *res = parsed_result; - unsigned i; - uint64_t mask = res->core_mask; - uint32_t freq; - - for (i = 0; mask; mask &= ~(1ULL << i++)) { - if ((mask >> i) & 1) { - freq = power_manager_get_current_frequency(i); - if (freq > 0) - cmdline_printf(cl, "Core %u: %"PRId32"\n", i, freq); - } - } -} - -cmdline_parse_token_string_t cmd_show_cpu_freq_mask = - TOKEN_STRING_INITIALIZER(struct cmd_show_cpu_freq_mask_result, - show_cpu_freq_mask, "show_cpu_freq_mask"); -cmdline_parse_token_num_t cmd_show_cpu_freq_mask_core_mask = - TOKEN_NUM_INITIALIZER(struct cmd_show_cpu_freq_mask_result, - core_mask, UINT64); - -cmdline_parse_inst_t cmd_show_cpu_freq_mask_set = { - .f = cmd_show_cpu_freq_mask_parsed, - .data = NULL, - .help_str = "show_cpu_freq_mask , Get the current frequency for each " - "core specified in the mask", - .tokens = { - (void *)&cmd_show_cpu_freq_mask, - (void *)&cmd_show_cpu_freq_mask_core_mask, - NULL, - }, -}; - -struct cmd_set_cpu_freq_mask_result { - cmdline_fixed_string_t set_cpu_freq_mask; - uint64_t core_mask; - cmdline_fixed_string_t cmd; -}; - -static void -cmd_set_cpu_freq_mask_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) -{ - struct cmd_set_cpu_freq_mask_result *res = parsed_result; - int ret = -1; - - if (!strcmp(res->cmd , "up")) - ret = power_manager_scale_mask_up(res->core_mask); - else if (!strcmp(res->cmd , "down")) - ret = power_manager_scale_mask_down(res->core_mask); - else if (!strcmp(res->cmd , "min")) - ret = power_manager_scale_mask_min(res->core_mask); - else if (!strcmp(res->cmd , "max")) - ret = power_manager_scale_mask_max(res->core_mask); - if (ret < 0) { - cmdline_printf(cl, "Error scaling core_mask(0x%"PRIx64") '%s' , not " - "all cores specified have been scaled\n", - res->core_mask, res->cmd); - }; -} - -cmdline_parse_token_string_t cmd_set_cpu_freq_mask = - TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_mask_result, - set_cpu_freq_mask, "set_cpu_freq_mask"); -cmdline_parse_token_num_t cmd_set_cpu_freq_mask_core_mask = - TOKEN_NUM_INITIALIZER(struct cmd_set_cpu_freq_mask_result, - core_mask, UINT64); -cmdline_parse_token_string_t cmd_set_cpu_freq_mask_result = - TOKEN_STRING_INITIALIZER(struct cmd_set_cpu_freq_mask_result, - cmd, "up#down#min#max"); - -cmdline_parse_inst_t cmd_set_cpu_freq_mask_set = { - .f = cmd_set_cpu_freq_mask_parsed, - .data = NULL, - .help_str = "set_cpu_freq , Set the current " - "frequency for the cores specified in by scaling " - "each up/down/min/max.", - .tokens = { - (void *)&cmd_set_cpu_freq_mask, - (void *)&cmd_set_cpu_freq_mask_core_mask, - (void *)&cmd_set_cpu_freq_mask_result, - NULL, - }, -}; - - - struct cmd_show_cpu_freq_result { cmdline_fixed_string_t show_cpu_freq; uint8_t core_num; @@ -615,6 +489,10 @@ cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl, ret = power_manager_scale_core_min(res->core_num); else if (!strcmp(res->cmd , "max")) ret = power_manager_scale_core_max(res->core_num); + else if (!strcmp(res->cmd, "enable_turbo")) + ret = power_manager_enable_turbo_core(res->core_num); + else if (!strcmp(res->cmd, "disable_turbo")) + ret = power_manager_disable_turbo_core(res->core_num); if (ret < 0) { cmdline_printf(cl, "Error scaling core(%u) '%s'\n", res->core_num, res->cmd); @@ -624,18 +502,18 @@ cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl, 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 = +cmdline_parse_token_num_t cmd_set_cpu_freq_core_num = TOKEN_NUM_INITIALIZER(struct cmd_set_cpu_freq_result, core_num, 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"); + cmd, "up#down#min#max#enable_turbo#disable_turbo"); cmdline_parse_inst_t cmd_set_cpu_freq_set = { .f = cmd_set_cpu_freq_parsed, .data = NULL, - .help_str = "set_cpu_freq , Set the current " - "frequency for the specified core by scaling up/down/min/max", + .help_str = "set_cpu_freq , adjust the current " + "frequency for the specified core", .tokens = { (void *)&cmd_set_cpu_freq, (void *)&cmd_set_cpu_freq_core_num, @@ -650,12 +528,10 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_channels_op_set, (cmdline_parse_inst_t *)&cmd_channels_status_op_set, (cmdline_parse_inst_t *)&cmd_show_vm_set, - (cmdline_parse_inst_t *)&cmd_show_cpu_freq_mask_set, - (cmdline_parse_inst_t *)&cmd_set_cpu_freq_mask_set, (cmdline_parse_inst_t *)&cmd_show_cpu_freq_set, (cmdline_parse_inst_t *)&cmd_set_cpu_freq_set, - (cmdline_parse_inst_t *)&cmd_set_pcpu_mask_set, (cmdline_parse_inst_t *)&cmd_set_pcpu_set, + (cmdline_parse_inst_t *)&cmd_set_query_set, NULL, };