PDA

View Full Version : Tricore 1767 Execution Time Measurement



rckr
Oct 16th, 2015, 06:14 AM
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?fold erId=db3a304313719f4f011372875d300070&fileId=db3a304336797ff90136a131cf343b05&ack=t

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

matthiasluh
Feb 25th, 2016, 09:44 AM
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_no rmal);
}

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