Commit [r2858] Maximize Restore History

Debian: ARM compilation fixes.

karya 2014-07-26

changed /trunk/debian/control
changed /trunk/debian/patches/series
changed /trunk/debian/changelog
changed /trunk/debian/rules
copied /trunk/debian/patches/fix-setenv-ld_preload.patch -> /trunk/debian/patches/arm-compilation-fix.patch
copied /trunk/debian/patches/fix-brk-restore-for-mtcp_restart.patch -> /trunk/debian/patches/increase-ckpt-timeout-for-autotest.patch
/trunk/debian/control Diff Switch to side-by-side view
Loading...
/trunk/debian/patches/series Diff Switch to side-by-side view
Loading...
/trunk/debian/changelog Diff Switch to side-by-side view
Loading...
/trunk/debian/rules Diff Switch to side-by-side view
Loading...
/trunk/debian/patches/fix-setenv-ld_preload.patch to /trunk/debian/patches/arm-compilation-fix.patch
--- a/trunk/debian/patches/fix-setenv-ld_preload.patch
+++ b/trunk/debian/patches/arm-compilation-fix.patch
@@ -1,93 +1,84 @@
-Description: Fix a racy setenv(LD_PRELOAD, ...)
- See comments in src/dmtcpworker.cpp for more details.
+Description: Compilation fix for older ARM CPUs
+ Older ARM CPUs don't have 'dmb' instruction for memory barriers.  The solution
+ is to use gcc atomic builtin __sync_synchronize() to provide full memory
+ barrier.
  .
- dmtcp (2.2-1) unstable; urgency=low
+ dmtcp (2.3.1-2) unstable; urgency=low
  .
-   * New upstream release 2.2.
-   * Changing distribution from experimental to unstable.
-   * Updated debian standards version to 3.9.5.
-   * Removed libmtcp and libdmtcpaware packages.
-   * Run make check in "slow" mode.
-   * Updated copyright file.
-   * Added debian/NEWS file.
-   * Removed some stale files from install procedure.
+   * Compilation fix for older ARM CPUs.
    * Upload sponsored by Yaroslav Halchenko <debian@onerussian.com>
 Author: Kapil Arya <kapil@ccs.neu.edu>
 
----
-The information above should follow the Patch Tagging Guidelines, please
-checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
-are templates for supplementary fields that you might want to add:
-
-Origin: upstream (svn rev 2750)
-
---- dmtcp-2.2.orig/src/dmtcpworker.cpp
-+++ dmtcp-2.2/src/dmtcpworker.cpp
-@@ -49,6 +49,26 @@ bool dmtcp::DmtcpWorker::_exitInProgress
+--- dmtcp-2.3.1.orig/src/dmtcpplugin.cpp
++++ dmtcp-2.3.1/src/dmtcpplugin.cpp
+@@ -50,13 +50,18 @@ static dmtcp_fnptr_t userHookPreCheckpoi
+ static dmtcp_fnptr_t userHookPostCheckpoint = NULL;
+ static dmtcp_fnptr_t userHookPostRestart = NULL;
  
