[PATCHv2,3/4] Add generic hp-timing support

Message ID DB5PR08MB10304525CE0855AE190027E2839B0@DB5PR08MB1030.eurprd08.prod.outlook.com
State New
Headers show
Series
  • [PATCHv2,1/4] Cleanup clock_*time includes
Related show

Commit Message

Wilco Dijkstra Jan. 25, 2019, 4:20 p.m.
v2: use stdint.h rather than inttypes.h

Add missing generic hp_timing support. Remove unused HP_TIMING_AVAIL
and HP_SMALL_TIMING_AVAIL.  Use the VDSO clock_gettime (CLOCK_MONOTONIC, )
on targets which don't use an inlined instruction returning time/cycles.

ChangeLog:
2019-01-25  Wilco Dijkstra  <wdijkstr@arm.com>

	* sysdeps/alpha/hp-timing.h (HP_TIMING_AVAIL): Remove define.
	(HP_SMALL_TIMING_AVAIL) Remove.
	* sysdeps/generic/hp-timing.h (HP_TIMING_NONAVAIL): Remove.
	(HP_TIMING_NOW): Add generic implementation.
	* sysdeps/generic/hp-timing-common.h (HP_TIMING_AVAIL): Remove.
	* sysdeps/ia64/hp-timing.h (HP_TIMING_AVAIL): Remove define.
	(HP_SMALL_TIMING_AVAIL) Remove.
	* sysdeps/powerpc/powerpc32/power4/hp-timing.h: Likewise. 	
	* sysdeps/powerpc/powerpc64/hp-timing.h: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/hp-timing.h: Likewise.
	* sysdeps/sparc/sparc64/hp-timing.h: Likewise.
	* sysdeps/x86/hp-timing.h: Likewise.
--

Patch

diff --git a/sysdeps/alpha/hp-timing.h b/sysdeps/alpha/hp-timing.h
index 481132663ce0268de1b3384a7a01084e70d9af66..65db6031ee19dbd86ae42806faa66d00bf09ab12 100644
--- a/sysdeps/alpha/hp-timing.h
+++ b/sysdeps/alpha/hp-timing.h
@@ -21,12 +21,8 @@ 
 #define _HP_TIMING_H	1
 
 /* We always have the timestamp register, but it's got only a 4 second
-   range.  Use it for ld.so profiling only.  */
-#define HP_TIMING_AVAIL		(0)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
-/* We indeed have inlined functions.  */
-#define HP_TIMING_INLINE	(1)
+   range.  Only use it for benchmarking.  */
+#define HP_TIMING_INLINE	(0)
 
 /* We use 32 bit values for the times.  */
 typedef unsigned int hp_timing_t;
diff --git a/sysdeps/generic/hp-timing-common.h b/sysdeps/generic/hp-timing-common.h
index 0ffb8534442165bdb93628bf973cb758bb8546f6..f7a0147a4f2788ae9c7a14b248fd580e7cc04b07 100644
--- a/sysdeps/generic/hp-timing-common.h
+++ b/sysdeps/generic/hp-timing-common.h
@@ -20,8 +20,6 @@ 
 /* In case a platform supports timers in the hardware the following macros
    and types must be defined:
 
-   - HP_TIMING_AVAIL: test for availability.
-
    - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
      implemented using function calls but instead uses some inlined code
      which might simply consist of a few assembler instructions.  We have to
diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
index fb2a6036fc9a208b7d5524c45927c273c96746a8..aad768dc849ff4b81844c4a7514e15f144ffa2f3 100644
--- a/sysdeps/generic/hp-timing.h
+++ b/sysdeps/generic/hp-timing.h
@@ -20,21 +20,19 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* There are no generic definitions for the times.  We could write something
-   using the `gettimeofday' system call where available but the overhead of
-   the system call might be too high.  */
+#include <time.h>
+#include <stdint.h>
+#include <hp-timing-common.h>
 
-/* Provide dummy definitions.  */
-#define HP_TIMING_AVAIL		(0)
-#define HP_SMALL_TIMING_AVAIL	(0)
 #define HP_TIMING_INLINE	(0)
