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