Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime
@ 2010-05-24 14:54 Nils Carlson
  2010-05-25 14:31 ` Pierre-Marc Fournier
  2010-05-26 16:33 ` Pierre-Marc Fournier
  0 siblings, 2 replies; 4+ messages in thread
From: Nils Carlson @ 2010-05-24 14:54 UTC (permalink / raw)


This patch replaces gettimeofday with clock_gettime(CLOCK_MONOTONIC,)

Signed-off-by: Nils Carlson <nils.carlson at ludd.ltu.se>

diff --git a/include/ust/clock.h b/include/ust/clock.h
index d4b6a9d..bc26d26 100644
--- a/include/ust/clock.h
+++ b/include/ust/clock.h
@@ -18,6 +18,7 @@
 #ifndef UST_CLOCK_H
 #define UST_CLOCK_H

+#include <time.h>
 #include <sys/time.h>
 #include <ust/kcompat/kcompat.h>

@@ -25,7 +26,7 @@

 /* There are two types of clocks that can be used.
    - TSC based clock
-   - gettimeofday() clock
+   - gettimeofday() clock - to guarantee monotonicity use clock_gettime

    Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are
inlined):
      Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
@@ -41,13 +42,13 @@

 static __inline__ u64 trace_clock_read64(void)
 {
-       struct timeval tv;
+       struct timespec ts;
        u64 retval;

-       gettimeofday(&tv, NULL);
-       retval = tv.tv_sec;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+       retval = ts.tv_sec;
        retval *= 1000000;
-       retval += tv.tv_usec;
+       retval += ts.tv_nsec / 1000;

        return retval;
 }
diff --git a/libust/Makefile.am b/libust/Makefile.am
index 2de5857..e357ad1 100644
--- a/libust/Makefile.am
+++ b/libust/Makefile.am
@@ -27,6 +27,7 @@ libust_la_LDFLAGS = -no-undefined -version-info 0:0:0

 libust_la_LIBADD = \
        -lpthread \
+       -lrt \
        $(top_builddir)/snprintf/libustsnprintf.la \
        $(top_builddir)/libustcomm/libustcomm.la







^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime
  2010-05-24 14:54 [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime Nils Carlson
@ 2010-05-25 14:31 ` Pierre-Marc Fournier
  2010-05-25 19:38   ` Nils Carlson
  2010-05-26 16:33 ` Pierre-Marc Fournier
  1 sibling, 1 reply; 4+ messages in thread
From: Pierre-Marc Fournier @ 2010-05-25 14:31 UTC (permalink / raw)


Thanks, comments below.


On 05/24/2010 10:54 AM, Nils Carlson wrote:
> This patch replaces gettimeofday with clock_gettime(CLOCK_MONOTONIC,)
>
> Signed-off-by: Nils Carlson<nils.carlson at ludd.ltu.se>
>
> diff --git a/include/ust/clock.h b/include/ust/clock.h
> index d4b6a9d..bc26d26 100644
> --- a/include/ust/clock.h
> +++ b/include/ust/clock.h
> @@ -18,6 +18,7 @@
>   #ifndef UST_CLOCK_H
>   #define UST_CLOCK_H
>
> +#include<time.h>
>   #include<sys/time.h>
>   #include<ust/kcompat/kcompat.h>
>
> @@ -25,7 +26,7 @@
>
>   /* There are two types of clocks that can be used.
>      - TSC based clock
> -   - gettimeofday() clock
> +   - gettimeofday() clock - to guarantee monotonicity use clock_gettime
>
>      Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are
> inlined):
>        Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
> @@ -41,13 +42,13 @@
>
>   static __inline__ u64 trace_clock_read64(void)
>   {
> -       struct timeval tv;
> +       struct timespec ts;
>          u64 retval;
>
> -       gettimeofday(&tv, NULL);
> -       retval = tv.tv_sec;
> +       clock_gettime(CLOCK_MONOTONIC,&ts);
> +       retval = ts.tv_sec;
>          retval *= 1000000;
> -       retval += tv.tv_usec;
> +       retval += ts.tv_nsec / 1000;

Any specific reason for truncating the nanoseconds here?

>
>          return retval;
>   }
> diff --git a/libust/Makefile.am b/libust/Makefile.am
> index 2de5857..e357ad1 100644
> --- a/libust/Makefile.am
> +++ b/libust/Makefile.am
> @@ -27,6 +27,7 @@ libust_la_LDFLAGS = -no-undefined -version-info 0:0:0
>
>   libust_la_LIBADD = \
>          -lpthread \
> +       -lrt \

I guess this isn't supposed to be part of the patch?

>          $(top_builddir)/snprintf/libustsnprintf.la \
>          $(top_builddir)/libustcomm/libustcomm.la
>
>
>
>
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime
  2010-05-25 14:31 ` Pierre-Marc Fournier
@ 2010-05-25 19:38   ` Nils Carlson
  0 siblings, 0 replies; 4+ messages in thread
From: Nils Carlson @ 2010-05-25 19:38 UTC (permalink / raw)


Comments below,

On May 25, 2010, at 4:31 PM, Pierre-Marc Fournier wrote:

> Thanks, comments below.
>
>
> On 05/24/2010 10:54 AM, Nils Carlson wrote:
>> This patch replaces gettimeofday with clock_gettime(CLOCK_MONOTONIC,)
>>
>> Signed-off-by: Nils Carlson<nils.carlson at ludd.ltu.se>
>>
>> diff --git a/include/ust/clock.h b/include/ust/clock.h
>> index d4b6a9d..bc26d26 100644
>> --- a/include/ust/clock.h
>> +++ b/include/ust/clock.h
>> @@ -18,6 +18,7 @@
>>  #ifndef UST_CLOCK_H
>>  #define UST_CLOCK_H
>>
>> +#include<time.h>
>>  #include<sys/time.h>
>>  #include<ust/kcompat/kcompat.h>
>>
>> @@ -25,7 +26,7 @@
>>
>>  /* There are two types of clocks that can be used.
>>     - TSC based clock
>> -   - gettimeofday() clock
>> +   - gettimeofday() clock - to guarantee monotonicity use  
>> clock_gettime
>>
>>     Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are
>> inlined):
>>       Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
>> @@ -41,13 +42,13 @@
>>
>>  static __inline__ u64 trace_clock_read64(void)
>>  {
>> -       struct timeval tv;
>> +       struct timespec ts;
>>         u64 retval;
>>
>> -       gettimeofday(&tv, NULL);
>> -       retval = tv.tv_sec;
>> +       clock_gettime(CLOCK_MONOTONIC,&ts);
>> +       retval = ts.tv_sec;
>>         retval *= 1000000;
>> -       retval += tv.tv_usec;
>> +       retval += ts.tv_nsec / 1000;
>
> Any specific reason for truncating the nanoseconds here?

Only to provide the same fidelity as the previous code. I don't know  
enough
about how you use the timer, so I didn't take it upon myself to change  
the
resolution.

>
>>
>>         return retval;
>>  }
>> diff --git a/libust/Makefile.am b/libust/Makefile.am
>> index 2de5857..e357ad1 100644
>> --- a/libust/Makefile.am
>> +++ b/libust/Makefile.am
>> @@ -27,6 +27,7 @@ libust_la_LDFLAGS = -no-undefined -version-info  
>> 0:0:0
>>
>>  libust_la_LIBADD = \
>>         -lpthread \
>> +       -lrt \
>
> I guess this isn't supposed to be part of the patch?

It is. clock_gettime requires the realtime clock library.

>
>>         $(top_builddir)/snprintf/libustsnprintf.la \
>>         $(top_builddir)/libustcomm/libustcomm.la
>>
>>
>>
>>
>>
>> _______________________________________________
>> ltt-dev mailing list
>> ltt-dev at lists.casi.polymtl.ca
>> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime
  2010-05-24 14:54 [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime Nils Carlson
  2010-05-25 14:31 ` Pierre-Marc Fournier
@ 2010-05-26 16:33 ` Pierre-Marc Fournier
  1 sibling, 0 replies; 4+ messages in thread
From: Pierre-Marc Fournier @ 2010-05-26 16:33 UTC (permalink / raw)


Merged manually because the patch was corrupt. Perhaps due to your user 
agent?

Also modified things to use the full precision.

Thanks!

pmf

Nils Carlson wrote:
> This patch replaces gettimeofday with clock_gettime(CLOCK_MONOTONIC,)
> 
> Signed-off-by: Nils Carlson <nils.carlson at ludd.ltu.se>
> 
> diff --git a/include/ust/clock.h b/include/ust/clock.h
> index d4b6a9d..bc26d26 100644
> --- a/include/ust/clock.h
> +++ b/include/ust/clock.h
> @@ -18,6 +18,7 @@
>  #ifndef UST_CLOCK_H
>  #define UST_CLOCK_H
> 
> +#include <time.h>
>  #include <sys/time.h>
>  #include <ust/kcompat/kcompat.h>
> 
> @@ -25,7 +26,7 @@
> 
>  /* There are two types of clocks that can be used.
>     - TSC based clock
> -   - gettimeofday() clock
> +   - gettimeofday() clock - to guarantee monotonicity use clock_gettime
> 
>     Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are
> inlined):
>       Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
> @@ -41,13 +42,13 @@
> 
>  static __inline__ u64 trace_clock_read64(void)
>  {
> -       struct timeval tv;
> +       struct timespec ts;
>         u64 retval;
> 
> -       gettimeofday(&tv, NULL);
> -       retval = tv.tv_sec;
> +       clock_gettime(CLOCK_MONOTONIC, &ts);
> +       retval = ts.tv_sec;
>         retval *= 1000000;
> -       retval += tv.tv_usec;
> +       retval += ts.tv_nsec / 1000;
> 
>         return retval;
>  }
> diff --git a/libust/Makefile.am b/libust/Makefile.am
> index 2de5857..e357ad1 100644
> --- a/libust/Makefile.am
> +++ b/libust/Makefile.am
> @@ -27,6 +27,7 @@ libust_la_LDFLAGS = -no-undefined -version-info 0:0:0
> 
>  libust_la_LIBADD = \
>         -lpthread \
> +       -lrt \
>         $(top_builddir)/snprintf/libustsnprintf.la \
>         $(top_builddir)/libustcomm/libustcomm.la
> 
> 
> 
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-05-26 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24 14:54 [ltt-dev] PATCH [0/1]: Replace gettimeofday with clock_gettime Nils Carlson
2010-05-25 14:31 ` Pierre-Marc Fournier
2010-05-25 19:38   ` Nils Carlson
2010-05-26 16:33 ` Pierre-Marc Fournier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox