[Pkg-libvirt-commits] [libguestfs] 61/266: aarch64: Add common function for getting the CPU model.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:41:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 5ce123400745469a8dc3a931547c581d69b3bd8e
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Thu Aug 7 12:25:13 2014 +0100
aarch64: Add common function for getting the CPU model.
And force a 64 bit CPU model when running on aarch64 with TCG.
---
src/guestfs-internal.h | 1 +
src/launch-direct.c | 13 ++++---------
src/launch-libvirt.c | 30 ++++++++++++++++++------------
src/launch.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 21 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index b99335b..2e9a1d1 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -730,6 +730,7 @@ extern void guestfs___print_timestamped_message (guestfs_h *g, const char *fs, .
extern void guestfs___launch_send_progress (guestfs_h *g, int perdozen);
extern char *guestfs___appliance_command_line (guestfs_h *g, const char *appliance_dev, int flags);
#define APPLIANCE_COMMAND_LINE_IS_TCG 1
+const char *guestfs___get_cpu_model (int kvm);
extern void guestfs___register_backend (const char *name, const struct backend_ops *);
extern int guestfs___set_backend (guestfs_h *g, const char *method);
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 0c3589b..3bae254 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -279,6 +279,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
struct hv_param *hp;
bool has_kvm;
int force_tcg;
+ const char *cpu_model;
/* At present you must add drives before starting the appliance. In
* future when we enable hotplugging you won't need to do this.
@@ -418,17 +419,11 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
*/
has_kvm = is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC);
-#if !defined(__arm__)
- /* It is faster to pass the CPU host model to the appliance,
- * allowing maximum speed for things like checksums, encryption.
- * Only do this with KVM. It is broken in subtle ways on TCG, and
- * fairly pointless anyway.
- */
- if (has_kvm && !force_tcg) {
+ cpu_model = guestfs___get_cpu_model (has_kvm && !force_tcg);
+ if (cpu_model) {
ADD_CMDLINE ("-cpu");
- ADD_CMDLINE ("host");
+ ADD_CMDLINE (cpu_model);
}
-#endif
/* The qemu -machine option (added 2010-12) is a bit more sane
* since it falls back through various different acceleration
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 6ce4361..f86ff74 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -999,6 +999,8 @@ construct_libvirt_xml_cpu (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
+ const char *cpu_model;
+
start_element ("memory") {
attribute ("unit", "MiB");
string_format ("%d", g->memsize);
@@ -1009,21 +1011,25 @@ construct_libvirt_xml_cpu (guestfs_h *g,
string_format ("%d", g->memsize);
} end_element ();
-#if !defined(__arm__)
- /* It is faster to pass the CPU host model to the appliance,
- * allowing maximum speed for things like checksums, encryption.
- * Only do this with KVM. It is broken in subtle ways on TCG, and
- * fairly pointless anyway.
- */
- if (params->data->is_kvm) {
+ cpu_model = guestfs___get_cpu_model (params->data->is_kvm);
+ if (cpu_model) {
start_element ("cpu") {
- attribute ("mode", "host-passthrough");
- start_element ("model") {
- attribute ("fallback", "allow");
- } end_element ();
+ if (STREQ (cpu_model, "host")) {
+ attribute ("mode", "host-passthrough");
+ start_element ("model") {
+ attribute ("fallback", "allow");
+ } end_element ();
+ }
+ else {
+ /* XXX This does not work, see:
+ * https://www.redhat.com/archives/libvirt-users/2014-August/msg00043.html
+ */
+ start_element ("model") {
+ string (cpu_model);
+ } end_element ();
+ }
} end_element ();
}
-#endif
start_element ("vcpu") {
string_format ("%d", g->smp);
diff --git a/src/launch.c b/src/launch.c
index 18c0feb..dba68fd 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -378,6 +378,56 @@ guestfs___appliance_command_line (guestfs_h *g, const char *appliance_dev,
return ret;
}
+/* Return the right CPU model to use as the -cpu parameter or its
+ * equivalent in libvirt. This returns:
+ *
+ * - "host" (means use -cpu host)
+ * - some string such as "cortex-a57" (means use -cpu string)
+ * - NULL (means no -cpu option at all)
+ *
+ * This is made unnecessarily hard and fragile because of two stupid
+ * choices in QEMU:
+ *
+ * (1) The default for qemu-system-aarch64 -M virt is to emulate a
+ * cortex-a15 (WTF?).
+ *
+ * (2) We don't know for sure if KVM will work, but -cpu host is
+ * broken with TCG, so we almost always pass a broken -cpu flag if KVM
+ * is semi-broken in any way.
+ */
+const char *
+guestfs___get_cpu_model (int kvm)
+{
+#if defined(__arm__) /* 32 bit ARM. */
+ return NULL;
+
+#elif defined(__aarch64__)
+ /* With -M virt, the default -cpu is cortex-a15. Stupid. */
+ if (kvm)
+ return "host";
+ else
+ return "cortex-a57";
+
+#elif defined(__i386__) || defined(__x86_64__)
+ /* It is faster to pass the CPU host model to the appliance,
+ * allowing maximum speed for things like checksums, encryption.
+ * Only do this with KVM. It is broken in subtle ways on TCG, and
+ * fairly pointless anyway.
+ */
+ if (kvm)
+ return "host";
+ else
+ return NULL;
+
+#else
+ /* Hope for the best ... */
+ if (kvm)
+ return "host";
+ else
+ return NULL;
+#endif
+}
+
/* glibc documents, but does not actually implement, a 'getumask(3)'
* call. This implements a thread-safe way to get the umask. Note
* this is only called when g->verbose is true and after g->tmpdir
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list