From 70b17a5ccb8204df1fbbf04d8232492267dd7533 Mon Sep 17 00:00:00 2001
From: Patrik Nyblom <pan@erlang.org>
Date: Tue, 12 Jun 2012 18:45:45 +0200
Subject: Make heart use clock_gettime when available

---
 erts/etc/common/Makefile.in |  5 ++++-
 erts/etc/common/heart.c     | 38 ++++++++++++++++++++++++++++++--------
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in
index 3db4fcba61..20c4c3c2b1 100644
--- a/erts/etc/common/Makefile.in
+++ b/erts/etc/common/Makefile.in
@@ -61,6 +61,9 @@ LD        = @LD@
 LIBS      = @LIBS@
 LDFLAGS   = @LDFLAGS@
 
+# For clock_gettime in heart
+RTLIBS = @LIBRT@
+
 ifeq ($(TARGET),win32)
 ifeq ($(TYPE),debug)
 CFLAGS = $(subst -O2,-g,@CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSDIR) \
@@ -459,7 +462,7 @@ else
 
 $(BINDIR)/heart@EXEEXT@: $(OBJDIR)/heart.o $(ENTRY_OBJ)
 	$(LD) $(LDFLAGS) $(ENTRY_LDFLAGS) -o $@ $(OBJDIR)/heart.o \
-		$(ENTRY_OBJ) $(WINDSOCK)
+		$(RTLIBS) $(ENTRY_OBJ) $(WINDSOCK)
 
 $(OBJDIR)/heart.o: heart.c
 	$(CC) $(CFLAGS) -o $@ -c heart.c
diff --git a/erts/etc/common/heart.c b/erts/etc/common/heart.c
index 4f738947b7..c1f6551d21 100644
--- a/erts/etc/common/heart.c
+++ b/erts/etc/common/heart.c
@@ -102,9 +102,6 @@
  * that can simulate gethrtime with clock_gettime, no use implementing
  * a phony gethrtime in this file as the time questions are so infrequent.
  */
-#if defined(CORRET_USING_TIMES) || defined(GETHRTIME_WITH_CLOCK_GETTIME)
-#  define HEART_CORRECT_USING_TIMES 1
-#endif
 
 #include <stdio.h>
 #include <stddef.h>
@@ -134,7 +131,7 @@
 #  include <sys/time.h>
 #  include <unistd.h>
 #  include <signal.h>
-#  if defined(HEART_CORRECT_USING_TIMES)
+#  if defined(CORRECT_USING_TIMES)
 #    include <sys/times.h>
 #    include <limits.h>
 #  endif
@@ -446,7 +443,8 @@ message_loop(erlin_fd, erlout_fd)
      */
     timestamp(&now);
     if (now > last_received + heart_beat_timeout) {
-		print_error("heart-beat time-out.");
+	print_error("heart-beat time-out, no activity for %lu seconds", 
+		    (unsigned long) (now - last_received));
 		return R_TIMEOUT;
     }
     /*
@@ -1072,7 +1070,31 @@ time_t timestamp(time_t *res)
     return r;
 }
    
-#elif defined(HAVE_GETHRTIME) 
+#elif defined(HAVE_GETHRTIME)  || defined(GETHRTIME_WITH_CLOCK_GETTIME)
+
+#if defined(GETHRTIME_WITH_CLOCK_GETTIME)
+typedef long long SysHrTime;
+
+SysHrTime sys_gethrtime(void);
+
+SysHrTime sys_gethrtime(void)
+{
+    struct timespec ts;
+    long long result;
+    if (clock_gettime(CLOCK_MONOTONIC,&ts) != 0) {
+	print_error("Fatal, could not get clock_monotonic value, terminating! "
+		    "errno = %d\n", errno);
+	exit(1);
+    }
+    result = ((long long) ts.tv_sec) * 1000000000LL + 
+	((long long) ts.tv_nsec);
+    return (SysHrTime) result;
+}
+#else
+typedef hrtime_t SysHrTime;
+#define sys_gethrtime() gethrtime()
+#endif
+
 
 void init_timestamp(void)
 {
@@ -1080,14 +1102,14 @@ void init_timestamp(void)
 
 time_t timestamp(time_t *res)
 {
-    hrtime_t ht = gethrtime();
+    SysHrTime ht = sys_gethrtime();
     time_t r = (time_t) (ht / 1000000000);
     if (res != NULL)
 	*res = r;
     return r;
 }
 
-#elif defined(HEART_CORRECT_USING_TIMES)
+#elif defined(CORRECT_USING_TIMES)
 
 #  ifdef NO_SYSCONF
 #    include <sys/param.h>
-- 
cgit v1.2.3


From d2c7d9ffb3ceffdb324ce93fc2ea2f442f12c1fe Mon Sep 17 00:00:00 2001
From: Erlang/OTP <otp@erlang.org>
Date: Wed, 13 Jun 2012 18:57:14 +0200
Subject: Prepare release

---
 erts/doc/src/notes.xml | 24 ++++++++++++++++++++++++
 erts/vsn.mk            |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/erts/doc/src/notes.xml b/erts/doc/src/notes.xml
index 09950e865b..8ff3f50348 100644
--- a/erts/doc/src/notes.xml
+++ b/erts/doc/src/notes.xml
@@ -30,6 +30,30 @@
   </header>
   <p>This document describes the changes made to the ERTS application.</p>
 
+<section><title>Erts 5.7.5.3</title>
+
+    <section><title>Fixed Bugs and Malfunctions</title>
+      <list>
+        <item>
+          <p>
+	    On Linux systems using heart (erl -heart) and a
+	    HEAR_BEAT_TIMEOUT less than default, heart could fire
+	    even though Erlang was running fine after approx 298 to
+	    497 days (depending on kernel config). This was due to
+	    the behaviour of the times(2) system call. Usage of
+	    times(2) is now replaced with clock_gettime(2) and the
+	    CLOCK_MONOTONIC clock, resulting in a more stable
+	    solution. The Erlang VM itself has used clock_gettime(2)
+	    on linux since before R12B, so this only affects the
+	    heart program.</p>
+          <p>
+	    Own Id: OTP-10111 Aux Id: seq12075 </p>
+        </item>
+      </list>
+    </section>
+
+</section>
+
 <section><title>Erts 5.7.5.2</title>
 
     <section><title>Known Bugs and Problems</title>
diff --git a/erts/vsn.mk b/erts/vsn.mk
index 4e6571c70b..2e830150d8 100644
--- a/erts/vsn.mk
+++ b/erts/vsn.mk
@@ -17,7 +17,7 @@
 # %CopyrightEnd%
 # 
 
-VSN = 5.7.5.2
+VSN = 5.7.5.3
 SYSTEM_VSN = R13B04
 
 # Port number 4365 in 4.2
-- 
cgit v1.2.3