CEPH filesystem development
 help / color / mirror / Atom feed
From: Venky Shankar <vshankar@redhat.com>
To: jlayton@redhat.com, idryomov@gmail.com
Cc: xiubli@redhat.com, ceph-devel@vger.kernel.org,
	Venky Shankar <vshankar@redhat.com>
Subject: [PATCH v2 2/4] ceph: track average r/w/m latency
Date: Tue,  8 Mar 2022 07:42:17 -0500	[thread overview]
Message-ID: <20220308124219.771527-3-vshankar@redhat.com> (raw)
In-Reply-To: <20220308124219.771527-1-vshankar@redhat.com>

Make the math a bit simpler to understand (should not
effect execution speeds).

Signed-off-by: Venky Shankar <vshankar@redhat.com>
---
 fs/ceph/metric.c | 29 +++++++++++++++--------------
 fs/ceph/metric.h |  1 +
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c
index 454d2c93208e..14b6af48b611 100644
--- a/fs/ceph/metric.c
+++ b/fs/ceph/metric.c
@@ -249,6 +249,7 @@ int ceph_metric_init(struct ceph_client_metric *m)
 		metric->size_max = 0;
 		metric->total = 0;
 		metric->latency_sum = 0;
+		metric->latency_avg = 0;
 		metric->latency_sq_sum = 0;
 		metric->latency_min = KTIME_MAX;
 		metric->latency_max = 0;
@@ -306,20 +307,19 @@ void ceph_metric_destroy(struct ceph_client_metric *m)
 		max = new;			\
 }
 
-static inline void __update_stdev(ktime_t total, ktime_t lsum,
-				  ktime_t *sq_sump, ktime_t lat)
+static inline void __update_mean_and_stdev(ktime_t total, ktime_t *lavg,
+					   ktime_t *sq_sump, ktime_t lat)
 {
-	ktime_t avg, sq;
-
-	if (unlikely(total == 1))
-		return;
-
-	/* the sq is (lat - old_avg) * (lat - new_avg) */
-	avg = DIV64_U64_ROUND_CLOSEST((lsum - lat), (total - 1));
-	sq = lat - avg;
-	avg = DIV64_U64_ROUND_CLOSEST(lsum, total);
-	sq = sq * (lat - avg);
-	*sq_sump += sq;
+	ktime_t avg;
+
+	if (unlikely(total == 1)) {
+		*lavg = lat;
+	} else {
+		/* the sq is (lat - old_avg) * (lat - new_avg) */
+		avg = *lavg + div64_s64(lat - *lavg, total);
+		*sq_sump += (lat - *lavg)*(lat - avg);
+		*lavg = avg;
+	}
 }
 
 void ceph_update_metrics(struct ceph_metric *m,
@@ -338,6 +338,7 @@ void ceph_update_metrics(struct ceph_metric *m,
 	METRIC_UPDATE_MIN_MAX(m->size_min, m->size_max, size);
 	m->latency_sum += lat;
 	METRIC_UPDATE_MIN_MAX(m->latency_min, m->latency_max, lat);
-	__update_stdev(total, m->latency_sum, &m->latency_sq_sum, lat);
+	__update_mean_and_stdev(total, &m->latency_avg,	&m->latency_sq_sum,
+				lat);
 	spin_unlock(&m->lock);
 }
diff --git a/fs/ceph/metric.h b/fs/ceph/metric.h
index 5b2bb2897056..c47ba0074e49 100644
--- a/fs/ceph/metric.h
+++ b/fs/ceph/metric.h
@@ -137,6 +137,7 @@ struct ceph_metric {
 	u64 size_min;
 	u64 size_max;
 	ktime_t latency_sum;
+	ktime_t latency_avg;
 	ktime_t latency_sq_sum;
 	ktime_t latency_min;
 	ktime_t latency_max;
-- 
2.31.1


  parent reply	other threads:[~2022-03-08 12:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 12:42 [PATCH v2 0/4] ceph: forward average read/write/metadata latency Venky Shankar
2022-03-08 12:42 ` [PATCH v2 1/4] ceph: use ktime_to_timespec64() rather than jiffies_to_timespec64() Venky Shankar
2022-03-08 12:42 ` Venky Shankar [this message]
2022-03-08 12:42 ` [PATCH v2 3/4] ceph: include average/stdev r/w/m latency in mds metrics Venky Shankar
2022-03-08 12:42 ` [PATCH v2 4/4] ceph: use tracked average r/w/m latencies to display metrics in debugfs Venky Shankar
2022-03-08 12:57 ` [PATCH v2 0/4] ceph: forward average read/write/metadata latency Xiubo Li
2022-03-08 15:58 ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220308124219.771527-3-vshankar@redhat.com \
    --to=vshankar@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=jlayton@redhat.com \
    --cc=xiubli@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox