From: Alex Williamson <alex.williamson@hp.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@hp.com
Subject: [Qemu-devel] [PATCH 5/7] virtio-net: MAC filter optimization
Date: Fri, 05 Jun 2009 14:47:13 -0600 [thread overview]
Message-ID: <20090605204713.3355.5535.stgit@kvm.aw> (raw)
In-Reply-To: <20090605204647.3355.81929.stgit@kvm.aw>
The MAC filter table is received from the guest as two separate
buffers, one with unicast entries, the other with multicast
entries. If we track the index dividing the two sets, we can
avoid searching the part of the table with the wrong type of
entries.
We could store this index as part of the save image, but its
trivially easy to discover it on load.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---
hw/virtio-net.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 64515a3..5239cc0 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -37,6 +37,7 @@ typedef struct VirtIONet
uint8_t allmulti;
struct {
int in_use;
+ int first_multi;
uint8_t multi_overflow;
uint8_t uni_overflow;
uint8_t *macs;
@@ -100,6 +101,7 @@ static void virtio_net_reset(VirtIODevice *vdev)
/* Flush any MAC and VLAN filter table state */
n->mac_table.in_use = 0;
+ n->mac_table.first_multi = 0;
n->mac_table.multi_overflow = 0;
n->mac_table.uni_overflow = 0;
memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
@@ -172,6 +174,7 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
return VIRTIO_NET_ERR;
n->mac_table.in_use = 0;
+ n->mac_table.first_multi = 0;
n->mac_table.uni_overflow = 0;
n->mac_table.multi_overflow = 0;
memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
@@ -190,6 +193,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
n->mac_table.uni_overflow = 1;
}
+ n->mac_table.first_multi = n->mac_table.in_use;
+
mac_data.entries = ldl_le_p(elem->out_sg[2].iov_base);
if (sizeof(mac_data.entries) +
@@ -356,17 +361,24 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
} else if (n->allmulti || n->mac_table.multi_overflow) {
return 1;
}
+
+ for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) {
+ if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN)) {
+ return 1;
+ }
+ }
} else { // unicast
if (n->mac_table.uni_overflow) {
return 1;
} else if (!memcmp(ptr, n->mac, ETH_ALEN)) {
return 1;
}
- }
- for (i = 0; i < n->mac_table.in_use; i++) {
- if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN))
- return 1;
+ for (i = 0; i < n->mac_table.first_multi; i++) {
+ if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN)) {
+ return 1;
+ }
+ }
}
return 0;
@@ -542,6 +554,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
{
VirtIONet *n = opaque;
+ int i;
if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
return -EINVAL;
@@ -592,6 +605,14 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
n->mac_table.uni_overflow = qemu_get_byte(f);
}
+ /* Find the first multicast entry in the saved MAC filter */
+ for (i = 0; i < n->mac_table.in_use; i++) {
+ if (n->mac_table.macs[i * ETH_ALEN] & 1) {
+ break;
+ }
+ }
+ n->mac_table.first_multi = i;
+
if (n->tx_timer_active) {
qemu_mod_timer(n->tx_timer,
qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
next prev parent reply other threads:[~2009-06-05 20:53 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-05 20:46 [Qemu-devel] [PATCH 0/7] virtio-net: Filter cleanup/improvements Alex Williamson
2009-06-05 20:46 ` [Qemu-devel] [PATCH 1/7] virtio-net: Add version_id 7 placeholder for vnet header support Alex Williamson
2009-06-05 20:46 ` [Qemu-devel] [PATCH 2/7] virtio-net: Use a byte to store RX mode flags Alex Williamson
2009-06-05 20:47 ` [Qemu-devel] [PATCH 3/7] virtio-net: reorganize receive_filter() Alex Williamson
2009-06-05 20:47 ` [Qemu-devel] [PATCH 4/7] virtio-net: Fix MAC filter overflow handling Alex Williamson
2009-06-05 20:47 ` Alex Williamson [this message]
2009-06-05 20:47 ` [Qemu-devel] [PATCH 6/7] virtio-net: Add new RX filter controls Alex Williamson
2009-06-06 20:48 ` Michael S. Tsirkin
2009-06-08 19:01 ` Alex Williamson
2009-06-08 19:18 ` Anthony Liguori
2009-06-08 19:29 ` Daniel P. Berrange
2009-06-08 21:03 ` Anthony Liguori
2009-06-09 9:57 ` Daniel P. Berrange
2009-06-09 15:00 ` Jamie Lokier
2009-06-09 15:42 ` [Qemu-devel] " Jan Kiszka
2009-06-09 23:50 ` Jamie Lokier
2009-06-10 8:46 ` Michael S. Tsirkin
2009-06-10 8:58 ` Jan Kiszka
2009-06-10 9:07 ` Michael S. Tsirkin
2009-06-10 9:13 ` Gleb Natapov
2009-06-10 9:17 ` Michael S. Tsirkin
2009-06-10 9:22 ` Gleb Natapov
2009-06-10 9:35 ` Michael S. Tsirkin
2009-06-08 20:18 ` [Qemu-devel] " Alex Williamson
2009-06-05 20:47 ` [Qemu-devel] [PATCH 7/7] virtio-net: Increase filter and control limits Alex Williamson
2009-06-06 20:44 ` Michael S. Tsirkin
2009-06-08 18:49 ` Alex Williamson
2009-06-09 19:25 ` [Qemu-devel] [PATCH 0/7] virtio-net: Filter cleanup/improvements Mark McLoughlin
2009-06-09 21:08 ` Alex Williamson
2009-06-10 6:51 ` Rusty Russell
2009-06-10 20:43 ` Alex Williamson
2009-06-12 17:07 ` Mark McLoughlin
2009-06-12 19:19 ` Alex Williamson
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=20090605204713.3355.5535.stgit@kvm.aw \
--to=alex.williamson@hp.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).