DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Hunt <david.hunt@intel.com>
To: david.hunt@intel.com
Cc: dev@dpdk.org, Marcin Hajkowski <marcinx.hajkowski@intel.com>
Subject: [dpdk-dev] [PATCH v2 3/4] power: add mechanism to disable queries
Date: Fri, 27 Sep 2019 13:16:00 +0100	[thread overview]
Message-ID: <20190927121601.23661-4-david.hunt@intel.com> (raw)
In-Reply-To: <20190927121601.23661-1-david.hunt@intel.com>

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


  parent reply	other threads:[~2019-09-27 12:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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     ` David Hunt [this message]
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

Reply instructions:

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

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

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

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

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

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

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