List:Commits« Previous MessageNext Message »
From:jonas Date:June 9 2008 1:57pm
Subject:bzr commit into mysql-5.1-telco-6.2 branch (jonas:2617) Bug#35607
View as plain text  
#At file:///home/jonas/src/telco-6.2/

 2617 jonas@stripped	2008-06-09
      ndb - bug#35607
        use CLOCK_MONOTONIC if present/possible
        both for NdbTick_Current* and NdbCondition_WaitTimeout
modified:
  configure.in
  storage/ndb/src/common/portlib/NdbCondition.c
  storage/ndb/src/common/portlib/NdbTick.c
  storage/ndb/src/common/util/ndb_init.cpp
  storage/ndb/src/kernel/blocks/backup/Backup.cpp
  storage/ndb/tools/restore/restore_main.cpp
  storage/ndb/tools/waiter.cpp

per-file comments:
  configure.in
    1) add AC_CHECK_LIB for clock_gettime as it's defined in -lrt (atleast on my linux)
    2) add AC_CHECK_FUNCS for pthread_condattr_setclock
  storage/ndb/src/common/portlib/NdbCondition.c
    use CLOCK_MONOTONIC is possible
  storage/ndb/src/common/portlib/NdbTick.c
    use CLOCK_MONOTONIC if possible
  storage/ndb/src/common/util/ndb_init.cpp
    check if possible to use CLOCK_MONOTONIC for pthread_cond
  storage/ndb/src/kernel/blocks/backup/Backup.cpp
    s/gettimeofday/NdbTick_CurrentMillisecond/
  storage/ndb/tools/restore/restore_main.cpp
    s/gettimeofday/NdbTick_CurrentMillisecond/
  storage/ndb/tools/waiter.cpp
    s/gettimeofday/NdbTick_CurrentMillisecond/
=== modified file 'configure.in'
--- a/configure.in	2008-05-14 08:33:19 +0000
+++ b/configure.in	2008-06-09 11:57:17 +0000
@@ -2063,6 +2063,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bs
 #
 #
 #
+AC_CHECK_LIB(rt, clock_gettime)
 case "$target" in
  *-*-aix4* | *-*-sco*)
 	# (grr) aix 4.3 has a stub for clock_gettime, (returning ENOSYS)
@@ -2073,6 +2074,7 @@ case "$target" in
  *) AC_CHECK_FUNCS(clock_gettime)
     ;;
 esac
+AC_CHECK_FUNCS(pthread_condattr_setclock)
 
 # Check that isinf() is available in math.h and can be used in both C and C++ 
 # code

=== modified file 'storage/ndb/src/common/portlib/NdbCondition.c'
--- a/storage/ndb/src/common/portlib/NdbCondition.c	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/src/common/portlib/NdbCondition.c	2008-06-09 11:57:17 +0000
@@ -26,7 +26,51 @@ struct NdbCondition
   pthread_cond_t cond;
 };
 
+#ifdef HAVE_CLOCK_GETTIME
+static int clock_id = CLOCK_REALTIME;
+#endif
+
+void
+NdbCondition_Init()
+{
+#if defined HAVE_CLOCK_GETTIME && defined HAVE_PTHREAD_CONDATTR_SETCLOCK
&& \
+    defined CLOCK_MONOTONIC
+  
+  int res, init = 0;
+  pthread_cond_t tmp;
+  pthread_condattr_t attr;
+  if ((res = pthread_condattr_init(&attr)) != 0)
+    goto nogo;
+
+  init = 1;
+  
+  if ((res = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) != 0)
+    goto nogo;
+
+  if ((res = pthread_cond_init(&tmp, &attr)) != 0)
+    goto nogo;
 
+  pthread_condattr_destroy(&attr);
+  pthread_cond_destroy(&tmp);
+
+  clock_id = CLOCK_MONOTONIC;
+  
+  return;
+  
+nogo:
+  if (init)
+  {
+    pthread_condattr_destroy(&attr);
+  }
+  
+  clock_id = CLOCK_REALTIME;
+  fprintf(stderr, 
+          "Failed to use CLOCK_MONOTONIC for pthread_condition res: %u\n", 
+          res);
+  fflush(stderr);
+  return;
+#endif
+}
 
 struct NdbCondition* 
 NdbCondition_Create(void)
