DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/4] Frequency list query
@ 2019-04-03 17:15 Hajkowski
  2019-04-03 17:15 ` Hajkowski
                   ` (5 more replies)
  0 siblings, 6 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Extend guest channel and sample apps to query CPU frequncies.

Please note that these changes depends on
(http://patchwork.dpdk.org/cover/52057/) which should be applied first.

Marcin Hajkowski (4):
  power: extend guest channel for query freq.
  power: process cpu freq. query
  power: add mechanism to disable queries
  power: add cmd to query CPU freq.

 examples/vm_power_manager/channel_manager.c   |  20 +++
 examples/vm_power_manager/channel_manager.h   |  18 +++
 examples/vm_power_manager/channel_monitor.c   |  70 +++++++-
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 examples/vm_power_manager/vm_power_cli.c      |  48 ++++++
 lib/librte_power/channel_commands.h           |  21 +++
 lib/librte_power/guest_channel.c              |  27 ++--
 lib/librte_power/guest_channel.h              |  21 ++-
 8 files changed, 339 insertions(+), 36 deletions(-)

-- 
2.17.2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 0/4] Frequency list query
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
@ 2019-04-03 17:15 ` Hajkowski
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq Hajkowski
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Extend guest channel and sample apps to query CPU frequncies.

Please note that these changes depends on
(http://patchwork.dpdk.org/cover/52057/) which should be applied first.

Marcin Hajkowski (4):
  power: extend guest channel for query freq.
  power: process cpu freq. query
  power: add mechanism to disable queries
  power: add cmd to query CPU freq.

 examples/vm_power_manager/channel_manager.c   |  20 +++
 examples/vm_power_manager/channel_manager.h   |  18 +++
 examples/vm_power_manager/channel_monitor.c   |  70 +++++++-
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 examples/vm_power_manager/vm_power_cli.c      |  48 ++++++
 lib/librte_power/channel_commands.h           |  21 +++
 lib/librte_power/guest_channel.c              |  27 ++--
 lib/librte_power/guest_channel.h              |  21 ++-
 8 files changed, 339 insertions(+), 36 deletions(-)

-- 
2.17.2


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq.
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
  2019-04-03 17:15 ` Hajkowski
@ 2019-04-03 17:15 ` Hajkowski
  2019-04-03 17:15   ` Hajkowski
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 2/4] power: process cpu freq. query Hajkowski
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Extend incoming packet reading API with new packet
type which carries CPU frequencies.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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
 }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq.
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq Hajkowski
@ 2019-04-03 17:15   ` Hajkowski
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
  1 sibling, 0 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Extend incoming packet reading API with new packet
type which carries CPU frequencies.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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
 }
-- 
2.17.2


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 2/4] power: process cpu freq. query
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
  2019-04-03 17:15 ` Hajkowski
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq Hajkowski
@ 2019-04-03 17:15 ` Hajkowski
  2019-04-03 17:15   ` Hajkowski
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries Hajkowski
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

On query received from VM guest send CPUs frequencies.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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
-- 
2.17.2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 2/4] power: process cpu freq. query
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 2/4] power: process cpu freq. query Hajkowski
@ 2019-04-03 17:15   ` Hajkowski
  0 siblings, 0 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

On query received from VM guest send CPUs frequencies.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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
-- 
2.17.2


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
                   ` (2 preceding siblings ...)
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 2/4] power: process cpu freq. query Hajkowski
@ 2019-04-03 17:15 ` Hajkowski
  2019-04-03 17:15   ` Hajkowski
  2019-04-03 17:16 ` [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq Hajkowski
  2019-07-04 19:57 ` [dpdk-dev] [PATCH 0/4] Frequency list query Thomas Monjalon
  5 siblings, 1 reply; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add new command which gives possibility to enable/disable queries
form VM guest.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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 <linux/limits.h>
 #include <sys/un.h>
 #include <rte_atomic.h>
