16cda32c0SRodney W. Grimes /* 26cda32c0SRodney W. Grimes * Copyright (c) 1992, 1993 36cda32c0SRodney W. Grimes * The Regents of the University of California. All rights reserved. 46cda32c0SRodney W. Grimes * 56cda32c0SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 66cda32c0SRodney W. Grimes * modification, are permitted provided that the following conditions 76cda32c0SRodney W. Grimes * are met: 86cda32c0SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 96cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 106cda32c0SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 116cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 126cda32c0SRodney W. Grimes * documentation and/or other materials provided with the distribution. 136cda32c0SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 146cda32c0SRodney W. Grimes * must display the following acknowledgement: 156cda32c0SRodney W. Grimes * This product includes software developed by the University of 166cda32c0SRodney W. Grimes * California, Berkeley and its contributors. 176cda32c0SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 186cda32c0SRodney W. Grimes * may be used to endorse or promote products derived from this software 196cda32c0SRodney W. Grimes * without specific prior written permission. 206cda32c0SRodney W. Grimes * 216cda32c0SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 226cda32c0SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 236cda32c0SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 246cda32c0SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 256cda32c0SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 266cda32c0SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 276cda32c0SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 286cda32c0SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 296cda32c0SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 306cda32c0SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 316cda32c0SRodney W. Grimes * SUCH DAMAGE. 326cda32c0SRodney W. Grimes * 336cda32c0SRodney W. Grimes * @(#)profile.h 8.1 (Berkeley) 6/11/93 341130b656SJordan K. Hubbard * $FreeBSD$ 356cda32c0SRodney W. Grimes */ 366cda32c0SRodney W. Grimes 37912e6037SBruce Evans #ifndef _MACHINE_PROFILE_H_ 38912e6037SBruce Evans #define _MACHINE_PROFILE_H_ 39836dc83bSPaul Richards 40e5171bbeSBruce Evans #ifdef KERNEL 41e5171bbeSBruce Evans /* 42a7d00b5bSBruce Evans * Config generates something to tell the compiler to align functions on 16 43a7d00b5bSBruce Evans * byte boundaries. A strict alignment is good for keeping the tables small. 44a7d00b5bSBruce Evans */ 45a7d00b5bSBruce Evans #define FUNCTION_ALIGNMENT 16 46a7d00b5bSBruce Evans 47a7d00b5bSBruce Evans /* 48e5171bbeSBruce Evans * The kernel uses assembler stubs instead of unportable inlines. 49e5171bbeSBruce Evans * This is mainly to save a little time when profiling is not enabled, 50e5171bbeSBruce Evans * which is the usual case for the kernel. 51e5171bbeSBruce Evans */ 52e5171bbeSBruce Evans #define _MCOUNT_DECL void mcount 53e5171bbeSBruce Evans #define MCOUNT 54e5171bbeSBruce Evans 551f403fcfSBruce Evans #ifdef GUPROF 561f403fcfSBruce Evans #define CALIB_SCALE 1000 571f403fcfSBruce Evans #define KCOUNT(p,index) ((p)->kcount[(index) \ 58a7d00b5bSBruce Evans / (HISTFRACTION * sizeof(HISTCOUNTER))]) 591f403fcfSBruce Evans #define MCOUNT_DECL(s) 601f403fcfSBruce Evans #define MCOUNT_ENTER(s) 611f403fcfSBruce Evans #define MCOUNT_EXIT(s) 621f403fcfSBruce Evans #define PC_TO_I(p, pc) ((fptrint_t)(pc) - (fptrint_t)(p)->lowpc) 631f403fcfSBruce Evans #else 641f403fcfSBruce Evans #define MCOUNT_DECL(s) u_long s; 651f403fcfSBruce Evans #define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } 661f403fcfSBruce Evans #define MCOUNT_EXIT(s) (write_eflags(s)) 671f403fcfSBruce Evans #endif /* GUPROF */ 681f403fcfSBruce Evans 69e5171bbeSBruce Evans #else /* !KERNEL */ 70e5171bbeSBruce Evans 71a7d00b5bSBruce Evans #define FUNCTION_ALIGNMENT 4 72a7d00b5bSBruce Evans 73e5171bbeSBruce Evans #define _MCOUNT_DECL static __inline void _mcount 746cda32c0SRodney W. Grimes 756cda32c0SRodney W. Grimes #define MCOUNT \ 76e5171bbeSBruce Evans void \ 77e5171bbeSBruce Evans mcount() \ 78e5171bbeSBruce Evans { \ 79912e6037SBruce Evans fptrint_t selfpc, frompc; \ 806cda32c0SRodney W. Grimes /* \ 81912e6037SBruce Evans * Find the return address for mcount, \ 826cda32c0SRodney W. Grimes * and the return address for mcount's caller. \ 836cda32c0SRodney W. Grimes * \ 84912e6037SBruce Evans * selfpc = pc pushed by call to mcount \ 856cda32c0SRodney W. Grimes */ \ 866cda32c0SRodney W. Grimes asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ 876cda32c0SRodney W. Grimes /* \ 88912e6037SBruce Evans * frompc = pc pushed by call to mcount's caller. \ 89912e6037SBruce Evans * The caller's stack frame has already been built, so %ebp is \ 90912e6037SBruce Evans * the caller's frame pointer. The caller's raddr is in the \ 91912e6037SBruce Evans * caller's frame following the caller's caller's frame pointer. \ 926cda32c0SRodney W. Grimes */ \ 93912e6037SBruce Evans asm("movl (%%ebp),%0" : "=r" (frompc)); \ 94912e6037SBruce Evans frompc = ((fptrint_t *)frompc)[1]; \ 95912e6037SBruce Evans _mcount(frompc, selfpc); \ 966cda32c0SRodney W. Grimes } 97e5171bbeSBruce Evans #endif /* KERNEL */ 98912e6037SBruce Evans 99912e6037SBruce Evans /* An unsigned integral type that can hold function pointers. */ 100912e6037SBruce Evans typedef u_int fptrint_t; 101912e6037SBruce Evans 102912e6037SBruce Evans /* 103912e6037SBruce Evans * An unsigned integral type that can hold non-negative difference between 104912e6037SBruce Evans * function pointers. 105912e6037SBruce Evans */ 106912e6037SBruce Evans typedef int fptrdiff_t; 107912e6037SBruce Evans 108e5171bbeSBruce Evans #ifdef KERNEL 109d6b9e17eSBruce Evans 110912e6037SBruce Evans void mcount __P((fptrint_t frompc, fptrint_t selfpc)); 111912e6037SBruce Evans 112e5171bbeSBruce Evans #ifdef GUPROF 113d6b9e17eSBruce Evans struct gmonparam; 114d6b9e17eSBruce Evans 115d6b9e17eSBruce Evans void nullfunc_loop_profiled __P((void)); 116d6b9e17eSBruce Evans void nullfunc_profiled __P((void)); 117d6b9e17eSBruce Evans void startguprof __P((struct gmonparam *p)); 118d6b9e17eSBruce Evans void stopguprof __P((struct gmonparam *p)); 119d6b9e17eSBruce Evans #else 120d6b9e17eSBruce Evans #define startguprof(p) 121d6b9e17eSBruce Evans #define stopguprof(p) 122d6b9e17eSBruce Evans #endif /* GUPROF */ 123d6b9e17eSBruce Evans 124d6b9e17eSBruce Evans #else /* !KERNEL */ 125d6b9e17eSBruce Evans 126d6b9e17eSBruce Evans #include <sys/cdefs.h> 127d6b9e17eSBruce Evans 128d6b9e17eSBruce Evans __BEGIN_DECLS 129d6b9e17eSBruce Evans void mcount __P((void)) __asm("mcount"); 130d6b9e17eSBruce Evans static void _mcount __P((fptrint_t frompc, fptrint_t selfpc)); 131e5171bbeSBruce Evans __END_DECLS 132e5171bbeSBruce Evans 133d6b9e17eSBruce Evans #endif /* KERNEL */ 134d6b9e17eSBruce Evans 135d6b9e17eSBruce Evans #ifdef GUPROF 136d6b9e17eSBruce Evans /* XXX doesn't quite work outside kernel yet. */ 137d6b9e17eSBruce Evans extern int cputime_bias; 138d6b9e17eSBruce Evans 139d6b9e17eSBruce Evans __BEGIN_DECLS 140d6b9e17eSBruce Evans int cputime __P((void)); 141d6b9e17eSBruce Evans void empty_loop __P((void)); 142d6b9e17eSBruce Evans void mexitcount __P((fptrint_t selfpc)); 143d6b9e17eSBruce Evans void nullfunc __P((void)); 144d6b9e17eSBruce Evans void nullfunc_loop __P((void)); 145d6b9e17eSBruce Evans __END_DECLS 146d6b9e17eSBruce Evans #endif 147d6b9e17eSBruce Evans 148e5171bbeSBruce Evans #endif /* !_MACHINE_PROFILE_H_ */ 149