From: Bernhard Kaindl <bernhard.kaindl@cloud.com>
To: xen-devel@lists.xenproject.org
Cc: "Bernhard Kaindl" <bernhard.kaindl@cloud.com>,
"Dario Faggioli" <dfaggioli@suse.com>,
"Juergen Gross" <jgross@suse.com>,
"George Dunlap" <gwd@xenproject.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH 1/2] sched/core: For a new metric, add vcpu->nonaffine_time
Date: Mon, 21 Jul 2025 11:49:49 +0200 [thread overview]
Message-ID: <20250721094951.2006-1-bernhard.kaindl@cloud.com> (raw)
To monitor the effectiveness of vCPU soft-affinity on NUMA hosts,
we'd like to create a vCPU metric that accumulates the amount of
vCPU time running outside of the soft affinity mask of the sched-unit:
- Add a new time counter, nonaffine_time to struct vcpu.
- Accumulate the nonaffine_time on vcpu_runstate_change():
Account the time spent in the RUNSTATE_running state outside
of unit->cpu_soft_affinity: It is always initialized and defaults
to cpumask_all (bits for all NR_CPUS set), so we only accumulate
nonaffine time when the vCPU runs on an unset CPU (non-affine).
In the next patch, this field can be used to retrieve the accumulated
nonaffine running time e.g. using vcpu_runstate_get().
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
---
xen/common/sched/core.c | 20 ++++++++++++++++++++
xen/include/xen/sched.h | 11 +++++++++++
2 files changed, 31 insertions(+)
diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index 13fdf57e57..489255b9c6 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -260,6 +260,23 @@ static inline void vcpu_urgent_count_update(struct vcpu *v)
}
}
+/*
+ * For accounting non-affine running time of a vCPU, return true if
+ * the vCPU is running in RUNSTATE_running state while not on a CPU
+ * in unit->cpu_soft_affinity.
+ */
+static inline bool nonaffine(const struct vcpu *v,
+ const struct sched_unit *unit)
+{
+ /*
+ * unit->cpu_soft_affinity is always initialized and defaults to
+ * cpumask_all (bits for all NR_CPUS set), so we only accumulate
+ * nonaffine time when the vCPU runs on an unset CPU (non-affine).
+ */
+ return v->runstate.state == RUNSTATE_running &&
+ !cpumask_test_cpu(v->processor, unit->cpu_soft_affinity);
+}
+
static inline void vcpu_runstate_change(
struct vcpu *v, int new_state, s_time_t new_entry_time)
{
@@ -285,6 +302,9 @@ static inline void vcpu_runstate_change(
{
v->runstate.time[v->runstate.state] += delta;
v->runstate.state_entry_time = new_entry_time;
+
+ if ( nonaffine(v, unit) ) /* When running nonaffine, add delta */
+ v->nonaffine_time += delta;
}
v->runstate.state = new_state;
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index fe53d4fab7..aba60afd4f 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -198,7 +198,18 @@ struct vcpu
struct sched_unit *sched_unit;
+ /*
+ * The struct vcpu_runstate_info contains the vCPU time spent
+ * in each runstate and the entry time of the current runstate.
+ *
+ * Note: This field is used for the guest runstate shared memory area.
+ * Therefore, it is part of the frozen guest API and cannot be changed.
+ */
struct vcpu_runstate_info runstate;
+
+ /* vCPU time running outside the scheduling unit's soft_affinity mask */
+ uint64_t nonaffine_time;
+
#ifndef CONFIG_COMPAT
# define runstate_guest(v) ((v)->runstate_guest)
XEN_GUEST_HANDLE(vcpu_runstate_info_t) runstate_guest; /* guest address */
--
2.43.0
next reply other threads:[~2025-07-21 9:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 9:49 Bernhard Kaindl [this message]
2025-07-21 9:49 ` [PATCH 2/2] sched/core: Update vcpu_runstate_get() to return nonaffine time Bernhard Kaindl
2025-07-21 10:43 ` Jan Beulich
2025-07-21 11:49 ` Jürgen Groß
2025-07-21 11:22 ` [PATCH 1/2] sched/core: For a new metric, add vcpu->nonaffine_time 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=20250721094951.2006-1-bernhard.kaindl@cloud.com \
--to=bernhard.kaindl@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dfaggioli@suse.com \
--cc=gwd@xenproject.org \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.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.