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