This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to profile the C6474 function in the DSP/BIOS environment?

Other Parts Discussed in Thread: TMS320C6474

Basically I want to count the number of cpu cycles taken on each core of C6474.  It should work in the in the DSP/BIOS environment.  

 

Now I have the code mentioned in document "sprab20_Inter-Core Communication on TMS320C6474" and it works well.  But the number of cpu cycles needed for each core is unknown.   Is there any example code for this profiling purpose?

  • #include <clk.h>

    unsigned int start, stop, delta;

    start = CLK_gethtime();

    // code to be benchmarked

    stop = CLK_gethtime();

    delta = stop - start;  // number of elapsed CPU cycles

  • Thank you so much.   I have some further questions.

     

    1. As in your answer "// code to be benchmarked", is there any function to let the cpu run for a given number of cycles.  For example, something like a "cpurun(1000)", then in the "delta = stop - start;  // number of elapsed CPU cycles" , delta is 1000.

     

    2. Would you please confirm that the actual time needed can be calculated by the product of "delta" and 1e-9, (For the C6474 @1GHz)?

     

  • beaver said:

    Thank you so much.   I have some further questions.

     

    1. As in your answer "// code to be benchmarked", is there any function to let the cpu run for a given number of cycles.  For example, something like a "cpurun(1000)", then in the "delta = stop - start;  // number of elapsed CPU cycles" , delta is 1000.

    Not really.  Something like TSK_sleep?  It's not exact since you have context switches, etc.

    beaver said:

    2. Would you please confirm that the actual time needed can be calculated by the product of "delta" and 1e-9, (For the C6474 @1GHz)?

    The code I showed would return the number of CPU cycles, so yes, multiplying by the CPU clock period would give you the time in seconds.

  • Thank you for your information.   However, I have not succeeded in the profiling yet.  Here is the part of the codes

     

    // This function is called from the PRD function manager.

    void sendIPCmessagePRD(){

    int i, data;

    unsigned int start, stop, delta;

    ......

    // CLK_start();

    start = CLK_gethtime();

     

    // code to be benchmarked

    // Data processing

    data = 0;

    for (i = 0; i< 1000000; i++)

    {

    data += 1;

    }

    stop = CLK_gethtime();

    delta = stop - start;  // number of elapsed CPU cycles

    LOG_printf(&trace, "Number of cycles is %d", delta);

    }

     

    But the delta value is abnormal.  It does not change to the number of iteration in the for loop.  And the number of cycles is not reasonable (sometimes it is always 14 for any iteration number and sometimes it is always 0).

     

    Any idea about this problem? I was stucked to it for a long time.

     

     

     

     

  • My guess is that the compiler/optimizer is being overly smart and pre-computing that loop.  Try making i and/or data volatile so that the compiler does not optimize it.

  • Your guess is correct.  Now the profiling works.  Thank you very much for your informative answer.