1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _FS_CEPH_MDS_METRIC_H
3 #define _FS_CEPH_MDS_METRIC_H
5 #include <linux/types.h>
6 #include <linux/percpu_counter.h>
7 #include <linux/ktime.h>
9 extern bool disable_send_metrics;
11 enum ceph_metric_type {
12 CLIENT_METRIC_TYPE_CAP_INFO,
13 CLIENT_METRIC_TYPE_READ_LATENCY,
14 CLIENT_METRIC_TYPE_WRITE_LATENCY,
15 CLIENT_METRIC_TYPE_METADATA_LATENCY,
16 CLIENT_METRIC_TYPE_DENTRY_LEASE,
18 CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
21 /* metric caps header */
22 struct ceph_metric_cap {
23 __le32 type; /* ceph metric type */
28 __le32 data_len; /* length of sizeof(hit + mis + total) */
34 /* metric read latency header */
35 struct ceph_metric_read_latency {
36 __le32 type; /* ceph metric type */
41 __le32 data_len; /* length of sizeof(sec + nsec) */
46 /* metric write latency header */
47 struct ceph_metric_write_latency {
48 __le32 type; /* ceph metric type */
53 __le32 data_len; /* length of sizeof(sec + nsec) */
58 /* metric metadata latency header */
59 struct ceph_metric_metadata_latency {
60 __le32 type; /* ceph metric type */
65 __le32 data_len; /* length of sizeof(sec + nsec) */
70 struct ceph_metric_head {
71 __le32 num; /* the number of metrics that will be sent */
74 /* This is the global metrics */
75 struct ceph_client_metric {
76 atomic64_t total_dentries;
77 struct percpu_counter d_lease_hit;
78 struct percpu_counter d_lease_mis;
80 atomic64_t total_caps;
81 struct percpu_counter i_caps_hit;
82 struct percpu_counter i_caps_mis;
84 spinlock_t read_latency_lock;
86 ktime_t read_latency_sum;
87 ktime_t read_latency_sq_sum;
88 ktime_t read_latency_min;
89 ktime_t read_latency_max;
91 spinlock_t write_latency_lock;
93 ktime_t write_latency_sum;
94 ktime_t write_latency_sq_sum;
95 ktime_t write_latency_min;
96 ktime_t write_latency_max;
98 spinlock_t metadata_latency_lock;
100 ktime_t metadata_latency_sum;
101 ktime_t metadata_latency_sq_sum;
102 ktime_t metadata_latency_min;
103 ktime_t metadata_latency_max;
105 struct ceph_mds_session *session;
106 struct delayed_work delayed_work; /* delayed work */
109 static inline void metric_schedule_delayed(struct ceph_client_metric *m)
111 if (disable_send_metrics)
115 schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
118 extern int ceph_metric_init(struct ceph_client_metric *m);
119 extern void ceph_metric_destroy(struct ceph_client_metric *m);
121 static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
123 percpu_counter_inc(&m->i_caps_hit);
126 static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
128 percpu_counter_inc(&m->i_caps_mis);
131 extern void ceph_update_read_latency(struct ceph_client_metric *m,
132 ktime_t r_start, ktime_t r_end,
134 extern void ceph_update_write_latency(struct ceph_client_metric *m,
135 ktime_t r_start, ktime_t r_end,
137 extern void ceph_update_metadata_latency(struct ceph_client_metric *m,
138 ktime_t r_start, ktime_t r_end,
140 #endif /* _FS_CEPH_MDS_METRIC_H */