DPDK patches and discussions
 help / color / mirror / Atom feed
From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
To: david.hunt@intel.com
Cc: dev@dpdk.org, Marcin Hajkowski <marcinx.hajkowski@intel.com>
Subject: [dpdk-dev] [PATCH v6 3/4] power: process incoming confirmation cmds
Date: Fri, 27 Sep 2019 09:42:15 +0100	[thread overview]
Message-ID: <20190927084216.29094-4-marcinx.hajkowski@intel.com> (raw)
In-Reply-To: <20190927084216.29094-1-marcinx.hajkowski@intel.com>

Extend vm_power_guest to check incoming confirmations
of messages previously sent to host.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
Tested-by: David Hunt <david.hunt@intel.com>
Acked-by: Lee Daly <lee.daly@intel.com>
---
 examples/vm_power_manager/guest_cli/Makefile  |  1 +
 .../guest_cli/vm_power_cli_guest.c            | 73 +++++++++++++++----
 2 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/examples/vm_power_manager/guest_cli/Makefile b/examples/vm_power_manager/guest_cli/Makefile
index e35a68d0f..67cf08193 100644
--- a/examples/vm_power_manager/guest_cli/Makefile
+++ b/examples/vm_power_manager/guest_cli/Makefile
@@ -18,6 +18,7 @@ SRCS-y := main.c vm_power_cli_guest.c parse.c
 
 CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power/
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
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 78c3aa0a1..cdb241801 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
@@ -27,7 +27,7 @@
 #define CHANNEL_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
 
 
-#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+#define RTE_LOGTYPE_GUEST_CLI RTE_LOGTYPE_USER1
 
 struct cmd_quit_result {
 	cmdline_fixed_string_t quit;
@@ -132,6 +132,32 @@ struct cmd_set_cpu_freq_result {
 	cmdline_fixed_string_t cmd;
 };
 
+static int
+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);
+	if (ret < 0)
+		return -1;
+
+	switch (pkt.command) {
+	case(CPU_POWER_CMD_ACK):
+		*result = 1;
+		break;
+	case(CPU_POWER_CMD_NACK):
+		*result = 0;
+		break;
+	default:
+		RTE_LOG(ERR, GUEST_CLI,
+				"Received invalid response from host, expecting ACK/NACK.\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static void
 cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl,
 		       __attribute__((unused)) void *data)
@@ -139,20 +165,31 @@ cmd_set_cpu_freq_parsed(void *parsed_result, struct cmdline *cl,
 	int ret = -1;
 	struct cmd_set_cpu_freq_result *res = parsed_result;
 
-	if (!strcmp(res->cmd , "up"))
+	if (!strcmp(res->cmd, "up"))
 		ret = rte_power_freq_up(res->lcore_id);
-	else if (!strcmp(res->cmd , "down"))
+	else if (!strcmp(res->cmd, "down"))
 		ret = rte_power_freq_down(res->lcore_id);
-	else if (!strcmp(res->cmd , "min"))
+	else if (!strcmp(res->cmd, "min"))
 		ret = rte_power_freq_min(res->lcore_id);
-	else if (!strcmp(res->cmd , "max"))
+	else if (!strcmp(res->cmd, "max"))
 		ret = rte_power_freq_max(res->lcore_id);
 	else if (!strcmp(res->cmd, "enable_turbo"))
 		ret = rte_power_freq_enable_turbo(res->lcore_id);
 	else if (!strcmp(res->cmd, "disable_turbo"))
 		ret = rte_power_freq_disable_turbo(res->lcore_id);
-	if (ret != 1)
+
+	if (ret != 1) {
 		cmdline_printf(cl, "Error sending message: %s\n", strerror(ret));
+		return;
+	}
+	int result;
+	ret = check_response_cmd(res->lcore_id, &result);
+	if (ret < 0) {
+		RTE_LOG(ERR, GUEST_CLI, "No confirmation for sent message received\n");
+	} else {
+		cmdline_printf(cl, "%s received for message sent to host.\n",
+				result == 1 ? "ACK" : "NACK");
+	}
 }
 
 cmdline_parse_token_string_t cmd_set_cpu_freq =
@@ -185,16 +222,26 @@ struct cmd_send_policy_result {
 };
 
 static inline int
-send_policy(struct channel_packet *pkt)
+send_policy(struct channel_packet *pkt, struct cmdline *cl)
 {
 	int ret;
 
 	ret = rte_power_guest_channel_send_msg(pkt, 1);
-	if (ret == 0)
-		return 1;
-	RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
-			ret > 0 ? strerror(ret) : "channel not connected");
-	return -1;
+	if (ret < 0) {
+		RTE_LOG(ERR, GUEST_CLI, "Error sending message: %s\n",
+				ret > 0 ? strerror(ret) : "channel not connected");
+		return -1;
+	}
+
+	int result;
+	ret = check_response_cmd(1, &result);
+	if (ret < 0) {
+		RTE_LOG(ERR, GUEST_CLI, "No confirmation for sent policy received\n");
+	} else {
+		cmdline_printf(cl, "%s for sent policy received.\n",
+				result == 1 ? "ACK" : "NACK");
+	}
+	return 1;
 }
 
 static void
