From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id C23E61B4E3 for ; Fri, 5 Apr 2019 15:28:18 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2019 06:28:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,312,1549958400"; d="scan'208";a="158546494" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.181]) by fmsmga002.fm.intel.com with ESMTP; 05 Apr 2019 06:28:17 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Fri, 5 Apr 2019 15:24:55 +0200 Message-Id: <20190405132455.15468-5-marcinx.hajkowski@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190405132455.15468-1-marcinx.hajkowski@intel.com> References: <20190405132455.15468-1-marcinx.hajkowski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 4/4] power: send confirmation cmd to vm guest X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: 20190402082121.5472-1-marcinx.hajkowski@intel.com List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Apr 2019 13:28:19 -0000 From: Marcin Hajkowski Use new guest channel API to send confirmation message for received power command. Signed-off-by: Marcin Hajkowski --- examples/vm_power_manager/channel_monitor.c | 68 +++++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index 7892d75de..ed580b36a 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -627,6 +627,41 @@ apply_policy(struct policy *pol) apply_workload_profile(pol); } +static int +write_binary_packet(struct channel_packet *pkt, struct channel_info *chan_info) +{ + int ret, buffer_len = sizeof(*pkt); + void *buffer = pkt; + + if (chan_info->fd < 0) { + RTE_LOG(ERR, CHANNEL_MONITOR, "Channel is not connected\n"); + return -1; + } + + while (buffer_len > 0) { + ret = write(chan_info->fd, buffer, buffer_len); + if (ret == -1) { + if (errno == EINTR) + continue; + RTE_LOG(ERR, CHANNEL_MONITOR, "Write function failed due to %s.\n", + strerror(errno)); + return -1; + } + buffer = (char *)buffer + ret; + buffer_len -= ret; + } + return 0; +} + +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); +} + static int process_request(struct channel_packet *pkt, struct channel_info *chan_info) { @@ -650,33 +685,54 @@ 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; + switch (pkt->unit) { case(CPU_POWER_SCALE_MIN): - power_manager_scale_core_min(core_num); + scale_res = power_manager_scale_core_min(core_num); break; case(CPU_POWER_SCALE_MAX): - power_manager_scale_core_max(core_num); + scale_res = power_manager_scale_core_max(core_num); break; case(CPU_POWER_SCALE_DOWN): - power_manager_scale_core_down(core_num); + scale_res = power_manager_scale_core_down(core_num); break; case(CPU_POWER_SCALE_UP): - power_manager_scale_core_up(core_num); + scale_res = power_manager_scale_core_up(core_num); break; case(CPU_POWER_ENABLE_TURBO): - power_manager_enable_turbo_core(core_num); + scale_res = power_manager_enable_turbo_core(core_num); break; case(CPU_POWER_DISABLE_TURBO): - power_manager_disable_turbo_core(core_num); + scale_res = power_manager_disable_turbo_core(core_num); break; default: + valid_unit = false; break; } + + if (valid_unit) { + ret = send_ack_for_received_cmd(pkt, + chan_info, + scale_res > 0 ? + CPU_POWER_CMD_ACK : + CPU_POWER_CMD_NACK); + if (ret < 0) + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); + } else + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Unexpected unit type.\n"); + } if (pkt->command == PKT_POLICY) { RTE_LOG(INFO, CHANNEL_MONITOR, "Processing policy request %s\n", pkt->vm_name); + int ret = send_ack_for_received_cmd(pkt, + chan_info, + CPU_POWER_CMD_ACK); + if (ret < 0) + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); update_policy(pkt); policy_is_set = 1; } -- 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 899CAA0679 for ; Fri, 5 Apr 2019 15:28:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1E0EC1B505; Fri, 5 Apr 2019 15:28:30 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id C23E61B4E3 for ; Fri, 5 Apr 2019 15:28:18 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2019 06:28:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,312,1549958400"; d="scan'208";a="158546494" Received: from mhajkowx-mobl.ger.corp.intel.com ([10.104.116.181]) by fmsmga002.fm.intel.com with ESMTP; 05 Apr 2019 06:28:17 -0700 From: Hajkowski To: david.hunt@intel.com Cc: dev@dpdk.org, Marcin Hajkowski Date: Fri, 5 Apr 2019 15:24:55 +0200 Message-Id: <20190405132455.15468-5-marcinx.hajkowski@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190405132455.15468-1-marcinx.hajkowski@intel.com> References: <20190405132455.15468-1-marcinx.hajkowski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 4/4] power: send confirmation cmd to vm guest X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: 20190402082121.5472-1-marcinx.hajkowski@intel.com 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: <20190405132455.CJ6mnj9G8jDL61dnx6RJCALrFM7taIGAOveRmPl7vXI@z> From: Marcin Hajkowski Use new guest channel API to send confirmation message for received power command. Signed-off-by: Marcin Hajkowski --- examples/vm_power_manager/channel_monitor.c | 68 +++++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c index 7892d75de..ed580b36a 100644 --- a/examples/vm_power_manager/channel_monitor.c +++ b/examples/vm_power_manager/channel_monitor.c @@ -627,6 +627,41 @@ apply_policy(struct policy *pol) apply_workload_profile(pol); } +static int +write_binary_packet(struct channel_packet *pkt, struct channel_info *chan_info) +{ + int ret, buffer_len = sizeof(*pkt); + void *buffer = pkt; + + if (chan_info->fd < 0) { + RTE_LOG(ERR, CHANNEL_MONITOR, "Channel is not connected\n"); + return -1; + } + + while (buffer_len > 0) { + ret = write(chan_info->fd, buffer, buffer_len); + if (ret == -1) { + if (errno == EINTR) + continue; + RTE_LOG(ERR, CHANNEL_MONITOR, "Write function failed due to %s.\n", + strerror(errno)); + return -1; + } + buffer = (char *)buffer + ret; + buffer_len -= ret; + } + return 0; +} + +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); +} + static int process_request(struct channel_packet *pkt, struct channel_info *chan_info) { @@ -650,33 +685,54 @@ 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; + switch (pkt->unit) { case(CPU_POWER_SCALE_MIN): - power_manager_scale_core_min(core_num); + scale_res = power_manager_scale_core_min(core_num); break; case(CPU_POWER_SCALE_MAX): - power_manager_scale_core_max(core_num); + scale_res = power_manager_scale_core_max(core_num); break; case(CPU_POWER_SCALE_DOWN): - power_manager_scale_core_down(core_num); + scale_res = power_manager_scale_core_down(core_num); break; case(CPU_POWER_SCALE_UP): - power_manager_scale_core_up(core_num); + scale_res = power_manager_scale_core_up(core_num); break; case(CPU_POWER_ENABLE_TURBO): - power_manager_enable_turbo_core(core_num); + scale_res = power_manager_enable_turbo_core(core_num); break; case(CPU_POWER_DISABLE_TURBO): - power_manager_disable_turbo_core(core_num); + scale_res = power_manager_disable_turbo_core(core_num); break; default: + valid_unit = false; break; } + + if (valid_unit) { + ret = send_ack_for_received_cmd(pkt, + chan_info, + scale_res > 0 ? + CPU_POWER_CMD_ACK : + CPU_POWER_CMD_NACK); + if (ret < 0) + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); + } else + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Unexpected unit type.\n"); + } if (pkt->command == PKT_POLICY) { RTE_LOG(INFO, CHANNEL_MONITOR, "Processing policy request %s\n", pkt->vm_name); + int ret = send_ack_for_received_cmd(pkt, + chan_info, + CPU_POWER_CMD_ACK); + if (ret < 0) + RTE_LOG(DEBUG, CHANNEL_MONITOR, "Error during sending ack command.\n"); update_policy(pkt); policy_is_set = 1; } -- 2.17.2