From ca051264aeaedfa50930c58c9885e5a959e42a10 Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Fri, 15 Jun 2018 17:10:58 +0200 Subject: [PATCH] vhost: dump interrupt coalescing parameters in RPC info/config Change-Id: I7fec9a5fe30bb64f6c76fc951a40e27cf86ecdee Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/415461 Tested-by: SPDK Automated Test System Reviewed-by: Karol Latecki Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- include/spdk/vhost.h | 12 ++++++++++++ lib/vhost/vhost.c | 35 ++++++++++++++++++++++++++++++++++- lib/vhost/vhost_internal.h | 6 ++++++ lib/vhost/vhost_rpc.c | 6 ++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 7af284d84..b74cc9bef 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -162,6 +162,18 @@ const struct spdk_cpuset *spdk_vhost_dev_get_cpumask(struct spdk_vhost_dev *vdev int spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, uint32_t iops_threshold); +/** + * Get coalescing parameters. + * + * \see spdk_vhost_set_coalescing + * + * \param vdev vhost device. + * \param delay_base_us Optional pointer to store base delay time. + * \param iops_threshold Optional pointer to store IOPS threshold. + */ +void spdk_vhost_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us, + uint32_t *iops_threshold); + /** * Construct an empty vhost SCSI device. This will create a * Unix domain socket together with a vhost-user slave server waiting diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 002799b91..3bb3de634 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -338,7 +338,7 @@ spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, uint32_t iops_threshold) { uint64_t delay_time_base = delay_base_us * spdk_get_ticks_hz() / 1000000ULL; - uint32_t io_rate = iops_threshold * SPDK_VHOST_DEV_STATS_CHECK_INTERVAL_MS / 1000; + uint32_t io_rate = iops_threshold * SPDK_VHOST_DEV_STATS_CHECK_INTERVAL_MS / 1000U; if (delay_time_base >= UINT32_MAX) { SPDK_ERRLOG("Delay time of %"PRIu32" is to big\n", delay_base_us); @@ -351,9 +351,25 @@ spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, vdev->coalescing_delay_time_base = delay_time_base; vdev->coalescing_io_rate_threshold = io_rate; + + vdev->coalescing_delay_us = delay_base_us; + vdev->coalescing_iops_threshold = iops_threshold; return 0; } +void +spdk_vhost_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us, + uint32_t *iops_threshold) +{ + if (delay_base_us) { + *delay_base_us = vdev->coalescing_delay_us; + } + + if (iops_threshold) { + *iops_threshold = vdev->coalescing_iops_threshold; + } +} + /* * Enqueue id and len to used ring. */ @@ -1386,6 +1402,8 @@ static int spdk_vhost_config_json_cb(struct spdk_vhost_dev *vdev, void *arg) { struct spdk_vhost_write_config_json_ctx *ctx = arg; + uint32_t delay_base_us; + uint32_t iops_threshold; if (vdev == NULL) { spdk_json_write_array_end(ctx->w); @@ -1395,6 +1413,21 @@ spdk_vhost_config_json_cb(struct spdk_vhost_dev *vdev, void *arg) } vdev->backend->write_config_json(vdev, ctx->w); + + spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold); + if (delay_base_us) { + spdk_json_write_object_begin(ctx->w); + spdk_json_write_named_string(ctx->w, "method", "set_vhost_controller_coalescing"); + + spdk_json_write_named_object_begin(ctx->w, "params"); + spdk_json_write_named_string(ctx->w, "ctrlr", vdev->name); + spdk_json_write_named_uint32(ctx->w, "delay_base_us", delay_base_us); + spdk_json_write_named_uint32(ctx->w, "iops_threshold", iops_threshold); + spdk_json_write_object_end(ctx->w); + + spdk_json_write_object_end(ctx->w); + } + return 0; } diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 33b8e7a7f..dfc0bf623 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -150,6 +150,12 @@ struct spdk_vhost_dev { const struct spdk_vhost_dev_backend *backend; + /* Saved orginal values used to setup coalescing to avoid integer + * rounding issues during save/load config. + */ + uint32_t coalescing_delay_us; + uint32_t coalescing_iops_threshold; + uint32_t coalescing_delay_time_base; /* Threshold when event coalescing for virtqueue will be turned on. */ diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index 14d410475..a07d32de5 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -459,6 +459,8 @@ static int spdk_rpc_get_vhost_controllers_cb(struct spdk_vhost_dev *vdev, void *arg) { struct rpc_get_vhost_ctrlrs *ctx = arg; + uint32_t delay_base_us, iops_threshold; + if (vdev == NULL) { spdk_json_write_array_end(ctx->w); @@ -467,10 +469,14 @@ spdk_rpc_get_vhost_controllers_cb(struct spdk_vhost_dev *vdev, void *arg) return 0; } + spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold); + spdk_json_write_object_begin(ctx->w); spdk_json_write_named_string(ctx->w, "ctrlr", spdk_vhost_dev_get_name(vdev)); spdk_json_write_named_string_fmt(ctx->w, "cpumask", "0x%s", spdk_cpuset_fmt(vdev->cpumask)); + spdk_json_write_named_uint32(ctx->w, "delay_base_us", delay_base_us); + spdk_json_write_named_uint32(ctx->w, "iops_threshold", iops_threshold); spdk_json_write_named_object_begin(ctx->w, "backend_specific"); spdk_vhost_dump_info_json(vdev, ctx->w);