Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _FS_CEPH_MDS_METRIC_H
0003 #define _FS_CEPH_MDS_METRIC_H
0004 
0005 #include <linux/ceph/types.h>
0006 #include <linux/percpu_counter.h>
0007 #include <linux/ktime.h>
0008 
0009 extern bool disable_send_metrics;
0010 
0011 enum ceph_metric_type {
0012     CLIENT_METRIC_TYPE_CAP_INFO,
0013     CLIENT_METRIC_TYPE_READ_LATENCY,
0014     CLIENT_METRIC_TYPE_WRITE_LATENCY,
0015     CLIENT_METRIC_TYPE_METADATA_LATENCY,
0016     CLIENT_METRIC_TYPE_DENTRY_LEASE,
0017     CLIENT_METRIC_TYPE_OPENED_FILES,
0018     CLIENT_METRIC_TYPE_PINNED_ICAPS,
0019     CLIENT_METRIC_TYPE_OPENED_INODES,
0020     CLIENT_METRIC_TYPE_READ_IO_SIZES,
0021     CLIENT_METRIC_TYPE_WRITE_IO_SIZES,
0022     CLIENT_METRIC_TYPE_AVG_READ_LATENCY,
0023     CLIENT_METRIC_TYPE_STDEV_READ_LATENCY,
0024     CLIENT_METRIC_TYPE_AVG_WRITE_LATENCY,
0025     CLIENT_METRIC_TYPE_STDEV_WRITE_LATENCY,
0026     CLIENT_METRIC_TYPE_AVG_METADATA_LATENCY,
0027     CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY,
0028 
0029     CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY,
0030 };
0031 
0032 /*
0033  * This will always have the highest metric bit value
0034  * as the last element of the array.
0035  */
0036 #define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED {      \
0037     CLIENT_METRIC_TYPE_CAP_INFO,           \
0038     CLIENT_METRIC_TYPE_READ_LATENCY,       \
0039     CLIENT_METRIC_TYPE_WRITE_LATENCY,      \
0040     CLIENT_METRIC_TYPE_METADATA_LATENCY,       \
0041     CLIENT_METRIC_TYPE_DENTRY_LEASE,       \
0042     CLIENT_METRIC_TYPE_OPENED_FILES,       \
0043     CLIENT_METRIC_TYPE_PINNED_ICAPS,       \
0044     CLIENT_METRIC_TYPE_OPENED_INODES,      \
0045     CLIENT_METRIC_TYPE_READ_IO_SIZES,      \
0046     CLIENT_METRIC_TYPE_WRITE_IO_SIZES,     \
0047     CLIENT_METRIC_TYPE_AVG_READ_LATENCY,       \
0048     CLIENT_METRIC_TYPE_STDEV_READ_LATENCY,     \
0049     CLIENT_METRIC_TYPE_AVG_WRITE_LATENCY,      \
0050     CLIENT_METRIC_TYPE_STDEV_WRITE_LATENCY,    \
0051     CLIENT_METRIC_TYPE_AVG_METADATA_LATENCY,   \
0052     CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY, \
0053                            \
0054     CLIENT_METRIC_TYPE_MAX,            \
0055 }
0056 
0057 struct ceph_metric_header {
0058     __le32 type;     /* ceph metric type */
0059     __u8  ver;
0060     __u8  compat;
0061     __le32 data_len; /* length of sizeof(hit + mis + total) */
0062 } __packed;
0063 
0064 /* metric caps header */
0065 struct ceph_metric_cap {
0066     struct ceph_metric_header header;
0067     __le64 hit;
0068     __le64 mis;
0069     __le64 total;
0070 } __packed;
0071 
0072 /* metric read latency header */
0073 struct ceph_metric_read_latency {
0074     struct ceph_metric_header header;
0075     struct ceph_timespec lat;
0076     struct ceph_timespec avg;
0077     __le64 sq_sum;
0078     __le64 count;
0079 } __packed;
0080 
0081 /* metric write latency header */
0082 struct ceph_metric_write_latency {
0083     struct ceph_metric_header header;
0084     struct ceph_timespec lat;
0085     struct ceph_timespec avg;
0086     __le64 sq_sum;
0087     __le64 count;
0088 } __packed;
0089 
0090 /* metric metadata latency header */
0091 struct ceph_metric_metadata_latency {
0092     struct ceph_metric_header header;
0093     struct ceph_timespec lat;
0094     struct ceph_timespec avg;
0095     __le64 sq_sum;
0096     __le64 count;
0097 } __packed;
0098 
0099 /* metric dentry lease header */
0100 struct ceph_metric_dlease {
0101     struct ceph_metric_header header;
0102     __le64 hit;
0103     __le64 mis;
0104     __le64 total;
0105 } __packed;
0106 
0107 /* metric opened files header */
0108 struct ceph_opened_files {
0109     struct ceph_metric_header header;
0110     __le64 opened_files;
0111     __le64 total;
0112 } __packed;
0113 
0114 /* metric pinned i_caps header */
0115 struct ceph_pinned_icaps {
0116     struct ceph_metric_header header;
0117     __le64 pinned_icaps;
0118     __le64 total;
0119 } __packed;
0120 
0121 /* metric opened inodes header */
0122 struct ceph_opened_inodes {
0123     struct ceph_metric_header header;
0124     __le64 opened_inodes;
0125     __le64 total;
0126 } __packed;
0127 
0128 /* metric read io size header */
0129 struct ceph_read_io_size {
0130     struct ceph_metric_header header;
0131     __le64 total_ops;
0132     __le64 total_size;
0133 } __packed;
0134 
0135 /* metric write io size header */
0136 struct ceph_write_io_size {
0137     struct ceph_metric_header header;
0138     __le64 total_ops;
0139     __le64 total_size;
0140 } __packed;
0141 
0142 struct ceph_metric_head {
0143     __le32 num; /* the number of metrics that will be sent */
0144 } __packed;
0145 
0146 enum metric_type {
0147     METRIC_READ,
0148     METRIC_WRITE,
0149     METRIC_METADATA,
0150     METRIC_COPYFROM,
0151     METRIC_MAX
0152 };
0153 
0154 struct ceph_metric {
0155     spinlock_t lock;
0156     u64 total;
0157     u64 size_sum;
0158     u64 size_min;
0159     u64 size_max;
0160     ktime_t latency_sum;
0161     ktime_t latency_avg;
0162     ktime_t latency_sq_sum;
0163     ktime_t latency_min;
0164     ktime_t latency_max;
0165 };
0166 
0167 /* This is the global metrics */
0168 struct ceph_client_metric {
0169     atomic64_t            total_dentries;
0170     struct percpu_counter d_lease_hit;
0171     struct percpu_counter d_lease_mis;
0172 
0173     atomic64_t            total_caps;
0174     struct percpu_counter i_caps_hit;
0175     struct percpu_counter i_caps_mis;
0176 
0177     struct ceph_metric metric[METRIC_MAX];
0178 
0179     /* The total number of directories and files that are opened */
0180     atomic64_t opened_files;
0181 
0182     /* The total number of inodes that have opened files or directories */
0183     struct percpu_counter opened_inodes;
0184     struct percpu_counter total_inodes;
0185 
0186     struct ceph_mds_session *session;
0187     struct delayed_work delayed_work;  /* delayed work */
0188 };
0189 
0190 static inline void metric_schedule_delayed(struct ceph_client_metric *m)
0191 {
0192     if (disable_send_metrics)
0193         return;
0194 
0195     /* per second */
0196     schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
0197 }
0198 
0199 extern int ceph_metric_init(struct ceph_client_metric *m);
0200 extern void ceph_metric_destroy(struct ceph_client_metric *m);
0201 
0202 static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
0203 {
0204     percpu_counter_inc(&m->i_caps_hit);
0205 }
0206 
0207 static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
0208 {
0209     percpu_counter_inc(&m->i_caps_mis);
0210 }
0211 
0212 extern void ceph_update_metrics(struct ceph_metric *m,
0213                 ktime_t r_start, ktime_t r_end,
0214                 unsigned int size, int rc);
0215 
0216 static inline void ceph_update_read_metrics(struct ceph_client_metric *m,
0217                         ktime_t r_start, ktime_t r_end,
0218                         unsigned int size, int rc)
0219 {
0220     ceph_update_metrics(&m->metric[METRIC_READ],
0221                 r_start, r_end, size, rc);
0222 }
0223 static inline void ceph_update_write_metrics(struct ceph_client_metric *m,
0224                          ktime_t r_start, ktime_t r_end,
0225                          unsigned int size, int rc)
0226 {
0227     ceph_update_metrics(&m->metric[METRIC_WRITE],
0228                 r_start, r_end, size, rc);
0229 }
0230 static inline void ceph_update_metadata_metrics(struct ceph_client_metric *m,
0231                         ktime_t r_start, ktime_t r_end,
0232                         int rc)
0233 {
0234     ceph_update_metrics(&m->metric[METRIC_METADATA],
0235                 r_start, r_end, 0, rc);
0236 }
0237 static inline void ceph_update_copyfrom_metrics(struct ceph_client_metric *m,
0238                         ktime_t r_start, ktime_t r_end,
0239                         unsigned int size, int rc)
0240 {
0241     ceph_update_metrics(&m->metric[METRIC_COPYFROM],
0242                 r_start, r_end, size, rc);
0243 }
0244 #endif /* _FS_CEPH_MDS_METRIC_H */