qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: jan.kiszka@siemens.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] pci-assign: Add MSI affinity support
Date: Sun, 12 May 2013 14:01:36 +0300	[thread overview]
Message-ID: <20130512110136.GA10144@redhat.com> (raw)
In-Reply-To: <20130509163605.22536.77178.stgit@bling.home>

On Thu, May 09, 2013 at 10:36:05AM -0600, Alex Williamson wrote:
> Track the last MSIMessage programmed so we can determine when it has
> changed and update the routing to the guest.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  hw/i386/kvm/pci-assign.c |   27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> index 0f83a4c..e09265b 100644
> --- a/hw/i386/kvm/pci-assign.c
> +++ b/hw/i386/kvm/pci-assign.c
> @@ -134,6 +134,7 @@ typedef struct AssignedDevice {
>      int msi_nr;
>      struct {
>          int virq;
> +        MSIMessage msg;
>      } *msi;
>      MSIXTableEntry *msix_table;
>      hwaddr msix_table_addr;
> @@ -1015,6 +1016,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
>          assigned_dev->msi = g_malloc(sizeof(*assigned_dev->msi));
>          assigned_dev->msi_nr = 1;
>          assigned_dev->msi[0].virq = virq;
> +        assigned_dev->msi[0].msg = msg;
>          if (kvm_device_msi_assign(kvm_state, assigned_dev->dev_id, virq) < 0) {
>              perror("assigned_dev_update_msi: kvm_device_msi_assign");
>          }
> @@ -1027,6 +1029,27 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
>      }
>  }
>  
> +static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
> +{
> +    AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
> +    uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap +
> +                                     PCI_MSI_FLAGS);
> +    MSIMessage msg;
> +
> +    if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI ||
> +        !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) {
> +        return;
> +    }
> +
> +    msg = msi_get_message(pci_dev, 0);
> +
> +    if (msg.address != assigned_dev->msi[0].msg.address ||
> +        msg.data != assigned_dev->msi[0].msg.data) {
> +        kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi[0].virq, msg);
> +        assigned_dev->msi[0].msg = msg;
> +    }
> +}
> +

Okay, but why do we track the message in AssignedDevice?
To avoid extra calls to kvm_irqchip_update_msi_route?
Let's not do premature optimizations please:
just call kvm_irqchip_update_msi_route directly,
no need to track the message in AssignedDevice.

Moreover, if you can measure a performance gain
from tracking msg in AssignedDevice there's a
better way to do this: we have an outstanding patch to kvm,
which optimized the no change case away to an array
lookup. This benefits msi-x as well.

>  static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
>  {
>      return (entry->ctrl & cpu_to_le32(0x1)) != 0;
> @@ -1202,6 +1225,10 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
>          if (range_covers_byte(address, len,
>                                pci_dev->msi_cap + PCI_MSI_FLAGS)) {
>              assigned_dev_update_msi(pci_dev);
> +        } else if (ranges_overlap(address, len,
> +                                  pci_dev->msi_cap + PCI_MSI_ADDRESS_LO,
> +                                  10 - PCI_MSI_ADDRESS_LO)) {
> +            assigned_dev_update_msi_msg(pci_dev);
>          }
>      }
>      if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {

  reply	other threads:[~2013-05-12 11:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09 16:35 [Qemu-devel] [PATCH 0/2] pci-assign: MSI affinity support Alex Williamson
2013-05-09 16:35 ` [Qemu-devel] [PATCH 1/2] pci-assign: Refactor MSI virq array Alex Williamson
2013-05-09 16:36 ` [Qemu-devel] [PATCH 2/2] pci-assign: Add MSI affinity support Alex Williamson
2013-05-12 11:01   ` Michael S. Tsirkin [this message]
2013-05-10 12:40 ` [Qemu-devel] [PATCH 0/2] pci-assign: " Jan Kiszka
2013-05-10 15:47   ` Alex Williamson
2013-05-12 11:23   ` Michael S. Tsirkin
2013-05-22 22:59 ` Anthony Liguori

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=20130512110136.GA10144@redhat.com \
    --to=mst@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    /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).