xref: /optee_os/lib/libutee/arch/arm/gprof/gmon.h (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1*1bb92983SJerome Forissier /* SPDX-License-Identifier: (BSD-2-Clause AND BSD-3-Clause) */
2883c4be3SJerome Forissier /*
3883c4be3SJerome Forissier  * Copyright (c) 2016, Linaro Limited
4883c4be3SJerome Forissier  * All rights reserved.
5883c4be3SJerome Forissier  *
6883c4be3SJerome Forissier  * Redistribution and use in source and binary forms, with or without
7883c4be3SJerome Forissier  * modification, are permitted provided that the following conditions are met:
8883c4be3SJerome Forissier  *
9883c4be3SJerome Forissier  * 1. Redistributions of source code must retain the above copyright notice,
10883c4be3SJerome Forissier  * this list of conditions and the following disclaimer.
11883c4be3SJerome Forissier  *
12883c4be3SJerome Forissier  * 2. Redistributions in binary form must reproduce the above copyright notice,
13883c4be3SJerome Forissier  * this list of conditions and the following disclaimer in the documentation
14883c4be3SJerome Forissier  * and/or other materials provided with the distribution.
15883c4be3SJerome Forissier  *
16883c4be3SJerome Forissier  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17883c4be3SJerome Forissier  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18883c4be3SJerome Forissier  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19883c4be3SJerome Forissier  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20883c4be3SJerome Forissier  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21883c4be3SJerome Forissier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22883c4be3SJerome Forissier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23883c4be3SJerome Forissier  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24883c4be3SJerome Forissier  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25883c4be3SJerome Forissier  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26883c4be3SJerome Forissier  * POSSIBILITY OF SUCH DAMAGE.
27883c4be3SJerome Forissier  */
28883c4be3SJerome Forissier 
29883c4be3SJerome Forissier /*
30883c4be3SJerome Forissier  * This file is adapted from glibc' gmon/sys/gmon.h.
31883c4be3SJerome Forissier  *-
32883c4be3SJerome Forissier  * Copyright (c) 1982, 1986, 1992, 1993
33883c4be3SJerome Forissier  *	The Regents of the University of California.  All rights reserved.
34883c4be3SJerome Forissier  *
35883c4be3SJerome Forissier  * Redistribution and use in source and binary forms, with or without
36883c4be3SJerome Forissier  * modification, are permitted provided that the following conditions
37883c4be3SJerome Forissier  * are met:
38883c4be3SJerome Forissier  * 1. Redistributions of source code must retain the above copyright
39883c4be3SJerome Forissier  *    notice, this list of conditions and the following disclaimer.
40883c4be3SJerome Forissier  * 2. Redistributions in binary form must reproduce the above copyright
41883c4be3SJerome Forissier  *    notice, this list of conditions and the following disclaimer in the
42883c4be3SJerome Forissier  *    documentation and/or other materials provided with the distribution.
43883c4be3SJerome Forissier  * 4. Neither the name of the University nor the names of its contributors
44883c4be3SJerome Forissier  *    may be used to endorse or promote products derived from this software
45883c4be3SJerome Forissier  *    without specific prior written permission.
46883c4be3SJerome Forissier  *
47883c4be3SJerome Forissier  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48883c4be3SJerome Forissier  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49883c4be3SJerome Forissier  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50883c4be3SJerome Forissier  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51883c4be3SJerome Forissier  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52883c4be3SJerome Forissier  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53883c4be3SJerome Forissier  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54883c4be3SJerome Forissier  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55883c4be3SJerome Forissier  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56883c4be3SJerome Forissier  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57883c4be3SJerome Forissier  * SUCH DAMAGE.
58883c4be3SJerome Forissier  */
59883c4be3SJerome Forissier 
60883c4be3SJerome Forissier /*
61883c4be3SJerome Forissier  * See gmon_out.h for gmon.out format.
62883c4be3SJerome Forissier  */
63883c4be3SJerome Forissier 
64883c4be3SJerome Forissier #ifndef GMON_H
65883c4be3SJerome Forissier #define GMON_H
66883c4be3SJerome Forissier 
67883c4be3SJerome Forissier #include <stdint.h>
68883c4be3SJerome Forissier 
69883c4be3SJerome Forissier /* Exported by the TA linker script */
70883c4be3SJerome Forissier extern uint8_t __text_start[];
71883c4be3SJerome Forissier extern uint8_t __text_end[];
72883c4be3SJerome Forissier 
73883c4be3SJerome Forissier void __mcount_internal(unsigned long frompc, unsigned long selfpc);
74883c4be3SJerome Forissier 
75883c4be3SJerome Forissier 
76883c4be3SJerome Forissier /*
77883c4be3SJerome Forissier  * Histogram counters are unsigned shorts (according to the kernel).
78883c4be3SJerome Forissier  */
79883c4be3SJerome Forissier #define	HISTCOUNTER	unsigned short
80883c4be3SJerome Forissier 
81883c4be3SJerome Forissier /*
82883c4be3SJerome Forissier  * Fraction of text space to allocate for histogram counters here, 1/2
83883c4be3SJerome Forissier  */
84883c4be3SJerome Forissier #define	HISTFRACTION	2
85883c4be3SJerome Forissier 
86883c4be3SJerome Forissier /*
87883c4be3SJerome Forissier  * Fraction of text space to allocate for from hash buckets.
88883c4be3SJerome Forissier  * The value of HASHFRACTION is based on the minimum number of bytes
89883c4be3SJerome Forissier  * of separation between two subroutine call points in the object code.
90883c4be3SJerome Forissier  * Given MIN_SUBR_SEPARATION bytes of separation the value of
91883c4be3SJerome Forissier  * HASHFRACTION is calculated as:
92883c4be3SJerome Forissier  *
93883c4be3SJerome Forissier  *	HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
94883c4be3SJerome Forissier  *
95883c4be3SJerome Forissier  * For example, on the VAX, the shortest two call sequence is:
96883c4be3SJerome Forissier  *
97883c4be3SJerome Forissier  *	calls	$0,(r0)
98883c4be3SJerome Forissier  *	calls	$0,(r0)
99883c4be3SJerome Forissier  *
100883c4be3SJerome Forissier  * which is separated by only three bytes, thus HASHFRACTION is
101883c4be3SJerome Forissier  * calculated as:
102883c4be3SJerome Forissier  *
103883c4be3SJerome Forissier  *	HASHFRACTION = 3 / (2 * 2 - 1) = 1
104883c4be3SJerome Forissier  *
105883c4be3SJerome Forissier  * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
106883c4be3SJerome Forissier  * is less than three, this algorithm will not work!
107883c4be3SJerome Forissier  *
108883c4be3SJerome Forissier  * In practice, however, call instructions are rarely at a minimal
109883c4be3SJerome Forissier  * distance.  Hence, we will define HASHFRACTION to be 2 across all
110883c4be3SJerome Forissier  * architectures.  This saves a reasonable amount of space for
111883c4be3SJerome Forissier  * profiling data structures without (in practice) sacrificing
112883c4be3SJerome Forissier  * any granularity.
113883c4be3SJerome Forissier  */
114883c4be3SJerome Forissier #define	HASHFRACTION	2
115883c4be3SJerome Forissier 
116883c4be3SJerome Forissier /*
117883c4be3SJerome Forissier  * Percent of text space to allocate for tostructs.
118883c4be3SJerome Forissier  * This is a heuristic; we will fail with a warning when profiling programs
119883c4be3SJerome Forissier  * with a very large number of very small functions, but that's
120883c4be3SJerome Forissier  * normally OK.
121883c4be3SJerome Forissier  * 2 is probably still a good value for normal programs.
122883c4be3SJerome Forissier  * Profiling a test case with 64000 small functions will work if
123883c4be3SJerome Forissier  * you raise this value to 3 and link statically (which bloats the
124883c4be3SJerome Forissier  * text size, thus raising the number of arcs expected by the heuristic).
125883c4be3SJerome Forissier  */
126883c4be3SJerome Forissier #define ARCDENSITY	3
127883c4be3SJerome Forissier 
128883c4be3SJerome Forissier /*
129883c4be3SJerome Forissier  * Always allocate at least this many tostructs.  This
130883c4be3SJerome Forissier  * hides the inadequacy of the ARCDENSITY heuristic, at least
131883c4be3SJerome Forissier  * for small programs.
132883c4be3SJerome Forissier  */
133883c4be3SJerome Forissier #define MINARCS		50
134883c4be3SJerome Forissier 
135883c4be3SJerome Forissier /*
136883c4be3SJerome Forissier  * The type used to represent indices into gmonparam.tos[].
137883c4be3SJerome Forissier  */
138883c4be3SJerome Forissier #define	ARCINDEX	unsigned long
139883c4be3SJerome Forissier 
140883c4be3SJerome Forissier /*
141883c4be3SJerome Forissier  * Maximum number of arcs we want to allow.
142883c4be3SJerome Forissier  * Used to be max representable value of ARCINDEX minus 2, but now
143883c4be3SJerome Forissier  * that ARCINDEX is a long, that's too large; we don't really want
144883c4be3SJerome Forissier  * to allow a 48 gigabyte table.
145883c4be3SJerome Forissier  * The old value of 1<<16 wasn't high enough in practice for large C++
146883c4be3SJerome Forissier  * programs; will 1<<20 be adequate for long?  FIXME
147883c4be3SJerome Forissier  */
148883c4be3SJerome Forissier #define MAXARCS		(1 << 20)
149883c4be3SJerome Forissier 
150883c4be3SJerome Forissier struct tostruct {
151883c4be3SJerome Forissier 	unsigned long selfpc;
152883c4be3SJerome Forissier 	long count;
153883c4be3SJerome Forissier 	ARCINDEX link;
154883c4be3SJerome Forissier };
155883c4be3SJerome Forissier 
156883c4be3SJerome Forissier /*
157883c4be3SJerome Forissier  * A raw arc, with pointers to the calling site and the called site and a
158883c4be3SJerome Forissier  * count.
159883c4be3SJerome Forissier  */
160883c4be3SJerome Forissier struct rawarc {
161883c4be3SJerome Forissier 	unsigned long	raw_frompc;
162883c4be3SJerome Forissier 	unsigned long	raw_selfpc;
163883c4be3SJerome Forissier 	long		raw_count;
164883c4be3SJerome Forissier };
165883c4be3SJerome Forissier 
166883c4be3SJerome Forissier /*
167883c4be3SJerome Forissier  * General rounding functions.
168883c4be3SJerome Forissier  */
169883c4be3SJerome Forissier #define ROUNDDOWN(x, y)	(((x)/(y))*(y))
170883c4be3SJerome Forissier #define ROUNDUP(x, y)	((((x)+(y)-1)/(y))*(y))
171883c4be3SJerome Forissier 
172883c4be3SJerome Forissier /*
173883c4be3SJerome Forissier  * The profiling data structures are housed in this structure.
174883c4be3SJerome Forissier  */
175883c4be3SJerome Forissier struct gmonparam {
176883c4be3SJerome Forissier 	long int	state;
177883c4be3SJerome Forissier 	unsigned short	*kcount;
178883c4be3SJerome Forissier 	unsigned long	kcountsize;
179883c4be3SJerome Forissier 	ARCINDEX	*froms;
180883c4be3SJerome Forissier 	unsigned long	fromssize;
181883c4be3SJerome Forissier 	struct tostruct	*tos;
182883c4be3SJerome Forissier 	unsigned long	tossize;
183883c4be3SJerome Forissier 	unsigned long	tolimit;
184883c4be3SJerome Forissier 	unsigned long	lowpc;
185883c4be3SJerome Forissier 	unsigned long	highpc;
186883c4be3SJerome Forissier 	unsigned long	textsize;
187883c4be3SJerome Forissier 	unsigned long	hashfraction;
188883c4be3SJerome Forissier 	long		log_hashfraction;
189883c4be3SJerome Forissier 	/* */
190883c4be3SJerome Forissier 	uint32_t	prof_rate; /* PC sampling frequency */
191883c4be3SJerome Forissier };
192883c4be3SJerome Forissier 
193883c4be3SJerome Forissier /*
194883c4be3SJerome Forissier  * Possible states of profiling.
195883c4be3SJerome Forissier  */
196883c4be3SJerome Forissier #define	GMON_PROF_ON		0
197883c4be3SJerome Forissier #define	GMON_PROF_BUSY		1
198883c4be3SJerome Forissier #define	GMON_PROF_ERROR		2
199883c4be3SJerome Forissier #define	GMON_PROF_OFF		3
200883c4be3SJerome Forissier #define	GMON_PROF_OFF_EXITING	4
201883c4be3SJerome Forissier 
202883c4be3SJerome Forissier #endif /* GMON_H */
203