xref: /onnv-gate/usr/src/lib/libtnfprobe/trace_funcs.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate  */
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate  * Includes
30*0Sstevel@tonic-gate  */
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifndef DEBUG
33*0Sstevel@tonic-gate #define	NDEBUG	1
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <assert.h>
37*0Sstevel@tonic-gate #include <limits.h>
38*0Sstevel@tonic-gate #include <values.h>
39*0Sstevel@tonic-gate #include <stdio.h>
40*0Sstevel@tonic-gate #include <string.h>
41*0Sstevel@tonic-gate #include <unistd.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #include "tnf_trace.h"
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate /*
46*0Sstevel@tonic-gate  * Defines
47*0Sstevel@tonic-gate  */
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate #define	ASSERT(expr)	assert(expr)
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate #define	ENCODED_TAG(tag, tagarg) 		\
52*0Sstevel@tonic-gate 	(((tag) | ((tagarg) & 0xfffc)) | TNF_REF32_T_PAIR)
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * CAUTION: halfword_accessible assumes that the pointer is to a reclaimable
56*0Sstevel@tonic-gate  *		block - i.e. negative offsets have a 0 in high bit
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate #define	HALFWORD_ACCESSIBLE(x) 			\
59*0Sstevel@tonic-gate 	((((x) & 0xffff8000) == 0) || (((x) & 0xffff8000) == 0x7fff8000))
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate /*
62*0Sstevel@tonic-gate  * Check that x can be encoded in tagarg slot
63*0Sstevel@tonic-gate  * Same as above, but operates on ints (no space bit)
64*0Sstevel@tonic-gate  */
65*0Sstevel@tonic-gate #define	TAGARG_CHECK(x)				\
66*0Sstevel@tonic-gate 	(((x) < 32767) && ((x) > -32768))
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * Check that hi 32 bits of hrtime are zero
70*0Sstevel@tonic-gate  */
71*0Sstevel@tonic-gate #define	TIME_CHECK(x)				\
72*0Sstevel@tonic-gate 	(((x) >> 32) == 0)
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate  * CAUTION: Use the following macro only when doing a self relative pointer
76*0Sstevel@tonic-gate  *		to a target in the same block
77*0Sstevel@tonic-gate  */
78*0Sstevel@tonic-gate #define	PTR_DIFF(item, ref)			\
79*0Sstevel@tonic-gate 	((tnf_ref32_t)((tnf_record_p)(item) - (tnf_record_p)(ref)))
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate /*
82*0Sstevel@tonic-gate  * Typedefs
83*0Sstevel@tonic-gate  */
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate typedef struct {
86*0Sstevel@tonic-gate 	tnf_probe_event_t		probe_event;
87*0Sstevel@tonic-gate 	tnf_time_delta_t		time_delta;
88*0Sstevel@tonic-gate } probe_event_prototype_t;
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate  * tnf_trace_alloc
92*0Sstevel@tonic-gate  * 	the probe allocation function
93*0Sstevel@tonic-gate  */
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate #define	IS_NEWBLOCK(blockArray, dataBuffer) \
96*0Sstevel@tonic-gate 	    (((caddr_t)&blockArray[1]) == (caddr_t)dataBuffer)
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate void *
tnf_trace_alloc(tnf_ops_t * ops,tnf_probe_control_t * probe_p,tnf_probe_setup_t * set_p)99*0Sstevel@tonic-gate tnf_trace_alloc(tnf_ops_t *ops, tnf_probe_control_t *probe_p,
100*0Sstevel@tonic-gate     tnf_probe_setup_t *set_p)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	TNFW_B_WCB		*wcb;
103*0Sstevel@tonic-gate 	volatile char 		*file_start;
104*0Sstevel@tonic-gate 	uintptr_t		probe_index;
105*0Sstevel@tonic-gate 	tnf_record_p		sched_record_p;
106*0Sstevel@tonic-gate 	tnf_reference_t		sched_offset, tag_disp;
107*0Sstevel@tonic-gate 	tnf_block_header_t	*block;
108*0Sstevel@tonic-gate 	tnf_uint32_t		shift;
109*0Sstevel@tonic-gate 	probe_event_prototype_t *buffer;
110*0Sstevel@tonic-gate 	hrtime_t 		curr_time, time_diff;
111*0Sstevel@tonic-gate 	tnf_schedule_t		*sched;
112*0Sstevel@tonic-gate 	tnf_ref32_t		*fwd_p;
113*0Sstevel@tonic-gate 	ulong_t			size, asize;
114*0Sstevel@tonic-gate #if defined(DEBUG) || defined(VERYVERBOSE)
115*0Sstevel@tonic-gate 	char tmp_buf[512];
116*0Sstevel@tonic-gate #endif
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 	ASSERT(ops != NULL);
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 	/* check if already in a probe */
121*0Sstevel@tonic-gate 	if (ops->busy)
122*0Sstevel@tonic-gate 		return (NULL);
123*0Sstevel@tonic-gate 	ops->busy = 1;
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate #ifdef VERYVERBOSE
127*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc: begin\n");
128*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
129*0Sstevel@tonic-gate #endif
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	/*
132*0Sstevel@tonic-gate 	 * CAUTION: Ordering of function calls in this file is critical because
133*0Sstevel@tonic-gate 	 * we call TNFW_B_GIVEBACK. Between the time we allocate space for the
134*0Sstevel@tonic-gate 	 * event and call TNFW_B_GIVEBACK there can be no other allocations!!
135*0Sstevel@tonic-gate 	 */
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 	/*
138*0Sstevel@tonic-gate 	 * Write probe tag if needed
139*0Sstevel@tonic-gate 	 */
140*0Sstevel@tonic-gate 	probe_index = probe_p->index;
141*0Sstevel@tonic-gate #ifdef VERYVERBOSE
142*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc: (1) probe_index=%p\n", probe_index);
143*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
144*0Sstevel@tonic-gate #endif
145*0Sstevel@tonic-gate 	if (probe_index == 0) {
146*0Sstevel@tonic-gate 	    if ((probe_index = tnf_probe_tag(ops, probe_p)) == 0) {
147*0Sstevel@tonic-gate #ifdef VERYVERBOSE
148*0Sstevel@tonic-gate 	    sprintf(tmp_buf, "tnf_trace_alloc: (2) probe_index=%p\n",
149*0Sstevel@tonic-gate 		    probe_index);
150*0Sstevel@tonic-gate 	    (void) write(2, tmp_buf, strlen(tmp_buf));
151*0Sstevel@tonic-gate 	    sprintf(tmp_buf, "tnf_trace_alloc: goto null_ret\n");
152*0Sstevel@tonic-gate 	    (void) write(2, tmp_buf, strlen(tmp_buf));
153*0Sstevel@tonic-gate 	    fflush(stderr);
154*0Sstevel@tonic-gate 	    sleep(2);
155*0Sstevel@tonic-gate #endif
156*0Sstevel@tonic-gate 	    goto null_ret;
157*0Sstevel@tonic-gate 	    }
158*0Sstevel@tonic-gate #ifdef VERYVERBOSE
159*0Sstevel@tonic-gate 	    sprintf(tmp_buf, "tnf_trace_alloc: (3) probe_index=%p\n",
160*0Sstevel@tonic-gate 		probe_index);
161*0Sstevel@tonic-gate 	    (void) write(2, tmp_buf, strlen(tmp_buf));
162*0Sstevel@tonic-gate 	    fflush(stderr);
163*0Sstevel@tonic-gate #endif
164*0Sstevel@tonic-gate 	}
165*0Sstevel@tonic-gate 	/*
166*0Sstevel@tonic-gate 	 * Determine how much memory is required
167*0Sstevel@tonic-gate 	 */
168*0Sstevel@tonic-gate 	size = probe_p->tnf_event_size;
169*0Sstevel@tonic-gate 	asize = size + sizeof (tnf_ref32_t);	/* one fwd ptr */
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate 	if (PROBE_IS_FILE_PTR(probe_index)) {
172*0Sstevel@tonic-gate 		/* common case - probe_index is a file ptr */
173*0Sstevel@tonic-gate 		tag_disp = probe_index & PROBE_INDEX_LOW_MASK;
174*0Sstevel@tonic-gate 	} else {
175*0Sstevel@tonic-gate 		/* rare case -- get an extra fwd ptr */
176*0Sstevel@tonic-gate 		asize += sizeof (tnf_ref32_t);
177*0Sstevel@tonic-gate 	}
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 	/*
180*0Sstevel@tonic-gate 	 * Allocate memory
181*0Sstevel@tonic-gate 	 */
182*0Sstevel@tonic-gate 	wcb = &(ops->wcb);
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
185*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc, wcb=%p\n", wcb);
186*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
187*0Sstevel@tonic-gate #endif
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 	buffer = ops->alloc(wcb, asize, ops->mode);
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
192*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc, buffer=%p\n", buffer);
193*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
194*0Sstevel@tonic-gate #endif
195*0Sstevel@tonic-gate 	if (buffer == NULL)
196*0Sstevel@tonic-gate 		goto null_ret;
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate 	/* LINTED pointer cast may result in improper alignment */
199*0Sstevel@tonic-gate 	fwd_p = (tnf_ref32_t *) ((char *)(buffer) + size);
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
202*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc, fwd_pr=%p\n", fwd_p);
203*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
204*0Sstevel@tonic-gate #endif
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	/* set file_start after calling alloc because it allocs the file */
207*0Sstevel@tonic-gate 	file_start = _tnfw_b_control->tnf_buffer;
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	/* Check if the probe tag needs more work */
210*0Sstevel@tonic-gate 	if (!PROBE_IS_FILE_PTR(probe_index)) {
211*0Sstevel@tonic-gate 		/* LINTED use up first fwd ptr */
212*0Sstevel@tonic-gate 		*fwd_p = TNF_REF32_MAKE_PERMANENT(
213*0Sstevel@tonic-gate 		/* LINTED ptr subtraction */
214*0Sstevel@tonic-gate 			(tnf_record_p)probe_index - (tnf_record_p) file_start);
215*0Sstevel@tonic-gate 		/* LINTED ptr subtraction */
216*0Sstevel@tonic-gate 		tag_disp = PTR_DIFF(fwd_p, buffer);
217*0Sstevel@tonic-gate 		ASSERT(TAGARG_CHECK(tag_disp));
218*0Sstevel@tonic-gate 		tag_disp |= TNF_TAG16_T_REL;
219*0Sstevel@tonic-gate 		tag_disp = tag_disp << TNF_REF32_TAG16_SHIFT;
220*0Sstevel@tonic-gate 		fwd_p++;
221*0Sstevel@tonic-gate 	}
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate 	/*
224*0Sstevel@tonic-gate 	 * Get timestamp
225*0Sstevel@tonic-gate 	 */
226*0Sstevel@tonic-gate 	curr_time = gethrtime();
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 	/*
229*0Sstevel@tonic-gate 	 * initialize and write schedule record if needed
230*0Sstevel@tonic-gate 	 * watch out for sched->record_p - it has to be checked after alloc is
231*0Sstevel@tonic-gate 	 * called for the event, because it could be side effected by alloc
232*0Sstevel@tonic-gate 	 * if a fork happened.  Pre-requisite to our algorithm - if a fork
233*0Sstevel@tonic-gate 	 * happens all other threads have to be quiescent i.e. not in a probe.
234*0Sstevel@tonic-gate 	 */
235*0Sstevel@tonic-gate 	sched = &(ops->schedule);
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
238*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc, sched=%p\n", sched);
239*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
240*0Sstevel@tonic-gate #endif
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	/* LINTED pointer cast */
243*0Sstevel@tonic-gate 	shift = ((tnf_buf_file_header_t *)file_start)->com.file_log_size;
244*0Sstevel@tonic-gate 	block = (tnf_block_header_t *)((ulong_t)buffer & TNF_BLOCK_MASK);
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	if ((sched_record_p = sched->record_p) == NULL ||
247*0Sstevel@tonic-gate 	    IS_NEWBLOCK(block, buffer)) {
248*0Sstevel@tonic-gate 		/* No record written yet */
249*0Sstevel@tonic-gate 		goto new_schedule;
250*0Sstevel@tonic-gate 	}
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate 	/*
253*0Sstevel@tonic-gate 	 * Note: Don't bother about space bit here, because we'll
254*0Sstevel@tonic-gate 	 * only use bits 15:2 anyway
255*0Sstevel@tonic-gate 	 */
256*0Sstevel@tonic-gate 	sched_offset = ((sched->record_gen - block->generation) << shift) +
257*0Sstevel@tonic-gate 		/* LINTED - ptr subtraction */
258*0Sstevel@tonic-gate 		(uint_t) (sched_record_p - (caddr_t)buffer);
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate 	if (!TAGARG_CHECK(sched_offset))
261*0Sstevel@tonic-gate 		/* Record too far away to reference */
262*0Sstevel@tonic-gate 		goto new_schedule;
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	time_diff = curr_time - sched->time_base;
265*0Sstevel@tonic-gate 	if (!TIME_CHECK(time_diff))
266*0Sstevel@tonic-gate 		/* Time delta can't fit in 32 bits */
267*0Sstevel@tonic-gate 		goto new_schedule;
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 	/*
270*0Sstevel@tonic-gate 	 * Can reuse existing schedule record
271*0Sstevel@tonic-gate 	 * Since we did not allocate any more space, can giveback
272*0Sstevel@tonic-gate 	 */
273*0Sstevel@tonic-gate 	/* LINTED - GIVEBACK returns a pointer subtraction */
274*0Sstevel@tonic-gate 	TNFW_B_GIVEBACK(wcb, fwd_p);
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate good_ret:
277*0Sstevel@tonic-gate 	/*
278*0Sstevel@tonic-gate 	 * Store return params and two common event members, return buffer
279*0Sstevel@tonic-gate 	 */
280*0Sstevel@tonic-gate 	set_p->tpd_p = ops;
281*0Sstevel@tonic-gate 	set_p->buffer_p = buffer;
282*0Sstevel@tonic-gate 	set_p->probe_p = probe_p;
283*0Sstevel@tonic-gate 	buffer->probe_event = ENCODED_TAG(tag_disp, sched_offset);
284*0Sstevel@tonic-gate 	/* LINTED - TIME_CHECK already passed, see above */
285*0Sstevel@tonic-gate 	buffer->time_delta = tnf_time_delta(ops, (unsigned long)time_diff,
286*0Sstevel@tonic-gate 	    &buffer->probe_time_delta);
287*0Sstevel@tonic-gate 	return (buffer);
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate new_schedule:
290*0Sstevel@tonic-gate 	/*
291*0Sstevel@tonic-gate 	 * Write a new schedule record for this thread
292*0Sstevel@tonic-gate 	 */
293*0Sstevel@tonic-gate #ifdef VERYVERBOSE
294*0Sstevel@tonic-gate 	sprintf(tmp_buf, "	tnf_trace_alloc: initializing "
295*0Sstevel@tonic-gate 				"new schedule record\n");
296*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
297*0Sstevel@tonic-gate #endif
298*0Sstevel@tonic-gate 	_tnf_sched_init(sched, curr_time);
299*0Sstevel@tonic-gate 	time_diff = 0;
300*0Sstevel@tonic-gate 	if ((sched_record_p = tnf_schedule_write(ops, sched)) != NULL) {
301*0Sstevel@tonic-gate 		/* use one of the extra alloced words for the forwarding ptr */
302*0Sstevel@tonic-gate 		/* LINTED - ptr subtraction */
303*0Sstevel@tonic-gate 		*fwd_p = TNF_REF32_MAKE_RECLAIMABLE(
304*0Sstevel@tonic-gate 			((sched->record_gen - block->generation) << shift) +
305*0Sstevel@tonic-gate 			(sched_record_p - (tnf_record_p)fwd_p));
306*0Sstevel@tonic-gate 		/* LINTED - ptr subtraction */
307*0Sstevel@tonic-gate 		sched_offset = PTR_DIFF(fwd_p, buffer);
308*0Sstevel@tonic-gate 		ASSERT(TAGARG_CHECK(sched_offset));
309*0Sstevel@tonic-gate 	} else {
310*0Sstevel@tonic-gate 		/* Allocation failed (tracing may have been stopped) */
311*0Sstevel@tonic-gate 		sched_offset = 0;
312*0Sstevel@tonic-gate 		*fwd_p = TNF_NULL;
313*0Sstevel@tonic-gate 	}
314*0Sstevel@tonic-gate 	goto good_ret;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate null_ret:
317*0Sstevel@tonic-gate 	/*
318*0Sstevel@tonic-gate 	 * reset re-entrancy protector, because tnf_trace_end() will
319*0Sstevel@tonic-gate 	 * not be called
320*0Sstevel@tonic-gate 	 */
321*0Sstevel@tonic-gate #ifdef VERYVERBOSE
322*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_alloc: null return\n");
323*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
324*0Sstevel@tonic-gate #endif
325*0Sstevel@tonic-gate 	ops->busy = 0;
326*0Sstevel@tonic-gate 	return (NULL);
327*0Sstevel@tonic-gate }
328*0Sstevel@tonic-gate 
329*0Sstevel@tonic-gate /*
330*0Sstevel@tonic-gate  * tnf_trace_end
331*0Sstevel@tonic-gate  *	the last (usually only) function in the list of probe functions
332*0Sstevel@tonic-gate  */
333*0Sstevel@tonic-gate void
tnf_trace_end(tnf_probe_setup_t * set_p)334*0Sstevel@tonic-gate tnf_trace_end(tnf_probe_setup_t *set_p)
335*0Sstevel@tonic-gate {
336*0Sstevel@tonic-gate #ifdef VERYVERBOSE
337*0Sstevel@tonic-gate 	char tmp_buf[512];
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_end: \n");
340*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
341*0Sstevel@tonic-gate #endif
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate 	(set_p->probe_p->commit_func)(set_p);
344*0Sstevel@tonic-gate 	set_p->tpd_p->busy = 0;
345*0Sstevel@tonic-gate }
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate /*
348*0Sstevel@tonic-gate  * tnf_trace_commit
349*0Sstevel@tonic-gate  *	a probe commit function that really commits trace data
350*0Sstevel@tonic-gate  */
351*0Sstevel@tonic-gate void
tnf_trace_commit(tnf_probe_setup_t * set_p)352*0Sstevel@tonic-gate tnf_trace_commit(tnf_probe_setup_t *set_p)
353*0Sstevel@tonic-gate {
354*0Sstevel@tonic-gate #ifdef VERYVERBOSE
355*0Sstevel@tonic-gate 	char tmp_buf[512];
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_commit: \n\n");
358*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
359*0Sstevel@tonic-gate #endif
360*0Sstevel@tonic-gate 	(void) set_p->tpd_p->commit(&(set_p->tpd_p->wcb));
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 	return;
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate }
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate /*
367*0Sstevel@tonic-gate  * tnf_trace_rollback
368*0Sstevel@tonic-gate  *	a probe commit function that unrolls trace data
369*0Sstevel@tonic-gate  */
370*0Sstevel@tonic-gate void
tnf_trace_rollback(tnf_probe_setup_t * set_p)371*0Sstevel@tonic-gate tnf_trace_rollback(tnf_probe_setup_t *set_p)
372*0Sstevel@tonic-gate {
373*0Sstevel@tonic-gate #ifdef VERYVERBOSE
374*0Sstevel@tonic-gate 	char tmp_buf[512];
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_trace_rollback: \n\n");
377*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
378*0Sstevel@tonic-gate #endif
379*0Sstevel@tonic-gate 	(void) set_p->tpd_p->rollback(&(set_p->tpd_p->wcb));
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 	return;
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate }
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate /*
386*0Sstevel@tonic-gate  * tnf_allocate
387*0Sstevel@tonic-gate  *	exported interface for allocating trace memory
388*0Sstevel@tonic-gate  */
389*0Sstevel@tonic-gate 
390*0Sstevel@tonic-gate void *
tnf_allocate(tnf_ops_t * ops,size_t size)391*0Sstevel@tonic-gate tnf_allocate(tnf_ops_t *ops, size_t size)
392*0Sstevel@tonic-gate {
393*0Sstevel@tonic-gate 	void *retval;
394*0Sstevel@tonic-gate 	char tmp_buf[512];
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
397*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_allocate\n");
398*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
399*0Sstevel@tonic-gate #endif
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate 	retval = ops->alloc(&(ops->wcb), size, ops->mode);
402*0Sstevel@tonic-gate 
403*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
404*0Sstevel@tonic-gate 	sprintf(tmp_buf, "tnf_allocate, retval=%p\n", retval);
405*0Sstevel@tonic-gate 	(void) write(2, tmp_buf, strlen(tmp_buf));
406*0Sstevel@tonic-gate #endif
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate 	return (retval);
409*0Sstevel@tonic-gate }
410