Skip to contentSkip to conversation

Frequency list query

PATCH In review Hajkowski 5 participants 17 messages Apr 3, 2019 – Oct 27, 2019

lore
Share & tools
lore

Hajkowski

author
#0 lore raw

cover Frequency list query

From: Marcin Hajkowski <[email protected]>

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(-)
Signature · 1 line
2.17.2
author
#1 lore raw

PATCH 1/4 power: extend guest channel for query freq.

From: Marcin Hajkowski <[email protected]>

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

---
 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(-)
lib/librte_power/channel_commands.h +21 -0
index 33fd53a6d..ce587283c 100644
@@ -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
 }
lib/librte_power/guest_channel.c +16 -11
index 888423891..439cd2f38 100644
@@ -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
lib/librte_power/guest_channel.h +16 -5
index 7c385df39..473901547 100644
@@ -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
 }
Signature · 1 line
2.17.2
author
#10 lore raw

PATCH 2/4 power: process cpu freq. query

In reply to Hajkowski

From: Marcin Hajkowski <[email protected]>

On query received from VM guest send CPUs frequencies.

---
 examples/vm_power_manager/channel_monitor.c | 67 ++++++++++++++++++---
 1 file changed, 59 insertions(+), 8 deletions(-)
examples/vm_power_manager/channel_monitor.c +59 -8
index ed580b36a..69934d4e6 100644
@@ -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
Signature · 1 line
2.17.2
author
#11 lore raw

PATCH 3/4 power: add mechanism to disable queries

In reply to Hajkowski

From: Marcin Hajkowski <[email protected]>

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

---
 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(+)
examples/vm_power_manager/channel_manager.c +20 -0
index 09bfa5c0d..7c852360a 100644
@@ -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;
examples/vm_power_manager/channel_manager.h +18 -0
index c3cdce492..6b032a79f 100644
@@ -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.
examples/vm_power_manager/channel_monitor.c +3 -0
index 69934d4e6..71fd8952b 100644
@@ -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;
 
examples/vm_power_manager/vm_power_cli.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.17.2
author
#12 lore raw

PATCH 4/4 power: add cmd to query CPU freq.

In reply to Hajkowski

From: Marcin Hajkowski <[email protected]>

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

---
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 1 file changed, 138 insertions(+), 12 deletions(-)
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +138 -12
index af49dfef8..d1b4ac2aa 100644
@@ -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;
 
Signature · 1 line
2.17.2
#16 lore raw
In reply to Hajkowski

03/04/2019 19:15, Hajkowski:

Quoted 5 lines

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.

Acked-by on v1 4/4
#13 lore raw

Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.

In reply to Hajkowski
Quoted 20 lines

-----Original Message-----
From: Hajkowski, MarcinX
Sent: Wednesday, April 3, 2019 6:16 PM
To: Hunt, David <[email protected]>
Cc: [email protected]; Hajkowski, MarcinX <[email protected]>
Subject: [PATCH 4/4] power: add cmd to query CPU freq.

From: Marcin Hajkowski <[email protected]>

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

---
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 1 file changed, 138 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

<...>

