fscache.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* FS-Cache tracepoints
  3. *
  4. * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #undef TRACE_SYSTEM
  8. #define TRACE_SYSTEM fscache
  9. #if !defined(_TRACE_FSCACHE_H) || defined(TRACE_HEADER_MULTI_READ)
  10. #define _TRACE_FSCACHE_H
  11. #include <linux/fscache.h>
  12. #include <linux/tracepoint.h>
  13. /*
  14. * Define enums for tracing information.
  15. */
  16. #ifndef __FSCACHE_DECLARE_TRACE_ENUMS_ONCE_ONLY
  17. #define __FSCACHE_DECLARE_TRACE_ENUMS_ONCE_ONLY
  18. enum fscache_cache_trace {
  19. fscache_cache_collision,
  20. fscache_cache_get_acquire,
  21. fscache_cache_new_acquire,
  22. fscache_cache_put_alloc_volume,
  23. fscache_cache_put_cache,
  24. fscache_cache_put_prep_failed,
  25. fscache_cache_put_relinquish,
  26. fscache_cache_put_volume,
  27. };
  28. enum fscache_volume_trace {
  29. fscache_volume_collision,
  30. fscache_volume_get_cookie,
  31. fscache_volume_get_create_work,
  32. fscache_volume_get_hash_collision,
  33. fscache_volume_get_withdraw,
  34. fscache_volume_free,
  35. fscache_volume_new_acquire,
  36. fscache_volume_put_cookie,
  37. fscache_volume_put_create_work,
  38. fscache_volume_put_hash_collision,
  39. fscache_volume_put_relinquish,
  40. fscache_volume_put_withdraw,
  41. fscache_volume_see_create_work,
  42. fscache_volume_see_hash_wake,
  43. fscache_volume_wait_create_work,
  44. };
  45. enum fscache_cookie_trace {
  46. fscache_cookie_collision,
  47. fscache_cookie_discard,
  48. fscache_cookie_failed,
  49. fscache_cookie_get_attach_object,
  50. fscache_cookie_get_end_access,
  51. fscache_cookie_get_hash_collision,
  52. fscache_cookie_get_inval_work,
  53. fscache_cookie_get_lru,
  54. fscache_cookie_get_use_work,
  55. fscache_cookie_new_acquire,
  56. fscache_cookie_put_hash_collision,
  57. fscache_cookie_put_lru,
  58. fscache_cookie_put_object,
  59. fscache_cookie_put_over_queued,
  60. fscache_cookie_put_relinquish,
  61. fscache_cookie_put_withdrawn,
  62. fscache_cookie_put_work,
  63. fscache_cookie_see_active,
  64. fscache_cookie_see_lru_discard,
  65. fscache_cookie_see_lru_discard_clear,
  66. fscache_cookie_see_lru_do_one,
  67. fscache_cookie_see_relinquish,
  68. fscache_cookie_see_withdraw,
  69. fscache_cookie_see_work,
  70. };
  71. enum fscache_active_trace {
  72. fscache_active_use,
  73. fscache_active_use_modify,
  74. fscache_active_unuse,
  75. };
  76. enum fscache_access_trace {
  77. fscache_access_acquire_volume,
  78. fscache_access_acquire_volume_end,
  79. fscache_access_cache_pin,
  80. fscache_access_cache_unpin,
  81. fscache_access_invalidate_cookie,
  82. fscache_access_invalidate_cookie_end,
  83. fscache_access_io_end,
  84. fscache_access_io_not_live,
  85. fscache_access_io_read,
  86. fscache_access_io_resize,
  87. fscache_access_io_wait,
  88. fscache_access_io_write,
  89. fscache_access_lookup_cookie,
  90. fscache_access_lookup_cookie_end,
  91. fscache_access_lookup_cookie_end_failed,
  92. fscache_access_relinquish_volume,
  93. fscache_access_relinquish_volume_end,
  94. fscache_access_unlive,
  95. };
  96. #endif
  97. /*
  98. * Declare tracing information enums and their string mappings for display.
  99. */
  100. #define fscache_cache_traces \
  101. EM(fscache_cache_collision, "*COLLIDE*") \
  102. EM(fscache_cache_get_acquire, "GET acq ") \
  103. EM(fscache_cache_new_acquire, "NEW acq ") \
  104. EM(fscache_cache_put_alloc_volume, "PUT alvol") \
  105. EM(fscache_cache_put_cache, "PUT cache") \
  106. EM(fscache_cache_put_prep_failed, "PUT pfail") \
  107. EM(fscache_cache_put_relinquish, "PUT relnq") \
  108. E_(fscache_cache_put_volume, "PUT vol ")
  109. #define fscache_volume_traces \
  110. EM(fscache_volume_collision, "*COLLIDE*") \
  111. EM(fscache_volume_get_cookie, "GET cook ") \
  112. EM(fscache_volume_get_create_work, "GET creat") \
  113. EM(fscache_volume_get_hash_collision, "GET hcoll") \
  114. EM(fscache_volume_get_withdraw, "GET withd") \
  115. EM(fscache_volume_free, "FREE ") \
  116. EM(fscache_volume_new_acquire, "NEW acq ") \
  117. EM(fscache_volume_put_cookie, "PUT cook ") \
  118. EM(fscache_volume_put_create_work, "PUT creat") \
  119. EM(fscache_volume_put_hash_collision, "PUT hcoll") \
  120. EM(fscache_volume_put_relinquish, "PUT relnq") \
  121. EM(fscache_volume_put_withdraw, "PUT withd") \
  122. EM(fscache_volume_see_create_work, "SEE creat") \
  123. EM(fscache_volume_see_hash_wake, "SEE hwake") \
  124. E_(fscache_volume_wait_create_work, "WAIT crea")
  125. #define fscache_cookie_traces \
  126. EM(fscache_cookie_collision, "*COLLIDE*") \
  127. EM(fscache_cookie_discard, "DISCARD ") \
  128. EM(fscache_cookie_failed, "FAILED ") \
  129. EM(fscache_cookie_get_attach_object, "GET attch") \
  130. EM(fscache_cookie_get_hash_collision, "GET hcoll") \
  131. EM(fscache_cookie_get_end_access, "GQ endac") \
  132. EM(fscache_cookie_get_inval_work, "GQ inval") \
  133. EM(fscache_cookie_get_lru, "GET lru ") \
  134. EM(fscache_cookie_get_use_work, "GQ use ") \
  135. EM(fscache_cookie_new_acquire, "NEW acq ") \
  136. EM(fscache_cookie_put_hash_collision, "PUT hcoll") \
  137. EM(fscache_cookie_put_lru, "PUT lru ") \
  138. EM(fscache_cookie_put_object, "PUT obj ") \
  139. EM(fscache_cookie_put_over_queued, "PQ overq") \
  140. EM(fscache_cookie_put_relinquish, "PUT relnq") \
  141. EM(fscache_cookie_put_withdrawn, "PUT wthdn") \
  142. EM(fscache_cookie_put_work, "PQ work ") \
  143. EM(fscache_cookie_see_active, "- activ") \
  144. EM(fscache_cookie_see_lru_discard, "- x-lru") \
  145. EM(fscache_cookie_see_lru_discard_clear,"- lrudc") \
  146. EM(fscache_cookie_see_lru_do_one, "- lrudo") \
  147. EM(fscache_cookie_see_relinquish, "- x-rlq") \
  148. EM(fscache_cookie_see_withdraw, "- x-wth") \
  149. E_(fscache_cookie_see_work, "- work ")
  150. #define fscache_active_traces \
  151. EM(fscache_active_use, "USE ") \
  152. EM(fscache_active_use_modify, "USE-m ") \
  153. E_(fscache_active_unuse, "UNUSE ")
  154. #define fscache_access_traces \
  155. EM(fscache_access_acquire_volume, "BEGIN acq_vol") \
  156. EM(fscache_access_acquire_volume_end, "END acq_vol") \
  157. EM(fscache_access_cache_pin, "PIN cache ") \
  158. EM(fscache_access_cache_unpin, "UNPIN cache ") \
  159. EM(fscache_access_invalidate_cookie, "BEGIN inval ") \
  160. EM(fscache_access_invalidate_cookie_end,"END inval ") \
  161. EM(fscache_access_io_end, "END io ") \
  162. EM(fscache_access_io_not_live, "END io_notl") \
  163. EM(fscache_access_io_read, "BEGIN io_read") \
  164. EM(fscache_access_io_resize, "BEGIN io_resz") \
  165. EM(fscache_access_io_wait, "WAIT io ") \
  166. EM(fscache_access_io_write, "BEGIN io_writ") \
  167. EM(fscache_access_lookup_cookie, "BEGIN lookup ") \
  168. EM(fscache_access_lookup_cookie_end, "END lookup ") \
  169. EM(fscache_access_lookup_cookie_end_failed,"END lookupf") \
  170. EM(fscache_access_relinquish_volume, "BEGIN rlq_vol") \
  171. EM(fscache_access_relinquish_volume_end,"END rlq_vol") \
  172. E_(fscache_access_unlive, "END unlive ")
  173. /*
  174. * Export enum symbols via userspace.
  175. */
  176. #undef EM
  177. #undef E_
  178. #define EM(a, b) TRACE_DEFINE_ENUM(a);
  179. #define E_(a, b) TRACE_DEFINE_ENUM(a);
  180. fscache_cache_traces;
  181. fscache_volume_traces;
  182. fscache_cookie_traces;
  183. fscache_access_traces;
  184. /*
  185. * Now redefine the EM() and E_() macros to map the enums to the strings that
  186. * will be printed in the output.
  187. */
  188. #undef EM
  189. #undef E_
  190. #define EM(a, b) { a, b },
  191. #define E_(a, b) { a, b }
  192. TRACE_EVENT(fscache_cache,
  193. TP_PROTO(unsigned int cache_debug_id,
  194. int usage,
  195. enum fscache_cache_trace where),
  196. TP_ARGS(cache_debug_id, usage, where),
  197. TP_STRUCT__entry(
  198. __field(unsigned int, cache )
  199. __field(int, usage )
  200. __field(enum fscache_cache_trace, where )
  201. ),
  202. TP_fast_assign(
  203. __entry->cache = cache_debug_id;
  204. __entry->usage = usage;
  205. __entry->where = where;
  206. ),
  207. TP_printk("C=%08x %s r=%d",
  208. __entry->cache,
  209. __print_symbolic(__entry->where, fscache_cache_traces),
  210. __entry->usage)
  211. );
  212. TRACE_EVENT(fscache_volume,
  213. TP_PROTO(unsigned int volume_debug_id,
  214. int usage,
  215. enum fscache_volume_trace where),
  216. TP_ARGS(volume_debug_id, usage, where),
  217. TP_STRUCT__entry(
  218. __field(unsigned int, volume )
  219. __field(int, usage )
  220. __field(enum fscache_volume_trace, where )
  221. ),
  222. TP_fast_assign(
  223. __entry->volume = volume_debug_id;
  224. __entry->usage = usage;
  225. __entry->where = where;
  226. ),
  227. TP_printk("V=%08x %s u=%d",
  228. __entry->volume,
  229. __print_symbolic(__entry->where, fscache_volume_traces),
  230. __entry->usage)
  231. );
  232. TRACE_EVENT(fscache_cookie,
  233. TP_PROTO(unsigned int cookie_debug_id,
  234. int ref,
  235. enum fscache_cookie_trace where),
  236. TP_ARGS(cookie_debug_id, ref, where),
  237. TP_STRUCT__entry(
  238. __field(unsigned int, cookie )
  239. __field(int, ref )
  240. __field(enum fscache_cookie_trace, where )
  241. ),
  242. TP_fast_assign(
  243. __entry->cookie = cookie_debug_id;
  244. __entry->ref = ref;
  245. __entry->where = where;
  246. ),
  247. TP_printk("c=%08x %s r=%d",
  248. __entry->cookie,
  249. __print_symbolic(__entry->where, fscache_cookie_traces),
  250. __entry->ref)
  251. );
  252. TRACE_EVENT(fscache_active,
  253. TP_PROTO(unsigned int cookie_debug_id,
  254. int ref,
  255. int n_active,
  256. int n_accesses,
  257. enum fscache_active_trace why),
  258. TP_ARGS(cookie_debug_id, ref, n_active, n_accesses, why),
  259. TP_STRUCT__entry(
  260. __field(unsigned int, cookie )
  261. __field(int, ref )
  262. __field(int, n_active )
  263. __field(int, n_accesses )
  264. __field(enum fscache_active_trace, why )
  265. ),
  266. TP_fast_assign(
  267. __entry->cookie = cookie_debug_id;
  268. __entry->ref = ref;
  269. __entry->n_active = n_active;
  270. __entry->n_accesses = n_accesses;
  271. __entry->why = why;
  272. ),
  273. TP_printk("c=%08x %s r=%d a=%d c=%d",
  274. __entry->cookie,
  275. __print_symbolic(__entry->why, fscache_active_traces),
  276. __entry->ref,
  277. __entry->n_accesses,
  278. __entry->n_active)
  279. );
  280. TRACE_EVENT(fscache_access_cache,
  281. TP_PROTO(unsigned int cache_debug_id,
  282. int ref,
  283. int n_accesses,
  284. enum fscache_access_trace why),
  285. TP_ARGS(cache_debug_id, ref, n_accesses, why),
  286. TP_STRUCT__entry(
  287. __field(unsigned int, cache )
  288. __field(int, ref )
  289. __field(int, n_accesses )
  290. __field(enum fscache_access_trace, why )
  291. ),
  292. TP_fast_assign(
  293. __entry->cache = cache_debug_id;
  294. __entry->ref = ref;
  295. __entry->n_accesses = n_accesses;
  296. __entry->why = why;
  297. ),
  298. TP_printk("C=%08x %s r=%d a=%d",
  299. __entry->cache,
  300. __print_symbolic(__entry->why, fscache_access_traces),
  301. __entry->ref,
  302. __entry->n_accesses)
  303. );
  304. TRACE_EVENT(fscache_access_volume,
  305. TP_PROTO(unsigned int volume_debug_id,
  306. unsigned int cookie_debug_id,
  307. int ref,
  308. int n_accesses,
  309. enum fscache_access_trace why),
  310. TP_ARGS(volume_debug_id, cookie_debug_id, ref, n_accesses, why),
  311. TP_STRUCT__entry(
  312. __field(unsigned int, volume )
  313. __field(unsigned int, cookie )
  314. __field(int, ref )
  315. __field(int, n_accesses )
  316. __field(enum fscache_access_trace, why )
  317. ),
  318. TP_fast_assign(
  319. __entry->volume = volume_debug_id;
  320. __entry->cookie = cookie_debug_id;
  321. __entry->ref = ref;
  322. __entry->n_accesses = n_accesses;
  323. __entry->why = why;
  324. ),
  325. TP_printk("V=%08x c=%08x %s r=%d a=%d",
  326. __entry->volume,
  327. __entry->cookie,
  328. __print_symbolic(__entry->why, fscache_access_traces),
  329. __entry->ref,
  330. __entry->n_accesses)
  331. );
  332. TRACE_EVENT(fscache_access,
  333. TP_PROTO(unsigned int cookie_debug_id,
  334. int ref,
  335. int n_accesses,
  336. enum fscache_access_trace why),
  337. TP_ARGS(cookie_debug_id, ref, n_accesses, why),
  338. TP_STRUCT__entry(
  339. __field(unsigned int, cookie )
  340. __field(int, ref )
  341. __field(int, n_accesses )
  342. __field(enum fscache_access_trace, why )
  343. ),
  344. TP_fast_assign(
  345. __entry->cookie = cookie_debug_id;
  346. __entry->ref = ref;
  347. __entry->n_accesses = n_accesses;
  348. __entry->why = why;
  349. ),
  350. TP_printk("c=%08x %s r=%d a=%d",
  351. __entry->cookie,
  352. __print_symbolic(__entry->why, fscache_access_traces),
  353. __entry->ref,
  354. __entry->n_accesses)
  355. );
  356. TRACE_EVENT(fscache_acquire,
  357. TP_PROTO(struct fscache_cookie *cookie),
  358. TP_ARGS(cookie),
  359. TP_STRUCT__entry(
  360. __field(unsigned int, cookie )
  361. __field(unsigned int, volume )
  362. __field(int, v_ref )
  363. __field(int, v_n_cookies )
  364. ),
  365. TP_fast_assign(
  366. __entry->cookie = cookie->debug_id;
  367. __entry->volume = cookie->volume->debug_id;
  368. __entry->v_ref = refcount_read(&cookie->volume->ref);
  369. __entry->v_n_cookies = atomic_read(&cookie->volume->n_cookies);
  370. ),
  371. TP_printk("c=%08x V=%08x vr=%d vc=%d",
  372. __entry->cookie,
  373. __entry->volume, __entry->v_ref, __entry->v_n_cookies)
  374. );
  375. TRACE_EVENT(fscache_relinquish,
  376. TP_PROTO(struct fscache_cookie *cookie, bool retire),
  377. TP_ARGS(cookie, retire),
  378. TP_STRUCT__entry(
  379. __field(unsigned int, cookie )
  380. __field(unsigned int, volume )
  381. __field(int, ref )
  382. __field(int, n_active )
  383. __field(u8, flags )
  384. __field(bool, retire )
  385. ),
  386. TP_fast_assign(
  387. __entry->cookie = cookie->debug_id;
  388. __entry->volume = cookie->volume->debug_id;
  389. __entry->ref = refcount_read(&cookie->ref);
  390. __entry->n_active = atomic_read(&cookie->n_active);
  391. __entry->flags = cookie->flags;
  392. __entry->retire = retire;
  393. ),
  394. TP_printk("c=%08x V=%08x r=%d U=%d f=%02x rt=%u",
  395. __entry->cookie, __entry->volume, __entry->ref,
  396. __entry->n_active, __entry->flags, __entry->retire)
  397. );
  398. TRACE_EVENT(fscache_invalidate,
  399. TP_PROTO(struct fscache_cookie *cookie, loff_t new_size),
  400. TP_ARGS(cookie, new_size),
  401. TP_STRUCT__entry(
  402. __field(unsigned int, cookie )
  403. __field(loff_t, new_size )
  404. ),
  405. TP_fast_assign(
  406. __entry->cookie = cookie->debug_id;
  407. __entry->new_size = new_size;
  408. ),
  409. TP_printk("c=%08x sz=%llx",
  410. __entry->cookie, __entry->new_size)
  411. );
  412. TRACE_EVENT(fscache_resize,
  413. TP_PROTO(struct fscache_cookie *cookie, loff_t new_size),
  414. TP_ARGS(cookie, new_size),
  415. TP_STRUCT__entry(
  416. __field(unsigned int, cookie )
  417. __field(loff_t, old_size )
  418. __field(loff_t, new_size )
  419. ),
  420. TP_fast_assign(
  421. __entry->cookie = cookie->debug_id;
  422. __entry->old_size = cookie->object_size;
  423. __entry->new_size = new_size;
  424. ),
  425. TP_printk("c=%08x os=%08llx sz=%08llx",
  426. __entry->cookie,
  427. __entry->old_size,
  428. __entry->new_size)
  429. );
  430. #endif /* _TRACE_FSCACHE_H */
  431. /* This part must be outside protection */
  432. #include <trace/define_trace.h>