cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cocies
Visitor
Visitor
7,980 Views
Registered: ‎08-15-2013

Timer in Zynq

Hallo Everyone,

I want to mess the speed of a function in my Program. Normally I will initiate a timer and look the number of the register, after the function has ran. That is the easiest thing in the standalone mode. But I am new to linux. Can somebody tell me, how to do it under linux?

The Hardware has worked, because it can work in the standalone mode. It will be helpful, when someone give me an easily example for it.

Thanks for any answers.

0 Kudos
8 Replies
pniklas
Adventurer
Adventurer
7,953 Views
Registered: ‎05-16-2012

You can use the following:

 

include

 

#include <time.h>

uint64 time_ns; struct timespec mytime = { 0x00, 0x00}; if(clock_gettime(CLOCK_MONOTONIC, &mytime) != 0) { time_ns = 0; fprintf(stderr, "Could not retrieve current OS time stamp\n"); } else { time_ns = (mytime.tv_sec*1000000000LL + mytime.tv_nsec); }

 Or you can use any other clock.

If you put this in a function, call this function at the beginning and after you finished your stuff. And then calculate the time in between.

 

Regards,

Peter

0 Kudos
7,792 Views
Registered: ‎12-12-2013

Hi

 

I am trying to use the example you had posted in c application code.I get the follwing error

 

error: 'CLOCK_MONOTONIC' undeclared (first use in this function)

 

I have the compiler settings as

${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -std=gnu99

command= arm-xilinx-linux-gnueabi-gcc

 

I have included sys/timing.h

 

Earlier std was set as c99 and there was a suggestion on one of the sites to set it gnu99 in order to get rid of the error. But the error still seems to be there. Could you plz help me with this?

 

0 Kudos
pniklas
Adventurer
Adventurer
7,787 Views
Registered: ‎05-16-2012

Hi,

 

I think you need to link against the RT-library:

"-lrt"

 But please double check that.

 

Regards,

Peter

0 Kudos
7,776 Views
Registered: ‎12-12-2013

Hi

 

Here is my code

 

#include <stdio.h>
#include <time.h>

int main()
{
 struct timespec mytime = { 0x00, 0x00};
 int i=0;
 unsigned long long time_ns;
 if(clock_gettime(CLOCK_MONOTONIC, &mytime) != 0) {
  time_ns = 0;
  printf("Could not retrieve current OS time stamp\n");
 } else {
  time_ns = (mytime.tv_sec*1000000000LL + mytime.tv_nsec);
  printf("Start time %d",time_ns);
 }
 for(i=0;i<100;i++)
    printf("Hello World\n");
}

 

Here is my complier messages. It compiles fine

 

make all

Building file: ../src/helloworld.c

Invoking: ARM Linux gcc compiler

arm-xilinx-linux-gnueabi-gcc -Wall -O0 -g3 -c -fmessage-length=0 -MMD -MP -MF"src/helloworld.d" -MT"src/helloworld.d" -o "src/helloworld.o" "../src/helloworld.c"

../src/helloworld.c: In function 'main':

../src/helloworld.c:32:3: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long unsigned int' [-Wformat]

../src/helloworld.c:37:1: warning: control reaches end of non-void function [-Wreturn-type]

Finished building: ../src/helloworld.c

 

Building target: linux_hello_world_0.elf

Invoking: ARM Linux gcc linker

arm-xilinx-linux-gnueabi-gcc -pg -o "linux_hello_world_0.elf" ./src/helloworld.o

Finished building target: linux_hello_world_0.elf

 

But when I run the configuration this is the error I get

 

zynq> echo $PWD'>'

/root>

zynq>

zynq> /root/hello.elf

/root/hello.elf: /lib/libc.so.6: version `GLIBC_2.17' not found (required by /root/hello.elf)

zynq>

zynq> exit

 

 

0 Kudos
pniklas
Adventurer
Adventurer
7,752 Views
Registered: ‎05-16-2012

I'm not completely sure on this, but it seems to me, that you have a library version mismatch, or that a library is missing in general.

 

It could be that the libraries you use to build your software does not match the libraries that are available on the target.

If this is the case, you would have to, either

-) use a different compiler version, or

-) rebuild the filesystem with the correct libraries

 

If the library is missing completely on the target, you would have to add it to the filesystem.

As I said, I'm not completely sure on this

 

Regards,

Peter

 

 

0 Kudos
7,742 Views
Registered: ‎12-12-2013

Hi

 

Thanks for your response. I found the libc.so.6 on the target. Now how do I know which compiler version will have the same library. I am currently using SDK

 

Release 14.7 Build SDK_P.20131013

 

Is there any other clock or timer I can use to profile my code?

 

Sala

0 Kudos
7,741 Views
Registered: ‎12-12-2013

Hi,

I have it working now. The time time_ns is in ms or ns?

Thanks
Sala
0 Kudos
pniklas
Adventurer
Adventurer
7,733 Views
Registered: ‎05-16-2012

the timespec structure is split in two values:

tv_sec (seconds)

tv_nsec (nanoseconds)

 

so depending on what you want to do, you have to calculate a summed up time, according to your granularity.

In the code I wrote above it would be in nanoseconds.

 

Regards,

Peter

0 Kudos