mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
conf: create memory bandwidth monitor.
Following domain configuration changes create two memory bandwidth monitors: one is monitoring the bandwidth consumed by vCPU 0, another is for vCPU 5. ``` <cputune> <memorytune vcpus='0-4'> <node id='0' bandwidth='20'/> <node id='1' bandwidth='30'/> + <monitor vcpus='0'/> </memorytune> + <memorytune vcpus='5'> + <monitor vcpus='5'/> + </memorytune> </cputune> ``` Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Huaqiang <huaqiang.wang@intel.com>
This commit is contained in:
parent
1d0c3c3a62
commit
40a070ae01
@ -1023,14 +1023,21 @@
|
|||||||
<ref name='cpuset'/>
|
<ref name='cpuset'/>
|
||||||
</attribute>
|
</attribute>
|
||||||
<oneOrMore>
|
<oneOrMore>
|
||||||
<element name="node">
|
<choice>
|
||||||
<attribute name="id">
|
<element name="node">
|
||||||
<ref name='unsignedInt'/>
|
<attribute name="id">
|
||||||
</attribute>
|
<ref name='unsignedInt'/>
|
||||||
<attribute name="bandwidth">
|
</attribute>
|
||||||
<ref name='unsignedInt'/>
|
<attribute name="bandwidth">
|
||||||
</attribute>
|
<ref name='unsignedInt'/>
|
||||||
</element>
|
</attribute>
|
||||||
|
</element>
|
||||||
|
<element name="monitor">
|
||||||
|
<attribute name="vcpus">
|
||||||
|
<ref name='cpuset'/>
|
||||||
|
</attribute>
|
||||||
|
</element>
|
||||||
|
</choice>
|
||||||
</oneOrMore>
|
</oneOrMore>
|
||||||
</element>
|
</element>
|
||||||
</zeroOrMore>
|
</zeroOrMore>
|
||||||
|
@ -19711,10 +19711,14 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
|
|||||||
{
|
{
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
||||||
virDomainResctrlDefPtr resctrl = NULL;
|
virDomainResctrlDefPtr resctrl = NULL;
|
||||||
|
virDomainResctrlDefPtr newresctrl = NULL;
|
||||||
g_autoptr(virBitmap) vcpus = NULL;
|
g_autoptr(virBitmap) vcpus = NULL;
|
||||||
g_autofree xmlNodePtr *nodes = NULL;
|
g_autofree xmlNodePtr *nodes = NULL;
|
||||||
g_autoptr(virResctrlAlloc) alloc = NULL;
|
g_autoptr(virResctrlAlloc) alloc = NULL;
|
||||||
ssize_t i = 0;
|
ssize_t i = 0;
|
||||||
|
size_t nmons = 0;
|
||||||
|
size_t ret = -1;
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
@ -19741,29 +19745,44 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* First, parse <memorytune/node> element if any <node> element exists */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (virDomainMemorytuneDefParseMemory(ctxt, nodes[i], alloc) < 0)
|
if (virDomainMemorytuneDefParseMemory(ctxt, nodes[i], alloc) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a new allocation, format ID and append to resctrl, otherwise
|
* If this is a new allocation, format ID and append to resctrl, otherwise
|
||||||
* just update the existing alloc information, which is done in above
|
* just update the existing alloc information, which is done in above
|
||||||
* virDomainMemorytuneDefParseMemory */
|
* virDomainMemorytuneDefParseMemory */
|
||||||
if (!resctrl) {
|
if (!resctrl) {
|
||||||
if (!(resctrl = virDomainResctrlNew(node, alloc, vcpus, flags)))
|
if (!(newresctrl = virDomainResctrlNew(node, alloc, vcpus, flags)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, resctrl) < 0) {
|
resctrl = newresctrl;
|
||||||
virDomainResctrlDefFree(resctrl);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* Next, parse <memorytune/monitor> element */
|
||||||
|
nmons = resctrl->nmonitors;
|
||||||
|
if (virDomainResctrlMonDefParse(def, ctxt, node,
|
||||||
|
VIR_RESCTRL_MONITOR_TYPE_MEMBW,
|
||||||
|
resctrl) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
nmons = resctrl->nmonitors - nmons;
|
||||||
|
/* Now @nmons contains the new <monitor> element number found in current
|
||||||
|
* <memorytune> element, and @n holds the number of new <node> element,
|
||||||
|
* only append the new @newresctrl object to domain if any of them is
|
||||||
|
* not zero. */
|
||||||
|
if (newresctrl && (nmons || n)) {
|
||||||
|
if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, newresctrl) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virDomainResctrlDefFree(newresctrl);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27630,12 +27649,19 @@ virDomainMemorytuneDefFormat(virBufferPtr buf,
|
|||||||
{
|
{
|
||||||
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
g_autofree char *vcpus = NULL;
|
g_autofree char *vcpus = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
if (virResctrlAllocForeachMemory(resctrl->alloc,
|
if (virResctrlAllocForeachMemory(resctrl->alloc,
|
||||||
virDomainMemorytuneDefFormatHelper,
|
virDomainMemorytuneDefFormatHelper,
|
||||||
&childrenBuf) < 0)
|
&childrenBuf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i< resctrl->nmonitors; i++) {
|
||||||
|
if (virDomainResctrlMonDefFormatHelper(resctrl->monitors[i],
|
||||||
|
VIR_RESCTRL_MONITOR_TYPE_MEMBW,
|
||||||
|
&childrenBuf) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!virBufferUse(&childrenBuf))
|
if (!virBufferUse(&childrenBuf))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10,12 +10,17 @@
|
|||||||
<cache id='1' level='3' type='both' size='768' unit='KiB'/>
|
<cache id='1' level='3' type='both' size='768' unit='KiB'/>
|
||||||
</cachetune>
|
</cachetune>
|
||||||
<memorytune vcpus='0-1'>
|
<memorytune vcpus='0-1'>
|
||||||
|
<monitor vcpus='0-1'/>
|
||||||
<node id='0' bandwidth='20'/>
|
<node id='0' bandwidth='20'/>
|
||||||
|
<monitor vcpus='0'/>
|
||||||
<node id='1' bandwidth='30'/>
|
<node id='1' bandwidth='30'/>
|
||||||
</memorytune>
|
</memorytune>
|
||||||
<memorytune vcpus='3'>
|
<memorytune vcpus='3'>
|
||||||
<node id='0' bandwidth='50'/>
|
<node id='0' bandwidth='50'/>
|
||||||
</memorytune>
|
</memorytune>
|
||||||
|
<memorytune vcpus='2'>
|
||||||
|
<monitor vcpus='2'/>
|
||||||
|
</memorytune>
|
||||||
</cputune>
|
</cputune>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc'>hvm</type>
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
42
tests/genericxml2xmloutdata/memorytune.xml
Normal file
42
tests/genericxml2xmloutdata/memorytune.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<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>
|
||||||
|
<cachetune vcpus='0-1'>
|
||||||
|
<cache id='0' level='3' type='both' size='768' unit='KiB'/>
|
||||||
|
<cache id='1' level='3' type='both' size='768' unit='KiB'/>
|
||||||
|
</cachetune>
|
||||||
|
<memorytune vcpus='0-1'>
|
||||||
|
<node id='0' bandwidth='20'/>
|
||||||
|
<node id='1' bandwidth='30'/>
|
||||||
|
<monitor vcpus='0-1'/>
|
||||||
|
<monitor vcpus='0'/>
|
||||||
|
</memorytune>
|
||||||
|
<memorytune vcpus='3'>
|
||||||
|
<node id='0' bandwidth='50'/>
|
||||||
|
</memorytune>
|
||||||
|
<memorytune vcpus='2'>
|
||||||
|
<monitor vcpus='2'/>
|
||||||
|
</memorytune>
|
||||||
|
</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-i686</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>
|
@ -173,7 +173,7 @@ mymain(void)
|
|||||||
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
||||||
DO_TEST_FULL("cachetune-colliding-monitor", false, true,
|
DO_TEST_FULL("cachetune-colliding-monitor", false, true,
|
||||||
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
||||||
DO_TEST("memorytune");
|
DO_TEST_DIFFERENT("memorytune");
|
||||||
DO_TEST_FULL("memorytune-colliding-allocs", false, true,
|
DO_TEST_FULL("memorytune-colliding-allocs", false, true,
|
||||||
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
|
||||||
DO_TEST_FULL("memorytune-colliding-cachetune", false, true,
|
DO_TEST_FULL("memorytune-colliding-cachetune", false, true,
|
||||||
|
Loading…
Reference in New Issue
Block a user