* Nanoseconds precision
@ 2005-08-25 12:28 Ronaldo.Afonso
2005-08-25 12:40 ` Steve Graegert
0 siblings, 1 reply; 6+ messages in thread
From: Ronaldo.Afonso @ 2005-08-25 12:28 UTC (permalink / raw)
To: linux-c-programming
Hello all,
I need to get nanosecond's precision from the time of my system. I've
analyzing the code of the "date command" and it seems it really doesn't
show me nanosecond's precision, what it, in fact, does is just multiply by
1000 a microsecond's precison number that it gets from a system call. Does
anybody know how I can really get a nanosecond's precision from my system?
Thanks.
Ronaldo Z. Afonso
Projetista de Software
Cyclades Brasil
ronaldo.afonso@cyclades.com.br
Phone: 55 11 5033-3361
Fax: 55 11 5033-3388
www.cyclades.com.br
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Nanoseconds precision
2005-08-25 12:28 Nanoseconds precision Ronaldo.Afonso
@ 2005-08-25 12:40 ` Steve Graegert
2005-08-25 13:20 ` Ronaldo.Afonso
0 siblings, 1 reply; 6+ messages in thread
From: Steve Graegert @ 2005-08-25 12:40 UTC (permalink / raw)
To: Ronaldo.Afonso@cyclades.com; +Cc: linux-c-programming
On 8/25/05, Ronaldo.Afonso@cyclades.com <Ronaldo.Afonso@cyclades.com> wrote:
>
> Hello all,
>
> I need to get nanosecond's precision from the time of my system. I've
> analyzing the code of the "date command" and it seems it really doesn't
> show me nanosecond's precision, what it, in fact, does is just multiply by
> 1000 a microsecond's precison number that it gets from a system call. Does
> anybody know how I can really get a nanosecond's precision from my system?
librt contains time-related functions with nanosecond precision. To
see what inside try this:
$ nm /lib/librt.so.1 | grep clock_
I am sure, there is something of use for you.
Regards
\Steve
--
Steve Graegert <graegerts@gmail.com>
Software Consultancy {C/C++ && Java && .NET}
Mobile: +49 (176) 21248869
Office: +49 (9131) 7126409
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Nanoseconds precision
2005-08-25 12:40 ` Steve Graegert
@ 2005-08-25 13:20 ` Ronaldo.Afonso
2005-08-25 13:37 ` Steve Graegert
0 siblings, 1 reply; 6+ messages in thread
From: Ronaldo.Afonso @ 2005-08-25 13:20 UTC (permalink / raw)
To: Steve Graegert; +Cc: linux-c-programming, linux-c-programming-owner
All the functions in the libc do not show me nanosecond's precision. What
they do is get a microsecond number and multiply it by 1000. So, I realized
that it has to be that way because it's impossible to get a nanosecond's
precison on a machine with a 2Ghz clock. The system needs more than a
nanosecond to execute an instruction, so any nanosecond's precision, at
leas on a 2Ghz machine, should be inaccurate. I'm just sharing what I've
found.
Anyway, I'd like to thank everyone who helped me with this question.
Steve Graegert
<graegerts@gmail.
com> To
Sent by: "Ronaldo.Afonso@cyclades.com"
linux-c-programmi <Ronaldo.Afonso@cyclades.com>
ng-owner@vger.ker cc
nel.org linux-c-programming@vger.kernel.org
Subject
Re: Nanoseconds precision
08/25/2005 09:40
AM
On 8/25/05, Ronaldo.Afonso@cyclades.com <Ronaldo.Afonso@cyclades.com>
wrote:
>
> Hello all,
>
> I need to get nanosecond's precision from the time of my system. I've
> analyzing the code of the "date command" and it seems it really doesn't
> show me nanosecond's precision, what it, in fact, does is just multiply
by
> 1000 a microsecond's precison number that it gets from a system call.
Does
> anybody know how I can really get a nanosecond's precision from my
system?
librt contains time-related functions with nanosecond precision. To
see what inside try this:
$ nm /lib/librt.so.1 | grep clock_
I am sure, there is something of use for you.
Regards
\Steve
--
Steve Graegert <graegerts@gmail.com>
Software Consultancy {C/C++ && Java && .NET}
Mobile: +49 (176) 21248869
Office: +49 (9131) 7126409
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Nanoseconds precision
2005-08-25 13:20 ` Ronaldo.Afonso
@ 2005-08-25 13:37 ` Steve Graegert
2005-08-25 13:41 ` Håkon Hallingstad
2005-08-25 13:45 ` Steve Graegert
0 siblings, 2 replies; 6+ messages in thread
From: Steve Graegert @ 2005-08-25 13:37 UTC (permalink / raw)
To: Ronaldo.Afonso@cyclades.com
Cc: linux-c-programming, linux-c-programming-owner
On 8/25/05, Ronaldo.Afonso@cyclades.com <Ronaldo.Afonso@cyclades.com> wrote:
>
> All the functions in the libc do not show me nanosecond's precision. What
> they do is get a microsecond number and multiply it by 1000. So, I realized
> that it has to be that way because it's impossible to get a nanosecond's
> precison on a machine with a 2Ghz clock. The system needs more than a
> nanosecond to execute an instruction, so any nanosecond's precision, at
> leas on a 2Ghz machine, should be inaccurate. I'm just sharing what I've
> found.
>
> Anyway, I'd like to thank everyone who helped me with this question.
#include <time.h>
int clock_gettime(clockid_t clock_id, struct timespec *tp);
timespec.nv_nsec provides nanosecond resolution. Use CLOCK_REALTIME
for clock_id.
Regards
\Steve
--
Steve Graegert <graegerts@gmail.com>
Software Consultancy {C/C++ && Java && .NET}
Mobile: +49 (176) 21248869
Office: +49 (9131) 7126409
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Nanoseconds precision
2005-08-25 13:37 ` Steve Graegert
@ 2005-08-25 13:41 ` Håkon Hallingstad
2005-08-25 13:45 ` Steve Graegert
1 sibling, 0 replies; 6+ messages in thread
From: Håkon Hallingstad @ 2005-08-25 13:41 UTC (permalink / raw)
To: Linux C Programming
Or you may use the "rdtsc" (Read Time Stamp Counter) assembly instruction.
On Thu, Aug 25, 2005 at 03:37:27PM +0200, Steve Graegert wrote:
> On 8/25/05, Ronaldo.Afonso@cyclades.com <Ronaldo.Afonso@cyclades.com> wrote:
> >
> > All the functions in the libc do not show me nanosecond's precision. What
> > they do is get a microsecond number and multiply it by 1000. So, I realized
> > that it has to be that way because it's impossible to get a nanosecond's
> > precison on a machine with a 2Ghz clock. The system needs more than a
> > nanosecond to execute an instruction, so any nanosecond's precision, at
> > leas on a 2Ghz machine, should be inaccurate. I'm just sharing what I've
> > found.
> >
> > Anyway, I'd like to thank everyone who helped me with this question.
>
> #include <time.h>
> int clock_gettime(clockid_t clock_id, struct timespec *tp);
>
> timespec.nv_nsec provides nanosecond resolution. Use CLOCK_REALTIME
> for clock_id.
>
> Regards
>
> \Steve
>
> --
>
> Steve Graegert <graegerts@gmail.com>
> Software Consultancy {C/C++ && Java && .NET}
> Mobile: +49 (176) 21248869
> Office: +49 (9131) 7126409
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Nanoseconds precision
2005-08-25 13:37 ` Steve Graegert
2005-08-25 13:41 ` Håkon Hallingstad
@ 2005-08-25 13:45 ` Steve Graegert
1 sibling, 0 replies; 6+ messages in thread
From: Steve Graegert @ 2005-08-25 13:45 UTC (permalink / raw)
To: Ronaldo.Afonso@cyclades.com
Cc: linux-c-programming, linux-c-programming-owner
On 8/25/05, Steve Graegert <graegerts@gmail.com> wrote:
> On 8/25/05, Ronaldo.Afonso@cyclades.com <Ronaldo.Afonso@cyclades.com> wrote:
> >
> > All the functions in the libc do not show me nanosecond's precision. What
> > they do is get a microsecond number and multiply it by 1000. So, I realized
> > that it has to be that way because it's impossible to get a nanosecond's
> > precison on a machine with a 2Ghz clock. The system needs more than a
> > nanosecond to execute an instruction, so any nanosecond's precision, at
> > leas on a 2Ghz machine, should be inaccurate. I'm just sharing what I've
> > found.
> >
> > Anyway, I'd like to thank everyone who helped me with this question.
>
> #include <time.h>
> int clock_gettime(clockid_t clock_id, struct timespec *tp);
>
> timespec.nv_nsec provides nanosecond resolution. Use CLOCK_REALTIME
> for clock_id.
BTW: Most of the existing implementations have been fixed to cope with
these new, fast machines. There is a technique known as Time
Interpolation which is implemented on most IA64 machines an in almost
every current 1,6 GHz+ system. So you can be quite sure that the
results are as accurate as possible. I am aware of patches that
utilize memory mapped or CPU counter to do the time interpolations for
any platforms. This allows an easy way to realize a nanosecond
resolution for all platforms.
Regards
\Steve
--
Steve Graegert <graegerts@gmail.com>
Software Consultancy {C/C++ && Java && .NET}
Mobile: +49 (176) 21248869
Office: +49 (9131) 7126409
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-08-25 13:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-25 12:28 Nanoseconds precision Ronaldo.Afonso
2005-08-25 12:40 ` Steve Graegert
2005-08-25 13:20 ` Ronaldo.Afonso
2005-08-25 13:37 ` Steve Graegert
2005-08-25 13:41 ` Håkon Hallingstad
2005-08-25 13:45 ` Steve Graegert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).