conf: Refactor memory bandwidth capability structure

Move memory bandwidth capability nodes into one data structure,
this allows us to add a monitor for memory bandwidth.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Wang Huaqiang 2018-09-20 18:10:49 +08:00 committed by John Ferlan
parent 58fcee6f3a
commit 8f6887998b
2 changed files with 18 additions and 14 deletions

View File

@ -245,9 +245,9 @@ virCapsDispose(void *object)
virCapsHostCacheBankFree(caps->host.cache.banks[i]); virCapsHostCacheBankFree(caps->host.cache.banks[i]);
VIR_FREE(caps->host.cache.banks); VIR_FREE(caps->host.cache.banks);
for (i = 0; i < caps->host.nnodes; i++) for (i = 0; i < caps->host.memBW.nnodes; i++)
virCapsHostMemBWNodeFree(caps->host.nodes[i]); virCapsHostMemBWNodeFree(caps->host.memBW.nodes[i]);
VIR_FREE(caps->host.nodes); VIR_FREE(caps->host.memBW.nodes);
VIR_FREE(caps->host.netprefix); VIR_FREE(caps->host.netprefix);
VIR_FREE(caps->host.pagesSize); VIR_FREE(caps->host.pagesSize);
@ -957,20 +957,19 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
static int static int
virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf,
size_t nnodes, virCapsHostMemBWPtr memBW)
virCapsHostMemBWNodePtr *nodes)
{ {
size_t i = 0; size_t i = 0;
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
if (!nnodes) if (!memBW->nnodes)
return 0; return 0;
virBufferAddLit(buf, "<memory_bandwidth>\n"); virBufferAddLit(buf, "<memory_bandwidth>\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
for (i = 0; i < nnodes; i++) { for (i = 0; i < memBW->nnodes; i++) {
virCapsHostMemBWNodePtr node = nodes[i]; virCapsHostMemBWNodePtr node = memBW->nodes[i];
virResctrlInfoMemBWPerNodePtr control = &node->control; virResctrlInfoMemBWPerNodePtr control = &node->control;
char *cpus_str = virBitmapFormat(node->cpus); char *cpus_str = virBitmapFormat(node->cpus);
@ -1109,8 +1108,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
if (virCapabilitiesFormatCaches(&buf, &caps->host.cache) < 0) if (virCapabilitiesFormatCaches(&buf, &caps->host.cache) < 0)
goto error; goto error;
if (virCapabilitiesFormatMemoryBandwidth(&buf, caps->host.nnodes, if (virCapabilitiesFormatMemoryBandwidth(&buf, &caps->host.memBW) < 0)
caps->host.nodes) < 0)
goto error; goto error;
for (i = 0; i < caps->host.nsecModels; i++) { for (i = 0; i < caps->host.nsecModels; i++) {
@ -1673,8 +1671,8 @@ virCapabilitiesInitResctrlMemory(virCapsPtr caps)
if (!(node->cpus = virBitmapNewCopy(bank->cpus))) if (!(node->cpus = virBitmapNewCopy(bank->cpus)))
goto cleanup; goto cleanup;
if (VIR_APPEND_ELEMENT(caps->host.nodes, if (VIR_APPEND_ELEMENT(caps->host.memBW.nodes,
caps->host.nnodes, node) < 0) { caps->host.memBW.nnodes, node) < 0) {
goto cleanup; goto cleanup;
} }
} }

View File

@ -166,6 +166,13 @@ struct _virCapsHostMemBWNode {
virResctrlInfoMemBWPerNode control; virResctrlInfoMemBWPerNode control;
}; };
typedef struct _virCapsHostMemBW virCapsHostMemBW;
typedef virCapsHostMemBW *virCapsHostMemBWPtr;
struct _virCapsHostMemBW {
size_t nnodes;
virCapsHostMemBWNodePtr *nodes;
};
typedef struct _virCapsHost virCapsHost; typedef struct _virCapsHost virCapsHost;
typedef virCapsHost *virCapsHostPtr; typedef virCapsHost *virCapsHostPtr;
struct _virCapsHost { struct _virCapsHost {
@ -189,8 +196,7 @@ struct _virCapsHost {
virCapsHostCache cache; virCapsHostCache cache;
size_t nnodes; virCapsHostMemBW memBW;
virCapsHostMemBWNodePtr *nodes;
size_t nsecModels; size_t nsecModels;
virCapsHostSecModelPtr secModels; virCapsHostSecModelPtr secModels;