[libvirt] [PATCH 5/5] qemu: Add support for setting the TSEG size
Martin Kletzander
mkletzan at redhat.com
Thu May 31 00:29:55 UTC 2018
On Wed, May 30, 2018 at 11:58:54PM +0200, Martin Kletzander wrote:
>On Wed, May 30, 2018 at 08:01:10PM +0200, Ján Tomko wrote:
>>On Mon, May 21, 2018 at 05:00:53PM +0200, Martin Kletzander wrote:
>>>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1469338
>>>
>>>Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
>>>---
>>> src/qemu/qemu_command.c | 18 ++++
>>> src/qemu/qemu_domain.c | 84 +++++++++++++++++++
>>> .../qemuxml2argvdata/tseg-explicit-size.args | 28 +++++++
>>> tests/qemuxml2argvdata/tseg-explicit-size.xml | 23 +++++
>>> tests/qemuxml2argvdata/tseg-i440fx.xml | 23 +++++
>>> tests/qemuxml2argvdata/tseg-invalid-size.xml | 23 +++++
>>> .../tseg-old-machine-type.args | 27 ++++++
>>> .../tseg-old-machine-type.xml | 21 +++++
>>> tests/qemuxml2argvdata/tseg.args | 28 +++++++
>>> tests/qemuxml2argvdata/tseg.xml | 21 +++++
>>> tests/qemuxml2argvtest.c | 48 +++++++++++
>>> .../qemuxml2xmloutdata/tseg-explicit-size.xml | 46 ++++++++++
>>> .../tseg-old-machine-type.xml | 44 ++++++++++
>>> tests/qemuxml2xmloutdata/tseg.xml | 46 ++++++++++
>>> tests/qemuxml2xmltest.c | 25 ++++++
>>> 15 files changed, 505 insertions(+)
>>> create mode 100644 tests/qemuxml2argvdata/tseg-explicit-size.args
>>> create mode 100644 tests/qemuxml2argvdata/tseg-explicit-size.xml
>>> create mode 100644 tests/qemuxml2argvdata/tseg-i440fx.xml
>>> create mode 100644 tests/qemuxml2argvdata/tseg-invalid-size.xml
>>> create mode 100644 tests/qemuxml2argvdata/tseg-old-machine-type.args
>>> create mode 100644 tests/qemuxml2argvdata/tseg-old-machine-type.xml
>>> create mode 100644 tests/qemuxml2argvdata/tseg.args
>>> create mode 100644 tests/qemuxml2argvdata/tseg.xml
>>> create mode 100644 tests/qemuxml2xmloutdata/tseg-explicit-size.xml
>>> create mode 100644 tests/qemuxml2xmloutdata/tseg-old-machine-type.xml
>>> create mode 100644 tests/qemuxml2xmloutdata/tseg.xml
>>>
>>
>>>diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>>>index 881d0ea46a75..3ea9e3d47344 100644
>>>--- a/src/qemu/qemu_domain.c
>>>+++ b/src/qemu/qemu_domain.c
>>>@@ -3319,6 +3319,87 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def)
[...]
>>>+static int
>>>+qemuDomainDefTsegPostParse(virDomainDefPtr def,
>>>+ virQEMUCapsPtr qemuCaps)
>>>+{
>>>+ if (def->features[VIR_DOMAIN_FEATURE_SMM] != VIR_TRISTATE_SWITCH_ON)
>>>+ return 0;
>>>+
>>>+ if (!def->tseg_size)
>>>+ return qemuDomainSetDefaultTsegSize(def, qemuCaps);
>>>+
>>>+ if (!qemuDomainIsQ35(def)) {
>>>+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>>+ _("SMM TSEG is only supported with q35 machine type"));
>>>+ return -1;
>>>+ }
>>>+
>>>+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MCH_EXTENDED_TSEG_MBYTES)) {
>>>+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>>+ _("Setting TSEG size is not supported with this QEMU binary"));
>>>+ return -1;
>>>+ }
>>>+
>>>+ if (VIR_ROUND_UP(def->tseg_size, 1024 * 1024) != def->tseg_size) {
>>
>>Interesting way of writing the % operator.
>>
More like very interesting brainfart [1] I had there. I mean I almost open-coded
the VIR_ROUND_UP at first and haven't even thought about anything else. Wow.
Actually, in the resulting assembly (comparing -O2) it both streches across 5
lines that are very weirdly different/similar. What's way faster is:
if (def->tseg_size & ((1<<20) - 1))
which just expands to
xorl %eax, %eax
andl $1048575, %edi
and to make it even more confusing, the previous two approaches share the `andl`
line with this one. Scary.
[1] And that's very weak word for this particular "thing".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180531/839b8b30/attachment-0001.sig>
More information about the libvir-list
mailing list