xref: /titanic_41/usr/src/uts/common/tnf/trace_init.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
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  * Copyright 1994-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Includes
31  */
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/debug.h>
36 #include <sys/tnf.h>
37 #include <sys/thread.h>
38 #include <sys/dtrace.h>
39 
40 #include "tnf_buf.h"
41 #include "tnf_types.h"
42 #include "tnf_trace.h"
43 
44 #ifndef NPROBE
45 
46 /*
47  * Globals
48  */
49 
50 size_t tnf_trace_file_size = TNF_TRACE_FILE_DEFAULT;
51 
52 /*
53  * tnf_trace_on
54  */
55 void
tnf_trace_on(void)56 tnf_trace_on(void)
57 {
58 	TNFW_B_UNSET_STOPPED(tnfw_b_state);
59 	tnf_tracing_active = 1;
60 	dtrace_vtime_enable_tnf();
61 	/* Enable system call tracing for all processes */
62 	set_all_proc_sys();
63 }
64 
65 /*
66  * tnf_trace_off
67  */
68 void
tnf_trace_off(void)69 tnf_trace_off(void)
70 {
71 	TNFW_B_SET_STOPPED(tnfw_b_state);
72 	dtrace_vtime_disable_tnf();
73 	tnf_tracing_active = 0;
74 	/* System call tracing is automatically disabled */
75 }
76 
77 /*
78  * tnf_trace_init
79  * 	Not reentrant: only called from tnf_allocbuf(), which is
80  *	single-threaded.
81  */
82 void
tnf_trace_init(void)83 tnf_trace_init(void)
84 {
85 	int stopped;
86 	tnf_ops_t *ops;
87 
88 	ASSERT(tnf_buf != NULL);
89 	ASSERT(!tnf_tracing_active);
90 
91 	stopped = tnfw_b_state & TNFW_B_STOPPED;
92 
93 	/*
94 	 * Initialize the buffer
95 	 */
96 	tnfw_b_init_buffer(tnf_buf, tnf_trace_file_size);
97 
98 	/*
99 	 * Mark allocator running (not stopped). Luckily,
100 	 * tnf_trace_alloc() first checks tnf_tracing_active, so no
101 	 * trace data will be written.
102 	 */
103 	tnfw_b_state = TNFW_B_RUNNING;
104 
105 	/*
106 	 * 1195835: Write out some tags now.  The stopped bit needs
107 	 * to be clear while we do this.
108 	 */
109 	/* LINTED pointer cast may result in improper alignment */
110 	if ((ops = (tnf_ops_t *)curthread->t_tnf_tpdp) != NULL) {
111 		tnf_tag_data_t	*tag;
112 		TNFW_B_POS	*pos;
113 
114 		ASSERT(!LOCK_HELD(&ops->busy));
115 		LOCK_INIT_HELD(&ops->busy); /* XXX save a call */
116 
117 		tag = TAG_DATA(tnf_struct_type);
118 		(void) tag->tag_desc(ops, tag);
119 		tag = TAG_DATA(tnf_probe_type);
120 		(void) tag->tag_desc(ops, tag);
121 		tag = TAG_DATA(tnf_kernel_schedule);
122 		(void) tag->tag_desc(ops, tag);
123 
124 		pos = &ops->wcb.tnfw_w_tag_pos;
125 		TNFW_B_COMMIT(pos);
126 		pos = &ops->wcb.tnfw_w_pos;
127 		TNFW_B_ROLLBACK(pos);
128 
129 		LOCK_INIT_CLEAR(&ops->busy); /* XXX save a call */
130 	}
131 
132 	/* Restore stopped bit */
133 	tnfw_b_state |= stopped;
134 }
135 
136 #endif /* NPROBE */
137