From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvW9N-0001o5-12 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 09:01:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvW9I-0001jH-5X for qemu-devel@nongnu.org; Wed, 07 Oct 2009 09:01:48 -0400 Received: from [199.232.76.173] (port=40353 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvW9H-0001iw-PW for qemu-devel@nongnu.org; Wed, 07 Oct 2009 09:01:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21936) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvW9G-0008Fi-KT for qemu-devel@nongnu.org; Wed, 07 Oct 2009 09:01:42 -0400 Message-ID: <4ACC9133.9060903@redhat.com> Date: Wed, 07 Oct 2009 15:01:39 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <20091007123348.GA31537@redhat.com> In-Reply-To: <20091007123348.GA31537@redhat.com> Content-Type: multipart/mixed; boundary="------------050305070501010304000507" Subject: [Qemu-devel] Re: [PATCH] qemu/pci: optimize pci config handling List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Isaku Yamahata , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------050305070501010304000507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 10/07/2009 02:33 PM, 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. You can even go a step further and save it only if something is actually being changed. Untested though. Not-quite-signed-off-by: Paolo Bonzini Paolo --------------050305070501010304000507 Content-Type: text/plain; name="qemu-write-pci.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu-write-pci.patch" diff --git a/hw/pci.c b/hw/pci.c index 41e99a9..f9959fc 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -541,19 +541,26 @@ 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]; + uint8_t orig[PCI_CONFIG_HEADER_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); + /* not efficient, but simple. If modifying the header, save it so we + can compare its contents later. */ + if (addr < sizeof orig) { + memcpy(orig, d->config, sizeof orig); + } + + for(i = 0; i < l && addr+i < PCI_CONFIG_SPACE_SIZE; val >>= 8, ++i) { + uint8_t wmask = d->wmask[addr+i]; + d->config[addr+i] = (d->config[addr+i] & ~wmask) | (val & wmask); + } + + if (addr < sizeof orig) { + 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))) + pci_update_mappings(d); } - 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))) - pci_update_mappings(d); } void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len) --------------050305070501010304000507--