提交 63d95a19 编写于 作者: M Martin Kletzander

conf: Format cache banks in capabilities with virFormatIntPretty

Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 b4698edc
...@@ -883,7 +883,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf, ...@@ -883,7 +883,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
for (i = 0; i < ncaches; i++) { for (i = 0; i < ncaches; i++) {
virCapsHostCacheBankPtr bank = caches[i]; virCapsHostCacheBankPtr bank = caches[i];
char *cpus_str = virBitmapFormat(bank->cpus); char *cpus_str = virBitmapFormat(bank->cpus);
bool kilos = !(bank->size % 1024); const char *unit = NULL;
unsigned long long short_size = virFormatIntPretty(bank->size, &unit);
if (!cpus_str) if (!cpus_str)
return -1; return -1;
...@@ -897,34 +898,47 @@ virCapabilitiesFormatCaches(virBufferPtr buf, ...@@ -897,34 +898,47 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
"size='%llu' unit='%s' cpus='%s'", "size='%llu' unit='%s' cpus='%s'",
bank->id, bank->level, bank->id, bank->level,
virCacheTypeToString(bank->type), virCacheTypeToString(bank->type),
bank->size >> (kilos * 10), short_size, unit, cpus_str);
kilos ? "KiB" : "B",
cpus_str);
VIR_FREE(cpus_str); VIR_FREE(cpus_str);
virBufferSetChildIndent(&controlBuf, buf); virBufferSetChildIndent(&controlBuf, buf);
for (j = 0; j < bank->ncontrols; j++) { for (j = 0; j < bank->ncontrols; j++) {
bool min_kilos = !(bank->controls[j]->granularity % 1024); const char *min_unit;
virResctrlInfoPtr controls = bank->controls[j];
unsigned long long gran_short_size = controls->granularity;
unsigned long long min_short_size = controls->min;
/* Only use KiB if both values are divisible */ gran_short_size = virFormatIntPretty(gran_short_size, &unit);
if (bank->controls[j]->min) min_short_size = virFormatIntPretty(min_short_size, &min_unit);
min_kilos = min_kilos && !(bank->controls[j]->min % 1024);
/* Only use the smaller unit if they are different */
if (min_short_size) {
unsigned long long gran_div;
unsigned long long min_div;
gran_div = controls->granularity / gran_short_size;
min_div = controls->min / min_short_size;
if (min_div > gran_div) {
min_short_size *= min_div / gran_div;
} else if (min_div < gran_div) {
unit = min_unit;
gran_short_size *= gran_div / min_div;
}
}
virBufferAsprintf(&controlBuf, virBufferAsprintf(&controlBuf,
"<control granularity='%llu'", "<control granularity='%llu'",
bank->controls[j]->granularity >> (min_kilos * 10)); gran_short_size);
if (bank->controls[j]->min) { if (min_short_size)
virBufferAsprintf(&controlBuf, virBufferAsprintf(&controlBuf, " min='%llu'", min_short_size);
" min='%llu'",
bank->controls[j]->min >> (min_kilos * 10));
}
virBufferAsprintf(&controlBuf, virBufferAsprintf(&controlBuf,
" unit='%s' type='%s' maxAllocs='%u'/>\n", " unit='%s' type='%s' maxAllocs='%u'/>\n",
min_kilos ? "KiB" : "B", unit,
virCacheTypeToString(bank->controls[j]->scope), virCacheTypeToString(controls->scope),
bank->controls[j]->max_allocation); controls->max_allocation);
} }
if (virBufferCheckError(&controlBuf) < 0) if (virBufferCheckError(&controlBuf) < 0)
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
</cells> </cells>
</topology> </topology>
<cache> <cache>
<bank id='0' level='3' type='both' size='8192' unit='KiB' cpus='0-7'/> <bank id='0' level='3' type='both' size='8' unit='MiB' cpus='0-7'/>
</cache> </cache>
</host> </host>
......
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
</cells> </cells>
</topology> </topology>
<cache> <cache>
<bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'> <bank id='0' level='3' type='both' size='15' unit='MiB' cpus='0-5'>
<control granularity='768' unit='KiB' type='code' maxAllocs='8'/> <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
<control granularity='768' unit='KiB' type='data' maxAllocs='8'/> <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
</bank> </bank>
<bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'> <bank id='1' level='3' type='both' size='15' unit='MiB' cpus='6-11'>
<control granularity='768' unit='KiB' type='code' maxAllocs='8'/> <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
<control granularity='768' unit='KiB' type='data' maxAllocs='8'/> <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
</bank> </bank>
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
</cells> </cells>
</topology> </topology>
<cache> <cache>
<bank id='0' level='3' type='both' size='33792' unit='KiB' cpus='0'> <bank id='0' level='3' type='both' size='33' unit='MiB' cpus='0'>
<control granularity='3072' unit='KiB' type='both' maxAllocs='16'/> <control granularity='3' unit='MiB' type='both' maxAllocs='16'/>
</bank> </bank>
</cache> </cache>
</host> </host>
......
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
</cells> </cells>
</topology> </topology>
<cache> <cache>
<bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'> <bank id='0' level='3' type='both' size='15' unit='MiB' cpus='0-5'>
<control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/> <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
</bank> </bank>
<bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'> <bank id='1' level='3' type='both' size='15' unit='MiB' cpus='6-11'>
<control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/> <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
</bank> </bank>
</cache> </cache>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册