mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
conf: Format cache banks in capabilities with virFormatIntPretty
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
b4698edcb0
commit
63d95a19cc
@ -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);
|
||||
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 */
|
||||
if (bank->controls[j]->min)
|
||||
min_kilos = min_kilos && !(bank->controls[j]->min % 1024);
|
||||
gran_short_size = virFormatIntPretty(gran_short_size, &unit);
|
||||
min_short_size = virFormatIntPretty(min_short_size, &min_unit);
|
||||
|
||||
virBufferAsprintf(&controlBuf,
|
||||
"<control granularity='%llu'",
|
||||
bank->controls[j]->granularity >> (min_kilos * 10));
|
||||
/* Only use the smaller unit if they are different */
|
||||
if (min_short_size) {
|
||||
unsigned long long gran_div;
|
||||
unsigned long long min_div;
|
||||
|
||||
if (bank->controls[j]->min) {
|
||||
virBufferAsprintf(&controlBuf,
|
||||
" min='%llu'",
|
||||
bank->controls[j]->min >> (min_kilos * 10));
|
||||
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'",
|
||||
gran_short_size);
|
||||
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user