Tricore 1767 Execution Time Measurement

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello,

I'm working with a Tricore 1767 on a Infineon Hybridkit2.
I want to measure the execution time of my implemented code.


I found this file:
http://www.infineon.com/dgdl/ap3216810_TriCore_Performace_Optimization.pdf?folderId=db3a304313719f4f...

In Chap. 2.2 they refere to the CPU Clock Counter CCNT.
It's def in regtc1767.sfr :
#define CCTRL 0xfc00 /* Counter Control Register */

In Fig.1 is an example:

// Start Measure
t1a=__mfcr(CCNT);
t1b=__mfcr(ICNT);
Benchmark();
// Stop Measure
t2a=__mfcr(CCNT);
t2b=__mfcr(ICNT);
cpu_clk = t2a-t1a;
instr_cnt = t2b-t1b;

Note: Performance Counters need be enabled before can be used. To enable all the counters set the CCTRL.CE bit to 1.

My questions are:
-How to read CCNT in my code?
-Where to set CCTRL.CE bit?
-Whats the Datatype of t1a=__mfcr(CCNT)?



My first idea was to Measure the execution time via Analog Output Port toggeling.
But I didn't find the functions to set the Analog I/O to Output and set the values.


Can someone help me with one of those two methods, or is there a better way to measure execution time?

Thanks,
Max
0 Likes
4 Replies
MatthiasLuh
Level 1
Level 1
First reply posted Welcome!
Hey,
I know this is old but I think many people will have similar problems. I finally solved it like this:


void benchmark_start()
{
IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal);
}

IfxCpu_Perf benchmark_end()
{
return IfxCpu_stopCounters();
}

void benchmark_output(IfxCpu_Perf benchmark_result)
{
uart_send_int(benchmark_result.clock.counter); /* uart_send_int is my own function */
uart_send_int(benchmark_result.instruction.counter);
}


if you don't use the framework, this is what the framework basically does (copied from Infineon SW Framework version iLLD_1_0_0_8_0):


IFX_INLINE void IfxCpu_resetAndStartCounters(IfxCpu_CounterMode mode)
{
Ifx_CPU_CCTRL cctrl;
cctrl.U = __mfcr(CPU_CCTRL);
/*Disable the counters */
cctrl.B.CE = 0;
__mtcr(CPU_CCTRL, cctrl.U);

/* reset the counters */
__mtcr(CPU_CCNT, 0);
__mtcr(CPU_ICNT, 0);
__mtcr(CPU_M1CNT, 0);
__mtcr(CPU_M2CNT, 0);
__mtcr(CPU_M3CNT, 0);

/*Enable the counters, set the counter mode */
cctrl.B.CE = 1;
cctrl.B.CM = mode;
__mtcr(CPU_CCTRL, cctrl.U);
}

IFX_INLINE IfxCpu_Perf IfxCpu_stopCounters(void)
{
IfxCpu_Perf result;
/*Disable the counters, reset the control reg */
/* Use inline assembly to ensure constant implementation, and execution of the measurement routines */
__stopPerfCounters();

Ifx_CPU_CCNT ccnt;
ccnt.U = __mfcr(CPU_CCNT);
result.clock.counter = ccnt.B.CountValue;
result.clock.overlfow = ccnt.B.SOvf;

Ifx_CPU_ICNT icnt;
icnt.U = __mfcr(CPU_ICNT);
result.instruction.counter = icnt.B.CountValue;
result.instruction.overlfow = icnt.B.SOvf;

Ifx_CPU_M1CNT m1cnt;
m1cnt.U = __mfcr(CPU_M1CNT);
result.counter1.counter = m1cnt.B.CountValue;
result.counter1.overlfow = m1cnt.B.SOvf;

Ifx_CPU_M2CNT m2cnt;
m2cnt.U = __mfcr(CPU_M2CNT);
result.counter2.counter = m2cnt.B.CountValue;
result.counter2.overlfow = m2cnt.B.SOvf;

Ifx_CPU_M3CNT m3cnt;
m3cnt.U = __mfcr(CPU_M3CNT);
result.counter3.counter = m3cnt.B.CountValue;
result.counter3.overlfow = m3cnt.B.SOvf;
return result;
}


Good luck,
Matthias
0 Likes
User17394
Level 2
Level 2
Hello Matthias,

I'm trying to get performance data from my Tricore TC275 using the free toolchain tricore Hightec. Basically I have my function that I run several times with a for loop and I want to return the average time of execution of my program.

---------------------------------------
// beginning of the counter, void benchmark_start ()

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

myfunction ();

}

// end of the counter, IfxCpu_Perf benchmark_end () (IfxCpu_Perf is not recognized)

// final result: (end-start) / 10000


------------------------------------------------------


Maybe it's a lybrary that I have to include?

The problem is that I do not understand how to include your "benchmark" functions in my code, could you help me please?
0 Likes
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
Hi Pirate02. The IfxCpu_Perf functions are part of Infineon's Low Level Device (iLLD) driver library. Add those to your project and then try something like this:


#include "IfxCpu.h"

void main( void )
{
IfxCpu_Perf perf;

IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal);
for (i = 0; i <10000; i ++) {
myfunction ();
}
perf = IfxCpu_stopCounters();

printf( "clocks: %d instructions: %d", perf.clock.counter, perf.instruction.counter );
}

The CPU debug system is activated by default when a debugger is connected. If you need this code to work even when a debugger is not connected, add this to turn on the debug system:


#include "IfxCbs_reg.h"

// Unlock debug system if it's not already unlocked
if( !(__mfcr(CPU_DBGSR) & 0x1) )
{
CBS_OEC.U = 0xA1;
CBS_OEC.U = 0x5E;
CBS_OEC.U = 0xA1;
CBS_OEC.U = 0x5E;
}

_mtcr( CPU_DBGSR, 1 ); // enable the Core Debug Controller

Note: this is for the AURIX family, not the TC17xx.
0 Likes
User17394
Level 2
Level 2
Hello Thank you for your return,

I'm working on the sample file "TimeDemo_ApplicationKitTC275C-Step" (on HighTec). When I try to add the # include "IfxCpu.h", he can not recognize the lybrary in my project (I do not know if it's different on DAVE). Would you have a way to find this file because I have the impression that it does not exist on the IDE "HighTec Free tool chain".

Thank you in advance.3636.attach3637.attach
0 Likes