xref: /illumos-gate/usr/src/cmd/mdb/common/modules/genunix/ddi_periodic.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 /*
12  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
13  */
14 
15 #include "ddi_periodic.h"
16 
17 #include <mdb/mdb_modapi.h>
18 #include <sys/ddi_periodic.h>
19 #include <sys/sysmacros.h>
20 #include <stdio.h>
21 
22 /*ARGSUSED*/
23 int
24 dprinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
25 {
26 	char prflags[4];
27 	ddi_periodic_impl_t dpr;
28 	boolean_t verbose = B_FALSE;
29 
30 	if (!(flags & DCMD_ADDRSPEC)) {
31 		if (mdb_walk_dcmd("ddi_periodic", "ddi_periodic", argc, argv)
32 		    == -1) {
33 			mdb_warn("cannot walk 'ddi_periodic'");
34 			return (DCMD_ERR);
35 		}
36 		return (DCMD_OK);
37 	}
38 
39 	if (mdb_getopts(argc, argv,
40 	    'v', MDB_OPT_SETBITS, B_TRUE, &verbose, NULL) != argc)
41 		return (DCMD_USAGE);
42 
43 	if (mdb_vread(&dpr, sizeof (dpr), addr) == -1) {
44 		mdb_warn("could not read ddi_periodic_impl_t at %p", addr);
45 		return (DCMD_ERR);
46 	}
47 
48 	if (DCMD_HDRSPEC(flags)) {
49 		mdb_printf("%16s %4s %3s %5s %5s %12s %s\n", "ADDR", "ID",
50 		    "LVL", "FLAGS", "MS", "FIRE_COUNT", "HANDLER");
51 		if (verbose) {
52 			mdb_printf("%16s %16s %16s %s\n", "", "THREAD",
53 			    "CYCLIC_ID", "ARGUMENT");
54 		}
55 	}
56 
57 	prflags[0] = dpr.dpr_flags & DPF_DISPATCHED ? 'D' : '-';
58 	prflags[1] = dpr.dpr_flags & DPF_EXECUTING ? 'X' : '-';
59 	prflags[2] = dpr.dpr_flags & DPF_CANCELLED ? 'C' : '-';
60 	prflags[3] = '\0';
61 
62 	mdb_printf("%16p %4x %3d %5s %5d %12x %a\n", addr, dpr.dpr_id,
63 	    dpr.dpr_level, prflags, (int)(dpr.dpr_interval / 1000000),
64 	    dpr.dpr_fire_count, dpr.dpr_handler);
65 	if (verbose) {
66 		mdb_printf("%16s %16p %16p %a\n", "", dpr.dpr_thread,
67 		    dpr.dpr_cyclic_id, dpr.dpr_arg);
68 	}
69 
70 	return (DCMD_OK);
71 }
72