profile.h revision 129198
1129198Scognet/*
2129198Scognet * Copyright (c) 1992, 1993
3129198Scognet *	The Regents of the University of California.  All rights reserved.
4129198Scognet *
5129198Scognet * Redistribution and use in source and binary forms, with or without
6129198Scognet * modification, are permitted provided that the following conditions
7129198Scognet * are met:
8129198Scognet * 1. Redistributions of source code must retain the above copyright
9129198Scognet *    notice, this list of conditions and the following disclaimer.
10129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
11129198Scognet *    notice, this list of conditions and the following disclaimer in the
12129198Scognet *    documentation and/or other materials provided with the distribution.
13129198Scognet * 3. All advertising materials mentioning features or use of this software
14129198Scognet *    must display the following acknowledgement:
15129198Scognet *	This product includes software developed by the University of
16129198Scognet *	California, Berkeley and its contributors.
17129198Scognet * 4. Neither the name of the University nor the names of its contributors
18129198Scognet *    may be used to endorse or promote products derived from this software
19129198Scognet *    without specific prior written permission.
20129198Scognet *
21129198Scognet * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22129198Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23129198Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24129198Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25129198Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26129198Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27129198Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31129198Scognet * SUCH DAMAGE.
32129198Scognet *
33129198Scognet *	@(#)profile.h	8.1 (Berkeley) 6/11/93
34129198Scognet * $FreeBSD: head/sys/arm/include/profile.h 129198 2004-05-14 11:46:45Z cognet $
35129198Scognet */
36129198Scognet
37129198Scognet#ifndef _MACHINE_PROFILE_H_
38129198Scognet#define	_MACHINE_PROFILE_H_
39129198Scognet
40129198Scognet#ifdef _KERNEL
41129198Scognet
42129198Scognet/*
43129198Scognet * Config generates something to tell the compiler to align functions on 16
44129198Scognet * byte boundaries.  A strict alignment is good for keeping the tables small.
45129198Scognet */
46129198Scognet#define	FUNCTION_ALIGNMENT	16
47129198Scognet
48129198Scognet/*
49129198Scognet * The kernel uses assembler stubs instead of unportable inlines.
50129198Scognet * This is mainly to save a little time when profiling is not enabled,
51129198Scognet * which is the usual case for the kernel.
52129198Scognet */
53129198Scognet#define	_MCOUNT_DECL void mcount
54129198Scognet#define	MCOUNT
55129198Scognet
56129198Scognet#ifdef GUPROF
57129198Scognet#define	CALIB_SCALE	1000
58129198Scognet#define	KCOUNT(p,index)	((p)->kcount[(index) \
59129198Scognet			 / (HISTFRACTION * sizeof(HISTCOUNTER))])
60129198Scognet#define	MCOUNT_DECL(s)
61129198Scognet#define	MCOUNT_ENTER(s)
62129198Scognet#define	MCOUNT_EXIT(s)
63129198Scognet#define	PC_TO_I(p, pc)	((uintfptr_t)(pc) - (uintfptr_t)(p)->lowpc)
64129198Scognet#else
65129198Scognet#define	MCOUNT_DECL(s)	u_long s;
66129198Scognet#ifdef SMP
67129198Scognetextern int	mcount_lock;
68129198Scognet#define	MCOUNT_ENTER(s)	{ s = read_eflags(); disable_intr(); \
69129198Scognet 			  while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1)) \
70129198Scognet			  	/* nothing */ ; }
71129198Scognet#define	MCOUNT_EXIT(s)	{ atomic_store_rel_int(&mcount_lock, 0); \
72129198Scognet			  write_eflags(s); }
73129198Scognet#else
74129198Scognet#define	MCOUNT_ENTER(s)	{ s = read_eflags(); disable_intr(); }
75129198Scognet#define	MCOUNT_EXIT(s)	(write_eflags(s))
76129198Scognet#endif
77129198Scognet#endif /* GUPROF */
78129198Scognet
79129198Scognet#else /* !_KERNEL */
80129198Scognet
81129198Scognet#define	FUNCTION_ALIGNMENT	4
82129198Scognet
83129198Scognet#define	_MCOUNT_DECL static __inline void _mcount
84129198Scognet
85129198Scognet#define	MCOUNT
86129198Scognet
87129198Scognettypedef	unsigned int	uintfptr_t;
88129198Scognet
89129198Scognet#endif /* _KERNEL */
90129198Scognet
91129198Scognet/*
92129198Scognet * An unsigned integral type that can hold non-negative difference between
93129198Scognet * function pointers.
94129198Scognet */
95129198Scognettypedef	u_int	fptrdiff_t;
96129198Scognet
97129198Scognet#ifdef _KERNEL
98129198Scognet
99129198Scognetvoid	mcount(uintfptr_t frompc, uintfptr_t selfpc);
100129198Scognetvoid	kmupetext(uintfptr_t nhighpc);
101129198Scognet
102129198Scognet#ifdef GUPROF
103129198Scognetstruct gmonparam;
104129198Scognet
105129198Scognetvoid	nullfunc_loop_profiled(void);
106129198Scognetvoid	nullfunc_profiled(void);
107129198Scognetvoid	startguprof(struct gmonparam *p);
108129198Scognetvoid	stopguprof(struct gmonparam *p);
109129198Scognet#else
110129198Scognet#define	startguprof(p)
111129198Scognet#define	stopguprof(p)
112129198Scognet#endif /* GUPROF */
113129198Scognet
114129198Scognet#else /* !_KERNEL */
115129198Scognet
116129198Scognet#include <sys/cdefs.h>
117129198Scognet
118129198Scognet__BEGIN_DECLS
119129198Scognet#ifdef __GNUC__
120129198Scognetvoid	mcount(void) __asm(".mcount");
121129198Scognet#endif
122129198Scognet__END_DECLS
123129198Scognet
124129198Scognet#endif /* _KERNEL */
125129198Scognet
126129198Scognet#ifdef GUPROF
127129198Scognet/* XXX doesn't quite work outside kernel yet. */
128129198Scognetextern int	cputime_bias;
129129198Scognet
130129198Scognet__BEGIN_DECLS
131129198Scognetint	cputime(void);
132129198Scognetvoid	empty_loop(void);
133129198Scognetvoid	mexitcount(uintfptr_t selfpc);
134129198Scognetvoid	nullfunc(void);
135129198Scognetvoid	nullfunc_loop(void);
136129198Scognet__END_DECLS
137129198Scognet#endif
138129198Scognet
139129198Scognet#endif /* !_MACHINE_PROFILE_H_ */
140