Move the kernel-specific logic to adjust frompc from MI to MD. For
these two reasons: 1. On ia64 a function pointer does not hold the address of the first instruction of a functions implementation. It holds the address of a function descriptor. Hence the user(), btrap(), eintr() and bintr() prototypes are wrong for getting the actual code address. 2. The logic forces interrupt, trap and exception entry points to be layed-out contiguously. This can not be achieved on ia64 and is generally just bad programming. The MCOUNT_FROMPC_USER macro is used to set the frompc argument to some kernel address which represents any frompc that falls outside the kernel text range. The macro can expand to ~0U to bail out in that case. The MCOUNT_FROMPC_INTR macro is used to set the frompc argument to some kernel address to represent a call to a trap or interrupt handler. This to avoid that the trap or interrupt handler appear to be called from everywhere in the call graph. The macro can expand to ~0U to prevent adjusting frompc. Note that the argument is selfpc, not frompc. This commit defines the macros on all architectures equivalently to the original code in sys/libkern/mcount.c. People can take it from here... Compile-tested on: alpha, amd64, i386, ia64 and sparc64 Boot-tested on: i386
This commit is contained in:
parent
401528f8f8
commit
0f2fe153bc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=134398
@ -215,11 +215,27 @@ LX98: ldgp $29,0($27); \
|
||||
*
|
||||
* XXX These macros should probably use inline assembly.
|
||||
*/
|
||||
#define MCOUNT_ENTER(s) \
|
||||
s = _alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH)
|
||||
#define MCOUNT_EXIT(s) \
|
||||
(void)_alpha_pal_swpipl(s);
|
||||
#define MCOUNT_DECL(s) u_long s;
|
||||
u_long _alpha_pal_swpipl(u_long);
|
||||
|
||||
#define MCOUNT_ENTER(s) s = _alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH)
|
||||
#define MCOUNT_EXIT(s) (void)_alpha_pal_swpipl(s)
|
||||
#define MCOUNT_DECL(s) u_long s;
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0UL)
|
||||
|
||||
_MCOUNT_DECL(uintfptr_t, uintfptr_t);
|
||||
|
||||
#else /* !_KERNEL */
|
||||
typedef u_long uintfptr_t;
|
||||
#endif
|
||||
|
@ -87,6 +87,19 @@ extern int mcount_lock;
|
||||
#endif
|
||||
#endif /* GUPROF */
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0UL)
|
||||
|
||||
#else /* !_KERNEL */
|
||||
|
||||
#define FUNCTION_ALIGNMENT 4
|
||||
|
@ -72,6 +72,19 @@ extern int mcount_lock;
|
||||
#endif
|
||||
#endif /* GUPROF */
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0U)
|
||||
|
||||
#else /* !_KERNEL */
|
||||
|
||||
#define FUNCTION_ALIGNMENT 4
|
||||
|
@ -87,6 +87,19 @@ extern int mcount_lock;
|
||||
#endif
|
||||
#endif /* GUPROF */
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0U)
|
||||
|
||||
#else /* !_KERNEL */
|
||||
|
||||
#define FUNCTION_ALIGNMENT 4
|
||||
|
@ -26,6 +26,9 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_PROFILE_H_
|
||||
#define _MACHINE_PROFILE_H_
|
||||
|
||||
#define _MCOUNT_DECL void __mcount
|
||||
#define MCOUNT
|
||||
|
||||
@ -41,6 +44,16 @@ typedef unsigned long fptrdiff_t;
|
||||
#define MCOUNT_EXIT(s) intr_restore(s)
|
||||
#define MCOUNT_DECL(s) register_t s;
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? ~0UL : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) (~0UL)
|
||||
|
||||
_MCOUNT_DECL(uintfptr_t, uintfptr_t);
|
||||
|
||||
#else /* !_KERNEL */
|
||||
@ -48,3 +61,5 @@ _MCOUNT_DECL(uintfptr_t, uintfptr_t);
|
||||
typedef unsigned long uintfptr_t;
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _MACHINE_PROFILE_H_ */
|
||||
|
@ -39,10 +39,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <vm/pmap.h>
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -61,16 +57,16 @@ void user(void);
|
||||
* perform this optimization.
|
||||
*/
|
||||
_MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
|
||||
register uintfptr_t frompc, selfpc;
|
||||
uintfptr_t frompc, selfpc;
|
||||
{
|
||||
#ifdef GUPROF
|
||||
int delta;
|
||||
#endif
|
||||
register fptrdiff_t frompci;
|
||||
register u_short *frompcindex;
|
||||
register struct tostruct *top, *prevtop;
|
||||
register struct gmonparam *p;
|
||||
register long toindex;
|
||||
fptrdiff_t frompci;
|
||||
u_short *frompcindex;
|
||||
struct tostruct *top, *prevtop;
|
||||
struct gmonparam *p;
|
||||
long toindex;
|
||||
#ifdef _KERNEL
|
||||
MCOUNT_DECL(s)
|
||||
#endif
|
||||
@ -89,24 +85,20 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
|
||||
#else
|
||||
p->state = GMON_PROF_BUSY;
|
||||
#endif
|
||||
frompci = frompc - p->lowpc;
|
||||
|
||||
#ifdef _KERNEL
|
||||
/*
|
||||
* When we are called from an exception handler, frompci may be
|
||||
* for a user address. Convert such frompci's to the index of
|
||||
* user() to merge all user counts.
|
||||
* When we are called from an exception handler, frompc may be
|
||||
* a user address. Convert such frompc's to some representation
|
||||
* in kernel address space.
|
||||
*/
|
||||
if (frompci >= p->textsize) {
|
||||
if (frompci + p->lowpc
|
||||
>= (uintfptr_t)(VM_MAXUSER_ADDRESS))
|
||||
goto done;
|
||||
frompci = (uintfptr_t)user - p->lowpc;
|
||||
if (frompci >= p->textsize)
|
||||
goto done;
|
||||
}
|
||||
frompc = MCOUNT_FROMPC_USER(frompc);
|
||||
#endif
|
||||
|
||||
frompci = frompc - p->lowpc;
|
||||
if (frompci >= p->textsize)
|
||||
goto done;
|
||||
|
||||
#ifdef GUPROF
|
||||
if (p->state == GMON_PROF_HIRES) {
|
||||
/*
|
||||
@ -141,18 +133,14 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
|
||||
/*
|
||||
* When we are called from an exception handler, frompc is faked
|
||||
* to be for where the exception occurred. We've just solidified
|
||||
* the count for there. Now convert frompci to the index of btrap()
|
||||
* for trap handlers and bintr() for interrupt handlers to make
|
||||
* exceptions appear in the call graph as calls from btrap() and
|
||||
* bintr() instead of calls from all over.
|
||||
* the count for there. Now convert frompci to an index that
|
||||
* represents the kind of exception so that interruptions appear
|
||||
* in the call graph as calls from those index instead of calls
|
||||
* from all over.
|
||||
*/
|
||||
if ((uintfptr_t)selfpc >= (uintfptr_t)btrap
|
||||
&& (uintfptr_t)selfpc < (uintfptr_t)eintr) {
|
||||
if ((uintfptr_t)selfpc >= (uintfptr_t)bintr)
|
||||
frompci = (uintfptr_t)bintr - p->lowpc;
|
||||
else
|
||||
frompci = (uintfptr_t)btrap - p->lowpc;
|
||||
}
|
||||
frompc = MCOUNT_FROMPC_INTR(selfpc);
|
||||
if ((frompc - p->lowpc) < p->textsize)
|
||||
frompci = frompc - p->lowpc;
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -49,6 +49,20 @@ _mcount() \
|
||||
#define MCOUNT_ENTER(s)
|
||||
#define MCOUNT_EXIT(s)
|
||||
#define MCOUNT_DECL(s)
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0U)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* !_MACHINE_PROFILE_H_ */
|
||||
|
@ -46,6 +46,19 @@ typedef u_long fptrdiff_t;
|
||||
#define MCOUNT_ENTER(s) s = rdpr(pil); wrpr(pil, 0, 14)
|
||||
#define MCOUNT_EXIT(s) wrpr(pil, 0, s)
|
||||
|
||||
void bintr(void);
|
||||
void btrap(void);
|
||||
void eintr(void);
|
||||
void user(void);
|
||||
|
||||
#define MCOUNT_FROMPC_USER(pc) \
|
||||
((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
|
||||
|
||||
#define MCOUNT_FROMPC_INTR(pc) \
|
||||
((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ? \
|
||||
((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr : \
|
||||
(uintfptr_t)btrap) : ~0UL)
|
||||
|
||||
void mcount(uintfptr_t frompc, uintfptr_t selfpc);
|
||||
|
||||
#else /* !_KERNEL */
|
||||
|
Loading…
Reference in New Issue
Block a user