From patchwork Fri Sep 9 19:02:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9324177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3BA9F60231 for ; Fri, 9 Sep 2016 19:04:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D11329FB0 for ; Fri, 9 Sep 2016 19:04:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2130229FBB; Fri, 9 Sep 2016 19:04:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 31E4B29FB0 for ; Fri, 9 Sep 2016 19:04:36 +0000 (UTC) Received: from localhost ([::1]:59781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biR6J-0008VR-9X for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Sep 2016 15:04:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biR5u-0008T7-BB for qemu-devel@nongnu.org; Fri, 09 Sep 2016 15:04:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biR5q-0001uf-3A for qemu-devel@nongnu.org; Fri, 09 Sep 2016 15:04:09 -0400 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:33016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biR5p-0001uW-PK for qemu-devel@nongnu.org; Fri, 09 Sep 2016 15:04:06 -0400 Received: by mail-pa0-x241.google.com with SMTP id h5so4205919pao.0 for ; Fri, 09 Sep 2016 12:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Xk41a98w1UyAyIGKN1sKntbN22yD7/T+5Z/miSnUqwQ=; b=SqhZ7VEl7rdPzegPCE9QuYqD+ww++LpNdavQWxvEKnx4bRQTR/fkzFC4GoLmSSzzY+ 6q7kCUtGn8w8zTBsAkRqzZsvBmM+azyjgRnWkMRlb0N2GBwdQ4llJsW9GcSCBH/PfVFl NoczAnu4nIZUA/gC+e5s4Dl61uysHLSP1QZMQC7pjyHc3jTBf9rRaVXNzx30BZcvUQok W5qW0l1Ucw2aoIpxBiqURk3xl3j62o44oDFUdEZ2vl82MaTFXMTAtj/eQJ+nI/M5NaRO krqw/VAh0lxXV5xeV+68aWxyEM0tjVAqKnEz7/t3dK3tXpKZetVOhQdEYqV068qtXFv3 CW4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Xk41a98w1UyAyIGKN1sKntbN22yD7/T+5Z/miSnUqwQ=; b=gteZ+rkLNQfLjOeRQu4CL8MWe8clECgkgjjJb9L6qBlfHnDnq/9GjJujOVGzyl6byu 9c3CvDksL2zJHGqfSLj1z6jAVv3dOt1v/fb0u0uhBflrw06xO7NJAc5H1e5AL6R9jDyy BlpXZVjEDOm3A56Xp7GhNUMl0iyEqVtacYBcxcc32Gdghx88PlRo7CaR02gEx7RPjtfP yPcfVj131id5mpt9aRB0ZBGS1Jh6vtVQ1MxGEZntM9bViV2PuwDVdGenQdZoW0YLPDiE QnhrNhmY3JmL8FkMV0FpK3/VjpNQtc0oq2DFHnxuKNx/ueGLcU5EkEeMozhQX9L0tRwI prqA== X-Gm-Message-State: AE9vXwOTL6ExqPpZxZTW0pP+us63CNN8DI55oQ0EyzaZ3CJh+nXVW3Kjp5LSVBSnA6/tXg== X-Received: by 10.66.152.238 with SMTP id vb14mr9233006pab.78.1473447844679; Fri, 09 Sep 2016 12:04:04 -0700 (PDT) Received: from linux.local ([106.208.12.73]) by smtp.gmail.com with ESMTPSA id m65sm7013997pfg.79.2016.09.09.12.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 12:04:03 -0700 (PDT) From: Ashijeet Acharya To: lcapitulino@redhat.com Date: Sat, 10 Sep 2016 00:32:58 +0530 Message-Id: <1473447778-29339-1-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::241 Subject: [Qemu-devel] [PATCH v5] migrate: Move max-bandwidth and downtime-limit to migrate_set_parameter 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: quintela@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, dgilbert@redhat.com, Ashijeet Acharya , amit.shah@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Mark old-commands for speed and downtime as deprecated. Move max-bandwidth and downtime-limit into migrate-set-parameters for setting maximum migration speed and expected downtime limit parameters respectively. Change downtime units to milliseconds (only for new-command) and update the query part in both hmp and qmp qemu control interfaces. NOTE: This patch is solely based on Eric's new boxed parameters from QAPI patch series. Signed-off-by: Ashijeet Acharya --- Changes in v5: - Include units in the output of 'info migrte_parameters' - Change 'old-commands' to 'backwards' in deprecation comments - Include a error check for overflow of downtime_limit value - Solve long line issues --- hmp.c | 27 +++++++++++++++ include/migration/migration.h | 1 - migration/migration.c | 76 +++++++++++++++++++++++++++++++------------ qapi-schema.json | 23 +++++++++++-- qmp-commands.hx | 14 ++++++-- 5 files changed, 113 insertions(+), 28 deletions(-) diff --git a/hmp.c b/hmp.c index 0893b8e..f9c81b1 100644 --- a/hmp.c +++ b/hmp.c @@ -309,6 +309,14 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) monitor_printf(mon, " %s: '%s'", MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME], params->has_tls_hostname ? params->tls_hostname : ""); + assert(params->has_max_bandwidth); + monitor_printf(mon, " %s: %" PRId64 " bytes/second", + MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH], + params->max_bandwidth); + assert(params->has_downtime_limit); + monitor_printf(mon, " %s: %" PRId64 " milliseconds", + MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT], + params->downtime_limit); monitor_printf(mon, "\n"); } @@ -1200,6 +1208,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +/* Kept for backwards compatibility */ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) { double value = qdict_get_double(qdict, "value"); @@ -1218,6 +1227,7 @@ void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) } } +/* Kept for backwards compatibility */ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) { int64_t value = qdict_get_int(qdict, "value"); @@ -1258,7 +1268,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) { const char *param = qdict_get_str(qdict, "parameter"); const char *valuestr = qdict_get_str(qdict, "value"); + int64_t valuebw = 0; long valueint = 0; + char *endp; Error *err = NULL; bool use_int_value = false; int i; @@ -1295,6 +1307,20 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.has_tls_hostname = true; p.tls_hostname = (char *) valuestr; break; + case MIGRATION_PARAMETER_MAX_BANDWIDTH: + p.has_max_bandwidth = true; + valuebw = qemu_strtosz(valuestr, &endp); + if (valuebw < 0 || (size_t)valuebw != valuebw + || *endp != '\0') { + error_setg(&err, "Invalid size %s", valuestr); + goto cleanup; + } + p.max_bandwidth = valuebw; + break; + case MIGRATION_PARAMETER_DOWNTIME_LIMIT: + p.has_downtime_limit = true; + use_int_value = true; + break; } if (use_int_value) { @@ -1310,6 +1336,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.decompress_threads = valueint; p.cpu_throttle_initial = valueint; p.cpu_throttle_increment = valueint; + p.downtime_limit = valueint; } qmp_migrate_set_parameters(&p, &err); diff --git a/include/migration/migration.h b/include/migration/migration.h index 3c96623..a5429ee 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -129,7 +129,6 @@ struct MigrationSrcPageRequest { struct MigrationState { - int64_t bandwidth_limit; size_t bytes_xfer; size_t xfer_limit; QemuThread thread; diff --git a/migration/migration.c b/migration/migration.c index 42336e3..9b4aa55 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -44,6 +44,10 @@ #define BUFFER_DELAY 100 #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY) +/* Time in nanoseconds we are allowed to stop the source, + * for sending the last part */ +#define DEFAULT_MIGRATE_SET_DOWNTIME 300000000 + /* Default compression thread count */ #define DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT 8 /* Default decompression thread count, usually decompression is at @@ -80,7 +84,6 @@ MigrationState *migrate_get_current(void) static bool once; static MigrationState current_migration = { .state = MIGRATION_STATUS_NONE, - .bandwidth_limit = MAX_THROTTLE, .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE, .mbps = -1, .parameters = { @@ -89,6 +92,8 @@ MigrationState *migrate_get_current(void) .decompress_threads = DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT, .cpu_throttle_initial = DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL, .cpu_throttle_increment = DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT, + .max_bandwidth = MAX_THROTTLE, + .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME, }, }; @@ -573,6 +578,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->tls_creds = g_strdup(s->parameters.tls_creds); params->has_tls_hostname = !!s->parameters.tls_hostname; params->tls_hostname = g_strdup(s->parameters.tls_hostname); + params->has_max_bandwidth = true; + params->max_bandwidth = s->parameters.max_bandwidth; + params->has_downtime_limit = true; + params->downtime_limit = s->parameters.downtime_limit / 1000000; return params; } @@ -804,6 +813,20 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) "cpu_throttle_increment", "an integer in the range of 1 to 99"); } + if (params->has_max_bandwidth && + (params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "max_bandwidth", + "an integer in the range of 0 to SIZE_MAX"); + return; + } + if (params->has_downtime_limit && + (params->downtime_limit < 0 || params->downtime_limit > 2000000)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "downtime_limit", + "an integer in the range of 0 to 2000000 milliseconds"); + return; + } if (params->has_compress_level) { s->parameters.compress_level = params->compress_level; @@ -828,6 +851,20 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) g_free(s->parameters.tls_hostname); s->parameters.tls_hostname = g_strdup(params->tls_hostname); } + if (params->has_max_bandwidth) { + s->parameters.max_bandwidth = params->max_bandwidth; + if (s->to_dst_file) { + qemu_file_set_rate_limit(s->to_dst_file, + s->parameters.max_bandwidth / XFER_LIMIT_RATIO); + } + } + if (params->has_downtime_limit) { + params->downtime_limit *= 1000000; /* convert to nanoseconds */ + + s = migrate_get_current(); + max_downtime = params->downtime_limit; + s->parameters.downtime_limit = max_downtime; + } } @@ -1159,30 +1196,27 @@ int64_t qmp_query_migrate_cache_size(Error **errp) return migrate_xbzrle_cache_size(); } -void qmp_migrate_set_speed(int64_t value, Error **errp) +void qmp_migrate_set_speed(int64_t valuebw, Error **errp) { - MigrationState *s; - - if (value < 0) { - value = 0; - } - if (value > SIZE_MAX) { - value = SIZE_MAX; - } + MigrationParameters p = { + .has_max_bandwidth = true, + .max_bandwidth = valuebw, + }; - s = migrate_get_current(); - s->bandwidth_limit = value; - if (s->to_dst_file) { - qemu_file_set_rate_limit(s->to_dst_file, - s->bandwidth_limit / XFER_LIMIT_RATIO); - } + qmp_migrate_set_parameters(&p, errp); } -void qmp_migrate_set_downtime(double value, Error **errp) +void qmp_migrate_set_downtime(double valuedowntime, Error **errp) { - value *= 1e9; - value = MAX(0, MIN(UINT64_MAX, value)); - max_downtime = (uint64_t)value; + valuedowntime *= 1000; /* Convert to milliseconds */ + valuedowntime = MAX(0, MIN(INT64_MAX, valuedowntime)); + + MigrationParameters p = { + .has_downtime_limit = true, + .downtime_limit = valuedowntime, + }; + + qmp_migrate_set_parameters(&p, errp); } bool migrate_postcopy_ram(void) @@ -1854,7 +1888,7 @@ void migrate_fd_connect(MigrationState *s) qemu_file_set_blocking(s->to_dst_file, true); qemu_file_set_rate_limit(s->to_dst_file, - s->bandwidth_limit / XFER_LIMIT_RATIO); + s->parameters.max_bandwidth / XFER_LIMIT_RATIO); /* Notify before starting migration thread */ notifier_list_notify(&migration_state_notifiers, s); diff --git a/qapi-schema.json b/qapi-schema.json index 88b4888..f92ec88 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -637,12 +637,19 @@ # hostname must be provided so that the server's x509 # certificate identity can be validated. (Since 2.7) # +# @max-bandwidth: to set maximum speed for migration. maximum speed in +# bytes per second. (Since 2.8) +# +# @downtime-limit: set maximum tolerated downtime for migration. maximum +# downtime in milliseconds (Since 2.8) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', 'data': ['compress-level', 'compress-threads', 'decompress-threads', 'cpu-throttle-initial', 'cpu-throttle-increment', - 'tls-creds', 'tls-hostname'] } + 'tls-creds', 'tls-hostname', 'max-bandwidth', + 'downtime-limit'] } # # @migrate-set-parameters @@ -691,6 +698,12 @@ # hostname must be provided so that the server's x509 # certificate identity can be validated. (Since 2.7) # +# @max-bandwidth: to set maximum speed for migration. maximum speed in +# bytes per second. (Since 2.8) +# +# @downtime-limit: set maximum tolerated downtime for migration. maximum +# downtime in milliseconds (Since 2.8) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -700,7 +713,9 @@ '*cpu-throttle-initial': 'int', '*cpu-throttle-increment': 'int', '*tls-creds': 'str', - '*tls-hostname': 'str'} } + '*tls-hostname': 'str', + '*max-bandwidth': 'int', + '*downtime-limit': 'int'} } ## # @query-migrate-parameters # @@ -1782,6 +1797,8 @@ # # Returns: nothing on success # +# Notes: This command is deprecated in favor of 'migrate-set-parameters' +# # Since: 0.14.0 ## { 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } @@ -1795,7 +1812,7 @@ # # Returns: nothing on success # -# Notes: A value lesser than zero will be automatically round up to zero. +# Notes: This command is deprecated in favor of 'migrate-set-parameters' # # Since: 0.14.0 ## diff --git a/qmp-commands.hx b/qmp-commands.hx index e6c9193..9c277dd 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3800,7 +3800,9 @@ Set migration parameters throttled for auto-converge (json-int) - "cpu-throttle-increment": set throttle increasing percentage for auto-converge (json-int) - +- "max-bandwidth": set maximum speed for migrations (in bytes/sec) (json-int) +- "downtime-limit": set maximum tolerated downtime (in milliseconds) for + migrations (json-int) Arguments: Example: @@ -3813,7 +3815,7 @@ EQMP { .name = "migrate-set-parameters", .args_type = - "compress-level:i?,compress-threads:i?,decompress-threads:i?,cpu-throttle-initial:i?,cpu-throttle-increment:i?", + "compress-level:i?,compress-threads:i?,decompress-threads:i?,cpu-throttle-initial:i?,cpu-throttle-increment:i?,max-bandwidth:i?,downtime-limit:i?", .mhandler.cmd_new = qmp_marshal_migrate_set_parameters, }, SQMP @@ -3830,6 +3832,10 @@ Query current migration parameters throttled (json-int) - "cpu-throttle-increment" : throttle increasing percentage for auto-converge (json-int) + - "max-bandwidth" : maximium migration speed in bytes per second + (json-int) + - "downtime-limit" : maximum tolerated downtime of migration in + milliseconds (json-int) Arguments: @@ -3842,7 +3848,9 @@ Example: "cpu-throttle-increment": 10, "compress-threads": 8, "compress-level": 1, - "cpu-throttle-initial": 20 + "cpu-throttle-initial": 20, + "max-bandwidth": 33554432, + "downtime-limit": 300 } }