@@ -206,7 +253,7 @@ cmd_send_policy_parsed(void *parsed_result, struct cmdline *cl,
 
 	if (!strcmp(res->cmd, "now")) {
 		printf("Sending Policy down now!\n");
-		ret = send_policy(&policy);
+		ret = send_policy(&policy, cl);
 	}
 	if (ret != 1)
 		cmdline_printf(cl, "Error sending message: %s\n",
-- 
2.17.1


  parent reply	other threads:[~2019-09-27  8:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 13:24 [dpdk-dev] [PATCH v5 0/4] bidirect guest channel Hajkowski
2019-04-05 13:24 ` Hajkowski
2019-04-05 13:24 ` [dpdk-dev] [PATCH v5 1/4] power: fix invalid socket indicator value Hajkowski
2019-04-05 13:24   ` Hajkowski
2019-09-27  8:42   ` [dpdk-dev] [PATCH v6 0/4] bidirectional guest channel Marcin Hajkowski
2019-09-27  8:42     ` [dpdk-dev] [PATCH v6 1/4] power: fix invalid socket indicator value Marcin Hajkowski
2019-09-27  8:42     ` [dpdk-dev] [PATCH v6 2/4] power: extend guest channel API for reading Marcin Hajkowski
2019-09-27  8:42     ` Marcin Hajkowski [this message]
2019-09-27  8:42     ` [dpdk-dev] [PATCH v6 4/4] power: send confirmation cmd to vm guest Marcin Hajkowski
2019-10-27 18:29     ` [dpdk-dev] [PATCH v6 0/4] bidirectional guest channel Thomas Monjalon
2019-04-05 13:24 ` [dpdk-dev] [PATCH v5 2/4] power: extend guest channel API for reading Hajkowski
2019-04-05 13:24   ` Hajkowski
2019-09-26 13:00   ` Hunt, David
2019-09-26 15:53     ` Daly, Lee
2019-04-05 13:24 ` [dpdk-dev] [PATCH v5 3/4] power: process incoming confirmation cmds Hajkowski
2019-04-05 13:24   ` Hajkowski
2019-09-26 13:01   ` Hunt, David
2019-09-26 15:49     ` Daly, Lee
2019-04-05 13:24 ` [dpdk-dev] [PATCH v5 4/4] power: send confirmation cmd to vm guest Hajkowski
2019-04-05 13:24   ` Hajkowski
2019-09-26 13:06   ` Hunt, David
2019-09-26 15:47     ` Daly, Lee
2019-04-22 20:36 ` [dpdk-dev] [PATCH v5 0/4] bidirect guest channel Thomas Monjalon
2019-04-22 20:36   ` Thomas Monjalon
2019-04-24  8:38   ` Hunt, David
2019-04-24  8:38     ` Hunt, David
2019-04-24  8:44     ` Thomas Monjalon
2019-04-24  8:44       ` Thomas Monjalon
2019-07-04 19:55       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190927084216.29094-4-marcinx.hajkowski@intel.com \
    --to=marcinx.hajkowski@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).