conf: Refactor cache bank capability structure

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@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Wang Huaqiang 2018-09-20 18:10:48 +08:00 committed by John Ferlan
parent 12093f1fea
commit 58fcee6f3a
2 changed files with 25 additions and 21 deletions

View File

@ -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;

View File

@ -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;