Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cross-process support for MC_ignore
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 19 Dec 2014 08:51:16 +0000 (09:51 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 19 Dec 2014 09:08:40 +0000 (10:08 +0100)
src/mc/mc_checkpoint.c
src/mc/mc_process.c
src/mc/mc_process.h

index 594699d..1825cdc 100644 (file)
@@ -574,6 +574,7 @@ static void mc_free_snapshot_ignored_data_pvoid(void* data) {
 
 static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
 {
+  xbt_assert(snapshot->process);
   snapshot->ignored_data = xbt_dynar_new(sizeof(s_mc_snapshot_ignored_data_t), mc_free_snapshot_ignored_data_pvoid);
 
   // Copy the memory:
@@ -584,13 +585,16 @@ static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
     ignored_data.start = region->addr;
     ignored_data.size = region->size;
     ignored_data.data = malloc(region->size);
-    memcpy(ignored_data.data, region->addr, region->size);
+    // TODO, we should do this once per privatization segment:
+    MC_process_read(snapshot->process,
+      MC_ADDRESS_SPACE_READ_FLAGS_NONE,
+      ignored_data.data, region->addr, region->size, MC_PROCESS_INDEX_DISABLED);
     xbt_dynar_push(snapshot->ignored_data, &ignored_data);
   }
 
   // Zero the memory:
   xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
-    memset(region->addr, 0, region->size);
+    MC_process_clear_memory(snapshot->process, region->addr, region->size);
   }
 
 }
@@ -600,7 +604,8 @@ static void MC_snapshot_ignore_restore(mc_snapshot_t snapshot)
   unsigned int cursor = 0;
   s_mc_snapshot_ignored_data_t ignored_data;
   xbt_dynar_foreach (snapshot->ignored_data, cursor, ignored_data) {
-    memcpy(ignored_data.start, ignored_data.data, ignored_data.size);
+    MC_process_write(snapshot->process,
+      ignored_data.data, ignored_data.start, ignored_data.size);
   }
 }
 
index 23b1c12..207efa9 100644 (file)
@@ -10,6 +10,8 @@
 #include <regex.h>
 #include <sys/mman.h> // PROT_*
 
+#include <pthread.h>
+
 #include <libgen.h>
 
 #include "mc_process.h"
@@ -428,3 +430,33 @@ void MC_process_write(mc_process_t process, const void* local, void* remote, siz
       xbt_die("Write to process %lli failed", (long long) process->pid);
   }
 }
+
+static pthread_once_t zero_buffer_flag = PTHREAD_ONCE_INIT;
+static const void* zero_buffer;
+static const int zero_buffer_size = 10 * 4096;
+
+static void MC_zero_buffer_init(void)
+{
+  int fd = open("/dev/zero", O_RDONLY);
+  if (fd<0)
+    xbt_die("Could not open /dev/zero");
+  zero_buffer = mmap(NULL, zero_buffer_size, PROT_READ, MAP_SHARED, fd, 0);
+  if (zero_buffer == MAP_FAILED)
+    xbt_die("Could not map the zero buffer");
+  close(fd);
+}
+
+void MC_process_clear_memory(mc_process_t process, void* remote, size_t len)
+{
+  if (MC_process_is_self(process)) {
+    memset(remote, 0, len);
+  } else {
+    pthread_once(&zero_buffer_flag, MC_zero_buffer_init);
+    while (len) {
+      size_t s = len > zero_buffer_size ? zero_buffer_size : len;
+      MC_process_write(process, zero_buffer, remote, s);
+      remote = (char*) remote + s;
+      len -= s;
+    }
+  }
+}
index 64a62ac..9825fed 100644 (file)
@@ -123,6 +123,8 @@ const void* MC_process_read(mc_process_t process,
  */
 void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len);
 
+void MC_process_clear_memory(mc_process_t process, void* remote, size_t len);
+
 /* Functions, variables of the process: */
 
 mc_object_info_t MC_process_find_object_info(mc_process_t process, const void* addr);