Net patches
The following changes since commit b6179aaff961627fcb59d7b234297966b81ac726:
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20190304' into staging (2019-03-04 16:50:41 +0000)
are available in the git repository at:
https://github.com/jasowang/qemu.git tags/net-pull-request
for you to fetch changes up to 4b9b70000218640a42c3ea908a12665e5840b6cd:
tests: Add a test for qemu self announcements (2019-03-05 11:27:41 +0800)
----------------------------------------------------------------
Changes from V1:
- build fixes for qmp controlled announcing
----------------------------------------------------------------
Dr. David Alan Gilbert (9):
net: Introduce announce timer
migration: Add announce parameters
virtio-net: Switch to using announce timer
migration: Switch to using announce timer
net: Add a network device specific self-announcement ability
virtio-net: Allow qemu_announce_self to trigger virtio announcements
qmp: Add announce-self command
hmp: Add hmp_announce_self
tests: Add a test for qemu self announcements
Vincenzo Maffione (3):
net: netmap: small improvements netmap_send()
net: netmap: simplify netmap_receive()
net: netmap: improve netmap_receive_iov()
Zhang Chen (1):
net/colo-compare.c: Remove duplicated code
hmp-commands.hx | 16 +++++ hmp.c | 33 ++++++++++ hmp.h | 1 + hw/net/trace-events | 6 ++ hw/net/virtio-net.c | 69 +++++++++++++++----- include/hw/virtio/virtio-net.h | 4 +- include/migration/misc.h | 12 +--- include/net/announce.h | 41 ++++++++++++ include/net/net.h | 2 + include/qemu/typedefs.h | 1 + include/sysemu/sysemu.h | 2 - migration/migration.c | 103 +++++++++++++++++++++++++++++- migration/migration.h | 4 ++ migration/savevm.c | 72 +-------------------- migration/trace-events | 1 - net/Makefile.objs | 1 + net/announce.c | 140 +++++++++++++++++++++++++++++++++++++++++ net/colo-compare.c | 8 --- net/netmap.c | 110 ++++++++++++++------------------ net/trace-events | 3 + qapi/migration.json | 53 +++++++++++++++- qapi/net.json | 43 +++++++++++++ tests/Makefile.include | 3 + tests/test-announce-self.c | 82 ++++++++++++++++++++++++ tests/test-hmp.c | 1 + 25 files changed, 637 insertions(+), 174 deletions(-) create mode 100644 include/net/announce.h create mode 100644 net/announce.c create mode 100644 tests/test-announce-self.c
[Qemu-devel] [PULL V2 01/13] net/colo-compare.c: Remove duplicated code
From: Zhang Chen <[email protected]>
Fix duplicated code:
https://bugs.launchpad.net/qemu/+bug/1811499
--- net/colo-compare.c | 8 -------- 1 file changed, 8 deletions(-)
net/colo-compare.c +0 -8
@@ -294,14 +294,6 @@ static bool colo_mark_tcp_pkt(Packet *ppkt, Packet *spkt,return true; } } -if (ppkt->tcp_seq == spkt->tcp_seq && ppkt->seq_end == spkt->seq_end) { -if (colo_compare_packet_payload (ppkt, spkt, - ppkt->header_size, spkt->header_size, - ppkt->payload_size)) { - *mark =COLO_COMPARE_FREE_SECONDARY |COLO_COMPARE_FREE_PRIMARY ; -return true; - } - }/* one part of secondary packet payload still need to be compared */ if (!after (ppkt->seq_end, spkt->seq_end)) {
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 02/13] net: netmap: small improvements netmap_send()
In reply to Jason WangFrom: Vincenzo Maffione <[email protected]>
This change improves the handling of incomplete multi-slot packets (e.g. with the NS_MOREFRAG set), by advancing ring->head only on complete packets. The ring->cur pointer is advanced in any case in order to acknowledge the kernel and move the wake-up point (thus avoiding repeated wake-ups).
Also don't be verbose when incomplete packets are found.
--- net/netmap.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
net/netmap.c +19 -12
@@ -272,39 +272,46 @@ static void netmap_send(void *opaque) {NetmapState *s = opaque;struct netmap_ring *ring = s->rx; +unsigned int tail = ring->tail; -/* Keep sending while there are available packets into the netmap +/* Keep sending while there are available slots in the netmap RX ring and the forwarding path towards the peer is open. */ -while (!nm_ring_empty (ring)) { -uint32_t i; +while (ring->head != tail) { +uint32_t i = ring->head;uint32_t idx;bool morefrag;int iovcnt =0 ;int iovsize; +/* Get a (possibly multi-slot) packet. */ do { - i = ring->cur; idx = ring->slot[i].buf_idx; morefrag = (ring->slot[i].flags &NS_MOREFRAG ); - s->iov[iovcnt].iov_base = (u_char *)NETMAP_BUF (ring, idx); + s->iov[iovcnt].iov_base = (void *)NETMAP_BUF (ring, idx); s->iov[iovcnt].iov_len = ring->slot[i].len; iovcnt++; + i =nm_ring_next (ring, i); + }while (i != tail && morefrag); - ring->cur = ring->head =nm_ring_next (ring, i); - }while (!nm_ring_empty (ring) && morefrag); +/* Advance ring->cur to tell the kernel that we have seen the slots. */ + ring->cur = i; -if (unlikely (nm_ring_empty (ring) && morefrag)) { -RD (5 ,"[netmap_send] ran out of slots, with a pending" -"incomplete packet\n" ); +if (unlikely (morefrag)) { +/* This is a truncated packet, so we can stop without releasing the +* incomplete slots by updating ring->head. We will hopefully +* re-read the complete packet the next time we are called. */ +break ; } iovsize =qemu_sendv_packet_async (&s->nc, s->iov, iovcnt, netmap_send_completed); +/* Release the slots to the kernel. */ + ring->head = i; +if (iovsize ==0 ) {/* The peer does not receive anymore. Packet is queued, stop -* reading from the backend until netmap_send_completed() -*/ +* reading from the backend until netmap_send_completed(). */ netmap_read_poll (s, false);break ; }
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 03/13] net: netmap: simplify netmap_receive()
In reply to Jason WangFrom: Vincenzo Maffione <[email protected]>
Improve code reuse by implementing netmap_receive() with a call to netmap_receive_iov().
--- net/netmap.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-)
net/netmap.c +11 -39
@@ -154,45 +154,6 @@ static void netmap_writable(void *opaque)qemu_flush_queued_packets (&s->nc); } -static ssize_t netmap_receive (NetClientState *nc, -const uint8_t *buf,size_t size) -{ -NetmapState *s =DO_UPCAST (NetmapState, nc, nc); -struct netmap_ring *ring = s->tx; -uint32_t i; -uint32_t idx; -uint8_t *dst; - -if (unlikely (!ring)) { -/* Drop. */ -return size; - } - -if (unlikely (size > ring->nr_buf_size)) { -RD (5 ,"[netmap_receive] drop packet of size %d > %d\n" , - (int )size, ring->nr_buf_size); -return size; - } - -if (nm_ring_empty (ring)) { -/* No available slots in the netmap TX ring. */ -netmap_write_poll (s, true); -return 0 ; - } - - i = ring->cur; - idx = ring->slot[i].buf_idx; - dst = (uint8_t *)NETMAP_BUF (ring, idx); - - ring->slot[i].len = size; - ring->slot[i].flags =0 ; -pkt_copy (buf, dst, size); - ring->cur = ring->head =nm_ring_next (ring, i); -ioctl (s->nmd->fd,NIOCTXSYNC ,NULL ); - -return size; -} -static ssize_t netmap_receive_iov (NetClientState *nc,const struct iovec *iov,int iovcnt) {
@@ -259,6 +220,17 @@ static ssize_t netmap_receive_iov(NetClientState *nc,return iov_size (iov, iovcnt); } +static ssize_t netmap_receive (NetClientState *nc, +const uint8_t *buf,size_t size) +{ +struct iovec iov; + + iov.iov_base = (void *)buf; + iov.iov_len = size; + +return netmap_receive_iov (nc, &iov,1 ); +} +/* Complete a previous send (backend --> guest) and enable the fd_read callback. */ static void netmap_send_completed (NetClientState *nc,ssize_t len)
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 04/13] net: netmap: improve netmap_receive_iov()
In reply to Jason WangFrom: Vincenzo Maffione <[email protected]>
Changes:
- Save CPU cycles by computing the return value while scanning the input iovec, rather than calling iov_size() at the end.
- Remove check for s->tx != NULL, because it cannot happen.
- Cache ring->tail in a local variable and use it to check for space in the TX ring. The use of nm_ring_empty() was invalid, because nobody is updating ring->cur and ring->head at that point.
- In case we run out of netmap slots in the middle of a packet,
move the wake-up point by advancing ring->cur, but do not
expose the incomplete packet (i.e., by updating also ring->head).--- net/netmap.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
net/netmap.c +17 -12
@@ -159,21 +159,22 @@ static ssize_t netmap_receive_iov(NetClientState *nc, {NetmapState *s =DO_UPCAST (NetmapState, nc, nc);struct netmap_ring *ring = s->tx; +unsigned int tail = ring->tail; +ssize_t totlen =0 ;uint32_t last;uint32_t idx;uint8_t *dst;int j;uint32_t i; -if (unlikely (!ring)) { -/* Drop the packet. */ -return iov_size (iov, iovcnt); - } - - last = i = ring->cur; + last = i = ring->head;if (nm_ring_space (ring) < iovcnt) { -/* Not enough netmap slots. */ +/* Not enough netmap slots. Tell the kernel that we have seen the new +* available slots (so that it notifies us again when it has more +* ones), but without publishing any new slots to be processed +* (e.g., we don't advance ring->head). */ + ring->cur = tail;netmap_write_poll (s, true);return 0 ; }
@@ -183,14 +184,17 @@ static ssize_t netmap_receive_iov(NetClientState *nc,int offset =0 ;int nm_frag_size; + totlen += iov_frag_size; +/* Split each iovec fragment over more netmap slots, if necessary. */ while (iov_frag_size) { nm_frag_size =MIN (iov_frag_size, ring->nr_buf_size); -if (unlikely (nm_ring_empty (ring))) { -/* We run out of netmap slots while splitting the +if (unlikely (i == tail)) { +/* We ran out of netmap slots while splitting the iovec fragments. */ + ring->cur = tail;netmap_write_poll (s, true);return 0 ; }
@@ -212,12 +216,13 @@ static ssize_t netmap_receive_iov(NetClientState *nc,/* The last slot must not have NS_MOREFRAG set. */ ring->slot[last].flags &= ~NS_MOREFRAG ; -/* Now update ring->cur and ring->head. */ - ring->cur = ring->head = i; +/* Now update ring->head and ring->cur to publish the new slots and +* the new wakeup point. */ + ring->head = ring->cur = i;ioctl (s->nmd->fd,NIOCTXSYNC ,NULL ); -return iov_size (iov, iovcnt); +return totlen; } static ssize_t netmap_receive(NetClientState *nc,
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 05/13] net: Introduce announce timer
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
The 'announce timer' will be used by migration, and explicit requests for qemu to perform network announces.
Based on the work by Germano Veit Michel <[email protected]>
and Vlad Yasevich <[email protected]>
--- include/net/announce.h | 39 ++++++++++++++++++++++++++++++++ include/qemu/typedefs.h | 1 + migration/migration.c | 1 + net/Makefile.objs | 1 + net/announce.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ qapi/net.json | 23 +++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 include/net/announce.h create mode 100644 net/announce.c
include/net/announce.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Self-announce facility +* (c) 2017-2019 Red Hat, Inc. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_NET_ANNOUNCE_H +#define QEMU_NET_ANNOUNCE_H + +#include "qemu-common.h" +#include "qapi/qapi-types-net.h" +#include "qemu/timer.h" + +struct AnnounceTimer { +QEMUTimer *tm; +AnnounceParameters params; +QEMUClockType type; +int round; +}; + +/* Returns: update the timer to the next time point */ +int64_t qemu_announce_timer_step (AnnounceTimer *timer); + +/* Delete the underlying timer */ +void qemu_announce_timer_del (AnnounceTimer *timer); + +/* +* Under BQL/main thread +* Reset the timer to the given parameters/type/notifier. +*/ +void qemu_announce_timer_reset (AnnounceTimer *timer, +AnnounceParameters *params, +QEMUClockType type, +QEMUTimerCB *cb, +void *opaque); + +#endif
include/qemu/typedefs.h +1 -0
@@ -8,6 +8,7 @@typedef struct AdapterInfo AdapterInfo ;typedef struct AddressSpace AddressSpace ;typedef struct AioContext AioContext ; +typedef struct AnnounceTimer AnnounceTimer ;typedef struct BdrvDirtyBitmap BdrvDirtyBitmap ;typedef struct BdrvDirtyBitmapIter BdrvDirtyBitmapIter ;typedef struct BlockBackend BlockBackend ;
migration/migration.c +1 -0
@@ -45,6 +45,7 @@#include "migration/colo.h" #include "hw/boards.h" #include "monitor/monitor.h" +#include "net/announce.h" #define MAX_THROTTLE (32 << 20)/* Migration transfer speed throttling */
net/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o common-obj-y += socket.o common-obj-y += dump.o common-obj-y += eth.o +common-obj-y += announce.o common-obj-$(CONFIG_L2TPV3) += l2tpv3.o common-obj-$(call land,$(CONFIG_VIRTIO_NET),$(CONFIG_VHOST_NET_USER)) += vhost-user.o common-obj-$(call land,$(call lnot,$(CONFIG_VIRTIO_NET)),$(CONFIG_VHOST_NET_USER)) += vhost-user-stub.o
net/announce.c new file +60 -0
60 lines not on this page · raw message
qapi/net.json +23 -0
@@ -684,3 +684,26 @@ ## { 'event': 'NIC_RX_FILTER_CHANGED', 'data': { '*name': 'str', 'path': 'str' } } + +## +# @AnnounceParameters: +# +# Parameters for self-announce timers +# +# @initial: Initial delay (in ms) before sending the first GARP/RARP +# announcement +# +# @max: Maximum delay (in ms) between GARP/RARP announcement packets +# +# @rounds: Number of self-announcement attempts +# +# @step: Delay increase (in ms) after each self-announcement attempt +# +# Since: 4.0 +## + +{ 'struct': 'AnnounceParameters', + 'data': { 'initial': 'int', + 'max': 'int', + 'rounds': 'int', + 'step': 'int' } }
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 06/13] migration: Add announce parameters
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Add migration parameters that control RARP/GARP announcement timeouts.
Based on earlier patches by myself and
Vladislav Yasevich <[email protected]>
--- hmp.c | 28 +++++++++++++ include/migration/misc.h | 2 + migration/migration.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ qapi/migration.json | 53 +++++++++++++++++++++++-- 4 files changed, 180 insertions(+), 3 deletions(-)
hmp.c +28 -0
@@ -334,6 +334,18 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) params =qmp_query_migrate_parameters (NULL );if (params) { +monitor_printf (mon,"%s: %" PRIu64" ms\n" , +MigrationParameter_str (MIGRATION_PARAMETER_ANNOUNCE_INITIAL ), + params->announce_initial); +monitor_printf (mon,"%s: %" PRIu64" ms\n" , +MigrationParameter_str (MIGRATION_PARAMETER_ANNOUNCE_MAX ), + params->announce_max); +monitor_printf (mon,"%s: %" PRIu64"\n" , +MigrationParameter_str (MIGRATION_PARAMETER_ANNOUNCE_ROUNDS ), + params->announce_rounds); +monitor_printf (mon,"%s: %" PRIu64" ms\n" , +MigrationParameter_str (MIGRATION_PARAMETER_ANNOUNCE_STEP ), + params->announce_step);assert (params->has_compress_level); monitor_printf(mon, "%s: %u\n", MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
@@ -1757,6 +1769,22 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_max_postcopy_bandwidth = true;visit_type_size (v, param, &p->max_postcopy_bandwidth, &err);break ; +case MIGRATION_PARAMETER_ANNOUNCE_INITIAL : + p->has_announce_initial = true; +visit_type_size (v, param, &p->announce_initial, &err); +break ; +case MIGRATION_PARAMETER_ANNOUNCE_MAX : + p->has_announce_max = true; +visit_type_size (v, param, &p->announce_max, &err); +break ; +case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS : + p->has_announce_rounds = true; +visit_type_size (v, param, &p->announce_rounds, &err); +break ; +case MIGRATION_PARAMETER_ANNOUNCE_STEP : + p->has_announce_step = true; +visit_type_size (v, param, &p->announce_step, &err); +break ;default :assert (0 ); }
include/migration/misc.h +2 -0
@@ -15,6 +15,7 @@#define MIGRATION_MISC_H #include "qemu/notify.h" +#include "qapi/qapi-types-net.h" /* migration/ram.c */
@@ -38,6 +39,7 @@ int64_t self_announce_delay(int round)return 50 + (SELF_ANNOUNCE_ROUNDS - round -1 ) *100 ; } +AnnounceParameters *migrate_announce_params (void );/* migration/savevm.c */ void dump_vmstate_json_to_file (FILE *out_fp);
migration/migration.c +100 -0
146 lines not on this page · raw message
qapi/migration.json +50 -3
92 lines not on this page · raw message
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 07/13] virtio-net: Switch to using announce timer
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
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 <[email protected]>
--- 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(-)
hw/net/trace-events +5 -0
@@ -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)
hw/net/virtio-net.c +23 -13
@@ -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
@@ -152,8 +154,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); }
@@ -467,8 +470,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 */
@@ -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 ==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 {
@@ -2286,6 +2288,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 ));
@@ -2322,8 +2325,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 ;
@@ -2679,8 +2689,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) {/*
@@ -2743,8 +2754,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);
include/hw/virtio/virtio-net.h +2 -2
@@ -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; };
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 08/13] migration: Switch to using announce timer
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Switch the announcements to using the new announce timer. Move the code that does it to announce.c rather than savevm because it really has nothing to do with the actual migration.
Migration starts the announce from bh's and so they're all in the main thread/bql, and so there's never any racing with the timers themselves.
--- include/migration/misc.h | 10 ------- include/net/announce.h | 2 ++ include/sysemu/sysemu.h | 2 -- migration/migration.c | 2 +- migration/migration.h | 4 +++ migration/savevm.c | 72 ++---------------------------------------------- migration/trace-events | 1 - net/announce.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ net/trace-events | 3 ++ 9 files changed, 81 insertions(+), 83 deletions(-)
include/migration/misc.h +0 -10
@@ -29,16 +29,6 @@ void blk_mig_init(void);static inline void blk_mig_init (void ) {}#endif -#define SELF_ANNOUNCE_ROUNDS 5 - -static inline -int64_t self_announce_delay (int round) -{ -assert (round <SELF_ANNOUNCE_ROUNDS && round >0 ); -/* delay 50ms, 150ms, 250ms, ... */ -return 50 + (SELF_ANNOUNCE_ROUNDS - round -1 ) *100 ; -} -AnnounceParameters *migrate_announce_params (void );/* migration/savevm.c */
include/net/announce.h +2 -0
@@ -36,4 +36,6 @@ void qemu_announce_timer_reset(AnnounceTimer *timer, QEMUTimerCB *cb, void *opaque); +void qemu_announce_self (AnnounceTimer *timer,AnnounceParameters *params); +#endif
include/sysemu/sysemu.h +0 -2
@@ -81,8 +81,6 @@ extern bool machine_init_done;void qemu_add_machine_init_done_notifier (Notifier *notify);void qemu_remove_machine_init_done_notifier (Notifier *notify); -void qemu_announce_self (void ); -extern int autostart; typedef enum {
migration/migration.c +1 -1
@@ -374,7 +374,7 @@ static void process_incoming_migration_bh(void *opaque)* This must happen after all error conditions are dealt with and * we're sure the VM is going to be running on this host. */ -qemu_announce_self (); +qemu_announce_self (&mis->announce_timer,migrate_announce_params ());if (multifd_load_cleanup (&local_err) !=0 ) {error_report_err (local_err);
migration/migration.h +4 -0
@@ -21,6 +21,7 @@#include "qemu/coroutine_int.h" #include "hw/qdev.h" #include "io/channel.h" +#include "net/announce.h" struct PostcopyBlocktimeContext ;
@@ -36,6 +37,9 @@ struct MigrationIncomingState {*/ QemuEvent main_thread_load_event; +/* For network announces */ +AnnounceTimer announce_timer; +size_t largest_page_size;bool have_fault_thread;QemuThread fault_thread;
migration/savevm.c +3 -69
96 lines not on this page · raw message
migration/trace-events +0 -1
@@ -52,7 +52,6 @@ vmstate_save_state_top(const char *idstr) "%s" vmstate_subsection_save_loop(const char *name, const char *sub) "%s/%s" vmstate_subsection_save_top(const char *idstr) "%s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" -qemu_announce_self_iter(const char *mac) "%s" # migration/vmstate.c vmstate_load_field_error(const char *field, int ret) "field \"%s\" load failed, ret = %d"
net/announce.c +68 -0
79 lines not on this page · raw message
net/trace-events +3 -0
@@ -1,5 +1,8 @@ # See docs/devel/tracing.txt for syntax documentation. +# net/announce.c +qemu_announce_self_iter(const char *mac) "%s" + # net/vhost-user.c vhost_user_event(const char *chr, int event) "chr: %s got event: %d"
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 09/13] net: Add a network device specific self-announcement ability
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Some network devices have a capability to do self announcements (ex: virtio-net). Add infrastructure that would allow devices to expose this ability.
--- include/net/net.h | 2 ++ net/announce.c | 5 +++++ 2 files changed, 7 insertions(+)
include/net/net.h +2 -0
@@ -60,6 +60,7 @@ typedef int (SetVnetLE)(NetClientState *, bool);typedef int (SetVnetBE )(NetClientState *,bool );typedef struct SocketReadState SocketReadState ;typedef void (SocketReadStateFinalize )(SocketReadState *rs); +typedef void (NetAnnounce )(NetClientState *); typedef struct NetClientInfo { NetClientDriver type;
@@ -80,6 +81,7 @@ typedef struct NetClientInfo {SetVnetHdrLen *set_vnet_hdr_len;SetVnetLE *set_vnet_le;SetVnetBE *set_vnet_be; +NetAnnounce *announce; } NetClientInfo;struct NetClientState {
net/announce.c +5 -0
@@ -102,6 +102,11 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque) len =announce_self_create (buf, nic->conf->macaddr.a);qemu_send_packet_raw (qemu_get_queue (nic), buf, len); + +/* if the NIC provides it's own announcement support, use it as well */ +if (nic->ncs->info->announce) { + nic->ncs->info->announce (nic->ncs); + } }static void qemu_announce_self_once (void *opaque) {
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 10/13] virtio-net: Allow qemu_announce_self to trigger virtio announcements
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Expose the virtio-net self announcement capability and allow qemu_announce_self() to call it.
These announces are caused by something external (i.e. the announce-self command); they won't trigger if the migration counter is triggering announces at the same time.
--- hw/net/trace-events | 1 + hw/net/virtio-net.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-)
hw/net/trace-events +1 -0
@@ -361,6 +361,7 @@ sunhme_rx_desc(uint32_t addr, int offset, uint32_t status, int len, int cr, int sunhme_rx_xsum_calc(uint16_t xsum) "calculated incoming xsum as 0x%x" # hw/net/virtio-net.c +virtio_net_announce_notify(void) "" virtio_net_announce_timer(int round) "%d" virtio_net_handle_announce(int round) "%d" virtio_net_post_load_device(void)
hw/net/virtio-net.c +32 -3
@@ -150,15 +150,42 @@ static bool virtio_net_started(VirtIONet *n, uint8_t status) (n->status &VIRTIO_NET_S_LINK_UP ) && vdev->vm_running; } +static void virtio_net_announce_notify (VirtIONet *net) +{ +VirtIODevice *vdev =VIRTIO_DEVICE (net); +trace_virtio_net_announce_notify (); + + net->status |=VIRTIO_NET_S_ANNOUNCE ; +virtio_notify_config (vdev); +} +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_timer.round--; - n->status |=VIRTIO_NET_S_ANNOUNCE ; -virtio_notify_config (vdev); +virtio_net_announce_notify (n); +} + +static void virtio_net_announce (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +VirtIODevice *vdev =VIRTIO_DEVICE (n); + +/* +* Make sure the virtio migration announcement timer isn't running +* If it is, let it trigger announcement so that we do not cause +* confusion. +*/ +if (n->announce_timer.round) { +return ; + } + +if (virtio_vdev_has_feature (vdev,VIRTIO_NET_F_GUEST_ANNOUNCE ) && +virtio_vdev_has_feature (vdev,VIRTIO_NET_F_CTRL_VQ )) { +virtio_net_announce_notify (n); + } }static void virtio_net_vhost_status (VirtIONet *n,uint8_t status)
@@ -2556,6 +2583,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .link_status_changed = virtio_net_set_link_status, .query_rx_filter = virtio_net_query_rxfilter, + .announce = virtio_net_announce, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)
@@ -2692,6 +2720,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)qemu_announce_timer_reset (&n->announce_timer,migrate_announce_params (),QEMU_CLOCK_VIRTUAL , virtio_net_announce_timer, n); + n->announce_timer.round =0 ;if (n->netclient_type) {/*
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 11/13] qmp: Add announce-self command
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Add a qmp command that can trigger guest announcements.
It uses its own announce-timer instance, and parameters passed to it explicitly in the command.
Like most qmp commands, it's in the main thread/bql, so there's no racing with any outstanding timer.
Based on work of Germano Veit Michel <[email protected]> and
Vladislav Yasevich <[email protected]>
--- net/announce.c | 7 +++++++ qapi/net.json | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+)
net/announce.c +7 -0
@@ -12,6 +12,7 @@#include "net/net.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-net.h" +#include "qapi/qapi-commands-net.h" #include "trace.h" int64_t qemu_announce_timer_step (AnnounceTimer *timer)
@@ -131,3 +132,9 @@ void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params)qemu_announce_timer_del (timer); } } + +void qmp_announce_self (AnnounceParameters *params,Error **errp) +{ +static AnnounceTimer announce_timer; +qemu_announce_self (&announce_timer, params); +}
qapi/net.json +20 -0
@@ -707,3 +707,23 @@ 'max': 'int', 'rounds': 'int', 'step': 'int' } } + +## +# @announce-self: +# +# Trigger generation of broadcast RARP frames to update network switches. +# This can be useful when network bonds fail-over the active slave. +# +# @params: AnnounceParameters giving timing and repetition count of announce +# +# Example: +# +# -> { "execute": "announce-self" +# "arguments": { +# "initial": 50, "max": 550, "rounds": 10, "step": 50 } } +# <- { "return": {} } +# +# Since: 4.0 +## +{ 'command': 'announce-self', 'boxed': true, + 'data' : 'AnnounceParameters'}
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 12/13] hmp: Add hmp_announce_self
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
Add an HMP command to trigger self annocements.
Unlike the QMP command (which takes a set of parameters), the HMP command reuses the set of parameters used for migration.
--- hmp-commands.hx | 16 ++++++++++++++++ hmp.c | 5 +++++ hmp.h | 1 + tests/test-hmp.c | 1 + 4 files changed, 23 insertions(+)
hmp-commands.hx +16 -0
@@ -939,6 +939,22 @@ stops because the size limit is reached. ETEXI { + .name = "announce_self", + .args_type = "", + .params = "", + .help = "Trigger GARP/RARP announcements", + .cmd = hmp_announce_self, + }, + +STEXI +@item announce_self +@findex announce_self +Trigger a round of GARP/RARP broadcasts; this is useful for explicitly updating the +network infrastructure after a reconfiguration or some forms of migration. +The timings of the round are set by the migration announce parameters. +ETEXI + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,resume:-r,uri:s", .params = "[-d] [-b] [-i] [-r] uri",
hmp.c +5 -0
@@ -1570,6 +1570,11 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict) } +void hmp_announce_self (Monitor *mon,const QDict *qdict) +{ +qmp_announce_self (migrate_announce_params (),NULL ); +} +void hmp_migrate_cancel (Monitor *mon,const QDict *qdict) {qmp_migrate_cancel (NULL );
hmp.h +1 -0
@@ -46,6 +46,7 @@ void hmp_sync_profile(Monitor *mon, const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);void hmp_system_powerdown (Monitor *mon,const QDict *qdict);void hmp_exit_preconfig (Monitor *mon,const QDict *qdict); +void hmp_announce_self (Monitor *mon,const QDict *qdict);void hmp_cpu (Monitor *mon,const QDict *qdict);void hmp_memsave (Monitor *mon,const QDict *qdict);void hmp_pmemsave (Monitor *mon,const QDict *qdict);
tests/test-hmp.c +1 -0
@@ -20,6 +20,7 @@static int verbose;static const char *hmp_cmds[] = { +"announce_self" ,"boot_set ndc" ,"chardev-add null,id=testchardev1" ,"chardev-send-break testchardev1" ,
Signature · 1 line
2.5.0
[Qemu-devel] [PULL V2 13/13] tests: Add a test for qemu self announcements
In reply to Jason WangFrom: "Dr. David Alan Gilbert" <[email protected]>
We now expose qemu_announce_self through QMP and HMP. Add a test with some very basic packet validation (make sure we get a RARP).
--- tests/Makefile.include | 3 ++ tests/test-announce-self.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/test-announce-self.c
tests/Makefile.include +3 -0
@@ -225,6 +225,7 @@ check-qtest-i386-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF) check-qtest-i386-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF) check-qtest-i386-$(CONFIG_RTL8139_PCI) += tests/test-filter-redirector$(EXESUF) check-qtest-i386-y += tests/migration-test$(EXESUF) +check-qtest-i386-y += tests/test-announce-self$(EXESUF) check-qtest-i386-y += tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y += tests/numa-test$(EXESUF) check-qtest-x86_64-y += $(check-qtest-i386-y)
@@ -263,6 +264,7 @@ check-qtest-ppc64-$(CONFIG_PSERIES) += tests/spapr-phb-test$(EXESUF) check-qtest-ppc64-$(CONFIG_PSERIES) += tests/device-plug-test$(EXESUF) check-qtest-ppc64-$(CONFIG_POWERNV) += tests/pnv-xscom-test$(EXESUF) check-qtest-ppc64-y += tests/migration-test$(EXESUF) +check-qtest-ppc64-y += tests/test-announce-self$(EXESUF) check-qtest-ppc64-$(CONFIG_PSERIES) += tests/rtas-test$(EXESUF) check-qtest-ppc64-$(CONFIG_SLIRP) += tests/pxe-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_OHCI) += tests/usb-hcd-ohci-test$(EXESUF)
@@ -779,6 +781,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o tests/migration-test$(EXESUF): tests/migration-test.o +tests/test-announce-self$(EXESUF): tests/test-announce-self.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \ $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \ $(chardev-obj-y)
tests/test-announce-self.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.5.0
Peter Maydell
AppliedQuoted 9 lines · Jason Wang
The following changes since commit
b6179aaff961627fcb59d7b234297966b81ac726:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20190304' into staging (2019-03-04 16:50:41 +0000)
are available in the git repository at:
https://github.com/jasowang/qemu.git tags/net-pull-request
Quoted 9 lines
for you to fetch changes up to
4b9b70000218640a42c3ea908a12665e5840b6cd:tests: Add a test for qemu self announcements (2019-03-05 11:27:41 +0800)
----------------------------------------------------------------
Changes from V1:
- build fixes for qmp controlled announcing
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.
-- PMM
Quoted 18 lines · Peter Maydell
Quoted 8 lines · Jason Wang
The following changes since commit
b6179aaff961627fcb59d7b234297966b81ac726:Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20190304' into staging (2019-03-04 16:50:41 +0000)are available in the git repository at:
https://github.com/jasowang/qemu.git tags/net-pull-request
Quoted 9 lines
for you to fetch changes up to
4b9b70000218640a42c3ea908a12665e5840b6cd:tests: Add a test for qemu self announcements (2019-03-05 11:27:41 +0800)
----------------------------------------------------------------
Changes from V1:
- build fixes for qmp controlled announcing
Quoted 6 lines
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.-- PMM
Done.
Thanks