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