Profiling performance using Root Counters?

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
User avatar
ArthCarvalho
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Profiling performance using Root Counters?

Post by ArthCarvalho » November 29th, 2019, 1:29 pm

Hello, I was trying to profile how my code is performing by using a root counter, but I don't think it is working correctly, and the documentation is very sparse about this, and not much was explained in the examples so I'm still confused.

I initilized the counter like this: (copied this from one of the examples in the SDK)
EnterCriticalSection();

SetRCnt( RCntCNT2, 0xffff, RCntMdNOINTR );
SetRCnt(RCntCNT2, 0xffff, RCntMdNOINTR|RCntMdFR);
StartRCnt( RCntCNT2 );

ExitCriticalSection();
And polled the counter like this multiple times inside my main loop:
// Player and Camera movement code here
prof_logic = GetRCnt(RCntCNT2);
// BG&Player model transformation and drawing code here
prof_transform = GetRCnt(RCntCNT2);
// Other stuff code here
prof_frame_end = GetRCnt(RCntCNT2);
ResetRCnt(RCntCNT2);
I've only tested this on emulators, but I'm getting values that I'm not sure are correct. Every time I call GetRCnt, does it reset the counter? Because I get values at the start that are larger than the values at the end of the frame.
Is this the way I'm supposed to use the counter or I am doing something wrong?

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2296
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Profiling performance using Root Counters?

Post by Shadow » November 29th, 2019, 5:19 pm

Code: Select all

// maximum number of tests
#define MAXTESTS 100

unsigned int perftest_lastcounter; // the last sampled counter value
unsigned int perftest_numcycles; // the number of completed test cycles
unsigned int perftest_currtest; // which test is currently running
unsigned int perftest_testtimes[MAXTESTS]; // storage for accumulated test times


// call this first to set things up
void perftest_Init(void)
{
	int i;
	
	for (i=0; i<MAXTESTS; i++)
	{
		perftest_testtimes[i] = 0;
	}
	
	perftest_numcycles = 0;
	perftest_currtest = 0;
	perftest_lastcounter = GetRCnt(0);
}


// call this at the start of each frame
void perftest_Startframe(void)
{
	perftest_numcycles++;
	perftest_currtest = 0;
	perftest_lastcounter = GetRCnt(0);
}


// call this at each performance test point
void perftest_Testpoint(void)
{
	unsigned int time, cval;
	
	cval = GetRCnt(0);
	time = cval - perftest_lastcounter;
	perftest_lastcounter = cval;
	perftest_testtimes[perftest_currtest++] += time;
}


// call this to get the test values
unsigned int perftest_Gettime(int testnum)
{
	if (perftest_numcycles == 0) return 0; // avoid divide by zero
	return perftest_testtimes[testnum] / perftest_numcycles;
}
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

rama3
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 472
Joined: April 16th, 2017, 10:54 pm

Re: Profiling performance using Root Counters?

Post by rama3 » November 29th, 2019, 9:59 pm

So I suppose the fix is to use root counter 2?

Counters generally require you to have the datasheet that states how they work.
In case Sony never documented them, maybe the general MIPS CPU core datasheet has them.

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2296
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Profiling performance using Root Counters?

Post by Shadow » November 30th, 2019, 6:03 am

Yeah use GetRCnt(0);
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
ArthCarvalho
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Re: Profiling performance using Root Counters?

Post by ArthCarvalho » November 30th, 2019, 6:52 am

I tried the code, and I'm still getting wild fluctuating values (ranging from positive, super high and negative).
I tired using GetRCnt(0) directly like you did in your code but then I seem to be getting looping values that makes no sense.
Does GetRCnt() not work on emulators?
Image

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2296
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Profiling performance using Root Counters?

Post by Shadow » November 30th, 2019, 9:41 am

Don't use emulation, use real hardware.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
ArthCarvalho
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Re: Profiling performance using Root Counters?

Post by ArthCarvalho » November 30th, 2019, 12:02 pm

I'm aware that I need to run this on real hardware, while I wasn't expecting it to have proper results, I expected at least something that made sense so I could tell I was on the right track, but no emulator will return anything correctly for this so my only choice is to burn an ISO and run it on my console.

rama3
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 472
Joined: April 16th, 2017, 10:54 pm

Re: Profiling performance using Root Counters?

Post by rama3 » December 1st, 2019, 7:09 am

I recommend looking for a PSX model number <= 750x (with expansion port) and one of the homebrew friendly expansion cards.
For the card, all it has to do is boot you into a Serial Comms loader (great example here: viewtopic.php?f=75&t=3460).

You'll also need a USB to PSX serial adapter, which you need to build yourself (or have it made by someone, I think your efforts deserve it :p).

This allows fully discless testing on real hardware, with the real counters.
Counters can be tricky to emulate all the details, and games rarely need them to be perfect.
You'll find that many (most?) emulators don't do them correctly.

Oh, and if the expansion port boot method is too much hassle, you can just burn a single Serial Comms loader disk and run from that ;p

User avatar
ArthCarvalho
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Re: Profiling performance using Root Counters?

Post by ArthCarvalho » December 2nd, 2019, 10:47 pm

rama3 wrote:
December 1st, 2019, 7:09 am
I recommend looking for a PSX model number <= 750x (with expansion port) and one of the homebrew friendly expansion cards.
For the card, all it has to do is boot you into a Serial Comms loader (great example here: viewtopic.php?f=75&t=3460).

You'll also need a USB to PSX serial adapter, which you need to build yourself (or have it made by someone, I think your efforts deserve it :p).

This allows fully discless testing on real hardware, with the real counters.
Counters can be tricky to emulate all the details, and games rarely need them to be perfect.
You'll find that many (most?) emulators don't do them correctly.

Oh, and if the expansion port boot method is too much hassle, you can just burn a single Serial Comms loader disk and run from that ;p
I have a SCPH-7001, but before I can have the courage to modify it I have to find a spare if anything goes wrong.

But anyway, I decided to burn a disc and give it a try on the real hardware, unfortunately I'm getting the same weird numbers here too:
Image
Chances are that I'm doing something wrong but... this plus that mysterious crash I'm having (That happened on this frame I posted above (SCPH-7001)) when using DualShock code makes me wonder if my PSY-Q installation is really corrupt/has something wrong with it.

Misscelan
Curious PSXDEV User
Curious PSXDEV User
Posts: 21
Joined: December 11th, 2016, 7:47 am

Re: Profiling performance using Root Counters?

Post by Misscelan » December 2nd, 2019, 11:24 pm

RCntCNT1 is the HBLANK counter that happens every 63.56/64 microseconds (PAL/NTCS).
So a second is expected when GetRCnt(RCntCNT1) >= 15625 for NTCS or 15733 for PAL.

This works fine for me on both real hardware and NOCASH.

Btw, good progress on your project, looking really promissing :)

rama3
/// PSXDEV | ELITE ///
/// PSXDEV | ELITE ///
Posts: 472
Joined: April 16th, 2017, 10:54 pm

Re: Profiling performance using Root Counters?

Post by rama3 » December 4th, 2019, 12:56 am

I like how the old analog video capture instantly enhances the mood of the scene ;p

For SIO, all you need is a small external device that plugs into the serial port on your 7001.
It doesn't require any internal modification.

User avatar
ArthCarvalho
Active PSXDEV User
Active PSXDEV User
Posts: 35
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Re: Profiling performance using Root Counters?

Post by ArthCarvalho » December 7th, 2019, 5:28 am

Thanks! RCntCNT1 really worked even on emulators, now I finally get to somehow profile my code.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests