Add a fallback clock for portability reasons
authorAlex Pyrgiotis <apyrgio@grnet.gr>
Thu, 14 Mar 2013 16:29:23 +0000 (18:29 +0200)
committerAlex Pyrgiotis <apyrgio@grnet.gr>
Thu, 14 Mar 2013 16:29:23 +0000 (18:29 +0200)
xseg/peers/user/bench-timer.c
xseg/peers/user/bench-xseg.c
xseg/peers/user/bench-xseg.h

index edb47fa..ac5f51a 100644 (file)
@@ -70,7 +70,7 @@ void timer_start(struct bench *prefs, struct timer *timer)
        if (GET_FLAG(INSANITY, prefs->flags) < timer->insanity)
                return;
 
-       clock_gettime(CLOCK_MONOTONIC_RAW, &timer->start_time);
+       clock_gettime(CLOCK_BENCH, &timer->start_time);
 }
 
 void timer_stop(struct bench *prefs, struct timer *timer,
@@ -95,7 +95,7 @@ void timer_stop(struct bench *prefs, struct timer *timer,
        else
                start_time = *start;
 
-       clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
+       clock_gettime(CLOCK_BENCH, &end_time);
 
        //Get elapsed time by subtracting start time from end time.
        //Subtraction can result to a negative value, so we check for both cases
index 1da07cb..d111191 100644 (file)
@@ -324,7 +324,7 @@ int custom_peer_init(struct peerd *peer, int argc, char *argv[])
 reseed:
        //We proceed to initialise the global_id, and seed variables.
        if (seed == -1) {
-               clock_gettime(CLOCK_MONOTONIC_RAW, &timer_seed);
+               clock_gettime(CLOCK_BENCH, &timer_seed);
                seed = timer_seed.tv_nsec;
        } else {
                set_by_hand = 1;
index ca9e510..e583442 100644 (file)
 
 #include <bench-lfsr.h>
 
+/*
+ * If CLOCK_MONOTONIC_RAW is not defined in our system, use CLOCK_MONOTONIC
+ * instead. CLOCK_MONOTONIC_RAW is preferred since we are guaranteed that the
+ * clock won't skew.
+ */
+#ifdef CLOCK_MONOTONIC_RAW
+#define CLOCK_BENCH CLOCK_MONOTONIC_RAW
+#else
+#define CLOCK_BENCH CLOCK_MONOTONIC
+#endif
+
+
 #define MAX_ARG_LEN 10
 
 /*