1 /* 2 * Copyright (c) 2016, Linaro Limited 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * This file is adapted from glibc' gmon/sys/gmon.h. 30 *- 31 * Copyright (c) 1982, 1986, 1992, 1993 32 * The Regents of the University of California. All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 4. Neither the name of the University nor the names of its contributors 43 * may be used to endorse or promote products derived from this software 44 * without specific prior written permission. 45 * 46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * SUCH DAMAGE. 57 */ 58 59 /* 60 * See gmon_out.h for gmon.out format. 61 */ 62 63 #ifndef GMON_H 64 #define GMON_H 65 66 #include <stdint.h> 67 68 /* Exported by the TA linker script */ 69 extern uint8_t __text_start[]; 70 extern uint8_t __text_end[]; 71 72 void __mcount_internal(unsigned long frompc, unsigned long selfpc); 73 74 75 /* 76 * Histogram counters are unsigned shorts (according to the kernel). 77 */ 78 #define HISTCOUNTER unsigned short 79 80 /* 81 * Fraction of text space to allocate for histogram counters here, 1/2 82 */ 83 #define HISTFRACTION 2 84 85 /* 86 * Fraction of text space to allocate for from hash buckets. 87 * The value of HASHFRACTION is based on the minimum number of bytes 88 * of separation between two subroutine call points in the object code. 89 * Given MIN_SUBR_SEPARATION bytes of separation the value of 90 * HASHFRACTION is calculated as: 91 * 92 * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); 93 * 94 * For example, on the VAX, the shortest two call sequence is: 95 * 96 * calls $0,(r0) 97 * calls $0,(r0) 98 * 99 * which is separated by only three bytes, thus HASHFRACTION is 100 * calculated as: 101 * 102 * HASHFRACTION = 3 / (2 * 2 - 1) = 1 103 * 104 * Note that the division above rounds down, thus if MIN_SUBR_FRACTION 105 * is less than three, this algorithm will not work! 106 * 107 * In practice, however, call instructions are rarely at a minimal 108 * distance. Hence, we will define HASHFRACTION to be 2 across all 109 * architectures. This saves a reasonable amount of space for 110 * profiling data structures without (in practice) sacrificing 111 * any granularity. 112 */ 113 #define HASHFRACTION 2 114 115 /* 116 * Percent of text space to allocate for tostructs. 117 * This is a heuristic; we will fail with a warning when profiling programs 118 * with a very large number of very small functions, but that's 119 * normally OK. 120 * 2 is probably still a good value for normal programs. 121 * Profiling a test case with 64000 small functions will work if 122 * you raise this value to 3 and link statically (which bloats the 123 * text size, thus raising the number of arcs expected by the heuristic). 124 */ 125 #define ARCDENSITY 3 126 127 /* 128 * Always allocate at least this many tostructs. This 129 * hides the inadequacy of the ARCDENSITY heuristic, at least 130 * for small programs. 131 */ 132 #define MINARCS 50 133 134 /* 135 * The type used to represent indices into gmonparam.tos[]. 136 */ 137 #define ARCINDEX unsigned long 138 139 /* 140 * Maximum number of arcs we want to allow. 141 * Used to be max representable value of ARCINDEX minus 2, but now 142 * that ARCINDEX is a long, that's too large; we don't really want 143 * to allow a 48 gigabyte table. 144 * The old value of 1<<16 wasn't high enough in practice for large C++ 145 * programs; will 1<<20 be adequate for long? FIXME 146 */ 147 #define MAXARCS (1 << 20) 148 149 struct tostruct { 150 unsigned long selfpc; 151 long count; 152 ARCINDEX link; 153 }; 154 155 /* 156 * A raw arc, with pointers to the calling site and the called site and a 157 * count. 158 */ 159 struct rawarc { 160 unsigned long raw_frompc; 161 unsigned long raw_selfpc; 162 long raw_count; 163 }; 164 165 /* 166 * General rounding functions. 167 */ 168 #define ROUNDDOWN(x, y) (((x)/(y))*(y)) 169 #define ROUNDUP(x, y) ((((x)+(y)-1)/(y))*(y)) 170 171 /* 172 * The profiling data structures are housed in this structure. 173 */ 174 struct gmonparam { 175 long int state; 176 unsigned short *kcount; 177 unsigned long kcountsize; 178 ARCINDEX *froms; 179 unsigned long fromssize; 180 struct tostruct *tos; 181 unsigned long tossize; 182 unsigned long tolimit; 183 unsigned long lowpc; 184 unsigned long highpc; 185 unsigned long textsize; 186 unsigned long hashfraction; 187 long log_hashfraction; 188 /* */ 189 uint32_t prof_rate; /* PC sampling frequency */ 190 }; 191 192 /* 193 * Possible states of profiling. 194 */ 195 #define GMON_PROF_ON 0 196 #define GMON_PROF_BUSY 1 197 #define GMON_PROF_ERROR 2 198 #define GMON_PROF_OFF 3 199 #define GMON_PROF_OFF_EXITING 4 200 201 #endif /* GMON_H */ 202