Moves some timing func from benchutil to parlib
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 17 Apr 2014 00:49:56 +0000 (17:49 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 17 Apr 2014 00:49:56 +0000 (17:49 -0700)
They don't need to be in benchutil, unlike the other benchutil functions
that use libm.  Also, programs that want to use the simply timing
functions won't need to -lbenchutil (and -lm).

tests/alarm.c
user/benchutil/alarm.c
user/benchutil/include/measure.h
user/benchutil/measure.c
user/parlib/include/timing.h
user/parlib/timing.c

index 7b0375e..84c71f1 100644 (file)
@@ -11,6 +11,7 @@
 #include <event.h>
 #include <measure.h>
 #include <uthread.h>
+#include <timing.h>
 
 /* Am I the only one annoyed at how open has different includes than
  * close/read/write? */
index 2276d48..d83a574 100644 (file)
@@ -36,6 +36,7 @@
 #include <measure.h>
 #include <uthread.h>
 #include <spinlock.h>
+#include <timing.h>
 
 /* Helpers, basically renamed kernel interfaces, with the *tchain. */
 static void __tc_locked_set_alarm(struct timer_chain *tchain,
index ff6a6f3..1b427b7 100644 (file)
@@ -40,13 +40,3 @@ void print_throughput(void **data, unsigned int nr_steps, uint64_t interval,
                       int nr_i, int nr_j,
                       int (*get_sample)(void **data, int i, int j,
                                         uint64_t *sample));
-
-/* Conversion btw tsc ticks and time units.  From Akaros's kern/src/time.c */
-uint64_t tsc2sec(uint64_t tsc_time);
-uint64_t tsc2msec(uint64_t tsc_time);
-uint64_t tsc2usec(uint64_t tsc_time);
-uint64_t tsc2nsec(uint64_t tsc_time);
-uint64_t sec2tsc(uint64_t sec);
-uint64_t msec2tsc(uint64_t msec);
-uint64_t usec2tsc(uint64_t usec);
-uint64_t nsec2tsc(uint64_t nsec);
index 0ce3071..0355e87 100644 (file)
@@ -290,71 +290,3 @@ void print_throughput(void **data, unsigned int nr_steps, uint64_t interval,
        free(next_sample);
        free(step_events);
 }
-
-/* Conversion btw tsc ticks and time units.  From Akaros's kern/src/time.c */
-
-/* We can overflow/wraparound when we multiply up, but we have to divide last,
- * or else we lose precision.  If we're too big and will overflow, we'll
- * sacrifice precision for correctness, and degrade to the next lower level
- * (losing 3 digits worth).  The recursive case shouldn't overflow, since it
- * called something that scaled down the tsc_time by more than 1000. */
-uint64_t tsc2sec(uint64_t tsc_time)
-{
-       return tsc_time / get_tsc_freq();
-}
-
-uint64_t tsc2msec(uint64_t tsc_time)
-{
-       if (mult_will_overflow_u64(tsc_time, 1000))
-               return tsc2sec(tsc_time) * 1000;
-       else 
-               return (tsc_time * 1000) / get_tsc_freq();
-}
-
-uint64_t tsc2usec(uint64_t tsc_time)
-{
-       if (mult_will_overflow_u64(tsc_time, 1000000))
-               return tsc2msec(tsc_time) * 1000;
-       else
-               return (tsc_time * 1000000) / get_tsc_freq();
-}
-
-uint64_t tsc2nsec(uint64_t tsc_time)
-{
-       if (mult_will_overflow_u64(tsc_time, 1000000000))
-               return tsc2usec(tsc_time) * 1000;
-       else
-               return (tsc_time * 1000000000) / get_tsc_freq();
-}
-
-uint64_t sec2tsc(uint64_t sec)
-{
-       if (mult_will_overflow_u64(sec, get_tsc_freq()))
-               return (uint64_t)(-1);
-       else
-               return sec * get_tsc_freq();
-}
-
-uint64_t msec2tsc(uint64_t msec)
-{
-       if (mult_will_overflow_u64(msec, get_tsc_freq()))
-               return sec2tsc(msec / 1000);
-       else
-               return (msec * get_tsc_freq()) / 1000;
-}
-
-uint64_t usec2tsc(uint64_t usec)
-{
-       if (mult_will_overflow_u64(usec, get_tsc_freq()))
-               return msec2tsc(usec / 1000);
-       else
-               return (usec * get_tsc_freq()) / 1000000;
-}
-
-uint64_t nsec2tsc(uint64_t nsec)
-{
-       if (mult_will_overflow_u64(nsec, get_tsc_freq()))
-               return usec2tsc(nsec / 1000);
-       else
-               return (nsec * get_tsc_freq()) / 1000000000;
-}
index 8474038..69b224f 100644 (file)
@@ -1,10 +1,21 @@
 #ifndef __PARLIB_TIMING_H__
 #define __PARLIB_TIMING_H__
 #include <stdint.h>
+#include <tsc-compat.h>
 
 void udelay(uint64_t usec);
 void ndelay(uint64_t nsec);
 uint64_t udiff(uint64_t begin, uint64_t end);
 uint64_t ndiff(uint64_t begin, uint64_t end);
 
+/* Conversion btw tsc ticks and time units.  From Akaros's kern/src/time.c */
+uint64_t tsc2sec(uint64_t tsc_time);
+uint64_t tsc2msec(uint64_t tsc_time);
+uint64_t tsc2usec(uint64_t tsc_time);
+uint64_t tsc2nsec(uint64_t tsc_time);
+uint64_t sec2tsc(uint64_t sec);
+uint64_t msec2tsc(uint64_t msec);
+uint64_t usec2tsc(uint64_t usec);
+uint64_t nsec2tsc(uint64_t nsec);
+
 #endif /* __PARLIB_TIMING_H__ */
index fea7e29..cd54d8c 100644 (file)
@@ -40,3 +40,71 @@ uint64_t ndiff(uint64_t begin, uint64_t end)
 {
        return (end - begin) * 1000000000 /  __procinfo.tsc_freq;
 }
+
+/* Conversion btw tsc ticks and time units.  From Akaros's kern/src/time.c */
+
+/* We can overflow/wraparound when we multiply up, but we have to divide last,
+ * or else we lose precision.  If we're too big and will overflow, we'll
+ * sacrifice precision for correctness, and degrade to the next lower level
+ * (losing 3 digits worth).  The recursive case shouldn't overflow, since it
+ * called something that scaled down the tsc_time by more than 1000. */
+uint64_t tsc2sec(uint64_t tsc_time)
+{
+       return tsc_time / get_tsc_freq();
+}
+
+uint64_t tsc2msec(uint64_t tsc_time)
+{
+       if (mult_will_overflow_u64(tsc_time, 1000))
+               return tsc2sec(tsc_time) * 1000;
+       else
+               return (tsc_time * 1000) / get_tsc_freq();
+}
+
+uint64_t tsc2usec(uint64_t tsc_time)
+{
+       if (mult_will_overflow_u64(tsc_time, 1000000))
+               return tsc2msec(tsc_time) * 1000;
+       else
+               return (tsc_time * 1000000) / get_tsc_freq();
+}
+
+uint64_t tsc2nsec(uint64_t tsc_time)
+{
+       if (mult_will_overflow_u64(tsc_time, 1000000000))
+               return tsc2usec(tsc_time) * 1000;
+       else
+               return (tsc_time * 1000000000) / get_tsc_freq();
+}
+
+uint64_t sec2tsc(uint64_t sec)
+{
+       if (mult_will_overflow_u64(sec, get_tsc_freq()))
+               return (uint64_t)(-1);
+       else
+               return sec * get_tsc_freq();
+}
+
+uint64_t msec2tsc(uint64_t msec)
+{
+       if (mult_will_overflow_u64(msec, get_tsc_freq()))
+               return sec2tsc(msec / 1000);
+       else
+               return (msec * get_tsc_freq()) / 1000;
+}
+
+uint64_t usec2tsc(uint64_t usec)
+{
+       if (mult_will_overflow_u64(usec, get_tsc_freq()))
+               return msec2tsc(usec / 1000);
+       else
+               return (usec * get_tsc_freq()) / 1000000;
+}
+
+uint64_t nsec2tsc(uint64_t nsec)
+{
+       if (mult_will_overflow_u64(nsec, get_tsc_freq()))
+               return usec2tsc(nsec / 1000);
+       else
+               return (nsec * get_tsc_freq()) / 1000000000;
+}