Skip to content

Commit 367290e

Browse files
vshankaridryomov
authored andcommitted
ceph: track average r/w/m latency
Make the math a bit simpler to understand (should not affect execution speeds). Signed-off-by: Venky Shankar <vshankar@redhat.com> Reviewed-by: Xiubo Li <xiubli@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 8d728c7 commit 367290e

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

fs/ceph/metric.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ int ceph_metric_init(struct ceph_client_metric *m)
249249
metric->size_max = 0;
250250
metric->total = 0;
251251
metric->latency_sum = 0;
252+
metric->latency_avg = 0;
252253
metric->latency_sq_sum = 0;
253254
metric->latency_min = KTIME_MAX;
254255
metric->latency_max = 0;
@@ -306,20 +307,19 @@ void ceph_metric_destroy(struct ceph_client_metric *m)
306307
max = new; \
307308
}
308309

309-
static inline void __update_stdev(ktime_t total, ktime_t lsum,
310-
ktime_t *sq_sump, ktime_t lat)
310+
static inline void __update_mean_and_stdev(ktime_t total, ktime_t *lavg,
311+
ktime_t *sq_sump, ktime_t lat)
311312
{
312-
ktime_t avg, sq;
313-
314-
if (unlikely(total == 1))
315-
return;
316-
317-
/* the sq is (lat - old_avg) * (lat - new_avg) */
318-
avg = DIV64_U64_ROUND_CLOSEST((lsum - lat), (total - 1));
319-
sq = lat - avg;
320-
avg = DIV64_U64_ROUND_CLOSEST(lsum, total);
321-
sq = sq * (lat - avg);
322-
*sq_sump += sq;
313+
ktime_t avg;
314+
315+
if (unlikely(total == 1)) {
316+
*lavg = lat;
317+
} else {
318+
/* the sq is (lat - old_avg) * (lat - new_avg) */
319+
avg = *lavg + div64_s64(lat - *lavg, total);
320+
*sq_sump += (lat - *lavg)*(lat - avg);
321+
*lavg = avg;
322+
}
323323
}
324324

325325
void ceph_update_metrics(struct ceph_metric *m,
@@ -338,6 +338,7 @@ void ceph_update_metrics(struct ceph_metric *m,
338338
METRIC_UPDATE_MIN_MAX(m->size_min, m->size_max, size);
339339
m->latency_sum += lat;
340340
METRIC_UPDATE_MIN_MAX(m->latency_min, m->latency_max, lat);
341-
__update_stdev(total, m->latency_sum, &m->latency_sq_sum, lat);
341+
__update_mean_and_stdev(total, &m->latency_avg, &m->latency_sq_sum,
342+
lat);
342343
spin_unlock(&m->lock);
343344
}

fs/ceph/metric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct ceph_metric {
137137
u64 size_min;
138138
u64 size_max;
139139
ktime_t latency_sum;
140+
ktime_t latency_avg;
140141
ktime_t latency_sq_sum;
141142
ktime_t latency_min;
142143
ktime_t latency_max;

0 commit comments

Comments
 (0)