From patchwork Fri Feb 22 14:55:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445b5z3CHcz9s9L for ; Sat, 23 Feb 2019 02:36:07 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCrt-00054z-9w for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:36:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHI-0000S1-Qy for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF3-0007En-76 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:55:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54008) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF0-0006FV-MH for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:55:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35831306100B; Fri, 22 Feb 2019 14:55:26 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F0A51A7DF; Fri, 22 Feb 2019 14:55:24 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:08 +0800 Message-Id: <1550847320-25110-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 22 Feb 2019 14:55:26 +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 01/13] net/colo-compare.c: Remove duplicated code 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: Zhang Chen , Jason Wang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen Fix duplicated code: https://bugs.launchpad.net/qemu/+bug/1811499 Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud̩ Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 3e515f3..bf10526 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -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)) { From patchwork Fri Feb 22 14:55:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445Zyp00Kzz9s9L for ; Sat, 23 Feb 2019 02:29:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxClr-0000HK-TI for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:29:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCH5-0000QT-Eb for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF6-0007gg-GL for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF6-0006H9-3X for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E4F530C1A41; Fri, 22 Feb 2019 14:55:28 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B80531A7DD; Fri, 22 Feb 2019 14:55:26 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:09 +0800 Message-Id: <1550847320-25110-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 22 Feb 2019 14:55:28 +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 02/13] net: Introduce 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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 and Vlad Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- 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 diff --git a/include/net/announce.h b/include/net/announce.h new file mode 100644 index 0000000..b89f1c2 --- /dev/null +++ b/include/net/announce.h @@ -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 diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 5d1a2d8..e4a0a65 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -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; diff --git a/migration/migration.c b/migration/migration.c index 37e06b7..a9c4c6f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -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 */ diff --git a/net/Makefile.objs b/net/Makefile.objs index b2bf88a..b363fe9 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -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-$(CONFIG_POSIX) += vhost-user.o common-obj-$(CONFIG_SLIRP) += slirp.o diff --git a/net/announce.c b/net/announce.c new file mode 100644 index 0000000..8876eb6 --- /dev/null +++ b/net/announce.c @@ -0,0 +1,60 @@ +/* + * Self-announce + * (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. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "net/announce.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-net.h" + +int64_t qemu_announce_timer_step(AnnounceTimer *timer) +{ + int64_t step; + + step = timer->params.initial + + (timer->params.rounds - timer->round - 1) * + timer->params.step; + + if (step < 0 || step > timer->params.max) { + step = timer->params.max; + } + timer_mod(timer->tm, qemu_clock_get_ms(timer->type) + step); + + return step; +} + +void qemu_announce_timer_del(AnnounceTimer *timer) +{ + if (timer->tm) { + timer_del(timer->tm); + timer_free(timer->tm); + timer->tm = NULL; + } +} + +/* + * 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) +{ + /* + * We're under the BQL, so the current timer can't + * be firing, so we should be able to delete it. + */ + qemu_announce_timer_del(timer); + + QAPI_CLONE_MEMBERS(AnnounceParameters, &timer->params, params); + timer->round = params->rounds; + timer->type = type; + timer->tm = timer_new_ms(type, cb, opaque); +} diff --git a/qapi/net.json b/qapi/net.json index a1a0f39..5face0c 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -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' } } From patchwork Fri Feb 22 14:55:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445b1v6MW0z9s9L for ; Sat, 23 Feb 2019 02:32:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCoT-0002Pq-MJ for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:32:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHI-0000Vn-RQ for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF2-0007D7-7O for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:55:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57598) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCEz-0006Jz-Sa for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:55:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9E0230C194A; Fri, 22 Feb 2019 14:55:30 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF3CE1A836; Fri, 22 Feb 2019 14:55:28 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:10 +0800 Message-Id: <1550847320-25110-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 22 Feb 2019 14:55:30 +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 03/13] migration: Add announce parameters 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" Add migration parameters that control RARP/GARP announcement timeouts. Based on earlier patches by myself and Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Acked-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hmp.c | 28 +++++++++++++ include/migration/misc.h | 2 + migration/migration.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ qapi/migration.json | 53 +++++++++++++++++++++++-- 4 files changed, 180 insertions(+), 3 deletions(-) diff --git a/hmp.c b/hmp.c index 1e006ee..f3db0bf 100644 --- a/hmp.c +++ b/hmp.c @@ -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); } diff --git a/include/migration/misc.h b/include/migration/misc.h index 4ebf24c..e837ab3 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -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); diff --git a/migration/migration.c b/migration/migration.c index a9c4c6f..ca9c35a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -87,6 +87,15 @@ */ #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0 +/* + * Parameters for self_announce_delay giving a stream of RARP/ARP + * packets after migration. + */ +#define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50 +#define DEFAULT_MIGRATE_ANNOUNCE_MAX 550 +#define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5 +#define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 + static NotifierList migration_state_notifiers = NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); @@ -740,10 +749,32 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth; params->has_max_cpu_throttle = true; params->max_cpu_throttle = s->parameters.max_cpu_throttle; + params->has_announce_initial = true; + params->announce_initial = s->parameters.announce_initial; + params->has_announce_max = true; + params->announce_max = s->parameters.announce_max; + params->has_announce_rounds = true; + params->announce_rounds = s->parameters.announce_rounds; + params->has_announce_step = true; + params->announce_step = s->parameters.announce_step; return params; } +AnnounceParameters *migrate_announce_params(void) +{ + static AnnounceParameters ap; + + MigrationState *s = migrate_get_current(); + + ap.initial = s->parameters.announce_initial; + ap.max = s->parameters.announce_max; + ap.rounds = s->parameters.announce_rounds; + ap.step = s->parameters.announce_step; + + return Š+} + /* * Return true if we're already in the middle of a migration * (i.e. any of the active or setup states) @@ -1117,6 +1148,35 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp) return false; } + if (params->has_announce_initial && + params->announce_initial > 100000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_initial", + "is invalid, it must be less than 100000 ms"); + return false; + } + if (params->has_announce_max && + params->announce_max > 100000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_max", + "is invalid, it must be less than 100000 ms"); + return false; + } + if (params->has_announce_rounds && + params->announce_rounds > 1000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_rounds", + "is invalid, it must be in the range of 0 to 1000"); + return false; + } + if (params->has_announce_step && + (params->announce_step < 1 || + params->announce_step > 10000)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_step", + "is invalid, it must be in the range of 1 to 10000 ms"); + return false; + } return true; } @@ -1191,6 +1251,18 @@ static void migrate_params_test_apply(MigrateSetParameters *params, if (params->has_max_cpu_throttle) { dest->max_cpu_throttle = params->max_cpu_throttle; } + if (params->has_announce_initial) { + dest->announce_initial = params->announce_initial; + } + if (params->has_announce_max) { + dest->announce_max = params->announce_max; + } + if (params->has_announce_rounds) { + dest->announce_rounds = params->announce_rounds; + } + if (params->has_announce_step) { + dest->announce_step = params->announce_step; + } } static void migrate_params_apply(MigrateSetParameters *params, Error **errp) @@ -1273,6 +1345,18 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) if (params->has_max_cpu_throttle) { s->parameters.max_cpu_throttle = params->max_cpu_throttle; } + if (params->has_announce_initial) { + s->parameters.announce_initial = params->announce_initial; + } + if (params->has_announce_max) { + s->parameters.announce_max = params->announce_max; + } + if (params->has_announce_rounds) { + s->parameters.announce_rounds = params->announce_rounds; + } + if (params->has_announce_step) { + s->parameters.announce_step = params->announce_step; + } } void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) @@ -3275,6 +3359,18 @@ static Property migration_properties[] = { DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState, parameters.max_cpu_throttle, DEFAULT_MIGRATE_MAX_CPU_THROTTLE), + DEFINE_PROP_SIZE("announce-initial", MigrationState, + parameters.announce_initial, + DEFAULT_MIGRATE_ANNOUNCE_INITIAL), + DEFINE_PROP_SIZE("announce-max", MigrationState, + parameters.announce_max, + DEFAULT_MIGRATE_ANNOUNCE_MAX), + DEFINE_PROP_SIZE("announce-rounds", MigrationState, + parameters.announce_rounds, + DEFAULT_MIGRATE_ANNOUNCE_ROUNDS), + DEFINE_PROP_SIZE("announce-step", MigrationState, + parameters.announce_step, + DEFAULT_MIGRATE_ANNOUNCE_STEP), /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -3347,6 +3443,10 @@ static void migration_instance_init(Object *obj) params->has_xbzrle_cache_size = true; params->has_max_postcopy_bandwidth = true; params->has_max_cpu_throttle = true; + params->has_announce_initial = true; + params->has_announce_max = true; + params->has_announce_rounds = true; + params->has_announce_step = true; qemu_sem_init(&ms->postcopy_pause_sem, 0); qemu_sem_init(&ms->postcopy_pause_rp_sem, 0); diff --git a/qapi/migration.json b/qapi/migration.json index 7a795ec..1fd7bbe 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -480,6 +480,18 @@ # # Migration parameters enumeration # +# @announce-initial: Initial delay (in milliseconds) before sending the first +# announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: Set the compression level to be used in live migration, # the compression level is an integer between 0 and 9, where 0 means # no compression, 1 means the best compression speed, and 9 means best @@ -557,10 +569,13 @@ # # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', - 'data': ['compress-level', 'compress-threads', 'decompress-threads', + 'data': ['announce-initial', 'announce-max', + 'announce-rounds', 'announce-step', + 'compress-level', 'compress-threads', 'decompress-threads', 'compress-wait-thread', 'cpu-throttle-initial', 'cpu-throttle-increment', 'tls-creds', 'tls-hostname', 'max-bandwidth', @@ -572,6 +587,18 @@ ## # @MigrateSetParameters: # +# @announce-initial: Initial delay (in milliseconds) before sending the first +# announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: compression level # # @compress-threads: compression thread count @@ -653,7 +680,11 @@ # TODO either fuse back into MigrationParameters, or make # MigrationParameters members mandatory { 'struct': 'MigrateSetParameters', - 'data': { '*compress-level': 'int', + 'data': { '*announce-initial': 'size', + '*announce-max': 'size', + '*announce-rounds': 'size', + '*announce-step': 'size', + '*compress-level': 'int', '*compress-threads': 'int', '*compress-wait-thread': 'bool', '*decompress-threads': 'int', @@ -692,6 +723,18 @@ # # The optional members aren't actually optional. # +# @announce-initial: Initial delay (in milliseconds) before sending the +# first announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: compression level # # @compress-threads: compression thread count @@ -769,7 +812,11 @@ # Since: 2.4 ## { 'struct': 'MigrationParameters', - 'data': { '*compress-level': 'uint8', + 'data': { '*announce-initial': 'size', + '*announce-max': 'size', + '*announce-rounds': 'size', + '*announce-step': 'size', + '*compress-level': 'uint8', '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', '*decompress-threads': 'uint8', From patchwork Fri Feb 22 14:55:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZrP1wtLz9s5c for ; Sat, 23 Feb 2019 02:24:21 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCgV-0004J8-3X for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:24:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHG-0000Sd-Sc for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF7-0007lC-Ho for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF7-0006Ml-0U for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0247659AC; Fri, 22 Feb 2019 14:55:32 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 352E41A7DF; Fri, 22 Feb 2019 14:55:30 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:11 +0800 Message-Id: <1550847320-25110-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 22 Feb 2019 14:55:32 +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 04/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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 3f319ef..b50f86d 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 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" #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; }; From patchwork Fri Feb 22 14:55:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZHQ1hhXz9s9T for ; Sat, 23 Feb 2019 01:59:14 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCIC-0000cN-3R for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 09:59:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHB-0000QT-As for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF8-0007tY-Vo for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55326) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF8-0006PI-FR for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2752D7F746; Fri, 22 Feb 2019 14:55:35 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D48C28540; Fri, 22 Feb 2019 14:55:33 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:12 +0800 Message-Id: <1550847320-25110-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 22 Feb 2019 14:55:35 +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 05/13] migration: 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- 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(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index e837ab3..0471e04 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -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 */ diff --git a/include/net/announce.h b/include/net/announce.h index b89f1c2..892d302 100644 --- a/include/net/announce.h +++ b/include/net/announce.h @@ -36,4 +36,6 @@ void qemu_announce_timer_reset(AnnounceTimer *timer, QEMUTimerCB *cb, void *opaque); +void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params); + #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4b5a6b7..89604a8 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -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 { diff --git a/migration/migration.c b/migration/migration.c index ca9c35a..c39d305 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -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); diff --git a/migration/migration.h b/migration/migration.h index dcd05d9..c99154d 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -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; diff --git a/migration/savevm.c b/migration/savevm.c index 3226604..b3868f7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -57,13 +57,7 @@ #include "sysemu/replay.h" #include "qjson.h" #include "migration/colo.h" - -#ifndef ETH_P_RARP -#define ETH_P_RARP 0x8035 -#endif -#define ARP_HTYPE_ETH 0x0001 -#define ARP_PTYPE_IP 0x0800 -#define ARP_OP_REQUEST_REV 0x3 +#include "net/announce.h" const unsigned int postcopy_ram_discard_version = 0; @@ -125,67 +119,6 @@ static struct mig_cmd_args { * generic extendable format with an exception for two old entities. */ -static int announce_self_create(uint8_t *buf, - uint8_t *mac_addr) -{ - /* Ethernet header. */ - memset(buf, 0xff, 6); /* destination MAC addr */ - memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ - *(uint16_t *)(buf + 12) = htons(ETH_P_RARP); /* ethertype */ - - /* RARP header. */ - *(uint16_t *)(buf + 14) = htons(ARP_HTYPE_ETH); /* hardware addr space */ - *(uint16_t *)(buf + 16) = htons(ARP_PTYPE_IP); /* protocol addr space */ - *(buf + 18) = 6; /* hardware addr length (ethernet) */ - *(buf + 19) = 4; /* protocol addr length (IPv4) */ - *(uint16_t *)(buf + 20) = htons(ARP_OP_REQUEST_REV); /* opcode */ - memcpy(buf + 22, mac_addr, 6); /* source hw addr */ - memset(buf + 28, 0x00, 4); /* source protocol addr */ - memcpy(buf + 32, mac_addr, 6); /* target hw addr */ - memset(buf + 38, 0x00, 4); /* target protocol addr */ - - /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS). */ - memset(buf + 42, 0x00, 18); - - return 60; /* len (FCS will be added by hardware) */ -} - -static void qemu_announce_self_iter(NICState *nic, void *opaque) -{ - uint8_t buf[60]; - int len; - - trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr)); - len = announce_self_create(buf, nic->conf->macaddr.a); - - qemu_send_packet_raw(qemu_get_queue(nic), buf, len); -} - - -static void qemu_announce_self_once(void *opaque) -{ - static int count = SELF_ANNOUNCE_ROUNDS; - QEMUTimer *timer = *(QEMUTimer **)opaque; - - qemu_foreach_nic(qemu_announce_self_iter, NULL); - - if (--count) { - /* delay 50ms, 150ms, 250ms, ... */ - timer_mod(timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + - self_announce_delay(count)); - } else { - timer_del(timer); - timer_free(timer); - } -} - -void qemu_announce_self(void) -{ - static QEMUTimer *timer; - timer = timer_new_ms(QEMU_CLOCK_REALTIME, qemu_announce_self_once, &timer); - qemu_announce_self_once(&timer); -} - /***********************************************************/ /* savevm/loadvm support */ @@ -1765,13 +1698,14 @@ static void loadvm_postcopy_handle_run_bh(void *opaque) { Error *local_err = NULL; HandleRunBhData *data = opaque; + MigrationIncomingState *mis = migration_incoming_get_current(); /* TODO we should move all of this lot into postcopy_ram.c or a shared code * in migration.c */ cpu_synchronize_all_post_init(); - qemu_announce_self(); + qemu_announce_self(&mis->announce_timer, migrate_announce_params()); /* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ diff --git a/migration/trace-events b/migration/trace-events index bd2d0cd..72e3fcb 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -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" diff --git a/net/announce.c b/net/announce.c index 8876eb6..13ad9c2 100644 --- a/net/announce.c +++ b/net/announce.c @@ -9,8 +9,10 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "net/announce.h" +#include "net/net.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-net.h" +#include "trace.h" int64_t qemu_announce_timer_step(AnnounceTimer *timer) { @@ -58,3 +60,69 @@ void qemu_announce_timer_reset(AnnounceTimer *timer, timer->type = type; timer->tm = timer_new_ms(type, cb, opaque); } + +#ifndef ETH_P_RARP +#define ETH_P_RARP 0x8035 +#endif +#define ARP_HTYPE_ETH 0x0001 +#define ARP_PTYPE_IP 0x0800 +#define ARP_OP_REQUEST_REV 0x3 + +static int announce_self_create(uint8_t *buf, + uint8_t *mac_addr) +{ + /* Ethernet header. */ + memset(buf, 0xff, 6); /* destination MAC addr */ + memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ + *(uint16_t *)(buf + 12) = htons(ETH_P_RARP); /* ethertype */ + + /* RARP header. */ + *(uint16_t *)(buf + 14) = htons(ARP_HTYPE_ETH); /* hardware addr space */ + *(uint16_t *)(buf + 16) = htons(ARP_PTYPE_IP); /* protocol addr space */ + *(buf + 18) = 6; /* hardware addr length (ethernet) */ + *(buf + 19) = 4; /* protocol addr length (IPv4) */ + *(uint16_t *)(buf + 20) = htons(ARP_OP_REQUEST_REV); /* opcode */ + memcpy(buf + 22, mac_addr, 6); /* source hw addr */ + memset(buf + 28, 0x00, 4); /* source protocol addr */ + memcpy(buf + 32, mac_addr, 6); /* target hw addr */ + memset(buf + 38, 0x00, 4); /* target protocol addr */ + + /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS). */ + memset(buf + 42, 0x00, 18); + + return 60; /* len (FCS will be added by hardware) */ +} + +static void qemu_announce_self_iter(NICState *nic, void *opaque) +{ + uint8_t buf[60]; + int len; + + trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr)); + len = announce_self_create(buf, nic->conf->macaddr.a); + + qemu_send_packet_raw(qemu_get_queue(nic), buf, len); +} +static void qemu_announce_self_once(void *opaque) +{ + AnnounceTimer *timer = (AnnounceTimer *)opaque; + + qemu_foreach_nic(qemu_announce_self_iter, NULL); + + if (--timer->round) { + qemu_announce_timer_step(timer); + } else { + qemu_announce_timer_del(timer); + } +} + +void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params) +{ + qemu_announce_timer_reset(timer, params, QEMU_CLOCK_REALTIME, + qemu_announce_self_once, timer); + if (params->rounds) { + qemu_announce_self_once(timer); + } else { + qemu_announce_timer_del(timer); + } +} diff --git a/net/trace-events b/net/trace-events index 7b594cf..3417ac0 100644 --- a/net/trace-events +++ b/net/trace-events @@ -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" From patchwork Fri Feb 22 14:55:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445Zv220zdz9s5c for ; Sat, 23 Feb 2019 02:26:38 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCii-00066r-4T for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:26:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHH-0000SI-0B for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF6-0007hd-Me for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF6-0006aq-Am for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFE06300250C; Fri, 22 Feb 2019 14:55:40 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A86141A7DF; Fri, 22 Feb 2019 14:55:35 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:13 +0800 Message-Id: <1550847320-25110-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 22 Feb 2019 14:55:40 +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 06/13] net: Add a network device specific self-announcement ability 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: Vladislav Yasevich , Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" Some network devices have a capability to do self announcements (ex: virtio-net). Add infrastructure that would allow devices to expose this ability. Signed-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- include/net/net.h | 2 ++ net/announce.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 075cc01..acf0451 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -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 { diff --git a/net/announce.c b/net/announce.c index 13ad9c2..070f37a 100644 --- a/net/announce.c +++ b/net/announce.c @@ -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) { From patchwork Fri Feb 22 14:55:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZyK2WQhz9s9L for ; Sat, 23 Feb 2019 02:29:29 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxClT-0008PD-7H for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:29:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHG-0000TB-SW for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF7-0007mh-QN for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31305) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF7-0006eW-Cs for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C70230970D0; Fri, 22 Feb 2019 14:55:43 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DBB12854A; Fri, 22 Feb 2019 14:55:41 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:14 +0800 Message-Id: <1550847320-25110-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 22 Feb 2019 14:55: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 07/13] virtio-net: Allow qemu_announce_self to trigger virtio announcements 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: Vladislav Yasevich , Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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. Signed-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/net/trace-events | 1 + hw/net/virtio-net.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index b237d90..3a86004 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -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) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b50f86d..ed0fa97 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -162,15 +162,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) @@ -2568,6 +2595,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) @@ -2709,6 +2737,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) { /* From patchwork Fri Feb 22 14:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZZC2YPMz9s9T for ; Sat, 23 Feb 2019 02:12:03 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCUb-0003CO-7N for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:12:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHG-0000QT-TW for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF7-0007kU-EP for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF7-0006j9-2x for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDE86305B889; Fri, 22 Feb 2019 14:55:47 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD69B1A7CD; Fri, 22 Feb 2019 14:55:43 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:15 +0800 Message-Id: <1550847320-25110-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 22 Feb 2019 14:55:48 +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 08/13] qmp: Add announce-self command 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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 and Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- net/announce.c | 7 +++++++ qapi/net.json | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/net/announce.c b/net/announce.c index 070f37a..91e9a6e 100644 --- a/net/announce.c +++ b/net/announce.c @@ -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); +} diff --git a/qapi/net.json b/qapi/net.json index 5face0c..c093087 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -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": { "params:" { +# "initial": 50, "max": 550, "rounds": 10, "step": 50 } } } +# <- { "return": {} } +# +# Since: 4.0 +## +{ 'command': 'announce-self', + 'data' : {'params': 'AnnounceParameters'} } From patchwork Fri Feb 22 14:55:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZM20YtBz9sB3 for ; Sat, 23 Feb 2019 02:02:22 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCLE-0003ZP-0n for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:02:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHA-0000C3-V2 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCFX-0000B9-Ij for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCFS-0006sL-Fz for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D39E6C04959C; Fri, 22 Feb 2019 14:55:50 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 778271A7CD; Fri, 22 Feb 2019 14:55:48 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:16 +0800 Message-Id: <1550847320-25110-10-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 22 Feb 2019 14:55:50 +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 09/13] hmp: Add hmp_announce_self 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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. Signend-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 5 +++++ hmp.h | 1 + tests/test-hmp.c | 1 + 4 files changed, 21 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index ba71558..9f812bc 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -931,6 +931,20 @@ 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 GARP/RARP announcements. +ETEXI + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,resume:-r,uri:s", .params = "[-d] [-b] [-i] [-r] uri", diff --git a/hmp.c b/hmp.c index f3db0bf..5f13b16 100644 --- a/hmp.c +++ b/hmp.c @@ -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); diff --git a/hmp.h b/hmp.h index 5f1addc..e0f32f0 100644 --- a/hmp.h +++ b/hmp.h @@ -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); diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 1a3a9c5..8c49d2f 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -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", From patchwork Fri Feb 22 14:55:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZdY2MyMz9s9L for ; Sat, 23 Feb 2019 02:14:57 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCXP-0005XB-69 for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:14:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHG-0000VD-Ry for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF8-0007rG-HZ for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF7-00074S-V2 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EC16300B915; Fri, 22 Feb 2019 14:55:53 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CD871A7DF; Fri, 22 Feb 2019 14:55:51 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:17 +0800 Message-Id: <1550847320-25110-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 22 Feb 2019 14:55:53 +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 10/13] tests: Add a test for qemu self announcements 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: Vlad Yasevich , Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" 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). Signed-off-by: Vlad Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- tests/Makefile.include | 3 ++ tests/test-announce-self.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/test-announce-self.c diff --git a/tests/Makefile.include b/tests/Makefile.include index b39e989..1b0874c 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -144,6 +144,7 @@ check-qtest-generic-y += tests/qmp-cmd-test$(EXESUF) check-qtest-generic-y += tests/device-introspect-test$(EXESUF) check-qtest-generic-y += tests/cdrom-test$(EXESUF) +gcov-files-generic-y = migration/savevm.c check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) @@ -221,6 +222,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) @@ -258,6 +260,7 @@ check-qtest-ppc64-y += $(check-qtest-ppc-y) check-qtest-ppc64-$(CONFIG_PSERIES) += tests/spapr-phb-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) diff --git a/tests/test-announce-self.c b/tests/test-announce-self.c new file mode 100644 index 0000000..2ff0c77 --- /dev/null +++ b/tests/test-announce-self.c @@ -0,0 +1,83 @@ +/* + * QTest testcase for qemu_announce_self + * + * Copyright (c) 2017 Red hat, Inc. + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qemu-common.h" +#include "qemu/sockets.h" +#include "qemu/iov.h" +#include "libqos/libqos-pc.h" +#include "libqos/libqos-spapr.h" + +#ifndef ETH_P_RARP +#define ETH_P_RARP 0x8035 +#endif + +static QTestState *test_init(int socket) +{ + char *args; + + args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device " + "virtio-net-pci,netdev=hs0", socket); + + return qtest_start(args); +} + + +static void test_announce(int socket) +{ + char buffer[60]; + int len; + QDict *rsp; + int ret; + uint16_t *proto = (uint16_t *)&buffer[12]; + + rsp = qmp("{ 'execute' : 'announce-self', " + " 'arguments': {" + " 'params': {" + " 'initial': 50, 'max': 550," + " 'rounds': 10, 'step': 50 } } }"); + assert(!qdict_haskey(rsp, "error")); + qobject_unref(rsp); + + /* Catch the packet and make sure it's a RARP */ + ret = qemu_recv(socket, &len, sizeof(len), 0); + g_assert_cmpint(ret, ==, sizeof(len)); + len = ntohl(len); + + ret = qemu_recv(socket, buffer, len, 0); + g_assert_cmpint(*proto, ==, htons(ETH_P_RARP)); +} + +static void setup(gconstpointer data) +{ + QTestState *qs; + void (*func) (int socket) = data; + int sv[2], ret; + + ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv); + g_assert_cmpint(ret, !=, -1); + + qs = test_init(sv[1]); + func(sv[0]); + + /* End test */ + close(sv[0]); + qtest_quit(qs); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qtest_add_data_func("/virtio/net/test_announce_self", test_announce, setup); + + return g_test_run(); +} From patchwork Fri Feb 22 14:55:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445Zj23T5Nz9s5c for ; Sat, 23 Feb 2019 02:17:58 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCaK-00080a-9g for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:17:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHH-0000VB-42 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF6-0007fa-A2 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF5-0007Ck-SK for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 919695D61F; Fri, 22 Feb 2019 14:55:55 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB9541A7CD; Fri, 22 Feb 2019 14:55:53 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:18 +0800 Message-Id: <1550847320-25110-12-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 22 Feb 2019 14:55:55 +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 11/13] net: netmap: small improvements netmap_send() 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 , Vincenzo Maffione Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vincenzo Maffione 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. Signed-off-by: Vincenzo Maffione Signed-off-by: Jason Wang --- net/netmap.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 2d11a8f..71a8122 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -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; } From patchwork Fri Feb 22 14:55:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZQy5qcRz9s9L for ; Sat, 23 Feb 2019 02:05:43 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCOR-00063B-4n for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:05:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHB-0000S1-2N for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCFX-0000AJ-FP for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCFR-0007Mj-7P for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAF57308220A; Fri, 22 Feb 2019 14:55:57 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F3311A7DF; Fri, 22 Feb 2019 14:55:55 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:19 +0800 Message-Id: <1550847320-25110-13-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 22 Feb 2019 14:55:57 +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 12/13] net: netmap: simplify netmap_receive() 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 , Vincenzo Maffione Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vincenzo Maffione Improve code reuse by implementing netmap_receive() with a call to netmap_receive_iov(). Signed-off-by: Vincenzo Maffione Signed-off-by: Jason Wang --- net/netmap.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 71a8122..852106a 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -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) From patchwork Fri Feb 22 14:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445ZVj0RFFz9s9L for ; Sat, 23 Feb 2019 02:09:01 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCRe-0000Xn-W8 for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:08:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCHE-0000QR-W9 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF9-0007wx-Lz for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF9-0007es-3S for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16C1181235; Fri, 22 Feb 2019 14:56:00 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A29728558; Fri, 22 Feb 2019 14:55:58 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:20 +0800 Message-Id: <1550847320-25110-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 22 Feb 2019 14:56:00 +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 13/13] net: netmap: improve netmap_receive_iov() 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 , Vincenzo Maffione Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vincenzo Maffione 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). Signed-off-by: Vincenzo Maffione Signed-off-by: Jason Wang --- net/netmap.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 852106a..0cc8f54 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -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,