All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Julien Grall <julien@xen.org>,
	Anthony PERARD <anthony.perard@vates.tech>
Subject: [PATCH v8 9/9] tools/xenstored: use xenmanage_poll_changed_domain()
Date: Tue,  4 Feb 2025 12:34:07 +0100	[thread overview]
Message-ID: <20250204113407.16839-10-jgross@suse.com> (raw)
In-Reply-To: <20250204113407.16839-1-jgross@suse.com>

Instead of checking each known domain after having received a
VIRQ_DOM_EXC event, use the new xenmanage_poll_changed_domain()
function for directly getting the domid of a domain having changed
its state.

A test doing "xl shutdown" of 1000 guests has shown to reduce the
consumed cpu time of xenstored by 6% with this change applied.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V8:
- new patch
---
 tools/xenstored/domain.c | 64 +++++++++++++++++++++++++++++-----------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 63df24030e..ad16a00ce3 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -621,30 +621,24 @@ static int destroy_domain(void *_domain)
 	return 0;
 }
 
-static int check_domain(const void *k, void *v, void *arg)
+static int do_check_domain(struct domain *domain, bool *notify,
+			   unsigned int state, uint64_t unique_id)
 {
-	unsigned int state;
 	struct connection *conn;
-	int dom_invalid;
-	struct domain *domain = v;
-	bool *notify = arg;
-	uint64_t unique_id;
 
-	dom_invalid = xenmanage_get_domain_info(xm_handle, domain->domid,
-						&state, &unique_id);
-	if (!dom_invalid) {
+	if (unique_id) {
 		if (!domain->unique_id)
 			domain->unique_id = unique_id;
 		else if (domain->unique_id != unique_id)
-			dom_invalid = 1;
+			unique_id = 0;
 	}
 
 	if (!domain->introduced) {
-		if (dom_invalid)
+		if (!unique_id)
 			talloc_free(domain);
 		return 0;
 	}
-	if (!dom_invalid) {
+	if (unique_id) {
 		if ((state & XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN)
 		    && !domain->shutdown) {
 			domain->shutdown = true;
@@ -667,6 +661,21 @@ static int check_domain(const void *k, void *v, void *arg)
 	return 0;
 }
 
+static int check_domain(const void *k, void *v, void *arg)
+{
+	struct domain *domain = v;
+	unsigned int state;
+	uint64_t unique_id;
+
+	if (xenmanage_get_domain_info(xm_handle, domain->domid, &state,
+				      &unique_id)) {
+		unique_id = 0;
+		state = 0;
+	}
+
+	return do_check_domain(domain, arg, state, unique_id);
+}
+
 void check_domains(void)
 {
 	bool notify = false;
@@ -678,6 +687,30 @@ void check_domains(void)
 		fire_special_watches("@releaseDomain");
 }
 
+static struct domain *find_domain_struct(unsigned int domid)
+{
+	return hashtable_search(domhash, &domid);
+}
+
+static void do_check_domains(void)
+{
+	unsigned int domid;
+	unsigned int state;
+	uint64_t unique_id;
+	struct domain *domain;
+	bool notify = false;
+
+	while (!xenmanage_poll_changed_domain(xm_handle, &domid, &state,
+					      &unique_id)) {
+		domain = find_domain_struct(domid);
+		if (domain)
+			do_check_domain(domain, &notify, state, unique_id);
+	}
+
+	if (notify)
+		fire_special_watches("@releaseDomain");
+}
+
 /* We scan all domains rather than use the information given here. */
 void handle_event(void)
 {
@@ -687,7 +720,7 @@ void handle_event(void)
 		barf_perror("Failed to read from event fd");
 
 	if (port == virq_port)
-		check_domains();
+		do_check_domains();
 
 	if (xenevtchn_unmask(xce_handle, port) == -1)
 		barf_perror("Failed to write to event fd");
@@ -698,11 +731,6 @@ static char *talloc_domain_path(const void *context, unsigned int domid)
 	return talloc_asprintf(context, "/local/domain/%u", domid);
 }
 
-static struct domain *find_domain_struct(unsigned int domid)
-{
-	return hashtable_search(domhash, &domid);
-}
-
 int domain_get_quota(const void *ctx, struct connection *conn,
 		     unsigned int domid)
 {
-- 
2.43.0



  parent reply	other threads:[~2025-02-04 11:43 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 11:33 [PATCH v8 0/9] remove libxenctrl usage from xenstored Juergen Gross
2025-02-04 11:33 ` [PATCH v8 1/9] xen/events: don't allow binding a global virq from any domain Juergen Gross
2025-03-11  9:35   ` Julien Grall
2025-03-11  9:51     ` Jürgen Groß
2025-03-11 19:04       ` Julien Grall
2025-03-12  7:05         ` Jürgen Groß
2025-02-04 11:34 ` [PATCH v8 2/9] xen/events: allow setting of global virq handler only for unbound virqs Juergen Gross
2025-02-04 11:34 ` [PATCH v8 3/9] xen: add bitmap to indicate per-domain state changes Juergen Gross
2025-03-06 15:41   ` Jan Beulich
2025-03-06 15:52     ` Jürgen Groß
2025-02-04 11:34 ` [PATCH v8 4/9] xen: add new domctl get_changed_domain Juergen Gross
2025-02-04 11:34 ` [PATCH v8 5/9] tools/libs: add a new libxenmanage library Juergen Gross
2025-02-04 11:34 ` [PATCH v8 6/9] tools/xenstored: use new stable interface instead of libxenctrl Juergen Gross
2025-02-04 11:34 ` [PATCH v8 7/9] docs: update xenstore migration stream definition Juergen Gross
2025-03-11  9:43   ` Julien Grall
2025-03-11  9:58     ` Jürgen Groß
2025-03-11 18:52       ` Julien Grall
2025-02-04 11:34 ` [PATCH v8 8/9] tools/xenstored: use unique_id to identify new domain with same domid Juergen Gross
2025-03-12 17:40   ` Jason Andryuk
2025-03-13  9:52     ` Jürgen Groß
2025-02-04 11:34 ` Juergen Gross [this message]
2025-03-12 17:45   ` [PATCH v8 9/9] tools/xenstored: use xenmanage_poll_changed_domain() Jason Andryuk
2025-03-13  9:53     ` Jürgen Groß
2025-02-25 11:10 ` [PATCH v8 0/9] remove libxenctrl usage from xenstored Juergen Gross
2025-03-05  8:23   ` Juergen Gross
2025-03-05 23:32     ` Stefano Stabellini
2025-03-06 13:13       ` Jan Beulich
2025-03-06 13:27         ` Jürgen Groß
2025-03-06 13:53           ` Jan Beulich
2025-03-06 13:56             ` Jürgen Groß

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=20250204113407.16839-10-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=anthony.perard@vates.tech \
    --cc=julien@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.