home *** CD-ROM | disk | FTP | other *** search
- /*
- * Open: - Cache speed measurement is obviously broken
- * I suppose the PPC notices that the code does
- * nothing..but somehow it does this nothing pretty fast
- * ..too fast imho.
- *
- *
- *
- */
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <hardware/custom.h>
- #include <hardware/intbits.h>
- #include <math.h>
- #include <exec/types.h>
- #include <utility/tagitem.h>
- #include <dos/dos.h>
- #include <powerup/gcclib/powerup_protos.h>
- #include <powerup/ppclib/time.h>
- #include <powerup/ppclib/memory.h>
- #include <powerup/ppcinline/exec.h>
- #include <powerup/ppcinline/dos.h>
-
- //UBYTE vers[] = VERSTAG;
-
- #ifndef max
- #define max(a,b) ((a) > (b) ? (a) : (b))
- #endif
-
- #ifndef min
- #define min(a,b) ((a) <= (b) ? (a) : (b))
- #endif
-
-
- #define INDEX_SIZE 0
- #define INDEX_LOOP 1
- #define INDEX_ADDRESS 2
- #define INDEX_ADDRESSSIZE 3
- #define INDEX_FULL 4
- #define INDEX_CHIP 5
- #define INDEX_ROM 6
- #define INDEX_MMU 7
- #define INDEX_CACHE 8
- #define INDEX_COUNT 9
-
- /* M68k */
- #define M68KCACHEINHIBITED_SERIALIZED (0x40)
- #define M68KCACHE_WRITETHROUGH (0x00)
- #define M68KCACHE_COPYBACK (0x20)
- #define M68KCACHEINHIBITED_NONSERIALIZED (0x60)
- #define M68KCACHE_MASK (0x60)
- #define PAGE_SIZE 4096
- #define PAGE_MASK (PAGE_SIZE-1)
-
-
- #define MEMSIZE MemSize
- #define ALLOCSIZE (max(MEMSIZE,CacheBorder)+PAGE_SIZE)
- #define INTOFF FALSE
-
- #define TIMEPRE PPCCacheFlushAll(); \
- PPCSetTimerObject(MyTimerObject,PPCTIMERTAG_START,NULL);
-
- #define TIMEPOST PPCSetTimerObject(MyTimerObject,PPCTIMERTAG_STOP,NULL); \
- CalcTimer();
-
- /* The Cache measurement is broken
- */
- #define CACHETEST FALSE
-
- void memreadlinetime(APTR,ULONG,ULONG);
- void memwritelinetime(APTR,ULONG,ULONG);
- void memwritelinetime2(APTR,ULONG,ULONG);
- void memreadline(APTR,ULONG,ULONG);
- void memwriteline(APTR,ULONG,ULONG);
- void memwriteline2(APTR,ULONG,ULONG);
-
- void memreadlonglongtime(APTR,ULONG,ULONG);
- void memreadlongtime(APTR,ULONG,ULONG);
- void memreadwordtime(APTR,ULONG,ULONG);
- void memreadbytetime(APTR,ULONG,ULONG);
- void memwritelonglongtime(APTR,ULONG,ULONG);
- void memwritelongtime(APTR,ULONG,ULONG);
- void memwritewordtime(APTR,ULONG,ULONG);
- void memwritebytetime(APTR,ULONG,ULONG);
- void memreadlonglong(APTR,ULONG,ULONG);
- void memreadword(APTR,ULONG,ULONG);
- void memreadbyte(APTR,ULONG,ULONG);
- void memwritelonglong(APTR,ULONG,ULONG);
- void memwritelong(APTR,ULONG,ULONG);
- void memwriteword(APTR,ULONG,ULONG);
- void memwritebyte(APTR,ULONG,ULONG);
-
- #if INTOFF
-
- #define DISABLE Intenar = ((struct Custom*) 0xdff000)->intenar;\
- ((struct Custom*) 0xdff000)->intena = (UWORD) ((~INTF_PORTS)&(~INTF_SETCLR))
- #define ENABLE ((struct Custom*) 0xdff000)->intena = INTF_SETCLR|Intenar;
-
- #else
-
- #define DISABLE
- #define ENABLE
-
- #endif
-
- LONG *MyArgs[INDEX_COUNT];
- struct Library *SysBase;
- struct Library *DOSBase;
- long long Result;
- void *MyTimerObject;
- ULONG ticks;
- long long allticks;
- long long loopticks=0;
- ULONG LoopCount=100;
- ULONG MemSize;
- UWORD Intenar;
- ULONG CacheBorder;
- ULONG CacheSize;
- char *ArgumentString = "Size/N,Loop/N,Address/N,ASize/N,Full/S,Chip/S,Rom/S,MMU/S,CACHE/S";
-
- void CalcTimer(void);
- void CacheTest(APTR Source,
- APTR Dest);
- void MemoryBurstTest(APTR Source,
- APTR Dest,
- ULONG Mode);
- void MemorySingleTest(APTR Source,
- APTR Dest);
-
-
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
-
- int main(void)
- {
- struct RDArgs *rdargs;
- struct TagItem MyTags[2];
- APTR Source;
- APTR Dest;
-
- SysBase =(struct Library*) *((ULONG*)4L);
-
- if (DOSBase=OpenLibrary("dos.library",0))
- {
- if (!(rdargs=ReadArgs(ArgumentString,(LONG*) &MyArgs[0],NULL)))
- {
- PPCprintf("Commandline Error\n");
- return(20);
- }
- else
- {
- if (MyArgs[INDEX_LOOP])
- {
- LoopCount = *MyArgs[INDEX_LOOP];
- }
-
- MyTags[0].ti_Tag = PPCTIMERTAG_CPU;
- MyTags[0].ti_Data = TRUE;
- MyTags[1].ti_Tag = TAG_END;
- if (MyTimerObject=PPCCreateTimerObject(MyTags))
- {
- CacheBorder = 0x10000;
- CacheSize = 0x8000;
-
- if (MyArgs[INDEX_SIZE])
- {
- MemSize = (*MyArgs[INDEX_SIZE] + 0xfff) & ~0xfff;
- }
-
- MemSize = max(CacheBorder,MemSize);
-
-
-
- if ((MyArgs[INDEX_CACHE]) ||
- (MyArgs[INDEX_FULL]))
- {
- if (CacheSize > 0)
- {
- if (Source=PPCAllocVec(CacheSize,
- MEMF_FAST))
- {
- if (Dest=PPCAllocVec(CacheSize,
- MEMF_FAST))
- {
- CacheTest(Source,
- Dest);
-
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Dest Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
- }
- }
-
-
-
- if ((!MyArgs[INDEX_ADDRESS]) ||
- (MyArgs[INDEX_FULL]))
- {
- if (Source=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST))
- {
- if (Dest=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST))
- {
- PPCprintf("CopyBack ");
- MemoryBurstTest(Source,
- Dest,
- M68KCACHE_COPYBACK);
-
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Dest Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
-
-
-
- if ((MyArgs[INDEX_MMU]) ||
- (MyArgs[INDEX_FULL]) )
- {
- if (Source=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_WRITETHROUGHPPC))
- {
- if (Dest=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_WRITETHROUGHPPC))
- {
- PPCprintf("WriteThrough ");
- MemoryBurstTest(Source,
- Dest,
- M68KCACHE_WRITETHROUGH);
-
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Dest Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
-
-
- if (Source=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_NOCACHEPPC))
- {
- if (Dest=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_NOCACHEPPC))
- {
- PPCprintf("NoCache ");
- MemorySingleTest(Source,
- Dest);
-
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Dest Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
-
-
- if (Source=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_NOCACHESYNCPPC))
- {
- if (Dest=PPCAllocVec(ALLOCSIZE,
- MEMF_FAST|MEMF_NOCACHESYNCPPC))
- {
- PPCprintf("NoCacheSync ");
- MemorySingleTest(Source,
- Dest);
-
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Dest Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
- }
- }
-
-
- if ((MyArgs[INDEX_CHIP]) ||
- (MyArgs[INDEX_FULL]))
- {
- if (Source=PPCAllocVec(ALLOCSIZE,
- MEMF_CHIP))
- {
- if (Dest=PPCAllocVec(ALLOCSIZE,
- MEMF_CHIP))
- {
- PPCprintf("Chipram:\n");
- MemorySingleTest(Source,
- Dest);
- PPCFreeVec(Dest);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
- PPCFreeVec(Source);
- }
- else
- {
- PPCprintf("Error: Can`t alloc Source Fastram:\n");
- }
- }
-
- if ((MyArgs[INDEX_ROM]) ||
- (MyArgs[INDEX_FULL]))
- {
- PPCprintf("Rom:\n");
- MemoryBurstTest((APTR) 0xf80000,
- NULL,
- M68KCACHE_COPYBACK);
- }
-
- if (MyArgs[INDEX_ADDRESS])
- {
- if (MyArgs[INDEX_ADDRESSSIZE])
- {
- MemSize = (*MyArgs[INDEX_ADDRESSSIZE] + 0xfff) & ~0xfff;
- }
- PPCprintf("Ram Size 0x%lx Loop Count %ld\n",
- MemSize,
- LoopCount);
-
- PPCprintf("0x%08lx - 0x%08lx: assumes cacheoff at the address\n",
- *MyArgs[INDEX_ADDRESS],
- *MyArgs[INDEX_ADDRESS] + MemSize);
-
- MemorySingleTest((APTR) *MyArgs[INDEX_ADDRESS],
- NULL);
- }
- PPCDeleteTimerObject(MyTimerObject);
- }
- }
- CloseLibrary(DOSBase);
- return(0);
- }
- else
- {
- PPCprintf("Can`t open dos.library\n");
- }
- return(20);
- }
-
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
-
- void CalcTimer(void)
- {
- PPCGetTimerObject(MyTimerObject,
- PPCTIMERTAG_TICKSPERSEC,
- &Result);
-
- ticks = Result;
-
- PPCGetTimerObject(MyTimerObject,
- PPCTIMERTAG_DIFFTICKS,
- &Result);
-
- allticks = Result;
- #if 0
- PPCprintf("%Ld ticks\n",Result);
- #endif
-
- }
-
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
-
- void CacheTest(APTR Source,
- APTR Dest)
- {
- long long Size;
- ULONG LoopCount;
-
- PPCprintf("CPU Cache isn`t working yet..measurements are wrong\n");
-
- #if CACHETEST
- LoopCount = 100*100;
- // Size = CacheSize;
- Size = 4096;
-
- PPCprintf("CPU Cache Performance Statistics\n");
-
- DISABLE;
-
- TIMEPRE;
- memreadlonglongtime(Source,Size>>5,LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadlonglong(Source,Size>>5,LoopCount);
- TIMEPOST;
-
- PPCprintf("%16Ld 64Bit Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- TIMEPRE;
- memreadlongtime(Source,Size>>5,LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadlong(Source,Size>>5,LoopCount);
- TIMEPOST;
-
- PPCprintf("%16Ld Long Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- TIMEPRE;
- memreadwordtime(Source,Size>>5,LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadword(Source,Size>>5,LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Word Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- TIMEPRE;
- memreadbytetime(Source,Size>>5,LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memreadbyte(Source,Size>>5,LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Byte Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- ENABLE;
-
- #endif
- }
-
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
-
- void MemoryBurstTest(APTR Source,
- APTR Dest,
- ULONG Mode)
- {
- long long Size;
-
- DISABLE;
-
- PPCprintf("Bus Burst Performance Statistics\n");
-
- for (Size=CacheBorder;Size<=MEMSIZE;Size<<=1)
- {
- TIMEPRE;
- memreadlinetime(Source,(ULONG)(Size>>5),LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadline(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
-
- PPCprintf("%16Ld Line Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- if (PPCSetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
- {
- return;
- }
-
- }
-
- if ((ULONG) Source != 0xf80000)
- {
- if (Mode == M68KCACHE_WRITETHROUGH)
- {
- /* To use the Writebuffer in writethrough
- * we have to use linear write accesses
- */
- for (Size=CacheBorder;Size<=MEMSIZE;Size<<=1)
- {
- TIMEPRE;
- memwritelinetime2(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memwriteline2(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Line Write\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- if (PPCSetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
- {
- return;
- }
-
- }
- }
- else
- {
- /* For copyback modes it`s enough to read the first long
- * from the cacheline. The buscontroller stalls the cpu
- * until the whole line is loaded so additional loads
- * would only add additional cache accesses though the
- * line is already loaded
- */
- for (Size=CacheBorder;Size<=MEMSIZE;Size<<=1)
- {
- TIMEPRE;
- memwritelinetime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memwriteline(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Line Write\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- if (PPCSetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
- {
- return;
- }
- }
- }
- }
- ENABLE;
- }
-
-
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
- /*------------------------------------------------------------------------*/
-
- void MemorySingleTest(APTR Source,
- APTR Dest)
- {
- long long Size;
-
- PPCprintf("- Bus CacheMode Performance Statistics\n");
-
- DISABLE;
-
- for (Size=4096;Size<=MEMSIZE;Size<<=1)
- {
- TIMEPRE;
- memreadlongtime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadlong(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
-
- PPCprintf("%16Ld Long Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- TIMEPRE;
- memreadwordtime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks=allticks;
-
- TIMEPRE;
- memreadword(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Word Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- TIMEPRE;
- memreadbytetime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memreadbyte(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Byte Read\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- if (PPCSetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
- {
- return;
- }
- }
-
- if ((ULONG) Source != 0xf80000)
- {
- for (Size=4096;Size<=MEMSIZE;Size<<=1)
- {
- TIMEPRE;
- memreadlongtime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memwritelong(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Long Write\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- TIMEPRE;
- memreadwordtime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memwriteword(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Word Write\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
- TIMEPRE;
- memreadbytetime(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- loopticks = allticks;
-
- TIMEPRE;
- memwritebyte(Source,(ULONG) (Size>>5),LoopCount);
- TIMEPOST;
- PPCprintf("%16Ld Byte Write\t%4g MB/s Mem Bandwidth\n",
- Size,
- ((double) ((Size * LoopCount * ticks ) / (allticks - loopticks))) / (1024*1024));
-
-
- if (PPCSetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
- {
- return;
- }
- }
- }
-
-
- ENABLE;
- }
-
-
-
-