UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor harbinnet
Visitor
14,745 Views
Registered: ‎06-29-2008

Why XTime_GetTime() don't work, always return the same value

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

0 Kudos
9 Replies
Explorer
Explorer
14,735 Views
Registered: ‎12-11-2007

Re: Why XTime_GetTime() don't work, always return the same value

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.

 

 

0 Kudos
Visitor metty
Visitor
14,732 Views
Registered: ‎06-30-2008

Re: Why XTime_GetTime() don't work, always return the same value

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!!

 

 

0 Kudos
Explorer
Explorer
14,724 Views
Registered: ‎02-06-2008

Re: Why XTime_GetTime() don't work, always return the same value

Hi

 

Try to save the values to an array and then use the xil_printf.

 

BR

Benjamin Andersen

0 Kudos
Explorer
Explorer
14,716 Views
Registered: ‎12-11-2007

Re: Why XTime_GetTime() don't work, always return the same value

//blush.

 

Thanks for pointing it out. 2power32 looks more reasonable, coz he used %d.

0 Kudos
Explorer
Explorer
14,711 Views
Registered: ‎12-11-2007

Re: Why XTime_GetTime() don't work, always return the same value

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.

0 Kudos
Xilinx Employee
Xilinx Employee
14,691 Views
Registered: ‎01-18-2008

Re: Why XTime_GetTime() don't work, always return the same value

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.

Visitor harbinnet
Visitor
14,655 Views
Registered: ‎06-29-2008

Re: Why XTime_GetTime() don't work, always return the same value

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

0 Kudos
Highlighted
Observer gacrum
Observer
9,926 Views
Registered: ‎07-16-2009

Re: Why XTime_GetTime() don't work, always return the same value

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.

 

0 Kudos
Observer aeonjose
Observer
366 Views
Registered: ‎12-09-2019

Re: Why XTime_GetTime() don't work, always return the same value

thanyou. xil_printf() was the problem. gave printf() and it printed properly. 

0 Kudos