@@ -38,8 +82,24 @@ NdbCondition_Create(void)
   
   if (tmpCond == NULL)
     return NULL;
-  
+ 
+#if defined HAVE_CLOCK_GETTIME && defined HAVE_PTHREAD_CONDATTR_SETCLOCK
&& \
+    defined CLOCK_MONOTONIC
+  if (clock_id == CLOCK_MONOTONIC)
+  {
+    pthread_condattr_t attr;
+    pthread_condattr_init(&attr);
+    pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
+    result = pthread_cond_init(&tmpCond->cond, &attr);
+    pthread_condattr_destroy(&attr);
+  }
+  else
+  {
+    result = pthread_cond_init(&tmpCond->cond, NULL);
+  }
+#else
   result = pthread_cond_init(&tmpCond->cond, NULL);
+#endif
   
   assert(result==0);
   return tmpCond;
@@ -73,7 +133,7 @@ NdbCondition_WaitTimeout(struct NdbCondi
     return 1;
   
 #ifdef HAVE_CLOCK_GETTIME
-  clock_gettime(CLOCK_REALTIME, &abstime);
+  clock_gettime(clock_id, &abstime);
 #else
   {
     struct timeval tick_time;

=== modified file 'storage/ndb/src/common/portlib/NdbTick.c'
--- a/storage/ndb/src/common/portlib/NdbTick.c	2007-06-05 16:00:42 +0000
+++ b/storage/ndb/src/common/portlib/NdbTick.c	2008-06-09 11:57:17 +0000
@@ -23,12 +23,18 @@
 #define MICROSEC_PER_MILLISEC 1000
 #define MILLISEC_PER_NANOSEC 1000000
 
-
 #ifdef HAVE_CLOCK_GETTIME
+
+#ifdef CLOCK_MONOTONIC
+#define CLOCK CLOCK_MONOTONIC
+#else
+#define CLOCK CLOCK_REALTIME
+#endif
+
 NDB_TICKS NdbTick_CurrentMillisecond(void)
 {
   struct timespec tick_time;
-  clock_gettime(CLOCK_REALTIME, &tick_time);
+  clock_gettime(CLOCK, &tick_time);
 
   return 
     ((NDB_TICKS)tick_time.tv_sec)  * ((NDB_TICKS)MILLISEC_PER_SEC) +
@@ -38,7 +44,7 @@ NDB_TICKS NdbTick_CurrentMillisecond(voi
 int 
 NdbTick_CurrentMicrosecond(NDB_TICKS * secs, Uint32 * micros){
   struct timespec t;
-  int res = clock_gettime(CLOCK_REALTIME, &t);
+  int res = clock_gettime(CLOCK, &t);
   * secs   = t.tv_sec;
   * micros = t.tv_nsec / 1000;
   return res;

=== modified file 'storage/ndb/src/common/util/ndb_init.cpp'
--- a/storage/ndb/src/common/util/ndb_init.cpp	2008-04-22 19:36:05 +0000
+++ b/storage/ndb/src/common/util/ndb_init.cpp	2008-06-09 11:57:17 +0000
@@ -26,6 +26,8 @@ extern void destroy_event_logger(class E
 
 static int ndb_init_called = 0;
 
+extern "C" void NdbCondition_Init();
+
 extern "C"
 {
 
@@ -44,6 +46,8 @@ ndb_init_internal()
       exit(1);
     }
   }
+
+  NdbCondition_Init();
 }
 
 int

=== modified file 'storage/ndb/src/kernel/blocks/backup/Backup.cpp'
--- a/storage/ndb/src/kernel/blocks/backup/Backup.cpp	2008-05-16 13:08:36 +0000
+++ b/storage/ndb/src/kernel/blocks/backup/Backup.cpp	2008-06-09 11:57:17 +0000
@@ -2367,9 +2367,8 @@ Backup::stopBackupReply(Signal* signal, 
 void
 Backup::initReportStatus(Signal *signal, BackupRecordPtr ptr)
 {
-  struct timeval the_time;
-  gettimeofday(&the_time, 0);
-  ptr.p->m_next_report = the_time.tv_sec + m_backup_report_frequency;
+  Uint64 now = NdbTick_CurrentMillisecond() / 1000;
+  ptr.p->m_next_report = now + m_backup_report_frequency;
 }
 
 void
@@ -2378,12 +2377,11 @@ Backup::checkReportStatus(Signal *signal
   if (m_backup_report_frequency == 0)
     return;
 
-  struct timeval the_time;
-  gettimeofday(&the_time, 0);
-  if (the_time.tv_sec > ptr.p->m_next_report)
+  Uint64 now = NdbTick_CurrentMillisecond() / 1000;
+  if (now > ptr.p->m_next_report)
   {
     reportStatus(signal, ptr);
-    ptr.p->m_next_report = the_time.tv_sec + m_backup_report_frequency;
+    ptr.p->m_next_report = now + m_backup_report_frequency;
   }
 }
 

=== modified file 'storage/ndb/tools/restore/restore_main.cpp'
--- a/storage/ndb/tools/restore/restore_main.cpp	2007-09-12 12:07:08 +0000
+++ b/storage/ndb/tools/restore/restore_main.cpp	2008-06-09 11:57:17 +0000
@@ -648,20 +648,20 @@ static void exitHandler(int code)
 
 static void init_progress()
 {
-  struct timeval the_time;
-  gettimeofday(&the_time, 0);
-  g_report_next = the_time.tv_sec + opt_progress_frequency;
+  Uint64 now = NdbTick_CurrentMillisecond() / 1000;
+  g_report_next = now + opt_progress_frequency;
 }
 
 static int check_progress()
 {
   if (!opt_progress_frequency)
     return 0;
-  struct timeval the_time;
-  gettimeofday(&the_time, 0);
-  if (the_time.tv_sec >= g_report_next)
+
+  Uint64 now = NdbTick_CurrentMillisecond() / 1000;
+  
+  if (now  >= g_report_next)
   {
-    g_report_next = the_time.tv_sec + opt_progress_frequency;
+    g_report_next = now + opt_progress_frequency;
     return 1;
   }
   return 0;

=== modified file 'storage/ndb/tools/waiter.cpp'
--- a/storage/ndb/tools/waiter.cpp	2008-03-20 09:18:53 +0000
+++ b/storage/ndb/tools/waiter.cpp	2008-06-09 11:57:17 +0000
@@ -21,6 +21,7 @@
 #include <NdbMain.h>
 #include <NdbOut.hpp>
 #include <NdbSleep.h>
+#include <NdbTick.h>
 
 #include <NDBT.hpp>
 
@@ -214,12 +215,11 @@ waitClusterStatus(const char* _addr,
   const int MAX_RESET_ATTEMPTS = 10;
   bool allInState = false;
 
-  struct timeval time_now;
-  gettimeofday(&time_now, 0);
-  Int64 timeout_time = time_now.tv_sec + _timeout;
+  Uint64 time_now = NdbTick_CurrentMillisecond();
+  Int64 timeout_time = time_now + 1000 * _timeout;
 
   while (allInState == false){
-    if (_timeout > 0 && time_now.tv_sec > timeout_time){
+    if (_timeout > 0 && time_now > timeout_time){
       /**
        * Timeout has expired waiting for the nodes to enter
        * the state we want
@@ -257,7 +257,7 @@ waitClusterStatus(const char* _addr,
 	    << " resetting timeout "
 	    << resetAttempts << endl;
 
-      timeout_time = time_now.tv_sec + _timeout;
+      timeout_time = time_now + 1000 * _timeout;
 
       resetAttempts++;
     }
@@ -290,7 +290,8 @@ waitClusterStatus(const char* _addr,
     }
 
     attempts++;
-    gettimeofday(&time_now, 0);
+    
+    time_now = NdbTick_CurrentMillisecond();
   }
   return 0;
 }

Thread
bzr commit into mysql-5.1-telco-6.2 branch (jonas:2617) Bug#35607jonas9 Jun