profile.h revision 13107
1122394Sharti/* 2122394Sharti * Copyright (c) 1992, 1993 3122394Sharti * The Regents of the University of California. All rights reserved. 4122394Sharti * 5122394Sharti * Redistribution and use in source and binary forms, with or without 6122394Sharti * modification, are permitted provided that the following conditions 7133211Sharti * are met: 8133211Sharti * 1. Redistributions of source code must retain the above copyright 9133211Sharti * notice, this list of conditions and the following disclaimer. 10133211Sharti * 2. Redistributions in binary form must reproduce the above copyright 11133211Sharti * notice, this list of conditions and the following disclaimer in the 12133211Sharti * documentation and/or other materials provided with the distribution. 13122394Sharti * 3. All advertising materials mentioning features or use of this software 14122394Sharti * must display the following acknowledgement: 15122394Sharti * This product includes software developed by the University of 16133211Sharti * California, Berkeley and its contributors. 17133211Sharti * 4. Neither the name of the University nor the names of its contributors 18133211Sharti * may be used to endorse or promote products derived from this software 19133211Sharti * without specific prior written permission. 20133211Sharti * 21133211Sharti * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22133211Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23133211Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24133211Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25133211Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26133211Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27133211Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28122394Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29156066Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30122394Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31122394Sharti * SUCH DAMAGE. 32122394Sharti * 33122394Sharti * @(#)profile.h 8.1 (Berkeley) 6/11/93 34122394Sharti * $Id: profile.h,v 1.4 1994/09/15 16:27:14 paul Exp $ 35122394Sharti */ 36122394Sharti 37122394Sharti#ifndef _MACHINE_PROFILE_H_ 38122394Sharti#define _MACHINE_PROFILE_H_ 39122394Sharti 40122394Sharti#if 0 41122394Sharti#define _MCOUNT_DECL static inline void _mcount 42122394Sharti 43122394Sharti#define MCOUNT \ 44122394Shartiextern void mcount() asm("mcount"); void mcount() { \ 45154180Sharti fptrint_t selfpc, frompc; \ 46154180Sharti /* \ 47122394Sharti * Find the return address for mcount, \ 48122394Sharti * and the return address for mcount's caller. \ 49122394Sharti * \ 50122394Sharti * selfpc = pc pushed by call to mcount \ 51122394Sharti */ \ 52122394Sharti asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ 53122394Sharti /* \ 54122394Sharti * frompc = pc pushed by call to mcount's caller. \ 55122394Sharti * The caller's stack frame has already been built, so %ebp is \ 56122394Sharti * the caller's frame pointer. The caller's raddr is in the \ 57154180Sharti * caller's frame following the caller's caller's frame pointer. \ 58154180Sharti */ \ 59154180Sharti asm("movl (%%ebp),%0" : "=r" (frompc)); \ 60154180Sharti frompc = ((fptrint_t *)frompc)[1]; \ 61154180Sharti _mcount(frompc, selfpc); \ 62154180Sharti} 63154180Sharti#else 64154180Sharti#define _MCOUNT_DECL void mcount 65154180Sharti#define MCOUNT 66154180Sharti#endif 67154180Sharti 68154180Sharti#define MCOUNT_ENTER { save_eflags = read_eflags(); disable_intr(); } 69122394Sharti#define MCOUNT_EXIT (write_eflags(save_eflags)) 70154180Sharti 71122394Sharti#define CALIB_SCALE 1000 72122394Sharti#define KCOUNT(p,index) ((p)->kcount[(index) \ 73122394Sharti / (HISTFRACTION * sizeof(*(p)->kcount))]) 74122394Sharti#define PC_TO_I(p, pc) ((fptrint_t)(pc) - (fptrint_t)(p)->lowpc) 75122394Sharti 76122394Sharti/* An unsigned integral type that can hold function pointers. */ 77122394Shartitypedef u_int fptrint_t; 78122394Sharti 79142810Sharti/* 80122394Sharti * An unsigned integral type that can hold non-negative difference between 81122394Sharti * function pointers. 82128237Sharti */ 83128237Shartitypedef int fptrdiff_t; 84128237Sharti 85122394Shartiu_int cputime __P((void)); 86122394Shartivoid mcount __P((fptrint_t frompc, fptrint_t selfpc)); 87122394Shartivoid mexitcount __P((fptrint_t selfpc)); 88122394Sharti 89122394Sharti#endif /* !MACHINE_PROFILE_H */ 90122394Sharti