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 http://www.opensolaris.org/os/licensing.
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 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/* #pragma ident	"@(#)sdt_subr.c	1.7	06/04/03 SMI" */
27
28#include <sys/sdt_impl.h>
29
30static dtrace_pattr_t vtrace_attr = {
31{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
32{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
33{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
34{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
35{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
36};
37
38static dtrace_pattr_t info_attr = {
39{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
40{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
41{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
42{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
43{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
44};
45
46static dtrace_pattr_t fpu_attr = {
47{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
48{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
49{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
50{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_CPU },
51{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
52};
53
54static dtrace_pattr_t fsinfo_attr = {
55{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
56{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
57{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
58{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
59{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
60};
61
62static dtrace_pattr_t stab_attr = {
63{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
64{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
65{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
66{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
67{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
68};
69
70static dtrace_pattr_t sdt_attr = {
71{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
72{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
73{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
74{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
75{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
76};
77
78sdt_provider_t sdt_providers[] = {
79	{ "vtrace", "__vtrace____", &vtrace_attr, 0 },
80	{ "sysinfo", "__cpu_sysinfo____", &info_attr, 0 },
81	{ "vminfo", "__vminfo____", &info_attr, 0 },
82	{ "fpuinfo", "__fpuinfo____", &fpu_attr, 0 },
83	{ "sched", "__sched____", &stab_attr, 0 },
84	{ "proc", "__proc____", &stab_attr, 0 },
85	{ "io", "__io____", &stab_attr, 0 },
86	{ "mib", "__mib____", &stab_attr, 0 },
87	{ "fsinfo", "__fsinfo____", &fsinfo_attr, 0 },
88	{ "sdt", "__sdt____", &sdt_attr, 0 },
89	{ NULL }
90};
91
92#warning !!! Need xnu cognate for disp_t.
93#warning !!! Need translators for bufinfo_t, cpuinfo_t, devinfo_t, fileinfo_t.
94sdt_argdesc_t sdt_args[] = {
95	{ "sched", "wakeup", 0, 0, "struct thread *", "lwpsinfo_t *" },
96	{ "sched", "wakeup", 1, 0, "struct proc *", "psinfo_t *" },
97	{ "sched", "dequeue", 0, 0, "struct thread *", "lwpsinfo_t *" },
98	{ "sched", "dequeue", 1, 0, "struct proc *", "psinfo_t *" },
99	{ "sched", "dequeue", 2, 1, "disp_t *", "cpuinfo_t *" },
100	{ "sched", "enqueue", 0, 0, "struct thread *", "lwpsinfo_t *" },
101	{ "sched", "enqueue", 1, 0, "struct proc *", "psinfo_t *" },
102	{ "sched", "enqueue", 2, 1, "disp_t *", "cpuinfo_t *" },
103	{ "sched", "enqueue", 3, 2, "int", NULL },
104	{ "sched", "off-cpu", 0, 0, "struct thread *", "lwpsinfo_t *" },
105	{ "sched", "off-cpu", 1, 0, "struct proc *", "psinfo_t *" },
106	{ "sched", "tick", 0, 0, "struct thread *", "lwpsinfo_t *" },
107	{ "sched", "tick", 1, 0, "struct proc *", "psinfo_t *" },
108	{ "sched", "change-pri", 0, 0, "struct thread *", "lwpsinfo_t *" },
109	{ "sched", "change-pri", 1, 0, "struct proc *", "psinfo_t *" },
110	{ "sched", "change-pri", 2, 1, "pri_t", NULL },
111	{ "sched", "schedctl-nopreempt", 0, 0, "struct thread *", "lwpsinfo_t *" },
112	{ "sched", "schedctl-nopreempt", 1, 0, "struct proc *", "psinfo_t *" },
113	{ "sched", "schedctl-nopreempt", 2, 1, "int", NULL },
114	{ "sched", "schedctl-preempt", 0, 0, "struct thread *", "lwpsinfo_t *" },
115	{ "sched", "schedctl-preempt", 1, 0, "struct proc *", "psinfo_t *" },
116	{ "sched", "schedctl-yield", 0, 0, "int", NULL },
117	{ "sched", "surrender", 0, 0, "struct thread *", "lwpsinfo_t *" },
118	{ "sched", "surrender", 1, 0, "struct proc *", "psinfo_t *" },
119
120	{ "proc", "create", 0, 0, "struct proc *", "psinfo_t *" },
121	{ "proc", "exec", 0, 0, "string", NULL },
122	{ "proc", "exec-failure", 0, 0, "int", NULL },
123	/* proc:::exec-success has no arguments */
124	{ "proc", "exit", 0, 0, "int", NULL },
125	{ "proc", "fault", 0, 0, "int", NULL },
126	{ "proc", "fault", 1, 1, "siginfo_t *", NULL },
127	{ "proc", "lwp-create", 0, 0, "struct thread *", "lwpsinfo_t *" },
128	{ "proc", "lwp-create", 1, 1, "struct proc *", "psinfo_t *" },
129	/* proc:::lwp-start has no arguments */
130	/* proc:::lwp-exit has no arguments */
131	{ "proc", "signal-clear", 0, 0, "int", NULL },
132	{ "proc", "signal-clear", 1, 1, "siginfo_t *", NULL },
133	{ "proc", "signal-discard", 0, 0, "struct thread *", "lwpsinfo_t *" },
134	{ "proc", "signal-discard", 1, 1, "struct proc *", "psinfo_t *" },
135	{ "proc", "signal-discard", 2, 2, "int", NULL },
136	{ "proc", "signal-handle", 0, 0, "int", NULL },
137	{ "proc", "signal-handle", 1, 1, "siginfo_t *", NULL },
138	{ "proc", "signal-handle", 2, 2, "void (*)(void)", NULL },
139	{ "proc", "signal-send", 0, 0, "struct thread *", "lwpsinfo_t *" },
140	{ "proc", "signal-send", 1, 1, "struct proc *", "psinfo_t *" },
141	{ "proc", "signal-send", 2, 2, "int", NULL },
142	/* proc:::start has no arguments */
143
144	{ "io", "start", 0, 0, "struct buf *", "bufinfo_t *" },
145	{ "io", "start", 1, 0, "struct buf *", "devinfo_t *" },
146	{ "io", "start", 2, 0, "struct buf *", "fileinfo_t *" },
147	{ "io", "done", 0, 0, "struct buf *", "bufinfo_t *" },
148	{ "io", "done", 1, 0, "struct buf *", "devinfo_t *" },
149	{ "io", "done", 2, 0, "struct buf *", "fileinfo_t *" },
150	{ "io", "wait-start", 0, 0, "struct buf *", "bufinfo_t *" },
151	{ "io", "wait-start", 1, 0, "struct buf *", "devinfo_t *" },
152	{ "io", "wait-start", 2, 0, "struct buf *", "fileinfo_t *" },
153	{ "io", "wait-done", 0, 0, "struct buf *", "bufinfo_t *" },
154	{ "io", "wait-done", 1, 0, "struct buf *", "devinfo_t *" },
155	{ "io", "wait-done", 2, 0, "struct buf *", "fileinfo_t *" },
156
157	{ "vminfo", "anonfree", 0, 0, "int", NULL },
158	{ "vminfo", "anonpgin", 0, 0, "int", NULL },
159	{ "vminfo", "anonpgout", 0, 0, "int", NULL },
160	{ "vminfo", "as_fault", 0, 0, "int", NULL },
161	{ "vminfo", "cow_fault", 0, 0, "int", NULL },
162	{ "vminfo", "dfree", 0, 0, "int", NULL },
163	{ "vminfo", "execfree", 0, 0, "int", NULL },
164	{ "vminfo", "execpgin", 0, 0, "int", NULL },
165	{ "vminfo", "execpgout", 0, 0, "int", NULL },
166	{ "vminfo", "fsfree", 0, 0, "int", NULL },
167	{ "vminfo", "fspgin", 0, 0, "int", NULL },
168	{ "vminfo", "fspgout", 0, 0, "int", NULL },
169	{ "vminfo", "kerenl_asflt", 0, 0, "int", NULL },
170	{ "vminfo", "maj_fault", 0, 0, "int", NULL },
171	{ "vminfo", "pgfrec", 0, 0, "int", NULL },
172	{ "vminfo", "pgin", 0, 0, "int", NULL },
173	{ "vminfo", "pgout", 0, 0, "int", NULL },
174	{ "vminfo", "pgpgin", 0, 0, "int", NULL },
175	{ "vminfo", "pgpgout", 0, 0, "int", NULL },
176	{ "vminfo", "pgrec", 0, 0, "int", NULL },
177	{ "vminfo", "pgrrun", 0, 0, "int", NULL },
178	{ "vminfo", "pgswapin", 0, 0, "int", NULL },
179	{ "vminfo", "pgswapout", 0, 0, "int", NULL },
180	{ "vminfo", "prot_fault", 0, 0, "int", NULL },
181	{ "vminfo", "rev", 0, 0, "int", NULL },
182	{ "vminfo", "scan", 0, 0, "int", NULL },
183	{ "vminfo", "softlock", 0, 0, "int", NULL },
184	{ "vminfo", "swapin", 0, 0, "int", NULL },
185	{ "vminfo", "swapout", 0, 0, "int", NULL },
186	{ "vminfo", "zfod", 0, 0, "int", NULL },
187
188	{ "mib", NULL, 0, 0, "int", NULL },
189	{ "fsinfo", NULL, 0, 0, "struct vnode *", "fileinfo_t *" },
190	{ "fsinfo", NULL, 1, 1, "int", "int" },
191	{ NULL }
192};
193
194/*ARGSUSED*/
195void
196sdt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
197{
198#pragma unused(arg, id)
199	sdt_probe_t *sdp = parg;
200	int i;
201
202	desc->dtargd_native[0] = '\0';
203	desc->dtargd_xlate[0] = '\0';
204
205	for (i = 0; sdt_args[i].sda_provider != NULL; i++) {
206		sdt_argdesc_t *a = &sdt_args[i];
207
208		if (strcmp(sdp->sdp_provider->sdtp_name, a->sda_provider) != 0)
209			continue;
210
211		if (a->sda_name != NULL &&
212		    strcmp(sdp->sdp_name, a->sda_name) != 0)
213			continue;
214
215		if (desc->dtargd_ndx != a->sda_ndx)
216			continue;
217
218		if (a->sda_native != NULL)
219			(void) strcpy(desc->dtargd_native, a->sda_native);
220
221		if (a->sda_xlate != NULL)
222			(void) strcpy(desc->dtargd_xlate, a->sda_xlate);
223
224		desc->dtargd_mapping = a->sda_mapping;
225		return;
226	}
227
228	desc->dtargd_ndx = DTRACE_ARGNONE;
229}
230