From 27635c770f5ceb75fcf06a04a771013e365e010c Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 1 Aug 2018 11:50:38 -0700 Subject: [PATCH] bdev: track io_stats from deleted channels Currently, the bdev layer iterates over all of the existing channels of a bdev to collect I/O statistics. But this ignores statistics for channels that are deleted. Fix that by keeping an io_stat structure in the bdev which accumulates statistics for deleted channels. Use the bdev mutex to protect these accumulations. Signed-off-by: Jim Harris Change-Id: I3103c0b8b55973c827d977765f47e5b9e7f58e5f Reviewed-on: https://review.gerrithub.io/421029 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- include/spdk/bdev_module.h | 2 ++ lib/bdev/bdev.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index 37333934d..317dd64ad 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -324,6 +324,8 @@ struct spdk_bdev { /** weighted time performing I/O. Equal to measured_queue_depth * period */ uint64_t weighted_io_time; + /** accumulated I/O statistics for previously deleted channels of this bdev */ + struct spdk_bdev_io_stat stat; } internal; }; diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index fc85929f3..37bc593bc 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -1499,6 +1499,11 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf) SPDK_DEBUGLOG(SPDK_LOG_BDEV, "Destroying channel %p for bdev %s on thread %p\n", ch, ch->bdev->name, spdk_get_thread()); + /* This channel is going away, so add its statistics into the bdev so that they don't get lost. */ + pthread_mutex_lock(&ch->bdev->internal.mutex); + _spdk_bdev_io_stat_add(&ch->bdev->internal.stat, &ch->stat); + pthread_mutex_unlock(&ch->bdev->internal.mutex); + mgmt_ch = shared_resource->mgmt_ch; _spdk_bdev_abort_queued_io(&ch->queued_resets, ch); @@ -2305,6 +2310,12 @@ spdk_bdev_get_device_stat(struct spdk_bdev *bdev, struct spdk_bdev_io_stat *stat bdev_iostat_ctx->cb = cb; bdev_iostat_ctx->cb_arg = cb_arg; + /* Start with the statistics from previously deleted channels. */ + pthread_mutex_lock(&bdev->internal.mutex); + _spdk_bdev_io_stat_add(bdev_iostat_ctx->stat, &bdev->internal.stat); + pthread_mutex_unlock(&bdev->internal.mutex); + + /* Then iterate and add the statistics from each existing channel. */ spdk_for_each_channel(__bdev_to_io_dev(bdev), _spdk_bdev_get_each_channel_stat, bdev_iostat_ctx,