cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
harbinnet
Visitor
Visitor
16,203 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
Reply
9 Replies
jeffsen
Explorer
Explorer
16,193 Views
Registered: ‎12-11-2007

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
Reply
Anonymous
Not applicable
16,190 Views

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
Reply
bandersen
Explorer
Explorer
16,182 Views
Registered: ‎02-06-2008

Hi

 

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

 

BR

Benjamin Andersen

0 Kudos
Reply
jeffsen
Explorer
Explorer
16,174 Views
Registered: ‎12-11-2007

//blush.

 

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

0 Kudos
Reply
jeffsen
Explorer
Explorer
16,169 Views
Registered: ‎12-11-2007

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
Reply
vsiva
Xilinx Employee
Xilinx Employee
16,149 Views
Registered: ‎01-18-2008

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.

harbinnet
Visitor
Visitor
16,113 Views
Registered: ‎06-29-2008

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
Reply
gacrum
Observer
Observer
11,384 Views
Registered: ‎07-16-2009

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
Reply
aeonjose
Participant
Participant
1,824 Views
Registered: ‎12-09-2019

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

0 Kudos
Reply