xref: /titanic_52/usr/src/uts/common/tnf/tnf_trace.h (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 (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #ifndef _TNF_TRACE_H
27 #define	_TNF_TRACE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/time.h>
33 #include <sys/tnf_probe.h>
34 #include <sys/thread.h>
35 #include <sys/processor.h>
36 
37 #include "tnf_buf.h"
38 #include "tnf_types.h"
39 
40 /*
41  * Minimum and default size of trace file
42  */
43 
44 #define	TNF_TRACE_FILE_MIN	(128 * 1024)
45 #define	TNF_TRACE_FILE_DEFAULT	(1 * 1024 * 1024)
46 
47 /*
48  * Specification of index field of probe control block
49  */
50 
51 #define	PROBE_INDEX_TYPE_MASK	0x3
52 #define	PROBE_INDEX_MEM_PTR	0x0	/* index is a normal memory ptr */
53 #define	PROBE_INDEX_FILE_PTR	0x1	/* index is a file abs ptr */
54 #define	PROBE_INDEX_LOW_MASK	0xffff0000
55 #define	PROBE_INDEX_SHIFT	16
56 
57 #define	PROBE_IS_FILE_PTR(x)	\
58 	(((x) & PROBE_INDEX_TYPE_MASK) == PROBE_INDEX_FILE_PTR)
59 
60 #define	ATTR_SEPARATOR		';'
61 #define	VAL_SEPARATOR		' '
62 
63 /*
64  * Flags in proc struct
65  */
66 #define	PROC_F_FILTER	0x1
67 
68 #define	PROC_IS_FILTER(pp)	((pp)->p_tnf_flags & PROC_F_FILTER)
69 #define	PROC_FILTER_SET(pp)	((pp)->p_tnf_flags |= PROC_F_FILTER)
70 #define	PROC_FILTER_CLR(pp)	((pp)->p_tnf_flags &= ~PROC_F_FILTER)
71 
72 /*
73  * In-memory scheduling info, maintained per thread
74  */
75 
76 typedef struct {
77 	tnf_record_p		record_p;
78 	tnf_uint32_t		record_gen;
79 	hrtime_t		time_base;
80 	processorid_t		cpuid;
81 } tnf_schedule_t;
82 
83 /*
84  * Per-thread tracing operations and state
85  */
86 
87 struct _tnf_ops {
88 	char		mode;		/* allocation mode */
89 	tnf_byte_lock_t	busy;		/* currently in a probe */
90 	TNFW_B_WCB	wcb;		/* write control info */
91 	tnf_schedule_t	schedule;	/* scheduling info */
92 };
93 
94 /*
95  * File layout of a kernel schedule record
96  */
97 
98 typedef struct {
99 	tnf_tag_t		tag;
100 	tnf_kthread_id_t	tid;
101 	tnf_lwpid_t		lwpid;
102 	tnf_pid_t		pid;
103 	/*
104 	 * time base should be on a double word boundary to avoid pads
105 	 */
106 	tnf_time_base_t		time_base;
107 	tnf_cpuid_t		cpuid;
108 } tnf_schedule_prototype_t;
109 
110 /*
111  * File layout of a probe (event tag) record
112  */
113 
114 typedef struct {
115 	tnf_tag_t		tag;
116 	tnf_name_t		name;
117 	tnf_properties_t	properties;
118 	tnf_slot_types_t	slot_types;
119 	tnf_type_size_t		type_size;
120 	tnf_slot_names_t	slot_names;
121 	tnf_string_t		string;	/* XXX detail */
122 } tnf_probe_prototype_t;
123 
124 /*
125  * Tag data variables
126  */
127 
128 extern tnf_tag_data_t	*tnf_probe_type_tag_data;
129 extern tnf_tag_data_t	*tnf_kernel_schedule_tag_data;
130 
131 /*
132  *
133  */
134 
135 extern size_t tnf_trace_file_size;
136 
137 /*
138  * Function prototypes
139  */
140 
141 /* Encoder functions */
142 
143 tnf_record_p tnf_kernel_schedule(tnf_ops_t *, tnf_schedule_t *);
144 uintptr_t tnf_probe_tag(tnf_ops_t *, tnf_probe_control_t *);
145 
146 /* Trace functions */
147 
148 void *tnf_trace_alloc(tnf_ops_t *, tnf_probe_control_t *, tnf_probe_setup_t *);
149 
150 void tnf_trace_commit(tnf_probe_setup_t *);
151 void tnf_trace_rollback(tnf_probe_setup_t *);
152 
153 /* Trace control functions */
154 
155 void tnf_trace_init(void);
156 void tnf_trace_on(void);
157 void tnf_trace_off(void);
158 
159 #endif /* _TNF_TRACE_H */
160