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,
17 CLIENT_METRIC_TYPE_OPENED_FILES,
18 CLIENT_METRIC_TYPE_PINNED_ICAPS,
19 CLIENT_METRIC_TYPE_OPENED_INODES,
21 CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,
25 * This will always have the highest metric bit value
26 * as the last element of the array.
28 #define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED { \
29 CLIENT_METRIC_TYPE_CAP_INFO, \
30 CLIENT_METRIC_TYPE_READ_LATENCY, \
31 CLIENT_METRIC_TYPE_WRITE_LATENCY, \
32 CLIENT_METRIC_TYPE_METADATA_LATENCY, \
33 CLIENT_METRIC_TYPE_DENTRY_LEASE, \
34 CLIENT_METRIC_TYPE_OPENED_FILES, \
35 CLIENT_METRIC_TYPE_PINNED_ICAPS, \
36 CLIENT_METRIC_TYPE_OPENED_INODES, \
38 CLIENT_METRIC_TYPE_MAX, \
41 /* metric caps header */
42 struct ceph_metric_cap {
43 __le32 type; /* ceph metric type */
48 __le32 data_len; /* length of sizeof(hit + mis + total) */
54 /* metric read latency header */
55 struct ceph_metric_read_latency {
56 __le32 type; /* ceph metric type */
61 __le32 data_len; /* length of sizeof(sec + nsec) */
66 /* metric write latency header */
67 struct ceph_metric_write_latency {
68 __le32 type; /* ceph metric type */
73 __le32 data_len; /* length of sizeof(sec + nsec) */
78 /* metric metadata latency header */
79 struct ceph_metric_metadata_latency {
80 __le32 type; /* ceph metric type */
85 __le32 data_len; /* length of sizeof(sec + nsec) */
90 /* metric dentry lease header */
91 struct ceph_metric_dlease {
92 __le32 type; /* ceph metric type */
97 __le32 data_len; /* length of sizeof(hit + mis + total) */
103 /* metric opened files header */
104 struct ceph_opened_files {
105 __le32 type; /* ceph metric type */
110 __le32 data_len; /* length of sizeof(opened_files + total) */
115 /* metric pinned i_caps header */
116 struct ceph_pinned_icaps {
117 __le32 type; /* ceph metric type */
122 __le32 data_len; /* length of sizeof(pinned_icaps + total) */
127 /* metric opened inodes header */
128 struct ceph_opened_inodes {
129 __le32 type; /* ceph metric type */
134 __le32 data_len; /* length of sizeof(opened_inodes + total) */
135 __le64 opened_inodes;
139 struct ceph_metric_head {
140 __le32 num; /* the number of metrics that will be sent */
143 /* This is the global metrics */
144 struct ceph_client_metric {
145 atomic64_t total_dentries;
146 struct percpu_counter d_lease_hit;
147 struct percpu_counter d_lease_mis;
149 atomic64_t total_caps;
150 struct percpu_counter i_caps_hit;
151 struct percpu_counter i_caps_mis;
153 spinlock_t read_metric_lock;
155 ktime_t read_latency_sum;
156 ktime_t read_latency_sq_sum;
157 ktime_t read_latency_min;
158 ktime_t read_latency_max;
160 spinlock_t write_metric_lock;
162 ktime_t write_latency_sum;
163 ktime_t write_latency_sq_sum;
164 ktime_t write_latency_min;
165 ktime_t write_latency_max;
167 spinlock_t metadata_metric_lock;
169 ktime_t metadata_latency_sum;
170 ktime_t metadata_latency_sq_sum;
171 ktime_t metadata_latency_min;
172 ktime_t metadata_latency_max;
174 /* The total number of directories and files that are opened */
175 atomic64_t opened_files;
177 /* The total number of inodes that have opened files or directories */
178 struct percpu_counter opened_inodes;
179 struct percpu_counter total_inodes;
181 struct ceph_mds_session *session;
182 struct delayed_work delayed_work; /* delayed work */
185 static inline void metric_schedule_delayed(struct ceph_client_metric *m)
187 if (disable_send_metrics)
191 schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
194 extern int ceph_metric_init(struct ceph_client_metric *m);
195 extern void ceph_metric_destroy(struct ceph_client_metric *m);
197 static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
199 percpu_counter_inc(&m->i_caps_hit);
202 static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
204 percpu_counter_inc(&m->i_caps_mis);
207 extern void ceph_update_read_metrics(struct ceph_client_metric *m,
208 ktime_t r_start, ktime_t r_end,
210 extern void ceph_update_write_metrics(struct ceph_client_metric *m,
211 ktime_t r_start, ktime_t r_end,
213 extern void ceph_update_metadata_metrics(struct ceph_client_metric *m,
214 ktime_t r_start, ktime_t r_end,
216 #endif /* _FS_CEPH_MDS_METRIC_H */