From nobody Wed Apr 16 11:38:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551770426002745.3332734907367; Mon, 4 Mar 2019 23:20:26 -0800 (PST) Received: from localhost ([127.0.0.1]:38692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h14N8-000097-Qf for importer@patchew.org; Tue, 05 Mar 2019 02:20:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h14Fp-0002mK-HD for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h14Fo-0000e9-Fv for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h14Fo-0000dh-5q for qemu-devel@nongnu.org; Tue, 05 Mar 2019 02:12:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 691543081256; Tue, 5 Mar 2019 07:12:43 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-234.pek2.redhat.com [10.72.12.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA2CA5C207; Tue, 5 Mar 2019 07:12:39 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 5 Mar 2019 15:12:14 +0800 Message-Id: <1551769940-22739-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1551769940-22739-1-git-send-email-jasowang@redhat.com> References: <1551769940-22739-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 05 Mar 2019 07:12:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL V2 07/13] virtio-net: Switch to using announce timer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" 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 Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/net/trace-events | 5 +++++ hw/net/virtio-net.c | 36 +++++++++++++++++++++++------------- include/hw/virtio/virtio-net.h | 4 ++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index 9d49f62..b237d90 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -359,3 +359,8 @@ 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 6e6b146..38b8974 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" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -152,8 +154,9 @@ static void virtio_net_announce_timer(void *opaque) { VirtIONet *n =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + trace_virtio_net_announce_timer(n->announce_timer.round); =20 - n->announce_counter--; + n->announce_timer.round--; n->status |=3D VIRTIO_NET_S_ANNOUNCE; virtio_notify_config(vdev); } @@ -467,8 +470,8 @@ static void virtio_net_reset(VirtIODevice *vdev) n->nobcast =3D 0; /* multiqueue is disabled by default */ n->curr_queues =3D 1; - timer_del(n->announce_timer); - n->announce_counter =3D 0; + timer_del(n->announce_timer.tm); + n->announce_timer.round =3D 0; n->status &=3D ~VIRTIO_NET_S_ANNOUNCE; =20 /* Flush any MAC and VLAN filter table state */ @@ -964,13 +967,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 =3D=3D VIRTIO_NET_CTRL_ANNOUNCE_ACK && n->status & VIRTIO_NET_S_ANNOUNCE) { n->status &=3D ~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 { @@ -2286,6 +2288,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int i, link_down; =20 + 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)= ); @@ -2322,8 +2325,15 @@ static int virtio_net_post_load_device(void *opaque,= int version_id) =20 if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) && virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { - n->announce_counter =3D SELF_ANNOUNCE_ROUNDS; - timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)= ); + qemu_announce_timer_reset(&n->announce_timer, migrate_announce_par= ams(), + 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); + } } =20 return 0; @@ -2679,8 +2689,9 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) qemu_macaddr_default_if_unset(&n->nic_conf.macaddr); memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); n->status =3D VIRTIO_NET_S_LINK_UP; - n->announce_timer =3D 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); =20 if (n->netclient_type) { /* @@ -2743,8 +2754,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev, Error **errp) virtio_net_del_queue(n, i); } =20 - 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 a1a0be3..b96f0c6 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" =20 #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; }; --=20 2.5.0