11bb92983SJerome 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> 68*387b0ee3SEtienne Carriere #include <util.h> 69883c4be3SJerome Forissier 70883c4be3SJerome Forissier /* Exported by the TA linker script */ 71883c4be3SJerome Forissier extern uint8_t __text_start[]; 72883c4be3SJerome Forissier extern uint8_t __text_end[]; 73883c4be3SJerome Forissier 74883c4be3SJerome Forissier void __mcount_internal(unsigned long frompc, unsigned long selfpc); 75883c4be3SJerome Forissier 76883c4be3SJerome Forissier 77883c4be3SJerome Forissier /* 78883c4be3SJerome Forissier * Histogram counters are unsigned shorts (according to the kernel). 79883c4be3SJerome Forissier */ 80883c4be3SJerome Forissier #define HISTCOUNTER unsigned short 81883c4be3SJerome Forissier 82883c4be3SJerome Forissier /* 83883c4be3SJerome Forissier * Fraction of text space to allocate for histogram counters here, 1/2 84883c4be3SJerome Forissier */ 85883c4be3SJerome Forissier #define HISTFRACTION 2 86883c4be3SJerome Forissier 87883c4be3SJerome Forissier /* 88883c4be3SJerome Forissier * Fraction of text space to allocate for from hash buckets. 89883c4be3SJerome Forissier * The value of HASHFRACTION is based on the minimum number of bytes 90883c4be3SJerome Forissier * of separation between two subroutine call points in the object code. 91883c4be3SJerome Forissier * Given MIN_SUBR_SEPARATION bytes of separation the value of 92883c4be3SJerome Forissier * HASHFRACTION is calculated as: 93883c4be3SJerome Forissier * 94883c4be3SJerome Forissier * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); 95883c4be3SJerome Forissier * 96883c4be3SJerome Forissier * For example, on the VAX, the shortest two call sequence is: 97883c4be3SJerome Forissier * 98883c4be3SJerome Forissier * calls $0,(r0) 99883c4be3SJerome Forissier * calls $0,(r0) 100883c4be3SJerome Forissier * 101883c4be3SJerome Forissier * which is separated by only three bytes, thus HASHFRACTION is 102883c4be3SJerome Forissier * calculated as: 103883c4be3SJerome Forissier * 104883c4be3SJerome Forissier * HASHFRACTION = 3 / (2 * 2 - 1) = 1 105883c4be3SJerome Forissier * 106883c4be3SJerome Forissier * Note that the division above rounds down, thus if MIN_SUBR_FRACTION 107883c4be3SJerome Forissier * is less than three, this algorithm will not work! 108883c4be3SJerome Forissier * 109883c4be3SJerome Forissier * In practice, however, call instructions are rarely at a minimal 110883c4be3SJerome Forissier * distance. Hence, we will define HASHFRACTION to be 2 across all 111883c4be3SJerome Forissier * architectures. This saves a reasonable amount of space for 112883c4be3SJerome Forissier * profiling data structures without (in practice) sacrificing 113883c4be3SJerome Forissier * any granularity. 114883c4be3SJerome Forissier */ 115883c4be3SJerome Forissier #define HASHFRACTION 2 116883c4be3SJerome Forissier 117883c4be3SJerome Forissier /* 118883c4be3SJerome Forissier * Percent of text space to allocate for tostructs. 119883c4be3SJerome Forissier * This is a heuristic; we will fail with a warning when profiling programs 120883c4be3SJerome Forissier * with a very large number of very small functions, but that's 121883c4be3SJerome Forissier * normally OK. 122883c4be3SJerome Forissier * 2 is probably still a good value for normal programs. 123883c4be3SJerome Forissier * Profiling a test case with 64000 small functions will work if 124883c4be3SJerome Forissier * you raise this value to 3 and link statically (which bloats the 125883c4be3SJerome Forissier * text size, thus raising the number of arcs expected by the heuristic). 126883c4be3SJerome Forissier */ 127883c4be3SJerome Forissier #define ARCDENSITY 3 128883c4be3SJerome Forissier 129883c4be3SJerome Forissier /* 130883c4be3SJerome Forissier * Always allocate at least this many tostructs. This 131883c4be3SJerome Forissier * hides the inadequacy of the ARCDENSITY heuristic, at least 132883c4be3SJerome Forissier * for small programs. 133883c4be3SJerome Forissier */ 134883c4be3SJerome Forissier #define MINARCS 50 135883c4be3SJerome Forissier 136883c4be3SJerome Forissier /* 137883c4be3SJerome Forissier * The type used to represent indices into gmonparam.tos[]. 138883c4be3SJerome Forissier */ 139883c4be3SJerome Forissier #define ARCINDEX unsigned long 140883c4be3SJerome Forissier 141883c4be3SJerome Forissier /* 142883c4be3SJerome Forissier * Maximum number of arcs we want to allow. 143883c4be3SJerome Forissier * Used to be max representable value of ARCINDEX minus 2, but now 144883c4be3SJerome Forissier * that ARCINDEX is a long, that's too large; we don't really want 145883c4be3SJerome Forissier * to allow a 48 gigabyte table. 146883c4be3SJerome Forissier * The old value of 1<<16 wasn't high enough in practice for large C++ 147883c4be3SJerome Forissier * programs; will 1<<20 be adequate for long? FIXME 148883c4be3SJerome Forissier */ 149883c4be3SJerome Forissier #define MAXARCS (1 << 20) 150883c4be3SJerome Forissier 151883c4be3SJerome Forissier struct tostruct { 152883c4be3SJerome Forissier unsigned long selfpc; 153883c4be3SJerome Forissier long count; 154883c4be3SJerome Forissier ARCINDEX link; 155883c4be3SJerome Forissier }; 156883c4be3SJerome Forissier 157883c4be3SJerome Forissier /* 158883c4be3SJerome Forissier * A raw arc, with pointers to the calling site and the called site and a 159883c4be3SJerome Forissier * count. 160883c4be3SJerome Forissier */ 161883c4be3SJerome Forissier struct rawarc { 162883c4be3SJerome Forissier unsigned long raw_frompc; 163883c4be3SJerome Forissier unsigned long raw_selfpc; 164883c4be3SJerome Forissier long raw_count; 165883c4be3SJerome Forissier }; 166883c4be3SJerome Forissier 167883c4be3SJerome Forissier /* 168883c4be3SJerome Forissier * The profiling data structures are housed in this structure. 169883c4be3SJerome Forissier */ 170883c4be3SJerome Forissier struct gmonparam { 171883c4be3SJerome Forissier long int state; 172883c4be3SJerome Forissier unsigned short *kcount; 173883c4be3SJerome Forissier unsigned long kcountsize; 174883c4be3SJerome Forissier ARCINDEX *froms; 175883c4be3SJerome Forissier unsigned long fromssize; 176883c4be3SJerome Forissier struct tostruct *tos; 177883c4be3SJerome Forissier unsigned long tossize; 178883c4be3SJerome Forissier unsigned long tolimit; 179883c4be3SJerome Forissier unsigned long lowpc; 180883c4be3SJerome Forissier unsigned long highpc; 181883c4be3SJerome Forissier unsigned long textsize; 182883c4be3SJerome Forissier unsigned long hashfraction; 183883c4be3SJerome Forissier long log_hashfraction; 184883c4be3SJerome Forissier /* */ 185883c4be3SJerome Forissier uint32_t prof_rate; /* PC sampling frequency */ 186883c4be3SJerome Forissier }; 187883c4be3SJerome Forissier 188883c4be3SJerome Forissier /* 189883c4be3SJerome Forissier * Possible states of profiling. 190883c4be3SJerome Forissier */ 191883c4be3SJerome Forissier #define GMON_PROF_ON 0 192883c4be3SJerome Forissier #define GMON_PROF_BUSY 1 193883c4be3SJerome Forissier #define GMON_PROF_ERROR 2 194883c4be3SJerome Forissier #define GMON_PROF_OFF 3 195883c4be3SJerome Forissier #define GMON_PROF_OFF_EXITING 4 196883c4be3SJerome Forissier 197883c4be3SJerome Forissier #endif /* GMON_H */ 198