blob: bb45608181e7f2678367a6bf5167ba3f0b3715e8 [file] [log] [blame]
Xiubo Lif9009ef2020-03-19 23:44:59 -04001/* 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>
Xiubo Li97e27aa2020-03-19 23:45:01 -04007#include <linux/ktime.h>
Xiubo Lif9009ef2020-03-19 23:44:59 -04008
Xiubo Li18f473b2020-07-16 10:05:57 -04009extern bool disable_send_metrics;
10
11enum 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,
Xiubo Li3d8b6982021-03-24 13:08:25 +080017 CLIENT_METRIC_TYPE_OPENED_FILES,
18 CLIENT_METRIC_TYPE_PINNED_ICAPS,
19 CLIENT_METRIC_TYPE_OPENED_INODES,
Xiubo Li903f4fec2021-05-13 09:40:53 +080020 CLIENT_METRIC_TYPE_READ_IO_SIZES,
21 CLIENT_METRIC_TYPE_WRITE_IO_SIZES,
Xiubo Li18f473b2020-07-16 10:05:57 -040022
Xiubo Li903f4fec2021-05-13 09:40:53 +080023 CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_WRITE_IO_SIZES,
Xiubo Li18f473b2020-07-16 10:05:57 -040024};
25
Xiubo Li3b4168d2020-07-16 10:05:58 -040026/*
27 * This will always have the highest metric bit value
28 * as the last element of the array.
29 */
30#define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED { \
31 CLIENT_METRIC_TYPE_CAP_INFO, \
32 CLIENT_METRIC_TYPE_READ_LATENCY, \
33 CLIENT_METRIC_TYPE_WRITE_LATENCY, \
34 CLIENT_METRIC_TYPE_METADATA_LATENCY, \
Xiubo Li8ba3b8c2020-11-05 23:30:21 -050035 CLIENT_METRIC_TYPE_DENTRY_LEASE, \
Xiubo Li3d8b6982021-03-24 13:08:25 +080036 CLIENT_METRIC_TYPE_OPENED_FILES, \
37 CLIENT_METRIC_TYPE_PINNED_ICAPS, \
38 CLIENT_METRIC_TYPE_OPENED_INODES, \
Xiubo Li903f4fec2021-05-13 09:40:53 +080039 CLIENT_METRIC_TYPE_READ_IO_SIZES, \
40 CLIENT_METRIC_TYPE_WRITE_IO_SIZES, \
Xiubo Li3b4168d2020-07-16 10:05:58 -040041 \
42 CLIENT_METRIC_TYPE_MAX, \
43}
44
Xiubo Li8ecd34c2021-05-13 09:40:52 +080045struct ceph_metric_header {
Xiubo Li18f473b2020-07-16 10:05:57 -040046 __le32 type; /* ceph metric type */
Xiubo Li18f473b2020-07-16 10:05:57 -040047 __u8 ver;
48 __u8 compat;
Xiubo Li18f473b2020-07-16 10:05:57 -040049 __le32 data_len; /* length of sizeof(hit + mis + total) */
Xiubo Li8ecd34c2021-05-13 09:40:52 +080050} __packed;
51
52/* metric caps header */
53struct ceph_metric_cap {
54 struct ceph_metric_header header;
Xiubo Li18f473b2020-07-16 10:05:57 -040055 __le64 hit;
56 __le64 mis;
57 __le64 total;
58} __packed;
59
60/* metric read latency header */
61struct ceph_metric_read_latency {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080062 struct ceph_metric_header header;
Xiubo Li18f473b2020-07-16 10:05:57 -040063 __le32 sec;
64 __le32 nsec;
65} __packed;
66
67/* metric write latency header */
68struct ceph_metric_write_latency {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080069 struct ceph_metric_header header;
Xiubo Li18f473b2020-07-16 10:05:57 -040070 __le32 sec;
71 __le32 nsec;
72} __packed;
73
74/* metric metadata latency header */
75struct ceph_metric_metadata_latency {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080076 struct ceph_metric_header header;
Xiubo Li18f473b2020-07-16 10:05:57 -040077 __le32 sec;
78 __le32 nsec;
79} __packed;
80
Xiubo Li8ba3b8c2020-11-05 23:30:21 -050081/* metric dentry lease header */
82struct ceph_metric_dlease {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080083 struct ceph_metric_header header;
Xiubo Li8ba3b8c2020-11-05 23:30:21 -050084 __le64 hit;
85 __le64 mis;
86 __le64 total;
87} __packed;
88
Xiubo Li3d8b6982021-03-24 13:08:25 +080089/* metric opened files header */
90struct ceph_opened_files {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080091 struct ceph_metric_header header;
Xiubo Li3d8b6982021-03-24 13:08:25 +080092 __le64 opened_files;
93 __le64 total;
94} __packed;
95
96/* metric pinned i_caps header */
97struct ceph_pinned_icaps {
Xiubo Li8ecd34c2021-05-13 09:40:52 +080098 struct ceph_metric_header header;
Xiubo Li3d8b6982021-03-24 13:08:25 +080099 __le64 pinned_icaps;
100 __le64 total;
101} __packed;
102
103/* metric opened inodes header */
104struct ceph_opened_inodes {
Xiubo Li8ecd34c2021-05-13 09:40:52 +0800105 struct ceph_metric_header header;
Xiubo Li3d8b6982021-03-24 13:08:25 +0800106 __le64 opened_inodes;
107 __le64 total;
108} __packed;
109
Xiubo Li903f4fec2021-05-13 09:40:53 +0800110/* metric read io size header */
111struct ceph_read_io_size {
112 struct ceph_metric_header header;
113 __le64 total_ops;
114 __le64 total_size;
115} __packed;
116
117/* metric write io size header */
118struct ceph_write_io_size {
119 struct ceph_metric_header header;
120 __le64 total_ops;
121 __le64 total_size;
122} __packed;
123
Xiubo Li18f473b2020-07-16 10:05:57 -0400124struct ceph_metric_head {
125 __le32 num; /* the number of metrics that will be sent */
126} __packed;
127
Luís Henriques17e9fc92021-10-29 15:09:28 +0100128enum metric_type {
129 METRIC_READ,
130 METRIC_WRITE,
131 METRIC_METADATA,
Luís Henriquesc02cb7b2021-11-04 12:31:47 +0000132 METRIC_COPYFROM,
Luís Henriques17e9fc92021-10-29 15:09:28 +0100133 METRIC_MAX
134};
135
136struct ceph_metric {
137 spinlock_t lock;
138 u64 total;
139 u64 size_sum;
140 u64 size_min;
141 u64 size_max;
142 ktime_t latency_sum;
143 ktime_t latency_sq_sum;
144 ktime_t latency_min;
145 ktime_t latency_max;
146};
147
Xiubo Lif9009ef2020-03-19 23:44:59 -0400148/* This is the global metrics */
149struct ceph_client_metric {
150 atomic64_t total_dentries;
151 struct percpu_counter d_lease_hit;
152 struct percpu_counter d_lease_mis;
Xiubo Li1af16d52020-03-19 23:45:00 -0400153
Xiubo Li4f1d7562020-06-30 03:52:16 -0400154 atomic64_t total_caps;
Xiubo Li1af16d52020-03-19 23:45:00 -0400155 struct percpu_counter i_caps_hit;
156 struct percpu_counter i_caps_mis;
Xiubo Li97e27aa2020-03-19 23:45:01 -0400157
Luís Henriques17e9fc92021-10-29 15:09:28 +0100158 struct ceph_metric metric[METRIC_MAX];
Xiubo Li18f473b2020-07-16 10:05:57 -0400159
Xiubo Li1dd8d472020-09-03 09:01:40 -0400160 /* The total number of directories and files that are opened */
161 atomic64_t opened_files;
162
163 /* The total number of inodes that have opened files or directories */
164 struct percpu_counter opened_inodes;
165 struct percpu_counter total_inodes;
166
Xiubo Li18f473b2020-07-16 10:05:57 -0400167 struct ceph_mds_session *session;
168 struct delayed_work delayed_work; /* delayed work */
Xiubo Lif9009ef2020-03-19 23:44:59 -0400169};
170
Xiubo Li18f473b2020-07-16 10:05:57 -0400171static inline void metric_schedule_delayed(struct ceph_client_metric *m)
172{
173 if (disable_send_metrics)
174 return;
175
176 /* per second */
177 schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
178}
179
Xiubo Lif9009ef2020-03-19 23:44:59 -0400180extern int ceph_metric_init(struct ceph_client_metric *m);
181extern void ceph_metric_destroy(struct ceph_client_metric *m);
Xiubo Li1af16d52020-03-19 23:45:00 -0400182
183static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
184{
185 percpu_counter_inc(&m->i_caps_hit);
186}
187
188static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
189{
190 percpu_counter_inc(&m->i_caps_mis);
191}
Xiubo Li97e27aa2020-03-19 23:45:01 -0400192
Luís Henriques17e9fc92021-10-29 15:09:28 +0100193extern void ceph_update_metrics(struct ceph_metric *m,
194 ktime_t r_start, ktime_t r_end,
195 unsigned int size, int rc);
196
197static inline void ceph_update_read_metrics(struct ceph_client_metric *m,
198 ktime_t r_start, ktime_t r_end,
199 unsigned int size, int rc)
200{
201 ceph_update_metrics(&m->metric[METRIC_READ],
202 r_start, r_end, size, rc);
203}
204static inline void ceph_update_write_metrics(struct ceph_client_metric *m,
205 ktime_t r_start, ktime_t r_end,
206 unsigned int size, int rc)
207{
208 ceph_update_metrics(&m->metric[METRIC_WRITE],
209 r_start, r_end, size, rc);
210}
211static inline void ceph_update_metadata_metrics(struct ceph_client_metric *m,
212 ktime_t r_start, ktime_t r_end,
213 int rc)
214{
215 ceph_update_metrics(&m->metric[METRIC_METADATA],
216 r_start, r_end, 0, rc);
217}
Luís Henriquesc02cb7b2021-11-04 12:31:47 +0000218static inline void ceph_update_copyfrom_metrics(struct ceph_client_metric *m,
219 ktime_t r_start, ktime_t r_end,
220 unsigned int size, int rc)
221{
222 ceph_update_metrics(&m->metric[METRIC_COPYFROM],
223 r_start, r_end, size, rc);
224}
Xiubo Lif9009ef2020-03-19 23:44:59 -0400225#endif /* _FS_CEPH_MDS_METRIC_H */