<memorytune vcpus='0-3'>
<node id='0' bandwidth='60'/>
</memorytune>
+ <energytune vcpus='0-3'>
+ <monitor vcpus='0-3'/>
+ </energytune>
</cputune>
...
responsible for making sure the value makes sense on their system and
configuration.
+``energytune`` :since:`Since 12.4.0`
+ Optional ``energytune`` element allows to monitor energy consumption using the
+ resctrl filesystem on the host. Whether or not is this supported can be
+ gathered from capabilities where number of monitors and available features are
+ reported. The required attribute ``vcpus`` specifies to which allocation group
+ this monitor belongs. A vCPU can only be member of one allocation group and monitor
+ group. The ``vcpus`` specified by ``energytune`` can be identical to those
+ specified by ``cachetune`` or ``memorytune``. However they are not allowed to
+ overlap each other. Supported subelements are:
+
+ ``monitor``
+ The optional element ``monitor`` creates the energy monitor for
+ this allocation group and has the following required attribute:
+
+ ``vcpus``
+ vCPU list the monitor applies to.
+
Memory Allocation
-----------------
}
+static int
+virDomainEnergytuneDefParse(virDomainDef *def,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr node,
+ unsigned int flags)
+{
+ VIR_XPATH_NODE_AUTORESTORE(ctxt)
+ virDomainResctrlDef *resctrl = NULL;
+ virDomainResctrlDef *newresctrl = NULL;
+ g_autoptr(virBitmap) vcpus = NULL;
+ g_autoptr(virResctrlAlloc) alloc = NULL;
+ size_t nmons;
+ int ret = -1;
+
+ ctxt->node = node;
+
+ if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0)
+ return -1;
+
+ if (virBitmapIsAllClear(vcpus))
+ return 0;
+
+ if (virDomainResctrlVcpuMatch(def, vcpus, &resctrl) < 0)
+ return -1;
+
+ if (resctrl) {
+ alloc = virObjectRef(resctrl->alloc);
+ } else {
+ if (!(alloc = virResctrlAllocNew()))
+ return -1;
+ if (!(newresctrl = virDomainResctrlNew(node, alloc, vcpus, flags)))
+ return -1;
+ resctrl = newresctrl;
+ }
+
+ nmons = resctrl->nmonitors;
+ if (virDomainResctrlMonDefParse(def, ctxt, node,
+ VIR_RESCTRL_MONITOR_TYPE_ENERGY,
+ resctrl) < 0)
+ goto cleanup;
+
+ if (newresctrl && resctrl->nmonitors > nmons)
+ VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, newresctrl);
+
+ ret = 0;
+ cleanup:
+ virDomainResctrlDefFree(newresctrl);
+ return ret;
+}
+
+
static int
virDomainDefTunablesParse(virDomainDef *def,
xmlXPathContextPtr ctxt,
}
VIR_FREE(nodes);
+ if ((n = virXPathNodeSet("./cputune/energytune", ctxt, &nodes)) < 0)
+ return -1;
+
+ for (i = 0; i < n; i++) {
+ if (virDomainEnergytuneDefParse(def, ctxt, nodes[i], flags) < 0)
+ return -1;
+ }
+ VIR_FREE(nodes);
+
return 0;
}
return 0;
}
+
+static int
+virDomainEnergytuneDefFormat(virBuffer *buf,
+ virDomainResctrlDef *resctrl,
+ unsigned int flags)
+{
+ g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_autofree char *vcpus = NULL;
+ size_t i;
+
+ for (i = 0; i < resctrl->nmonitors; i++) {
+ if (virDomainResctrlMonDefFormatHelper(resctrl->monitors[i],
+ VIR_RESCTRL_MONITOR_TYPE_ENERGY,
+ &childrenBuf) < 0)
+ return -1;
+ }
+
+ if (!virBufferUse(&childrenBuf))
+ return 0;
+
+ vcpus = virBitmapFormat(resctrl->vcpus);
+ virBufferAsprintf(&attrBuf, " vcpus='%s'", vcpus);
+
+ if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) {
+ const char *alloc_id = virResctrlAllocGetID(resctrl->alloc);
+ if (!alloc_id)
+ return -1;
+
+ virBufferAsprintf(&attrBuf, " id='%s'", alloc_id);
+ }
+
+ virXMLFormatElement(buf, "energytune", &attrBuf, &childrenBuf);
+ return 0;
+}
+
static int
virDomainCputuneDefFormat(virBuffer *buf,
virDomainDef *def,
for (i = 0; i < def->nresctrls; i++)
virDomainMemorytuneDefFormat(&childrenBuf, def->resctrls[i], flags);
+ for (i = 0; i < def->nresctrls; i++)
+ virDomainEnergytuneDefFormat(&childrenBuf, def->resctrls[i], flags);
+
virXMLFormatElement(buf, "cputune", NULL, &childrenBuf);
return 0;
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <cputune>
+ <energytune vcpus='0-1'>
+ <monitor vcpus='0-1'/>
+ </energytune>
+ <energytune vcpus='3'>
+ <monitor vcpus='3'/>
+ </energytune>
+ </cputune>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-i386</emulator>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>