Re: [Qemu-devel] [PATCH v13 0/6] fsdev: qmp interface for io throttling
On 12/6/2017 5:49 PM, Eric Blake wrote: On 12/06/2017 10:15 AM, Pradeep Jagadeesh wrote: I didn't have time to follow the thread, but it's been a month without activity... where do we stand now ? I've merged I/O throttle for fsdev in 2.9, is there a chance we get the QMP/HMP part in 2.12 ? Hi Greg, Yes, I am waiting for Eric's reply. Because there were some issues when I merged code with Manos's throttlelimits code. So, I am waiting to see how to go about it. It needs some changes to reuse in fsdev/blk qmp code. I am very much would like to push qmp code upstream. We missed the window of opportunity to unify any differences in interfaces between what Manos added in 2.11 and your code, now that 2.11 is at -rc4. That means we are stuck with two slightly different interface; although it would still be nice to have glue code that can convert into and out of a preferred form, so that the bulk of the code can be common operations on the preferred struct. At this point, I don't know what additional information you want from myself or Markus on the interface front; it may be easier to post a rebased v14 and tackle it from there (even if it means our interface is still in a state of churn). Thanks for the quick reply. The problem is with the block devices code.So I was thinking to pull out those patches and just go ahead with the fsdev. I can directly use Manos code directly without any changes in fsdev case.So, I would like to go ahead and post v14 patches. Regards, Pradeep
Re: [Qemu-devel] [PATCH v13 0/6] fsdev: qmp interface for io throttling
On 12/6/2017 5:07 PM, Greg Kurz wrote: On Mon, 2 Oct 2017 10:33:26 -0400 Pradeep Jagadeesh <pradeepkiruv...@gmail.com> wrote: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. Some of the patches also remove the duplicate code that was present in block and fsdev files. Hi Pradeep, I didn't have time to follow the thread, but it's been a month without activity... where do we stand now ? I've merged I/O throttle for fsdev in 2.9, is there a chance we get the QMP/HMP part in 2.12 ? Hi Greg, Yes, I am waiting for Eric's reply. Because there were some issues when I merged code with Manos's throttlelimits code. So, I am waiting to see how to go about it. It needs some changes to reuse in fsdev/blk qmp code. I am very much would like to push qmp code upstream. Regards, Pradeep Cheers, -- Greg Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Use ThrottleLimits structure qmp: factor out throttle code to reuse code hmp: create a throttle initialization function for code reuse fsdev: QMP interface for throttling fsdev: hmp interface for throttling Makefile| 3 +- blockdev.c | 97 ++- fsdev/qemu-fsdev-dummy.c| 11 +++ fsdev/qemu-fsdev-throttle.c | 144 ++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 + hmp-commands-info.hx| 18 + hmp-commands.hx | 19 ++ hmp.c | 81 -- hmp.h | 4 ++ include/qemu/throttle-options.h | 3 + include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 4 ++ qapi/block-core.json| 75 + qapi/fsdev.json | 94 ++ qmp.c | 14 util/throttle.c | 70 +++ 19 files changed, 462 insertions(+), 224 deletions(-) create mode 100644 qapi/fsdev.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed unwanted headers from qmp-fsdev-throttle.h v8 -> v9: Addressed comments from Markus Armbruster and Eric Blake Removed the iothrottle.json and pushed the iothrottle struct to block-core.json v9 -> v10: Addressed comments from Albert Garcia Fixed issue related to dynamically passing throttle configuration Removed some unused code v10 -> v11: Addressed the comments from Markus Armbruster and Eric Blake Rebased the patches over 2.10 v11 -> v12: Addressed comments by Manos Pitsidiankis Moved back the device id to the fsdeviothrottle structure v12 -> v13: Addressed comments by Manos Pitsidiankis Replaced the throttle config strings with the macros
Re: [Qemu-devel] [PATCH v13 2/6] qmp: Use ThrottleLimits structure
On 10/13/2017 4:26 PM, Eric Blake wrote: [adding Markus, and block list] On 10/13/2017 09:16 AM, Alberto Garcia wrote: On Mon 02 Oct 2017 04:33:28 PM CEST, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits structure. { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*id': 'str', '*group': 'str' } } So BlockIOThrottle used to have parameters named bps_rd and iops_wr, and after this patch they become bps-read and iops-write. This breaks the API completely, as you can see if you run e.g. iotest 129: AssertionError: failed path traversal for "return" in "{u'error': {u'class': u'GenericError', u'desc': u"Parameter 'iops_rd' is unexpected"}}" I just checked previous versions of the series and I see that Manos already warned you of this in v11: https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg04698.html On the bright side, ThrottleLimits is marked 'since 2.11' (added in commit 432d889e), meaning it has not yet been released, so we CAN fix the naming in ThrottleLimits to be compatible with BlockIOThrottle if we want to share the type, as long as we get it done before the 2.11 release. It does mean tweaking Manos' code to use compatible names everywhere, but that may be a wise course of action (we tend to favor '-' in new API names unless there is a strong reason to use '_'; but sharing code for maximum back-compat would be a reason to use '_'). Could you please have a look at Manos reply and my reply also. Please let me know what you think. -Pradeep
Re: [Qemu-devel] [PATCH v13 2/6] qmp: Use ThrottleLimits structure
On 11/6/2017 10:35 AM, Manos Pitsidianakis wrote: On Fri, Oct 13, 2017 at 09:26:17AM -0500, Eric Blake wrote: [adding Markus, and block list] On 10/13/2017 09:16 AM, Alberto Garcia wrote: On Mon 02 Oct 2017 04:33:28 PM CEST, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits structure. { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*id': 'str', '*group': 'str' } } So BlockIOThrottle used to have parameters named bps_rd and iops_wr, and after this patch they become bps-read and iops-write. This breaks the API completely, as you can see if you run e.g. iotest 129: AssertionError: failed path traversal for "return" in "{u'error': {u'class': u'GenericError', u'desc': u"Parameter 'iops_rd' is unexpected"}}" I just checked previous versions of the series and I see that Manos already warned you of this in v11: https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg04698.html On the bright side, ThrottleLimits is marked 'since 2.11' (added in commit 432d889e), meaning it has not yet been released, so we CAN fix the naming in ThrottleLimits to be compatible with BlockIOThrottle if we want to share the type, as long as we get it done before the 2.11 release. We decided to keep BlockIOThrottle separate from ThrottleLimits because that would break the old I/O throttling API, just like is done in this patch series. BlockIOThrottle is the one using old naming conventions so I think it should be the one to go, if that has to be done. But this all boils down to whether the legacy throttling API has to break in 2.11 or not, which probably is the maintainer's decision. It does mean tweaking Manos' code to use compatible names everywhere, but that may be a wise course of action (we tend to favor '-' in new API names unless there is a strong reason to use '_'; but sharing code for maximum back-compat would be a reason to use '_'). Thanks for your reply Manos. @Eric, So shall I go ahead and revert my patches to as before. I mean using iothrottle structure?. What is your suggestion? -Pradeep -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v13 3/6] qmp: factor out throttle code to reuse code
On 11/2/2017 12:00 PM, Alberto Garcia wrote: On Thu 02 Nov 2017 11:55:26 AM CET, Pradeep Jagadeesh wrote: -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} The old code takes an empty ThrottleConfig, and initializes it using the values from a BlockIOThrottle structure... +tlimit = qapi_BlockIOThrottle_base(arg); +throttle_config_to_limits(, tlimit); ...but the new code does the exact opposite (?). Its a mistake of a call. It should be throttle_limits_to_config() I will change it. Thanks! It would be nice if the series had a few tests to verify that this all is working as expected :-) Sure!. Next time on!. -Pradeep Berto
Re: [Qemu-devel] [PATCH v13 3/6] qmp: factor out throttle code to reuse code
On 10/13/2017 4:29 PM, Alberto Garcia wrote: On Mon 02 Oct 2017 04:33:29 PM CEST, Pradeep Jagadeesh wrote: -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} The old code takes an empty ThrottleConfig, and initializes it using the values from a BlockIOThrottle structure... +tlimit = qapi_BlockIOThrottle_base(arg); +throttle_config_to_limits(, tlimit); ...but the new code does the exact opposite (?). Its a mistake of a call. It should be throttle_limits_to_config() I will change it. Regards, Pradeep Berto
Re: [Qemu-devel] [PATCH v13 2/6] qmp: Use ThrottleLimits structure
On 10/13/2017 4:26 PM, Eric Blake wrote: [adding Markus, and block list] On 10/13/2017 09:16 AM, Alberto Garcia wrote: On Mon 02 Oct 2017 04:33:28 PM CEST, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits structure. { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*id': 'str', '*group': 'str' } } So BlockIOThrottle used to have parameters named bps_rd and iops_wr, and after this patch they become bps-read and iops-write. This breaks the API completely, as you can see if you run e.g. iotest 129: AssertionError: failed path traversal for "return" in "{u'error': {u'class': u'GenericError', u'desc': u"Parameter 'iops_rd' is unexpected"}}" I just checked previous versions of the series and I see that Manos already warned you of this in v11: https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg04698.html On the bright side, ThrottleLimits is marked 'since 2.11' (added in commit 432d889e), meaning it has not yet been released, so we CAN fix the naming in ThrottleLimits to be compatible with BlockIOThrottle if we want to share the type, as long as we get it done before the 2.11 release. It does mean tweaking Manos' code to use compatible names everywhere, but that may be a wise course of action (we tend to favor '-' in new API names unless there is a strong reason to use '_'; but sharing code for maximum back-compat would be a reason to use '_'). Sorry for the late reply. I was out of office. I am ready to change them to "_" instead of "-". Need to ask Manos. @Manos, what do you say about the above comment. That makes sense. It will help to reuse lot of code. Shall we rename the parameters with "_" instead of "-"? Regards, Pradeep
Re: [Qemu-devel] [PATCH v11 1/6] throttle: factor out duplicate code
On 9/23/2017 12:33 PM, Manos Pitsidianakis wrote: On Fri, Sep 22, 2017 at 01:31:58PM +0200, Pradeep Jagadeesh wrote: On 9/18/2017 6:20 PM, Manos Pitsidianakis wrote: On Thu, Sep 14, 2017 at 06:40:05AM -0400, Pradeep Jagadeesh wrote: This patch factors out the duplicate throttle code that was still present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- blockdev.c | 44 +- fsdev/qemu-fsdev-throttle.c | 44 ++ include/qemu/throttle-options.h | 3 +++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 52 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24..9d33c25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_
[Qemu-devel] [PATCH v12 3/6] qmp: factor out throttle code to reuse code
This patch reuses the code to set throttle limits. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++-- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9d33c25..2bd8ebd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2569,6 +2569,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +ThrottleLimits *tlimit; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2586,56 +2587,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +tlimit = qapi_BlockIOThrottle_base(arg); +throttle_config_to_limits(, tlimit); if (!throttle_is_valid(, errp)) { goto out; -- 1.8.3.1
[Qemu-devel] [PATCH v12 5/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> Reviewed-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- 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 337a1f6..6556dbf 100644 --- a/Makefile +++ b/Makefile @@ -421,7 +421,8 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/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 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" 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" 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(>throttled_reqs[true]); } +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(>throttled_reqs[is_write]); +} + +static void schedule_next_request(FsThrottle *fst, bool is_write) +{ +bool must_wait = throttle_schedule_timer(>ts, >tt, is_write); +if (!must_wait) { +if (qemu_in_coroutine() && +throttle_co_restart_queue(fst, is_write)) { +return; +} else { +int64_t now = 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 = opaque; +bool is_write = data->is_write; +bool empty_queue = !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 = { +.fst = fst, +.is_write = true +}; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); + +rd.is_write = false; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); +} + +static void coroutine_fn fsdev_throttle_config(FsThrottle *fst) +{ +if (throttle_enabled(>cfg)) { +throttle_config(>ts, QEMU_CLOCK_REALTIME, >cfg); +} else { +throttle_restart_queues(fst); +} +} + +void fsdev_set_io_throttle(FsdevIOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; +ThrottleLimits *tlimits; + +throttle_get_config(>ts, ); +tlimits = qapi_FsdevIOThrottle_base(arg); +throttle_limits_to_config(tlimits, , errp); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_config(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, FsdevIOThrottle **fs9pcfg, + char *fsdevice) +{ +ThrottleConfig cfg = fst->cfg; +ThrottleLimits *tlimits; +FsdevIOThrottle *fscfg = g_malloc(sizeof(*fscfg)); +tlimits = qapi_FsdevIOThrottle_base(fscfg); + +fscfg->has_id = true; +fscfg->id = g_st
[Qemu-devel] [PATCH v12 6/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- hmp-commands-info.hx | 18 hmp-commands.hx | 19 hmp.c| 61 hmp.h| 4 4 files changed, 102 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 4ab7fce..54f1968 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index acaf0e6..92df590 100644 --- a/hmp.c +++ b/hmp.c @@ -1778,6 +1778,67 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +ThrottleLimits *tlimits; +FsdevIOThrottle throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +tlimits = qapi_FsdevIOThrottle_base(); +hmp_initialize_throttle_limits(tlimits, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, FsdevIOThrottle *fscfg) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps_total, + fscfg->bps_read, + fscfg->bps_write, + fscfg->bps_total_max, + fscfg->bps_read_max, + fscfg->bps_write_max, + fscfg->iops_total, + fscfg->iops_read, + fscfg->iops_write, + fscfg->iops_total_max, + fscfg->iops_read_max, + fscfg->iops_write_max, + fscfg->iops_size); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +FsdevIOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(NULL); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value); +} +qapi_free_FsdevIOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); vo
[Qemu-devel] [PATCH v12 1/6] throttle: factor out duplicate code
This patch factors out the duplicate throttle code that was still present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- blockdev.c | 44 +- fsdev/qemu-fsdev-throttle.c | 44 ++ include/qemu/throttle-options.h | 3 +++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 52 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24..9d33c25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->
[Qemu-devel] [PATCH v12 2/6] qmp: Use ThrottleLimits structure
This patch factors out code to use the ThrottleLimits structure. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- qapi/block-core.json | 75 +++- 1 file changed, 3 insertions(+), 72 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index bb11815..5ca4597 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1824,86 +1824,17 @@ # # A set of parameters describing block throttling. # -# @device: Block device name (deprecated, use @id instead) -# # @id: The name or QOM path of the guest device (since: 2.8) # -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) +# @device: Block device name (deprecated, use @id instead) # # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*id': 'str', '*group': 'str' } } ## # @ThrottleLimits: -- 1.8.3.1
[Qemu-devel] [PATCH v12 4/6] hmp: create a throttle initialization function for code reuse
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- hmp.c | 20 ++-- 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index cd046c6..acaf0e6 100644 --- a/hmp.c +++ b/hmp.c @@ -1752,20 +1752,28 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_throttle_limits(ThrottleLimits *iot, + const QDict *qdict) +{ +iot->bps_total = qdict_get_int(qdict, "bps"); +iot->bps_read = qdict_get_int(qdict, "bps_rd"); +iot->bps_write = qdict_get_int(qdict, "bps_wr"); +iot->iops_total = qdict_get_int(qdict, "iops"); +iot->iops_read = qdict_get_int(qdict, "iops_rd"); +iot->iops_write = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +ThrottleLimits *tlimits; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +tlimits = qapi_BlockIOThrottle_base(); +hmp_initialize_throttle_limits(tlimits, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v12 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. Some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Use ThrottleLimits structure qmp: factor out throttle code to reuse code hmp: create a throttle initialization function for code reuse fsdev: QMP interface for throttling fsdev: hmp interface for throttling Makefile| 3 +- blockdev.c | 97 ++- fsdev/qemu-fsdev-dummy.c| 11 +++ fsdev/qemu-fsdev-throttle.c | 144 ++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 + hmp-commands-info.hx| 18 + hmp-commands.hx | 19 ++ hmp.c | 81 -- hmp.h | 4 ++ include/qemu/throttle-options.h | 3 + include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 4 ++ qapi/block-core.json| 75 + qapi/fsdev.json | 94 ++ qmp.c | 14 util/throttle.c | 52 +++ 19 files changed, 444 insertions(+), 224 deletions(-) create mode 100644 qapi/fsdev.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed unwanted headers from qmp-fsdev-throttle.h v8 -> v9: Addressed comments from Markus Armbruster and Eric Blake Removed the iothrottle.json and pushed the iothrottle struct to block-core.json v9 -> v10: Addressed comments from Albert Garcia Fixed issue related to dynamically passing throttle configuration Removed some unused code v10 -> v11: Addressed the comments from Markus Armbruster and Eric Blake Rebased the patches over 2.10 v11 -> v12: Addressed comments by Manos Pitsidiankis Moved back the device id to the fsdeviothrottle structure -- 1.8.3.1
Re: [Qemu-devel] [PATCH v11 1/6] throttle: factor out duplicate code
On 9/18/2017 6:20 PM, Manos Pitsidianakis wrote: On Thu, Sep 14, 2017 at 06:40:05AM -0400, Pradeep Jagadeesh wrote: This patch factors out the duplicate throttle code that was still present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- blockdev.c | 44 +- fsdev/qemu-fsdev-throttle.c | 44 ++ include/qemu/throttle-options.h | 3 +++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 52 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24..9d33c25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THR
Re: [Qemu-devel] [PATCH v11 1/6] throttle: factor out duplicate code
On 9/18/2017 6:20 PM, Manos Pitsidianakis wrote: On Thu, Sep 14, 2017 at 06:40:05AM -0400, Pradeep Jagadeesh wrote: This patch factors out the duplicate throttle code that was still present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- blockdev.c | 44 +- fsdev/qemu-fsdev-throttle.c | 44 ++ include/qemu/throttle-options.h | 3 +++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 52 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24..9d33c25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THR
Re: [Qemu-devel] [PATCH v11 2/6] qmp: Use ThrottleLimits structure
On 9/18/2017 6:04 PM, Manos Pitsidianakis wrote: On Thu, Sep 14, 2017 at 06:40:06AM -0400, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits strurcture. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Markus Armbruster <arm...@redhat.com> --- qapi/block-core.json | 78 +++- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index bb11815..d0ccfda 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1826,84 +1826,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) BlockIOThrottle and ThrottleLimits are not directly compatible, for example here we have iops_rd_max_length as a name, # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*group': 'str' } } ## # @ThrottleLimits: @@ -1913,6 +1842,7 @@ # transaction. All fields are optional. When setting limits, if a field is # missing the current value is not changed. # +# @id: device id # @iops-total: limit total I/O operations per second # @iops-total-max: I/O operations burst # @iops-total-max-length: length of the iops-total-max burst period, in seconds @@ -1942,7 +1872,7 @@ # Since: 2.11 ## { 'struct': 'ThrottleLimits', - 'data': { '*iops-total' : 'int', '*iops-total-max' : 'int', + 'data': { '*id' : 'str', '*iops-total' : 'int', '*iops-total-max' : 'int', '*iops-total-max-length' : 'int', '*iops-rea
Re: [Qemu-devel] [PATCH v11 2/6] qmp: Use ThrottleLimits structure
On 9/18/2017 7:10 PM, Eric Blake wrote: On 09/14/2017 05:40 AM, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits strurcture. s/strurcture/structure/ Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Echoing the sentiments made elsewhere - this is a significant rewrite from the earlier version, so you WANT reviewers to look at it fresh rather than assuming that previous reviews still apply. OK, but shall I send them as V12 or V01 again? -Pradeep
Re: [Qemu-devel] [PATCH v11 2/6] qmp: Use ThrottleLimits structure
On 9/18/2017 6:25 PM, Manos Pitsidianakis wrote: On Thu, Sep 14, 2017 at 06:40:06AM -0400, Pradeep Jagadeesh wrote: This patch factors out code to use the ThrottleLimits strurcture. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Markus Armbruster <arm...@redhat.com> --- qapi/block-core.json | 78 +++- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index bb11815..d0ccfda 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1826,84 +1826,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*group': 'str' } } ## # @ThrottleLimits: @@ -1913,6 +1842,7 @@ # transaction. All fields are optional. When setting limits, if a field is # missing the current value is not changed. # +# @id: device id # @iops-total: limit total I/O operations per second # @iops-total-max: I/O operations burst # @iops-total-max-length: length of the iops-total-max burst period, in seconds @@ -1942,7 +1872,7 @@ # Since: 2.11 ## { 'struct': 'ThrottleLimits', - 'data': { '*iops-total' : 'int', '*iops-total-max' : 'int', + 'data': { '*id' : 'str', '*iops-total' : 'int', '*iops-total-max' : 'int', '*iops-total-max-length' : 'int', '*iops-read' : 'int', '*iops-read-max' : 'int', '*iops-read-max-length' : 'int', '*iops-write' : 'int', '*iops-
Re: [Qemu-devel] [PATCH v11 2/6] qmp: Use ThrottleLimits structure
On 9/14/2017 1:19 PM, Greg Kurz wrote: On Thu, 14 Sep 2017 06:40:06 -0400 Pradeep Jagadeesh <pradeepkiruv...@gmail.com> wrote: This patch factors out code to use the ThrottleLimits strurcture. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Markus Armbruster <arm...@redhat.com> --- qapi/block-core.json | 78 +++- Uhhh... what happened here ? Where did the lines go ? I've never reviewed this patch before... I did rebase the code on 2.10 Now I am using the ThrottleLimits structure that was introduced IN 2.10. This is same as the IOThrottle structure. So, many things got changed in this version. -Pradeep 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index bb11815..d0ccfda 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1826,84 +1826,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*group': 'str' } } ## # @ThrottleLimits: @@ -1913,6 +1842,7 @@ # transaction. All fields are optional. When setting limits, if a field is # missing the current value is not changed. # +# @id: device id # @iops-total: limit total I/O operations per second # @iops-total-max: I/O operations burst # @iops-total-max-length: length of the iops-total-max burst period, in seconds @@ -1942,7 +1872,7 @@ # Since: 2.11 ## {
[Qemu-devel] [PATCH v11 4/6] hmp: create a throttle initialization function for code reuse
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- hmp.c | 20 ++-- 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index cd046c6..acaf0e6 100644 --- a/hmp.c +++ b/hmp.c @@ -1752,20 +1752,28 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_throttle_limits(ThrottleLimits *iot, + const QDict *qdict) +{ +iot->bps_total = qdict_get_int(qdict, "bps"); +iot->bps_read = qdict_get_int(qdict, "bps_rd"); +iot->bps_write = qdict_get_int(qdict, "bps_wr"); +iot->iops_total = qdict_get_int(qdict, "iops"); +iot->iops_read = qdict_get_int(qdict, "iops_rd"); +iot->iops_write = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +ThrottleLimits *tlimits; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +tlimits = qapi_BlockIOThrottle_base(); +hmp_initialize_throttle_limits(tlimits, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v11 1/6] throttle: factor out duplicate code
This patch factors out the duplicate throttle code that was still present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- blockdev.c | 44 +- fsdev/qemu-fsdev-throttle.c | 44 ++ include/qemu/throttle-options.h | 3 +++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 52 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24..9d33c25 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->
[Qemu-devel] [PATCH v11 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. Some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Use ThrottleLimits structure qmp: factor out throttle code to reuse code hmp: create a throttle initialization function for code reuse fsdev: QMP interface for throttling fsdev: hmp interface for throttling Makefile| 3 +- blockdev.c | 97 ++-- fsdev/qemu-fsdev-dummy.c| 11 fsdev/qemu-fsdev-throttle.c | 140 ++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 ++ hmp.c | 79 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 3 + include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 4 ++ qapi/block-core.json| 78 ++ qapi/fsdev.json | 81 +++ qmp.c | 14 util/throttle.c | 52 +++ 19 files changed, 426 insertions(+), 226 deletions(-) create mode 100644 qapi/fsdev.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed unwanted headers from qmp-fsdev-throttle.h v8 -> v9: Addressed comments from Markus Armbruster and Eric Blake Removed the iothrottle.json and pushed the iothrottle struct to block-core.json v9 -> v10: Addressed comments from Albert Garcia Fixed issue related to dynamically passing throttle configuration Removed some unused code v10 -> v11: Addressed the comments from Markus Armbruster and Eric Blake Rebased the patches over 2.10 -- 1.8.3.1
[Qemu-devel] [PATCH v11 5/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> Reviewed-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- Makefile| 3 +- fsdev/qemu-fsdev-dummy.c| 11 ++ fsdev/qemu-fsdev-throttle.c | 96 ++--- fsdev/qemu-fsdev-throttle.h | 9 - fsdev/qemu-fsdev.c | 30 ++ monitor.c | 5 +++ qapi-schema.json| 4 ++ qapi/fsdev.json | 81 ++ qmp.c | 14 +++ 9 files changed, 244 insertions(+), 9 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 337a1f6..6556dbf 100644 --- a/Makefile +++ b/Makefile @@ -421,7 +421,8 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/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 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..dc5cb6c 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" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(ThrottleLimits *arg, Error **errp) +{ +return; +} + +ThrottleLimitsList *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..fb7a6fa 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" static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,92 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +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(>throttled_reqs[is_write]); +} + +static void schedule_next_request(FsThrottle *fst, bool is_write) +{ +bool must_wait = throttle_schedule_timer(>ts, >tt, is_write); +if (!must_wait) { +if (qemu_in_coroutine() && +throttle_co_restart_queue(fst, is_write)) { +return; +} else { +int64_t now = 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 = opaque; +bool is_write = data->is_write; +bool empty_queue = !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 = { +.fst = fst, +.is_write = true +}; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); + +rd.is_write = false; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); +} + +static void coroutine_fn fsdev_throttle_config(FsThrottle *fst) +{ +if (throttle_enabled(>cfg)) { +throttle_config(>ts, QEMU_CLOCK_REALTIME, >cfg); +} else { +throttle_restart_queues(fst); +} +} + +void fsdev_set_io_throttle(ThrottleLimits *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_get_config(>ts, ); +throttle_limits_to_config(arg, , errp); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_config(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, ThrottleLimits **fs9pcfg, + char *fsdevice) +{ +ThrottleConfig cfg = fst->cfg; +ThrottleLimits *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +throttle_config_to_limits(, fscfg); +*fs9pcfg = fscfg; +} + void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) {
[Qemu-devel] [PATCH v11 6/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- hmp-commands-info.hx | 18 hmp-commands.hx | 19 + hmp.c| 59 hmp.h| 4 4 files changed, 100 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 4ab7fce..54f1968 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index acaf0e6..ceec6c9 100644 --- a/hmp.c +++ b/hmp.c @@ -1778,6 +1778,65 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +ThrottleLimits throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +hmp_initialize_throttle_limits(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, ThrottleLimits *fscfg) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps_total, + fscfg->bps_read, + fscfg->bps_write, + fscfg->bps_total_max, + fscfg->bps_read_max, + fscfg->bps_write_max, + fscfg->iops_total, + fscfg->iops_read, + fscfg->iops_write, + fscfg->iops_total_max, + fscfg->iops_read_max, + fscfg->iops_write_max, + fscfg->iops_size); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +ThrottleLimitsList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(NULL); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value); +} +qapi_free_ThrottleLimitsList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mo
[Qemu-devel] [PATCH v11 3/6] qmp: factor out throttle code to reuse code
This patch reuses the code to set throttle limits. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Greg Kurz <gr...@kaod.org> --- blockdev.c | 53 +++-- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9d33c25..2bd8ebd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2569,6 +2569,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +ThrottleLimits *tlimit; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2586,56 +2587,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +tlimit = qapi_BlockIOThrottle_base(arg); +throttle_config_to_limits(, tlimit); if (!throttle_is_valid(, errp)) { goto out; -- 1.8.3.1
[Qemu-devel] [PATCH v11 2/6] qmp: Use ThrottleLimits structure
This patch factors out code to use the ThrottleLimits strurcture. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> Reviewed-by: Markus Armbruster <arm...@redhat.com> --- qapi/block-core.json | 78 +++- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index bb11815..d0ccfda 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1826,84 +1826,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'ThrottleLimits', + 'data': { '*device': 'str', '*group': 'str' } } ## # @ThrottleLimits: @@ -1913,6 +1842,7 @@ # transaction. All fields are optional. When setting limits, if a field is # missing the current value is not changed. # +# @id: device id # @iops-total: limit total I/O operations per second # @iops-total-max: I/O operations burst # @iops-total-max-length: length of the iops-total-max burst period, in seconds @@ -1942,7 +1872,7 @@ # Since: 2.11 ## { 'struct': 'ThrottleLimits', - 'data': { '*iops-total' : 'int', '*iops-total-max' : 'int', + 'data': { '*id' : 'str', '*iops-total' : 'int', '*iops-total-max' : 'int', '*iops-total-max-length' : 'int', '*iops-read' : 'int', '*iops-read-max' : 'int', '*iops-read-max-length' : 'int', '*iops-write' : 'int', '*iops-write-max' : 'int', -- 1.8.3.1
Re: [Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling
On 9/8/2017 2:34 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> writes: On 9/8/2017 12:02 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: [...] diff --git a/qmp.c b/qmp.c index b86201e..eed91e5 100644 --- a/qmp.c +++ b/qmp.c @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp) } } +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__) + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *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 */ Why do we need *two* stubs for these functions, one here and one in fsdev/qemu-fsdev-dummy.c? At two different platforms the build fails. So, there are needed. We don't add stubs to random places until the linker succeeds for all the configurations we happen to test. We figure out *how* the linker fails to correct our idea of where a certain stub belongs until we find the one appropriate home for it. If you can't figure that out, that's okay, just tell us how exactly the linker fails for you, and we'll be happy to help. If I do not have those stubs in qmp.c.The linking fails when I compile like "make docker-test-mingw@fedora" The stubs in qemu-fsdev-dummy.c required because when I configure on x86 as --disable-virtfs, then the compilation fails. So, I need the stubs at both the places. Please let me know if I can avoid some how. Regards, Pradeep
Re: [Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling
On 9/8/2017 2:34 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> writes: On 9/8/2017 12:02 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: [...] diff --git a/qmp.c b/qmp.c index b86201e..eed91e5 100644 --- a/qmp.c +++ b/qmp.c @@ -130,6 +130,20 @@ void qmp_cpu_add(int64_t id, Error **errp) } } +#if defined(_WIN64) || defined(_WIN32) || defined(__FreeBSD__) + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *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 */ Why do we need *two* stubs for these functions, one here and one in fsdev/qemu-fsdev-dummy.c? At two different platforms the build fails. So, there are needed. We don't add stubs to random places until the linker succeeds for all the configurations we happen to test. We figure out *how* the linker fails to correct our idea of where a certain stub belongs until we find the one appropriate home for it. OK, I will figure it out and send it across. But these were discussed since the v1, now I do not remember on top of my mind. I will have to dig my old emails and send it across or I should reproduce them again. If you can't figure that out, that's okay, just tell us how exactly the linker fails for you, and we'll be happy to help. Thanks for offering help! -Pradeep
Re: [Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling
On 9/8/2017 12:02 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: 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 <pradeep.jagade...@huawei.com> --- Makefile| 4 ++ fsdev/qemu-fsdev-dummy.c| 11 fsdev/qemu-fsdev-throttle.c | 145 ++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/fsdev.json | 81 + qmp.c | 14 + 9 files changed, 294 insertions(+), 8 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 81447b1..ec31ffa 100644 --- a/Makefile +++ b/Makefile @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + The ifdef is a *lie*: qapi.py *will* include this file no matter what. Lying to make is not a good idea. Drop the ifdef. Yes, thats right. As of these are useless. For the same reason I have these dummy functions in two different places. qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..28c82d2 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" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +return NULL; +} Predates this patch: should this be in stubs/? Might simplify fsdev/Makefile.objs. Explained above diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 0e6fb86..525352e 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c [Skipping this one...] diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h index e418643..bfeab40 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 -#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; @@ -36,4 +35,10 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *, bool , struct iovec *, int); void fsdev_throttle_cleanup(FsThrottle *); + +void fsdev_set_io_throttle(IOThrottle *, FsThrottle *, Error **errp); + +void fsdev_get_io_throttle(FsThrottle *, IOThrottle **iothp, + char *); Include the last parameter's name, for consistency with the other parameter declarations. OK + #endif /* _FSDEV_THROTTLE_H */ diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 266e442..0f701fc 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" static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = QTAILQ_HEAD_INITIALIZER(fsdriver_entries); @@ -98,3 +99,32 @@ FsDriverEntry *get_fsdev_fsentry(char *id) } return NULL; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + +FsDriverEntry *fse; + +fse = get_fsdev_fsentry(arg->has_id ? arg->id : NULL); !arg->has_id implies !arg->id. Therefore, Just arg->id would do, no need to check arg->has_id first. It's not wrong, though. +if (!fse) { +error_setg(errp, "Not a valid fsdev device"); +return; +} + +fsdev_set_io_throttle(arg, >fst, errp); +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +IOThrottleList *head = NULL, *p_next; +struct FsDriverListEntry *fsle; + +QTAILQ_FOREACH(fsle, _entries, next) { +p_next = g_new0(IOThrottleList, 1); +fsdev_get_io_throttle(>fse.fst, _next->value, + fsle->f
Re: [Qemu-devel] [PATCH v10 0/6] fsdev: qmp interface for io throttling
On 9/5/2017 11:19 PM, Eric Blake wrote: On 09/04/2017 11:07 AM, Pradeep Jagadeesh wrote: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: QMP interface for throttling fsdev: hmp interface for throttling I know you're already up to v10, but your code changes conflict with Manos throttling work, which has now landed on Kevin's branch: https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01051.html T: git git://repo.or.cz/qemu/kevin.git block How hard is it for you to post a rebased v11 on top of Manos' work? Hmm, I will try. No idea, how long its gonna take. -Pradeep
Re: [Qemu-devel] [PATCH v10 6/6] fsdev: hmp interface for throttling
On 9/5/2017 11:34 AM, Alberto Garcia wrote: On Tue 05 Sep 2017 11:13:09 AM CEST, Pradeep Jagadeesh wrote: a) Declare an Error, pass it _and then handle it_ (if you don't handle it, you're leaking it): Here you have no other way to know if qmp_query_fsdev_io_throttle() fails, so you should choose (a). OK, I will pass NULL. :-) (it's ok I guess, I don't see how that function can ever be made to fail in the future) :) Agreed. -Pradeep Berto
Re: [Qemu-devel] [PATCH v10 6/6] fsdev: hmp interface for throttling
On 9/5/2017 11:07 AM, Alberto Garcia wrote: On Tue 05 Sep 2017 10:28:02 AM CEST, Pradeep Jagadeesh wrote: +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value); +} +qapi_free_IOThrottleList(fsdev_list); +} You're passing an Error to qmp_query_fsdev_io_throttle() but then you don't handle it. Use hmp_handle_error() as I said in my previous e-mail. OK I will handle it. I know that with the current code qmp_query_fsdev_io_throttle() is never going to fail, but that's no reason to declare an Error and then ignore it. I need to pass err because the function qmp_query_fsdev_io_throttle(Error *) is created by the scripts. So, I have to declare and pass it. I do not is there any way to avoid this. When a function takes an Error ** like qmp_query_fsdev_io_throttle() and many others do, there are two alternatives: a) Declare an Error, pass it _and then handle it_ (if you don't handle it, you're leaking it): Error *err = NULL; some_function(); if (err) { /* handle err */ } b) Don't declare the Error and pass NULL instead: some_function(NULL); Note that (b) is perfectly valid, but if the function you're calling tries to set an Error then you won't get it. It's ok if you know what you're doing (which usually means: you have other way to determine if the function failed, _or_ you don't care if the function failed). Here you have no other way to know if qmp_query_fsdev_io_throttle() fails, so you should choose (a). I know that at the moment qmp_query_fsdev_io_throttle() can never fail so in practice this doesn't matter much _now_, but if in the future that function can fail then your code should be ready to handle it. OK, I will pass NULL. -Pradeep Berto
Re: [Qemu-devel] [PATCH v10 6/6] fsdev: hmp interface for throttling
On 9/5/2017 9:53 AM, Alberto Garcia wrote: On Mon 04 Sep 2017 06:07:47 PM CEST, Pradeep Jagadeesh wrote: +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value); +} +qapi_free_IOThrottleList(fsdev_list); +} You're passing an Error to qmp_query_fsdev_io_throttle() but then you don't handle it. Use hmp_handle_error() as I said in my previous e-mail. OK I will handle it. I know that with the current code qmp_query_fsdev_io_throttle() is never going to fail, but that's no reason to declare an Error and then ignore it. I need to pass err because the function qmp_query_fsdev_io_throttle(Error *) is created by the scripts. So, I have to declare and pass it. I do not is there any way to avoid this. -Pradeep Berto
[Qemu-devel] [PATCH v10 3/6] throttle: move out function to reuse the code
This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 53 +++- include/qemu/throttle-options.h | 2 ++ util/throttle.c | 59 + 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 780ae58..1caf2e0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2571,6 +2571,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2588,56 +2589,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index f63d38c..b736185 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "typedefs.h" +#include "qapi-types.h" #define THROTTLE_OPTS \ { \ @@ -92,5 +93,6 @@ } void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); #endif diff --git a/util/throttle.c b/util/throttle.c index 95c2ecf..dcc9d5a 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* Initialize a throttle config from an IOThrottle structure + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ +throttle_config_init(cfg); +cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; +cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; +cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + +cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; +cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; +cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + +if (arg->has_bps_max) { +cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; +} +if (arg->has_bps_rd_max) { +cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; +} +if (arg->has_bps_wr_max) { +cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; +} +if (arg->has_iops_max) { +cfg->buckets[THROTTLE_OPS_TOTAL].max = ar
[Qemu-devel] [PATCH v10 4/6] hmp: create a throttle initialization function for code reusability
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp.c | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index fd80dce..2dbfb80 100644 --- a/hmp.c +++ b/hmp.c @@ -1758,20 +1758,27 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v10 2/6] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- qapi/block-core.json | 34 +- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 833c602..a01074c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1819,11 +1819,13 @@ 'data': 'BlockIOThrottle' } ## -# @BlockIOThrottle: -# -# A set of parameters describing block throttling. +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: # -# @device: Block device name (deprecated, use @id instead) +# A set of parameters describing IO throttling # # @id: The name or QOM path of the guest device (since: 2.8) # @@ -1889,12 +1891,11 @@ # # @iops_size: an I/O size in bytes (Since 1.7) # -# @group: throttle group name (Since 2.4) # -# Since: 1.1 +# Since: 2.11 ## -{ 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', +{ 'struct': 'IOThrottle', + 'data': { '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', @@ -1902,7 +1903,22 @@ '*bps_max_length': 'int', '*bps_rd_max_length': 'int', '*bps_wr_max_length': 'int', '*iops_max_length': 'int', '*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } +'*iops_size': 'int' } } + +## +# @BlockIOThrottle: +# +# A set of parameters describing block throttling. +# +# @device: Block device name (deprecated, use @id instead) +# +# @group: throttle group name (Since 2.4) +# +# Since: 1.1 +## +{ 'struct': 'BlockIOThrottle', + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: -- 1.8.3.1
[Qemu-devel] [PATCH v10 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: QMP interface for throttling fsdev: hmp interface for throttling Makefile| 4 + blockdev.c | 97 + fsdev/qemu-fsdev-dummy.c| 11 +++ fsdev/qemu-fsdev-throttle.c | 189 ++-- fsdev/qemu-fsdev-throttle.h | 9 +- fsdev/qemu-fsdev.c | 30 +++ hmp-commands-info.hx| 18 hmp-commands.hx | 19 hmp.c | 79 +++-- hmp.h | 4 + include/qemu/throttle-options.h | 6 ++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 34 ++-- qapi/fsdev.json | 81 + qmp.c | 14 +++ util/throttle.c | 110 +++ 19 files changed, 558 insertions(+), 160 deletions(-) create mode 100644 qapi/fsdev.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed unwanted headers from qmp-fsdev-throttle.h v8 -> v9: Addressed comments from Markus Armbruster and Eric Blake Removed the iothrottle.json and pushed the iothrottle struct to block-core.json v9 -> v10: Addressed comments from Albert Garcia Fixed issue related to dynamically passing throttle configuration Removed some unused code -- 1.8.3.1
[Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> --- Makefile| 4 ++ fsdev/qemu-fsdev-dummy.c| 11 fsdev/qemu-fsdev-throttle.c | 145 ++-- fsdev/qemu-fsdev-throttle.h | 9 ++- fsdev/qemu-fsdev.c | 30 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/fsdev.json | 81 + qmp.c | 14 + 9 files changed, 294 insertions(+), 8 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 81447b1..ec31ffa 100644 --- a/Makefile +++ b/Makefile @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..28c82d2 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" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *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..525352e 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" static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,141 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +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(>throttled_reqs[is_write]); +} + +static void schedule_next_request(FsThrottle *fst, bool is_write) +{ +bool must_wait = throttle_schedule_timer(>ts, >tt, is_write); +if (!must_wait) { +if (qemu_in_coroutine() && +throttle_co_restart_queue(fst, is_write)) { +return; +} else { +int64_t now = 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 = opaque; +bool is_write = data->is_write; +bool empty_queue = !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 = { +.fst = fst, +.is_write = true +}; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); + +rd.is_write = false; + +co = qemu_coroutine_create(throttle_restart_queue_entry, ); +aio_co_enter(fst->ctx, co); +} + +static void coroutine_fn fsdev_throttle_config(FsThrottle *fst) +{ +if (throttle_enabled(>cfg)) { +throttle_config(>ts, QEMU_CLOCK_REALTIME, >cfg); +} else { +throttle_restart_queues(fst); +} +} + +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_config(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice) +{ +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg;
[Qemu-devel] [PATCH v10 6/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 hmp-commands.hx | 19 + hmp.c| 60 hmp.h| 4 4 files changed, 101 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238..07ed338 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 2dbfb80..6e63cf1 100644 --- a/hmp.c +++ b/hmp.c @@ -1783,6 +1783,66 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value); +} +qapi_free_IOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict); +#ifdef CONFIG_VIRTFS +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict); +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict); +#endif void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); void hmp_block_stream(Monitor *mon, const QDict *qdict); void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); -- 1.8.3.1
[Qemu-devel] [PATCH v10 1/6] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 44 +-- fsdev/qemu-fsdev-throttle.c | 44 ++- include/qemu/throttle-options.h | 4 include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 02cd69b..780ae58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -388,49 +388,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-
Re: [Qemu-devel] [PATCH v8 5/6] fsdev: hmp interface for throttling
On 8/30/2017 11:38 AM, Alberto Garcia wrote: On Tue 29 Aug 2017 04:23:06 PM CEST, Pradeep Jagadeesh wrote: +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); + hmp_handle_error(mon, ); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value, err); +} +qapi_free_IOThrottleList(fsdev_list); +} I don't think what you're doing with the Error here is right: - You store the error returned by qmp_query_fsdev_io_throttle(). - You report the error for _every_ fsdev in the list. That doesn't make much sense. - Furthermore, if there's an error then fsdev_list should be empty, so you're not reporting anything (and you're leaking the error). - Even if the list was not empty, hmp_handle_error() frees the error after reporting it. Therefore the second item in the list would try to report an error that has already been freed. You mean something like below? fsdev_list = qmp_query_fsdev_io_throttle(); if (err) { error_report_err(err); return; } Regards, Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/31/2017 3:34 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 05:12:22 PM CEST, Pradeep Jagadeesh wrote: On 8/30/2017 5:10 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 05:07:29 PM CEST, Pradeep Jagadeesh wrote: Thanks for the steps, I did reproduce the issue easily. Looking into the code, may be we also need to try the same with the block devices. I did some tests and it was working fine, so I'd suspect of the fsdev code first. OK, thanks for the clarification. I will look into fsdev code. I just took a quick look at the code, the problem is almost certainly in fsdev_set_io_throttle(): that doesn't simply update the config, it also reinitializes the FsThrottle structure completely, creates new timers and new throttled_reqs queues. If there were pending requests there they're probably lost forever. Take a look at blk_set_io_limits() and see how it is done for block devices. I fixed it. I am testing it. I was initializing the queues again. But it just needs updation of throttle configuration. -Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/31/2017 3:34 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 05:12:22 PM CEST, Pradeep Jagadeesh wrote: On 8/30/2017 5:10 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 05:07:29 PM CEST, Pradeep Jagadeesh wrote: Thanks for the steps, I did reproduce the issue easily. Looking into the code, may be we also need to try the same with the block devices. I did some tests and it was working fine, so I'd suspect of the fsdev code first. OK, thanks for the clarification. I will look into fsdev code. I just took a quick look at the code, the problem is almost certainly in fsdev_set_io_throttle(): that doesn't simply update the config, it also reinitializes the FsThrottle structure completely, creates new timers and new throttled_reqs queues. If there were pending requests there they're probably lost forever. Take a look at blk_set_io_limits() and see how it is done for block devices. Yes, that is right. I had a look. Now I am figuring out how to initialize the timers without loosing the pending requests. If I update the config when there is no IO going, it works fine. When IO is going and try to update it hangs. -Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/30/2017 5:10 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 05:07:29 PM CEST, Pradeep Jagadeesh wrote: Thanks for the steps, I did reproduce the issue easily. Looking into the code, may be we also need to try the same with the block devices. I did some tests and it was working fine, so I'd suspect of the fsdev code first. OK, thanks for the clarification. I will look into fsdev code. -Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/30/2017 4:54 PM, Alberto Garcia wrote: On Wed 30 Aug 2017 02:10:53 PM CEST, Pradeep Jagadeesh wrote: I'm trying to read from an 9p share that has limits set with hmp fsdev_set_io_throttle and I'm having some problems. Here's one simple way to reproduce it: 1) Launch qemu with -fsdev local,security_model=none,id=fs0,path=/some/files -device virtio-9p-pci,fsdev=fs0,mount_tag=fs0 2) In the guest, mount the fs0 share in /mnt 3) Run this hmp command fsdev_set_io_throttle fs0 0 4096 0 0 0 0 4) In the guest, start reading some large file from the 9p share: dd if=/mnt/large_file of=/dev/null bs=4k iflag=direct status=progress 5) Check the progress, reading speed should be around 4k per second. 6) While dd is still running, change the I/O limits: fsdev_set_io_throttle fs0 0 8192 0 0 0 0 7) If you check the status of the dd command, reading should be faster now. Instead, it is stalled. Thanks for the steps, I did reproduce the issue easily. Looking into the code, may be we also need to try the same with the block devices. -Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/30/2017 2:07 PM, Alberto Garcia wrote: On Tue 29 Aug 2017 04:23:01 PM CEST, Pradeep Jagadeesh wrote: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. I'm trying to read from an 9p share that has limits set with hmp fsdev_set_io_throttle and I'm having some problems. For example if I'm reading a large file and I change the I/O limits while the file is still being read then the guest process freezes. Can you try to reproduce that scenario? Thanks for letting me know about the issue. OK, I will try to reproduce.have a look. -Pradeep Berto
Re: [Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
On 8/29/2017 4:36 PM, Alberto Garcia wrote: On Tue 29 Aug 2017 04:23:01 PM CEST, Pradeep Jagadeesh wrote: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Oops, I was just reviewing the previous version of this series, but it looks like you just moved code around, so my comments still apply. Anyway, this should be v9, shouldn't it? v8 was published weeks ago: https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg01043.html Hmm, sorry it should be v9, I missed. I will resend the patches with newer version. Regards, Pradeep Berto
[Qemu-devel] [PATCH v8 2/6] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- qapi/block-core.json | 34 +- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 833c602..95bbc5e 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1819,11 +1819,13 @@ 'data': 'BlockIOThrottle' } ## -# @BlockIOThrottle: -# -# A set of parameters describing block throttling. +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: # -# @device: Block device name (deprecated, use @id instead) +# A set of parameters describing IO throttling # # @id: The name or QOM path of the guest device (since: 2.8) # @@ -1889,12 +1891,11 @@ # # @iops_size: an I/O size in bytes (Since 1.7) # -# @group: throttle group name (Since 2.4) # -# Since: 1.1 +# Since: 2.11 ## -{ 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', +{ 'struct': 'IOThrottle', + 'data': { '*id': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', @@ -1902,7 +1903,22 @@ '*bps_max_length': 'int', '*bps_rd_max_length': 'int', '*bps_wr_max_length': 'int', '*iops_max_length': 'int', '*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } +'*iops_size': 'int' } } + +## +# @BlockIOThrottle: +# +# A set of parameters describing block throttling. +# +# @device: Block device name (deprecated, use @id instead) +# +# @group: throttle group name (Since 2.4) +# +# Since: 1.1 +## +{ 'struct': 'BlockIOThrottle', + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: -- 1.8.3.1
[Qemu-devel] [PATCH v8 6/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 11 ++ fsdev/qemu-fsdev-throttle.c | 76 ++ fsdev/qemu-fsdev-throttle.h | 8 +++-- fsdev/qemu-fsdev.c | 38 + monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 81 + qmp.c | 14 9 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 81447b1..ec31ffa 100644 --- a/Makefile +++ b/Makefile @@ -414,6 +414,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..28c82d2 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" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *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..184ed4c 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" static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg->has_iops_max_length= fscfg->has_iops_max; +fscfg->iops_max_length= + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; +fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; +fscfg->iops_rd_
[Qemu-devel] [PATCH v8 1/6] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 44 +-- fsdev/qemu-fsdev-throttle.c | 44 ++- include/qemu/throttle-options.h | 4 include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 02cd69b..780ae58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -388,49 +388,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-
[Qemu-devel] [PATCH v8 3/6] throttle: move out function to reuse the code
This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 59 + 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 780ae58..1caf2e0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2571,6 +2571,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2588,56 +2589,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index f63d38c..a9deb8e 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "typedefs.h" +#include "qapi-types.h" #define THROTTLE_OPTS \ { \ @@ -93,4 +94,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index 95c2ecf..2d00532 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ +throttle_config_init(cfg); +cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; +cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; +cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + +cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; +cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; +cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + +if (arg->has_bps_max) { +cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; +} +if (arg->has_bps_rd_max) { +cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; +} +if (arg->has_bps_wr_max) { +cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; +} +if (arg->has_iops_max) { +cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; +} +if (arg->has_iops_rd_max) { +cfg->buckets[THROTTLE_OPS_READ].max = arg-
[Qemu-devel] [PATCH v8 4/6] hmp: create a throttle initialization function for code reusability
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp.c | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index fd80dce..2dbfb80 100644 --- a/hmp.c +++ b/hmp.c @@ -1758,20 +1758,27 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v8 5/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 +++ hmp-commands.hx | 19 hmp.c| 62 hmp.h| 4 4 files changed, 103 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238..07ed338 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 2dbfb80..712c6a3 100644 --- a/hmp.c +++ b/hmp.c @@ -1783,6 +1783,68 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); + hmp_handle_error(mon, ); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value, err); +} +qapi_free_IOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict);
[Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 4 ++ blockdev.c | 97 ++-- fsdev/qemu-fsdev-dummy.c| 11 fsdev/qemu-fsdev-throttle.c | 120 ++-- fsdev/qemu-fsdev-throttle.h | 8 ++- fsdev/qemu-fsdev.c | 38 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 81 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 34 +--- qapi/fsdev.json | 81 +++ qmp.c | 14 + util/throttle.c | 110 19 files changed, 505 insertions(+), 154 deletions(-) create mode 100644 qapi/fsdev.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed the iothrottle.json and pushed the iothrottle struct to block-core.json -- 1.8.3.1
Re: [Qemu-devel] [PATCH v7 2/6] qmp: Create IOThrottle structure
On 8/8/2017 5:18 PM, Markus Armbruster wrote: Alberto Garcia <be...@igalia.com> writes: On Tue 08 Aug 2017 02:30:43 PM CEST, Pradeep Jagadeesh wrote: On 8/8/2017 1:30 PM, Alberto Garcia wrote: On Mon 07 Aug 2017 04:48:38 PM CEST, Markus Armbruster wrote: Awkward question for a v7, but here goes anyway: why is IOThrottle worth its very own .json file? I feel this is a common throttle structure that is used by block devices as well as fsdev, so moved to a separate file. I'm not sure that's a good idea. Kevin, Berto, what do you think? Mmm... I don't have a very strong opinion, but if there's no actual need to move it to a separate file I'd prefer to leave it where it is. The segregation is the solid reason. Because throttling is a feature that is used by fsdev, block may many more in future. I do not see moving it back to block does it make any sense? It's not "moving it back", it's keeping it where it is. But I see no big problem with moving it to a common file either. I'd rather not put every struct shared across subsystem boundaries in its own file. We can keep it right where it is for now. Bonus: more readable diff. If we start sharing more throttle-related material than just a struct, we can reconsider. We could also move it to the existing file for common stuff: qapi/common.json. Not a great fit, though. So, the final conclusion is to move to common.json? Regards, Pradeep
Re: [Qemu-devel] [PATCH v7 2/6] qmp: Create IOThrottle structure
On 8/8/2017 1:30 PM, Alberto Garcia wrote: On Mon 07 Aug 2017 04:48:38 PM CEST, Markus Armbruster wrote: Awkward question for a v7, but here goes anyway: why is IOThrottle worth its very own .json file? I feel this is a common throttle structure that is used by block devices as well as fsdev, so moved to a separate file. I'm not sure that's a good idea. Kevin, Berto, what do you think? Mmm... I don't have a very strong opinion, but if there's no actual need to move it to a separate file I'd prefer to leave it where it is. The segregation is the solid reason. Because throttling is a feature that is used by fsdev, block may many more in future. I do not see moving it back to block does it make any sense? Regards, Pradeep Berto
Re: [Qemu-devel] [PATCH V8 5/6] fsdev: QMP interface for throttling
On 8/7/2017 2:44 PM, Eric Blake wrote: On 08/07/2017 07:37 AM, Pradeep Jagadeesh wrote: 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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 11 ++ fsdev/qemu-fsdev-throttle.c | 76 fsdev/qemu-fsdev-throttle.h | 8 +++-- fsdev/qemu-fsdev.c | 38 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 qapi/fsdev.json +## +# @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.10 +# 2.11, now. Hmm!. -Pradeep
[Qemu-devel] [PATCH V8 6/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 +++ hmp-commands.hx | 19 hmp.c| 62 hmp.h| 4 4 files changed, 103 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238..07ed338 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..aef9f79 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1680,6 +1680,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 2dbfb80..712c6a3 100644 --- a/hmp.c +++ b/hmp.c @@ -1783,6 +1783,68 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); + hmp_handle_error(mon, ); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value, err); +} +qapi_free_IOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index 1ff4552..d700d7d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict);
[Qemu-devel] [PATCH V8 1/6] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 44 +-- fsdev/qemu-fsdev-throttle.c | 44 ++- include/qemu/throttle-options.h | 4 include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index 02cd69b..780ae58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -388,49 +388,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 49eebb5..0e6fb86 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-
[Qemu-devel] [PATCH V8 5/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 11 ++ fsdev/qemu-fsdev-throttle.c | 76 fsdev/qemu-fsdev-throttle.h | 8 +++-- fsdev/qemu-fsdev.c | 38 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 97a58a0..5af92cb 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..28c82d2 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" int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ +return; +} + +IOThrottleList *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..184ed4c 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" static void fsdev_throttle_read_timer_cb(void *opaque) @@ -30,6 +31,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg->has_iops_max_length= fscfg->has_iops_max; +fscfg->iops_max_length= + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; +fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; +fscfg->iops_rd_
[Qemu-devel] [PATCH V8 4/6] hmp: create a throttle initialization function for code reusability
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp.c | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index fd80dce..2dbfb80 100644 --- a/hmp.c +++ b/hmp.c @@ -1758,20 +1758,27 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v8 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: QMP interface for throttling fsdev: hmp interface for throttling Makefile| 4 ++ blockdev.c | 97 ++-- fsdev/qemu-fsdev-dummy.c| 11 fsdev/qemu-fsdev-throttle.c | 120 ++-- fsdev/qemu-fsdev-throttle.h | 8 ++- fsdev/qemu-fsdev.c | 38 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 81 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 + qapi/fsdev.json | 84 qapi/iothrottle.json| 88 + qmp.c | 14 + util/throttle.c | 110 20 files changed, 574 insertions(+), 218 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle v7 -> v8: Addressed comments from Markus Armbruster and Eric Blake Removed unwanted headers from qmp-fsdev-throttle.h -- 1.8.3.1
[Qemu-devel] [PATCH V8 3/6] throttle: move out function to reuse the code
This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 59 + 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index 780ae58..1caf2e0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2571,6 +2571,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2588,56 +2589,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index f63d38c..a9deb8e 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "typedefs.h" +#include "qapi-types.h" #define THROTTLE_OPTS \ { \ @@ -93,4 +94,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index 95c2ecf..2d00532 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -553,3 +553,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ +throttle_config_init(cfg); +cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; +cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; +cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + +cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; +cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; +cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + +if (arg->has_bps_max) { +cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; +} +if (arg->has_bps_rd_max) { +cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; +} +if (arg->has_bps_wr_max) { +cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; +} +if (arg->has_iops_max) { +cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; +} +if (arg->has_iops_rd_max) { +cfg->buckets[THROTTLE_OPS_READ].max = arg-
[Qemu-devel] [PATCH V8 2/6] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- qapi/block-core.json | 76 ++--- qapi/iothrottle.json | 88 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 qapi/iothrottle.json diff --git a/qapi/block-core.json b/qapi/block-core.json index 833c602..98147ef 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -6,6 +6,7 @@ # QAPI common definitions { 'include': 'common.json' } +{ 'include': 'iothrottle.json' } ## # @SnapshotInfo: @@ -1825,84 +1826,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: diff --git a/qapi/iothrottle.json b/qapi/iothrottle.json new file mode 100644 index 000..0f067c3 --- /dev/null +++ b/qapi/iothrottle.json @@ -0,0 +1,88 @@ +# -*- Mode: Python -*- + +## +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: +# +# A set of parameters describing IO throttling +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: write throughput limit in bytes per second +# +# @iops:
Re: [Qemu-devel] [PATCH v7 2/6] qmp: Create IOThrottle structure
On 7/6/2017 7:55 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- qapi/block-core.json | 76 ++--- qapi/iothrottle.json | 88 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 qapi/iothrottle.json diff --git a/qapi/block-core.json b/qapi/block-core.json index f85c223..9320974 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -6,6 +6,7 @@ # QAPI common definitions { 'include': 'common.json' } +{ 'include': 'iothrottle.json' } ## # @SnapshotInfo: @@ -1761,84 +1762,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: diff --git a/qapi/iothrottle.json b/qapi/iothrottle.json new file mode 100644 index 000..0f067c3 --- /dev/null +++ b/qapi/iothrottle.json @@ -0,0 +1,88 @@ +# -*- Mode: Python -*- + +## +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: +# +# A set of parameters describing IO throttling +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read
Re: [Qemu-devel] [PATCH v7 5/6] fsdev: hmp interface for throttling
On 7/6/2017 8:15 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Fails to compile, first error: /work/armbru/qemu/hmp.c: In function ‘hmp_fsdev_set_io_throttle’: /work/armbru/qemu/hmp.c:1791:5: warning: implicit declaration of function ‘qmp_fsdev_set_io_throttle’ [-Wimplicit-function-declaration] qmp_fsdev_set_io_throttle(, ); ^ Do you need to swap PATCH 5 and 6? Hmm, yes better to swap, because of dependency. I will do in V8. -Pradeep
Re: [Qemu-devel] [PATCH v7 1/6] throttle: factor out duplicate code
On 7/10/2017 4:41 PM, Eric Blake wrote: On 07/04/2017 10:30 AM, Pradeep Jagadeesh wrote: This patch factor out the duplicate throttle code that was present in s/This patch factor/Factor/ It's okay to write commit messages in the imperative tense; the easiest way I know to start a good message is to use an implied "Apply this patch to ..." in front of the sentence. But "Apply this patch to This patch ..." obviously doesn't flow, compared to "Apply this patch to factor ..." OK block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- Reviewed-by: Eric Blake <ebl...@redhat.com>
Re: [Qemu-devel] [PATCH v7 6/6] fsdev: QMP interface for throttling
On 7/6/2017 8:47 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: 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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 10 ++ fsdev/qemu-fsdev-throttle.c | 76 +++- fsdev/qemu-fsdev-throttle.h | 13 +++ fsdev/qemu-fsdev.c | 37 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 16a0430..4fd7625 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS Uh, qapi-schema.json includes fsdev.json *unconditionally*, doesn't it? Yes, I did not find any ways to include with some condition. +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..f33305d 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -19,3 +19,13 @@ int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; Indentation is off. Will fix +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +abort(); +} Any particular reason why one of the stubs abort()s, but not the other? No idea, I think can even return NULL. I will change it. diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index c5e2499..4483533 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,7 +16,6 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" -#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -30,6 +29,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg-&g
Re: [Qemu-devel] [PATCH v7 0/6] fsdev: qmp interface for io throttling
On 7/7/2017 8:14 AM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 4 ++ blockdev.c | 97 ++--- fsdev/qemu-fsdev-dummy.c| 10 fsdev/qemu-fsdev-throttle.c | 118 ++-- fsdev/qemu-fsdev-throttle.h | 13 + fsdev/qemu-fsdev.c | 37 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 81 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 +- qapi/fsdev.json | 84 qapi/iothrottle.json| 88 ++ qmp.c | 14 + util/throttle.c | 110 + 20 files changed, 577 insertions(+), 216 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json No test coverage? I wanted to upstream these first then I am planning to write the tests. -Pradeep
Re: [Qemu-devel] [PATCH v7 0/6] fsdev: qmp interface for io throttling
On 7/14/2017 4:26 PM, Manos Pitsidianakis wrote: On Fri, Jul 14, 2017 at 03:15:06PM +0200, Pradeep Jagadeesh wrote: Hi Manos, Thanks for sharing the link to your code patch. On 7/14/2017 2:22 PM, Manos Pitsidianakis wrote: Hello Pradeep, you might be interested in my work on refactoring the block layer's throttling interface in my series: https://lists.nongnu.org/archive/html/qemu-devel/2017-07/msg04191.html Sure will have a look. In this series you copy the existing legacy interface we want to get rid of. I think it will be easier work for you to use the changes introduced in my patches when they are merged. So, should I wait till they are in?. Actually my throttle patches for fsdev are already upstream (2.9). Now I am just introducing the qmp/hmp interfaces for the same. If you plan on using ThrottleGroups, probably yes, I think, because we'd have duplicate interfaces afterwards instead of a unified one. You'd have to introduce a qmp/hmp command to set fsdev throttle now and after you use throttle groups it will become obsolete. I am not using ThrottleGroups in near future. -Pradeep Have you thought about using throttle groups? It'd mean many devices sharing the same limits. This way the interfaces can be unified. Please read docs/throttle.txt and see if it would be useful for you. I have read about the throttle group, last year when I was implementing the throttle feature for fsdev.My open source work depends on the projects I/my group work on. So, when I have more bandwidth work on those, I will surely take it up. Throttle group option may be useful feature even in case of fsdev devices. Regards, Pradeep
Re: [Qemu-devel] [PATCH v7 0/6] fsdev: qmp interface for io throttling
Hi Manos, Thanks for sharing the link to your code patch. On 7/14/2017 2:22 PM, Manos Pitsidianakis wrote: Hello Pradeep, you might be interested in my work on refactoring the block layer's throttling interface in my series: https://lists.nongnu.org/archive/html/qemu-devel/2017-07/msg04191.html Sure will have a look. In this series you copy the existing legacy interface we want to get rid of. I think it will be easier work for you to use the changes introduced in my patches when they are merged. So, should I wait till they are in?. Actually my throttle patches for fsdev are already upstream (2.9). Now I am just introducing the qmp/hmp interfaces for the same. Have you thought about using throttle groups? It'd mean many devices sharing the same limits. This way the interfaces can be unified. Please read docs/throttle.txt and see if it would be useful for you. I have read about the throttle group, last year when I was implementing the throttle feature for fsdev.My open source work depends on the projects I/my group work on. So, when I have more bandwidth work on those, I will surely take it up. Throttle group option may be useful feature even in case of fsdev devices. Regards, Pradeep
Re: [Qemu-devel] [PATCH v7 6/6] fsdev: QMP interface for throttling
On 7/6/2017 8:47 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: 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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 10 ++ fsdev/qemu-fsdev-throttle.c | 76 +++- fsdev/qemu-fsdev-throttle.h | 13 +++ fsdev/qemu-fsdev.c | 37 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 16a0430..4fd7625 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS Uh, qapi-schema.json includes fsdev.json *unconditionally*, doesn't it? Yes, that is right. I did not find a way to include fsdev.json conditionally. If I can do that, mostly can avoid many dump functions that are added in qmp.c,monitor.c and qemu-fsdev-dummy.c +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..f33305d 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -19,3 +19,13 @@ int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; Indentation is off. I will fix. +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +abort(); +} Any particular reason why one of the stubs abort()s, but not the other? Just to avoid proceeding further. diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index c5e2499..4483533 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,7 +16,6 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" -#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -30,6 +29,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps
Re: [Qemu-devel] [PATCH v7 0/6] fsdev: qmp interface for io throttling
On 7/7/2017 8:14 AM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 4 ++ blockdev.c | 97 ++--- fsdev/qemu-fsdev-dummy.c| 10 fsdev/qemu-fsdev-throttle.c | 118 ++-- fsdev/qemu-fsdev-throttle.h | 13 + fsdev/qemu-fsdev.c | 37 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 81 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 +- qapi/fsdev.json | 84 qapi/iothrottle.json| 88 ++ qmp.c | 14 + util/throttle.c | 110 + 20 files changed, 577 insertions(+), 216 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json No test coverage? Not yet, I am yet to write the tests. I can do it only after I finish this work. -Pradeep
[Qemu-devel] [PATCH v7 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 4 ++ blockdev.c | 97 ++--- fsdev/qemu-fsdev-dummy.c| 10 fsdev/qemu-fsdev-throttle.c | 118 ++-- fsdev/qemu-fsdev-throttle.h | 13 + fsdev/qemu-fsdev.c | 37 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 81 +-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 +- qapi/fsdev.json | 84 qapi/iothrottle.json| 88 ++ qmp.c | 14 + util/throttle.c | 110 + 20 files changed, 577 insertions(+), 216 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c v6 -> v7: Addressed comments from Albert Garcia and Dr. David Alan Gilbert Fixed the hmp-commands-info.hx and hmp-commands.hx as per Dr. David's comments. Fixed the bug with the hmp fsdev_set_io_throttle and info fsdev_iothrottle -- 1.8.3.1
[Qemu-devel] [PATCH v7 6/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 10 ++ fsdev/qemu-fsdev-throttle.c | 76 +++- fsdev/qemu-fsdev-throttle.h | 13 +++ fsdev/qemu-fsdev.c | 37 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 16a0430..4fd7625 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..f33305d 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -19,3 +19,13 @@ int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +abort(); +} diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index c5e2499..4483533 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,7 +16,6 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" -#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -30,6 +29,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg->has_iops_max_length= fscfg->has_iops_max; +fscfg->iops_max_length= + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; +fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; +fscfg->iops_rd_max_length = + cfg.buckets[THROTTLE_OPS_READ].burst_length; +fscfg->has_iops_wr_max_length = fscfg->has_iops_wr_max; +fscfg->iops_wr_max_length = +
[Qemu-devel] [PATCH v7 2/6] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- qapi/block-core.json | 76 ++--- qapi/iothrottle.json | 88 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 qapi/iothrottle.json diff --git a/qapi/block-core.json b/qapi/block-core.json index f85c223..9320974 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -6,6 +6,7 @@ # QAPI common definitions { 'include': 'common.json' } +{ 'include': 'iothrottle.json' } ## # @SnapshotInfo: @@ -1761,84 +1762,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: diff --git a/qapi/iothrottle.json b/qapi/iothrottle.json new file mode 100644 index 000..0f067c3 --- /dev/null +++ b/qapi/iothrottle.json @@ -0,0 +1,88 @@ +# -*- Mode: Python -*- + +## +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: +# +# A set of parameters describing IO throttling +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: write throughput limit in bytes per second +# +# @iops:
[Qemu-devel] [PATCH v7 5/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 +++ hmp-commands.hx | 19 hmp.c| 62 hmp.h| 4 4 files changed, 103 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae16901..5e4ea51 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev iothrottle information", +.cmd= hmp_info_fsdev_iothrottle, +}, + +#endif + +STEXI +@item info fsdev_iothrottle +@findex fsdev_iothrottle +Show fsdev device throttle info. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index e763606..b7eb9a6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1662,6 +1662,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev_set_io_throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 3f76073..97014d4 100644 --- a/hmp.c +++ b/hmp.c @@ -1774,6 +1774,68 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle = { +.has_id = true, +.id = (char *) qdict_get_str(qdict, "device"), +}; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" + " bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + "\n", + fscfg->bps, + fscfg->bps_rd, + fscfg->bps_wr, + fscfg->bps_max, + fscfg->bps_rd_max, + fscfg->bps_wr_max, + fscfg->iops, + fscfg->iops_rd, + fscfg->iops_wr, + fscfg->iops_max, + fscfg->iops_rd_max, + fscfg->iops_wr_max, + fscfg->iops_size); + hmp_handle_error(mon, ); +} + +void hmp_info_fsdev_iothrottle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fsdev_list, *info; +fsdev_list = qmp_query_fsdev_io_throttle(); + +for (info = fsdev_list; info; info = info->next) { +print_fsdev_throttle_config(mon, info->value, err); +} +qapi_free_IOThrottleList(fsdev_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index d8b94ce..dbf024d 100644 --- a/hmp.h +++ b/hmp.h @@ -81,6 +81,10 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict);
[Qemu-devel] [PATCH v7 1/6] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 44 +-- fsdev/qemu-fsdev-throttle.c | 44 ++- include/qemu/throttle-options.h | 4 include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 + 6 files changed, 61 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index f92dcf2..a95ea41 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..c5e2499 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-
[Qemu-devel] [PATCH v7 4/6] hmp: create a throttle initialization function for code reusability
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Acked-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp.c | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index 8c72c58..3f76073 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,27 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v7 3/6] throttle: move out function to reuse the code
This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 59 + 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index a95ea41..8090798 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2579,6 +2579,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2596,56 +2597,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index f63d38c..a9deb8e 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "typedefs.h" +#include "qapi-types.h" #define THROTTLE_OPTS \ { \ @@ -93,4 +94,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index a751126..2cf9ec5 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -565,3 +565,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ +throttle_config_init(cfg); +cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; +cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; +cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + +cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; +cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; +cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + +if (arg->has_bps_max) { +cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; +} +if (arg->has_bps_rd_max) { +cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; +} +if (arg->has_bps_wr_max) { +cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; +} +if (arg->has_iops_max) { +cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; +} +if (arg->has_iops_rd_max) { +cfg->buckets[THROTTLE_OPS_READ].max = arg-
Re: [Qemu-devel] [PATCH v6 5/6] fsdev: hmp interface for throttling
On 6/30/2017 11:33 AM, Dr. David Alan Gilbert wrote: * Pradeep Jagadeesh (pradeepkiruv...@gmail.com) wrote: This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 ++ hmp-commands.hx | 19 +++ hmp.c| 66 hmp.h| 4 4 files changed, 107 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae16901..f23b627 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "query-fsdev-iothrottle", This will end up as: info query-fsdev-iothrottle OK, I fix it as "fsdev_iothrottle" so the query- is unneeded since it's already info. +.args_type = "", +.params = "", +.help = "show fsdev device throttle information", +.cmd= hmp_fsdev_get_io_throttle, +}, + +#endif + +STEXI +@item info fsdev throttle I think that's supposed to match the .name - i.e. @item info query-fsdev-iothrottle (or whatever it will become) OK +@findex fsdevthrottleinfo again I think that's supposed to match the .name - see the other entries in that file. OK +Show fsdev device throttleinfo. And we may as well make that text match the .help text. OK +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index e763606..c60fd7e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1662,6 +1662,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev-set-io-throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle Again I think the @item and @findex have to match the .name - so I think make the .name use _'s rather than -'s for HMP. OK +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 220d301..b1c698b 100644 --- a/hmp.c +++ b/hmp.c @@ -1776,6 +1776,72 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +if (fscfg->bps || fscfg->bps_rd || fscfg->bps_wr || +fscfg->iops || fscfg->iops_rd || fscfg->iops_wr) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" +" bps=%" PRId64 +" bps_rd=%" PRId64 " bps_wr=%" PRId64 +" bps_max=%" PRId64 +" bps_rd_max=%" PRId64 +" bps_wr_max=%" PRId64 +" iops=%" PRId64 " iops_rd=%" PRId64 +" iops_wr=%" PRId64 +" iops_max=%" PRId64 +" iops_rd_max=%" PRId64 +" iops_wr_max=%" PRId64 +" iops_size=%" PRId64, +fscfg->bps, +fscfg->bps_rd, +fscfg->bps_wr, +fscfg->bps_max, +fscfg->bps_rd_max, +fscfg->bps_wr_max, +fscfg->iops, +fscfg->iops_rd, +fscfg->iops_wr, +fscfg->iops_max, +fscfg->iops_rd_max, +fscfg->iops_wr_max, +fscfg->iops_s
[Qemu-devel] [PATCH 3/6] throttle: move out function to reuse the code
This patch move out the throttle code to util/throttle.c to maximize the reusability of the code.The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- include/qemu/throttle-options.h | 4 +++ util/throttle.c | 59 + 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/blockdev.c b/blockdev.c index a95ea41..8090798 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2579,6 +2579,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2596,56 +2597,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index 659a410..ac4f221 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -10,6 +10,8 @@ #ifndef THROTTLE_OPTIONS_H #define THROTTLE_OPTIONS_H +#include "qmp-commands.h" + #define THROTTLE_OPTS \ { \ .name = "throttling.iops-total",\ @@ -91,4 +93,6 @@ void throttle_parse_options(ThrottleConfig *, QemuOpts *); +void throttle_set_io_limits(ThrottleConfig *, IOThrottle *); + #endif diff --git a/util/throttle.c b/util/throttle.c index a751126..2cf9ec5 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -565,3 +565,62 @@ void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) throttle_cfg->op_size = qemu_opt_get_number(opts, "throttling.iops-size", 0); } + +/* set the throttle limits + * + * @arg: iothrottle limits + * @cfg: throttle configuration + */ +void throttle_set_io_limits(ThrottleConfig *cfg, IOThrottle *arg) +{ +throttle_config_init(cfg); +cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; +cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; +cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; + +cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; +cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; +cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; + +if (arg->has_bps_max) { +cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; +} +if (arg->has_bps_rd_max) { +cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; +} +if (arg->has_bps_wr_max) { +cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; +} +if (arg->has_iops_max) { +cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; +} +if (arg->has_iops_
[Qemu-devel] [PATCH v6 5/6] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 ++ hmp-commands.hx | 19 +++ hmp.c| 66 hmp.h| 4 4 files changed, 107 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae16901..f23b627 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "query-fsdev-iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev device throttle information", +.cmd= hmp_fsdev_get_io_throttle, +}, + +#endif + +STEXI +@item info fsdev throttle +@findex fsdevthrottleinfo +Show fsdev device throttleinfo. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index e763606..c60fd7e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1662,6 +1662,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev-set-io-throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 220d301..b1c698b 100644 --- a/hmp.c +++ b/hmp.c @@ -1776,6 +1776,72 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +if (fscfg->bps || fscfg->bps_rd || fscfg->bps_wr || +fscfg->iops || fscfg->iops_rd || fscfg->iops_wr) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" +" bps=%" PRId64 +" bps_rd=%" PRId64 " bps_wr=%" PRId64 +" bps_max=%" PRId64 +" bps_rd_max=%" PRId64 +" bps_wr_max=%" PRId64 +" iops=%" PRId64 " iops_rd=%" PRId64 +" iops_wr=%" PRId64 +" iops_max=%" PRId64 +" iops_rd_max=%" PRId64 +" iops_wr_max=%" PRId64 +" iops_size=%" PRId64, +fscfg->bps, +fscfg->bps_rd, +fscfg->bps_wr, +fscfg->bps_max, +fscfg->bps_rd_max, +fscfg->bps_wr_max, +fscfg->iops, +fscfg->iops_rd, +fscfg->iops_wr, +fscfg->iops_max, +fscfg->iops_rd_max, +fscfg->iops_wr_max, +fscfg->iops_size); + } + hmp_handle_error(mon, ); +} + +void hmp_fsdev_get_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fs9p_list, *info; +fs9p_list = qmp_query_fsdev_io_throttle(); + +for (info = fs9p_list; info; info = info->next) { +if (info != fs9p_list) { +monitor_printf(mon, "\n"); +} +print_fsdev_throttle_config(mon, info->value, err); +qapi_free_IOThrottle(info->value); +} +qapi_free_IOThrottleList(fs9p_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h b/hmp.h index d8b94c
[Qemu-devel] [PATCH v6 6/6] fsdev: QMP interface for throttling
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 <pradeep.jagade...@huawei.com> --- Makefile| 4 +++ fsdev/qemu-fsdev-dummy.c| 10 ++ fsdev/qemu-fsdev-throttle.c | 76 +++- fsdev/qemu-fsdev-throttle.h | 13 +++ fsdev/qemu-fsdev.c | 37 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 14 9 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index 16a0430..4fd7625 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,10 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif + qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ diff --git a/fsdev/qemu-fsdev-dummy.c b/fsdev/qemu-fsdev-dummy.c index 6dc0fbc..f33305d 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -19,3 +19,13 @@ int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +abort(); +} diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index c5e2499..4483533 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -16,7 +16,6 @@ #include "qemu/error-report.h" #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" -#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -30,6 +29,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg->has_iops_max_length= fscfg->has_iops_max; +fscfg->iops_max_length= + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; +fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; +fscfg->iops_rd_max_length = + cfg.buckets[THROTTLE_OPS_READ].burst_length; +fscfg->has_iops_wr_max_length = fscfg->has_iops_wr_max; +fscfg->iops_wr_max_length = +
[Qemu-devel] [PATCH v6 0/6] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (6): throttle: factor out duplicate code qmp: Create IOThrottle structure throttle: move out function to reuse the code hmp: create a throttle initialization function for code reusability fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 4 ++ blockdev.c | 97 ++--- fsdev/qemu-fsdev-dummy.c| 10 fsdev/qemu-fsdev-throttle.c | 118 ++-- fsdev/qemu-fsdev-throttle.h | 13 + fsdev/qemu-fsdev.c | 37 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 87 +++-- hmp.h | 4 ++ include/qemu/throttle-options.h | 6 ++ include/qemu/throttle.h | 4 +- include/qemu/typedefs.h | 1 + monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 +- qapi/fsdev.json | 84 qapi/iothrottle.json| 88 ++ qmp.c | 14 + util/throttle.c | 110 + 20 files changed, 582 insertions(+), 216 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file v5 -> v6: Addressed comments from Greg Kurz and Markus Armbruster Split the commits to specific to hmp and throttle as suggested by Greg Moved ThrottleConfig typedef to qemu/typedefs.h Addressed compilation issue on FreeBSD by adding flags in qmp.c -- 1.8.3.1
[Qemu-devel] [PATCH v6 1/6] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> Reviewed-by: Alberto Garcia <be...@igalia.com> --- blockdev.c | 44 +-- fsdev/qemu-fsdev-throttle.c | 44 ++- include/qemu/throttle-options.h | 2 ++ include/qemu/throttle.h | 4 ++-- include/qemu/typedefs.h | 1 + util/throttle.c | 51 + 6 files changed, 59 insertions(+), 87 deletions(-) diff --git a/blockdev.c b/blockdev.c index f92dcf2..a95ea41 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,49 +387,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..c5e2499 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/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -31,48 +32,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-
[Qemu-devel] [PATCH v6 4/6] hmp: create a throttle initialization function
This patch creates a throttle initialization function to maximize the code reusability. The same code is also used by fsdev. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp.c | 21 +++-- 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index 8c72c58..220d301 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,29 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->has_id = true; +iot->id = (char *) qdict_get_str(qdict, "id"); +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } -- 1.8.3.1
[Qemu-devel] [PATCH v6 2/6] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- qapi/block-core.json | 76 ++--- qapi/iothrottle.json | 88 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 qapi/iothrottle.json diff --git a/qapi/block-core.json b/qapi/block-core.json index f85c223..9320974 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -6,6 +6,7 @@ # QAPI common definitions { 'include': 'common.json' } +{ 'include': 'iothrottle.json' } ## # @SnapshotInfo: @@ -1761,84 +1762,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: diff --git a/qapi/iothrottle.json b/qapi/iothrottle.json new file mode 100644 index 000..0f067c3 --- /dev/null +++ b/qapi/iothrottle.json @@ -0,0 +1,88 @@ +# -*- Mode: Python -*- + +## +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: +# +# A set of parameters describing IO throttling +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: write throughput limit in bytes per second +# +# @iops: total I/O operations per second +# +# @iops_rd: read
Re: [Qemu-devel] [PATCH v5 3/5] qmp: refactor duplicate code
On 6/21/2017 12:00 PM, Greg Kurz wrote: On Wed, 21 Jun 2017 10:34:42 +0200 Pradeep Jagadeesh <pradeep.jagade...@huawei.com> wrote: On 6/20/2017 6:05 PM, Greg Kurz wrote: On Mon, 19 Jun 2017 09:11:34 -0400 Pradeep Jagadeesh <pradeepkiruv...@gmail.com> wrote: This patch factor out the duplicate qmp throttle interface code that was present in both block and fsdev device files. The text is obviously wrong. I don't see any duplicate code below. OK, I will fix this. It is more something like: let's factor out the code that will be used by the existing QMP throttling API for block devices and the future QMP throttling API for fs devices. Please move the HMP part to another patch, as asked during v4 review. I have moved the hmp patches for the fsdev into a separate patch. Do you want me to push this also into a separate patch? Yes. These changes aren't related and theoretically belong to separate sub-maintainer trees. OK, I will split the commit and make separate patches. -Pradeep Also, blockdev.c and hmp.c do have maintainers. You should Cc: them each time because they know better than me and even if these patches are carried through my tree, I won't do it without an ack from them. OK, I will add them next time on. -Pradeep Cc'ing Markus for blockdev.c and David for hmp.c. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- hmp.c | 21 ++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 60 + 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5db9e5c..3d06e9e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2593,6 +2593,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2610,56 +2611,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/hmp.c b/hmp.c index 8c72c58..220d301 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,29 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->has_id = true; +iot->id = (char *) qdict_get_str(qdict, "id"); +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +
Re: [Qemu-devel] [PATCH v5 1/5] throttle: factor out duplicate code
On 6/22/2017 4:38 PM, Markus Armbruster wrote: Pradeep Jagadeesh <pradeepkiruv...@gmail.com> writes: This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 44 +--- fsdev/qemu-fsdev-throttle.c | 43 +-- fsdev/qemu-fsdev-throttle.h | 1 + include/qemu/throttle-options.h | 4 util/throttle.c | 50 + 5 files changed, 57 insertions(+), 85 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6472548..5db9e5c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -386,49 +386,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..da9c225 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -31,48 +31,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -fst->cfg.buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -fst->cfg.buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts,
Re: [Qemu-devel] [PATCH v5 3/5] qmp: refactor duplicate code
On 6/20/2017 6:05 PM, Greg Kurz wrote: On Mon, 19 Jun 2017 09:11:34 -0400 Pradeep Jagadeesh <pradeepkiruv...@gmail.com> wrote: This patch factor out the duplicate qmp throttle interface code that was present in both block and fsdev device files. The text is obviously wrong. I don't see any duplicate code below. OK, I will fix this. It is more something like: let's factor out the code that will be used by the existing QMP throttling API for block devices and the future QMP throttling API for fs devices. Please move the HMP part to another patch, as asked during v4 review. I have moved the hmp patches for the fsdev into a separate patch. Do you want me to push this also into a separate patch? Also, blockdev.c and hmp.c do have maintainers. You should Cc: them each time because they know better than me and even if these patches are carried through my tree, I won't do it without an ack from them. OK, I will add them next time on. -Pradeep Cc'ing Markus for blockdev.c and David for hmp.c. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- hmp.c | 21 ++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 60 + 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5db9e5c..3d06e9e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2593,6 +2593,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2610,56 +2611,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/hmp.c b/hmp.c index 8c72c58..220d301 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,29 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->has_id = true; +iot->id = (char *) qdict_get_str(qdict, "id"); +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "de
[Qemu-devel] [PATCH v5 3/5] qmp: refactor duplicate code
This patch factor out the duplicate qmp throttle interface code that was present in both block and fsdev device files. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 53 +++- hmp.c | 21 ++- include/qemu/throttle-options.h | 3 +++ util/throttle.c | 60 + 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5db9e5c..3d06e9e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2593,6 +2593,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; +IOThrottle *iothrottle; blk = qmp_get_blk(arg->has_device ? arg->device : NULL, arg->has_id ? arg->id : NULL, @@ -2610,56 +2611,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) goto out; } -throttle_config_init(); -cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps; -cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd; -cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr; - -cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops; -cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd; -cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr; - -if (arg->has_bps_max) { -cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max; -} -if (arg->has_bps_rd_max) { -cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max; -} -if (arg->has_bps_wr_max) { -cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max; -} -if (arg->has_iops_max) { -cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max; -} -if (arg->has_iops_rd_max) { -cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max; -} -if (arg->has_iops_wr_max) { -cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max; -} - -if (arg->has_bps_max_length) { -cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length; -} -if (arg->has_bps_rd_max_length) { -cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length; -} -if (arg->has_bps_wr_max_length) { -cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length; -} -if (arg->has_iops_max_length) { -cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length; -} -if (arg->has_iops_rd_max_length) { -cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length; -} -if (arg->has_iops_wr_max_length) { -cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length; -} - -if (arg->has_iops_size) { -cfg.op_size = arg->iops_size; -} +iothrottle = qapi_BlockIOThrottle_base(arg); +throttle_set_io_limits(, iothrottle); if (!throttle_is_valid(, errp)) { goto out; diff --git a/hmp.c b/hmp.c index 8c72c58..220d301 100644 --- a/hmp.c +++ b/hmp.c @@ -1749,20 +1749,29 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict) +{ +iot->has_id = true; +iot->id = (char *) qdict_get_str(qdict, "id"); +iot->bps = qdict_get_int(qdict, "bps"); +iot->bps_rd = qdict_get_int(qdict, "bps_rd"); +iot->bps_wr = qdict_get_int(qdict, "bps_wr"); +iot->iops = qdict_get_int(qdict, "iops"); +iot->iops_rd = qdict_get_int(qdict, "iops_rd"); +iot->iops_wr = qdict_get_int(qdict, "iops_wr"); +} + void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) { Error *err = NULL; +IOThrottle *iothrottle; BlockIOThrottle throttle = { .has_device = true, .device = (char *) qdict_get_str(qdict, "device"), -.bps = qdict_get_int(qdict, "bps"), -.bps_rd = qdict_get_int(qdict, "bps_rd"), -.bps_wr = qdict_get_int(qdict, "bps_wr"), -.iops = qdict_get_int(qdict, "iops"), -.iops_rd = qdict_get_int(qdict, "iops_rd"), -.iops_wr = qdict_get_int(qdict, "iops_wr"), }; +iothrottle = qapi_BlockIOThrottle_base(); +hmp_initialize_io_throttle(iothrottle, qdict); qmp_block_set_io_throttle(, ); hmp_handle_error(mon, ); } diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index 565553a..e94ea39 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -11,6 +11,7 @@ #define THROTTLE_OPTIONS_H #include "qemu/throttle.h" +#include "qmp-commands.h" #define THROTTLE_OPTS \ { \ @@ -
[Qemu-devel] [PATCH v5 4/5] fsdev: hmp interface for throttling
This patch introduces hmp interfaces for the fsdev throttle functionality Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- hmp-commands-info.hx | 18 ++ hmp-commands.hx | 19 +++ hmp.c| 66 hmp.h| 4 4 files changed, 107 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae16901..f23b627 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -84,6 +84,24 @@ STEXI Show block device statistics. ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "query-fsdev-iothrottle", +.args_type = "", +.params = "", +.help = "show fsdev device throttle information", +.cmd= hmp_fsdev_get_io_throttle, +}, + +#endif + +STEXI +@item info fsdev throttle +@findex fsdevthrottleinfo +Show fsdev device throttleinfo. +ETEXI + { .name = "block-jobs", .args_type = "", diff --git a/hmp-commands.hx b/hmp-commands.hx index e763606..c60fd7e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1662,6 +1662,25 @@ STEXI Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} ETEXI +#if defined(CONFIG_VIRTFS) + +{ +.name = "fsdev-set-io-throttle", +.args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", +.params = "device bps bps_rd bps_wr iops iops_rd iops_wr", +.help = "change I/O throttle limits for a fs devices", +.cmd= hmp_fsdev_set_io_throttle, +}, + +#endif + +STEXI +@item fsdev_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex fsdev_set_io_throttle +Change I/O throttle limits for a fs devices to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", diff --git a/hmp.c b/hmp.c index 220d301..b1c698b 100644 --- a/hmp.c +++ b/hmp.c @@ -1776,6 +1776,72 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); } +#ifdef CONFIG_VIRTFS + +void hmp_fsdev_set_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottle throttle; + +hmp_initialize_io_throttle(, qdict); +qmp_fsdev_set_io_throttle(, ); +hmp_handle_error(mon, ); +} + +static void print_fsdev_throttle_config(Monitor *mon, IOThrottle *fscfg, + Error *err) +{ +if (fscfg->bps || fscfg->bps_rd || fscfg->bps_wr || +fscfg->iops || fscfg->iops_rd || fscfg->iops_wr) +{ +monitor_printf(mon, "%s", fscfg->id); +monitor_printf(mon, "I/O throttling:" +" bps=%" PRId64 +" bps_rd=%" PRId64 " bps_wr=%" PRId64 +" bps_max=%" PRId64 +" bps_rd_max=%" PRId64 +" bps_wr_max=%" PRId64 +" iops=%" PRId64 " iops_rd=%" PRId64 +" iops_wr=%" PRId64 +" iops_max=%" PRId64 +" iops_rd_max=%" PRId64 +" iops_wr_max=%" PRId64 +" iops_size=%" PRId64, +fscfg->bps, +fscfg->bps_rd, +fscfg->bps_wr, +fscfg->bps_max, +fscfg->bps_rd_max, +fscfg->bps_wr_max, +fscfg->iops, +fscfg->iops_rd, +fscfg->iops_wr, +fscfg->iops_max, +fscfg->iops_rd_max, +fscfg->iops_wr_max, +fscfg->iops_size); + } + hmp_handle_error(mon, ); +} + +void hmp_fsdev_get_io_throttle(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +IOThrottleList *fs9p_list, *info; +fs9p_list = qmp_query_fsdev_io_throttle(); + +for (info = fs9p_list; info; info = info->next) { +if (info != fs9p_list) { +monitor_printf(mon, "\n"); +} +print_fsdev_throttle_config(mon, info->value, err); +qapi_free_IOThrottle(info->value); +} +qapi_free_IOThrottleList(fs9p_list); +} + +#endif + void hmp_block_stream(Monitor *mon, const QDict *qdict) { Error *error = NULL; diff --git a/hmp.h
[Qemu-devel] [PATCH v5 5/5] fsdev: QMP interface for throttling
This patch enables 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 <pradeep.jagade...@huawei.com> --- Makefile| 3 ++ fsdev/qemu-fsdev-dummy.c| 10 ++ fsdev/qemu-fsdev-throttle.c | 75 fsdev/qemu-fsdev-throttle.h | 12 +++ fsdev/qemu-fsdev.c | 37 monitor.c | 5 +++ qapi-schema.json| 3 ++ qapi/fsdev.json | 84 + qmp.c | 15 9 files changed, 244 insertions(+) create mode 100644 qapi/fsdev.json diff --git a/Makefile b/Makefile index c830d7a..996b1cf 100644 --- a/Makefile +++ b/Makefile @@ -414,6 +414,9 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \ $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/trace.json +ifdef CONFIG_VIRTFS +qapi-modules += $(SRC_PATH)/qapi/fsdev.json +endif 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..f33305d 100644 --- a/fsdev/qemu-fsdev-dummy.c +++ b/fsdev/qemu-fsdev-dummy.c @@ -19,3 +19,13 @@ int qemu_fsdev_add(QemuOpts *opts) { return 0; } + +void qmp_fsdev_set_io_throttle(IOThrottle *arg, Error **errp) +{ + return; +} + +IOThrottleList *qmp_query_fsdev_io_throttle(Error **errp) +{ +abort(); +} diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index da9c225..4483533 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -29,6 +29,81 @@ static void fsdev_throttle_write_timer_cb(void *opaque) qemu_co_enter_next(>throttled_reqs[true]); } +void fsdev_set_io_throttle(IOThrottle *arg, FsThrottle *fst, Error **errp) +{ +ThrottleConfig cfg; + +throttle_set_io_limits(, arg); + +if (throttle_is_valid(, errp)) { +fst->cfg = cfg; +fsdev_throttle_init(fst); +} +} + +void fsdev_get_io_throttle(FsThrottle *fst, IOThrottle **fs9pcfg, + char *fsdevice, Error **errp) +{ + +ThrottleConfig cfg = fst->cfg; +IOThrottle *fscfg = g_malloc0(sizeof(*fscfg)); + +fscfg->has_id = true; +fscfg->id = g_strdup(fsdevice); +fscfg->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; +fscfg->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; +fscfg->bps_wr = cfg.buckets[THROTTLE_BPS_WRITE].avg; + +fscfg->iops = cfg.buckets[THROTTLE_OPS_TOTAL].avg; +fscfg->iops_rd = cfg.buckets[THROTTLE_OPS_READ].avg; +fscfg->iops_wr = cfg.buckets[THROTTLE_OPS_WRITE].avg; + +fscfg->has_bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->bps_max = cfg.buckets[THROTTLE_BPS_TOTAL].max; +fscfg->has_bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->bps_rd_max = cfg.buckets[THROTTLE_BPS_READ].max; +fscfg->has_bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; +fscfg->bps_wr_max = cfg.buckets[THROTTLE_BPS_WRITE].max; + +fscfg->has_iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->iops_max= cfg.buckets[THROTTLE_OPS_TOTAL].max; +fscfg->has_iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->iops_rd_max = cfg.buckets[THROTTLE_OPS_READ].max; +fscfg->has_iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; +fscfg->iops_wr_max = cfg.buckets[THROTTLE_OPS_WRITE].max; + +fscfg->has_bps_max_length = fscfg->has_bps_max; +fscfg->bps_max_length = + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->has_bps_rd_max_length = fscfg->has_bps_rd_max; +fscfg->bps_rd_max_length = + cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->has_bps_wr_max_length = fscfg->has_bps_wr_max; +fscfg->bps_wr_max_length = + cfg.buckets[THROTTLE_BPS_WRITE].burst_length; + +fscfg->has_iops_max_length= fscfg->has_iops_max; +fscfg->iops_max_length= + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length; +fscfg->has_iops_rd_max_length = fscfg->has_iops_rd_max; +fscfg->iops_rd_max_length = + cfg.buckets[THROTTLE_OPS_READ].burst_length; +fscfg->has_iops_wr_max_length = fscfg->has_iops_wr_max; +fscfg->iops_wr_max_length = + cfg.buckets[THROTTLE_OPS_WRITE].burst_length; + +fscfg->bps_max_length = cfg.buckets[THROTTLE_BPS_TOTAL].burst_length; +fscfg->bps_rd_max_length = cfg.buckets[THROTTLE_BPS_READ].burst_length; +fscfg->bps_wr_max_length = cfg.buckets[THROTTLE_BPS_WRI
[Qemu-devel] [PATCH v5 0/5] fsdev: qmp interface for io throttling
These patches provide the qmp interface, to query the io throttle status of the all fsdev devices that are present in a vm. also, it provides an interface to set the io throttle parameters of a fsdev to a required value. some of the patches also remove the duplicate code that was present in block and fsdev files. Pradeep Jagadeesh (5): throttle: factor out duplicate code qmp: Create IOThrottle structure qmp: refactor duplicate code fsdev: hmp interface for throttling fsdev: QMP interface for throttling Makefile| 3 + blockdev.c | 97 ++--- fsdev/qemu-fsdev-dummy.c| 10 fsdev/qemu-fsdev-throttle.c | 118 ++-- fsdev/qemu-fsdev-throttle.h | 13 + fsdev/qemu-fsdev.c | 37 + hmp-commands-info.hx| 18 ++ hmp-commands.hx | 19 +++ hmp.c | 87 +++-- hmp.h | 4 ++ include/qemu/throttle-options.h | 7 +++ monitor.c | 5 ++ qapi-schema.json| 3 + qapi/block-core.json| 76 +- qapi/fsdev.json | 84 qapi/iothrottle.json| 88 ++ qmp.c | 15 + util/throttle.c | 110 + 18 files changed, 580 insertions(+), 214 deletions(-) create mode 100644 qapi/fsdev.json create mode 100644 qapi/iothrottle.json v0 -> v1: Addressed comments from Eric Blake, Greg Kurz and Daniel P.Berrange Mainly renaming the functions and removing the redundant code. v1 -> v2: Addressed comments from Eric Blake and Greg Kurz. As per the suggestion I split the patches into smaller patches. Removed some more duplicate code. v2 -> v3: Addresssed comments from Alberto Garcia. Changed the comment from block to iothrottle in the iothrottle.json Added the dummy functions in qemu-fsdev-dummy.c to address the compilation issues that were observed. v3 -> v4: Addressed comments from Eric Blake and Greg Kurz Re-ordered the patches Added the dummy functions in qmp.c to address the cross compilation issues v4 -> v5: Addressed comments from Eric Blake and Greg Kurz Split the fsdev qmp patch into hmp and qmp related patches Moved the common functionalities to throttle.c instead of creating a new file -- 1.8.3.1
[Qemu-devel] [PATCH v5 2/5] qmp: Create IOThrottle structure
This patch enables 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 <pradeep.jagade...@huawei.com> Reviewed-by: Greg Kurz <gr...@kaod.org> Reviewed-by: Eric Blake <ebl...@redhat.com> --- qapi/block-core.json | 76 ++--- qapi/iothrottle.json | 88 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 qapi/iothrottle.json diff --git a/qapi/block-core.json b/qapi/block-core.json index f85c223..9320974 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -6,6 +6,7 @@ # QAPI common definitions { 'include': 'common.json' } +{ 'include': 'iothrottle.json' } ## # @SnapshotInfo: @@ -1761,84 +1762,13 @@ # # @device: Block device name (deprecated, use @id instead) # -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @bps: total throughput limit in bytes per second -# -# @bps_rd: read throughput limit in bytes per second -# -# @bps_wr: write throughput limit in bytes per second -# -# @iops: total I/O operations per second -# -# @iops_rd: read I/O operations per second -# -# @iops_wr: write I/O operations per second -# -# @bps_max: total throughput limit during bursts, -# in bytes (Since 1.7) -# -# @bps_rd_max: read throughput limit during bursts, -#in bytes (Since 1.7) -# -# @bps_wr_max: write throughput limit during bursts, -#in bytes (Since 1.7) -# -# @iops_max: total I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_rd_max: read I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @iops_wr_max: write I/O operations per second during bursts, -# in bytes (Since 1.7) -# -# @bps_max_length: maximum length of the @bps_max burst -#period, in seconds. It must only -#be set if @bps_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @bps_rd_max_length: maximum length of the @bps_rd_max -# burst period, in seconds. It must only -# be set if @bps_rd_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @bps_wr_max_length: maximum length of the @bps_wr_max -# burst period, in seconds. It must only -# be set if @bps_wr_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_max_length: maximum length of the @iops burst -# period, in seconds. It must only -# be set if @iops_max is set as well. -# Defaults to 1. (Since 2.6) -# -# @iops_rd_max_length: maximum length of the @iops_rd_max -#burst period, in seconds. It must only -#be set if @iops_rd_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_wr_max_length: maximum length of the @iops_wr_max -#burst period, in seconds. It must only -#be set if @iops_wr_max is set as well. -#Defaults to 1. (Since 2.6) -# -# @iops_size: an I/O size in bytes (Since 1.7) -# # @group: throttle group name (Since 2.4) # # Since: 1.1 ## { 'struct': 'BlockIOThrottle', - 'data': { '*device': 'str', '*id': 'str', 'bps': 'int', 'bps_rd': 'int', -'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int', -'*bps_max': 'int', '*bps_rd_max': 'int', -'*bps_wr_max': 'int', '*iops_max': 'int', -'*iops_rd_max': 'int', '*iops_wr_max': 'int', -'*bps_max_length': 'int', '*bps_rd_max_length': 'int', -'*bps_wr_max_length': 'int', '*iops_max_length': 'int', -'*iops_rd_max_length': 'int', '*iops_wr_max_length': 'int', -'*iops_size': 'int', '*group': 'str' } } + 'base': 'IOThrottle', + 'data': { '*device': 'str', '*group': 'str' } } ## # @block-stream: diff --git a/qapi/iothrottle.json b/qapi/iothrottle.json new file mode 100644 index 000..0f067c3 --- /dev/null +++ b/qapi/iothrottle.json @@ -0,0 +1,88 @@ +# -*- Mode: Python -*- + +## +# == QAPI IOThrottle definitions +## + +## +# @IOThrottle: +# +# A set of parameters describing IO throttling +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: write throughput limit in bytes per second +# +# @iops: total I/O operations per second +# +# @iops_rd: read
[Qemu-devel] [PATCH v5 1/5] throttle: factor out duplicate code
This patch factor out the duplicate throttle code that was present in block and fsdev devices. Signed-off-by: Pradeep Jagadeesh <pradeep.jagade...@huawei.com> --- blockdev.c | 44 +--- fsdev/qemu-fsdev-throttle.c | 43 +-- fsdev/qemu-fsdev-throttle.h | 1 + include/qemu/throttle-options.h | 4 util/throttle.c | 50 + 5 files changed, 57 insertions(+), 85 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6472548..5db9e5c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -386,49 +386,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { -throttle_config_init(throttle_cfg); -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_number(opts, "throttling.bps-read-max", 0); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.bps-write-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.iops-total-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_READ].max = -qemu_opt_get_number(opts, "throttling.iops-read-max", 0); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = -qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - -throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = -qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = -qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); -throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = -qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - -throttle_cfg->op_size = -qemu_opt_get_number(opts, "throttling.iops-size", 0); - +throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; } diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..da9c225 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -31,48 +31,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { -throttle_config_init(>cfg); -fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.bps-total", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].avg = -qemu_opt_get_number(opts, "throttling.bps-read", 0); -fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.bps-write", 0); -fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = -qemu_opt_get_number(opts, "throttling.iops-total", 0); -fst->cfg.buckets[THROTTLE_OPS_READ].avg = -qemu_opt_get_number(opts, "throttling.iops-read", 0); -fst->cfg.buckets[THROTTLE_OPS_WRITE].avg = -qemu_opt_get_number(opts, "throttling.iops-write", 0); - -fst->cfg.buckets[THROTTLE_BPS_TOTAL].max = -qemu_opt_get_number(opts, "throttling.bps-total-max", 0); -fst->cfg.buckets[THROTTLE_BPS_READ].max = -qemu_opt_get_
Re: [Qemu-devel] [PATCH v4 4/4] fsdev: QMP interface for throttling
On 6/9/2017 11:07 AM, Greg Kurz wrote: GEN qmp-commands.h /tmp/qemu-test/src/qapi-schema.json:85: No such file or directory: qapi/fsdev.json Makefile:438: recipe for target 'qmp-commands.h' failed Please fix that. Ho ok, I will have a look. How are you trying to compile, using "make docker" options? Thanks Pradeep