From patchwork Wed Apr 3 17:15:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Hajkowski X-Patchwork-Id: 52215 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 13A261B53A; Wed, 3 Apr 2019 19:16:37 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id DB66D1B4EB for ; Wed, 3 Apr 2019 19:16:20 +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:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,305,1549958400"; d="scan'208";a="161086719" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.180]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 10:16:19 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Wed, 3 Apr 2019 19:15:57 +0200 Message-Id: <20190403171601.9788-2-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 Subject: [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq. 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" From: Marcin Hajkowski Extend incoming packet reading API with new packet type which carries CPU frequencies. Signed-off-by: Marcin Hajkowski --- lib/librte_power/channel_commands.h | 21 +++++++++++++++++++++ lib/librte_power/guest_channel.c | 27 ++++++++++++++++----------- lib/librte_power/guest_channel.h | 21 ++++++++++++++++----- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/lib/librte_power/channel_commands.h b/lib/librte_power/channel_commands.h index 33fd53a6d..ce587283c 100644 --- a/lib/librte_power/channel_commands.h +++ b/lib/librte_power/channel_commands.h @@ -15,6 +15,8 @@ extern "C" { /* Maximum number of channels per VM */ #define CHANNEL_CMDS_MAX_VM_CHANNELS 64 +/* --- Incoming messages --- */ + /* Valid Commands */ #define CPU_POWER 1 #define CPU_POWER_CONNECT 2 @@ -29,10 +31,19 @@ extern "C" { #define CPU_POWER_ENABLE_TURBO 5 #define CPU_POWER_DISABLE_TURBO 6 +/* CPU Power Queries */ +#define CPU_POWER_QUERY_FREQ_LIST 7 +#define CPU_POWER_QUERY_FREQ 8 + +/* --- Outgoing messages --- */ + /* Generic Power Command Response */ #define CPU_POWER_CMD_ACK 1 #define CPU_POWER_CMD_NACK 2 +/* CPU Power Query Responses */ +#define CPU_POWER_FREQ_LIST 3 + #define HOURS 24 #define MAX_VFS 10 @@ -85,6 +96,16 @@ struct channel_packet { struct t_boost_status t_boost_status; }; +struct channel_packet_freq_list { + uint64_t resource_id; /**< core_num, device */ + uint32_t unit; /**< scale down/up/min/max */ + uint32_t command; /**< Power, IO, etc */ + char vm_name[VM_MAX_NAME_SZ]; + + uint32_t freq_list[MAX_VCPU_PER_VM]; + uint8_t num_vcpu; +}; + #ifdef __cplusplus } diff --git a/lib/librte_power/guest_channel.c b/lib/librte_power/guest_channel.c index 888423891..439cd2f38 100644 --- a/lib/librte_power/guest_channel.c +++ b/lib/librte_power/guest_channel.c @@ -129,13 +129,15 @@ int rte_power_guest_channel_send_msg(struct channel_packet *pkt, return guest_channel_send_msg(pkt, lcore_id); } -int power_guest_channel_read_msg(struct channel_packet *pkt, - unsigned int lcore_id) +int power_guest_channel_read_msg(void *pkt, + size_t pkt_len, + unsigned int lcore_id) { int ret; struct pollfd fds; - void *buffer = pkt; - int buffer_len = sizeof(*pkt); + + if (pkt_len == 0 || pkt == NULL) + return -1; fds.fd = global_fds[lcore_id]; fds.events = POLLIN; @@ -161,29 +163,32 @@ int power_guest_channel_read_msg(struct channel_packet *pkt, return -1; } - while (buffer_len > 0) { + while (pkt_len > 0) { ret = read(global_fds[lcore_id], - buffer, buffer_len); + pkt, pkt_len); + if (ret < 0) { if (errno == EINTR) continue; return -1; } + if (ret == 0) { RTE_LOG(ERR, GUEST_CHANNEL, "Expected more data, but connection has been closed.\n"); return -1; } - buffer = (char *)buffer + ret; - buffer_len -= ret; + pkt = (char *)pkt + ret; + pkt_len -= ret; } return 0; } -int rte_power_guest_channel_receive_msg(struct channel_packet *pkt, - unsigned int lcore_id) +int rte_power_guest_channel_receive_msg(void *pkt, + size_t pkt_len, + unsigned int lcore_id) { - return power_guest_channel_read_msg(pkt, lcore_id); + return power_guest_channel_read_msg(pkt, pkt_len, lcore_id); } void diff --git a/lib/librte_power/guest_channel.h b/lib/librte_power/guest_channel.h index 7c385df39..473901547 100644 --- a/lib/librte_power/guest_channel.h +++ b/lib/librte_power/guest_channel.h @@ -17,6 +17,7 @@ extern "C" { * * @param path * The path to the serial device on the filesystem + * * @param lcore_id * lcore_id. * @@ -73,7 +74,11 @@ int rte_power_guest_channel_send_msg(struct channel_packet *pkt, * from the host endpoint. * * @param pkt - * Pointer to a populated struct channel_packet + * Pointer to channel_packet or + * channel_packet_freq_list struct. + * + * @param pkt_len + * Size of expected data packet. * * @param lcore_id * lcore_id. @@ -82,7 +87,8 @@ int rte_power_guest_channel_send_msg(struct channel_packet *pkt, * - 0 on success. * - Negative on error. */ -int power_guest_channel_read_msg(struct channel_packet *pkt, +int power_guest_channel_read_msg(void *pkt, + size_t pkt_len, unsigned int lcore_id); /** @@ -90,7 +96,11 @@ int power_guest_channel_read_msg(struct channel_packet *pkt, * from the host endpoint. * * @param pkt - * Pointer to a populated struct channel_packet + * Pointer to channel_packet or + * channel_packet_freq_list struct. + * + * @param pkt_len + * Size of expected data packet. * * @param lcore_id * lcore_id. @@ -100,8 +110,9 @@ int power_guest_channel_read_msg(struct channel_packet *pkt, * - Negative on error. */ int __rte_experimental -rte_power_guest_channel_receive_msg(struct channel_packet *pkt, - unsigned int lcore_id); +rte_power_guest_channel_receive_msg(void *pkt, + size_t pkt_len, + unsigned int lcore_id); #ifdef __cplusplus } From patchwork Wed Apr 3 17:15:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Hajkowski X-Patchwork-Id: 52217 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CB9221B54D; Wed, 3 Apr 2019 19:16:41 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 2D5C61B4ED for ; Wed, 3 Apr 2019 19:16:22 +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:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,305,1549958400"; d="scan'208";a="161086727" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.180]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 10:16:20 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Wed, 3 Apr 2019 19:15:58 +0200 Message-Id: <20190403171601.9788-3-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 Subject: [dpdk-dev] [PATCH 2/4] power: process cpu freq. query 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" From: Marcin Hajkowski On query received from VM guest send CPUs frequencies. Signed-off-by: Marcin Hajkowski --- examples/vm_power_manager/channel_monitor.c | 67 ++++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index ed580b36a..69934d4e6 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -628,10 +628,14 @@ apply_policy(struct policy *pol) } static int -write_binary_packet(struct channel_packet *pkt, struct channel_info *chan_info) +write_binary_packet(void *buffer, + size_t buffer_len, + struct channel_info *chan_info) { - int ret, buffer_len = sizeof(*pkt); - void *buffer = pkt; + int ret; + + if (buffer_len == 0 || buffer == NULL) + return -1; if (chan_info->fd < 0) { RTE_LOG(ERR, CHANNEL_MONITOR, "Channel is not connected\n"); @@ -653,13 +657,48 @@ write_binary_packet(struct channel_packet *pkt, struct channel_info *chan_info) return 0; } +static int +send_freq(struct channel_packet *pkt, + struct channel_info *chan_info, + bool freq_list) +{ + unsigned int vcore_id = pkt->resource_id; + struct channel_packet_freq_list channel_pkt_freq_list; + struct vm_info info; + + if (get_info_vm(pkt->vm_name, &info) != 0) + return -1; + + if (!freq_list && vcore_id >= MAX_VCPU_PER_VM) + return -1; + + channel_pkt_freq_list.command = CPU_POWER_FREQ_LIST; + channel_pkt_freq_list.num_vcpu = info.num_vcpus; + + if (freq_list) { + unsigned int i; + for (i = 0; i < info.num_vcpus; i++) + channel_pkt_freq_list.freq_list[i] = + power_manager_get_current_frequency(info.pcpu_map[i]); + } else { + channel_pkt_freq_list.freq_list[vcore_id] = + power_manager_get_current_frequency(info.pcpu_map[vcore_id]); + } + + return write_binary_packet(&channel_pkt_freq_list, + sizeof(channel_pkt_freq_list), + chan_info); +} + static int send_ack_for_received_cmd(struct channel_packet *pkt, struct channel_info *chan_info, uint32_t command) { pkt->command = command; - return write_binary_packet(pkt, chan_info); + return write_binary_packet(pkt, + sizeof(struct channel_packet), + chan_info); } static int @@ -685,8 +724,8 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) RTE_LOG(DEBUG, CHANNEL_MONITOR, "Processing requested cmd for cpu:%d\n", core_num); - bool valid_unit = true; int scale_res; + bool valid_unit = true; switch (pkt->unit) { case(CPU_POWER_SCALE_MIN): @@ -719,9 +758,9 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) CPU_POWER_CMD_ACK : CPU_POWER_CMD_NACK); if (ret < 0) - RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); + RTE_LOG(ERR, CHANNEL_MONITOR, "Error during sending ack command.\n"); } else - RTE_LOG(DEBUG, CHANNEL_MONITOR, "Unexpected unit type.\n"); + RTE_LOG(ERR, CHANNEL_MONITOR, "Unexpected unit type.\n"); } @@ -732,7 +771,7 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) chan_info, CPU_POWER_CMD_ACK); if (ret < 0) - RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); + RTE_LOG(ERR, CHANNEL_MONITOR, "Error during sending ack command.\n"); update_policy(pkt); policy_is_set = 1; } @@ -747,6 +786,18 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info) "Policy %s does not exist\n", pkt->vm_name); } + if (pkt->command == CPU_POWER_QUERY_FREQ_LIST || + pkt->command == CPU_POWER_QUERY_FREQ) { + + RTE_LOG(INFO, CHANNEL_MONITOR, + "Frequency for %s requested.\n", pkt->vm_name); + int ret = send_freq(pkt, + chan_info, + pkt->command == CPU_POWER_QUERY_FREQ_LIST); + if (ret < 0) + RTE_LOG(ERR, CHANNEL_MONITOR, "Error during frequency sending.\n"); + } + /* * Return is not checked as channel status may have been set to DISABLED * from management thread From patchwork Wed Apr 3 17:15:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Hajkowski X-Patchwork-Id: 52219 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org 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 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" 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, }; From patchwork Wed Apr 3 17:16:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Hajkowski X-Patchwork-Id: 52220 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BE21D1B567; Wed, 3 Apr 2019 19:16:48 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id B0FF31B513 for ; Wed, 3 Apr 2019 19:16:24 +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:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,305,1549958400"; d="scan'208";a="161086745" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.180]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 10:16:23 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Wed, 3 Apr 2019 19:16:00 +0200 Message-Id: <20190403171601.9788-5-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 Subject: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq. 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" From: Marcin Hajkowski Add command and related logic to query CPU frequencies either for specified CPU or all cores. Signed-off-by: Marcin Hajkowski Acked-by: Lee Daly --- .../guest_cli/vm_power_cli_guest.c | 150 ++++++++++++++++-- 1 file changed, 138 insertions(+), 12 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 af49dfef8..d1b4ac2aa 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 @@ -99,9 +99,9 @@ set_policy_defaults(struct channel_packet *pkt) strcpy(pkt->vm_name, "ubuntu2"); } -static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - __attribute__((unused)) void *data) +static void cmd_quit_parsed(__rte_unused void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) { unsigned lcore_id; @@ -126,10 +126,126 @@ cmdline_parse_inst_t cmd_quit = { /* *** VM operations *** */ -struct cmd_set_cpu_freq_result { - cmdline_fixed_string_t set_cpu_freq; - uint8_t lcore_id; - cmdline_fixed_string_t cmd; +struct cmd_freq_list_result { + cmdline_fixed_string_t query_freq; + cmdline_fixed_string_t cpu_num; +}; + +static int +query_freq_list(struct channel_packet *pkt, unsigned int lcore_id) +{ + int ret; + ret = rte_power_guest_channel_send_msg(pkt, lcore_id); + if (ret < 0) { + RTE_LOG(ERR, GUEST_CLI, "Error sending message.\n"); + return -1; + } + return 0; +} + +static int +receive_freq_list(struct channel_packet_freq_list *pkt_freq_list, + unsigned int lcore_id) +{ + int ret; + + ret = rte_power_guest_channel_receive_msg(pkt_freq_list, + sizeof(struct channel_packet_freq_list), + lcore_id); + if (ret < 0) { + RTE_LOG(ERR, GUEST_CLI, "Error receiving message.\n"); + return -1; + } + if (pkt_freq_list->command != CPU_POWER_FREQ_LIST) { + RTE_LOG(ERR, GUEST_CLI, "Unexpected message received.\n"); + return -1; + } + return 0; +} + +static void +cmd_query_freq_list_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_freq_list_result *res = parsed_result; + unsigned int lcore_id; + struct channel_packet_freq_list pkt_freq_list; + struct channel_packet pkt; + bool query_list = false; + int ret; + char *ep; + + memset(&pkt, 0, sizeof(struct channel_packet)); + memset(&pkt_freq_list, 0, sizeof(struct channel_packet_freq_list)); + + if (!strcmp(res->cpu_num, "all")) { + + /* Get first enabled lcore. */ + lcore_id = rte_get_next_lcore(-1, + 0, + 0); + if (lcore_id == RTE_MAX_LCORE) { + cmdline_printf(cl, "Enabled core not found.\n"); + return; + } + + pkt.command = CPU_POWER_QUERY_FREQ_LIST; + strcpy(pkt.vm_name, policy.vm_name); + query_list = true; + } else { + errno = 0; + lcore_id = (unsigned int)strtol(res->cpu_num, &ep, 10); + if (errno != 0 || lcore_id >= MAX_VCPU_PER_VM || + ep == res->cpu_num) { + cmdline_printf(cl, "Invalid parameter provided.\n"); + return; + } + pkt.command = CPU_POWER_QUERY_FREQ; + strcpy(pkt.vm_name, policy.vm_name); + pkt.resource_id = lcore_id; + } + + ret = query_freq_list(&pkt, lcore_id); + if (ret < 0) { + cmdline_printf(cl, "Error during sending frequency list query.\n"); + return; + } + + ret = receive_freq_list(&pkt_freq_list, lcore_id); + if (ret < 0) { + cmdline_printf(cl, "Error during frequency list reception.\n"); + return; + } + if (query_list) { + unsigned int i; + for (i = 0; i < pkt_freq_list.num_vcpu; ++i) + cmdline_printf(cl, "Frequency of [%d] vcore is %d.\n", + i, + pkt_freq_list.freq_list[i]); + } else { + cmdline_printf(cl, "Frequency of [%d] vcore is %d.\n", + lcore_id, + pkt_freq_list.freq_list[lcore_id]); + } +} + +cmdline_parse_token_string_t cmd_query_freq_token = + TOKEN_STRING_INITIALIZER(struct cmd_freq_list_result, query_freq, "query_cpu_freq"); +cmdline_parse_token_string_t cmd_query_freq_cpu_num_token = + TOKEN_STRING_INITIALIZER(struct cmd_freq_list_result, cpu_num, NULL); + +cmdline_parse_inst_t cmd_query_freq_list = { + .f = cmd_query_freq_list_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = "query_cpu_freq |all, request" + " information regarding virtual core frequencies." + " The keyword 'all' will query list of all vcores for the VM", + .tokens = { /* token list, NULL terminated */ + (void *)&cmd_query_freq_token, + (void *)&cmd_query_freq_cpu_num_token, + NULL, + }, }; static int @@ -138,7 +254,10 @@ check_response_cmd(unsigned int lcore_id, int *result) struct channel_packet pkt; int ret; - ret = rte_power_guest_channel_receive_msg(&pkt, lcore_id); + ret = rte_power_guest_channel_receive_msg(&pkt, + sizeof(pkt), + lcore_id); + if (ret < 0) return -1; @@ -150,16 +269,22 @@ check_response_cmd(unsigned int lcore_id, int *result) *result = 0; break; default: - RTE_LOG(DEBUG, GUEST_CLI, "Not expected command has been received.\n"); + RTE_LOG(ERR, GUEST_CLI, "Not expected command has been received.\n"); return -1; } return 0; } +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) + __rte_unused void *data) { int ret = -1; struct cmd_set_cpu_freq_result *res = parsed_result; @@ -245,7 +370,7 @@ send_policy(struct channel_packet *pkt, struct cmdline *cl) static void cmd_send_policy_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { int ret = -1; struct cmd_send_policy_result *res = parsed_result; @@ -281,11 +406,12 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_quit, (cmdline_parse_inst_t *)&cmd_send_policy_set, (cmdline_parse_inst_t *)&cmd_set_cpu_freq_set, + (cmdline_parse_inst_t *)&cmd_query_freq_list, NULL, }; void -run_cli(__attribute__((unused)) void *arg) +run_cli(__rte_unused void *arg) { struct cmdline *cl;