metric.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _FS_CEPH_MDS_METRIC_H
  3. #define _FS_CEPH_MDS_METRIC_H
  4. #include <linux/ceph/types.h>
  5. #include <linux/percpu_counter.h>
  6. #include <linux/ktime.h>
  7. extern bool disable_send_metrics;
  8. enum ceph_metric_type {
  9. CLIENT_METRIC_TYPE_CAP_INFO,
  10. CLIENT_METRIC_TYPE_READ_LATENCY,
  11. CLIENT_METRIC_TYPE_WRITE_LATENCY,
  12. CLIENT_METRIC_TYPE_METADATA_LATENCY,
  13. CLIENT_METRIC_TYPE_DENTRY_LEASE,
  14. CLIENT_METRIC_TYPE_OPENED_FILES,
  15. CLIENT_METRIC_TYPE_PINNED_ICAPS,
  16. CLIENT_METRIC_TYPE_OPENED_INODES,
  17. CLIENT_METRIC_TYPE_READ_IO_SIZES,
  18. CLIENT_METRIC_TYPE_WRITE_IO_SIZES,
  19. CLIENT_METRIC_TYPE_AVG_READ_LATENCY,
  20. CLIENT_METRIC_TYPE_STDEV_READ_LATENCY,
  21. CLIENT_METRIC_TYPE_AVG_WRITE_LATENCY,
  22. CLIENT_METRIC_TYPE_STDEV_WRITE_LATENCY,
  23. CLIENT_METRIC_TYPE_AVG_METADATA_LATENCY,
  24. CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY,
  25. CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY,
  26. };
  27. /*
  28. * This will always have the highest metric bit value
  29. * as the last element of the array.
  30. */
  31. #define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED { \
  32. CLIENT_METRIC_TYPE_CAP_INFO, \
  33. CLIENT_METRIC_TYPE_READ_LATENCY, \
  34. CLIENT_METRIC_TYPE_WRITE_LATENCY, \
  35. CLIENT_METRIC_TYPE_METADATA_LATENCY, \
  36. CLIENT_METRIC_TYPE_DENTRY_LEASE, \
  37. CLIENT_METRIC_TYPE_OPENED_FILES, \
  38. CLIENT_METRIC_TYPE_PINNED_ICAPS, \
  39. CLIENT_METRIC_TYPE_OPENED_INODES, \
  40. CLIENT_METRIC_TYPE_READ_IO_SIZES, \
  41. CLIENT_METRIC_TYPE_WRITE_IO_SIZES, \
  42. CLIENT_METRIC_TYPE_AVG_READ_LATENCY, \
  43. CLIENT_METRIC_TYPE_STDEV_READ_LATENCY, \
  44. CLIENT_METRIC_TYPE_AVG_WRITE_LATENCY, \
  45. CLIENT_METRIC_TYPE_STDEV_WRITE_LATENCY, \
  46. CLIENT_METRIC_TYPE_AVG_METADATA_LATENCY, \
  47. CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY, \
  48. \
  49. CLIENT_METRIC_TYPE_MAX, \
  50. }
  51. struct ceph_metric_header {
  52. __le32 type; /* ceph metric type */
  53. __u8 ver;
  54. __u8 compat;
  55. __le32 data_len; /* length of sizeof(hit + mis + total) */
  56. } __packed;
  57. /* metric caps header */
  58. struct ceph_metric_cap {
  59. struct ceph_metric_header header;
  60. __le64 hit;
  61. __le64 mis;
  62. __le64 total;
  63. } __packed;
  64. /* metric read latency header */
  65. struct ceph_metric_read_latency {
  66. struct ceph_metric_header header;
  67. struct ceph_timespec lat;
  68. struct ceph_timespec avg;
  69. __le64 sq_sum;
  70. __le64 count;
  71. } __packed;
  72. /* metric write latency header */
  73. struct ceph_metric_write_latency {
  74. struct ceph_metric_header header;
  75. struct ceph_timespec lat;
  76. struct ceph_timespec avg;
  77. __le64 sq_sum;
  78. __le64 count;
  79. } __packed;
  80. /* metric metadata latency header */
  81. struct ceph_metric_metadata_latency {
  82. struct ceph_metric_header header;
  83. struct ceph_timespec lat;
  84. struct ceph_timespec avg;
  85. __le64 sq_sum;
  86. __le64 count;
  87. } __packed;
  88. /* metric dentry lease header */
  89. struct ceph_metric_dlease {
  90. struct ceph_metric_header header;
  91. __le64 hit;
  92. __le64 mis;
  93. __le64 total;
  94. } __packed;
  95. /* metric opened files header */
  96. struct ceph_opened_files {
  97. struct ceph_metric_header header;
  98. __le64 opened_files;
  99. __le64 total;
  100. } __packed;
  101. /* metric pinned i_caps header */
  102. struct ceph_pinned_icaps {
  103. struct ceph_metric_header header;
  104. __le64 pinned_icaps;
  105. __le64 total;
  106. } __packed;
  107. /* metric opened inodes header */
  108. struct ceph_opened_inodes {
  109. struct ceph_metric_header header;
  110. __le64 opened_inodes;
  111. __le64 total;
  112. } __packed;
  113. /* metric read io size header */
  114. struct ceph_read_io_size {
  115. struct ceph_metric_header header;
  116. __le64 total_ops;
  117. __le64 total_size;
  118. } __packed;
  119. /* metric write io size header */
  120. struct ceph_write_io_size {
  121. struct ceph_metric_header header;
  122. __le64 total_ops;
  123. __le64 total_size;
  124. } __packed;
  125. struct ceph_metric_head {
  126. __le32 num; /* the number of metrics that will be sent */
  127. } __packed;
  128. enum metric_type {
  129. METRIC_READ,
  130. METRIC_WRITE,
  131. METRIC_METADATA,
  132. METRIC_COPYFROM,
  133. METRIC_MAX
  134. };
  135. struct ceph_metric {
  136. spinlock_t lock;
  137. u64 total;
  138. u64 size_sum;
  139. u64 size_min;
  140. u64 size_max;
  141. ktime_t latency_sum;
  142. ktime_t latency_avg;
  143. ktime_t latency_sq_sum;
  144. ktime_t latency_min;
  145. ktime_t latency_max;
  146. };
  147. /* This is the global metrics */
  148. struct ceph_client_metric {
  149. atomic64_t total_dentries;
  150. struct percpu_counter d_lease_hit;
  151. struct percpu_counter d_lease_mis;
  152. atomic64_t total_caps;
  153. struct percpu_counter i_caps_hit;
  154. struct percpu_counter i_caps_mis;
  155. struct ceph_metric metric[METRIC_MAX];
  156. /* The total number of directories and files that are opened */
  157. atomic64_t opened_files;
  158. /* The total number of inodes that have opened files or directories */
  159. struct percpu_counter opened_inodes;
  160. struct percpu_counter total_inodes;
  161. struct ceph_mds_session *session;
  162. struct delayed_work delayed_work; /* delayed work */
  163. };
  164. static inline void metric_schedule_delayed(struct ceph_client_metric *m)
  165. {
  166. if (disable_send_metrics)
  167. return;
  168. /* per second */
  169. schedule_delayed_work(&m->delayed_work, round_jiffies_relative(HZ));
  170. }
  171. extern int ceph_metric_init(struct ceph_client_metric *m);
  172. extern void ceph_metric_destroy(struct ceph_client_metric *m);
  173. static inline void ceph_update_cap_hit(struct ceph_client_metric *m)
  174. {
  175. percpu_counter_inc(&m->i_caps_hit);
  176. }
  177. static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
  178. {
  179. percpu_counter_inc(&m->i_caps_mis);
  180. }
  181. extern void ceph_update_metrics(struct ceph_metric *m,
  182. ktime_t r_start, ktime_t r_end,
  183. unsigned int size, int rc);
  184. static inline void ceph_update_read_metrics(struct ceph_client_metric *m,
  185. ktime_t r_start, ktime_t r_end,
  186. unsigned int size, int rc)
  187. {
  188. ceph_update_metrics(&m->metric[METRIC_READ],
  189. r_start, r_end, size, rc);
  190. }
  191. static inline void ceph_update_write_metrics(struct ceph_client_metric *m,
  192. ktime_t r_start, ktime_t r_end,
  193. unsigned int size, int rc)
  194. {
  195. ceph_update_metrics(&m->metric[METRIC_WRITE],
  196. r_start, r_end, size, rc);
  197. }
  198. static inline void ceph_update_metadata_metrics(struct ceph_client_metric *m,
  199. ktime_t r_start, ktime_t r_end,
  200. int rc)
  201. {
  202. ceph_update_metrics(&m->metric[METRIC_METADATA],
  203. r_start, r_end, 0, rc);
  204. }
  205. static inline void ceph_update_copyfrom_metrics(struct ceph_client_metric *m,
  206. ktime_t r_start, ktime_t r_end,
  207. unsigned int size, int rc)
  208. {
  209. ceph_update_metrics(&m->metric[METRIC_COPYFROM],
  210. r_start, r_end, size, rc);
  211. }
  212. #endif /* _FS_CEPH_MDS_METRIC_H */