kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org
Cc: alex.williamson@redhat.com, avi@redhat.com, mst@redhat.com,
	jan.kiszka@siemens.com, shashidhar.patil@gmail.com
Subject: [PATCH v2 4/8] pci-assign: Only calculate maximum MSI-X vector entries once
Date: Tue, 31 Jan 2012 22:32:44 -0700	[thread overview]
Message-ID: <20120201053244.9843.79456.stgit@bling.home> (raw)
In-Reply-To: <20120201052203.9843.80792.stgit@bling.home>

We'll use this in a few more places for reseting the MSI-X
table and ignoring certain accesses, so it seems worth two
bytes to not recalculate all the time.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/device-assignment.c |   17 +++++++----------
 hw/device-assignment.h |    1 +
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 53c843e..25dff2c 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -964,20 +964,14 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
 static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
 {
     AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev);
-    uint16_t entries_nr = 0, entries_max_nr;
-    int pos = 0, i, r = 0;
+    uint16_t entries_nr = 0;
+    int i, r = 0;
     struct kvm_assigned_msix_nr msix_nr;
     struct kvm_assigned_msix_entry msix_entry;
     MSIXTableEntry *entry = adev->msix_table;
 
-    pos = pci_find_capability(pci_dev, PCI_CAP_ID_MSIX);
-
-    entries_max_nr = *(uint16_t *)(pci_dev->config + pos + 2);
-    entries_max_nr &= PCI_MSIX_FLAGS_QSIZE;
-    entries_max_nr += 1;
-
     /* Get the usable entry number for allocating */
-    for (i = 0; i < entries_max_nr; i++, entry++) {
+    for (i = 0; i < adev->msix_max; i++, entry++) {
         /* Ignore unused entry even it's unmasked */
         if (entry->data == 0) {
             continue;
@@ -1005,7 +999,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
     msix_entry.assigned_dev_id = msix_nr.assigned_dev_id;
     entries_nr = 0;
     entry = adev->msix_table;
-    for (i = 0; i < entries_max_nr; i++, entry++) {
+    for (i = 0; i < adev->msix_max; i++, entry++) {
         if (entries_nr >= msix_nr.entry_nr)
             break;
         if (entry->data == 0) {
@@ -1218,6 +1212,9 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
         bar_nr = msix_table_entry & PCI_MSIX_FLAGS_BIRMASK;
         msix_table_entry &= ~PCI_MSIX_FLAGS_BIRMASK;
         dev->msix_table_addr = pci_region[bar_nr].base_addr + msix_table_entry;
+        dev->msix_max = pci_get_word(pci_dev->config + pos + PCI_MSIX_FLAGS);
+        dev->msix_max &= PCI_MSIX_FLAGS_QSIZE;
+        dev->msix_max += 1;
     }
 
     /* Minimal PM support, nothing writable, device appears to NAK changes */
diff --git a/hw/device-assignment.h b/hw/device-assignment.h
index 2e06ebb..b4bcfa6 100644
--- a/hw/device-assignment.h
+++ b/hw/device-assignment.h
@@ -117,6 +117,7 @@ typedef struct AssignedDevice {
     struct kvm_irq_routing_entry *entry;
     MSIXTableEntry *msix_table;
     target_phys_addr_t msix_table_addr;
+    uint16_t msix_max;
     MemoryRegion mmio;
     char *configfd_name;
     int32_t bootindex;


  parent reply	other threads:[~2012-02-01  5:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-01  5:32 [PATCH v2 0/8] pci-assign: better MSI-X table support Alex Williamson
2012-02-01  5:32 ` [PATCH v2 1/8] pci-assign: Fix warnings with DEBUG enabled Alex Williamson
2012-02-01  5:32 ` [PATCH v2 2/8] pci-assign: Update MSI-X MMIO to Memory API Alex Williamson
2012-02-01  5:32 ` [PATCH v2 3/8] pci-assign: Use struct for MSI-X table Alex Williamson
2012-02-01  5:32 ` Alex Williamson [this message]
2012-02-01  5:32 ` [PATCH v2 5/8] pci-assign: Proper initialization " Alex Williamson
2012-02-01  5:32 ` [PATCH v2 6/8] pci-assign: Allocate entries for all MSI-X vectors Alex Williamson
2012-02-01  5:33 ` [PATCH v2 7/8] pci-assign: Use MSIX_PAGE_SIZE Alex Williamson
2012-02-01  5:33 ` [PATCH v2 8/8] pci-assign: Update MSI-X config based on table writes Alex Williamson
2012-02-01  7:22   ` Michael S. Tsirkin
2012-02-01 13:48     ` Alex Williamson
2012-02-01 14:13       ` Jan Kiszka
2012-02-01 15:13       ` Michael S. Tsirkin
2012-02-01  7:25   ` Michael S. Tsirkin
2012-02-01 13:51     ` Alex Williamson
2012-02-07 20:04 ` [PATCH v2 0/8] pci-assign: better MSI-X table support Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120201053244.9843.79456.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=shashidhar.patil@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).