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