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