06-29-2008 09:39 PM
Hi everyone, I write the following code to get the running time of my program. But XTime_GetTime() always return the same value: xtime1=13
I am running the program on a PPC system. Is there any switch or ENABLE BIT I should turn on before using XTime_GetTime()?
#include <xtime_l.h>
XTime xtime1;
while(1){
XTime_GetTime(&xtime1);
xil_printf("xtime1=%d \n\r",xtime1);
}
result read from COM1:
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
xtime1=13
........
Best regard,
Lipton Zeng
06-30-2008 01:00 AM
Hi,
This is weird, but it dose not imply that the XTime_GetTime() function dose not work.
One hint, xil_printf() itself simply takes quite a lot of CPU cycles, it might be a coincidence that your xil_printf() plus the jump instruction takes 2power64 cpu cycles.
Try to measure something else without xil_printf() and such like functions involved.
06-30-2008 01:14 AM
jeffsen,
think about what you have written. 2^64 clock cycles are 18446744073709551616 clock cycles, which means at a clock frequency of 300 MHz you need 61489146912 seconds for the counter to overflow, which are 1949 years!!
06-30-2008 01:26 AM
Hi
Try to save the values to an array and then use the xil_printf.
BR
Benjamin Andersen
06-30-2008 04:55 AM
//blush.
Thanks for pointing it out. 2power32 looks more reasonable, coz he used %d.
06-30-2008 05:17 AM
Acutally this is quite absurd! I can't figure out how dose this happen.
I looked into the assembly code, nothing seems wrong, while I got the same result.
06-30-2008 09:09 AM
sizeof(XTime) = 8. It is an unsigned long long, which is not supported by xil_printf. So you'd either want to do:
XTime_GetTime(&t);
l = t & ~0x0;
h = (t >> 32);
xil_printf("tl = %x %x\n\r", l, h);
where l & h are unsigned int's and should print the lower & upper halfs.
Or you might just want to do a printf %llu.
07-02-2008 01:22 AM
Thanks for all your replies.
Actually my program is something like this:
#include <xtime_l.h>
XTime xtime1,xtime2;
int tmp_time;
XTime_GetTime(&xtime1);
func1(...);
func2(...);
...
XTime_GetTime(&xtime2);
tmp_time = xtime2 - xtime1;
xil_printf("tmp_time =%d \n\r",tmp_time );
result:
tmp_time = 0;
So tmp_time should not be too big to xil_printf using %d.
I tried to print out xtime2 and xtime1. I found that both of them were 13. So I put XTime_GetTime() in a while(1) loop and printed it out.
Later I will try it in another EDK project.
Best regards,
Lipton Zeng
02-12-2013 08:37 AM
This is an extremely old thread, but it was the top result when I searched for XTime_GetTime.
I ran into the exact same thing. I believe the function is working properly, we were not printing it out properly.
XTime is a long long, so you need to use %lld or type cast it to what you are trying to print.
example:
#include "xtime_l.h
int main()
{
XTime time1;
XTime time2;
XTime_GetTime((XTime *) &time1);
//do something here that you want to time
XTime_GetTime((XTime *) &time2);
printf("Time1 %d, Time2 %d, Diff %d\n\r", time1, time2, time2-time1);
printf("Time1 %lld, Time2 %lld, Diff %lld\n\r", time1, time2, time2-time1);
printf("Time1 %d, Time2 %d, Diff %d\n\r", (int)time1, (int)time2, (int)(time2-time1));
return 0;
}
This outputs:
Time1 13, Time2 0, Diff 3279902
Time1 3279902, Time2 3280035, Diff 133
Time1 3279902, Time2 3280035, Diff 133
The first printf is incorrect, but the next to work as expected. I think the last one only works because the actual value in time1 and time2 can be represented with a 32 bit number.
To get seconds you need to divide by the PPC Clock speed.
12-12-2019 12:45 AM
thanyou. xil_printf() was the problem. gave printf() and it printed properly.