util: add abstractions for accessing histogram buckets
This simplifies some upcoming changes, where the buckets will be a dynamically allocated array instead of a static 2-dimensional array. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I3854319385937be9f9ace4be7dd22423e24f25e3 Reviewed-on: https://review.gerrithub.io/392706 Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
87b8c7db3c
commit
2eeec4be49
@ -91,6 +91,18 @@ struct spdk_histogram_data {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
__spdk_histogram_increment(struct spdk_histogram_data *h, uint32_t range, uint32_t index)
|
||||||
|
{
|
||||||
|
h->bucket[range][index]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
__spdk_histogram_get_count(const struct spdk_histogram_data *h, uint32_t range, uint32_t index)
|
||||||
|
{
|
||||||
|
return h->bucket[range][index];
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
spdk_histogram_data_reset(struct spdk_histogram_data *histogram)
|
spdk_histogram_data_reset(struct spdk_histogram_data *histogram)
|
||||||
{
|
{
|
||||||
@ -136,7 +148,7 @@ spdk_histogram_data_tally(struct spdk_histogram_data *histogram, uint64_t datapo
|
|||||||
uint32_t range = __spdk_histogram_data_get_bucket_range(histogram, datapoint);
|
uint32_t range = __spdk_histogram_data_get_bucket_range(histogram, datapoint);
|
||||||
uint32_t index = __spdk_histogram_data_get_bucket_index(histogram, datapoint, range);
|
uint32_t index = __spdk_histogram_data_get_bucket_index(histogram, datapoint, range);
|
||||||
|
|
||||||
histogram->bucket[range][index]++;
|
__spdk_histogram_increment(histogram, range, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
@ -170,7 +182,7 @@ spdk_histogram_data_iterate(const struct spdk_histogram_data *histogram,
|
|||||||
|
|
||||||
for (i = 0; i < SPDK_HISTOGRAM_NUM_BUCKET_RANGES(histogram); i++) {
|
for (i = 0; i < SPDK_HISTOGRAM_NUM_BUCKET_RANGES(histogram); i++) {
|
||||||
for (j = 0; j < SPDK_HISTOGRAM_NUM_BUCKETS_PER_RANGE(histogram); j++) {
|
for (j = 0; j < SPDK_HISTOGRAM_NUM_BUCKETS_PER_RANGE(histogram); j++) {
|
||||||
total += histogram->bucket[i][j];
|
total += __spdk_histogram_get_count(histogram, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +191,7 @@ spdk_histogram_data_iterate(const struct spdk_histogram_data *histogram,
|
|||||||
|
|
||||||
for (i = 0; i < SPDK_HISTOGRAM_NUM_BUCKET_RANGES(histogram); i++) {
|
for (i = 0; i < SPDK_HISTOGRAM_NUM_BUCKET_RANGES(histogram); i++) {
|
||||||
for (j = 0; j < SPDK_HISTOGRAM_NUM_BUCKETS_PER_RANGE(histogram); j++) {
|
for (j = 0; j < SPDK_HISTOGRAM_NUM_BUCKETS_PER_RANGE(histogram); j++) {
|
||||||
count = histogram->bucket[i][j];
|
count = __spdk_histogram_get_count(histogram, i, j);
|
||||||
so_far += count;
|
so_far += count;
|
||||||
last_bucket = bucket;
|
last_bucket = bucket;
|
||||||
bucket = __spdk_histogram_data_get_bucket_start(histogram, i, j);
|
bucket = __spdk_histogram_data_get_bucket_start(histogram, i, j);
|
||||||
|
Loading…
Reference in New Issue
Block a user