- void restoreUserLDPRELOAD()
- {
-+  /* A call to setenv() can result in a call to malloc(). The setenv() call may
-+   * also grab an low-level libc lock before calling malloc. The malloc()
-+   * wrapper, if present, will try to acquire the wrapper-lock. This can lead
-+   * to a deadlock in the following scenario:
-+   *
-+   * T1 (main thread): fork() -> acquire exclusive lock
-+   * T2 (ckpt thread): setenv() -> acquire low-level libc lock ->
-+   *                   malloc -> wait for wrapper-exec lock.
-+   * T1: setenv() -> block on low-level libc lock (held by T2).
-+   *
-+   * The simple solution is to not call setenv from DMTCP, and use putenv
-+   * instead. This requires larger change.
-+   *
-+   * Another solution is to set LD_PRELOAD to "" before user main(). This is as
-+   * good as unsetting it.  Later, the ckpt-thread can unset it if it is still
-+   * NULL, but then there is a possibility of a race between user code and
-+   * ckpt-thread.
-+   *
-+   */
++// Remove the dead code once the other part has been verified
++#if 0
+ //I wish we could use pthreads for the trickery in this file, but much of our
+ //code is executed before the thread we want to wake is restored.  Thus we do
+ //it the bad way.
+-#if defined(__i386__) || defined(__x86_64__)
++# if defined(__i386__) || defined(__x86_64__)
+ static inline void memfence(){  asm volatile ("mfence" ::: "memory"); }
+-#elif defined(__arm__)
++# elif defined(__arm__)
+ static inline void memfence(){  asm volatile ("dmb" ::: "memory"); }
++# endif
++#else
++# define memfence() __sync_synchronize()
+ #endif
+ 
+ EXTERNC int dmtcp_is_enabled() { return 1; }
+--- dmtcp-2.3.1.orig/src/membarrier.h
++++ dmtcp-2.3.1/src/membarrier.h
+@@ -35,9 +35,9 @@
+ #  define IMB
+ # endif
+ #elif defined(__arm__)
+-# define RMB asm volatile (".arch armv7-a \n\t dsb ; dmb" : : : "memory")
+-# define WMB asm volatile (".arch armv7-a \n\t dsb ; dmb" : : : "memory")
+-# define IMB asm volatile (".arch armv7-a \n\t isb" : : : "memory")
++# define RMB __sync_synchronize()
++# define WMB __sync_synchronize()
++# define IMB __sync_synchronize()
+ #else
+ # error "instruction architecture not implemented"
+ #endif
+--- dmtcp-2.3.1.orig/src/mtcp/mtcp_restart.c
++++ dmtcp-2.3.1/src/mtcp/mtcp_restart.c
+@@ -64,6 +64,8 @@ void mtcp_check_vdso(char **environ);
+ #define BINARY_NAME "mtcp_restart"
+ #define BINARY_NAME_M32 "mtcp_restart-32"
+ 
++#define memfence() __sync_synchronize()
 +
-   // We have now successfully used LD_PRELOAD to execute prior to main()
-   // Next, hide our value of LD_PRELOAD, in a global variable.
-   // At checkpoint and restart time, we will no longer need our LD_PRELOAD.
-@@ -66,11 +86,14 @@ void restoreUserLDPRELOAD()
-   //   exec("dmtcp_launch --ssh-slave ... ssh ..."), and re-execute.
-   //   This way, we will unset LD_PRELOAD here and now, instead of at that time.
-   char *preload = getenv("LD_PRELOAD");
-+  const char *dummy = "LD_PRELOAD=";
-   char *userPreload =  getenv(ENV_VAR_ORIG_LD_PRELOAD);
-+  strcpy(preload, dummy);
-   if (userPreload == NULL) {
--    _dmtcp_unsetenv("LD_PRELOAD");
-+    //_dmtcp_unsetenv("LD_PRELOAD");
-   } else {
--    setenv("LD_PRELOAD", userPreload, 1);
-+    strcat(preload, userPreload);
-+    //setenv("LD_PRELOAD", userPreload, 1);
-   }
-   JTRACE("LD_PRELOAD") (preload) (userPreload) (getenv(ENV_VAR_HIJACK_LIBS))
-     (getenv(ENV_VAR_HIJACK_LIBS_M32)) (getenv("LD_PRELOAD"));
-@@ -289,6 +312,7 @@ dmtcp::DmtcpWorker::DmtcpWorker (bool en
-     (programName) .Text("This program should not be run under ckpt control");
+ /* struct RestoreInfo to pass all parameters from one function to next.
+  * This must be global (not on stack) at the time that we jump from
+  * original stack to copy of restorememoryareas() on new stack.
+@@ -361,14 +363,19 @@ static void restart_fast_path()
+   void *stack_ptr = rinfo.restore_addr + rinfo.restore_size - MB;
  
-   calculateArgvAndEnvSize();
-+  restoreUserLDPRELOAD();
+ #ifdef __arm__
++#if 1
++  memfence();
++# else
++  // FIXME: Remove the dead code once memfence() is stable.
+ /* This delay loop was required for:
+  *    ARM v7 (rev 3, v71), SAMSUNG EXYNOS5 (Flattened Device Tree)
+  *    gcc-4.8.1 (Ubuntu pre-release for 14.04) ; Linux 3.13.0+ #54
+  */
+-{int x = 10000000;
+-int y = 1000000000;
+-for (; x>0; x--) for (; y>0; y--);
+-}
++//{int x = 10000000;
++//int y = 1000000000;
++//for (; x>0; x--) for (; y>0; y--);
++//}
++# endif
+ #endif
  
-   WorkerState::setCurrentState (WorkerState::RUNNING);
-   // define "Weak Symbols for each library plugin in libdmtcp.so
-@@ -461,15 +485,6 @@ void dmtcp::DmtcpWorker::waitForStage1Su
- 
-   WorkerState::setCurrentState (WorkerState::RUNNING);
- 
--  if (initialStartup) {
--    /* We should not call this function any higher in the logic because it
--     * calls setenv() and if it is running under bash, then getenv() will
--     * not work between the call to setenv() and bash main().
--     */
--    restoreUserLDPRELOAD();
--    initialStartup = 0;
--  }
--
-   waitForCoordinatorMsg ("SUSPEND", DMT_DO_SUSPEND);
- 
-   JTRACE("got SUSPEND message, preparing to acquire all ThreadSync locks");
+ #if 0
/trunk/debian/patches/fix-brk-restore-for-mtcp_restart.patch to /trunk/debian/patches/increase-ckpt-timeout-for-autotest.patch
--- a/trunk/debian/patches/fix-brk-restore-for-mtcp_restart.patch
+++ b/trunk/debian/patches/increase-ckpt-timeout-for-autotest.patch
@@ -1,38 +1,22 @@
-Description: Fix brk restore for mtcp_restart.
- To avoid conflicts with restore-area.
+Description: Increase ckpt timeout for autotest
+ On slower machines, ckpt may not finish in 10 seconds. Increase it to 20
+ seconds.
  .
- dmtcp (2.2-1) unstable; urgency=low
+ dmtcp (2.3.1-2) unstable; urgency=low
  .
-   * New upstream release 2.2.
-   * Changing distribution from experimental to unstable.
-   * Updated debian standards version to 3.9.5.
-   * Removed libmtcp and libdmtcpaware packages.
-   * Run make check in "slow" mode.
-   * Updated copyright file.
-   * Added debian/NEWS file.
-   * Removed some stale files from install procedure.
+   * Compilation fix for older ARM CPUs.
+   * Ckpt timeout increased for slower machines.
    * Upload sponsored by Yaroslav Halchenko <debian@onerussian.com>
 Author: Kapil Arya <kapil@ccs.neu.edu>
 
----
-The information above should follow the Patch Tagging Guidelines, please
-checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
-are templates for supplementary fields that you might want to add:
 
-Origin: upstream (svn rev 2752)
-
---- dmtcp-2.2.orig/src/mtcp/mtcp_restart.c
-+++ dmtcp-2.2/src/mtcp/mtcp_restart.c
-@@ -301,6 +301,12 @@ static void restore_brk(VA saved_brk, VA
-     MTCP_PRINTF("sbrk(%p): errno: %d (bad heap)\n",
- 		 saved_brk, mtcp_sys_errno );
-     mtcp_abort();
-+  } else if (new_brk > current_brk) {
-+    // Now unmap the just mapped extended heap. This is to ensure that we don't
-+    // have overlap with the restore region.
-+    if (mtcp_sys_munmap(current_brk, new_brk - current_brk) == -1) {
-+      MTCP_PRINTF("***WARNING: munmap failed: %d\n", mtcp_sys_errno);
-+    }
-   }
-   if (new_brk != saved_brk) {
-     if (new_brk == current_brk && new_brk > saved_brk)
+--- dmtcp-2.3.1.orig/test/autotest.py
++++ dmtcp-2.3.1/test/autotest.py
+@@ -115,6 +115,7 @@ for i in sys.argv:
+     CYCLES=100000
+   if i=="--slow":
+     SLOW=5
++    TIMEOUT *= 2
+   if i=="--retry-once":
+     RETRY_ONCE = True
+   #TODO:  Install SIGSEGV handler with infinite loop, and add to LD_PRELOAD