From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: Marcus Granado <Marcus.Granado@eu.citrix.com>,
Keir Fraser <keir@xen.org>,
Ian Campbell <Ian.Campbell@citrix.com>,
Li Yechen <lccycc123@gmail.com>,
George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
Juergen Gross <juergen.gross@ts.fujitsu.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Jan Beulich <JBeulich@suse.com>,
Justin Weaver <jtweaver@hawaii.edu>, Matt Wilson <msw@amazon.com>,
Elena Ufimtseva <ufimtseva@gmail.com>
Subject: [PATCH v4 10/15] xen: sched: DOMCTL_*vcpuaffinity works with hard and soft affinity
Date: Fri, 22 Nov 2013 19:57:59 +0100 [thread overview]
Message-ID: <20131122185758.11200.44816.stgit@Solace> (raw)
In-Reply-To: <20131122183332.11200.20231.stgit@Solace>
by adding a flag for the caller to specify which one he cares about.
Add also another cpumap there. This way, in case of
DOMCTL_setvcpuaffinity, Xen can return back to the caller the
"effective affinity" of the vcpu. We call the effective affinity
the intersection between cpupool's cpus, the (new?) hard affinity
and the (new?) soft affinity.
The purpose of this is allowing the toolstack to figure out whether
or not the requested change produced sensible results, when combined
with the other settings that are already in place.
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@eu.citrix.com>
---
Changes since v3:
* no longer discarding possible errors. Also, rollback setting
hard affinity if setting soft affinity fails afterwards, so
that the caller really sees no changes when the call fails,
as requested during review;
* fixed -EFAULT --> -ENOMEM in case of a failed memory allocation,
as requested during review;
* removed non necessary use of pointer to pointer, as requested
during review.
Changes from v2:
* in DOMCTL_[sg]etvcpuaffinity, flag is really a flag now,
i.e., we accept request for setting and getting: (1) only
hard affinity; (2) only soft affinity; (3) both; as
suggested during review.
---
tools/libxc/xc_domain.c | 4 +-
xen/arch/x86/traps.c | 4 +-
xen/common/domctl.c | 92 +++++++++++++++++++++++++++++++++++++++++--
xen/common/schedule.c | 35 +++++++++++-----
xen/common/wait.c | 6 +--
xen/include/public/domctl.h | 15 ++++++-
xen/include/xen/sched.h | 3 +
7 files changed, 134 insertions(+), 25 deletions(-)
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 1ccafc5..f9ae4bf 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -215,7 +215,9 @@ int xc_vcpu_setaffinity(xc_interface *xch,
domctl.cmd = XEN_DOMCTL_setvcpuaffinity;
domctl.domain = (domid_t)domid;
- domctl.u.vcpuaffinity.vcpu = vcpu;
+ domctl.u.vcpuaffinity.vcpu = vcpu;
+ /* Soft affinity is there, but not used anywhere for now, so... */
+ domctl.u.vcpuaffinity.flags = XEN_VCPUAFFINITY_HARD;
memcpy(local, cpumap, cpusize);
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 157031e..ff4523b 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3103,7 +3103,7 @@ static void nmi_mce_softirq(void)
* Make sure to wakeup the vcpu on the
* specified processor.
*/
- vcpu_set_affinity(st->vcpu, cpumask_of(st->processor));
+ vcpu_set_hard_affinity(st->vcpu, cpumask_of(st->processor));
/* Affinity is restored in the iret hypercall. */
}
@@ -3132,7 +3132,7 @@ void async_exception_cleanup(struct vcpu *curr)
if ( !cpumask_empty(curr->cpu_hard_affinity_tmp) &&
!cpumask_equal(curr->cpu_hard_affinity_tmp, curr->cpu_hard_affinity) )
{
- vcpu_set_affinity(curr, curr->cpu_hard_affinity_tmp);
+ vcpu_set_hard_affinity(curr, curr->cpu_hard_affinity_tmp);
cpumask_clear(curr->cpu_hard_affinity_tmp);
}
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 5e0ac5c..6081d22 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -616,20 +616,102 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
if ( op->cmd == XEN_DOMCTL_setvcpuaffinity )
{
- cpumask_var_t new_affinity;
+ cpumask_var_t new_affinity, old_affinity;
+ cpumask_t *online;
+
+ /* We need this to restore hard affinity if setting soft fails */
+ if ( !alloc_cpumask_var(&old_affinity) )
+ {
+ ret = -ENOMEM;
+ break;
+ }
+ cpumask_copy(old_affinity, v->cpu_hard_affinity);
ret = xenctl_bitmap_to_cpumask(
&new_affinity, &op->u.vcpuaffinity.cpumap);
- if ( !ret )
+ if ( ret )
+ {
+ free_cpumask_var(old_affinity);
+ break;
+ }
+
+ ret = -EINVAL;
+ if ( op->u.vcpuaffinity.flags == 0 )
+ goto setvcpuaffinity_out;
+
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_HARD )
+ {
+ ret = vcpu_set_hard_affinity(v, new_affinity);
+ if ( ret )
+ goto setvcpuaffinity_out;
+ }
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_SOFT )
+ {
+ ret = vcpu_set_soft_affinity(v, new_affinity);
+ if ( ret )
+ {
+ /*
+ * Since we're returning error, the caller expects nothing
+ * happened, so we rollback the changes to hard affinity
+ * (if any).
+ */
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_HARD )
+ vcpu_set_hard_affinity(v, old_affinity);
+ goto setvcpuaffinity_out;
+ }
+ }
+
+ /*
+ * Report back to the caller what the "effective affinity", that
+ * is the intersection of cpupool's pcpus, the (new?) hard
+ * affinity and the (new?) soft-affinity.
+ */
+ if ( !guest_handle_is_null(op->u.vcpuaffinity.eff_cpumap.bitmap) )
{
- ret = vcpu_set_affinity(v, new_affinity);
- free_cpumask_var(new_affinity);
+ online = cpupool_online_cpumask(v->domain->cpupool);
+ cpumask_and(new_affinity, online, v->cpu_hard_affinity);
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_SOFT)
+ cpumask_and(new_affinity, new_affinity,
+ v->cpu_soft_affinity);
+
+ ret = cpumask_to_xenctl_bitmap(
+ &op->u.vcpuaffinity.eff_cpumap, new_affinity);
}
+
+ setvcpuaffinity_out:
+ free_cpumask_var(new_affinity);
+ free_cpumask_var(old_affinity);
}
else
{
+ cpumask_var_t affinity;
+
+ /*
+ * If the caller asks for both _HARD and _SOFT, what we return
+ * is the intersection of hard and soft affinity for the vcpu.
+ */
+ if ( !alloc_cpumask_var(&affinity) )
+ {
+ ret = -ENOMEM;
+ break;
+ }
+ cpumask_setall(affinity);
+
+ if ( op->u.vcpuaffinity.flags == 0 )
+ {
+ ret = -EINVAL;
+ free_cpumask_var(affinity);
+ break;
+ }
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_HARD )
+ cpumask_copy(affinity, v->cpu_hard_affinity);
+ if ( op->u.vcpuaffinity.flags & XEN_VCPUAFFINITY_SOFT )
+ cpumask_and(affinity, affinity, v->cpu_soft_affinity);
+
ret = cpumask_to_xenctl_bitmap(
- &op->u.vcpuaffinity.cpumap, v->cpu_hard_affinity);
+ &op->u.vcpuaffinity.cpumap, affinity);
+
+ free_cpumask_var(affinity);
}
}
break;
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index c9ae521..b1e9b08 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -654,22 +654,14 @@ void sched_set_node_affinity(struct domain *d, nodemask_t *mask)
SCHED_OP(DOM2OP(d), set_node_affinity, d, mask);
}
-int vcpu_set_affinity(struct vcpu *v, const cpumask_t *affinity)
+static int vcpu_set_affinity(
+ struct vcpu *v, const cpumask_t *affinity, cpumask_t *which)
{
- cpumask_t online_affinity;
- cpumask_t *online;
spinlock_t *lock;
- if ( v->domain->is_pinned )
- return -EINVAL;
- online = VCPU2ONLINE(v);
- cpumask_and(&online_affinity, affinity, online);
- if ( cpumask_empty(&online_affinity) )
- return -EINVAL;
-
lock = vcpu_schedule_lock_irq(v);
- cpumask_copy(v->cpu_hard_affinity, affinity);
+ cpumask_copy(which, affinity);
/* Always ask the scheduler to re-evaluate placement
* when changing the affinity */
@@ -688,6 +680,27 @@ int vcpu_set_affinity(struct vcpu *v, const cpumask_t *affinity)
return 0;
}
+int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity)
+{
+ cpumask_t online_affinity;
+ cpumask_t *online;
+
+ if ( v->domain->is_pinned )
+ return -EINVAL;
+
+ online = VCPU2ONLINE(v);
+ cpumask_and(&online_affinity, affinity, online);
+ if ( cpumask_empty(&online_affinity) )
+ return -EINVAL;
+
+ return vcpu_set_affinity(v, affinity, v->cpu_hard_affinity);
+}
+
+int vcpu_set_soft_affinity(struct vcpu *v, const cpumask_t *affinity)
+{
+ return vcpu_set_affinity(v, affinity, v->cpu_soft_affinity);
+}
+
/* Block the currently-executing domain until a pertinent event occurs. */
void vcpu_block(void)
{
diff --git a/xen/common/wait.c b/xen/common/wait.c
index 3f6ff41..1f6b597 100644
--- a/xen/common/wait.c
+++ b/xen/common/wait.c
@@ -135,7 +135,7 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv)
/* Save current VCPU affinity; force wakeup on *this* CPU only. */
wqv->wakeup_cpu = smp_processor_id();
cpumask_copy(&wqv->saved_affinity, curr->cpu_hard_affinity);
- if ( vcpu_set_affinity(curr, cpumask_of(wqv->wakeup_cpu)) )
+ if ( vcpu_set_hard_affinity(curr, cpumask_of(wqv->wakeup_cpu)) )
{
gdprintk(XENLOG_ERR, "Unable to set vcpu affinity\n");
domain_crash_synchronous();
@@ -166,7 +166,7 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv)
static void __finish_wait(struct waitqueue_vcpu *wqv)
{
wqv->esp = NULL;
- (void)vcpu_set_affinity(current, &wqv->saved_affinity);
+ (void)vcpu_set_hard_affinity(current, &wqv->saved_affinity);
}
void check_wakeup_from_wait(void)
@@ -184,7 +184,7 @@ void check_wakeup_from_wait(void)
/* Re-set VCPU affinity and re-enter the scheduler. */
struct vcpu *curr = current;
cpumask_copy(&wqv->saved_affinity, curr->cpu_hard_affinity);
- if ( vcpu_set_affinity(curr, cpumask_of(wqv->wakeup_cpu)) )
+ if ( vcpu_set_hard_affinity(curr, cpumask_of(wqv->wakeup_cpu)) )
{
gdprintk(XENLOG_ERR, "Unable to set vcpu affinity\n");
domain_crash_synchronous();
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 01a3652..4f71450 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -300,8 +300,19 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_nodeaffinity_t);
/* XEN_DOMCTL_setvcpuaffinity */
/* XEN_DOMCTL_getvcpuaffinity */
struct xen_domctl_vcpuaffinity {
- uint32_t vcpu; /* IN */
- struct xenctl_bitmap cpumap; /* IN/OUT */
+ /* IN variables. */
+ uint32_t vcpu;
+ /* Set/get the hard affinity for vcpu */
+#define _XEN_VCPUAFFINITY_HARD 0
+#define XEN_VCPUAFFINITY_HARD (1U<<_XEN_VCPUAFFINITY_HARD)
+ /* Set/get the soft affinity for vcpu */
+#define _XEN_VCPUAFFINITY_SOFT 1
+#define XEN_VCPUAFFINITY_SOFT (1U<<_XEN_VCPUAFFINITY_SOFT)
+ uint32_t flags;
+ /* IN/OUT variables. */
+ struct xenctl_bitmap cpumap;
+ /* OUT variables. */
+ struct xenctl_bitmap eff_cpumap;
};
typedef struct xen_domctl_vcpuaffinity xen_domctl_vcpuaffinity_t;
DEFINE_XEN_GUEST_HANDLE(xen_domctl_vcpuaffinity_t);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 3575312..0f728b3 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -755,7 +755,8 @@ void scheduler_free(struct scheduler *sched);
int schedule_cpu_switch(unsigned int cpu, struct cpupool *c);
void vcpu_force_reschedule(struct vcpu *v);
int cpu_disable_scheduler(unsigned int cpu);
-int vcpu_set_affinity(struct vcpu *v, const cpumask_t *affinity);
+int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity);
+int vcpu_set_soft_affinity(struct vcpu *v, const cpumask_t *affinity);
void restore_vcpu_affinity(struct domain *d);
void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate);
next prev parent reply other threads:[~2013-11-22 18:57 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-22 18:56 [PATCH v4 00/15] Implement vcpu soft affinity for credit1 Dario Faggioli
2013-11-22 18:56 ` [PATCH v4 01/15] xl: match output of vcpu-list with pinning syntax Dario Faggioli
2013-11-22 18:56 ` [PATCH v4 02/15] libxl: sanitize error handling in libxl_get_max_{cpus, nodes} Dario Faggioli
2013-11-25 17:26 ` George Dunlap
2013-11-27 13:45 ` Ian Campbell
2013-12-02 18:21 ` Dario Faggioli
2013-12-03 9:41 ` Ian Campbell
2013-12-03 11:40 ` Dario Faggioli
2013-12-03 11:45 ` Ian Campbell
2013-12-03 12:06 ` Dario Faggioli
2013-12-03 17:40 ` Ian Jackson
2013-11-22 18:56 ` [PATCH v4 03/15] libxl: introduce libxl_get_nr_cpus() Dario Faggioli
2013-11-27 13:49 ` Ian Campbell
2013-12-03 17:48 ` Ian Jackson
2013-12-03 17:52 ` Dario Faggioli
2013-12-03 17:54 ` Ian Jackson
2013-12-03 18:09 ` George Dunlap
2013-12-03 18:17 ` Konrad Rzeszutek Wilk
2013-12-03 18:22 ` George Dunlap
2013-12-03 18:26 ` Dario Faggioli
2013-12-03 18:19 ` Dario Faggioli
2013-12-03 18:15 ` Dario Faggioli
2013-12-03 18:16 ` Ian Jackson
2013-11-22 18:57 ` [PATCH v4 04/15] xl: allow for node-wise specification of vcpu pinning Dario Faggioli
2013-11-22 18:57 ` [PATCH v4 05/15] xl: implement and enable dryrun mode for `xl vcpu-pin' Dario Faggioli
2013-11-22 18:57 ` [PATCH v4 06/15] xl: test script for the cpumap parser (for vCPU pinning) Dario Faggioli
2013-11-22 18:57 ` [PATCH v4 07/15] xen: sched: rename v->cpu_affinity into v->cpu_hard_affinity Dario Faggioli
2013-11-22 18:57 ` [PATCH v4 08/15] xen: sched: introduce soft-affinity and use it instead d->node-affinity Dario Faggioli
2013-11-22 18:57 ` [PATCH v4 09/15] xen: derive NUMA node affinity from hard and soft CPU affinity Dario Faggioli
2013-11-22 18:57 ` Dario Faggioli [this message]
2013-11-27 13:11 ` [PATCH v4 10/15] xen: sched: DOMCTL_*vcpuaffinity works with hard and soft affinity Jan Beulich
2013-11-27 14:17 ` George Dunlap
2013-11-27 14:31 ` Dario Faggioli
2013-11-22 18:58 ` [PATCH v4 11/15] libxc: get and set soft and hard affinity Dario Faggioli
2013-11-22 18:58 ` [PATCH v4 12/15] libxl: get and set soft affinity Dario Faggioli
2013-11-25 17:52 ` George Dunlap
2013-11-27 14:45 ` Ian Campbell
2013-12-02 18:17 ` Dario Faggioli
2013-12-03 9:35 ` Ian Campbell
2013-11-22 18:58 ` [PATCH v4 13/15] xl: enable getting and setting soft Dario Faggioli
2013-11-27 14:57 ` Ian Campbell
2013-12-02 18:10 ` Dario Faggioli
2013-12-03 9:32 ` Ian Campbell
2013-12-03 10:27 ` Dario Faggioli
2013-12-03 10:59 ` Ian Campbell
2013-12-03 11:14 ` Dario Faggioli
2013-12-03 11:18 ` Ian Campbell
2013-11-22 18:58 ` [PATCH v4 14/15] xl: enable for specifying node-affinity in the config file Dario Faggioli
2013-11-27 15:53 ` Ian Campbell
2013-12-02 18:22 ` Dario Faggioli
2013-11-22 18:58 ` [PATCH v4 15/15] libxl: automatic NUMA placement affects soft affinity Dario Faggioli
2013-11-27 15:55 ` Ian Campbell
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=20131122185758.11200.44816.stgit@Solace \
--to=dario.faggioli@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=Marcus.Granado@eu.citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jtweaver@hawaii.edu \
--cc=juergen.gross@ts.fujitsu.com \
--cc=keir@xen.org \
--cc=lccycc123@gmail.com \
--cc=msw@amazon.com \
--cc=ufimtseva@gmail.com \
--cc=xen-devel@lists.xen.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 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).