mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
util: Use default group's mask for unspecified resctrl allocations
Introduce virResctrlAllocCopyMasks() and use that to initially copy the default group schemata to the allocation before reserving any parts of the cache. The reason for this is that when new group is created the schemata will have unknown data in it. If there was previously group with the same CLoS ID, it will have the previous valies, if not it will have all bits set. And we need to set all unspecified (in the XML) allocations to the same one as the default group. Some non-Linux functions now need to be made public due to this change. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1289368 Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
f6199295a9
commit
c39ce914dd
@ -667,8 +667,6 @@ virResctrlAllocGetType(virResctrlAllocPtr resctrl,
|
||||
}
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
static int
|
||||
virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl,
|
||||
unsigned int level,
|
||||
@ -696,8 +694,6 @@ virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl,
|
||||
return virBitmapCopy(a_type->masks[cache], mask);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static int
|
||||
virResctrlAllocUpdateSize(virResctrlAllocPtr resctrl,
|
||||
@ -917,8 +913,6 @@ virResctrlAllocFormat(virResctrlAllocPtr resctrl)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
static int
|
||||
virResctrlAllocParseProcessCache(virResctrlInfoPtr resctrl,
|
||||
virResctrlAllocPtr alloc,
|
||||
@ -1090,6 +1084,8 @@ virResctrlAllocGetDefault(virResctrlInfoPtr resctrl)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
static void
|
||||
virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst,
|
||||
virResctrlAllocPerTypePtr src)
|
||||
@ -1298,23 +1294,8 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
|
||||
ssize_t last_bits = 0;
|
||||
ssize_t last_pos = -1;
|
||||
|
||||
/* If there is no reservation requested we need to set all bits. That's due
|
||||
* to weird interface of the resctrl sysfs. It's also the reason why we
|
||||
* cannot reserve the whole cache in one allocation. */
|
||||
if (!size) {
|
||||
a_mask = virBitmapNew(i_type->bits);
|
||||
if (!a_mask)
|
||||
return -1;
|
||||
|
||||
virBitmapSetAll(a_mask);
|
||||
|
||||
if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) {
|
||||
virBitmapFree(a_mask);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cache >= f_type->nmasks) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
@ -1417,6 +1398,44 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virResctrlAllocCopyMasks(virResctrlAllocPtr dst,
|
||||
virResctrlAllocPtr src)
|
||||
{
|
||||
unsigned int level = 0;
|
||||
|
||||
for (level = 0; level < src->nlevels; level++) {
|
||||
virResctrlAllocPerLevelPtr s_level = src->levels[level];
|
||||
unsigned int type = 0;
|
||||
|
||||
if (!s_level)
|
||||
continue;
|
||||
|
||||
for (type = 0; type < VIR_CACHE_TYPE_LAST; type++) {
|
||||
virResctrlAllocPerTypePtr s_type = s_level->types[type];
|
||||
virResctrlAllocPerTypePtr d_type = NULL;
|
||||
unsigned int cache = 0;
|
||||
|
||||
if (!s_type)
|
||||
continue;
|
||||
|
||||
d_type = virResctrlAllocGetType(dst, level, type);
|
||||
if (!d_type)
|
||||
return -1;
|
||||
|
||||
for (cache = 0; cache < s_type->nmasks; cache++) {
|
||||
virBitmapPtr mask = s_type->masks[cache];
|
||||
|
||||
if (mask && virResctrlAllocUpdateMask(dst, level, type, cache, mask) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function is called when creating an allocation in the system. What it
|
||||
* does is that it gets all the unused bits using virResctrlAllocGetUnused() and
|
||||
@ -1430,11 +1449,19 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
|
||||
int ret = -1;
|
||||
unsigned int level = 0;
|
||||
virResctrlAllocPtr alloc_free = NULL;
|
||||
virResctrlAllocPtr alloc_default = NULL;
|
||||
|
||||
alloc_free = virResctrlAllocGetUnused(resctrl);
|
||||
if (!alloc_free)
|
||||
return -1;
|
||||
|
||||
alloc_default = virResctrlAllocGetDefault(resctrl);
|
||||
if (!alloc_default)
|
||||
return -1;
|
||||
|
||||
if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0)
|
||||
return -1;
|
||||
|
||||
for (level = 0; level < alloc->nlevels; level++) {
|
||||
virResctrlAllocPerLevelPtr a_level = alloc->levels[level];
|
||||
virResctrlAllocPerLevelPtr f_level = NULL;
|
||||
@ -1482,6 +1509,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virObjectUnref(alloc_free);
|
||||
virObjectUnref(alloc_default);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user