From: Greg Kurz <groug@kaod.org>
To: Pradeep Jagadeesh <pradeepkiruvale@gmail.com>
Cc: eric blake <eblake@redhat.com>,
Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>,
alberto garcia <berto@igalia.com>,
Markus Armbruster <armbru@redhat.com>,
jani kokkonen <jani.kokkonen@huawei.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v10 1/6] throttle: factor out duplicate code
Date: Wed, 6 Sep 2017 11:49:59 +0200 [thread overview]
Message-ID: <20170906114959.2c385643@bahia> (raw)
In-Reply-To: <1504541267-36954-2-git-send-email-pradeep.jagadeesh@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 12314 bytes --]
With this patch applied, we get:
$ git log --no-decorate --oneline include/qemu/throttle-options.h
a54046b857be throttle: factor out duplicate code
a2a7862ca9ab throttle: factor out duplicate code
Maybe better to change the patch title to:
throttle: factor out more duplicate code
On Mon, 4 Sep 2017 12:07:42 -0400
Pradeep Jagadeesh <pradeepkiruvale@gmail.com> wrote:
> This patch factor out the duplicate throttle code that was present in
This patch factors out the duplicate throttle code that was still present in
> block and fsdev devices.
>
> Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>
> Reviewed-by: Alberto Garcia <berto@igalia.com>
With the above fixed.
Reviewed-by: Greg Kurz <groug@kaod.org>
> ---
> 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(&fst->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_number(opts, "throttling.bps-read-max", 0);
> - fst->cfg.buckets[THROTTLE_BPS_WRITE].max =
> - qemu_opt_get_number(opts, "throttling.bps-write-max", 0);
> - fst->cfg.buckets[THROTTLE_OPS_TOTAL].max =
> - qemu_opt_get_number(opts, "throttling.iops-total-max", 0);
> - fst->cfg.buckets[THROTTLE_OPS_READ].max =
> - qemu_opt_get_number(opts, "throttling.iops-read-max", 0);
> - fst->cfg.buckets[THROTTLE_OPS_WRITE].max =
> - qemu_opt_get_number(opts, "throttling.iops-write-max", 0);
> -
> - fst->cfg.buckets[THROTTLE_BPS_TOTAL].burst_length =
> - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1);
> - fst->cfg.buckets[THROTTLE_BPS_READ].burst_length =
> - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1);
> - fst->cfg.buckets[THROTTLE_BPS_WRITE].burst_length =
> - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1);
> - fst->cfg.buckets[THROTTLE_OPS_TOTAL].burst_length =
> - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1);
> - fst->cfg.buckets[THROTTLE_OPS_READ].burst_length =
> - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1);
> - fst->cfg.buckets[THROTTLE_OPS_WRITE].burst_length =
> - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1);
> - fst->cfg.op_size =
> - qemu_opt_get_number(opts, "throttling.iops-size", 0);
> -
> + throttle_parse_options(&fst->cfg, opts);
> throttle_is_valid(&fst->cfg, errp);
> }
>
> diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h
> index 3133d1c..f63d38c 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 "typedefs.h"
> +
> #define THROTTLE_OPTS \
> { \
> .name = "throttling.iops-total",\
> @@ -89,4 +91,6 @@
> .help = "when limiting by iops max size of an I/O in bytes",\
> }
>
> +void throttle_parse_options(ThrottleConfig *, QemuOpts *);
> +
> #endif
> diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
> index d056008..75d930c 100644
> --- a/include/qemu/throttle.h
> +++ b/include/qemu/throttle.h
> @@ -89,10 +89,10 @@ typedef struct LeakyBucket {
> * However it allows to keep the code clean and the bucket field is reset to
> * zero at the right time.
> */
> -typedef struct ThrottleConfig {
> +struct ThrottleConfig {
> LeakyBucket buckets[BUCKETS_COUNT]; /* leaky buckets */
> uint64_t op_size; /* size of an operation in bytes */
> -} ThrottleConfig;
> +};
>
> typedef struct ThrottleState {
> ThrottleConfig cfg; /* configuration */
> diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
> index 39bc835..90fe0f9 100644
> --- a/include/qemu/typedefs.h
> +++ b/include/qemu/typedefs.h
> @@ -100,6 +100,7 @@ typedef struct uWireSlave uWireSlave;
> typedef struct VirtIODevice VirtIODevice;
> typedef struct Visitor Visitor;
> typedef struct node_info NodeInfo;
> +typedef struct ThrottleConfig ThrottleConfig;
> typedef void SaveStateHandler(QEMUFile *f, void *opaque);
> typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
>
> diff --git a/util/throttle.c b/util/throttle.c
> index b2a52b8..95c2ecf 100644
> --- a/util/throttle.c
> +++ b/util/throttle.c
> @@ -27,6 +27,7 @@
> #include "qemu/throttle.h"
> #include "qemu/timer.h"
> #include "block/aio.h"
> +#include "qemu/throttle-options.h"
>
> /* This function make a bucket leak
> *
> @@ -502,3 +503,53 @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size)
> }
> }
>
> +/* parse the throttle options
> + *
> + * @opts: qemu options
> + * @throttle_cfg: throttle configuration
> + */
> +void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts)
> +{
> + 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);
> +}
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2017-09-06 9:50 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-04 16:07 [Qemu-devel] [PATCH v10 0/6] fsdev: qmp interface for io throttling Pradeep Jagadeesh
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 1/6] throttle: factor out duplicate code Pradeep Jagadeesh
2017-09-06 9:49 ` Greg Kurz [this message]
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 2/6] qmp: Create IOThrottle structure Pradeep Jagadeesh
2017-09-08 9:37 ` Markus Armbruster
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 3/6] throttle: move out function to reuse the code Pradeep Jagadeesh
2017-09-08 12:27 ` Greg Kurz
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 4/6] hmp: create a throttle initialization function for code reusability Pradeep Jagadeesh
2017-09-05 12:03 ` Alberto Garcia
2017-09-08 12:31 ` Greg Kurz
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 5/6] fsdev: QMP interface for throttling Pradeep Jagadeesh
2017-09-08 10:02 ` Markus Armbruster
2017-09-08 11:33 ` Alberto Garcia
2017-09-08 12:51 ` Markus Armbruster
2017-09-08 12:19 ` Pradeep Jagadeesh
2017-09-08 12:34 ` Markus Armbruster
2017-09-08 12:49 ` Pradeep Jagadeesh
2017-09-11 9:23 ` Pradeep Jagadeesh
2017-09-04 16:07 ` [Qemu-devel] [PATCH v10 6/6] fsdev: hmp " Pradeep Jagadeesh
2017-09-05 7:53 ` Alberto Garcia
2017-09-05 8:28 ` Pradeep Jagadeesh
2017-09-05 8:57 ` Greg Kurz
2017-09-05 9:07 ` Alberto Garcia
2017-09-05 9:13 ` Pradeep Jagadeesh
2017-09-05 9:34 ` Alberto Garcia
2017-09-05 9:36 ` Pradeep Jagadeesh
2017-09-05 17:57 ` Dr. David Alan Gilbert
2017-09-05 21:19 ` [Qemu-devel] [PATCH v10 0/6] fsdev: qmp interface for io throttling Eric Blake
2017-09-06 10:12 ` Pradeep Jagadeesh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170906114959.2c385643@bahia \
--to=groug@kaod.org \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=eblake@redhat.com \
--cc=jani.kokkonen@huawei.com \
--cc=pradeep.jagadeesh@huawei.com \
--cc=pradeepkiruvale@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.