^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) #ifndef _FS_CEPH_MDS_METRIC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _FS_CEPH_MDS_METRIC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/percpu_counter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) extern bool disable_send_metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) enum ceph_metric_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) CLIENT_METRIC_TYPE_CAP_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) CLIENT_METRIC_TYPE_READ_LATENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) CLIENT_METRIC_TYPE_WRITE_LATENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) CLIENT_METRIC_TYPE_METADATA_LATENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) CLIENT_METRIC_TYPE_DENTRY_LEASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * This will always have the highest metric bit value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * as the last element of the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) CLIENT_METRIC_TYPE_CAP_INFO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) CLIENT_METRIC_TYPE_READ_LATENCY, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) CLIENT_METRIC_TYPE_WRITE_LATENCY, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) CLIENT_METRIC_TYPE_METADATA_LATENCY, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) CLIENT_METRIC_TYPE_MAX, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* metric caps header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct ceph_metric_cap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) __le32 type; /* ceph metric type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __u8 compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __le32 data_len; /* length of sizeof(hit + mis + total) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __le64 hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __le64 mis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __le64 total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* metric read latency header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct ceph_metric_read_latency {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) __le32 type; /* ceph metric type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __u8 compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __le32 data_len; /* length of sizeof(sec + nsec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __le32 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __le32 nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* metric write latency header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct ceph_metric_write_latency {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) __le32 type; /* ceph metric type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) __u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) __u8 compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) __le32 data_len; /* length of sizeof(sec + nsec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) __le32 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __le32 nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* metric metadata latency header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct ceph_metric_metadata_latency {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) __le32 type; /* ceph metric type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) __u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) __u8 compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) __le32 data_len; /* length of sizeof(sec + nsec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) __le32 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __le32 nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct ceph_metric_head {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __le32 num; /* the number of metrics that will be sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* This is the global metrics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct ceph_client_metric {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) atomic64_t total_dentries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct percpu_counter d_lease_hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct percpu_counter d_lease_mis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) atomic64_t total_caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct percpu_counter i_caps_hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct percpu_counter i_caps_mis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) spinlock_t read_latency_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u64 total_reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ktime_t read_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ktime_t read_latency_sq_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ktime_t read_latency_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ktime_t read_latency_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) spinlock_t write_latency_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u64 total_writes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ktime_t write_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ktime_t write_latency_sq_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ktime_t write_latency_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ktime_t write_latency_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) spinlock_t metadata_latency_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u64 total_metadatas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ktime_t metadata_latency_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ktime_t metadata_latency_sq_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ktime_t metadata_latency_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ktime_t metadata_latency_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* The total number of directories and files that are opened */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) atomic64_t opened_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* The total number of inodes that have opened files or directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct percpu_counter opened_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct percpu_counter total_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ceph_mds_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct delayed_work delayed_work; /* delayed work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline void metric_schedule_delayed(struct ceph_client_metric *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (disable_send_metrics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* per second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern int ceph_metric_init(struct ceph_client_metric *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern void ceph_metric_destroy(struct ceph_client_metric *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) percpu_counter_inc(&m->i_caps_hit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) percpu_counter_inc(&m->i_caps_mis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern void ceph_update_read_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern void ceph_update_write_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) extern void ceph_update_metadata_latency(struct ceph_client_metric *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ktime_t r_start, ktime_t r_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #endif /* _FS_CEPH_MDS_METRIC_H */