@@ -94,13 +94,14 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
cookie->type = type;
}
-/* block_latency_histogram_compare_func:
+/**
+ * block_histogram_compare_func:
* Compare @key with interval [@it[0], @it[1]).
* Return: -1 if @key < @it[0]
* 0 if @key in [@it[0], @it[1])
* +1 if @key >= @it[1]
*/
-static int block_latency_histogram_compare_func(const void *key, const void *it)
+static int block_histogram_compare_func(const void *key, const void *it)
{
uint64_t k = *(uint64_t *)key;
uint64_t a = ((uint64_t *)it)[0];
@@ -109,8 +110,7 @@ static int block_latency_histogram_compare_func(const void *key, const void *it)
return k < a ? -1 : (k < b ? 0 : 1);
}
-static void block_latency_histogram_account(BlockLatencyHistogram *hist,
- int64_t latency_ns)
+static void block_histogram_account(BlockHistogram *hist, int64_t val)
{
uint64_t *pos;
@@ -120,28 +120,26 @@ static void block_latency_histogram_account(BlockLatencyHistogram *hist,
}
- if (latency_ns < hist->boundaries[0]) {
+ if (val < hist->boundaries[0]) {
hist->bins[0]++;
return;
}
- if (latency_ns >= hist->boundaries[hist->nbins - 2]) {
+ if (val >= hist->boundaries[hist->nbins - 2]) {
hist->bins[hist->nbins - 1]++;
return;
}
- pos = bsearch(&latency_ns, hist->boundaries, hist->nbins - 2,
+ pos = bsearch(&val, hist->boundaries, hist->nbins - 2,
sizeof(hist->boundaries[0]),
- block_latency_histogram_compare_func);
+ block_histogram_compare_func);
assert(pos != NULL);
hist->bins[pos - hist->boundaries + 1]++;
}
-int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
- uint64List *boundaries)
+static int block_histogram_set(BlockHistogram *hist, uint64List *boundaries)
{
- BlockLatencyHistogram *hist = &stats->latency_histogram[type];
uint64List *entry;
uint64_t *ptr;
uint64_t prev = 0;
@@ -170,15 +168,27 @@ int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
return 0;
}
+static void block_histogram_clear(BlockHistogram *hist)
+{
+ g_free(hist->bins);
+ g_free(hist->boundaries);
+ memset(hist, 0, sizeof(*hist));
+}
+
+int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
+ uint64List *boundaries)
+{
+ BlockHistogram *hist = &stats->latency_histogram[type];
+
+ return block_histogram_set(hist, boundaries);
+}
+
void block_latency_histograms_clear(BlockAcctStats *stats)
{
int i;
for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
- BlockLatencyHistogram *hist = &stats->latency_histogram[i];
- g_free(hist->bins);
- g_free(hist->boundaries);
- memset(hist, 0, sizeof(*hist));
+ block_histogram_clear(&stats->latency_histogram[i]);
}
}
@@ -204,8 +214,8 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
stats->nr_ops[cookie->type]++;
}
- block_latency_histogram_account(&stats->latency_histogram[cookie->type],
- latency_ns);
+ block_histogram_account(&stats->latency_histogram[cookie->type],
+ latency_ns);
if (!failed || stats->account_failed) {
stats->total_time_ns[cookie->type] += latency_ns;
@@ -415,9 +415,8 @@ static uint64List *uint64_list(uint64_t *list, int size)
return out_list;
}
-static void bdrv_latency_histogram_stats(BlockLatencyHistogram *hist,
- bool *not_null,
- BlockLatencyHistogramInfo **info)
+static void bdrv_histogram_stats(BlockHistogram *hist, bool *not_null,
+ BlockLatencyHistogramInfo **info)
{
*not_null = hist->bins != NULL;
if (*not_null) {
@@ -494,15 +493,15 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
block_acct_queue_depth(ts, BLOCK_ACCT_WRITE);
}
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ],
- &ds->has_rd_latency_histogram,
- &ds->rd_latency_histogram);
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_WRITE],
- &ds->has_wr_latency_histogram,
- &ds->wr_latency_histogram);
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH],
- &ds->has_flush_latency_histogram,
- &ds->flush_latency_histogram);
+ bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ],
+ &ds->has_rd_latency_histogram,
+ &ds->rd_latency_histogram);
+ bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_WRITE],
+ &ds->has_wr_latency_histogram,
+ &ds->wr_latency_histogram);
+ bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH],
+ &ds->has_flush_latency_histogram,
+ &ds->flush_latency_histogram);
}
static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
@@ -46,7 +46,7 @@ struct BlockAcctTimedStats {
QSLIST_ENTRY(BlockAcctTimedStats) entries;
};
-typedef struct BlockLatencyHistogram {
+typedef struct BlockHistogram {
/* The following histogram is represented like this:
*
* 5| *
@@ -57,7 +57,7 @@ typedef struct BlockLatencyHistogram {
* +------------------
* 10 50 100
*
- * BlockLatencyHistogram histogram = {
+ * BlockHistogram histogram = {
* .nbins = 4,
* .boundaries = {10, 50, 100},
* .bins = {3, 1, 5, 2},
@@ -74,7 +74,7 @@ typedef struct BlockLatencyHistogram {
uint64_t *boundaries; /* @nbins-1 numbers here
(all boundaries, except 0 and +inf) */
uint64_t *bins;
-} BlockLatencyHistogram;
+} BlockHistogram;
struct BlockAcctStats {
QemuMutex lock;
@@ -88,7 +88,7 @@ struct BlockAcctStats {
QSLIST_HEAD(, BlockAcctTimedStats) intervals;
bool account_invalid;
bool account_failed;
- BlockLatencyHistogram latency_histogram[BLOCK_MAX_IOTYPE];
+ BlockHistogram latency_histogram[BLOCK_MAX_IOTYPE];
};
typedef struct BlockAcctCookie {