1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or https://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 #include <sys/list.h>
23 
24 #if defined(_KERNEL)
25 #if defined(HAVE_DECLARE_EVENT_CLASS)
26 
27 #undef TRACE_SYSTEM
28 #define	TRACE_SYSTEM zfs
29 
30 #undef TRACE_SYSTEM_VAR
31 #define	TRACE_SYSTEM_VAR zfs_arc
32 
33 #if !defined(_TRACE_ARC_H) || defined(TRACE_HEADER_MULTI_READ)
34 #define	_TRACE_ARC_H
35 
36 #include <linux/tracepoint.h>
37 #include <sys/types.h>
38 #include <sys/trace_common.h> /* For ZIO macros */
39 
40 /*
41  * Generic support for one argument tracepoints of the form:
42  *
43  * DTRACE_PROBE1(...,
44  *     arc_buf_hdr_t *, ...);
45  */
46 /* BEGIN CSTYLED */
47 DECLARE_EVENT_CLASS(zfs_arc_buf_hdr_class,
48 	TP_PROTO(arc_buf_hdr_t *ab),
49 	TP_ARGS(ab),
50 	TP_STRUCT__entry(
51 	    __array(uint64_t,		hdr_dva_word, 2)
52 	    __field(uint64_t,		hdr_birth)
53 	    __field(uint32_t,		hdr_flags)
54 	    __field(uint32_t,		hdr_bufcnt)
55 	    __field(arc_buf_contents_t,	hdr_type)
56 	    __field(uint16_t,		hdr_psize)
57 	    __field(uint16_t,		hdr_lsize)
58 	    __field(uint64_t,		hdr_spa)
59 	    __field(arc_state_type_t,	hdr_state_type)
60 	    __field(clock_t,		hdr_access)
61 	    __field(uint32_t,		hdr_mru_hits)
62 	    __field(uint32_t,		hdr_mru_ghost_hits)
63 	    __field(uint32_t,		hdr_mfu_hits)
64 	    __field(uint32_t,		hdr_mfu_ghost_hits)
65 	    __field(uint32_t,		hdr_l2_hits)
66 	    __field(int64_t,		hdr_refcount)
67 	),
68 	TP_fast_assign(
69 	    __entry->hdr_dva_word[0]	= ab->b_dva.dva_word[0];
70 	    __entry->hdr_dva_word[1]	= ab->b_dva.dva_word[1];
71 	    __entry->hdr_birth		= ab->b_birth;
72 	    __entry->hdr_flags		= ab->b_flags;
73 	    __entry->hdr_bufcnt	= ab->b_l1hdr.b_bufcnt;
74 	    __entry->hdr_psize		= ab->b_psize;
75 	    __entry->hdr_lsize		= ab->b_lsize;
76 	    __entry->hdr_spa		= ab->b_spa;
77 	    __entry->hdr_state_type	= ab->b_l1hdr.b_state->arcs_state;
78 	    __entry->hdr_access		= ab->b_l1hdr.b_arc_access;
79 	    __entry->hdr_mru_hits	= ab->b_l1hdr.b_mru_hits;
80 	    __entry->hdr_mru_ghost_hits	= ab->b_l1hdr.b_mru_ghost_hits;
81 	    __entry->hdr_mfu_hits	= ab->b_l1hdr.b_mfu_hits;
82 	    __entry->hdr_mfu_ghost_hits	= ab->b_l1hdr.b_mfu_ghost_hits;
83 	    __entry->hdr_l2_hits	= ab->b_l2hdr.b_hits;
84 	    __entry->hdr_refcount	= ab->b_l1hdr.b_refcnt.rc_count;
85 	),
86 	TP_printk("hdr { dva 0x%llx:0x%llx birth %llu "
87 	    "flags 0x%x bufcnt %u type %u psize %u lsize %u spa %llu "
88 	    "state_type %u access %lu mru_hits %u mru_ghost_hits %u "
89 	    "mfu_hits %u mfu_ghost_hits %u l2_hits %u refcount %lli }",
90 	    __entry->hdr_dva_word[0], __entry->hdr_dva_word[1],
91 	    __entry->hdr_birth, __entry->hdr_flags,
92 	    __entry->hdr_bufcnt, __entry->hdr_type, __entry->hdr_psize,
93 	    __entry->hdr_lsize, __entry->hdr_spa, __entry->hdr_state_type,
94 	    __entry->hdr_access, __entry->hdr_mru_hits,
95 	    __entry->hdr_mru_ghost_hits, __entry->hdr_mfu_hits,
96 	    __entry->hdr_mfu_ghost_hits, __entry->hdr_l2_hits,
97 	    __entry->hdr_refcount)
98 );
99 /* END CSTYLED */
100 
101 #define	DEFINE_ARC_BUF_HDR_EVENT(name) \
102 DEFINE_EVENT(zfs_arc_buf_hdr_class, name, \
103     TP_PROTO(arc_buf_hdr_t *ab), \
104     TP_ARGS(ab))
105 DEFINE_ARC_BUF_HDR_EVENT(zfs_arc__hit);
106 DEFINE_ARC_BUF_HDR_EVENT(zfs_arc__iohit);
107 DEFINE_ARC_BUF_HDR_EVENT(zfs_arc__evict);
108 DEFINE_ARC_BUF_HDR_EVENT(zfs_arc__delete);
109 DEFINE_ARC_BUF_HDR_EVENT(zfs_new_state__mru);
110 DEFINE_ARC_BUF_HDR_EVENT(zfs_new_state__mfu);
111 DEFINE_ARC_BUF_HDR_EVENT(zfs_new_state__uncached);
112 DEFINE_ARC_BUF_HDR_EVENT(zfs_arc__async__upgrade__sync);
113 DEFINE_ARC_BUF_HDR_EVENT(zfs_l2arc__hit);
114 DEFINE_ARC_BUF_HDR_EVENT(zfs_l2arc__miss);
115 
116 /*
117  * Generic support for two argument tracepoints of the form:
118  *
119  * DTRACE_PROBE2(...,
120  *     vdev_t *, ...,
121  *     zio_t *, ...);
122  */
123 /* BEGIN CSTYLED */
124 DECLARE_EVENT_CLASS(zfs_l2arc_rw_class,
125 	TP_PROTO(vdev_t *vd, zio_t *zio),
126 	TP_ARGS(vd, zio),
127 	TP_STRUCT__entry(
128 	    __field(uint64_t,	vdev_id)
129 	    __field(uint64_t,	vdev_guid)
130 	    __field(uint64_t,	vdev_state)
131 	    ZIO_TP_STRUCT_ENTRY
132 	),
133 	TP_fast_assign(
134 	    __entry->vdev_id	= vd->vdev_id;
135 	    __entry->vdev_guid	= vd->vdev_guid;
136 	    __entry->vdev_state	= vd->vdev_state;
137 	    ZIO_TP_FAST_ASSIGN
138 	),
139 	TP_printk("vdev { id %llu guid %llu state %llu } "
140 	    ZIO_TP_PRINTK_FMT, __entry->vdev_id, __entry->vdev_guid,
141 	    __entry->vdev_state, ZIO_TP_PRINTK_ARGS)
142 );
143 /* END CSTYLED */
144 
145 #define	DEFINE_L2ARC_RW_EVENT(name) \
146 DEFINE_EVENT(zfs_l2arc_rw_class, name, \
147     TP_PROTO(vdev_t *vd, zio_t *zio), \
148     TP_ARGS(vd, zio))
149 DEFINE_L2ARC_RW_EVENT(zfs_l2arc__read);
150 DEFINE_L2ARC_RW_EVENT(zfs_l2arc__write);
151 
152 
153 /*
154  * Generic support for two argument tracepoints of the form:
155  *
156  * DTRACE_PROBE2(...,
157  *     zio_t *, ...,
158  *     l2arc_write_callback_t *, ...);
159  */
160 /* BEGIN CSTYLED */
161 DECLARE_EVENT_CLASS(zfs_l2arc_iodone_class,
162 	TP_PROTO(zio_t *zio, l2arc_write_callback_t *cb),
163 	TP_ARGS(zio, cb),
164 	TP_STRUCT__entry(ZIO_TP_STRUCT_ENTRY),
165 	TP_fast_assign(ZIO_TP_FAST_ASSIGN),
166 	TP_printk(ZIO_TP_PRINTK_FMT, ZIO_TP_PRINTK_ARGS)
167 );
168 /* END CSTYLED */
169 
170 #define	DEFINE_L2ARC_IODONE_EVENT(name) \
171 DEFINE_EVENT(zfs_l2arc_iodone_class, name, \
172     TP_PROTO(zio_t *zio, l2arc_write_callback_t *cb), \
173     TP_ARGS(zio, cb))
174 DEFINE_L2ARC_IODONE_EVENT(zfs_l2arc__iodone);
175 
176 
177 /*
178  * Generic support for four argument tracepoints of the form:
179  *
180  * DTRACE_PROBE4(...,
181  *     arc_buf_hdr_t *, ...,
182  *     const blkptr_t *,
183  *     uint64_t,
184  *     const zbookmark_phys_t *);
185  */
186 /* BEGIN CSTYLED */
187 DECLARE_EVENT_CLASS(zfs_arc_miss_class,
188 	TP_PROTO(arc_buf_hdr_t *hdr,
189 	    const blkptr_t *bp, uint64_t size, const zbookmark_phys_t *zb),
190 	TP_ARGS(hdr, bp, size, zb),
191 	TP_STRUCT__entry(
192 	    __array(uint64_t,		hdr_dva_word, 2)
193 	    __field(uint64_t,		hdr_birth)
194 	    __field(uint32_t,		hdr_flags)
195 	    __field(uint32_t,		hdr_bufcnt)
196 	    __field(arc_buf_contents_t,	hdr_type)
197 	    __field(uint16_t,		hdr_psize)
198 	    __field(uint16_t,		hdr_lsize)
199 	    __field(uint64_t,		hdr_spa)
200 	    __field(arc_state_type_t,	hdr_state_type)
201 	    __field(clock_t,		hdr_access)
202 	    __field(uint32_t,		hdr_mru_hits)
203 	    __field(uint32_t,		hdr_mru_ghost_hits)
204 	    __field(uint32_t,		hdr_mfu_hits)
205 	    __field(uint32_t,		hdr_mfu_ghost_hits)
206 	    __field(uint32_t,		hdr_l2_hits)
207 	    __field(int64_t,		hdr_refcount)
208 
209 	    __array(uint64_t,		bp_dva0, 2)
210 	    __array(uint64_t,		bp_dva1, 2)
211 	    __array(uint64_t,		bp_dva2, 2)
212 	    __array(uint64_t,		bp_cksum, 4)
213 
214 	    __field(uint64_t,		bp_lsize)
215 
216 	    __field(uint64_t,		zb_objset)
217 	    __field(uint64_t,		zb_object)
218 	    __field(int64_t,		zb_level)
219 	    __field(uint64_t,		zb_blkid)
220 	),
221 	TP_fast_assign(
222 	    __entry->hdr_dva_word[0]	= hdr->b_dva.dva_word[0];
223 	    __entry->hdr_dva_word[1]	= hdr->b_dva.dva_word[1];
224 	    __entry->hdr_birth		= hdr->b_birth;
225 	    __entry->hdr_flags		= hdr->b_flags;
226 	    __entry->hdr_bufcnt		= hdr->b_l1hdr.b_bufcnt;
227 	    __entry->hdr_psize		= hdr->b_psize;
228 	    __entry->hdr_lsize		= hdr->b_lsize;
229 	    __entry->hdr_spa		= hdr->b_spa;
230 	    __entry->hdr_state_type	= hdr->b_l1hdr.b_state->arcs_state;
231 	    __entry->hdr_access		= hdr->b_l1hdr.b_arc_access;
232 	    __entry->hdr_mru_hits	= hdr->b_l1hdr.b_mru_hits;
233 	    __entry->hdr_mru_ghost_hits	= hdr->b_l1hdr.b_mru_ghost_hits;
234 	    __entry->hdr_mfu_hits	= hdr->b_l1hdr.b_mfu_hits;
235 	    __entry->hdr_mfu_ghost_hits	= hdr->b_l1hdr.b_mfu_ghost_hits;
236 	    __entry->hdr_l2_hits	= hdr->b_l2hdr.b_hits;
237 	    __entry->hdr_refcount	= hdr->b_l1hdr.b_refcnt.rc_count;
238 
239 	    __entry->bp_dva0[0]		= bp->blk_dva[0].dva_word[0];
240 	    __entry->bp_dva0[1]		= bp->blk_dva[0].dva_word[1];
241 	    __entry->bp_dva1[0]		= bp->blk_dva[1].dva_word[0];
242 	    __entry->bp_dva1[1]		= bp->blk_dva[1].dva_word[1];
243 	    __entry->bp_dva2[0]		= bp->blk_dva[2].dva_word[0];
244 	    __entry->bp_dva2[1]		= bp->blk_dva[2].dva_word[1];
245 	    __entry->bp_cksum[0]	= bp->blk_cksum.zc_word[0];
246 	    __entry->bp_cksum[1]	= bp->blk_cksum.zc_word[1];
247 	    __entry->bp_cksum[2]	= bp->blk_cksum.zc_word[2];
248 	    __entry->bp_cksum[3]	= bp->blk_cksum.zc_word[3];
249 
250 	    __entry->bp_lsize		= size;
251 
252 	    __entry->zb_objset		= zb->zb_objset;
253 	    __entry->zb_object		= zb->zb_object;
254 	    __entry->zb_level		= zb->zb_level;
255 	    __entry->zb_blkid		= zb->zb_blkid;
256 	),
257 	TP_printk("hdr { dva 0x%llx:0x%llx birth %llu "
258 	    "flags 0x%x bufcnt %u psize %u lsize %u spa %llu state_type %u "
259 	    "access %lu mru_hits %u mru_ghost_hits %u mfu_hits %u "
260 	    "mfu_ghost_hits %u l2_hits %u refcount %lli } "
261 	    "bp { dva0 0x%llx:0x%llx dva1 0x%llx:0x%llx dva2 "
262 	    "0x%llx:0x%llx cksum 0x%llx:0x%llx:0x%llx:0x%llx "
263 	    "lsize %llu } zb { objset %llu object %llu level %lli "
264 	    "blkid %llu }",
265 	    __entry->hdr_dva_word[0], __entry->hdr_dva_word[1],
266 	    __entry->hdr_birth, __entry->hdr_flags,
267 	    __entry->hdr_bufcnt, __entry->hdr_psize, __entry->hdr_lsize,
268 	    __entry->hdr_spa, __entry->hdr_state_type, __entry->hdr_access,
269 	    __entry->hdr_mru_hits, __entry->hdr_mru_ghost_hits,
270 	    __entry->hdr_mfu_hits, __entry->hdr_mfu_ghost_hits,
271 	    __entry->hdr_l2_hits, __entry->hdr_refcount,
272 	    __entry->bp_dva0[0], __entry->bp_dva0[1],
273 	    __entry->bp_dva1[0], __entry->bp_dva1[1],
274 	    __entry->bp_dva2[0], __entry->bp_dva2[1],
275 	    __entry->bp_cksum[0], __entry->bp_cksum[1],
276 	    __entry->bp_cksum[2], __entry->bp_cksum[3],
277 	    __entry->bp_lsize, __entry->zb_objset, __entry->zb_object,
278 	    __entry->zb_level, __entry->zb_blkid)
279 );
280 /* END CSTYLED */
281 
282 #define	DEFINE_ARC_MISS_EVENT(name) \
283 DEFINE_EVENT(zfs_arc_miss_class, name, \
284     TP_PROTO(arc_buf_hdr_t *hdr, \
285     const blkptr_t *bp, uint64_t size, const zbookmark_phys_t *zb), \
286     TP_ARGS(hdr, bp, size, zb))
287 DEFINE_ARC_MISS_EVENT(zfs_arc__miss);
288 
289 /*
290  * Generic support for four argument tracepoints of the form:
291  *
292  * DTRACE_PROBE4(...,
293  *     l2arc_dev_t *, ...,
294  *     list_t *, ...,
295  *     uint64_t, ...,
296  *     boolean_t, ...);
297  */
298 /* BEGIN CSTYLED */
299 DECLARE_EVENT_CLASS(zfs_l2arc_evict_class,
300 	TP_PROTO(l2arc_dev_t *dev,
301 	    list_t *buflist, uint64_t taddr, boolean_t all),
302 	TP_ARGS(dev, buflist, taddr, all),
303 	TP_STRUCT__entry(
304 	    __field(uint64_t,		vdev_id)
305 	    __field(uint64_t,		vdev_guid)
306 	    __field(uint64_t,		vdev_state)
307 
308 	    __field(uint64_t,		l2ad_hand)
309 	    __field(uint64_t,		l2ad_start)
310 	    __field(uint64_t,		l2ad_end)
311 	    __field(boolean_t,		l2ad_first)
312 	    __field(boolean_t,		l2ad_writing)
313 
314 	    __field(uint64_t,		taddr)
315 	    __field(boolean_t,		all)
316 	),
317 	TP_fast_assign(
318 	    __entry->vdev_id		= dev->l2ad_vdev->vdev_id;
319 	    __entry->vdev_guid		= dev->l2ad_vdev->vdev_guid;
320 	    __entry->vdev_state		= dev->l2ad_vdev->vdev_state;
321 
322 	    __entry->l2ad_hand		= dev->l2ad_hand;
323 	    __entry->l2ad_start		= dev->l2ad_start;
324 	    __entry->l2ad_end		= dev->l2ad_end;
325 	    __entry->l2ad_first		= dev->l2ad_first;
326 	    __entry->l2ad_writing	= dev->l2ad_writing;
327 
328 	    __entry->taddr		= taddr;
329 	    __entry->all		= all;
330 	),
331 	TP_printk("l2ad { vdev { id %llu guid %llu state %llu } "
332 	    "hand %llu start %llu end %llu "
333 	    "first %d writing %d } taddr %llu all %d",
334 	    __entry->vdev_id, __entry->vdev_guid, __entry->vdev_state,
335 	    __entry->l2ad_hand, __entry->l2ad_start,
336 	    __entry->l2ad_end, __entry->l2ad_first, __entry->l2ad_writing,
337 	    __entry->taddr, __entry->all)
338 );
339 /* END CSTYLED */
340 
341 #define	DEFINE_L2ARC_EVICT_EVENT(name) \
342 DEFINE_EVENT(zfs_l2arc_evict_class, name, \
343     TP_PROTO(l2arc_dev_t *dev, list_t *buflist, uint64_t taddr, boolean_t all),\
344     TP_ARGS(dev, buflist, taddr, all))
345 DEFINE_L2ARC_EVICT_EVENT(zfs_l2arc__evict);
346 
347 /*
348  * Generic support for three argument tracepoints of the form:
349  *
350  * DTRACE_PROBE3(...,
351  *     uint64_t, ...,
352  *     uint64_t, ...,
353  *     uint64_t, ...);
354  */
355 /* BEGIN CSTYLED */
356 DECLARE_EVENT_CLASS(zfs_arc_wait_for_eviction_class,
357 	TP_PROTO(uint64_t amount, uint64_t arc_evict_count, uint64_t aew_count),
358 	TP_ARGS(amount, arc_evict_count, aew_count),
359 	TP_STRUCT__entry(
360 	    __field(uint64_t,		amount)
361 	    __field(uint64_t,		arc_evict_count)
362 	    __field(uint64_t,		aew_count)
363 	),
364 	TP_fast_assign(
365 	    __entry->amount		= amount;
366 	    __entry->arc_evict_count	= arc_evict_count;
367 	    __entry->aew_count		= aew_count;
368 	),
369 	TP_printk("amount %llu arc_evict_count %llu aew_count %llu",
370 	    __entry->amount, __entry->arc_evict_count, __entry->aew_count)
371 );
372 /* END CSTYLED */
373 
374 #define	DEFINE_ARC_WAIT_FOR_EVICTION_EVENT(name) \
375 DEFINE_EVENT(zfs_arc_wait_for_eviction_class, name, \
376     TP_PROTO(uint64_t amount, uint64_t arc_evict_count, uint64_t aew_count), \
377     TP_ARGS(amount, arc_evict_count, aew_count))
378 DEFINE_ARC_WAIT_FOR_EVICTION_EVENT(zfs_arc__wait__for__eviction);
379 
380 #endif /* _TRACE_ARC_H */
381 
382 #undef TRACE_INCLUDE_PATH
383 #undef TRACE_INCLUDE_FILE
384 #define	TRACE_INCLUDE_PATH sys
385 #define	TRACE_INCLUDE_FILE trace_arc
386 #include <trace/define_trace.h>
387 
388 #else
389 
390 DEFINE_DTRACE_PROBE1(arc__hit);
391 DEFINE_DTRACE_PROBE1(arc__iohit);
392 DEFINE_DTRACE_PROBE1(arc__evict);
393 DEFINE_DTRACE_PROBE1(arc__delete);
394 DEFINE_DTRACE_PROBE1(new_state__mru);
395 DEFINE_DTRACE_PROBE1(new_state__mfu);
396 DEFINE_DTRACE_PROBE1(new_state__uncached);
397 DEFINE_DTRACE_PROBE1(arc__async__upgrade__sync);
398 DEFINE_DTRACE_PROBE1(l2arc__hit);
399 DEFINE_DTRACE_PROBE1(l2arc__miss);
400 DEFINE_DTRACE_PROBE2(l2arc__read);
401 DEFINE_DTRACE_PROBE2(l2arc__write);
402 DEFINE_DTRACE_PROBE2(l2arc__iodone);
403 DEFINE_DTRACE_PROBE3(arc__wait__for__eviction);
404 DEFINE_DTRACE_PROBE4(arc__miss);
405 DEFINE_DTRACE_PROBE4(l2arc__evict);
406 
407 #endif /* HAVE_DECLARE_EVENT_CLASS */
408 #endif /* _KERNEL */
409