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