@@ -124,34 +124,61 @@ static int mdsc_show(struct seq_file *s, void *p)
return 0;
}
+static s64 get_avg(struct percpu_counter *totalp, struct percpu_counter *sump,
+ s64 *total)
+{
+ s64 t, sum, avg = 0;
+
+ t = percpu_counter_sum(totalp);
+ sum = percpu_counter_sum(sump);
+
+ if (likely(t))
+ avg = DIV64_U64_ROUND_CLOSEST(sum, t);
+
+ *total = t;
+ return avg;
+}
+
+#define CEPH_METRIC_SHOW(name, total, avg, min, max) { \
+ s64 _avg, _min, _max; \
+ _avg = jiffies_to_usecs(avg); \
+ _min = jiffies_to_usecs(min == S64_MAX ? 0 : min); \
+ _max = jiffies_to_usecs(max); \
+ seq_printf(s, "%-14s%-12lld%-16lld%-16lld%lld\n", \
+ name, total, _avg, _min, _max); \
+}
+
static int metric_show(struct seq_file *s, void *p)
{
struct ceph_fs_client *fsc = s->private;
struct ceph_mds_client *mdsc = fsc->mdsc;
struct ceph_client_metric *m = &mdsc->metric;
int i, nr_caps = 0;
- s64 total, sum, avg = 0;
-
- seq_printf(s, "item total avg_lat(us)\n");
- seq_printf(s, "-------------------------------------\n");
-
- total = percpu_counter_sum(&m->total_reads);
- sum = percpu_counter_sum(&m->read_latency_sum);
- avg = total ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
- avg = jiffies_to_usecs(avg);
- seq_printf(s, "%-14s%-12lld%lld\n", "read", total, avg);
-
- total = percpu_counter_sum(&m->total_writes);
- sum = percpu_counter_sum(&m->write_latency_sum);
- avg = total ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
- avg = jiffies_to_usecs(avg);
- seq_printf(s, "%-14s%-12lld%lld\n", "write", total, avg);
-
- total = percpu_counter_sum(&m->total_metadatas);
- sum = percpu_counter_sum(&m->metadata_latency_sum);
- avg = total ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
- avg = jiffies_to_usecs(avg);
- seq_printf(s, "%-14s%-12lld%lld\n", "metadata", total, avg);
+ s64 total, avg, min, max;
+
+ seq_printf(s, "item total avg_lat(us) min_lat(us) max_lat(us)\n");
+ seq_printf(s, "---------------------------------------------------------------------\n");
+
+ avg = get_avg(&mdsc->metric.total_reads,
+ &mdsc->metric.read_latency_sum,
+ &total);
+ min = atomic64_read(&m->read_latency_min);
+ max = atomic64_read(&m->read_latency_max);
+ CEPH_METRIC_SHOW("read", total, avg, min, max);
+
+ avg = get_avg(&mdsc->metric.total_writes,
+ &mdsc->metric.write_latency_sum,
+ &total);
+ min = atomic64_read(&m->write_latency_min);
+ max = atomic64_read(&m->write_latency_max);
+ CEPH_METRIC_SHOW("write", total, avg, min, max);
+
+ avg = get_avg(&mdsc->metric.total_metadatas,
+ &mdsc->metric.metadata_latency_sum,
+ &total);
+ min = atomic64_read(&m->metadata_latency_min);
+ max = atomic64_read(&m->metadata_latency_max);
+ CEPH_METRIC_SHOW("metadata", total, avg, min, max);
seq_printf(s, "\n");
seq_printf(s, "item total miss hit\n");
@@ -37,6 +37,9 @@ int ceph_metric_init(struct ceph_client_metric *m)
if (ret)
goto err_read_latency_sum;
+ atomic64_set(&m->read_latency_min, S64_MAX);
+ atomic64_set(&m->read_latency_max, 0);
+
ret = percpu_counter_init(&m->total_writes, 0, GFP_KERNEL);
if (ret)
goto err_total_writes;
@@ -45,6 +48,9 @@ int ceph_metric_init(struct ceph_client_metric *m)
if (ret)
goto err_write_latency_sum;
+ atomic64_set(&m->write_latency_min, S64_MAX);
+ atomic64_set(&m->write_latency_max, 0);
+
ret = percpu_counter_init(&m->total_metadatas, 0, GFP_KERNEL);
if (ret)
goto err_total_metadatas;
@@ -53,6 +59,9 @@ int ceph_metric_init(struct ceph_client_metric *m)
if (ret)
goto err_metadata_latency_sum;
+ atomic64_set(&m->metadata_latency_min, S64_MAX);
+ atomic64_set(&m->metadata_latency_max, 0);
+
return 0;
err_metadata_latency_sum:
@@ -16,12 +16,18 @@ struct ceph_client_metric {
struct percpu_counter total_reads;
struct percpu_counter read_latency_sum;
+ atomic64_t read_latency_min;
+ atomic64_t read_latency_max;
struct percpu_counter total_writes;
struct percpu_counter write_latency_sum;
+ atomic64_t write_latency_min;
+ atomic64_t write_latency_max;
struct percpu_counter total_metadatas;
struct percpu_counter metadata_latency_sum;
+ atomic64_t metadata_latency_min;
+ atomic64_t metadata_latency_max;
};
extern int ceph_metric_init(struct ceph_client_metric *m);
@@ -37,16 +43,44 @@ static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
percpu_counter_inc(&m->i_caps_mis);
}
+static inline void __update_min_latency(atomic64_t *min, unsigned long lat)
+{
+ unsigned long cur, old;
+
+ cur = atomic64_read(min);
+ do {
+ old = cur;
+ if (likely(lat >= old))
+ break;
+ } while (unlikely((cur = atomic64_cmpxchg(min, old, lat)) != old));
+}
+
+static inline void __update_max_latency(atomic64_t *max, unsigned long lat)
+{
+ unsigned long cur, old;
+
+ cur = atomic64_read(max);
+ do {
+ old = cur;
+ if (likely(lat <= old))
+ break;
+ } while (unlikely((cur = atomic64_cmpxchg(max, old, lat)) != old));
+}
+
static inline void ceph_update_read_latency(struct ceph_client_metric *m,
unsigned long r_start,
unsigned long r_end,
int rc)
{
+ unsigned long lat = r_end - r_start;
+
if (rc < 0 && rc != -ENOENT && rc != -ETIMEDOUT)
return;
percpu_counter_inc(&m->total_reads);
- percpu_counter_add(&m->read_latency_sum, r_end - r_start);
+ percpu_counter_add(&m->read_latency_sum, lat);
+ __update_min_latency(&m->read_latency_min, lat);
+ __update_max_latency(&m->read_latency_max, lat);
}
static inline void ceph_update_write_latency(struct ceph_client_metric *m,
@@ -54,11 +88,15 @@ static inline void ceph_update_write_latency(struct ceph_client_metric *m,
unsigned long r_end,
int rc)
{
+ unsigned long lat = r_end - r_start;
+
if (rc && rc != -ETIMEDOUT)
return;
percpu_counter_inc(&m->total_writes);
- percpu_counter_add(&m->write_latency_sum, r_end - r_start);
+ percpu_counter_add(&m->write_latency_sum, lat);
+ __update_min_latency(&m->write_latency_min, lat);
+ __update_max_latency(&m->write_latency_max, lat);
}
static inline void ceph_update_metadata_latency(struct ceph_client_metric *m,
@@ -66,10 +104,14 @@ static inline void ceph_update_metadata_latency(struct ceph_client_metric *m,
unsigned long r_end,
int rc)
{
+ unsigned long lat = r_end - r_start;
+
if (rc && rc != -ENOENT)
return;
percpu_counter_inc(&m->total_metadatas);
- percpu_counter_add(&m->metadata_latency_sum, r_end - r_start);
+ percpu_counter_add(&m->metadata_latency_sum, lat);
+ __update_min_latency(&m->metadata_latency_min, lat);
+ __update_max_latency(&m->metadata_latency_max, lat);
}
#endif /* _FS_CEPH_MDS_METRIC_H */