+#include <stdbool.h>
 
 /* 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 <vm_name> <enable|disable>, 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries Hajkowski
@ 2019-04-03 17:15   ` Hajkowski
  0 siblings, 0 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add new command which gives possibility to enable/disable queries
form VM guest.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 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 <linux/limits.h>
 #include <sys/un.h>
 #include <rte_atomic.h>
+#include <stdbool.h>
 
 /* 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 <vm_name> <enable|disable>, 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


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
                   ` (3 preceding siblings ...)
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries Hajkowski
@ 2019-04-03 17:16 ` Hajkowski
  2019-04-03 17:16   ` Hajkowski
  2019-09-27  9:52   ` Daly, Lee
  2019-07-04 19:57 ` [dpdk-dev] [PATCH 0/4] Frequency list query Thomas Monjalon
  5 siblings, 2 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:16 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add command and related logic to query CPU frequencies
either for specified CPU or all cores.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 .../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 <core_num>|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;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.
  2019-04-03 17:16 ` [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq Hajkowski
@ 2019-04-03 17:16   ` Hajkowski
  2019-09-27  9:52   ` Daly, Lee
  1 sibling, 0 replies; 22+ messages in thread
From: Hajkowski @ 2019-04-03 17:16 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add command and related logic to query CPU frequencies
either for specified CPU or all cores.

Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
 .../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 <core_num>|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;
 
-- 
2.17.2


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH 0/4] Frequency list query
  2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
                   ` (4 preceding siblings ...)
  2019-04-03 17:16 ` [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq Hajkowski
@ 2019-07-04 19:57 ` Thomas Monjalon
  5 siblings, 0 replies; 22+ messages in thread
From: Thomas Monjalon @ 2019-07-04 19:57 UTC (permalink / raw)
  To: Hajkowski, david.hunt; +Cc: dev

03/04/2019 19:15, Hajkowski:
> Marcin Hajkowski (4):
>   power: extend guest channel for query freq.
>   power: process cpu freq. query
>   power: add mechanism to disable queries
>   power: add cmd to query CPU freq.

This is the same status as for 19.05,
there is no review, so it cannot be merged in 19.08.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.
  2019-04-03 17:16 ` [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq Hajkowski
  2019-04-03 17:16   ` Hajkowski
@ 2019-09-27  9:52   ` Daly, Lee
  2019-09-27 10:19     ` Ferruh Yigit
  1 sibling, 1 reply; 22+ messages in thread
From: Daly, Lee @ 2019-09-27  9:52 UTC (permalink / raw)
  To: 'Hajkowski, MarcinX', Hunt, David; +Cc: dev



> -----Original Message-----
> From: Hajkowski, MarcinX
> Sent: Wednesday, April 3, 2019 6:16 PM
> To: Hunt, David <david.hunt@intel.com>
> Cc: dev@dpdk.org; Hajkowski, MarcinX <marcinx.hajkowski@intel.com>
> Subject: [PATCH 4/4] power: add cmd to query CPU freq.
> 
> From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
> 
> Add command and related logic to query CPU frequencies either for specified
> CPU or all cores.
> 
> Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
> ---
>  .../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
<...>

> +
> +		pkt.command = CPU_POWER_QUERY_FREQ_LIST;
> +		strcpy(pkt.vm_name, policy.vm_name);

Can you use the internal rte_strlcpy() functions for security.

Add my tag after small change above has been applied to all instances of strcpy() in patchset.
For all in series:
Acked-by: Lee Daly <lee.daly@intel.com>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.
  2019-09-27  9:52   ` Daly, Lee
@ 2019-09-27 10:19     ` Ferruh Yigit
  2019-09-27 10:40       ` Hunt, David
  0 siblings, 1 reply; 22+ messages in thread
From: Ferruh Yigit @ 2019-09-27 10:19 UTC (permalink / raw)
  To: Daly, Lee, 'Hajkowski, MarcinX', Hunt, David; +Cc: dev

On 9/27/2019 10:52 AM, Daly, Lee wrote:
> 
> 
>> -----Original Message-----
>> From: Hajkowski, MarcinX
>> Sent: Wednesday, April 3, 2019 6:16 PM
>> To: Hunt, David <david.hunt@intel.com>
>> Cc: dev@dpdk.org; Hajkowski, MarcinX <marcinx.hajkowski@intel.com>
>> Subject: [PATCH 4/4] power: add cmd to query CPU freq.
>>
>> From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>>
>> Add command and related logic to query CPU frequencies either for specified
>> CPU or all cores.
>>
>> Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>> ---
>>  .../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
> <...>
> 
>> +
>> +		pkt.command = CPU_POWER_QUERY_FREQ_LIST;
>> +		strcpy(pkt.vm_name, policy.vm_name);
> 
> Can you use the internal rte_strlcpy() functions for security.

+1 to *not* use 'strcpy()', but better to use 'strlcpy()' directly,
since there is already a wrapper for the environment that doesn't support
'strlcpy()' [1].

[1] lib/librte_eal/common/include/rte_string_fns.h
#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)

> 
> Add my tag after small change above has been applied to all instances of strcpy() in patchset.
> For all in series:
> Acked-by: Lee Daly <lee.daly@intel.com>
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.
  2019-09-27 10:19     ` Ferruh Yigit
@ 2019-09-27 10:40       ` Hunt, David
  0 siblings, 0 replies; 22+ messages in thread
From: Hunt, David @ 2019-09-27 10:40 UTC (permalink / raw)
  To: Ferruh Yigit, Daly, Lee, 'Hajkowski, MarcinX'; +Cc: dev


On 27/09/2019 11:19, Ferruh Yigit wrote:
> On 9/27/2019 10:52 AM, Daly, Lee wrote:
>>
>>> -----Original Message-----
>>> From: Hajkowski, MarcinX
>>> Sent: Wednesday, April 3, 2019 6:16 PM
>>> To: Hunt, David <david.hunt@intel.com>
>>> Cc: dev@dpdk.org; Hajkowski, MarcinX <marcinx.hajkowski@intel.com>
>>> Subject: [PATCH 4/4] power: add cmd to query CPU freq.
>>>
>>> From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>>>
>>> Add command and related logic to query CPU frequencies either for specified
>>> CPU or all cores.
>>>
>>> Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>>> ---
>>>   .../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
>> <...>
>>
>>> +
>>> +		pkt.command = CPU_POWER_QUERY_FREQ_LIST;
>>> +		strcpy(pkt.vm_name, policy.vm_name);
>> Can you use the internal rte_strlcpy() functions for security.
> +1 to *not* use 'strcpy()', but better to use 'strlcpy()' directly,
> since there is already a wrapper for the environment that doesn't support
> 'strlcpy()' [1].
>
> [1] lib/librte_eal/common/include/rte_string_fns.h
> #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)


Agreed, I'm currently working on a respin that uses strlcpy(). Will post 
soon.

Rgds,
Dave.




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2 0/4] frequency list query from guest
  2019-04-03 17:15 ` [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq Hajkowski
  2019-04-03 17:15   ` Hajkowski
@ 2019-09-27 12:15   ` David Hunt
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq David Hunt
                       ` (4 more replies)
  1 sibling, 5 replies; 22+ messages in thread
From: David Hunt @ 2019-09-27 12:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev

Extend guest channel and sample apps to query CPU frequencies.

Please note that these changes depends on
(http://patches.dpdk.org/project/dpdk/list/?series=6568)
which should be applied first.

This feature is disabled by default, and must be explicitly enabled
so that queries from guests are allowed:

vmpower> set_query ubuntu3 enable

Then the guest can query the set frequency for one or all cores:

vmpower(guest)> query_cpu_freq all
Frequency of [0] vcore is 2300000.
Frequency of [1] vcore is 2300000.
Frequency of [2] vcore is 2300000.
Frequency of [3] vcore is 2300000.
Frequency of [4] vcore is 2300000.
Frequency of [5] vcore is 2300000.
Frequency of [6] vcore is 2300000.
Frequency of [7] vcore is 2300000.

---

v2:
* replaced strcpy() with strlcpy()

Marcin Hajkowski (4):
1/4 power: extend guest channel for query freq
2/4 power: process cpu freq query
3/4 power: add mechanism to disable queries
4/4 power: add cmd to query CPU freq


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
@ 2019-09-27 12:15     ` David Hunt
  2019-09-30  9:54       ` Hunt, David
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 2/4] power: process cpu freq query David Hunt
                       ` (3 subsequent siblings)
  4 siblings, 1 reply; 22+ messages in thread
From: David Hunt @ 2019-09-27 12:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Extend incoming packet reading API with new packet
type which carries CPU frequencies.

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>
---
 lib/librte_power/channel_commands.h | 21 +++++++++++++++++++++
 lib/librte_power/guest_channel.c    | 27 ++++++++++++++++-----------
 lib/librte_power/guest_channel.h    | 22 +++++++++++++++++-----
 3 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/lib/librte_power/channel_commands.h b/lib/librte_power/channel_commands.h
index d81216b42..e461d9c0d 100644
--- a/lib/librte_power/channel_commands.h
+++ b/lib/librte_power/channel_commands.h
@@ -12,6 +12,8 @@ extern "C" {
 #include <stdint.h>
 #include <stdbool.h>
 
+/* --- Incoming messages --- */
+
 /* Valid Commands */
 #define CPU_POWER               1
 #define CPU_POWER_CONNECT       2
