^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/percpu_counter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "metric.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "mds_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct ceph_mds_session *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct ceph_metric_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct ceph_metric_cap *cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ceph_metric_read_latency *read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct ceph_metric_write_latency *write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct ceph_metric_metadata_latency *meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct ceph_client_metric *m = &mdsc->metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u64 nr_caps = atomic64_read(&m->total_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct ceph_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) s64 sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) s32 items = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) s32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) + sizeof(*meta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (!msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) pr_err("send metrics to mds%d, failed to allocate message\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) s->s_mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) head = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* encode the cap metric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cap = (struct ceph_metric_cap *)(head + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) cap->type = cpu_to_le32(CLIENT_METRIC_TYPE_CAP_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) cap->ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) cap->compat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) cap->data_len = cpu_to_le32(sizeof(*cap) - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) cap->hit = cpu_to_le64(percpu_counter_sum(&mdsc->metric.i_caps_hit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) cap->mis = cpu_to_le64(percpu_counter_sum(&mdsc->metric.i_caps_mis));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) cap->total = cpu_to_le64(nr_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) items++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* encode the read latency metric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) read = (struct ceph_metric_read_latency *)(cap + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) read->type = cpu_to_le32(CLIENT_METRIC_TYPE_READ_LATENCY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) read->ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) read->compat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) read->data_len = cpu_to_le32(sizeof(*read) - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) sum = m->read_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) jiffies_to_timespec64(sum, &ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) read->sec = cpu_to_le32(ts.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) read->nsec = cpu_to_le32(ts.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) items++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* encode the write latency metric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) write = (struct ceph_metric_write_latency *)(read + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) write->type = cpu_to_le32(CLIENT_METRIC_TYPE_WRITE_LATENCY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) write->ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) write->compat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) write->data_len = cpu_to_le32(sizeof(*write) - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) sum = m->write_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) jiffies_to_timespec64(sum, &ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) write->sec = cpu_to_le32(ts.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) write->nsec = cpu_to_le32(ts.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) items++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* encode the metadata latency metric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) meta = (struct ceph_metric_metadata_latency *)(write + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) meta->type = cpu_to_le32(CLIENT_METRIC_TYPE_METADATA_LATENCY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) meta->ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) meta->compat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) meta->data_len = cpu_to_le32(sizeof(*meta) - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) sum = m->metadata_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) jiffies_to_timespec64(sum, &ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) meta->sec = cpu_to_le32(ts.tv_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) meta->nsec = cpu_to_le32(ts.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) items++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) put_unaligned_le32(items, &head->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) msg->front.iov_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) msg->hdr.version = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) msg->hdr.compat_version = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) dout("client%llu send metrics to mds%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ceph_client_gid(mdsc->fsc->client), s->s_mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ceph_con_send(&s->s_con, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void metric_get_session(struct ceph_mds_client *mdsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct ceph_mds_session *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) mutex_lock(&mdsc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) for (i = 0; i < mdsc->max_sessions; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) s = __ceph_lookup_mds_session(mdsc, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Skip it if MDS doesn't support the metric collection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * or the MDS will close the session's socket connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * directly when it get this message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (check_session_state(s) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) test_bit(CEPHFS_FEATURE_METRIC_COLLECT, &s->s_features)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) mdsc->metric.session = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ceph_put_mds_session(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) mutex_unlock(&mdsc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void metric_delayed_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct ceph_client_metric *m =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) container_of(work, struct ceph_client_metric, delayed_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct ceph_mds_client *mdsc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) container_of(m, struct ceph_mds_client, metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (mdsc->stopping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (!m->session || !check_session_state(m->session)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (m->session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ceph_put_mds_session(m->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) m->session = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) metric_get_session(mdsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (m->session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ceph_mdsc_send_metrics(mdsc, m->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) metric_schedule_delayed(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int ceph_metric_init(struct ceph_client_metric *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) atomic64_set(&m->total_dentries, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = percpu_counter_init(&m->d_lease_hit, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ret = percpu_counter_init(&m->d_lease_mis, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto err_d_lease_mis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) atomic64_set(&m->total_caps, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ret = percpu_counter_init(&m->i_caps_hit, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) goto err_i_caps_hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ret = percpu_counter_init(&m->i_caps_mis, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) goto err_i_caps_mis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) spin_lock_init(&m->read_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) m->read_latency_sq_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) m->read_latency_min = KTIME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) m->read_latency_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) m->total_reads = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) m->read_latency_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) spin_lock_init(&m->write_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) m->write_latency_sq_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) m->write_latency_min = KTIME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) m->write_latency_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) m->total_writes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) m->write_latency_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) spin_lock_init(&m->metadata_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) m->metadata_latency_sq_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) m->metadata_latency_min = KTIME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) m->metadata_latency_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) m->total_metadatas = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) m->metadata_latency_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) atomic64_set(&m->opened_files, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ret = percpu_counter_init(&m->opened_inodes, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) goto err_opened_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ret = percpu_counter_init(&m->total_inodes, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto err_total_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) m->session = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) INIT_DELAYED_WORK(&m->delayed_work, metric_delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) err_total_inodes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) percpu_counter_destroy(&m->opened_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) err_opened_inodes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) percpu_counter_destroy(&m->i_caps_mis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) err_i_caps_mis:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) percpu_counter_destroy(&m->i_caps_hit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) err_i_caps_hit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) percpu_counter_destroy(&m->d_lease_mis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) err_d_lease_mis:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) percpu_counter_destroy(&m->d_lease_hit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) void ceph_metric_destroy(struct ceph_client_metric *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) cancel_delayed_work_sync(&m->delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) percpu_counter_destroy(&m->total_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) percpu_counter_destroy(&m->opened_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) percpu_counter_destroy(&m->i_caps_mis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) percpu_counter_destroy(&m->i_caps_hit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) percpu_counter_destroy(&m->d_lease_mis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) percpu_counter_destroy(&m->d_lease_hit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ceph_put_mds_session(m->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static inline void __update_latency(ktime_t *totalp, ktime_t *lsump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ktime_t *min, ktime_t *max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ktime_t *sq_sump, ktime_t lat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ktime_t total, avg, sq, lsum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) total = ++(*totalp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) lsum = (*lsump += lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (unlikely(lat < *min))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) *min = lat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (unlikely(lat > *max))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *max = lat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (unlikely(total == 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* the sq is (lat - old_avg) * (lat - new_avg) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) avg = DIV64_U64_ROUND_CLOSEST((lsum - lat), (total - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) sq = lat - avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) avg = DIV64_U64_ROUND_CLOSEST(lsum, total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) sq = sq * (lat - avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) *sq_sump += sq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void ceph_update_read_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ktime_t lat = ktime_sub(r_end, r_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (unlikely(rc < 0 && rc != -ENOENT && rc != -ETIMEDOUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) spin_lock(&m->read_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) __update_latency(&m->total_reads, &m->read_latency_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) &m->read_latency_min, &m->read_latency_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) &m->read_latency_sq_sum, lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) spin_unlock(&m->read_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void ceph_update_write_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ktime_t lat = ktime_sub(r_end, r_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (unlikely(rc && rc != -ETIMEDOUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) spin_lock(&m->write_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) __update_latency(&m->total_writes, &m->write_latency_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) &m->write_latency_min, &m->write_latency_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) &m->write_latency_sq_sum, lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) spin_unlock(&m->write_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) void ceph_update_metadata_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ktime_t lat = ktime_sub(r_end, r_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (unlikely(rc && rc != -ENOENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) spin_lock(&m->metadata_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) __update_latency(&m->total_metadatas, &m->metadata_latency_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) &m->metadata_latency_min, &m->metadata_latency_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) &m->metadata_latency_sq_sum, lat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) spin_unlock(&m->metadata_latency_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }