From nobody Wed Feb 11 04:39:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498230250783866.2038795563102; Fri, 23 Jun 2017 08:04:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88A9E65744; Fri, 23 Jun 2017 15:04:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E2A480E70; Fri, 23 Jun 2017 15:04:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 457AB1853E32; Fri, 23 Jun 2017 15:04:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NF3xFO004200 for ; Fri, 23 Jun 2017 11:03:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1E0656E8D3; Fri, 23 Jun 2017 15:03:59 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-12-57.pek2.redhat.com [10.72.12.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 545126F9DB for ; Fri, 23 Jun 2017 15:03:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 88A9E65744 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 88A9E65744 From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 23:03:10 +0800 Message-Id: <1498230208-14144-9-git-send-email-abologna@redhat.com> In-Reply-To: <1498230208-14144-1-git-send-email-abologna@redhat.com> References: <1498230208-14144-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/26] conf: Simplify slot allocation X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 23 Jun 2017 15:04:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The current algorithm for slot allocation tries to be clever and avoid looking at buses / slots more than once unless it's necessary. Unfortunately that makes the code more complex, and it will cause problem later on in some situations unless even more complex code is added. Since the performance gains are going to be pretty modest anyway, we can just get rid of the extra complexity and use a completely straighforward implementation instead. Signed-off-by: Andrea Bolognani Reviewed-by: Laine Stump --- src/conf/domain_addr.c | 47 +++++++++-------------------------------------- src/conf/domain_addr.h | 2 -- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index b588b36..86b1367 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -741,46 +741,34 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSet= Ptr addrs, virDomainPCIConnectFlags flags, int function) { - /* default to starting the search for a free slot from - * the first slot of domain 0 bus 0... - */ virPCIDeviceAddress a =3D { 0 }; - bool found =3D false; =20 if (addrs->nbuses =3D=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("No PCI buses available"= )); goto error; } =20 - /* ...unless this search is for the exact same type of device as - * last time, then continue the search from the slot where we - * found the previous match (it's possible there will still be a - * function available on that slot). - */ - if (flags =3D=3D addrs->lastFlags) - a =3D addrs->lastaddr; - else - a.slot =3D addrs->buses[0].minSlot; - /* if the caller asks for "any function", give them function 0 */ if (function =3D=3D -1) a.function =3D 0; else a.function =3D function; =20 - while (a.bus < addrs->nbuses) { - if (virDomainPCIAddressFindUnusedFunctionOnBus(&addrs->buses[a.bus= ], - &a, function, + /* "Begin at the beginning," the King said, very gravely, "and go on + * till you come to the end: then stop." */ + for (a.bus =3D 0; a.bus < addrs->nbuses; a.bus++) { + virDomainPCIAddressBusPtr bus =3D &addrs->buses[a.bus]; + bool found =3D false; + + a.slot =3D bus->minSlot; + + if (virDomainPCIAddressFindUnusedFunctionOnBus(bus, &a, function, flags, &found) < 0)= { goto error; } =20 if (found) goto success; - - /* nothing on this bus, go to the next bus */ - if (++a.bus < addrs->nbuses) - a.slot =3D addrs->buses[a.bus].minSlot; } =20 /* There were no free slots after the last used one */ @@ -791,20 +779,6 @@ virDomainPCIAddressGetNextAddr(virDomainPCIAddressSetP= tr addrs, /* this device will use the first slot of the new bus */ a.slot =3D addrs->buses[a.bus].minSlot; goto success; - } else if (flags =3D=3D addrs->lastFlags) { - /* Check the buses from 0 up to the last used one */ - for (a.bus =3D 0; a.bus <=3D addrs->lastaddr.bus; a.bus++) { - a.slot =3D addrs->buses[a.bus].minSlot; - - if (virDomainPCIAddressFindUnusedFunctionOnBus(&addrs->buses[a= .bus], - &a, function, - flags, &found) = < 0) { - goto error; - } - - if (found) - goto success; - } } =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -851,9 +825,6 @@ virDomainPCIAddressReserveNextAddr(virDomainPCIAddressS= etPtr addrs, if (virDomainPCIAddressReserveAddrInternal(addrs, &addr, flags, false)= < 0) return -1; =20 - addrs->lastaddr =3D addr; - addrs->lastFlags =3D flags; - if (!addrs->dryRun) { dev->type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; dev->addr.pci =3D addr; diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index dbef4b1..c98a228 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -106,8 +106,6 @@ typedef virDomainPCIAddressBus *virDomainPCIAddressBusP= tr; struct _virDomainPCIAddressSet { virDomainPCIAddressBus *buses; size_t nbuses; - virPCIDeviceAddress lastaddr; - virDomainPCIConnectFlags lastFlags; bool dryRun; /* on a dry run, new buses are auto-added and addresses aren't saved in device infos */ }; --=20 2.7.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list