mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
conf: Optimize the iothreadid initialization
https://bugzilla.redhat.com/show_bug.cgi?id=1264008 The existing algorithm assumed that someone was making small, incremental changes; however, it is possible to change iothreads from 0 (or relatively small number) to some really large number and the algorithm would possibly spin its wheels doing unnecessary searches. So, optimize the algorithm using a bitmap to find available iothread_id's starting at 1 that aren't already defined by a "<thread id='#'>" and filling in the iothreadids array with those iothread_id values.
This commit is contained in:
parent
cc2d49f9be
commit
bb02d4c429
@ -2332,8 +2332,11 @@ virDomainIOThreadIDDefArrayFree(virDomainIOThreadIDDefPtr *def,
|
||||
static int
|
||||
virDomainIOThreadIDDefArrayInit(virDomainDefPtr def)
|
||||
{
|
||||
unsigned int iothread_id = 1;
|
||||
int retval = -1;
|
||||
size_t i;
|
||||
ssize_t nxt = -1;
|
||||
virDomainIOThreadIDDefPtr iothrid = NULL;
|
||||
virBitmapPtr thrmap = NULL;
|
||||
|
||||
/* Same value (either 0 or some number), then we have none to fill in or
|
||||
* the iothreadid array was filled from the XML
|
||||
@ -2341,19 +2344,40 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def)
|
||||
if (def->iothreads == def->niothreadids)
|
||||
return 0;
|
||||
|
||||
while (def->niothreadids != def->iothreads) {
|
||||
if (!virDomainIOThreadIDFind(def, iothread_id)) {
|
||||
virDomainIOThreadIDDefPtr iothrid;
|
||||
|
||||
if (!(iothrid = virDomainIOThreadIDAdd(def, iothread_id)))
|
||||
/* iothread's are numbered starting at 1, account for that */
|
||||
if (!(thrmap = virBitmapNew(def->iothreads + 1)))
|
||||
goto error;
|
||||
virBitmapSetAll(thrmap);
|
||||
|
||||
/* Clear 0 since we don't use it, then mark those which are
|
||||
* already provided by the user */
|
||||
ignore_value(virBitmapClearBit(thrmap, 0));
|
||||
for (i = 0; i < def->niothreadids; i++)
|
||||
ignore_value(virBitmapClearBit(thrmap,
|
||||
def->iothreadids[i]->iothread_id));
|
||||
|
||||
/* resize array */
|
||||
if (VIR_REALLOC_N(def->iothreadids, def->iothreads) < 0)
|
||||
goto error;
|
||||
|
||||
/* Populate iothreadids[] using the set bit number from thrmap */
|
||||
while (def->niothreadids < def->iothreads) {
|
||||
if ((nxt = virBitmapNextSetBit(thrmap, nxt)) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("failed to populate iothreadids"));
|
||||
goto error;
|
||||
}
|
||||
if (VIR_ALLOC(iothrid) < 0)
|
||||
goto error;
|
||||
iothrid->iothread_id = nxt;
|
||||
iothrid->autofill = true;
|
||||
def->iothreadids[def->niothreadids++] = iothrid;
|
||||
}
|
||||
iothread_id++;
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
|
||||
error:
|
||||
virBitmapFree(thrmap);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user