Re: [PATCHv2 18/23] qemu: Add monitor APIs to fetch CPUID data from QEMU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 15, 2013 at 02:30:47PM +0200, Peter Krempa wrote:
> From: Jiri Denemark <jdenemar@xxxxxxxxxx>
> 
> The qemu monitor supports retrieval of actual CPUID bits presented to
> the guest using QMP monitor. Add APIs to extract these information and
> tests for them.
> 
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/qemu/qemu_monitor.c                            |  21 ++++
>  src/qemu/qemu_monitor.h                            |   3 +
>  src/qemu/qemu_monitor_json.c                       | 107 +++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h                       |   3 +
>  tests/Makefile.am                                  |   1 +
>  .../qemumonitorjson-getcpu-empty.data              |   2 +
>  .../qemumonitorjson-getcpu-empty.json              |  46 +++++++++
>  .../qemumonitorjson-getcpu-filtered.data           |   4 +
>  .../qemumonitorjson-getcpu-filtered.json           |  46 +++++++++
>  .../qemumonitorjson-getcpu-full.data               |   5 +
>  .../qemumonitorjson-getcpu-full.json               |  46 +++++++++
>  .../qemumonitorjson-getcpu-host.data               |   6 ++
>  .../qemumonitorjson-getcpu-host.json               |  45 +++++++++
>  tests/qemumonitorjsontest.c                        |  76 +++++++++++++++
>  14 files changed, 411 insertions(+)
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.data
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-empty.json
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.data
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-filtered.json
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.data
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-full.json
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.data
>  create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-getcpu-host.json
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 2bafe28..f1556d8 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3926,3 +3926,24 @@ qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd)
> 
>      return 0;
>  }
> +
> +
> +virCPUDataPtr
> +qemuMonitorGetGuestCPU(qemuMonitorPtr mon)
> +{
> +    VIR_DEBUG("mon=%p", mon);
> +
> +    if (!mon) {
> +        virReportError(VIR_ERR_INVALID_ARG, "%s",
> +                       _("monitor must not be NULL"));
> +        return NULL;
> +    }
> +
> +    if (!mon->json) {
> +        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> +                       _("JSON monitor is required"));
> +        return NULL;
> +    }
> +
> +    return qemuMonitorJSONGetCPUData(mon, "feature-words");
> +}

Normal practice is to have the JSON API signature match
the main monitor API signature.

AFAICT this patch doesn't need the ability to pass in
different strings here, except from the test suite. I
don't see much point in testing stuff we don't use in
the main API. So I'd just hardcode "feature-words" in
the qemuMonitorJSONGetCPUData method.


> +
> +
> +static int
> +qemuMonitorJSONParseCPUFeatureWord(virJSONValuePtr data,
> +                                   virCPUx86CPUID *cpuid)
> +{
> +    const char *reg;
> +    unsigned long long fun;
> +    unsigned long long features;
> +
> +    memset(cpuid, 0, sizeof(*cpuid));
> +
> +    if (!(reg = virJSONValueObjectGetString(data, "cpuid-register"))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("missing cpuid-register in CPU data"));
> +        return -1;
> +    }
> +    if (virJSONValueObjectGetNumberUlong(data, "cpuid-input-eax", &fun)) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("missing or invalid cpuid-input-eax in CPU data"));
> +        return -1;
> +    }
> +    if (virJSONValueObjectGetNumberUlong(data, "features", &features) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("missing or invalid features in CPU data"));
> +        return -1;
> +    }
> +
> +    cpuid->function = fun;
> +    if (STREQ(reg, "EAX")) {
> +        cpuid->eax = features;
> +    } else if (STREQ(reg, "EBX")) {
> +        cpuid->ebx = features;
> +    } else if (STREQ(reg, "ECX")) {
> +        cpuid->ecx = features;
> +    } else if (STREQ(reg, "EDX")) {
> +        cpuid->edx = features;
> +    } else {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("unknown CPU register '%s'"), reg);
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +virCPUDataPtr
> +qemuMonitorJSONGetCPUData(qemuMonitorPtr mon,
> +                          const char *property)
> +{
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +    virJSONValuePtr data;
> +    virCPUDataPtr cpuData = NULL;
> +    virCPUx86Data *x86Data = NULL;
> +    virCPUx86CPUID cpuid;


Broken with non-x86 QEMU's

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]