@@ -26,10 +28,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
@@ -82,6 +93,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 61e142289..025961606 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.
@@ -101,8 +111,10 @@ int power_guest_channel_read_msg(struct channel_packet *pkt,
  */
 __rte_experimental
 int
-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
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] power: process cpu freq query
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq David Hunt
@ 2019-09-27 12:15     ` David Hunt
  2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 3/4] power: add mechanism to disable queries David Hunt
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 22+ messages in thread
From: David Hunt @ 2019-09-27 12:15 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

On query received from VM guest send CPUs frequencies.

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/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 0c73fac55..fd7269889 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -672,10 +672,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");
@@ -697,13 +701,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
@@ -729,8 +768,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):
@@ -763,9 +802,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");
 
 	}
 
@@ -776,7 +815,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;
 	}
@@ -791,6 +830,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
-- 
2.17.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] power: add mechanism to disable queries
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq David Hunt
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 2/4] power: process cpu freq query David Hunt
@ 2019-09-27 12:16     ` David Hunt
  2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq David Hunt
  2019-10-27 19:59     ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest Thomas Monjalon
  4 siblings, 0 replies; 22+ messages in thread
From: David Hunt @ 2019-09-27 12:16 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add new command which gives possibility to enable/disable queries
form VM guest.

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/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 4db225755..4ac21f02c 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -58,6 +58,7 @@ struct virtual_machine_info {
 	virDomainPtr domainPtr;
 	virDomainInfo info;
 	rte_spinlock_t config_spinlock;
+	int allow_query;
 	LIST_ENTRY(virtual_machine_info) vms_info;
 };
 
