xref: /openbmc/linux/fs/ceph/metric.h (revision 29c37341)
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 						\
31 	CLIENT_METRIC_TYPE_MAX,			\
32 }
33 
34 /* metric caps header */
35 struct ceph_metric_cap {
36 	__le32 type;     /* ceph metric type */
37 
38 	__u8  ver;
39 	__u8  compat;
40 
41 	__le32 data_len; /* length of sizeof(hit + mis + total) */
42 	__le64 hit;
43 	__le64 mis;
44 	__le64 total;
45 } __packed;
46 
47 /* metric read latency header */
48 struct ceph_metric_read_latency {
49 	__le32 type;     /* ceph metric type */
50 
51 	__u8  ver;
52 	__u8  compat;
53 
54 	__le32 data_len; /* length of sizeof(sec + nsec) */
55 	__le32 sec;
56 	__le32 nsec;
57 } __packed;
58 
59 /* metric write latency header */
60 struct ceph_metric_write_latency {
61 	__le32 type;     /* ceph metric type */
62 
63 	__u8  ver;
64 	__u8  compat;
65 
66 	__le32 data_len; /* length of sizeof(sec + nsec) */
67 	__le32 sec;
68 	__le32 nsec;
69 } __packed;
70 
71 /* metric metadata latency header */
72 struct ceph_metric_metadata_latency {
73 	__le32 type;     /* ceph metric type */
74 
75 	__u8  ver;
76 	__u8  compat;
77 
78 	__le32 data_len; /* length of sizeof(sec + nsec) */
79 	__le32 sec;
80 	__le32 nsec;
81 } __packed;
82 
83 struct ceph_metric_head {
84 	__le32 num;	/* the number of metrics that will be sent */
85 } __packed;
86 
87 /* This is the global metrics */
88 struct ceph_client_metric {
89 	atomic64_t            total_dentries;
90 	struct percpu_counter d_lease_hit;
91 	struct percpu_counter d_lease_mis;
92 
93 	atomic64_t            total_caps;
94 	struct percpu_counter i_caps_hit;
95 	struct percpu_counter i_caps_mis;
96 
97 	spinlock_t read_latency_lock;
98 	u64 total_reads;
99 	ktime_t read_latency_sum;
100 	ktime_t read_latency_sq_sum;
101 	ktime_t read_latency_min;
102 	ktime_t read_latency_max;
103 
104 	spinlock_t write_latency_lock;
105 	u64 total_writes;
106 	ktime_t write_latency_sum;
107 	ktime_t write_latency_sq_sum;
108 	ktime_t write_latency_min;
109 	ktime_t write_latency_max;
110 
111 	spinlock_t metadata_latency_lock;
112 	u64 total_metadatas;
113 	ktime_t metadata_latency_sum;
114 	ktime_t metadata_latency_sq_sum;
115 	ktime_t metadata_latency_min;
116 	ktime_t metadata_latency_max;
117 
118 	struct ceph_mds_session *session;
119 	struct delayed_work delayed_work;  /* delayed work */
120 };
121 
122 static inline void metric_schedule_delayed(struct ceph_client_metric *m)
123 {
124 	if (disable_send_metrics)
125 		return;
126 
127 	/* per second */
128 	schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
129 }
130 
131 extern int ceph_metric_init(struct ceph_client_metric *m);
132 extern void ceph_metric_destroy(struct ceph_client_metric *m);
133 
134 static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
135 {
136 	percpu_counter_inc(&m->i_caps_hit);
137 }
138 
139 static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
140 {
141 	percpu_counter_inc(&m->i_caps_mis);
142 }
143 
144 extern void ceph_update_read_latency(struct ceph_client_metric *m,
145 				     ktime_t r_start, ktime_t r_end,
146 				     int rc);
147 extern void ceph_update_write_latency(struct ceph_client_metric *m,
148 				      ktime_t r_start, ktime_t r_end,
149 				      int rc);
150 extern void ceph_update_metadata_latency(struct ceph_client_metric *m,
151 				         ktime_t r_start, ktime_t r_end,
152 					 int rc);
153 #endif /* _FS_CEPH_MDS_METRIC_H */
154