[libvirt] [PATCH 11/24] qemu: Add APIs for translating CPU features

Jiri Denemark posted 24 patches 6 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 11/24] qemu: Add APIs for translating CPU features
Posted by Jiri Denemark 6 years, 7 months ago
So far we always used libvirt's name of each CPU feature relying on
backward compatible aliases in QEMU. The new translation table can be
used whenever QEMU mandates or prefers canonical feature names.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_capabilities.c | 64 ++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_capabilities.h |  8 +++++
 2 files changed, 72 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5f989a2613..712933c13a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2848,6 +2848,70 @@ virQEMUCapsCPUFilterFeatures(const char *name,
 }
 
 
+typedef struct _virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeatureTranslationTable;
+typedef virQEMUCapsCPUFeatureTranslationTable *virQEMUCapsCPUFeatureTranslationTablePtr;
+struct _virQEMUCapsCPUFeatureTranslationTable {
+    const char *libvirt;
+    const char *qemu;
+};
+
+virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeaturesX86[] = {
+    {"cmp_legacy", "cmp-legacy"},
+    {"ds_cpl", "ds-cpl"},
+    {"fxsr_opt", "fxsr-opt"},
+    {"kvm_pv_eoi", "kvm-pv-eoi"},
+    {"kvm_pv_unhalt", "kvm-pv-unhalt"},
+    {"lahf_lm", "lahf-lm"},
+    {"nodeid_msr", "nodeid-msr"},
+    {"pclmuldq", "pclmulqdq"},
+    {"perfctr_core", "perfctr-core"},
+    {"perfctr_nb", "perfctr-nb"},
+    {"tsc_adjust", "tsc-adjust"},
+    {NULL, NULL}
+};
+
+
+static const char *
+virQEMUCapsCPUFeatureTranslate(virQEMUCapsPtr qemuCaps,
+                               const char *feature,
+                               bool reversed)
+{
+    virQEMUCapsCPUFeatureTranslationTablePtr table = NULL;
+    virQEMUCapsCPUFeatureTranslationTablePtr entry;
+
+    if (ARCH_IS_X86(qemuCaps->arch))
+        table = virQEMUCapsCPUFeaturesX86;
+
+    if (!table || !feature)
+        return feature;
+
+    for (entry = table; entry->libvirt; entry++) {
+        const char *key = reversed ? entry->qemu : entry->libvirt;
+
+        if (STREQ(feature, key))
+            return reversed ? entry->libvirt : entry->qemu;
+    }
+
+    return feature;
+}
+
+
+const char *
+virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
+                            const char *feature)
+{
+    return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, false);
+}
+
+
+const char *
+virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
+                              const char *feature)
+{
+    return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, true);
+}
+
+
 /**
  * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
  *          1 when the caller should fall back to using virCapsPtr->host.cpu,
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 3032d4edcd..685a77a8b0 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -646,6 +646,14 @@ bool virQEMUCapsGuestIsNative(virArch host,
 bool virQEMUCapsCPUFilterFeatures(const char *name,
                                   void *opaque);
 
+const char *
+virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
+                            const char *feature);
+
+const char *
+virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
+                              const char *feature);
+
 virSEVCapabilityPtr
 virQEMUCapsGetSEVCapabilities(virQEMUCapsPtr qemuCaps);
 
-- 
2.22.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/24] qemu: Add APIs for translating CPU features
Posted by Ján Tomko 6 years, 7 months ago
On Wed, Jun 19, 2019 at 11:38:08AM +0200, Jiri Denemark wrote:
>So far we always used libvirt's name of each CPU feature relying on
>backward compatible aliases in QEMU. The new translation table can be
>used whenever QEMU mandates or prefers canonical feature names.
>
>Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
>---
> src/qemu/qemu_capabilities.c | 64 ++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_capabilities.h |  8 +++++
> 2 files changed, 72 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list