@@ -791,6 +792,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));
@@ -867,6 +869,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;
@@ -896,6 +899,23 @@ remove_vm(const char *vm_name)
 	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
 disconnect_hypervisor(void)
 {
diff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h
index 3766e93c8..8284be0a1 100644
--- a/examples/vm_power_manager/channel_manager.h
+++ b/examples/vm_power_manager/channel_manager.h
@@ -12,6 +12,7 @@ extern "C" {
 #include <linux/limits.h>
 #include <sys/un.h>
 #include <rte_atomic.h>
+#include <stdbool.h>
 
 /* Maximum name length including '\0' terminator */
 #define CHANNEL_MGR_MAX_NAME_LEN    64
@@ -79,6 +80,7 @@ struct vm_info {
 	unsigned num_vcpus;                           /**< number of vCPUS */
 	struct channel_info channels[RTE_MAX_LCORE];  /**< channel_info array */
 	unsigned num_channels;                        /**< Number of channels */
+	int allow_query;                              /**< is query allowed */
 };
 
 /**
@@ -143,6 +145,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 fd7269889..0ae62835f 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -716,6 +716,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 89b000d92..5f64b83fb 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 <vm_name> <enable|disable>, 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.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
                       ` (2 preceding siblings ...)
  2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 3/4] power: add mechanism to disable queries David Hunt
@ 2019-09-27 12:16     ` David Hunt
  2019-09-27 12:38       ` Hunt, David
  2019-10-27 19:59     ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest Thomas Monjalon
  4 siblings, 1 reply; 22+ messages in thread
From: David Hunt @ 2019-09-27 12:16 UTC (permalink / raw)
  To: david.hunt; +Cc: dev, Marcin Hajkowski

From: Marcin Hajkowski <marcinx.hajkowski@intel.com>

Add command and related logic to query CPU frequencies
either for specified CPU or all cores.

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>
---
 .../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 cdb241801..0bdb2d0d0 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
@@ -96,12 +96,12 @@ set_policy_defaults(struct channel_packet *pkt)
 	pkt->workload = LOW;
 	pkt->policy_to_use = TIME;
 	pkt->command = PKT_POLICY;
-	strcpy(pkt->vm_name, "ubuntu2");
+	strlcpy(pkt->vm_name, "ubuntu2", sizeof(pkt->vm_name));
 }
 
-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;
+		strlcpy(pkt.vm_name, policy.vm_name, sizeof(pkt.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;
+		strlcpy(pkt.vm_name, policy.vm_name, sizeof(pkt.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 <core_num>|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;
 
@@ -158,9 +277,15 @@ check_response_cmd(unsigned int lcore_id, int *result)
 	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;
@@ -246,7 +371,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;
@@ -282,11 +407,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;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq
  2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq David Hunt
@ 2019-09-27 12:38       ` Hunt, David
  0 siblings, 0 replies; 22+ messages in thread
From: Hunt, David @ 2019-09-27 12:38 UTC (permalink / raw)
  Cc: dev, Marcin Hajkowski, Daly, Lee


On 27/09/2019 13:16, David Hunt wrote:
> From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>
> Add command and related logic to query CPU frequencies
> either for specified CPU or all cores.
>
> 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>
> ---
>   .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
>   1 file changed, 138 insertions(+), 12 deletions(-)
>

This patch set looks functionally good.

Some of the test steps I ran through are as follows:

Initialy attempt to query frequency from guest, it failed because 
queries were disabled.

     vmpower> set_query ubuntu3 disable

     vmpower(guest)> query_cpu_freq all
     GUEST_CLI: Error receiving message.
     Error during frequency list reception

Then I enabled queries for the VM:

     vmpower> set_query ubuntu3 enable

I was then able to query the freq list for all the cores in the VM:

     vmpower(guest)> query_cpu_freq all
     Frequency of [0] vcore is 2300000.
*Frequency of [1] vcore is 2300000.*
     Frequency of [2] vcore is 2300000.
     Frequency of [3] vcore is 2300000.
     Frequency of [4] vcore is 2300000.
     Frequency of [5] vcore is 2300000.
     Frequency of [6] vcore is 2300000.
     Frequency of [7] vcore is 2300000.

When a freq was changed in a core:

     vmpower(guest)> set_cpu_freq 1 down
     ACK received for message sent to host.

The frequency of core 1 had changed in the query, as expected:

     vmpower(guest)> query_cpu_freq all
     Frequency of [0] vcore is 2300000.
*Frequency of [1] vcore is 2200000.*
     Frequency of [2] vcore is 2300000.
     Frequency of [3] vcore is 2300000.
     Frequency of [4] vcore is 2300000.
     Frequency of [5] vcore is 2300000.
     Frequency of [6] vcore is 2300000.
     Frequency of [7] vcore is 2300000.

I've added a Tested-by tag to the v2 patchset.

Rgds,
Dave.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq
  2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq David Hunt
@ 2019-09-30  9:54       ` Hunt, David
  0 siblings, 0 replies; 22+ messages in thread
From: Hunt, David @ 2019-09-30  9:54 UTC (permalink / raw)
  Cc: dev, Marcin Hajkowski

On 27/09/2019 13:15, David Hunt wrote:
> From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
>
> Extend incoming packet reading API with new packet
> type which carries CPU frequencies.
>
> 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>
> ---
>   lib/librte_power/channel_commands.h | 21 +++++++++++++++++++++
>   lib/librte_power/guest_channel.c    | 27 ++++++++++++++++-----------
>   lib/librte_power/guest_channel.h    | 22 +++++++++++++++++-----
>   3 files changed, 54 insertions(+), 16 deletions(-)


Please note that these changes depends on
(http://patches.dpdk.org/project/dpdk/list/?series=6568)
which should be applied first.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/4] frequency list query from guest
  2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
                       ` (3 preceding siblings ...)
  2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq David Hunt
@ 2019-10-27 19:59     ` Thomas Monjalon
  4 siblings, 0 replies; 22+ messages in thread
From: Thomas Monjalon @ 2019-10-27 19:59 UTC (permalink / raw)
  To: David Hunt; +Cc: dev

27/09/2019 14:15, David Hunt:
> Marcin Hajkowski (4):
> 1/4 power: extend guest channel for query freq
> 2/4 power: process cpu freq query
> 3/4 power: add mechanism to disable queries
> 4/4 power: add cmd to query CPU freq

This first patch needs a fix to be able to compile (missing size parameter).
Such fix is done only in the patch 4. I adjust it while merging.

Applied, thanks



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-10-27 19:59 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 17:15 [dpdk-dev] [PATCH 0/4] Frequency list query Hajkowski
2019-04-03 17:15 ` Hajkowski
2019-04-03 17:15 ` [dpdk-dev] [PATCH 1/4] power: extend guest channel for query freq Hajkowski
2019-04-03 17:15   ` Hajkowski
2019-09-27 12:15   ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest David Hunt
2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq David Hunt
2019-09-30  9:54       ` Hunt, David
2019-09-27 12:15     ` [dpdk-dev] [PATCH v2 2/4] power: process cpu freq query David Hunt
2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 3/4] power: add mechanism to disable queries David Hunt
2019-09-27 12:16     ` [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq David Hunt
2019-09-27 12:38       ` Hunt, David
2019-10-27 19:59     ` [dpdk-dev] [PATCH v2 0/4] frequency list query from guest Thomas Monjalon
2019-04-03 17:15 ` [dpdk-dev] [PATCH 2/4] power: process cpu freq. query Hajkowski
2019-04-03 17:15   ` Hajkowski
2019-04-03 17:15 ` [dpdk-dev] [PATCH 3/4] power: add mechanism to disable queries Hajkowski
2019-04-03 17:15   ` Hajkowski
2019-04-03 17:16 ` [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq Hajkowski
2019-04-03 17:16   ` Hajkowski
2019-09-27  9:52   ` Daly, Lee
2019-09-27 10:19     ` Ferruh Yigit
2019-09-27 10:40       ` Hunt, David
2019-07-04 19:57 ` [dpdk-dev] [PATCH 0/4] Frequency list query Thomas Monjalon

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).