]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Use hp-timing on libmemusage
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 16 Dec 2021 16:43:38 +0000 (13:43 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Dec 2021 17:57:57 +0000 (14:57 -0300)
Instead of reimplemeting on GETTIME macro.

malloc/memusage.c
sysdeps/generic/memusage.h
sysdeps/i386/i686/memusage.h
sysdeps/ia64/memusage.h
sysdeps/x86_64/memusage.h

index de39ad1c1a27fd63bb4051c68e0d40813ef571ae..eaf4965e5e2a8e66c0c97967938dda529bb5c390 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/time.h>
 
 #include <memusage.h>
+#include <hp-timing.h>
 
 /* Pointer to the real functions.  These are determined used `dlsym'
    when really needed.  */
@@ -114,6 +115,23 @@ static struct entry buffer[2 * DEFAULT_BUFFER_SIZE];
 static uint32_t buffer_cnt;
 static struct entry first;
 
+static void
+gettime (struct entry *e)
+{
+#if HP_TIMING_INLINE
+  hp_timing_t now;
+  HP_TIMING_NOW (now);
+  e->time_low = now & 0xffffffff;
+  e->time_high = now >> 32;
+#else
+  struct __timespec64 now;
+  uint64_t usecs;
+  __clock_gettime64 (CLOCK_REALTIME, &now);
+  usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000;
+  e->time_low = usecs & 0xffffffff;
+  e->time_high = usecs >> 32;
+#endif
+}
 
 /* Update the global data after a successful function call.  */
 static void
@@ -177,7 +195,7 @@ update_data (struct header *result, size_t len, size_t old_len)
 
       buffer[idx].heap = current_heap;
       buffer[idx].stack = current_stack;
-      GETTIME (buffer[idx].time_low, buffer[idx].time_high);
+      gettime (&buffer[idx]);
 
       /* Write out buffer if it is full.  */
       if (idx + 1 == buffer_size)
@@ -267,7 +285,7 @@ me (void)
               /* Write the first entry.  */
               first.heap = 0;
               first.stack = 0;
-              GETTIME (first.time_low, first.time_high);
+              gettime (&first);
               /* Write it two times since we need the starting and end time. */
               write (fd, &first, sizeof (first));
               write (fd, &first, sizeof (first));
@@ -818,7 +836,7 @@ dest (void)
          stack.  */
       first.heap = peak_heap;
       first.stack = peak_stack;
-      GETTIME (first.time_low, first.time_high);
+      gettime (&first);
       write (fd, &first, sizeof (struct entry));
 
       /* Close the file.  */
index c9bde5cd11c4cdd168c4bb2403e38f36759e9bbf..514bd058d21608b8e410ecfd6ef20b6573e327b1 100644 (file)
 # warning "GETSP is not defined for this architecture."
 # define GETSP 0
 #endif
-
-#ifndef GETTIME
-# define GETTIME(low,high)                                                \
-  {                                                                       \
-    struct __timespec64 now;                                              \
-    uint64_t usecs;                                                       \
-    __clock_gettime64 (CLOCK_REALTIME, &now);                             \
-    usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
-    low = usecs & 0xffffffff;                                             \
-    high = usecs >> 32;                                                           \
-  }
-#endif
index 08b7831e12431f3c4e95b9bc9edccdf53701d448..07b241263c57f7de32609335d51e2d67f95754e6 100644 (file)
@@ -16,6 +16,5 @@
    <https://www.gnu.org/licenses/>.  */
 
 #define GETSP() ({ register uintptr_t stack_ptr asm ("esp"); stack_ptr; })
-#define GETTIME(low,high) asm ("rdtsc" : "=a" (low), "=d" (high))
 
 #include <sysdeps/generic/memusage.h>
index 3c3a5260078fac9cf8e7e73d3b1499c579caf0c0..33fd6ec899e6239c9c8b6473140d72a27e987c61 100644 (file)
 #include <hp-timing.h>
 
 #define GETSP() ({ register uintptr_t stack_ptr asm ("%r12"); stack_ptr; })
-#define GETTIME(low, high) \
-  {                                                                          \
-    hp_timing_t __now;                                                       \
-    HP_TIMING_NOW (__now);                                                   \
-    low = __now & 0xffffffff;                                                \
-    high = __now >> 32;                                                              \
-  }
 
 #include <sysdeps/generic/memusage.h>
index 568dd5512dc96c0bd426141875b28f5de85d270b..6652fc5da1375165378306ce712cb812b6800d3f 100644 (file)
@@ -16,6 +16,5 @@
    <https://www.gnu.org/licenses/>.  */
 
 #define GETSP() ({ register uintptr_t stack_ptr asm ("rsp"); stack_ptr; })
-#define GETTIME(low,high) asm ("rdtsc" : "=a" (low), "=d" (high))
 
 #include <sysdeps/generic/memusage.h>