From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 790FB1B513 for ; Wed, 3 Apr 2019 19:16:23 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 10:16:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,305,1549958400"; d="scan'208";a="161086738" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.180]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 10:16:22 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Wed, 3 Apr 2019 19:15:59 +0200 Message-Id: <20190403171601.9788-4-marcinx.hajkowski@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190403171601.9788-1-marcinx.hajkowski@intel.com> References: <20190403171601.9788-1-marcinx.hajkowski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Apr 2019 17:16:24 -0000 From: Marcin Hajkowski Add new command which gives possibility to enable/disable queries form VM guest. Signed-off-by: Marcin Hajkowski --- examples/vm_power_manager/channel_manager.c | 20 +++++++++ examples/vm_power_manager/channel_manager.h | 18 ++++++++ examples/vm_power_manager/channel_monitor.c | 3 ++ examples/vm_power_manager/vm_power_cli.c | 48 +++++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 09bfa5c0d..7c852360a 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -57,6 +57,7 @@ struct virtual_machine_info { virDomainPtr domainPtr; virDomainInfo info; rte_spinlock_t config_spinlock; + int allow_query; LIST_ENTRY(virtual_machine_info) vms_info; }; @@ -344,6 +345,23 @@ setup_channel_info(struct virtual_machine_info **vm_info_dptr, return 0; } +int +set_query_status(char *vm_name, + bool allow_query) +{ + struct virtual_machine_info *vm_info; + + vm_info = find_domain_by_name(vm_name); + if (vm_info == NULL) { + RTE_LOG(ERR, CHANNEL_MANAGER, "VM '%s' not found\n", vm_name); + return -1; + } + rte_spinlock_lock(&(vm_info->config_spinlock)); + vm_info->allow_query = allow_query ? 1 : 0; + rte_spinlock_unlock(&(vm_info->config_spinlock)); + return 0; +} + static void fifo_path(char *dst, unsigned int len) { @@ -752,6 +770,7 @@ get_info_vm(const char *vm_name, struct vm_info *info) channel_num++; } + info->allow_query = vm_info->allow_query; info->num_channels = channel_num; info->num_vcpus = vm_info->info.nrVirtCpu; rte_spinlock_unlock(&(vm_info->config_spinlock)); @@ -828,6 +847,7 @@ add_vm(const char *vm_name) else new_domain->status = CHANNEL_MGR_VM_ACTIVE; + new_domain->allow_query = 0; rte_spinlock_init(&(new_domain->config_spinlock)); LIST_INSERT_HEAD(&vm_list_head, new_domain, vms_info); return 0; diff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h index c3cdce492..6b032a79f 100644 --- a/examples/vm_power_manager/channel_manager.h +++ b/examples/vm_power_manager/channel_manager.h @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include /* Maximum number of CPUs */ #define CHANNEL_CMDS_MAX_CPUS 256 @@ -82,6 +83,7 @@ struct vm_info { unsigned num_vcpus; /**< number of vCPUS */ struct channel_info channels[CHANNEL_MGR_MAX_CHANNELS]; /**< Array of channel_info */ unsigned num_channels; /**< Number of channels */ + int allow_query; /**< is query allowed */ }; /** @@ -146,6 +148,22 @@ uint16_t get_pcpu(struct channel_info *chan_info, unsigned int vcpu); */ int set_pcpu(char *vm_name, unsigned int vcpu, unsigned int pcpu); +/** + * Allow or disallow queries for specified VM. + * It is thread-safe. + * + * @param name + * Virtual Machine name to lookup. + * + * @param allow_query + * Query status to be set. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int set_query_status(char *vm_name, bool allow_query); + /** * Add a VM as specified by name to the Channel Manager. The name must * correspond to a valid libvirt domain name. diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index 69934d4e6..71fd8952b 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -672,6 +672,9 @@ send_freq(struct channel_packet *pkt, if (!freq_list && vcore_id >= MAX_VCPU_PER_VM) return -1; + if (!info.allow_query) + return -1; + channel_pkt_freq_list.command = CPU_POWER_FREQ_LIST; channel_pkt_freq_list.num_vcpu = info.num_vcpus; diff --git a/examples/vm_power_manager/vm_power_cli.c b/examples/vm_power_manager/vm_power_cli.c index 41e89ff20..463ea02f8 100644 --- a/examples/vm_power_manager/vm_power_cli.c +++ b/examples/vm_power_manager/vm_power_cli.c @@ -293,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; @@ -484,6 +531,7 @@ cmdline_parse_ctx_t main_ctx[] = { (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_set, + (cmdline_parse_inst_t *)&cmd_set_query_set, NULL, }; -- 2.17.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id BAA05A0679 for ; Wed, 3 Apr 2019 19:17:49 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0351F1B559; Wed, 3 Apr 2019 19:16:46 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 790FB1B513 for ; Wed, 3 Apr 2019 19:16:23 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 10:16:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,305,1549958400"; d="scan'208";a="161086738" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.180]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 10:16:22 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Wed, 3 Apr 2019 19:15:59 +0200 Message-Id: <20190403171601.9788-4-marcinx.hajkowski@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190403171601.9788-1-marcinx.hajkowski@intel.com> References: <20190403171601.9788-1-marcinx.hajkowski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190403171559.4akp6IL-fAO0EhEZMGXXrcEbwFkFS4rDUbE8OFoBuk0@z> From: Marcin Hajkowski Add new command which gives possibility to enable/disable queries form VM guest. Signed-off-by: Marcin Hajkowski --- examples/vm_power_manager/channel_manager.c | 20 +++++++++ examples/vm_power_manager/channel_manager.h | 18 ++++++++ examples/vm_power_manager/channel_monitor.c | 3 ++ examples/vm_power_manager/vm_power_cli.c | 48 +++++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 09bfa5c0d..7c852360a 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -57,6 +57,7 @@ struct virtual_machine_info { virDomainPtr domainPtr; virDomainInfo info; rte_spinlock_t config_spinlock; + int allow_query; LIST_ENTRY(virtual_machine_info) vms_info; }; @@ -344,6 +345,23 @@ setup_channel_info(struct virtual_machine_info **vm_info_dptr, return 0; } +int +set_query_status(char *vm_name, + bool allow_query) +{ + struct virtual_machine_info *vm_info; + + vm_info = find_domain_by_name(vm_name); + if (vm_info == NULL) { + RTE_LOG(ERR, CHANNEL_MANAGER, "VM '%s' not found\n", vm_name); + return -1; + } + rte_spinlock_lock(&(vm_info->config_spinlock)); + vm_info->allow_query = allow_query ? 1 : 0; + rte_spinlock_unlock(&(vm_info->config_spinlock)); + return 0; +} + static void fifo_path(char *dst, unsigned int len) { @@ -752,6 +770,7 @@ get_info_vm(const char *vm_name, struct vm_info *info) channel_num++; } + info->allow_query = vm_info->allow_query; info->num_channels = channel_num; info->num_vcpus = vm_info->info.nrVirtCpu; rte_spinlock_unlock(&(vm_info->config_spinlock)); @@ -828,6 +847,7 @@ add_vm(const char *vm_name) else new_domain->status = CHANNEL_MGR_VM_ACTIVE; + new_domain->allow_query = 0; rte_spinlock_init(&(new_domain->config_spinlock)); LIST_INSERT_HEAD(&vm_list_head, new_domain, vms_info); return 0; diff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h index c3cdce492..6b032a79f 100644 --- a/examples/vm_power_manager/channel_manager.h +++ b/examples/vm_power_manager/channel_manager.h @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include /* Maximum number of CPUs */ #define CHANNEL_CMDS_MAX_CPUS 256 @@ -82,6 +83,7 @@ struct vm_info { unsigned num_vcpus; /**< number of vCPUS */ struct channel_info channels[CHANNEL_MGR_MAX_CHANNELS]; /**< Array of channel_info */ unsigned num_channels; /**< Number of channels */ + int allow_query; /**< is query allowed */ }; /** @@ -146,6 +148,22 @@ uint16_t get_pcpu(struct channel_info *chan_info, unsigned int vcpu); */ int set_pcpu(char *vm_name, unsigned int vcpu, unsigned int pcpu); +/** + * Allow or disallow queries for specified VM. + * It is thread-safe. + * + * @param name + * Virtual Machine name to lookup. + * + * @param allow_query + * Query status to be set. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int set_query_status(char *vm_name, bool allow_query); + /** * Add a VM as specified by name to the Channel Manager. The name must * correspond to a valid libvirt domain name. diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index 69934d4e6..71fd8952b 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -672,6 +672,9 @@ send_freq(struct channel_packet *pkt, if (!freq_list && vcore_id >= MAX_VCPU_PER_VM) return -1; + if (!info.allow_query) + return -1; + channel_pkt_freq_list.command = CPU_POWER_FREQ_LIST; channel_pkt_freq_list.num_vcpu = info.num_vcpus; diff --git a/examples/vm_power_manager/vm_power_cli.c b/examples/vm_power_manager/vm_power_cli.c index 41e89ff20..463ea02f8 100644 --- a/examples/vm_power_manager/vm_power_cli.c +++ b/examples/vm_power_manager/vm_power_cli.c @@ -293,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; @@ -484,6 +531,7 @@ cmdline_parse_ctx_t main_ctx[] = { (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_set, + (cmdline_parse_inst_t *)&cmd_set_query_set, NULL, }; -- 2.17.2