From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org, avi@redhat.com, mtosatti@redhat.com,
Juan Quintela <quintela@redhat.com>,
Amit Shah <amit.shah@redhat.com>,
kvm@vger.kernel.org
Subject: Re: [PATCHv2] qemu-kvm/vhost: fix up irqfd support
Date: Wed, 6 Oct 2010 23:44:40 +0200 [thread overview]
Message-ID: <20101006214440.GA17149@redhat.com> (raw)
In-Reply-To: <1286385864.3020.26.camel@x201>
On Wed, Oct 06, 2010 at 11:24:24AM -0600, Alex Williamson wrote:
> You could always keep the functions as separate wrapper callers of the
> common function so you only need to keep true = unset, false = set
> straight in one place. Thanks,
Just to show why it does not work, I did exactly this: as you see the
code is shorter but the true/false magic gets spread: it was in 2
places, (set/unset) now it is in 4 places and it is within the loop, in
code that is more complex.
So I think I'll stick to the original version and we can
patch it up later if there's a will.
diff --git a/hw/msix.c b/hw/msix.c
index 3d4dd61..4b705a0 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -583,40 +583,15 @@ void msix_unuse_all_vectors(PCIDevice *dev)
msix_free_irq_entries(dev);
}
-static int msix_set_mask_notifier_for_vector(PCIDevice *dev, unsigned vector)
+/* Invoke the notifier if vector entry is used and unmasked. */
+static int msix_notify_if_unmasked(PCIDevice *dev, unsigned vector, bool masked)
{
int r = 0;
- if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
+ if (!dev->msix_entry_used[vector] || msix_is_masked(dev, vector)) {
return 0;
-
- assert(dev->msix_mask_notifier);
-
- /* Unmask the new notifier unless vector is masked. */
- if (!msix_is_masked(dev, vector)) {
- r = dev->msix_mask_notifier(dev, vector, false);
- if (r < 0) {
- return r;
- }
}
- return r;
-}
-
-static int msix_unset_mask_notifier_for_vector(PCIDevice *dev, unsigned vector)
-{
- int r = 0;
- if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
- return 0;
-
assert(dev->msix_mask_notifier);
-
- /* Mask the old notifier unless it is already masked. */
- if (!msix_is_masked(dev, vector)) {
- r = dev->msix_mask_notifier(dev, vector, true);
- if (r < 0) {
- return r;
- }
- }
- return r;
+ return dev->msix_mask_notifier(dev, vector, masked);
}
int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
@@ -625,7 +600,7 @@ int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
assert(!dev->msix_mask_notifier);
dev->msix_mask_notifier = f;
for (n = 0; n < dev->msix_entries_nr; ++n) {
- r = msix_set_mask_notifier_for_vector(dev, n);
+ r = msix_notify_if_unmasked(dev, n, false);
if (r < 0) {
goto undo;
}
@@ -634,7 +609,7 @@ int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
undo:
while (--n >= 0) {
- msix_unset_mask_notifier_for_vector(dev, n);
+ msix_notify_if_unmasked(dev, n, true);
}
dev->msix_mask_notifier = NULL;
return r;
@@ -645,7 +620,7 @@ int msix_unset_mask_notifier(PCIDevice *dev)
int r, n;
assert(dev->msix_mask_notifier);
for (n = 0; n < dev->msix_entries_nr; ++n) {
- r = msix_unset_mask_notifier_for_vector(dev, n);
+ r = msix_notify_if_unmasked(dev, n, true);
if (r < 0) {
goto undo;
}
@@ -655,7 +630,7 @@ int msix_unset_mask_notifier(PCIDevice *dev)
undo:
while (--n >= 0) {
- msix_set_mask_notifier_for_vector(dev, n);
+ msix_notify_if_unmasked(dev, n, false);
}
return r;
}
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org, Juan Quintela <quintela@redhat.com>,
mtosatti@redhat.com, qemu-devel@nongnu.org, avi@redhat.com,
Amit Shah <amit.shah@redhat.com>
Subject: [Qemu-devel] Re: [PATCHv2] qemu-kvm/vhost: fix up irqfd support
Date: Wed, 6 Oct 2010 23:44:40 +0200 [thread overview]
Message-ID: <20101006214440.GA17149@redhat.com> (raw)
In-Reply-To: <1286385864.3020.26.camel@x201>
On Wed, Oct 06, 2010 at 11:24:24AM -0600, Alex Williamson wrote:
> You could always keep the functions as separate wrapper callers of the
> common function so you only need to keep true = unset, false = set
> straight in one place. Thanks,
Just to show why it does not work, I did exactly this: as you see the
code is shorter but the true/false magic gets spread: it was in 2
places, (set/unset) now it is in 4 places and it is within the loop, in
code that is more complex.
So I think I'll stick to the original version and we can
patch it up later if there's a will.
diff --git a/hw/msix.c b/hw/msix.c
index 3d4dd61..4b705a0 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -583,40 +583,15 @@ void msix_unuse_all_vectors(PCIDevice *dev)
msix_free_irq_entries(dev);
}
-static int msix_set_mask_notifier_for_vector(PCIDevice *dev, unsigned vector)
+/* Invoke the notifier if vector entry is used and unmasked. */
+static int msix_notify_if_unmasked(PCIDevice *dev, unsigned vector, bool masked)
{
int r = 0;
- if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
+ if (!dev->msix_entry_used[vector] || msix_is_masked(dev, vector)) {
return 0;
-
- assert(dev->msix_mask_notifier);
-
- /* Unmask the new notifier unless vector is masked. */
- if (!msix_is_masked(dev, vector)) {
- r = dev->msix_mask_notifier(dev, vector, false);
- if (r < 0) {
- return r;
- }
}
- return r;
-}
-
-static int msix_unset_mask_notifier_for_vector(PCIDevice *dev, unsigned vector)
-{
- int r = 0;
- if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
- return 0;
-
assert(dev->msix_mask_notifier);
-
- /* Mask the old notifier unless it is already masked. */
- if (!msix_is_masked(dev, vector)) {
- r = dev->msix_mask_notifier(dev, vector, true);
- if (r < 0) {
- return r;
- }
- }
- return r;
+ return dev->msix_mask_notifier(dev, vector, masked);
}
int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
@@ -625,7 +600,7 @@ int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
assert(!dev->msix_mask_notifier);
dev->msix_mask_notifier = f;
for (n = 0; n < dev->msix_entries_nr; ++n) {
- r = msix_set_mask_notifier_for_vector(dev, n);
+ r = msix_notify_if_unmasked(dev, n, false);
if (r < 0) {
goto undo;
}
@@ -634,7 +609,7 @@ int msix_set_mask_notifier(PCIDevice *dev, msix_mask_notifier_func f)
undo:
while (--n >= 0) {
- msix_unset_mask_notifier_for_vector(dev, n);
+ msix_notify_if_unmasked(dev, n, true);
}
dev->msix_mask_notifier = NULL;
return r;
@@ -645,7 +620,7 @@ int msix_unset_mask_notifier(PCIDevice *dev)
int r, n;
assert(dev->msix_mask_notifier);
for (n = 0; n < dev->msix_entries_nr; ++n) {
- r = msix_unset_mask_notifier_for_vector(dev, n);
+ r = msix_notify_if_unmasked(dev, n, true);
if (r < 0) {
goto undo;
}
@@ -655,7 +630,7 @@ int msix_unset_mask_notifier(PCIDevice *dev)
undo:
while (--n >= 0) {
- msix_set_mask_notifier_for_vector(dev, n);
+ msix_notify_if_unmasked(dev, n, false);
}
return r;
}
next prev parent reply other threads:[~2010-10-06 21:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-06 14:56 [PATCHv2] qemu-kvm/vhost: fix up irqfd support Michael S. Tsirkin
2010-10-06 14:56 ` [Qemu-devel] " Michael S. Tsirkin
2010-10-06 16:48 ` Alex Williamson
2010-10-06 16:48 ` [Qemu-devel] " Alex Williamson
2010-10-06 17:02 ` Michael S. Tsirkin
2010-10-06 17:02 ` [Qemu-devel] " Michael S. Tsirkin
2010-10-06 17:24 ` Alex Williamson
2010-10-06 17:24 ` [Qemu-devel] " Alex Williamson
2010-10-06 17:29 ` Michael S. Tsirkin
2010-10-06 17:29 ` [Qemu-devel] " Michael S. Tsirkin
2010-10-06 21:44 ` Michael S. Tsirkin [this message]
2010-10-06 21:44 ` Michael S. Tsirkin
2010-10-06 22:05 ` Alex Williamson
2010-10-06 22:05 ` [Qemu-devel] " Alex Williamson
2010-10-07 9:57 ` Michael S. Tsirkin
2010-10-07 9:57 ` [Qemu-devel] " Michael S. Tsirkin
2010-10-07 15:15 ` Alex Williamson
2010-10-07 15:15 ` [Qemu-devel] " Alex Williamson
2010-10-07 15:17 ` Michael S. Tsirkin
2010-10-07 15:17 ` [Qemu-devel] " Michael S. Tsirkin
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=20101006214440.GA17149@redhat.com \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=amit.shah@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.