From nobody Fri May 16 06:25:12 2025 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 1497606598552198.1860719163043; Fri, 16 Jun 2017 02:49:58 -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 C7A26145F83; Fri, 16 Jun 2017 09:49:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99AF394556; Fri, 16 Jun 2017 09:49:56 +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 598A24A492; Fri, 16 Jun 2017 09:49:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5G9nSka031261 for ; Fri, 16 Jun 2017 05:49:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 985D17EEE4; Fri, 16 Jun 2017 09:49:28 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D97F47F356 for ; Fri, 16 Jun 2017 09:49:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C7A26145F83 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 C7A26145F83 From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 16 Jun 2017 17:48:51 +0800 Message-Id: <1497606548-18870-8-git-send-email-abologna@redhat.com> In-Reply-To: <1497606548-18870-1-git-send-email-abologna@redhat.com> References: <1497606548-18870-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/24] 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.39]); Fri, 16 Jun 2017 09:49:57 +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. Reviewed-by: Laine Stump Signed-off-by: Andrea Bolognani --- 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