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

cross mob
mikewang
Level 2
Level 2
25 sign-ins 5 questions asked 10 replies posted

I am using TC377 board, I want to profile a function. How many clock cycle does it run ?  Not sure how to do that. 

 

Thanks.

 

Mike 

0 Likes
1 Solution
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang  ,

 

You could make use of performance counters. For more information about these, please refer to the section 12.11 of the Architecture manual Part1. The performance counters are controlled by the CCTRL register and can be enabled or disabled by writing the appropriate value to the counter enable CCTRL.CE bit. The counters are free running incrementors once enabled, and will roll over to zero after the maximum value is reached. The counters are free running incrementors once enabled, and will roll over to zero after the maximum value is reached. For your reference, please refer to this code example to understand more about these counters.

 

Best regards,
Anupama.

View solution in original post

0 Likes
17 Replies
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang  ,

 

You could make use of performance counters. For more information about these, please refer to the section 12.11 of the Architecture manual Part1. The performance counters are controlled by the CCTRL register and can be enabled or disabled by writing the appropriate value to the counter enable CCTRL.CE bit. The counters are free running incrementors once enabled, and will roll over to zero after the maximum value is reached. The counters are free running incrementors once enabled, and will roll over to zero after the maximum value is reached. For your reference, please refer to this code example to understand more about these counters.

 

Best regards,
Anupama.

0 Likes

Hi Anupama, Thanks. I also want to run simulator on Aurix studio. Can you share the document to run simulator from Aurix studio? Sometimes, I want to get cycle numbers of a function without running on device. 

Thanks.  Mike

0 Likes

Hi Anupama,

I tried a very simple sample code below. I use  #define MAX_LOOP_CNT 1900  , but perf counter is 11407. I think it should be close to 1900 cycles. It may be caused by debug build. Then I don't know how to run release build on Aurix studio .  Thanks Mike 

void loop(void)
{
volatile uint16 i; /* This data type is stored in RAM and cannot be optimized by the compiler */

for(i = 0; i < MAX_LOOP_CNT; i++)
{
__nop();
}
}

/* Function to run the CPU performance counters */
void runCpuPerfCounters(void)
{
IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal); /* Reset and start counters in normal mode */
loop(); /* Test loop to measure CPU performance */
g_perfCounts = IfxCpu_stopCounters(); /* Stop counters and get results */
}

 

0 Likes
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang , 


Could you please refer to this expert training also? As shown in this, the counter1 value comes out to be 190 only which is also the value of  MAX_LOOP_CNT. Can you share the screenshot of values you're getting as on my end I'm getting values around 190 only. How are you trying to debug? I'm running the function until the end of  runCpuPerfCounters() by setting only one breakpoint at the end of execution of this function and my values are matching as shown below. 

Anupama_0-1694165922858.png

Best regards, 
Anupama. 

0 Likes

Hi Anupama, 

I am using #define MAX_LOOP_CNT 1000. 

I am debugging from debugging configuration like below.

mikewang_3-1694286669369.png

 

I set a breakpoint after runCpuPerCounters(). 

mikewang_1-1694286424448.png

 

Then I got 3000 instead of 1000. I see you are using g_perfCounts,d instead of g_perfCounts. But it didn't work for me. What is the meaning g_perfCounts,d? (decimal???)

 

Thanks.

Mike

mikewang_0-1694286308743.png

 

 

0 Likes

Hi Anupama,

Very interesting! I tried to use 190, I am getting 192 cycles. But I tried to use 1900, I am getting 5702 instead of 5700. It is like 1900*3 = 5700  . I don't know why ? 

Thanks.

Xianju 

0 Likes

Hi Anupama,

Sorry , I replied to myself! I tried to use 190, I am getting 192 cycles. But I tried to use 1900, I am getting 5702 instead of 5700. It is like 1900*3 = 5700  . I don't know why ? 

Thanks.

Xianju 

0 Likes
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang ,

 

I'm using this code example and in this when I change the value to 1900, I'm getting the correct value of counter only. Could you please let me know if you're doing the same or you've done any changes in the code? In that case could you please share the code snippet ? And yes, d means decimal format.

 

Best regards, 
Anupama. 

0 Likes
lock attach
Attachments are accessible only for community members.

Hi Anupama, 

Attached is my code.  Especially the function below. I tried two methods, both are getting the same results.

unsigned int diff;
uint32 t1, t2, t3 ;
/* Function to run the CPU performance counters */
void runCpuPerfCounters(void)
{

    IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal);            /* Reset and start counters in normal mode  */
    t1 = __mfcr(CPU_M1CNT);
    loop();                                                             /* Test loop to measure CPU performance     */

    t2 = __mfcr(CPU_M1CNT) ;
    t3 = t2-t1;
    t3 = t3  & ~0x80000000;
    g_perfCounts = IfxCpu_stopCounters();                               /* Stop counters and get results            */
}

 Thanks.

 

Xianju 

0 Likes
lock attach
Attachments are accessible only for community members.
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang ,

 

I've tried with the 1900 value at my end and I'm getting the following results. 

 
 

 

Best regards, 

Anupama. 

0 Likes
mikewang
Level 2
Level 2
25 sign-ins 5 questions asked 10 replies posted

did you forget to share your results?  Thanks. Xianju

0 Likes
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang , 

 

I think it was not visible previously. Can you check now?

 

Best regards, 

Anupama. 

0 Likes

I created the project by myself , then add the code from sample code to my code. I will redo everything again. Thanks. 

0 Likes
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @mikewang , 

 

I think we should first directly import the available code example in ADS and see if there also you're getting the same issue. Could you please do that and share the results with me?

 

Best regards, 

Anupama. 

0 Likes

yes, that is a good plan. 

Hi Anupama, It works fine now after applying sample project . My project may have some problems. THank for your help.  mike

mikewang
Level 2
Level 2
25 sign-ins 5 questions asked 10 replies posted

If you can not reproduce my problem, is it possible my setting has some issues ? 

0 Likes