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