Skip to contentSkip to conversation

Timing calculation

Xenomai-help prakash srinivasan 4 participants 11 messages Aug 12, 2010 – Aug 14, 2010

lore
Share & tools
lore
#0 lore raw

Deal All,

I am executing a simple for() loop and like to calculate the time period for this loop. I used rt_timer_read(). As per the document, it mentioned that rt_timer_read() returns the current time expressed in clock ticks. I could not able to get an clear idea about it. Suppose if i convert it by using rt_timer_ticks2ns(), I am not getting the proper output. My code is,

RTIME start, end;

...

...

start=rt_timer_read();

for()

{}

end=rt_timer_read();

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

I would like to convert the ticks into nano seconds first and then into micro seconds. The final result is irrelevant. I am not sure, where is the issue. Help me to find the timings details properly.

In the example program trivial-periodic.c, they mentioned

"NOTE: printf may have unexpected impact on the timing of your program. It is used here in the critical loop only for demonstration purposes."

Why?

-Prakash

#1 lore raw

2010/8/12 prakash srinivasan <[email protected]>

Quoted 13 lines

Deal All,
I am executing a simple for() loop and like to calculate the time period for this loop. I used rt_timer_read(). As per the document, it mentioned that rt_timer_read() returns the current time expressed in clock ticks. I could not able to get an clear idea about it. Suppose if i convert it by using rt_timer_ticks2ns(), I am not getting the proper output. My code is,

