xref: /linux/fs/ceph/metric.h (revision caad79405086151dec128f78274a999f15d947ed)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _FS_CEPH_MDS_METRIC_H
3 #define _FS_CEPH_MDS_METRIC_H
4 
5 #include <linux/types.h>
6 #include <linux/percpu_counter.h>
7 #include <linux/ktime.h>
8 
9 extern bool disable_send_metrics;
10 
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,
20 
21 	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,
22 };
23 
24 /*
25  * This will always have the highest metric bit value
26  * as the last element of the array.
27  */
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,	\
37 						\
38 	CLIENT_METRIC_TYPE_MAX,			\
39 }
40 
41 /* metric caps header */
42 struct ceph_metric_cap {
43 	__le32 type;     /* ceph metric type */
44 
45 	__u8  ver;
46 	__u8  compat;
47 
48 	__le32 data_len; /* length of sizeof(hit + mis + total) */
49 	__le64 hit;
50 	__le64 mis;
51 	__le64 total;
52 } __packed;
53 
54 /* metric read latency header */
55 struct ceph_metric_read_latency {
56 	__le32 type;     /* ceph metric type */
57 
58 	__u8  ver;
59 	__u8  compat;
60 
61 	__le32 data_len; /* length of sizeof(sec + nsec) */
62 	__le32 sec;
63 	__le32 nsec;
64 } __packed;
65 
66 /* metric write latency header */
67 struct ceph_metric_write_latency {
68 	__le32 type;     /* ceph metric type */
69 
70 	__u8  ver;
71 	__u8  compat;
72 
73 	__le32 data_len; /* length of sizeof(sec + nsec) */
74 	__le32 sec;
75 	__le32 nsec;
76 } __packed;
77 
78 /* metric metadata latency header */
79 struct ceph_metric_metadata_latency {
80 	__le32 type;     /* ceph metric type */
81 
82 	__u8  ver;
83 	__u8  compat;
84 
85 	__le32 data_len; /* length of sizeof(sec + nsec) */
86 	__le32 sec;
87 	__le32 nsec;
88 } __packed;
89 
90 /* metric dentry lease header */
91 struct ceph_metric_dlease {
92 	__le32 type;     /* ceph metric type */
93 
94 	__u8  ver;
95 	__u8  compat;
96 
97 	__le32 data_len; /* length of sizeof(hit + mis + total) */
98 	__le64 hit;
99 	__le64 mis;
100 	__le64 total;
101 } __packed;
102 
103 /* metric opened files header */
104 struct ceph_opened_files {
105 	__le32 type;     /* ceph metric type */
106 
107 	__u8  ver;
108 	__u8  compat;
109 
110 	__le32 data_len; /* length of sizeof(opened_files + total) */
111 	__le64 opened_files;
112 	__le64 total;
113 } __packed;
114 
115 /* metric pinned i_caps header */
116 struct ceph_pinned_icaps {
117 	__le32 type;     /* ceph metric type */
118 
119 	__u8  ver;
120 	__u8  compat;
121 
122 	__le32 data_len; /* length of sizeof(pinned_icaps + total) */
123 	__le64 pinned_icaps;
124 	__le64 total;
125 } __packed;
126 
127 /* metric opened inodes header */
128 struct ceph_opened_inodes {
129 	__le32 type;     /* ceph metric type */
130 
131 	__u8  ver;
132 	__u8  compat;
133 
134 	__le32 data_len; /* length of sizeof(opened_inodes + total) */
135 	__le64 opened_inodes;
136 	__le64 total;
137 } __packed;
138 
139 struct ceph_metric_head {
140 	__le32 num;	/* the number of metrics that will be sent */
141 } __packed;
142 
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;
148 
149 	atomic64_t            total_caps;
150 	struct percpu_counter i_caps_hit;
151 	struct percpu_counter i_caps_mis;
152 
153 	spinlock_t read_metric_lock;
154 	u64 total_reads;
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;
159 
160 	spinlock_t write_metric_lock;
161 	u64 total_writes;
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;
166 
167 	spinlock_t metadata_metric_lock;
168 	u64 total_metadatas;
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;
173 
174 	/* The total number of directories and files that are opened */
175 	atomic64_t opened_files;
176 
177 	/* The total number of inodes that have opened files or directories */
178 	struct percpu_counter opened_inodes;
179 	struct percpu_counter total_inodes;
180 
181 	struct ceph_mds_session *session;
182 	struct delayed_work delayed_work;  /* delayed work */
183 };
184 
185 static inline void metric_schedule_delayed(struct ceph_client_metric *m)
186 {
187 	if (disable_send_metrics)
188 		return;
189 
190 	/* per second */
191 	schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
192 }
193 
194 extern int ceph_metric_init(struct ceph_client_metric *m);
195 extern void ceph_metric_destroy(struct ceph_client_metric *m);
196 
197 static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
198 {
199 	percpu_counter_inc(&m->i_caps_hit);
200 }
201 
202 static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
203 {
204 	percpu_counter_inc(&m->i_caps_mis);
205 }
206 
207 extern void ceph_update_read_metrics(struct ceph_client_metric *m,
208 				     ktime_t r_start, ktime_t r_end,
209 				     int rc);
210 extern void ceph_update_write_metrics(struct ceph_client_metric *m,
211 				      ktime_t r_start, ktime_t r_end,
212 				      int rc);
213 extern void ceph_update_metadata_metrics(struct ceph_client_metric *m,
214 				         ktime_t r_start, ktime_t r_end,
215 					 int rc);
216 #endif /* _FS_CEPH_MDS_METRIC_H */
217