examples/vm_power_manager/guest_cli/vm_power_cli_guest.c cmdline_parse_inst_t cmd_quit = { · line 194

Quoted 3 lines
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +3 -0
+
+		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:

#14 lore raw

Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.

Quoted 19 lines · Lee
Quoted 19 lines

-----Original Message-----
From: Hajkowski, MarcinX
Sent: Wednesday, April 3, 2019 6:16 PM
To: Hunt, David <[email protected]>
Cc: [email protected]; Hajkowski, MarcinX <[email protected]>
Subject: [PATCH 4/4] power: add cmd to query CPU freq.

From: Marcin Hajkowski <[email protected]>

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

---
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 1 file changed, 138 insertions(+), 12 deletions(-)
Quoted 8 lines
Quoted 1 line
(quoted diff) +0 -0

<...>

examples/vm_power_manager/guest_cli/vm_power_cli_guest.c cmdline_parse_inst_t cmd_quit = { · line 194

Quoted 3 lines
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +3 -0
+
+		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)

Quoted 5 lines

Add my tag after small change above has been applied to all instances of strcpy() in patchset. For all in series:

#15 lore raw

Re: [dpdk-dev] [PATCH 4/4] power: add cmd to query CPU freq.

Quoted 26 lines · Ferruh Yigit
Quoted 18 lines · Lee
Quoted 18 lines

-----Original Message-----
From: Hajkowski, MarcinX
Sent: Wednesday, April 3, 2019 6:16 PM
To: Hunt, David <[email protected]>
Cc: [email protected]; Hajkowski, MarcinX <[email protected]>
Subject: [PATCH 4/4] power: add cmd to query CPU freq.

From: Marcin Hajkowski <[email protected]>

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

---
  .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
  1 file changed, 138 insertions(+), 12 deletions(-)
Quoted 7 lines
Quoted 1 line
(quoted diff) +0 -0

<...>

examples/vm_power_manager/guest_cli/vm_power_cli_guest.c cmdline_parse_inst_t cmd_quit = { · line 194

Quoted 3 lines
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +3 -0
+
+		pkt.command = CPU_POWER_QUERY_FREQ_LIST;
+		strcpy(pkt.vm_name, policy.vm_name);

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

Quoted 6 lines

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

#2 lore raw

v2 cover frequency list query from guest

In reply to Hajkowski

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

#3 lore raw

PATCH v2 1/4 power: extend guest channel for query freq

From: Marcin Hajkowski <[email protected]>

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

---
 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(-)
lib/librte_power/channel_commands.h +21 -0
index d81216b42..e461d9c0d 100644
@@ -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
 }
lib/librte_power/guest_channel.c +16 -11
index 888423891..439cd2f38 100644
@@ -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
lib/librte_power/guest_channel.h +17 -5
index 61e142289..025961606 100644
@@ -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
 }
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 2/4 power: process cpu freq query

In reply to David Hunt

From: Marcin Hajkowski <[email protected]>

On query received from VM guest send CPUs frequencies.

---
 examples/vm_power_manager/channel_monitor.c | 67 ++++++++++++++++++---
 1 file changed, 59 insertions(+), 8 deletions(-)
examples/vm_power_manager/channel_monitor.c +59 -8
index 0c73fac55..fd7269889 100644
@@ -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
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 3/4 power: add mechanism to disable queries

In reply to David Hunt

From: Marcin Hajkowski <[email protected]>

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

---
 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(+)
examples/vm_power_manager/channel_manager.c +20 -0
index 4db225755..4ac21f02c 100644
@@ -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)
 {
examples/vm_power_manager/channel_manager.h +18 -0
index 3766e93c8..8284be0a1 100644
@@ -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.
examples/vm_power_manager/channel_monitor.c +3 -0
index fd7269889..0ae62835f 100644
@@ -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;
 
examples/vm_power_manager/vm_power_cli.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 4/4 power: add cmd to query CPU freq

In reply to David Hunt

From: Marcin Hajkowski <[email protected]>

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

---
 .../guest_cli/vm_power_cli_guest.c            | 150 ++++++++++++++++--
 1 file changed, 138 insertions(+), 12 deletions(-)
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +138 -12
index cdb241801..0bdb2d0d0 100644
@@ -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;
 
Signature · 1 line
2.17.1
#8 lore raw

Re: [dpdk-dev] [PATCH v2 4/4] power: add cmd to query CPU freq

Quoted 5 lines · David Hunt

From: Marcin Hajkowski <[email protected]>

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

Quoted 7 lines
---
  .../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.

#4 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] power: extend guest channel for query freq

In reply to David Hunt
Quoted 5 lines · David Hunt

From: Marcin Hajkowski <[email protected]>

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

Quoted 8 lines
---
  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.

#9 lore raw

Re: [dpdk-dev] [PATCH v2 0/4] frequency list query from guest

In reply to David Hunt

27/09/2019 14:15, David Hunt:

Quoted 5 lines

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