qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, quintela@redhat.com, jasowang@redhat.com,
	mst@redhat.com, eblake@redhat.com, armbru@redhat.com,
	berrange@redhat.com
Subject: [Qemu-devel] [PATCH 3/9] virtio-net: Switch to using announce timer
Date: Mon, 28 Jan 2019 17:03:15 +0000	[thread overview]
Message-ID: <20190128170321.16936-4-dgilbert@redhat.com> (raw)
In-Reply-To: <20190128170321.16936-1-dgilbert@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Switch virtio's self announcement to use the AnnounceTimer.
It keeps it's own AnnounceTimer (per device), and starts running it
using a migration post-load and a virtual clock; that way the
announce happens once the guest is actually running.
The timer uses the migration parameters to set the timing of
the repeats.

Based on earlier patches by myself and
 Vladislav Yasevich <vyasevic@redhat.com>

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/net/trace-events            |  7 +++++++
 hw/net/virtio-net.c            | 36 ++++++++++++++++++++++------------
 include/hw/virtio/virtio-net.h |  4 ++--
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/hw/net/trace-events b/hw/net/trace-events
index 9d49f62fa1..fc800dd606 100644
--- a/hw/net/trace-events
+++ b/hw/net/trace-events
@@ -359,3 +359,10 @@ sunhme_rx_filter_reject(void) "rejecting incoming frame"
 sunhme_rx_filter_accept(void) "accepting incoming frame"
 sunhme_rx_desc(uint32_t addr, int offset, uint32_t status, int len, int cr, int nr) "addr 0x%"PRIx32"(+0x%x) status 0x%"PRIx32 " len %d (ring %d/%d)"
 sunhme_rx_xsum_calc(uint16_t xsum) "calculated incoming xsum as 0x%x"
+
+# hw/net/virtio-net.c
+virtio_net_announce_timer(int round) "%d"
+virtio_net_handle_announce(int round) "%d"
+virtio_net_post_load_device(void)
+
+
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3f319ef723..b50f86d230 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -21,12 +21,14 @@
 #include "qemu/timer.h"
 #include "hw/virtio/virtio-net.h"
 #include "net/vhost_net.h"
+#include "net/announce.h"
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-net.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/misc.h"
 #include "standard-headers/linux/ethtool.h"
+#include "trace.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -164,8 +166,9 @@ static void virtio_net_announce_timer(void *opaque)
 {
     VirtIONet *n = opaque;
     VirtIODevice *vdev = VIRTIO_DEVICE(n);
+    trace_virtio_net_announce_timer(n->announce_timer.round);
 
-    n->announce_counter--;
+    n->announce_timer.round--;
     n->status |= VIRTIO_NET_S_ANNOUNCE;
     virtio_notify_config(vdev);
 }
@@ -479,8 +482,8 @@ static void virtio_net_reset(VirtIODevice *vdev)
     n->nobcast = 0;
     /* multiqueue is disabled by default */
     n->curr_queues = 1;
-    timer_del(n->announce_timer);
-    n->announce_counter = 0;
+    timer_del(n->announce_timer.tm);
+    n->announce_timer.round = 0;
     n->status &= ~VIRTIO_NET_S_ANNOUNCE;
 
     /* Flush any MAC and VLAN filter table state */
@@ -976,13 +979,12 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
 static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
                                       struct iovec *iov, unsigned int iov_cnt)
 {
+    trace_virtio_net_handle_announce(n->announce_timer.round);
     if (cmd == VIRTIO_NET_CTRL_ANNOUNCE_ACK &&
         n->status & VIRTIO_NET_S_ANNOUNCE) {
         n->status &= ~VIRTIO_NET_S_ANNOUNCE;
-        if (n->announce_counter) {
-            timer_mod(n->announce_timer,
-                      qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
-                      self_announce_delay(n->announce_counter));
+        if (n->announce_timer.round) {
+            qemu_announce_timer_step(&n->announce_timer);
         }
         return VIRTIO_NET_OK;
     } else {
@@ -2298,6 +2300,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
     VirtIODevice *vdev = VIRTIO_DEVICE(n);
     int i, link_down;
 
+    trace_virtio_net_post_load_device();
     virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs,
                                virtio_vdev_has_feature(vdev,
                                                        VIRTIO_F_VERSION_1));
@@ -2334,8 +2337,15 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
 
     if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
         virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
-        n->announce_counter = SELF_ANNOUNCE_ROUNDS;
-        timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
+        qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(),
+                                  QEMU_CLOCK_VIRTUAL,
+                                  virtio_net_announce_timer, n);
+        if (n->announce_timer.round) {
+            timer_mod(n->announce_timer.tm,
+                      qemu_clock_get_ms(n->announce_timer.type));
+        } else {
+            qemu_announce_timer_del(&n->announce_timer);
+        }
     }
 
     return 0;
