Move all cache banks into one data structure, this allows
us to add other cache component, such as cache monitor.
Signed-off-by: Wang Huaqiang <huaqiang.wang(a)intel.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/capabilities.c | 36 +++++++++++++++++-------------------
src/conf/capabilities.h | 10 ++++++++--
2 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 0d11fbd..fbaef13 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -241,9 +241,9 @@ virCapsDispose(void *object)
virCapabilitiesClearSecModel(&caps->host.secModels[i]);
VIR_FREE(caps->host.secModels);
- for (i = 0; i < caps->host.ncaches; i++)
- virCapsHostCacheBankFree(caps->host.caches[i]);
- VIR_FREE(caps->host.caches);
+ for (i = 0; i < caps->host.cache.nbanks; i++)
+ virCapsHostCacheBankFree(caps->host.cache.banks[i]);
+ VIR_FREE(caps->host.cache.banks);
for (i = 0; i < caps->host.nnodes; i++)
virCapsHostMemBWNodeFree(caps->host.nodes[i]);
@@ -864,21 +864,20 @@ virCapabilitiesFormatNUMATopology(virBufferPtr buf,
static int
virCapabilitiesFormatCaches(virBufferPtr buf,
- size_t ncaches,
- virCapsHostCacheBankPtr *caches)
+ virCapsHostCachePtr cache)
{
size_t i = 0;
size_t j = 0;
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
- if (!ncaches)
+ if (!cache->nbanks)
return 0;
virBufferAddLit(buf, "<cache>\n");
virBufferAdjustIndent(buf, 2);
- for (i = 0; i < ncaches; i++) {
- virCapsHostCacheBankPtr bank = caches[i];
+ for (i = 0; i < cache->nbanks; i++) {
+ virCapsHostCacheBankPtr bank = cache->banks[i];
char *cpus_str = virBitmapFormat(bank->cpus);
const char *unit = NULL;
unsigned long long short_size = virFormatIntPretty(bank->size, &unit);
@@ -1107,8 +1106,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
caps->host.numaCell) < 0)
goto error;
- if (virCapabilitiesFormatCaches(&buf, caps->host.ncaches,
- caps->host.caches) < 0)
+ if (virCapabilitiesFormatCaches(&buf, &caps->host.cache) < 0)
goto error;
if (virCapabilitiesFormatMemoryBandwidth(&buf, caps->host.nnodes,
@@ -1664,8 +1662,8 @@ virCapabilitiesInitResctrlMemory(virCapsPtr caps)
size_t i = 0;
int ret = -1;
- for (i = 0; i < caps->host.ncaches; i++) {
- virCapsHostCacheBankPtr bank = caps->host.caches[i];
+ for (i = 0; i < caps->host.cache.nbanks; i++) {
+ virCapsHostCacheBankPtr bank = caps->host.cache.banks[i];
if (VIR_ALLOC(node) < 0)
goto cleanup;
@@ -1787,11 +1785,11 @@ virCapabilitiesInitCaches(virCapsPtr caps)
bank->type = kernel_type;
VIR_FREE(type);
- for (i = 0; i < caps->host.ncaches; i++) {
- if (virCapsHostCacheBankEquals(bank, caps->host.caches[i]))
+ for (i = 0; i < caps->host.cache.nbanks; i++) {
+ if (virCapsHostCacheBankEquals(bank, caps->host.cache.banks[i]))
break;
}
- if (i == caps->host.ncaches) {
+ if (i == caps->host.cache.nbanks) {
/* If it is a new cache, then update its resctrl information. */
if (virResctrlInfoGetCache(caps->host.resctrl,
bank->level,
@@ -1800,8 +1798,8 @@ virCapabilitiesInitCaches(virCapsPtr caps)
&bank->controls) < 0)
goto cleanup;
- if (VIR_APPEND_ELEMENT(caps->host.caches,
- caps->host.ncaches,
+ if (VIR_APPEND_ELEMENT(caps->host.cache.banks,
+ caps->host.cache.nbanks,
bank) < 0) {
goto cleanup;
}
@@ -1817,8 +1815,8 @@ virCapabilitiesInitCaches(virCapsPtr caps)
/* Sort the array in order for the tests to be predictable. This way we can
* still traverse the directory instead of guessing names (in case there is
* 'index1' and 'index3' but no 'index2'). */
- qsort(caps->host.caches, caps->host.ncaches,
- sizeof(*caps->host.caches), virCapsHostCacheBankSorter);
+ qsort(caps->host.cache.banks, caps->host.cache.nbanks,
+ sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter);
if (virCapabilitiesInitResctrlMemory(caps) < 0)
goto cleanup;
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 046e275..744074b 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -151,6 +151,13 @@ struct _virCapsHostCacheBank {
virResctrlInfoPerCachePtr *controls;
};
+typedef struct _virCapsHostCache virCapsHostCache;
+typedef virCapsHostCache *virCapsHostCachePtr;
+struct _virCapsHostCache {
+ size_t nbanks;
+ virCapsHostCacheBankPtr *banks;
+};
+
typedef struct _virCapsHostMemBWNode virCapsHostMemBWNode;
typedef virCapsHostMemBWNode *virCapsHostMemBWNodePtr;
struct _virCapsHostMemBWNode {
@@ -180,8 +187,7 @@ struct _virCapsHost {
virResctrlInfoPtr resctrl;
- size_t ncaches;
- virCapsHostCacheBankPtr *caches;
+ virCapsHostCache cache;
size_t nnodes;
virCapsHostMemBWNodePtr *nodes;
--
2.7.4