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.

Significant variations in timing when using TSCL

Greetings

I am using CCS 3.3 and c6455 running at 1GHz. I am employing the TSCL registers to measure the time it takes (in terms of number of cycles) to execute a function.

My code is as follows:

#include <c6x.h>

...

maxiters = 50;   

for (j=0;j<maxiters;j++)

{

start = TSCL;
stop = TSCL;
overhead = stop-start;

start_count = TSCL;
my_function;
stop_count = TSCL;

count_time = stop_count-start_count;

printf("Execution time = %d ns\n",count_time-overhead);

}

...

When running the code, the Execution time for "my_function" reported varies significantly between approximately 100,000 cycles and 511,000,000 cycles. On the contrary, the overhead is always the same and equal to 4 cycles.

Any ideas what could cause this variation? It is quite a complicated function but I don't see why the variation should vary this greatly.

Even better, is there an alternative, more accurate way of measuring the time it takes to execute a function?

Many thanks in advance

Ry

  • Hi,

    Although I don't necessarily konw the intrinsics of how TSCL registers measure time (nor the intrinsics of the my_function()), I imagine two scenarios that may be happening between the start_count / stop_count lines:

    - Either the my_function() is experiencing cache hits/misses depending if data is pre-loaded from a previous run, or

    - The counter is wrapping around the 32-bit boundary and therefore giving very different readings every time the code runs (I don't see a reset of TSCL register).

    For this device you can also try to use the CCS Profile Clock - it will still impacted by the cache, though.

    I've hit both scenarios in the past (unfortunately none using the specific registers/device as yours), therefore I hope the tips may help you. I will reply to this thread if I think of any additional scenarios that may be relevant.

    Regards,

    Rafael