From: Anthony PERARD <anthony.perard@citrix.com>
To: Xen Devel <xen-devel@lists.xen.org>
Cc: "Liu, Jinsong" <jinsong.liu@intel.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Stefano Stabellini <stefano.stabellini@citrix.com>,
Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH 4/4] Implement 'xm vcpu-set' command for HVM guest
Date: Fri, 31 May 2013 17:33:13 +0100 [thread overview]
Message-ID: <1370017993-13437-5-git-send-email-anthony.perard@citrix.com> (raw)
In-Reply-To: <1370017993-13437-1-git-send-email-anthony.perard@citrix.com>
From: Ian Jackson <ian.jackson@eu.citrix.com>
Currently Xen has 'xm vcpu-set' command for PV domain, but not
available for HVM domain. This patch is use to enable 'xm vcpu-set'
command for HVM domain. It setup vcpu watch at xenstore, and at qemu
side, handle vcpu online/offline accordingly. With this patch, 'xm
vcpu-set' command works for both PV and HVM guest with same format.
Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
Port from qemu-xen-traditionnal to qemu-xen:
qemu-xen does not support anymore command through xenstore, so this
path include an initialisation of a xenstore loop.
An upstream of this patch would need to go QMP.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
hw/acpi_piix4.c | 5 +++--
xen-all.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 49c38d3..4c01aa2 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -728,8 +728,8 @@ static int disable_processor(PIIX4PMState *g, int cpu)
void qemu_cpu_add_remove(int cpu, int state)
{
- if ((cpu <=0) || (cpu >= max_cpus)) {
- fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+ if ((cpu < 0) || (cpu >= max_cpus)) {
+ fprintf(stderr, "vcpu out of range, should be [0~%d]\n", max_cpus - 1);
return;
}
@@ -742,6 +742,7 @@ void qemu_cpu_add_remove(int cpu, int state)
return;
}
}
+ fprintf(stderr, "%s vcpu %d\n", state ? "Add" : "Remove", cpu);
pm_update_sci(acpi_state);
}
diff --git a/xen-all.c b/xen-all.c
index daf43b9..04b88a6 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -99,6 +99,8 @@ typedef struct XenIOState {
Notifier suspend;
} XenIOState;
+static void xen_xenstore_watch_vcpu_set(XenIOState *state);
+
/* Xen specific function for piix pci */
int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -1170,6 +1172,7 @@ int xen_hvm_init(void)
xen_be_register("vkbd", &xen_kbdmouse_ops);
xen_be_register("qdisk", &xen_blkdev_ops);
xen_read_physmap(state);
+ xen_xenstore_watch_vcpu_set(state);
return 0;
}
@@ -1234,3 +1237,65 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
}
}
}
+
+/* Xenstore watch init for vcpu-set */
+
+static void xenstore_process_vcpu_set_event(char **vec, struct xs_handle *xsh)
+{
+ char *act = NULL;
+ char *vcpustr, *node = vec[XS_WATCH_PATH];
+ unsigned int vcpu, len;
+
+ vcpustr = strstr(node, "cpu/");
+ if (!vcpustr) {
+ fprintf(stderr, "vcpu-set: watch node error.\n");
+ return;
+ }
+ sscanf(vcpustr, "cpu/%u", &vcpu);
+
+ act = xs_read(xsh, XBT_NULL, node, &len);
+ if (!act) {
+ fprintf(stderr, "vcpu-set: no command yet.\n");
+ return;
+ }
+
+ if (!strncmp(act, "online", len))
+ qemu_cpu_add_remove(vcpu, 1);
+ else if (!strncmp(act, "offline", len))
+ qemu_cpu_add_remove(vcpu, 0);
+ else
+ fprintf(stderr, "vcpu-set: command error.\n");
+
+ free(act);
+ return;
+}
+
+static void xenstore_process_event(void *opaque)
+{
+ char **vec;
+ unsigned int num;
+ struct xs_handle *xsh = opaque;
+
+ vec = xs_read_watch(xsh, &num);
+ if (!vec)
+ return;
+
+ if (!strcmp(vec[XS_WATCH_TOKEN], "vcpu-set")) {
+ xenstore_process_vcpu_set_event(vec, xsh);
+ goto out;
+ }
+
+ out:
+ free(vec);
+}
+
+static void xen_xenstore_watch_vcpu_set(XenIOState *state)
+{
+ char path[40];
+ /* Set a watch for vcpu-set */
+ snprintf(path, sizeof(path), "/local/domain/%d/cpu", xen_domid);
+ xs_watch(state->xenstore, path, "vcpu-set");
+
+ qemu_set_fd_handler(xs_fileno(state->xenstore), xenstore_process_event,
+ NULL, state->xenstore);
+}
--
Anthony PERARD
next prev parent reply other threads:[~2013-05-31 16:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 16:33 [PATCH 0/4] CPU hotplug port from qemu-traditionnal to qemu-xen for 4.3 Anthony PERARD
2013-05-31 16:33 ` [PATCH 1/4] HVM vcpu add/remove: qemu logic for vcpu add/revmoe Anthony PERARD
2013-05-31 21:19 ` Konrad Rzeszutek Wilk
2013-06-03 10:23 ` Stefano Stabellini
2013-05-31 16:33 ` [PATCH 2/4] Fix vcpu hotplug bug: get correct vcpu_avail bitmap Anthony PERARD
2013-05-31 16:33 ` [PATCH 3/4] Update vcpu hotplug logic Anthony PERARD
2013-05-31 21:16 ` Konrad Rzeszutek Wilk
2013-05-31 16:33 ` Anthony PERARD [this message]
2013-05-31 21:14 ` [PATCH 4/4] Implement 'xm vcpu-set' command for HVM guest Konrad Rzeszutek Wilk
2013-06-03 8:40 ` Ian Campbell
2013-06-03 10:24 ` Stefano Stabellini
2013-05-31 16:39 ` [PATCH] libxl: Use -vcpu_avail with qemu-xen Anthony PERARD
2013-06-03 8:37 ` Ian Campbell
2013-06-03 10:10 ` Stefano Stabellini
2013-06-03 13:49 ` Anthony PERARD
2013-05-31 17:20 ` [PATCH 0/4] CPU hotplug port from qemu-traditionnal to qemu-xen for 4.3 Anthony PERARD
2013-06-03 8:37 ` Ian Campbell
[not found] ` <51A8DA91.1080601@citrix.com>
2013-05-31 21:16 ` Konrad Rzeszutek Wilk
2013-06-03 8:41 ` Ian Campbell
2013-06-03 11:12 ` Anthony PERARD
2013-06-03 10:13 ` Stefano Stabellini
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=1370017993-13437-5-git-send-email-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jinsong.liu@intel.com \
--cc=stefano.stabellini@citrix.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).