Преглед изворни кода

fix raw monotonic clock detection and usage

Samuel Thibault пре 15 година
родитељ
комит
f3768ddfa9
2 измењених фајлова са 32 додато и 10 уклоњено
  1. 3 3
      src/common/timing.c
  2. 29 7
      src/common/timing.h

+ 3 - 3
src/common/timing.c

@@ -18,7 +18,7 @@
 
 static double reference_start_time;
 
-#ifdef STARPU_HAVE_CLOCK_GETTIME
+#ifdef HAVE_CLOCK_GETTIME
 
 #define TICK_DIFF(t1, t2) ((long long)((t2).ts.tv_sec*1e9 + (t2).ts.tv_nsec) + \
 				- (long long)((t1).ts.tv_sec*1e9) + (long long)(t1).ts.tv_nsec)
@@ -55,7 +55,7 @@ inline double _starpu_timing_now(void)
 	return (absolute_now - reference_start_time);
 }
 
-#else // STARPU_HAVE_CLOCK_GETTIME
+#else // HAVE_CLOCK_GETTIME
 
 #define TICK_RAW_DIFF(t1, t2) ((t2).tick - (t1).tick)
 #define TICK_DIFF(t1, t2) (TICK_RAW_DIFF(t1, t2) - residual)
@@ -121,4 +121,4 @@ inline double _starpu_timing_now(void)
 
 }
 
-#endif // STARPU_HAVE_CLOCK_GETTIME
+#endif // HAVE_CLOCK_GETTIME

+ 29 - 7
src/common/timing.h

@@ -32,7 +32,7 @@
 #include <common/config.h>
 #include <starpu.h>
 
-#ifdef STARPU_HAVE_CLOCK_GETTIME
+#ifdef HAVE_CLOCK_GETTIME
 #include <time.h>
 #ifndef _POSIX_C_SOURCE
 /* for clock_gettime */
@@ -45,17 +45,39 @@ typedef struct starpu_tick_s
 	struct timespec ts;
 } starpu_tick_t;
 
+#ifdef __linux__
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW 4
+#endif
+#endif
 /* Modern CPUs' clocks are usually not synchronized so we use a monotonic clock
  * to have consistent timing measurements. The CLOCK_MONOTONIC_RAW clock is not
  * subject to NTP adjustments, but is not available on all systems (in that
  * case we use the CLOCK_MONOTONIC clock instead). */
-#ifndef CLOCK_MONOTONIC_RAW
-#define STARPU_GET_TICK(t) clock_gettime(CLOCK_MONOTONIC_RAW, &((t).ts))
-#else
-#define STARPU_GET_TICK(t) clock_gettime(CLOCK_MONOTONIC, &((t).ts))
+static inline void starpu_get_tick(starpu_tick_t *t) {
+#ifdef CLOCK_MONOTONIC_RAW
+	static int raw_supported = 0;
+	switch (raw_supported) {
+	case -1:
+		break;
+	case 1:
+		clock_gettime(CLOCK_MONOTONIC_RAW, &t->ts);
+		return;
+	case 0:
+		if (clock_gettime(CLOCK_MONOTONIC_RAW, &t->ts)) {
+			raw_supported = -1;
+			break;
+		} else {
+			raw_supported = 1;
+			return;
+		}
+	}
 #endif
+	clock_gettime(CLOCK_MONOTONIC, &t->ts);
+}
+#define STARPU_GET_TICK(t) starpu_get_tick(&(t))
 
-#else // !STARPU_HAVE_CLOCK_GETTIME
+#else // !HAVE_CLOCK_GETTIME
 
 typedef union starpu_u_tick
 {
@@ -78,7 +100,7 @@ typedef union starpu_u_tick
 #  define STARPU_GET_TICK(t) do {} while(0);
 #endif
 
-#endif // STARPU_HAVE_CLOCK_GETTIME
+#endif // HAVE_CLOCK_GETTIME
 
 void __attribute__ ((unused)) _starpu_timing_init(void);
 inline double __attribute__ ((unused)) _starpu_tick2usec(long long t);