Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 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> |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 7 | #include <linux/ktime.h> |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 8 | |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 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, |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 17 | CLIENT_METRIC_TYPE_OPENED_FILES, |
| 18 | CLIENT_METRIC_TYPE_PINNED_ICAPS, |
| 19 | CLIENT_METRIC_TYPE_OPENED_INODES, |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 20 | CLIENT_METRIC_TYPE_READ_IO_SIZES, |
| 21 | CLIENT_METRIC_TYPE_WRITE_IO_SIZES, |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 22 | |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 23 | CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_WRITE_IO_SIZES, |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 24 | }; |
| 25 | |
Xiubo Li | 3b4168d | 2020-07-16 10:05:58 -0400 | [diff] [blame] | 26 | /* |
| 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 Li | 8ba3b8c | 2020-11-05 23:30:21 -0500 | [diff] [blame] | 35 | CLIENT_METRIC_TYPE_DENTRY_LEASE, \ |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 36 | CLIENT_METRIC_TYPE_OPENED_FILES, \ |
| 37 | CLIENT_METRIC_TYPE_PINNED_ICAPS, \ |
| 38 | CLIENT_METRIC_TYPE_OPENED_INODES, \ |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 39 | CLIENT_METRIC_TYPE_READ_IO_SIZES, \ |
| 40 | CLIENT_METRIC_TYPE_WRITE_IO_SIZES, \ |
Xiubo Li | 3b4168d | 2020-07-16 10:05:58 -0400 | [diff] [blame] | 41 | \ |
| 42 | CLIENT_METRIC_TYPE_MAX, \ |
| 43 | } |
| 44 | |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 45 | struct ceph_metric_header { |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 46 | __le32 type; /* ceph metric type */ |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 47 | __u8 ver; |
| 48 | __u8 compat; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 49 | __le32 data_len; /* length of sizeof(hit + mis + total) */ |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 50 | } __packed; |
| 51 | |
| 52 | /* metric caps header */ |
| 53 | struct ceph_metric_cap { |
| 54 | struct ceph_metric_header header; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 55 | __le64 hit; |
| 56 | __le64 mis; |
| 57 | __le64 total; |
| 58 | } __packed; |
| 59 | |
| 60 | /* metric read latency header */ |
| 61 | struct ceph_metric_read_latency { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 62 | struct ceph_metric_header header; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 63 | __le32 sec; |
| 64 | __le32 nsec; |
| 65 | } __packed; |
| 66 | |
| 67 | /* metric write latency header */ |
| 68 | struct ceph_metric_write_latency { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 69 | struct ceph_metric_header header; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 70 | __le32 sec; |
| 71 | __le32 nsec; |
| 72 | } __packed; |
| 73 | |
| 74 | /* metric metadata latency header */ |
| 75 | struct ceph_metric_metadata_latency { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 76 | struct ceph_metric_header header; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 77 | __le32 sec; |
| 78 | __le32 nsec; |
| 79 | } __packed; |
| 80 | |
Xiubo Li | 8ba3b8c | 2020-11-05 23:30:21 -0500 | [diff] [blame] | 81 | /* metric dentry lease header */ |
| 82 | struct ceph_metric_dlease { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 83 | struct ceph_metric_header header; |
Xiubo Li | 8ba3b8c | 2020-11-05 23:30:21 -0500 | [diff] [blame] | 84 | __le64 hit; |
| 85 | __le64 mis; |
| 86 | __le64 total; |
| 87 | } __packed; |
| 88 | |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 89 | /* metric opened files header */ |
| 90 | struct ceph_opened_files { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 91 | struct ceph_metric_header header; |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 92 | __le64 opened_files; |
| 93 | __le64 total; |
| 94 | } __packed; |
| 95 | |
| 96 | /* metric pinned i_caps header */ |
| 97 | struct ceph_pinned_icaps { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 98 | struct ceph_metric_header header; |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 99 | __le64 pinned_icaps; |
| 100 | __le64 total; |
| 101 | } __packed; |
| 102 | |
| 103 | /* metric opened inodes header */ |
| 104 | struct ceph_opened_inodes { |
Xiubo Li | 8ecd34c | 2021-05-13 09:40:52 +0800 | [diff] [blame] | 105 | struct ceph_metric_header header; |
Xiubo Li | 3d8b698 | 2021-03-24 13:08:25 +0800 | [diff] [blame] | 106 | __le64 opened_inodes; |
| 107 | __le64 total; |
| 108 | } __packed; |
| 109 | |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 110 | /* metric read io size header */ |
| 111 | struct 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 */ |
| 118 | struct ceph_write_io_size { |
| 119 | struct ceph_metric_header header; |
| 120 | __le64 total_ops; |
| 121 | __le64 total_size; |
| 122 | } __packed; |
| 123 | |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 124 | struct ceph_metric_head { |
| 125 | __le32 num; /* the number of metrics that will be sent */ |
| 126 | } __packed; |
| 127 | |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 128 | /* This is the global metrics */ |
| 129 | struct ceph_client_metric { |
| 130 | atomic64_t total_dentries; |
| 131 | struct percpu_counter d_lease_hit; |
| 132 | struct percpu_counter d_lease_mis; |
Xiubo Li | 1af16d5 | 2020-03-19 23:45:00 -0400 | [diff] [blame] | 133 | |
Xiubo Li | 4f1d756 | 2020-06-30 03:52:16 -0400 | [diff] [blame] | 134 | atomic64_t total_caps; |
Xiubo Li | 1af16d5 | 2020-03-19 23:45:00 -0400 | [diff] [blame] | 135 | struct percpu_counter i_caps_hit; |
| 136 | struct percpu_counter i_caps_mis; |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 137 | |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 138 | spinlock_t read_metric_lock; |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 139 | u64 total_reads; |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 140 | u64 read_size_sum; |
| 141 | u64 read_size_min; |
| 142 | u64 read_size_max; |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 143 | ktime_t read_latency_sum; |
| 144 | ktime_t read_latency_sq_sum; |
| 145 | ktime_t read_latency_min; |
| 146 | ktime_t read_latency_max; |
| 147 | |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 148 | spinlock_t write_metric_lock; |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 149 | u64 total_writes; |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 150 | u64 write_size_sum; |
| 151 | u64 write_size_min; |
| 152 | u64 write_size_max; |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 153 | ktime_t write_latency_sum; |
| 154 | ktime_t write_latency_sq_sum; |
| 155 | ktime_t write_latency_min; |
| 156 | ktime_t write_latency_max; |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 157 | |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 158 | spinlock_t metadata_metric_lock; |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 159 | u64 total_metadatas; |
| 160 | ktime_t metadata_latency_sum; |
| 161 | ktime_t metadata_latency_sq_sum; |
| 162 | ktime_t metadata_latency_min; |
| 163 | ktime_t metadata_latency_max; |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 164 | |
Xiubo Li | 1dd8d47 | 2020-09-03 09:01:40 -0400 | [diff] [blame] | 165 | /* The total number of directories and files that are opened */ |
| 166 | atomic64_t opened_files; |
| 167 | |
| 168 | /* The total number of inodes that have opened files or directories */ |
| 169 | struct percpu_counter opened_inodes; |
| 170 | struct percpu_counter total_inodes; |
| 171 | |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 172 | struct ceph_mds_session *session; |
| 173 | struct delayed_work delayed_work; /* delayed work */ |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 174 | }; |
| 175 | |
Xiubo Li | 18f473b | 2020-07-16 10:05:57 -0400 | [diff] [blame] | 176 | static inline void metric_schedule_delayed(struct ceph_client_metric *m) |
| 177 | { |
| 178 | if (disable_send_metrics) |
| 179 | return; |
| 180 | |
| 181 | /* per second */ |
| 182 | schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ)); |
| 183 | } |
| 184 | |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 185 | extern int ceph_metric_init(struct ceph_client_metric *m); |
| 186 | extern void ceph_metric_destroy(struct ceph_client_metric *m); |
Xiubo Li | 1af16d5 | 2020-03-19 23:45:00 -0400 | [diff] [blame] | 187 | |
| 188 | static inline void ceph_update_cap_hit(struct ceph_client_metric *m) |
| 189 | { |
| 190 | percpu_counter_inc(&m->i_caps_hit); |
| 191 | } |
| 192 | |
| 193 | static inline void ceph_update_cap_mis(struct ceph_client_metric *m) |
| 194 | { |
| 195 | percpu_counter_inc(&m->i_caps_mis); |
| 196 | } |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 197 | |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 198 | extern void ceph_update_read_metrics(struct ceph_client_metric *m, |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 199 | ktime_t r_start, ktime_t r_end, |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 200 | unsigned int size, int rc); |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 201 | extern void ceph_update_write_metrics(struct ceph_client_metric *m, |
Xiubo Li | 97e27aa | 2020-03-19 23:45:01 -0400 | [diff] [blame] | 202 | ktime_t r_start, ktime_t r_end, |
Xiubo Li | 903f4fec | 2021-05-13 09:40:53 +0800 | [diff] [blame] | 203 | unsigned int size, int rc); |
Xiubo Li | 8ae99ae | 2021-03-22 20:28:49 +0800 | [diff] [blame] | 204 | extern void ceph_update_metadata_metrics(struct ceph_client_metric *m, |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 205 | ktime_t r_start, ktime_t r_end, |
| 206 | int rc); |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 207 | #endif /* _FS_CEPH_MDS_METRIC_H */ |