From nobody Mon Feb 9 19:52:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506955126782849.2258417480534; Mon, 2 Oct 2017 07:38:46 -0700 (PDT) Received: from localhost ([::1]:52624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz1rh-0000ZC-VJ for importer@patchew.org; Mon, 02 Oct 2017 10:38:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz1nT-0005eR-Dz for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dz1nN-0007v6-0m for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:34:15 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:37885) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dz1nM-0007ul-NI for qemu-devel@nongnu.org; Mon, 02 Oct 2017 10:34:08 -0400 Received: by mail-wr0-x243.google.com with SMTP id v38so946633wrc.4 for ; Mon, 02 Oct 2017 07:34:08 -0700 (PDT) Received: from localhost.localdomain.localdomain ([217.110.131.66]) by smtp.gmail.com with ESMTPSA id b89sm28440668wrd.42.2017.10.02.07.34.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 07:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ciLgGFJe7LfTO5QHt96NqeY7iVJDkqgH31QjLoNpUqo=; b=pLdagDxkNShOdI3JYNIWksCE02eXdce/Sok6qCpBMfqm/UITr4oLUQQq/Awo/hHJyP KCt4lGMCFFlJ/Prxfww77UyvHTAH2q2zEpsMPXQCCRHSTHpKqXQZ7YrJ6RuHSvhgpPkO gulaDRCDQEg8iWPKz9EGItiobTsGF0HlxoV4Ju8L61fUswdxQc3sUiVbsbjcuurD+xnd eRApunHnlUIAbtkrIWhD33zUK/rrG/47JbY33KY55+GWy6S+qo2tW1qjZD8d0hx6TGVC ACAhOBYvDBGOwqxW3VGykDMj18wzZ+Rzg/WHZSAjWAJdbI0HACMakl0gYZGan0Rj0D97 TDdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ciLgGFJe7LfTO5QHt96NqeY7iVJDkqgH31QjLoNpUqo=; b=J3hTD2xi0oEjuVqmVHcSx2vsYpPMS0dP8UX4K0MYaP4/lLTF+dp2CQhdvVV8RzuSda p6G+7ct2sKAY20mzo1VD4ix3ZWfPC8O3IxQp/G08/eRhUQyAplt9VFP5drRcJacPro3A /cKdxzZEcgq5M5c/Kb5G9UEG2Orp4pM4Q12eMg35wJBqf66LjAT54Y1+cfYqplRYtuVj +DJBJfU69tYd50oL3ecXfFWwoRfwKw9TPuoRk+uUaEAxCl/AUH8MBlenFB/EwT0SKjhA s4pb1Mg0lnIoytp7evVDdlez68QFtGlwSM6+V+L0Nijk1HZ/Nw8L+EINtR9Eq4mTAG8/ k0kA== X-Gm-Message-State: AMCzsaUTpPZ1FT3Z9JrDt08qKYypo9Ctbubczp5Xd9mMBJ8KQTa+VRvm xE1qRG7894geaAmhQgypT/4= X-Google-Smtp-Source: AOwi7QC+kcNd+7Fvm4mtUFmEhs9b50FjB/TrWPVJgXkY03xUqcqDu+wXNEk1JzPfFCTGnf0ToFeowg== X-Received: by 10.223.179.18 with SMTP id j18mr2004736wrd.262.1506954847588; Mon, 02 Oct 2017 07:34:07 -0700 (PDT) From: Pradeep Jagadeesh X-Google-Original-From: Pradeep Jagadeesh To: "eric blake" , "greg kurz" Date: Mon, 2 Oct 2017 10:33:31 -0400 Message-Id: <1506954812-6552-6-git-send-email-pradeep.jagadeesh@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506954812-6552-1-git-send-email-pradeep.jagadeesh@huawei.com> References: <1506954812-6552-1-git-send-email-pradeep.jagadeesh@huawei.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v13 5/6] fsdev: QMP interface for throttling X-BeenThere: qemu-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alberto garcia , Markus Armbruster , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" , Pradeep Jagadeesh , jani kokkonen Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch introduces qmp interfaces for the fsdev devices. This provides two interfaces one for querying info of all the fsdev devices. The second one to set the IO limits for the required fsdev device. Signed-off-by: Pradeep Jagadeesh Reviewed-by: Dr. David Alan Gilbert --- Makefile | 3 +- fsdev/qemu-fsdev-dummy.c | 11 +++++ fsdev/qemu-fsdev-throttle.c | 100 ++++++++++++++++++++++++++++++++++++++++= +--- fsdev/qemu-fsdev-throttle.h | 9 +++- fsdev/qemu-fsdev.c | 30 +++++++++++++ monitor.c | 5 +++ qapi-schema.json | 4 ++ qapi/fsdev.json | 94 +++++++++++++++++++++++++++++++++++++++++ qmp.c | 14 +++++++ 9 files changed, 261 insertions(+), 9 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index cee6e28..018cae1 100644 --- a/Makefile +++ b/Makefile @@ -417,7 +417,8 @@ qapi-modules =3D $(SRC_PATH)/qapi-schema.json $(SRC_PAT= H)/qapi/common.json \ $(SRC_PATH)/qapi/tpm.json \ $(SRC_PATH)/qapi/trace.json \ $(SRC_PATH)/qapi/transaction.json \ - $(SRC_PATH)/qapi/ui.json + $(SRC_PATH)/qapi/ui.json \ + $(SRC_PATH)/qapi/fsdev.json =20 qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..b775e66 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -14,8 +14,19 @@ #include "qemu-fsdev.h" #include "qemu/config-file.h" #include "qemu/module.h" +#include "qmp-commands.h" =20 int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(FsdevIOThrottle *arg, Error **errp) +{ + return; +} + +FsdevIOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + return NULL; +} diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 0e6fb86..7825be8 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,6 +16,7 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" +#include "qemu/main-loop.h" #include "qemu/throttle-options.h" =20 static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,96 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(&fst->throttled_reqs[true]); } =20 +typedef struct { + FsThrottle *fst; + bool is_write; +} RestartData; + +static bool coroutine_fn throttle_co_restart_queue(FsThrottle *fst, + bool is_write) +{ + return qemu_co_queue_next(&fst->throttled_reqs[is_write]); +} + +static void schedule_next_request(FsThrottle *fst, bool is_write) +{ + bool must_wait =3D throttle_schedule_timer(&fst->ts, &fst->tt, is_writ= e); + if (!must_wait) { + if (qemu_in_coroutine() && + throttle_co_restart_queue(fst, is_write)) { + return; + } else { + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + timer_mod(fst->tt.timers[is_write], now); + } + } +} + +static void coroutine_fn throttle_restart_queue_entry(void *opaque) +{ + RestartData *data =3D opaque; + bool is_write =3D data->is_write; + bool empty_queue =3D !throttle_co_restart_queue(data->fst, is_write); + if (empty_queue) { + schedule_next_request(data->fst, is_write); + } +} + +static void throttle_restart_queues(FsThrottle *fst) +{ + Coroutine *co; + RestartData rd =3D { + .fst =3D fst, + .is_write =3D true + }; + + co =3D qemu_coroutine_create(throttle_restart_queue_entry, &rd); + aio_co_enter(fst->ctx, co); + + rd.is_write =3D false; + + co =3D qemu_coroutine_create(throttle_restart_queue_entry, &rd); + aio_co_enter(fst->ctx, co); +} + +static void coroutine_fn fsdev_throttle_config(FsThrottle *fst) +{ + if (throttle_enabled(&fst->cfg)) { + throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->cfg); + } else { + throttle_restart_queues(fst); + } +} + +void fsdev_set_io_throttle(FsdevIOThrottle *arg, FsThrottle *fst, Error **= errp) +{ + ThrottleConfig cfg; + ThrottleLimits *tlimits; + + throttle_get_config(&fst->ts, &cfg); + tlimits =3D qapi_FsdevIOThrottle_base(arg); + throttle_limits_to_config(tlimits, &cfg, errp); + + if (throttle_is_valid(&cfg, errp)) { + fst->cfg =3D cfg; + fsdev_throttle_config(fst); + } +} + +void fsdev_get_io_throttle(FsThrottle *fst, FsdevIOThrottle **fs9pcfg, + char *fsdevice) +{ + ThrottleConfig cfg =3D fst->cfg; + ThrottleLimits *tlimits; + FsdevIOThrottle *fscfg =3D g_malloc(sizeof(*fscfg)); + tlimits =3D qapi_FsdevIOThrottle_base(fscfg); + + fscfg->has_id =3D true; + fscfg->id =3D g_strdup(fsdevice); + throttle_config_to_limits(&cfg, tlimits); + *fs9pcfg =3D fscfg; +} + void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **er= rp) { throttle_parse_options(&fst->cfg, opts); @@ -40,8 +131,9 @@ void fsdev_throttle_init(FsThrottle *fst) { if (throttle_enabled(&fst->cfg)) { throttle_init(&fst->ts); + fst->ctx =3D qemu_get_aio_context(); throttle_timers_init(&fst->tt, - qemu_get_aio_context(), + fst->ctx, QEMU_CLOCK_REALTIME, fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, @@ -62,11 +154,7 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle = *fst, bool is_write, } =20 throttle_account(&fst->ts, is_write, iov_size(iov, iovcnt)); - - if (!qemu_co_queue_empty(&fst->throttled_reqs[is_write]) && - !throttle_schedule_timer(&fst->ts, &fst->tt, is_write)) { - qemu_co_queue_next(&fst->throttled_reqs[is_write]); - } + schedule_next_request(fst, is_write); } } =20 diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h index e418643..5331c23 100644 --- a/fsdev/qemu-fsdev-throttle.h +++ b/fsdev/qemu-fsdev-throttle.h @@ -15,8 +15,6 @@ #ifndef _FSDEV_THROTTLE_H #define _FSDEV_THROTTLE_H =20 -#include "block/aio.h" -#include "qemu/main-loop.h" #include "qemu/coroutine.h" #include "qapi/error.h" #include "qemu/throttle.h" @@ -25,6 +23,7 @@ typedef struct FsThrottle { ThrottleState ts; ThrottleTimers tt; ThrottleConfig cfg; + AioContext *ctx; CoQueue throttled_reqs[2]; } FsThrottle; =20 @@ -36,4 +35,10 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *= , bool , struct iovec *, int); =20 void fsdev_throttle_cleanup(FsThrottle *); + +void fsdev_set_io_throttle(FsdevIOThrottle *, FsThrottle *, Error **errp); + +void fsdev_get_io_throttle(FsThrottle *, FsdevIOThrottle **iothp, + char *); + #endif /* _FSDEV_THROTTLE_H */ diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 266e442..4bfd233 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -16,6 +16,7 @@ #include "qemu-common.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qmp-commands.h" =20 static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries= =3D QTAILQ_HEAD_INITIALIZER(fsdriver_entries); @@ -98,3 +99,32 @@ FsDriverEntry *get_fsdev_fsentry(char *id) } return NULL; } + +void qmp_fsdev_set_io_throttle(FsdevIOThrottle *arg, Error **errp) +{ + + FsDriverEntry *fse; + + fse =3D get_fsdev_fsentry(arg->has_id ? arg->id : NULL); + if (!fse) { + error_setg(errp, "Not a valid fsdev device"); + return; + } + + fsdev_set_io_throttle(arg, &fse->fst, errp); +} + +FsdevIOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + FsdevIOThrottleList *head =3D NULL, *p_next; + struct FsDriverListEntry *fsle; + + QTAILQ_FOREACH(fsle, &fsdriver_entries, next) { + p_next =3D g_new0(FsdevIOThrottleList, 1); + fsdev_get_io_throttle(&fsle->fse.fst, &p_next->value, + fsle->fse.fsdev_id); + p_next->next =3D head; + head =3D p_next; + } + return head; +} diff --git a/monitor.c b/monitor.c index f4856b9..0a8f0ed 100644 --- a/monitor.c +++ b/monitor.c @@ -998,6 +998,11 @@ static void qmp_unregister_commands_hack(void) && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); #endif +#ifndef CONFIG_VIRTFS + qmp_unregister_command(&qmp_commands, "fsdev-set-io-throttle"); + qmp_unregister_command(&qmp_commands, "query-fsdev-io-throttle"); +#endif + } =20 void monitor_init_qmp_commands(void) diff --git a/qapi-schema.json b/qapi-schema.json index a3ba1c9..d9036f7 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -93,6 +93,10 @@ { 'include': 'qapi/trace.json' } { 'include': 'qapi/introspect.json' } =20 +# QAPI fsdev definitions +{ 'include': 'qapi/fsdev.json' } + + ## # =3D Miscellanea ## diff --git a/qapi/fsdev.json b/qapi/fsdev.json new file mode 100644 index 0000000..3beccab --- /dev/null +++ b/qapi/fsdev.json @@ -0,0 +1,94 @@ +# -*- Mode: Python -*- + +## +# =3D=3D QAPI fsdev definitions +## + +## +# @FsdevIOThrottle: +# +# A set of parameters describing block throttling. +# +# @id: device id +# +# Since: 2.11 +## +{ 'struct': 'FsdevIOThrottle', + 'base': 'ThrottleLimits', + 'data': { '*id': 'str' } } + +## +# @fsdev-set-io-throttle: +# +# Change I/O limits for a 9p/fsdev device. +# +# I/O limits can be enabled by setting throttle value to non-zero number. +# +# I/O limits can be disabled by setting all throttle values to 0. +# +# Returns: Nothing on success +# If @device is not a valid fsdev device, GenericError +# +# Since: 2.11 +# +# Example: +# +# -> { "execute": "fsdev-set-io-throttle", +# "arguments": { "id": "id0-1-0", +# "bps": 1000000, +# "bps_rd": 0, +# "bps_wr": 0, +# "iops": 0, +# "iops_rd": 0, +# "iops_wr": 0, +# "bps_max": 8000000, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 60, +# "iops_size": 0 } } +# <- { "returns": {} } +## +{ 'command': 'fsdev-set-io-throttle', 'boxed': true, + 'data': 'FsdevIOThrottle' } +## +# @query-fsdev-io-throttle: +# +# Returns: a list of @IOThrottle describing I/O throttle +# values of each fsdev device +# +# Since: 2.11 +# +# Example: +# +# -> { "Execute": "query-fsdev-io-throttle" } +# <- { "returns" : [ +# { +# "id": "id0-hd0", +# "bps":1000000, +# "bps_rd":0, +# "bps_wr":0, +# "iops":1000000, +# "iops_rd":0, +# "iops_wr":0, +# "bps_max": 8000000, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 0, +# "bps_rd_max_length": 0, +# "bps_wr_max_length": 0, +# "iops_max_length": 0, +# "iops_rd_max_length": 0, +# "iops_wr_max_length": 0, +# "iops_size": 0 +# } +# ] +# } +# +## +{ 'command': 'query-fsdev-io-throttle', 'returns': [ 'FsdevIOThrottle' ] } diff --git a/qmp.c b/qmp.c index e8c3031..e90a401 100644 --- a/qmp.c +++ b/qmp.c @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp) } } =20 +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__) + +void qmp_fsdev_set_io_throttle(FsdevIOThrottle *arg, Error **errp) +{ + return; +} + +FsdevIOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ + return NULL; +} + +#endif + #ifndef CONFIG_VNC /* If VNC support is enabled, the "true" query-vnc command is defined in the VNC subsystem */ --=20 1.8.3.1