Commit c695746d authored by julien.delange's avatar julien.delange
Browse files

finish to integrate gprof for LEON/RTEMS



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@642 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 7b8fa421
...@@ -43,11 +43,6 @@ ifeq ($(ENABLE_DYNAMIC_CONFIGURATION),1) ...@@ -43,11 +43,6 @@ ifeq ($(ENABLE_DYNAMIC_CONFIGURATION),1)
CFLAGS+=-D__PO_HI_USE_DYNAMIC_CONFIGURATION CFLAGS+=-D__PO_HI_USE_DYNAMIC_CONFIGURATION
endif endif
ifdef USE_GPROF
CFLAGS+=-pg -D__PO_HI_USE_GPROF
LDFLAGS+=-pg
endif
ifdef TARGET_INCLUDE ifdef TARGET_INCLUDE
INCLUDE=-I. -I$(RUNTIME_PATH)/include/ $(TARGET_INCLUDE) INCLUDE=-I. -I$(RUNTIME_PATH)/include/ $(TARGET_INCLUDE)
else else
......
...@@ -28,7 +28,7 @@ TARGET_TRANSPORT_SOURCES = ...@@ -28,7 +28,7 @@ TARGET_TRANSPORT_SOURCES =
TARGET_CFLAGS = -DRTEMS_POSIX -DLEON_RTEMS TARGET_CFLAGS = -DRTEMS_POSIX -DLEON_RTEMS
TARGET_INCLUDE = -I $(RUNTIME_PATH)/config/leon-rtems/ TARGET_INCLUDE = -I $(RUNTIME_PATH)/config/leon-rtems/
LD = LD = sparc-rtems-ld
TARGET_LDFLAGS = -lrtemsbsp -lc TARGET_LDFLAGS = -lrtemsbsp -lc
target-clean: target-clean:
...@@ -48,3 +48,8 @@ define bsp-link-cxx ...@@ -48,3 +48,8 @@ define bsp-link-cxx
-o $(BINARY) $(LINK_OBJS) $(LINK_LIBS) -o $(BINARY) $(LINK_OBJS) $(LINK_LIBS)
endef endef
ifdef USE_GPROF
TARGET_LDFLAGS+=-Wl,--wrap,Clock_isr
TARGET_CFLAGS+=-D__PO_HI_USE_GPROF
endif
...@@ -65,9 +65,7 @@ static char sccsid[] = "@(#)gmon.c 1.0 (E.S.A) 10/05/2010"; ...@@ -65,9 +65,7 @@ static char sccsid[] = "@(#)gmon.c 1.0 (E.S.A) 10/05/2010";
#include <rtems.h> #include <rtems.h>
#include <bsp.h> #include <bsp.h>
/* #define CONFIG_OS_PROFILE_OVER_SERIAL 1
* This was derived from above and modified to add different profiling info.
*/
/* /*
* Histogram counters are unsigned shorts (according to the kernel). * Histogram counters are unsigned shorts (according to the kernel).
...@@ -140,10 +138,10 @@ static char sccsid[] = "@(#)gmon.c 1.0 (E.S.A) 10/05/2010"; ...@@ -140,10 +138,10 @@ static char sccsid[] = "@(#)gmon.c 1.0 (E.S.A) 10/05/2010";
* the recording of calls via mcount(). * the recording of calls via mcount().
*/ */
struct tostruct { struct tostruct {
char *selfpc; char *selfpc;
long count; long count;
unsigned short link; unsigned short link;
unsigned short order; unsigned short order;
}; };
/* /*
...@@ -153,10 +151,10 @@ struct tostruct { ...@@ -153,10 +151,10 @@ struct tostruct {
* header for ncnt - sizeof(struct phdr) bytes. * header for ncnt - sizeof(struct phdr) bytes.
*/ */
struct phdr { struct phdr {
char *lpc; /* low program counter */ char *lpc; /* low program counter */
char *hpc; /* high program counter */ char *hpc; /* high program counter */
int ncnt; /* number of bytes of histogram counters minius int ncnt; /* number of bytes of histogram counters minius
sizeof(struct phdr) that follow */ sizeof(struct phdr) that follow */
}; };
/* /*
...@@ -166,9 +164,9 @@ struct phdr { ...@@ -166,9 +164,9 @@ struct phdr {
* counters to the end of the file. * counters to the end of the file.
*/ */
struct rawarc { struct rawarc {
unsigned long raw_frompc; unsigned long raw_frompc;
unsigned long raw_selfpc; unsigned long raw_selfpc;
unsigned long raw_count; unsigned long raw_count;
}; };
/* /*
...@@ -179,8 +177,8 @@ struct rawarc { ...@@ -179,8 +177,8 @@ struct rawarc {
*/ */
#define GMON_MAGIC 0xbeefbabe #define GMON_MAGIC 0xbeefbabe
struct gmon_data { struct gmon_data {
unsigned long type; /* constant for type of data following this struct */ unsigned long type; /* constant for type of data following this struct */
unsigned long size; /* size in bytes of the data following this struct */ unsigned long size; /* size in bytes of the data following this struct */
}; };
/* /*
...@@ -200,10 +198,10 @@ struct gmon_data { ...@@ -200,10 +198,10 @@ struct gmon_data {
*/ */
#define GMONTYPE_ARCS_ORDERS 3 #define GMONTYPE_ARCS_ORDERS 3
struct rawarc_order { struct rawarc_order {
unsigned long raw_frompc; unsigned long raw_frompc;
unsigned long raw_selfpc; unsigned long raw_selfpc;
unsigned long raw_count; unsigned long raw_count;
unsigned long raw_order; unsigned long raw_order;
}; };
/* /*
* The GMONTYPE_RLD_STATE gmon_data.type is for the rld_load()'ed state of the * The GMONTYPE_RLD_STATE gmon_data.type is for the rld_load()'ed state of the
...@@ -268,297 +266,363 @@ static char *s_profil = 0; ...@@ -268,297 +266,363 @@ static char *s_profil = 0;
#define MSG "No space for profiling buffer(s)\n" #define MSG "No space for profiling buffer(s)\n"
#define SAVE_L1( _pc_ ) \ #define SAVE_L1( _pc_ ) \
do{ \ do{ \
asm volatile( "mov %%l1, %0" : "=r" (_pc_) : "0" (_pc_) ); \ asm volatile( "mov %%l1, %0" : "=r" (_pc_) : "0" (_pc_) ); \
}while(0) }while(0)
static void moncontrol( int mode ); static void moncontrol( int mode );
static rtems_isr profile_clock_isr(rtems_vector_number vector); static rtems_isr profile_clock_isr(rtems_vector_number vector);
static rtems_isr Clock_isr(rtems_vector_number vector);
static void moncontrol( int mode ) static void moncontrol( int mode )
{ {
if (mode) { if (mode) {
/* start */ /* start */
s_profil = sbuf + sizeof(struct phdr); s_profil = sbuf + sizeof(struct phdr);
s_profil_sz = ssiz - sizeof(struct phdr); s_profil_sz = ssiz - sizeof(struct phdr);
profiling = 0; profiling = 0;
} else { } else {
/* stop */ /* stop */
s_profil = 0; s_profil = 0;
s_profil_sz = 0; s_profil_sz = 0;
profiling = 3; profiling = 3;
} }
} }
static void _mcleanup() static void _mcleanup()
{ {
int fromindex; int fromindex;
int endfrom; int endfrom;
char *frompc; char *frompc;
int toindex; int toindex;
struct rawarc rawarc; struct rawarc rawarc;
int ret = -1; int ret = -1;
moncontrol(0); moncontrol(0);
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1) #if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
ret = initialize_serial(); ret = initialize_serial();
#endif #endif
if( ret >= 0 ) if( ret >= 0 )
{ {
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1) #if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
write_serial( (uint8_t*)sbuf , (unsigned int)ssiz ); write_serial( (uint8_t*)sbuf , (unsigned int)ssiz );
#endif #endif
} }
fprintf( stderr , "[mcleanup] sbuf 0x%x ssiz %d\n" , (unsigned int)sbuf , (unsigned int)ssiz ); fprintf( stderr , "[mcleanup] sbuf 0x%x ssiz %d\n" , (unsigned int)sbuf , (unsigned int)ssiz );
endfrom = s_textsize / (HASHFRACTION * sizeof(*froms)); endfrom = s_textsize / (HASHFRACTION * sizeof(*froms));
for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) { for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) {
if ( froms[fromindex] == 0 ) { if ( froms[fromindex] == 0 ) {
continue; continue;
} }
frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms)); frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms));
for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link) for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link)
{ {
fprintf( stderr , fprintf( stderr ,
"[mcleanup] frompc 0x%x selfpc 0x%x count %d\n" , "[mcleanup] frompc 0x%x selfpc 0x%x count %d\n" ,
(unsigned int)frompc , (unsigned int)frompc ,
(unsigned int)tos[toindex].selfpc , (unsigned int)tos[toindex].selfpc ,
(unsigned int)tos[toindex].count ); (unsigned int)tos[toindex].count );
rawarc.raw_frompc = (unsigned long) frompc; rawarc.raw_frompc = (unsigned long) frompc;
rawarc.raw_selfpc = (unsigned long) tos[toindex].selfpc; rawarc.raw_selfpc = (unsigned long) tos[toindex].selfpc;
rawarc.raw_count = tos[toindex].count; rawarc.raw_count = tos[toindex].count;
if( ret >= 0 ) if( ret >= 0 )
{ {
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1) #if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
write_serial( (uint8_t*)&rawarc , (unsigned int)sizeof(rawarc)); write_serial( (uint8_t*)&rawarc , (unsigned int)sizeof(rawarc));
#endif #endif
} }
} }
} }
} }
void monstartup(char *lowpc, char *highpc) void monstartup(char *lowpc, char *highpc)
{ {
int monsize; int monsize;
char *buffer; char *buffer;
printf("%s\n", sccsid); printf("%s\n", sccsid);
/* /*
* round lowpc and highpc to multiples of the density we're using * round lowpc and highpc to multiples of the density we're using
* so the rest of the scaling (here and in gprof) stays in ints. * so the rest of the scaling (here and in gprof) stays in ints.
*/ */
lowpc = (char *) lowpc = (char *)
ROUNDDOWN((unsigned) lowpc, HISTFRACTION*sizeof(HISTCOUNTER)); ROUNDDOWN((unsigned) lowpc, HISTFRACTION*sizeof(HISTCOUNTER));
s_lowpc = lowpc; s_lowpc = lowpc;
highpc = (char *) highpc = (char *)
ROUNDUP((unsigned) highpc, HISTFRACTION*sizeof(HISTCOUNTER)); ROUNDUP((unsigned) highpc, HISTFRACTION*sizeof(HISTCOUNTER));
s_highpc = highpc; s_highpc = highpc;
s_textsize = highpc - lowpc; s_textsize = highpc - lowpc;
monsize = (s_textsize / HISTFRACTION) + sizeof(struct phdr); monsize = (s_textsize / HISTFRACTION) + sizeof(struct phdr);
buffer = (char*)malloc( monsize ); buffer = (char*)malloc( monsize );
if ( buffer == (char *) -1 ) if ( buffer == (char *) -1 )
{ {
printf("%s\n", MSG); printf("%s\n", MSG);
return; return;
} }
froms = (unsigned short *) malloc( s_textsize / HASHFRACTION ); froms = (unsigned short *) malloc( s_textsize / HASHFRACTION );
if ( froms == (unsigned short *) -1 ) if ( froms == (unsigned short *) -1 )
{ {
printf("%s\n", MSG); printf("%s\n", MSG);
froms = 0; froms = 0;
return; return;
} }
tolimit = s_textsize * ARCDENSITY / 100; tolimit = s_textsize * ARCDENSITY / 100;
if ( tolimit < MINARCS ) { if ( tolimit < MINARCS ) {
tolimit = MINARCS; tolimit = MINARCS;
} else if ( tolimit > 65534 ) { } else if ( tolimit > 65534 ) {
tolimit = 65534; tolimit = 65534;
} }
tos = (struct tostruct *) malloc( tolimit * sizeof( struct tostruct ) ); tos = (struct tostruct *) malloc( tolimit * sizeof( struct tostruct ) );
if ( tos == (struct tostruct *) -1 ) if ( tos == (struct tostruct *) -1 )
{ {
printf("%s\n", MSG); printf("%s\n", MSG);
froms = 0; froms = 0;
tos = 0; tos = 0;
return; return;
} }
tos[0].link = 0; tos[0].link = 0;
sbuf = buffer; sbuf = buffer;
bzero( buffer, sizeof(buffer) ); bzero( buffer, sizeof(buffer) );
ssiz = monsize; ssiz = monsize;
( (struct phdr *) sbuf ) -> lpc = lowpc; ( (struct phdr *) sbuf ) -> lpc = lowpc;
( (struct phdr *) sbuf ) -> hpc = highpc; ( (struct phdr *) sbuf ) -> hpc = highpc;
( (struct phdr *) sbuf ) -> ncnt = ssiz; ( (struct phdr *) sbuf ) -> ncnt = ssiz;
monsize -= sizeof(struct phdr); monsize -= sizeof(struct phdr);
if ( monsize <= 0 ) if ( monsize <= 0 )
return; return;
printf("PC histrogram scale = %d\n", HISTFRACTION); printf("PC histrogram scale = %d\n", HISTFRACTION);
/* Register the new clock driver */ /* Register the new clock driver */
set_vector( profile_clock_isr, 0x18, 1 ); set_vector( profile_clock_isr, 0x18, 1 );
atexit( _mcleanup ); atexit( _mcleanup );
moncontrol(1); moncontrol(1);
} }
void mcount() void mcount()
{ {
register char *selfpc; register char *selfpc;
register unsigned short *frompcindex; register unsigned short *frompcindex;
register struct tostruct *top; register struct tostruct *top;
register struct tostruct *prevtop; register struct tostruct *prevtop;
register long toindex; register long toindex;
static int first_call = 1; static int first_call = 1;
if( first_call ) if( first_call )
{ {
monstartup((char*)&text_start, (char*)&_endtext); monstartup((char*)&text_start, (char*)&_endtext);
first_call = 0; first_call = 0;
} }
/* /*
* find the return address for mcount, * find the return address for mcount,
* and the return address for mcount's caller. * and the return address for mcount's caller.
*/ */
/* selfpc = pc pushed by mcount call. /* selfpc = pc pushed by mcount call.
This identifies the function that was just entered. */ This identifies the function that was just entered. */
selfpc = (void *) __builtin_return_address (0); selfpc = (void *) __builtin_return_address (0);
/* frompcindex = pc in preceding frame. /* frompcindex = pc in preceding frame.
This identifies the caller of the function just entered. */ This identifies the caller of the function just entered. */
frompcindex = (void *) __builtin_return_address (1); frompcindex = (void *) __builtin_return_address (1);
/* /*
* check that we are profiling * check that we are profiling
* and that we aren't recursively invoked. * and that we aren't recursively invoked.
*/ */
if (profiling) { if (profiling) {
goto out; goto out;
} }
profiling++; profiling++;
/* /*
* check that frompcindex is a reasonable pc value. * check that frompcindex is a reasonable pc value.
* for example: signal catchers get called from the stack, * for example: signal catchers get called from the stack,
* not from text space. too bad. * not from text space. too bad.
*/ */
frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc); frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc);
if ((unsigned long) frompcindex > s_textsize) { if ((unsigned long) frompcindex > s_textsize) {
goto done; goto done;
} }
frompcindex = frompcindex =
&froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))]; &froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))];
toindex = *frompcindex; toindex = *frompcindex;
if (toindex == 0) { if (toindex == 0) {
/* /*
* first time traversing this arc * first time traversing this arc
*/ */
toindex = ++tos[0].link; toindex = ++tos[0].link;
if (toindex >= tolimit) { if (toindex >= tolimit) {
goto overflow;
}
*frompcindex = toindex;
top = &tos[toindex];
top->selfpc = selfpc;
top->count = 1;
top->link = 0;
goto done;
}
top = &tos[toindex];
if (top->selfpc == selfpc) {
/*
* arc at front of chain; usual case.
*/
top->count++;
goto done;
}
/*
* have to go looking down chain for it.
* top points to what we are looking at,
* prevtop points to previous top.
* we know it is not at the head of the chain.
*/
for (; /* goto done */; ) {
if (top->link == 0) {
/*
* top is end of the chain and none of the chain
* had top->selfpc == selfpc.
* so we allocate a new tostruct
* and link it to the head of the chain.
*/
toindex = ++tos[0].link;
if (toindex >= tolimit) {
goto overflow; goto overflow;
} }
top = &tos[toindex]; *frompcindex = toindex;
top->selfpc = selfpc; top = &tos[toindex];
top->count = 1; top->selfpc = selfpc;
top->link = *frompcindex; top->count = 1;
*frompcindex = toindex; top->link = 0;
goto done; goto done;
} }
/* top = &tos[toindex];
* otherwise, check the next arc on the chain. if (top->selfpc == selfpc) {
*/ /*
prevtop = top; * arc at front of chain; usual case.
top = &tos[top->link]; */
if (top->selfpc == selfpc) { top->count++;
/* goto done;
* there it is. }
* increment its count /*
* move it to the head of the chain. * have to go looking down chain for it.
*/ * top points to what we are looking at,
top->count++; * prevtop points to previous top.
toindex = prevtop->link; * we know it is not at the head of the chain.
prevtop->link = top->link; */
top->link = *frompcindex; for (; /* goto done */; ) {
*frompcindex = toindex; if (top->link == 0) {
goto done; /*
} * top is end of the chain and none of the chain
* had top->selfpc == selfpc.
} * so we allocate a new tostruct
* and link it to the head of the chain.
*/
toindex = ++tos[0].link;
if (toindex >= tolimit) {
goto overflow;
}
top = &tos[toindex];
top->selfpc = selfpc;
top->count = 1;
top->link = *frompcindex;
*frompcindex = toindex;
goto done;
}
/*
* otherwise, check the next arc on the chain.
*/
prevtop = top;
top = &tos[top->link];
if (top->selfpc == selfpc) {
/*
* there it is.
* increment its count
* move it to the head of the chain.
*/
top->count++;
toindex = prevtop->link;
prevtop->link = top->link;
top->link = *frompcindex;
*frompcindex = toindex;
goto done;
}
}
done: done:
profiling--; profiling--;
/* and fall through */ /* and fall through */
out: out:
return; /* normal return restores saved registers */ return; /* normal return restores saved registers */