Jump to content
  • 0

Performance evaluation


Andrea_cau

Question

Hi,
I'm using HDMI_IN project https://reference.digilentinc.com/learn/programmable-logic/tutorials/zybo-hdmi-demo/start.
I'm trying to evaluate a function performance.
I decided to don't use libraries because i had problems.
This is the code:
1        #define CLOCKS_PER_SECO TIMER_FREQ_HZ
2        volatile int *COUNTER_ADDR = (int *) 0xF8F00200;
3        uint64_t end, begin;
4        double myTotalTime;
5        ....
6
7        begin = *COUNTER_ADDR;
8
9        --BLOCK_CODE----
10
11        end = *COUNTER_ADDR;
12
13        myTotalTime = ((double)(end-begin))/CLOCKS_PER_SECO;
14
15        xil_printf("\r\nCycles: %llu \n\r", 2*(end - begin));
16        xil_printf("\rTotal Time: %llu sec\n\r", myTotalTime);
17        xil_printf("\rNumber of cycles in %f sec: %llu\n\r", myTotalTime, 2*(end - begin));

the output is in the file output1.txt and is obviously wrong.
Why?

Secondly,if i remove \r from the lines n. 15 16 17  the output is saved in output2.
Why is it different?

If in the line 16 i change %llu with %f, it does not print anything. why? i've declared as double,
i debugged and i've done the calculations with a calculator. the processor frequency should be 670MHz.
If i calculate with the calculator:
clock cycles: 52409775*2
total time:52409775*2/670000000= 0.15715074962518740629685157421289sec

it's correct??
Could you correct the code? i don't understand what i'm wrong.
Thanks!

output1.txt

output2.txt

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Hi,

I suspect the problem will disappear if you create a "double" variable for everything you want to print, and avoid expressions as "printf" arguments. C's automatic type conversion rules are a trap for the unwary, they got rid of it completely when they designed C#.

printf is special (same with some other "functions" e.g. min() that are usually macros) because the type of the arguments isn't fixed, as in a common function call.

Example (this particular line seems to work, it just shows the idea).

myTotalTime = ((double)(end-begin))/(double)CLOCKS_PER_SECO;

The constant "2" is suspicious. It might cause the return expression to be standard int. "2UL" should do, or ((uint64_t) 2)

 

Link to comment
Share on other sites

BTW here's one more C "gotcha". Probably not the problem here but worth mentioning.

This
#define CLOCKS_PER_SECO TIMER_FREQ_HZ
is going to bite you when a sloppily written header says

#define TIMER_FREQ_HZ something-1

Use

#define CLOCKS_PER_SECO (TIMER_FREQ_HZ)

instead.

 

Link to comment
Share on other sites

Thanks you for all.

ho fatto queste correzioni ma il risultato non è cambiato per nulla. se vi viene in mente altro vi ringrazio
i do this corrections but the result is not changed.
if you can think anything else, I thank you did you notice the incoherence in the output files?
i print 2 times each variable, but take different values

thanks

Andrea

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...