Re: [PATCH 2/2] qemu: Generate command line for tb-cache feature

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

 



On Thu, Nov 04, 2021 at 01:22:53PM +0100, Michal Privoznik wrote:
> Alright, here's the deal: to enable tb-cache one has to use
> '-accel tcg,tb-size=' which then conflicts with '-machine
> accel=tcg'. But sure, we can use the old -accel in this specific
> case. But because of how the tb-size argument is defined in QEMU
> there's no way for us to have a capability check. The feature was
> introduced in QEMU commit of v5.0.0-rc0~175^2~62 and is tied to
> TCG only. Therefore, I think we can live without capability
> check. Worst case scenario, QEMU fails to start.
> 
> Resolves: https://gitlab.com/libvirt/libvirt/-/issues/229
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/qemu/qemu_command.c                       | 14 ++++++-
>  ...efault-cpu-tcg-features.x86_64-latest.args | 40 +++++++++++++++++++
>  tests/qemuxml2argvtest.c                      |  1 +
>  3 files changed, 54 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.x86_64-latest.args
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 45278c7108..7d9cb386fd 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -7031,14 +7031,21 @@ qemuBuildMachineCommandLine(virCommand *cmd,
>      virTristateSwitch smm = def->features[VIR_DOMAIN_FEATURE_SMM];
>      virCPUDef *cpu = def->cpu;
>      g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
> +    unsigned long long tb_cache = 0;
>      size_t i;
>  
> +    if (def->features[VIR_DOMAIN_FEATURE_TCG] == VIR_TRISTATE_SWITCH_ON)
> +        tb_cache = def->tcg_features->tb_cache;
> +
>      virCommandAddArg(cmd, "-machine");
>      virBufferAdd(&buf, def->os.machine, -1);
>  
>      switch ((virDomainVirtType)def->virtType) {
>      case VIR_DOMAIN_VIRT_QEMU:
> -        virBufferAddLit(&buf, ",accel=tcg");
> +        /* Unfortunately, -machine doesn't accept -accel arguments and the two
> +         * are mutually exclusive. Don't output accel= if we need -accel. */
> +        if (tb_cache == 0)
> +            virBufferAddLit(&buf, ",accel=tcg");

The "-machine accel=nnn" syntax was the original way to configure accelerator.

The "-accel nnn,$opts" syntax was added in QEMU 2.9.0 with

  commit 8d4e9146b3568022ea5730d92841345d41275d66
  Author: KONRAD Frederic <fred.konrad@xxxxxxxxxxxxx>
  Date:   Thu Feb 23 18:29:08 2017 +0000

    tcg: add options for enabling MTTCG

with the accelerator name being sugar for "-machine accel=nnn".

Then in 5.0.0, this was reversed so that '-machine accel=nnn' is
now sugar for '-accel nnn'

  commit 6f6e1698a68ceb49e57676528612f22eaf2c16c3
  Author: Paolo Bonzini <pbonzini@xxxxxxxxxx>
  Date:   Wed Nov 13 10:10:47 2019 +0100

    vl: configure accelerators from -accel options

IOW, long term we want to be using -accel exclusively.

Given our minimum QEMU 2.11.0, we can in fact use -accel
exclusively already AFAICT.

That would simplify this patch so that we're not supporting
distinct syntax with tb_cache.

>          break;
>  
>      case VIR_DOMAIN_VIRT_KVM:
> @@ -7288,6 +7295,11 @@ qemuBuildMachineCommandLine(virCommand *cmd,
>  
>      virCommandAddArgBuffer(cmd, &buf);
>  
> +    if (tb_cache > 0) {
> +        virCommandAddArg(cmd, "-accel");
> +        virCommandAddArgFormat(cmd, "tcg,tb-size=%llu", tb_cache >> 10);
> +    }
> +
>      return 0;
>  }
>  
> diff --git a/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.x86_64-latest.args b/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.x86_64-latest.args
> new file mode 100644
> index 0000000000..0800ea4294
> --- /dev/null
> +++ b/tests/qemuxml2argvdata/x86_64-default-cpu-tcg-features.x86_64-latest.args
> @@ -0,0 +1,40 @@
> +LC_ALL=C \
> +PATH=/bin \
> +HOME=/tmp/lib/domain--1-guest \
> +USER=test \
> +LOGNAME=test \
> +XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
> +XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
> +XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
> +/usr/bin/qemu-system-x86_64 \
> +-name guest=guest,debug-threads=on \
> +-S \
> +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-guest/master-key.aes"}' \
> +-machine pc-q35-6.2,usb=off,dump-guest-core=off,memory-backend=pc.ram \
> +-accel tcg,tb-size=100 \
> +-cpu qemu64 \
> +-m 4096 \
> +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":4294967296}' \
> +-overcommit mem-lock=off \
> +-smp 4,sockets=4,cores=1,threads=1 \
> +-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
> +-display none \
> +-no-user-config \
> +-nodefaults \
> +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
> +-mon chardev=charmonitor,id=monitor,mode=control \
> +-rtc base=utc \
> +-no-shutdown \
> +-boot strict=on \
> +-device '{"driver":"pcie-root-port","port":8,"chassis":1,"id":"pci.1","bus":"pcie.0","multifunction":true,"addr":"0x1"}' \
> +-device '{"driver":"pcie-root-port","port":9,"chassis":2,"id":"pci.2","bus":"pcie.0","addr":"0x1.0x1"}' \
> +-device '{"driver":"pcie-root-port","port":10,"chassis":3,"id":"pci.3","bus":"pcie.0","addr":"0x1.0x2"}' \
> +-device '{"driver":"pcie-root-port","port":11,"chassis":4,"id":"pci.4","bus":"pcie.0","addr":"0x1.0x3"}' \
> +-device '{"driver":"qemu-xhci","id":"usb","bus":"pci.1","addr":"0x0"}' \
> +-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/guest.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
> +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2","file":"libvirt-1-storage"}' \
> +-device '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-1-format","id":"virtio-disk0","bootindex":1}' \
> +-audiodev id=audio1,driver=none \
> +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.3","addr":"0x0"}' \
> +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
> +-msg timestamp=on
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index 1c59395203..56ecc46071 100644
> --- a/tests/qemuxml2argvtest.c
> +++ b/tests/qemuxml2argvtest.c
> @@ -3422,6 +3422,7 @@ mymain(void)
>      DO_TEST_CAPS_ARCH_LATEST("x86_64-default-cpu-tcg-pc-4.2", "x86_64");
>      DO_TEST_CAPS_ARCH_LATEST("x86_64-default-cpu-kvm-q35-4.2", "x86_64");
>      DO_TEST_CAPS_ARCH_LATEST("x86_64-default-cpu-tcg-q35-4.2", "x86_64");
> +    DO_TEST_CAPS_ARCH_LATEST("x86_64-default-cpu-tcg-features", "x86_64");
>  
>      DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
>      DO_TEST_CAPS_LATEST("virtio-9p-createmode");
> -- 
> 2.32.0
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




[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]

  Powered by Linux