From patchwork Thu Oct 8 09:29:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 35423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E4C36B7088 for ; Thu, 8 Oct 2009 20:34:34 +1100 (EST) Received: from localhost ([127.0.0.1]:33452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvpOI-0006zR-KF for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 05:34:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvpLG-0006Ko-0Z for qemu-devel@nongnu.org; Thu, 08 Oct 2009 05:31:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvpLB-0006J2-8H for qemu-devel@nongnu.org; Thu, 08 Oct 2009 05:31:21 -0400 Received: from [199.232.76.173] (port=45069 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvpLA-0006Iz-Ss for qemu-devel@nongnu.org; Thu, 08 Oct 2009 05:31:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40579) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvpL9-0001lT-Ae for qemu-devel@nongnu.org; Thu, 08 Oct 2009 05:31:15 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n989VEMK002956; Thu, 8 Oct 2009 05:31:14 -0400 Received: from redhat.com (vpn-10-79.str.redhat.com [10.32.10.79]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n989VBKX013308; Thu, 8 Oct 2009 05:31:12 -0400 Date: Thu, 8 Oct 2009 11:29:11 +0200 From: "Michael S. Tsirkin" To: Isaku Yamahata , Paolo Bonzini Message-ID: <20091008092911.GC5269@redhat.com> References: <20091007123348.GA31537@redhat.com> <20091008000807.GL32367%yamahata@valinux.co.jp> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20091008000807.GL32367%yamahata@valinux.co.jp> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH] qemu/pci: optimize pci config handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Thu, Oct 08, 2009 at 09:08:07AM +0900, Isaku Yamahata wrote: > On Wed, Oct 07, 2009 at 02:33:49PM +0200, Michael S. Tsirkin wrote: > > There's no need to save all of config space before each config cycle: > > just the 64 byte header is enough for our purposes. This will become > > more important as we add pci express support, which has 4K config space. > > > > Signed-off-by: Michael S. Tsirkin > > Cc: Isaku Yamahata > > --- > > > > Isaku Yamahata, I think with this change, you can > > increase the size of config space to 4K without > > need for helper functions. Makes sense? > > It is good that the patch makes the function header size > independent(256 or 4K). > However, your patch just makes the code special. > I think helper functions should be introduced eventually. So maybe we should get away from both memcpy and range checks. How about the following? Note: it's untested, and we should see what this does to boot times. Quite likely nothing. I'd like to see some number on how many times does PCI header get written to during boot. I might check it myself but not anytime soon. Not-Quite-Signed-off-by: Michael S. Tsirkin diff --git a/hw/pci.c b/hw/pci.c index 1debdab..19b8cc6 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -583,18 +583,14 @@ uint32_t pci_default_read_config(PCIDevice *d, void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l) { - uint8_t orig[PCI_CONFIG_SPACE_SIZE]; int i; /* not efficient, but simple */ - memcpy(orig, d->config, PCI_CONFIG_SPACE_SIZE); for(i = 0; i < l && addr < PCI_CONFIG_SPACE_SIZE; val >>= 8, ++i, ++addr) { uint8_t wmask = d->wmask[addr]; d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask); } - if (memcmp(orig + PCI_BASE_ADDRESS_0, d->config + PCI_BASE_ADDRESS_0, 24) - || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND]) - & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO))) + if (ranges_overlap(addr, l, PCI_COMMAND, PCI_ROM_ADDRESS + 3)) pci_update_mappings(d); } diff --git a/hw/pci.h b/hw/pci.h index 93f93fb..b9374d1 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -366,4 +366,27 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base, PCIBus *sh_pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *pic, int devfn_min, int nirq); +/* These are not pci specific. Should move into a separate header. */ + +/* Check whether a given range covers a given byte. */ +static inline int range_covers_byte(uint64_t first, uint64_t last, + uint64_t byte) +{ + return first <= byte && last >= byte; +} + +/* Check whether 2 given ranges overlap. Undefined if last < first. */ +static inline int ranges_overlap(uint64_t first1, uint64_t last1, + uint64_t first2, uint64_t last2) +{ + return first1 >= last2 && first2 >= last1; +} + +/* Get last byte of a range from offset + length. + * Undefined for ranges that wrap around 0. */ +static inline uint64_t range_get_last(uint64_t offset, uint64_t len) +{ + return offset + len - 1; +} + #endif