main.c 3.16 KB
#include <os.h>
#include <rmon.h>
#include "osprof.h"

#define PROF_HISTO_ARRAY_V	((u16 *)0x80300000)
#define PROF_HISTO_ARRAY_P	((u16 *)0xa0300000)

OSProf	TestProf[2];

extern char _profSegmentTextStart[];
extern char _profSegmentTextEnd[];

char	bootStack[STACKSIZE];

static void	idle(void *);
static void	main(void *);

static OSThread	idleThread;
static char	idleThreadStack[STACKSIZE];

static OSThread	mainThread;
static char	mainThreadStack[STACKSIZE];

static OSThread	rmonThread;
static char	rmonThreadStack[RMON_STACKSIZE];

void prof(void);

boot(void)
{
    int *pr;
    
    osInitialize();
    osCreateThread(&mainThread, 1, main, (void *)0, mainThreadStack+STACKSIZE,
		  10);
    osStartThread(&mainThread);
}

static void
main(void *arg)
{
    int totalFailures = 0;
    int i;
	u16 bin;

    /*
     * Create idle thread
     */
    osCreateThread(&idleThread, 3, idle, (void *)0, idleThreadStack+STACKSIZE,
		  0);
    osStartThread(&idleThread);

    /* Start VI manager */
    osCreateViManager((OSPri)OS_PRIORITY_VIMGR);


    /*
     * Create rmon thread
     */
    osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
		rmonThreadStack+RMON_STACKSIZE, OS_PRIORITY_RMON);
    osStartThread(&rmonThread);

	/*
	 *  Initialize and turn on profiling
	 */
	TestProf[0].histo_base = PROF_HISTO_ARRAY_V;
	TestProf[0].histo_size = ((u32)timer1 - 
							(u32)prof) >> 2;
	TestProf[0].text_start = (u32 *)prof;
	TestProf[0].text_end   = (u32 *)timer1;

	TestProf[1].histo_base = PROF_HISTO_ARRAY_V+TestProf[0].histo_size;
	TestProf[1].histo_size = ((u32)_profSegmentTextEnd - 
							(u32)timer1) >> 2;
	TestProf[1].text_start = (u32 *)timer1;
	TestProf[1].text_end   = (u32 *)_profSegmentTextEnd;

#ifdef PROFILE_INIT
	rmonPrintf("0: histo_base %x\n", TestProf[0].histo_base);
	rmonPrintf("0: histo_size %x\n", TestProf[0].histo_size);
	rmonPrintf("0: text_start %x\n", TestProf[0].text_start);
	rmonPrintf("0: text_end   %x\n", TestProf[0].text_end);
	rmonPrintf("1: histo_base %x\n", TestProf[1].histo_base);
	rmonPrintf("1: histo_size %x\n", TestProf[1].histo_size);
	rmonPrintf("1: text_start %x\n", TestProf[1].text_start);
	rmonPrintf("1: text_end   %x\n", TestProf[1].text_end);


    rmonPrintf("Init profiling\n");
	osProfileInit(TestProf, 2);


	osProfileStart(1000);			/* 1 millisecond sample */
    rmonPrintf("Start profiling\n");

#endif /* PROFILE_INIT */

	for(i = 0; i < 3; i++) {

	/*
	 *  Use some time on CPU
	 */
    rmonPrintf("loop test\n");
    prof();

	/*
	 *  Make sure profiling counter doesn't interfere with other counters
	 */
#ifdef JUNK
    rmonPrintf("timer1\n");
    totalFailures += timer1();
    rmonPrintf("timer2\n");
    totalFailures += timer2();
    rmonPrintf("timer3\n");
    totalFailures += timer3();
#endif /* JUNK */

#ifdef PROFILE_FLUSH
	osProfileFlush();
	rmonPrintf("Flush Profile Data\n");
#endif /* PROFILE_FLUSH */

	} /* for loop */

#ifdef PROFILE_STOP
	/* 
	 *  Turn off profiling
	 */
	osProfileStop();
    rmonPrintf("Stop profiling\n");
#endif /* PROFILE_STOP */


	/*
	 *  XXX Profile several different text sections
	 */

    rmonPrintf("Done\n");
	/* make sure profiling data same every time */
	for(;;) {
	}

}

static void
idle(void *arg)
{
	for(;;);
}