@@ -2696,8 +2706,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     qemu_macaddr_default_if_unset(&n->nic_conf.macaddr);
     memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
-    n->announce_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
-                                     virtio_net_announce_timer, n);
+    qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(),
+                              QEMU_CLOCK_VIRTUAL,
+                              virtio_net_announce_timer, n);
 
     if (n->netclient_type) {
         /*
@@ -2760,8 +2771,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
         virtio_net_del_queue(n, i);
     }
 
-    timer_del(n->announce_timer);
-    timer_free(n->announce_timer);
+    qemu_announce_timer_del(&n->announce_timer);
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index a1a0be3bea..b96f0c643f 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -17,6 +17,7 @@
 #include "qemu/units.h"
 #include "standard-headers/linux/virtio_net.h"
 #include "hw/virtio/virtio.h"
+#include "net/announce.h"
 
 #define TYPE_VIRTIO_NET "virtio-net-device"
 #define VIRTIO_NET(obj) \
@@ -181,8 +182,7 @@ struct VirtIONet {
     char *netclient_name;
     char *netclient_type;
     uint64_t curr_guest_offloads;
-    QEMUTimer *announce_timer;
-    int announce_counter;
+    AnnounceTimer announce_timer;
     bool needs_vnet_hdr_swap;
     bool mtu_bypass_backend;
 };
-- 
2.20.1

  parent reply	other threads:[~2019-01-28 17:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 17:03 [Qemu-devel] [PATCH 0/9] Network announce changes Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 1/9] net: Introduce announce timer Dr. David Alan Gilbert (git)
2019-01-28 17:42   ` Eric Blake
2019-01-29 11:27     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` [Qemu-devel] [PATCH 2/9] migration: Add announce parameters Dr. David Alan Gilbert (git)
2019-01-28 17:45   ` Eric Blake
2019-01-29 11:34     ` Dr. David Alan Gilbert
2019-02-01 18:17   ` Markus Armbruster
2019-02-04 11:48     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` Dr. David Alan Gilbert (git) [this message]
2019-01-28 17:03 ` [Qemu-devel] [PATCH 4/9] migration: Switch to using announce timer Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 5/9] net: Add a network device specific self-announcement ability Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 6/9] virtio-net: Allow qemu_announce_self to trigger virtio announcements Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 7/9] qmp: Add announce-self command Dr. David Alan Gilbert (git)
2019-01-28 17:47   ` Eric Blake
2019-01-29 11:42     ` Dr. David Alan Gilbert
2019-01-28 17:03 ` [Qemu-devel] [PATCH 8/9] hmp: Add hmp_announce_self Dr. David Alan Gilbert (git)
2019-01-28 17:03 ` [Qemu-devel] [PATCH 9/9] tests: Add a test for qemu self announcments Dr. David Alan Gilbert (git)
2019-01-28 17:05   ` Michael S. Tsirkin
2019-01-29 10:45     ` Dr. David Alan Gilbert
2019-01-28 17:12 ` [Qemu-devel] [PATCH 0/9] Network announce changes Michael S. Tsirkin
2019-01-28 17:25   ` Dr. David Alan Gilbert
2019-02-01 18:07 ` Markus Armbruster
2019-02-04 11:19   ` Dr. David Alan Gilbert
2019-02-03 15:52 ` no-reply

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=20190128170321.16936-4-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@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 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).