Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Implements privatization support for MC_process_read
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 18 Dec 2014 15:03:03 +0000 (16:03 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 19 Dec 2014 09:08:34 +0000 (10:08 +0100)
This is currently needed for cross-process MC in order to read the
heap state.

src/mc/mc_checkpoint.c
src/mc/mc_object_info.c
src/mc/mc_object_info.h
src/mc/mc_process.c
src/mc/mc_process.h

index 774562e..594699d 100644 (file)
@@ -235,8 +235,8 @@ static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot, mc_region_
     ref_reg = mc_model_checker->parent_snapshot->snapshot_regions[index];
 
   mc_mem_region_t region;
     ref_reg = mc_model_checker->parent_snapshot->snapshot_regions[index];
 
   mc_mem_region_t region;
-  const bool privatization_aware = object_info && MC_object_info_executable(object_info);
-  if (privatization_aware && smpi_privatize_global_variables && smpi_process_count())
+  const bool privatization_aware = MC_object_info_is_privatized(object_info);
+  if (privatization_aware && smpi_process_count())
     region = MC_region_new_privatized(type, start_addr, permanent_addr, size, ref_reg);
   else
     region = MC_region_new(type, start_addr, permanent_addr, size, ref_reg);
     region = MC_region_new_privatized(type, start_addr, permanent_addr, size, ref_reg);
   else
     region = MC_region_new(type, start_addr, permanent_addr, size, ref_reg);
@@ -322,6 +322,18 @@ void MC_find_object_address(memory_map_t maps, mc_object_info_t result)
     i++;
   }
 
     i++;
   }
 
+  result->start = result->start_rw;
+  if ((const void*) result->start_ro > result->start)
+    result->start = result->start_ro;
+  if ((const void*) result->start_exec > result->start)
+    result->start = result->start_exec;
+
+  result->end = result->end_rw;
+  if (result->end_ro && (const void*) result->end_ro < result->end)
+    result->end = result->end_ro;
+  if (result->end_exec && (const void*) result->end_exec > result->end)
+    result->end = result->end_exec;
+
   xbt_assert(result->file_name);
   xbt_assert(result->start_rw);
   xbt_assert(result->start_exec);
   xbt_assert(result->file_name);
   xbt_assert(result->start_rw);
   xbt_assert(result->start_exec);
index d89471b..874235c 100644 (file)
@@ -5,7 +5,7 @@
 #include "mc_object_info.h"
 #include "mc_private.h"
 
 #include "mc_object_info.h"
 #include "mc_private.h"
 
-dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, void *ip)
+dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip)
 {
   xbt_dynar_t dynar = info->functions_index;
   mc_function_index_item_t base =
 {
   xbt_dynar_t dynar = info->functions_index;
   mc_function_index_item_t base =
index f3b9cd4..9914c56 100644 (file)
@@ -12,6 +12,7 @@
 #define MC_OBJECT_INFO_H
 
 #include <stdint.h>
 #define MC_OBJECT_INFO_H
 
 #include <stdint.h>
+#include <stdbool.h>
 
 #include <simgrid_config.h>
 #include <xbt/dict.h>
 
 #include <simgrid_config.h>
 #include <xbt/dict.h>
@@ -20,6 +21,7 @@
 #include "mc_forward.h"
 #include "mc_location.h"
 #include "mc_process.h"
 #include "mc_forward.h"
 #include "mc_location.h"
 #include "mc_process.h"
+#include "../smpi/private.h"
 
 SG_BEGIN_DECL();
 
 
 SG_BEGIN_DECL();
 
@@ -59,6 +61,7 @@ enum mc_object_info_flags {
 struct s_mc_object_info {
   enum mc_object_info_flags flags;
   char* file_name;
 struct s_mc_object_info {
   enum mc_object_info_flags flags;
   char* file_name;
+  const void* start, *end;
   char *start_exec, *end_exec; // Executable segment
   char *start_rw, *end_rw; // Read-write segment
   char *start_ro, *end_ro; // read-only segment
   char *start_exec, *end_exec; // Executable segment
   char *start_rw, *end_rw; // Read-write segment
   char *start_ro, *end_ro; // read-only segment
@@ -79,6 +82,12 @@ bool MC_object_info_executable(mc_object_info_t info)
   return info->flags & MC_OBJECT_INFO_EXECUTABLE;
 }
 
   return info->flags & MC_OBJECT_INFO_EXECUTABLE;
 }
 
+static inline __attribute__ ((always_inline))
+bool MC_object_info_is_privatized(mc_object_info_t info)
+{
+  return info && MC_object_info_executable(info) && smpi_privatize_global_variables;
+}
+
 /** Find the DWARF offset for this ELF object
  *
  *  An offset is applied to address found in DWARF:
 /** Find the DWARF offset for this ELF object
  *
  *  An offset is applied to address found in DWARF:
@@ -99,7 +108,7 @@ mc_object_info_t MC_new_object_info(void);
 mc_object_info_t MC_find_object_info(memory_map_t maps, const char* name, int executable);
 void MC_free_object_info(mc_object_info_t* p);
 
 mc_object_info_t MC_find_object_info(memory_map_t maps, const char* name, int executable);
 void MC_free_object_info(mc_object_info_t* p);
 
-dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, void *ip);
+dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip);
 dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name);
 
 void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
 dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, const char* name);
 
 void MC_post_process_object_info(mc_process_t process, mc_object_info_t info);
index 23774b5..23b1c12 100644 (file)
@@ -269,12 +269,36 @@ static void MC_process_init_memory_map_info(mc_process_t process)
   XBT_INFO("Get debug information done !");
 }
 
   XBT_INFO("Get debug information done !");
 }
 
-mc_object_info_t MC_process_find_object_info(mc_process_t process, void *ip)
+mc_object_info_t MC_process_find_object_info(mc_process_t process, const void *addr)
 {
   size_t i;
   for (i = 0; i != process->object_infos_size; ++i) {
 {
   size_t i;
   for (i = 0; i != process->object_infos_size; ++i) {
-    if (ip >= (void *) process->object_infos[i]->start_exec
-        && ip <= (void *) process->object_infos[i]->end_exec) {
+    if (addr >= (void *) process->object_infos[i]->start
+        && addr <= (void *) process->object_infos[i]->end) {
+      return process->object_infos[i];
+    }
+  }
+  return NULL;
+}
+
+mc_object_info_t MC_process_find_object_info_exec(mc_process_t process, const void *addr)
+{
+  size_t i;
+  for (i = 0; i != process->object_infos_size; ++i) {
+    if (addr >= (void *) process->object_infos[i]->start_exec
+        && addr <= (void *) process->object_infos[i]->end_exec) {
+      return process->object_infos[i];
+    }
+  }
+  return NULL;
+}
+
+mc_object_info_t MC_process_find_object_info_rw(mc_process_t process, const void *addr)
+{
+  size_t i;
+  for (i = 0; i != process->object_infos_size; ++i) {
+    if (addr >= (void *) process->object_infos[i]->start_rw
+        && addr <= (void *) process->object_infos[i]->end_rw) {
       return process->object_infos[i];
     }
   }
       return process->object_infos[i];
     }
   }
@@ -283,9 +307,9 @@ mc_object_info_t MC_process_find_object_info(mc_process_t process, void *ip)
 
 // Functions, variables…
 
 
 // Functions, variables…
 
-dw_frame_t MC_process_find_function(mc_process_t process, void *ip)
+dw_frame_t MC_process_find_function(mc_process_t process, const void *ip)
 {
 {
-  mc_object_info_t info = MC_process_find_object_info(process, ip);
+  mc_object_info_t info = MC_process_find_object_info_exec(process, ip);
   if (info == NULL)
     return NULL;
   else
   if (info == NULL)
     return NULL;
   else
@@ -369,8 +393,17 @@ const void* MC_process_read(mc_process_t process, e_adress_space_read_flags_t fl
   void* local, const void* remote, size_t len,
   int process_index)
 {
   void* local, const void* remote, size_t len,
   int process_index)
 {
-  if (process_index != MC_PROCESS_INDEX_DISABLED)
-    xbt_die("Not implemented yet");
+  if (process_index != MC_PROCESS_INDEX_DISABLED) {
+    mc_object_info_t info = MC_process_find_object_info_rw(process, remote);
+    // Segment overlap is not handled.
+    if (MC_object_info_is_privatized(info)) {
+      if (process_index < 0)
+        xbt_die("Missing process index");
+      // Address translation in the privaization segment:
+      size_t offset = (const char*) remote - info->start_rw;
+      remote = (const char*) remote - offset;
+    }
+  }
 
   if (MC_process_is_self(process)) {
     if (flags & MC_ADDRESS_SPACE_READ_FLAGS_LAZY)
 
   if (MC_process_is_self(process)) {
     if (flags & MC_ADDRESS_SPACE_READ_FLAGS_LAZY)
index 05ba9b0..64a62ac 100644 (file)
@@ -125,8 +125,11 @@ void MC_process_write(mc_process_t process, const void* local, void* remote, siz
 
 /* Functions, variables of the process: */
 
 
 /* Functions, variables of the process: */
 
-mc_object_info_t MC_process_find_object_info(mc_process_t process, void* ip);
-dw_frame_t MC_process_find_function(mc_process_t process, void* ip);
+mc_object_info_t MC_process_find_object_info(mc_process_t process, const void* addr);
+mc_object_info_t MC_process_find_object_info_exec(mc_process_t process, const void* addr);
+mc_object_info_t MC_process_find_object_info_rw(mc_process_t process, const void* addr);
+
+dw_frame_t MC_process_find_function(mc_process_t process, const void* ip);
 
 static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
 {
 
 static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
 {