profile.h revision 19000
11543Srgrimes/* 21543Srgrimes * Copyright (c) 1992, 1993 31543Srgrimes * The Regents of the University of California. All rights reserved. 41543Srgrimes * 51543Srgrimes * Redistribution and use in source and binary forms, with or without 61543Srgrimes * modification, are permitted provided that the following conditions 71543Srgrimes * are met: 81543Srgrimes * 1. Redistributions of source code must retain the above copyright 91543Srgrimes * notice, this list of conditions and the following disclaimer. 101543Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111543Srgrimes * notice, this list of conditions and the following disclaimer in the 121543Srgrimes * documentation and/or other materials provided with the distribution. 131543Srgrimes * 3. All advertising materials mentioning features or use of this software 141543Srgrimes * must display the following acknowledgement: 151543Srgrimes * This product includes software developed by the University of 161543Srgrimes * California, Berkeley and its contributors. 171543Srgrimes * 4. Neither the name of the University nor the names of its contributors 181543Srgrimes * may be used to endorse or promote products derived from this software 191543Srgrimes * without specific prior written permission. 201543Srgrimes * 211543Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221543Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231543Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241543Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251543Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261543Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271543Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281543Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291543Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301543Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311543Srgrimes * SUCH DAMAGE. 321543Srgrimes * 331543Srgrimes * @(#)profile.h 8.1 (Berkeley) 6/11/93 3419000Sbde * $Id: profile.h,v 1.7 1996/08/28 20:15:25 bde Exp $ 351543Srgrimes */ 361543Srgrimes 3713107Sbde#ifndef _MACHINE_PROFILE_H_ 3813107Sbde#define _MACHINE_PROFILE_H_ 392166Spaul 4013157Sbde#ifdef KERNEL 4113157Sbde/* 4213157Sbde * The kernel uses assembler stubs instead of unportable inlines. 4313157Sbde * This is mainly to save a little time when profiling is not enabled, 4413157Sbde * which is the usual case for the kernel. 4513157Sbde */ 4613157Sbde#define _MCOUNT_DECL void mcount 4713157Sbde#define MCOUNT 481543Srgrimes 4917879Sbde#ifdef GUPROF 5017879Sbde#define CALIB_SCALE 1000 5117879Sbde#define KCOUNT(p,index) ((p)->kcount[(index) \ 5217879Sbde / (HISTFRACTION * sizeof(*(p)->kcount))]) 5317879Sbde#define MCOUNT_DECL(s) 5417879Sbde#define MCOUNT_ENTER(s) 5517879Sbde#define MCOUNT_EXIT(s) 5617879Sbde#define PC_TO_I(p, pc) ((fptrint_t)(pc) - (fptrint_t)(p)->lowpc) 5717879Sbde#else 5817879Sbde#define MCOUNT_DECL(s) u_long s; 5917879Sbde#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } 6017879Sbde#define MCOUNT_EXIT(s) (write_eflags(s)) 6117879Sbde#endif /* GUPROF */ 6217879Sbde 6313157Sbde#else /* !KERNEL */ 6413157Sbde 6513157Sbde#define _MCOUNT_DECL static __inline void _mcount 6613157Sbde 671543Srgrimes#define MCOUNT \ 6813157Sbdevoid \ 6913157Sbdemcount() \ 7013157Sbde{ \ 7113107Sbde fptrint_t selfpc, frompc; \ 721543Srgrimes /* \ 7313107Sbde * Find the return address for mcount, \ 741543Srgrimes * and the return address for mcount's caller. \ 751543Srgrimes * \ 7613107Sbde * selfpc = pc pushed by call to mcount \ 771543Srgrimes */ \ 781543Srgrimes asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ 791543Srgrimes /* \ 8013107Sbde * frompc = pc pushed by call to mcount's caller. \ 8113107Sbde * The caller's stack frame has already been built, so %ebp is \ 8213107Sbde * the caller's frame pointer. The caller's raddr is in the \ 8313107Sbde * caller's frame following the caller's caller's frame pointer. \ 841543Srgrimes */ \ 8513107Sbde asm("movl (%%ebp),%0" : "=r" (frompc)); \ 8613107Sbde frompc = ((fptrint_t *)frompc)[1]; \ 8713107Sbde _mcount(frompc, selfpc); \ 881543Srgrimes} 8913157Sbde#endif /* KERNEL */ 902166Spaul 9113107Sbde/* An unsigned integral type that can hold function pointers. */ 9213107Sbdetypedef u_int fptrint_t; 9313107Sbde 9413107Sbde/* 9513107Sbde * An unsigned integral type that can hold non-negative difference between 9613107Sbde * function pointers. 9713107Sbde */ 9813107Sbdetypedef int fptrdiff_t; 9913107Sbde 10013157Sbde#ifdef KERNEL 10119000Sbde 10213157Sbdevoid mcount __P((fptrint_t frompc, fptrint_t selfpc)); 10319000Sbde 10419000Sbde#ifdef GUPROF 10519000Sbdestruct gmonparam; 10619000Sbde 10719000Sbdevoid nullfunc_loop_profiled __P((void)); 10819000Sbdevoid nullfunc_profiled __P((void)); 10919000Sbdevoid startguprof __P((struct gmonparam *p)); 11019000Sbdevoid stopguprof __P((struct gmonparam *p)); 11113157Sbde#else 11219000Sbde#define startguprof(p) 11319000Sbde#define stopguprof(p) 11419000Sbde#endif /* GUPROF */ 11519000Sbde 11619000Sbde#else /* !KERNEL */ 11719000Sbde 11819000Sbde#include <sys/cdefs.h> 11919000Sbde 12019000Sbde__BEGIN_DECLS 12113157Sbdevoid mcount __P((void)) __asm("mcount"); 12213157Sbdestatic void _mcount __P((fptrint_t frompc, fptrint_t selfpc)); 12319000Sbde__END_DECLS 12413157Sbde 12519000Sbde#endif /* KERNEL */ 12619000Sbde 12713157Sbde#ifdef GUPROF 12819000Sbde/* XXX doesn't quite work outside kernel yet. */ 12919000Sbdeextern int cputime_bias; 13019000Sbde 13119000Sbde__BEGIN_DECLS 13219000Sbdeint cputime __P((void)); 13319000Sbdevoid empty_loop __P((void)); 13413107Sbdevoid mexitcount __P((fptrint_t selfpc)); 13519000Sbdevoid nullfunc __P((void)); 13619000Sbdevoid nullfunc_loop __P((void)); 13719000Sbde__END_DECLS 13813157Sbde#endif 13913107Sbde 14013157Sbde#endif /* !_MACHINE_PROFILE_H_ */ 141