-typedef int hp_timing_t;
-#define HP_TIMING_NOW(var)
-#define HP_TIMING_DIFF(Diff, Start, End)
-#define HP_TIMING_ACCUM_NT(Sum, Diff)
-#define HP_TIMING_PRINT(Buf, Len, Val)
-
-/* Since this implementation is not available we tell the user about it.  */
-#define HP_TIMING_NONAVAIL	1
+
+typedef uint64_t hp_timing_t;
+
+#define HP_TIMING_NOW(var) \
+({								\
+  struct timespec tv;						\
+  __clock_gettime (CLOCK_MONOTONIC, &tv);			\
+  (var) = (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec);	\
+})
 
 #endif	/* hp-timing.h */
diff --git a/sysdeps/ia64/hp-timing.h b/sysdeps/ia64/hp-timing.h
index 17ef023a11564de9afd4eb9bfb706539d4400163..2ca248a530ab239c4789a00fb0e46d6ca43861ef 100644
--- a/sysdeps/ia64/hp-timing.h
+++ b/sysdeps/ia64/hp-timing.h
@@ -20,10 +20,6 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/powerpc/powerpc32/power4/hp-timing.h b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
index 0d77aa0992afd2487abb5bdf894585d81a4c02ee..ed2ca9bc7a0506945fcea65b9ebf699dba0f6ea0 100644
--- a/sysdeps/powerpc/powerpc32/power4/hp-timing.h
+++ b/sysdeps/powerpc/powerpc32/power4/hp-timing.h
@@ -20,10 +20,6 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/powerpc/powerpc64/hp-timing.h b/sysdeps/powerpc/powerpc64/hp-timing.h
index fb9ac1ce2a5e70f4c185380ca8df43cabcc6fd48..01678cd63432a8edd19f274122add87fc7e8a7e8 100644
--- a/sysdeps/powerpc/powerpc64/hp-timing.h
+++ b/sysdeps/powerpc/powerpc64/hp-timing.h
@@ -20,10 +20,6 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-/* We always assume having the timestamp register.  */
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
-
 /* We indeed have inlined functions.  */
 #define HP_TIMING_INLINE	(1)
 
diff --git a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
index 6a4ab08679330b019fc419ec64d4f4bd0079f609..3270c5b40a17c4af5e4c3d9c1f5b028a9a7a8a62 100644
--- a/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
+++ b/sysdeps/sparc/sparc32/sparcv9/hp-timing.h
@@ -20,8 +20,6 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
 #define HP_TIMING_INLINE	(1)
 
 typedef unsigned long long int hp_timing_t;
diff --git a/sysdeps/sparc/sparc64/hp-timing.h b/sysdeps/sparc/sparc64/hp-timing.h
index db95c02a8d91eea8db4a00d542c331e30f9f38e9..0f02b2a98f267d0e90e5297d5855753bc58c907c 100644
--- a/sysdeps/sparc/sparc64/hp-timing.h
+++ b/sysdeps/sparc/sparc64/hp-timing.h
@@ -20,8 +20,6 @@ 
 #ifndef _HP_TIMING_H
 #define _HP_TIMING_H	1
 
-#define HP_TIMING_AVAIL		(1)
-#define HP_SMALL_TIMING_AVAIL	(1)
 #define HP_TIMING_INLINE	(1)
 
 typedef unsigned long int hp_timing_t;
diff --git a/sysdeps/x86/hp-timing.h b/sysdeps/x86/hp-timing.h
index 9b6a998bcdd594d6260f0be9a8a783edbc8d333b..57b4c293cd65485669d359127e580d2ffacd3644 100644
--- a/sysdeps/x86/hp-timing.h
+++ b/sysdeps/x86/hp-timing.h
@@ -22,9 +22,6 @@ 
 #include <isa.h>
 
 #if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664
-/* We always assume having the timestamp register.  */
-# define HP_TIMING_AVAIL	(1)
-# define HP_SMALL_TIMING_AVAIL	(1)
 
 /* We indeed have inlined functions.  */
 # define HP_TIMING_INLINE	(1)