RTIME start, end;
...
...
start=rt_timer_read();
for()
{}
end=rt_timer_read();
printf(TOTAL LOOP TIMING=%ld usn", (long)((rt_timer_ticks2ns(end-start))/1000);

Quoted 1 line

I would like to convert the ticks into nano seconds first and then into micro seconds. The final result is irrelevant. I am not sure, where is the issue. Help me to find the timings details properly.

Irrelevant how? Not repeatable?
What are the printed values?

Did you try without rt_timer_ticks2ns first?

Did you see the note on rt_timer_read() ?
http://www.xenomai.org/documentation/xenomai-2.5/html/api/group__native__timer.html#g9665d6947e29d1a19dafb5401b0f6285
Note:
The value returned will represent a count of jiffies if the native
skin is bound to a periodic time base (see CONFIG_XENO_OPT_NATIVE_PERIOD), or nanoseconds otherwise.

Quoted 4 lines

In the example program trivial-periodic.c, they mentioned

"NOTE: printf may have unexpected impact on the timing of your program. It is used here in the critical loop only for demonstration purposes." Why?

Because printf is a complicated function ending up with syscalls which would make you switch to secondar mode etc.... (you can search the ML for answers on this subject).

Note that in your case the printf is after the loop (and timer read) so this must not be the problem.

--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org

#2 lore raw

On Thu, 12 Aug 2010 15:46:51 +0530 wrote

Quoted 28 lines
Quoted 27 lines

2010/8/12 prakash srinivasan

Deal All,

I am executing a simple for() loop and like to calculate the time period for this loop. I used rt_timer_read(). As per the document, it mentioned that rt_timer_read() returns the current time expressed in clock ticks. I could not able to get an clear idea about it. Suppose if i convert it by using rt_timer_ticks2ns(), I am not getting the proper output. My code is,

RTIME start, end;

...

...

start=rt_timer_read();

for()

{}

end=rt_timer_read();

printf(TOTAL LOOP TIMING=%ld usn", (long)((rt_timer_ticks2ns(end-start))/1000);

Quoted 5 lines
Quoted 1 line

I would like to convert the ticks into nano seconds first and then into micro seconds. The final result is irrelevant. I am not sure, where is the issue. Help me to find the timings details properly.

Irrelevant how? Not repeatable?

Early I gave (long)(start). The output was in negative.

Quoted 3 lines

What are the printed values?

Did you try without rt_timer_ticks2ns first?

Output without rt_time_ticks2ns()::

printf("Starting time: %ld\n",(long)start);

Starting time: 445465374

printf("End time: %ld\n",(long)end);

End time: 927680697

printf (Difference time:%ld\n",(long)(end-start))

Difference time: 482215323

Output with rt_timer_ticks2ns()::

printf("Starting time: %ld\n",(long)rt_timer_ticks2ns(start));

Starting time: -2090279950

printf("End time: %ld\n",(long)rt_timer_ticks2ns(end));

End time: -1168915612

printf (Difference time:%ld\n",(long)rt_timer_ticks2ns(end-start))

Difference time: 921364338

whether my call is correct, (long) rt_timerticks2ns(end-start)?

-Prakash

#3 lore raw
In reply to prakash srinivasan
Quoted 14 lines · prakash srinivasan

Deal All,

I am executing a simple for() loop and like to calculate the time period for this loop. I used rt_timer_read(). As per the document, it mentioned that rt_timer_read() returns the current time expressed in clock ticks. I could not able to get an clear idea about it. Suppose if i convert it by using rt_timer_ticks2ns(), I am not getting the proper output. My code is,

RTIME start, end;

...

...

start=rt_timer_read();

Quoted 7 lines

for()

{}

end=rt_timer_read();

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

What does:

  printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

report.

Wolfgang.

#4 lore raw

2010/8/12 Wolfgang Grandegger <[email protected]>:

Quoted 9 lines · prakash srinivasan
Quoted 8 lines

start=rt_timer_read();

for()

{}

Quoted 7 lines
Quoted 3 lines

end=rt_timer_read();

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

What does:

 printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

I was trying to check the exact type of
RTIME (return type of rt_timer_read())
and
SRTIME (expectted argument type and return type of rt_timer_ticks2ns) and
RTIME unsigned long long

so theoretically you would need the "%lld" (long long) format for rt_timer_ticks2ns returned value.

whereas you would need "%llu" for rt_timer_read() value.

If you try to print unsigned value with a signed format you'll get signed "print out" interpretation of the unsigned value, as you said:
"Early I gave (long)(start). The output was negative."

May be it would be worth having some RTIME_FORMAT
and STRIME_FORMAT macros in order to avoid that?

Signature · 3 lines
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
#6 lore raw
In reply to Wolfgang Grandegger
Quoted 10 lines
Quoted 3 lines

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

What does:

Quoted 5 lines

printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

report.

TOTAL LOOP TIMING = 5377070 us

In this case, the (unsigned) (long) (long)tart returns 1069623206

and (unsigned) (long) (long)end returns 2151726697

-Prakash

#10 lore raw
In reply to Wolfgang Grandegger
Quoted 7 lines

What does:

printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

report.

TOTAL LOOP TIMING= 5377070 us

In this case (unsigned)(long)(long)start returns 1069623206 and (unsigned)(long)(long)end returns 2151726697

-Prakash

#5 lore raw
In reply to Eric Noulard
Quoted 9 lines

I was trying to check the exact type of RTIME (return type of rt_timer_read()) and SRTIME (expectted argument type and return type of rt_timer_ticks2ns) and RTIME unsigned long long

so theoretically you would need the "%lld" (long long) format for

rt_timer_ticks2ns returned value.

Quoted 5 lines

whereas you would need "%llu" for rt_timer_read() value.

If you try to print unsigned value with a signed format you'll get

signed "print out" interpretation of the unsigned value, as you said:

"Early I gave (long)(start). The output was negative."

Quoted 7 lines

May be it would be worth having some RTIME_FORMAT and STRIME_FORMAT macros in order to avoid that?

Now I modified (unsigned)(long)(long) as return format for start and end. The output is,

Starting Time : 4295048924899

End time : 4297258900362

(long)(long)rt_timer_ticks2ns(end-start)= -1790994340162556031

-Prakash

#7 lore raw
In reply to asprakash_83
Quoted 5 lines · On 08/12/2010 05:38 PM, asprakash_83 wrote:
Quoted 4 lines
Quoted 2 lines

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

What does:

Quoted 7 lines
Quoted 3 lines

printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

report.

TOTAL LOOP TIMING = 5377070 us
In this case, the (unsigned) (long) (long)tart returns 1069623206 and (unsigned) (long) (long)end returns 2151726697

Are you happy with that result? Did really pass approx. 5 seconds between start and end?

Wolfgang.

#8 lore raw
Quoted 26 lines
Quoted 23 lines
Quoted 8 lines
Quoted 1 line

printf(TOTAL LOOP TIMING=%ld us\n", (long)((rt_timer_ticks2ns(end-start))/1000);

What does:

Quoted 5 lines

printf(TOTAL LOOP TIMING=%lld us\n", rt_timer_ticks2ns(end-start)/1000);

report.

TOTAL LOOP TIMING = 5377070 us

In this case, the (unsigned) (long) (long)tart returns 1069623206

Quoted 5 lines
Quoted 1 line

and (unsigned) (long) (long)end returns 2151726697

Are you happy with that result? Did really pass approx. 5 seconds

between start and end?

Definitely not and I am not confident about this output. Coz in this loop period I am sending datas from client to the server. Visibly noted that the server is getting all the datas within a second. So I am not sure the 5 sec is the right output. I just like to know all the above conversions are correct? and is it ok that the start ticks can be more than the end ticks?

-Prakash

#9 lore raw
Quoted 9 lines · prakash srinivasan
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

printf(TOTAL LOOP TIMING=%ld us\n",
(long)((rt_timer_ticks2ns(end-start))/1000);

What does: printf(TOTAL LOOP TIMING=%lld us\n",
rt_timer_ticks2ns(end-start)/1000); report.

TOTAL LOOP TIMING = 5377070 us In this case, the (unsigned) (long) (long)tart returns 1069623206 and (unsigned) (long) (long)end returns 2151726697

Are you happy with that result? Did really pass approx. 5 seconds

between start and end?

Could you format your mails correctly to make them readable? Use text, not HTML, truncate at 72 characters, and use > as a quotation mark, meaning that one '>' is the sign that you quote someone, two '>' is you quoting someone who quoted someone else, etc... I am really sorry to have to tell you about this, this is really basic knowledge of the netiquette, we should not have to tell you about it.

Quoted 6 lines

Definitely not and I am not confident about this output. Coz in this loop period I am sending datas from client to the server. Visibly noted that the server is getting all the datas within a second. So I am not sure the 5 sec is the right output. I just like to know all the above conversions are correct? and is it ok that the start ticks can be more than the end ticks?

The result of rt_timer_read is a long long, so, if you cast it to an unsigned, you loose the most significant bits. So, the result is totally meaningless. This again, is basic knowledge of the C language, we should not have to explain.

Your bug report is quite insufficient, we do not even know what version of Xenomai you use, maybe you are reporting a bug which has been solved a long time ago. Neither do we know what version of Linux and of the Adoes patch you use, or the contents of your .config file. We do not have a self-contained example that we can run to try and reproduce your issue.

So if you want some answers, please give us the means to answer you.

Signature · 1 line
					    Gilles.