提交 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,
for (i = 0; i < ncaches; i++) {
virCapsHostCacheBankPtr bank = caches[i];
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)
return -1;
......@@ -897,34 +898,47 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
"size='%llu' unit='%s' cpus='%s'",
bank->id, bank->level,
virCacheTypeToString(bank->type),
bank->size >> (kilos * 10),
kilos ? "KiB" : "B",
cpus_str);
short_size, unit, cpus_str);
VIR_FREE(cpus_str);
virBufferSetChildIndent(&controlBuf, buf);
for (j = 0; j < bank->ncontrols; j++) {
bool min_kilos = !(bank->controls[j]->granularity % 1024);
/* Only use KiB if both values are divisible */
if (bank->controls[j]->min)
min_kilos = min_kilos && !(bank->controls[j]->min % 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;
gran_short_size = virFormatIntPretty(gran_short_size, &unit);
min_short_size = virFormatIntPretty(min_short_size, &min_unit);
/* 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,
"<control granularity='%llu'",
bank->controls[j]->granularity >> (min_kilos * 10));
gran_short_size);
if (bank->controls[j]->min) {
virBufferAsprintf(&controlBuf,
" min='%llu'",
bank->controls[j]->min >> (min_kilos * 10));
}
if (min_short_size)
virBufferAsprintf(&controlBuf, " min='%llu'", min_short_size);
virBufferAsprintf(&controlBuf,
" unit='%s' type='%s' maxAllocs='%u'/>\n",
min_kilos ? "KiB" : "B",
virCacheTypeToString(bank->controls[j]->scope),
bank->controls[j]->max_allocation);
unit,
virCacheTypeToString(controls->scope),
controls->max_allocation);
}
if (virBufferCheckError(&controlBuf) < 0)
......
......@@ -29,7 +29,7 @@
</cells>
</topology>
<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>
</host>
......
......@@ -41,11 +41,11 @@
</cells>
</topology>
<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='data' maxAllocs='8'/>
</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='data' maxAllocs='8'/>
</bank>
......
......@@ -22,8 +22,8 @@
</cells>
</topology>
<cache>
<bank id='0' level='3' type='both' size='33792' unit='KiB' cpus='0'>
<control granularity='3072' unit='KiB' type='both' maxAllocs='16'/>
<bank id='0' level='3' type='both' size='33' unit='MiB' cpus='0'>
<control granularity='3' unit='MiB' type='both' maxAllocs='16'/>
</bank>
</cache>
</host>
......
......@@ -41,10 +41,10 @@
</cells>
</topology>
<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'/>
</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'/>
</bank>
</cache>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册