Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Communication of heap_area_to_ignore to the remote MCer
[simgrid.git] / src / mc / mc_ignore.c
index 9f3a0a7..5f8ea90 100644 (file)
@@ -9,6 +9,9 @@
 #include "mc_private.h"
 #include "smpi/private.h"
 #include "mc/mc_snapshot.h"
+#include "mc_ignore.h"
+#include "mc_protocol.h"
+#include "mc_client.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc,
                                 "Logging specific to MC ignore mechanism");
@@ -61,32 +64,10 @@ static void checkpoint_ignore_region_free_voidp(void *r)
 
 /***********************************************************************/
 
-void MC_ignore_heap(void *address, size_t size)
+void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
 {
-
   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
 
-  MC_SET_MC_HEAP;
-
-  mc_heap_ignore_region_t region = NULL;
-  region = xbt_new0(s_mc_heap_ignore_region_t, 1);
-  region->address = address;
-  region->size = size;
-
-  region->block =
-      ((char *) address -
-       (char *) std_heap->heapbase) / BLOCKSIZE + 1;
-
-  if (std_heap->heapinfo[region->block].type == 0) {
-    region->fragment = -1;
-    std_heap->heapinfo[region->block].busy_block.ignore++;
-  } else {
-    region->fragment =
-        ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap->
-        heapinfo[region->block].type;
-    std_heap->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
-  }
-
   if (mc_heap_comparison_ignore == NULL) {
     mc_heap_comparison_ignore =
         xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
@@ -102,25 +83,27 @@ void MC_ignore_heap(void *address, size_t size)
   int start = 0;
   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
 
+  // Find the position where we want to insert the mc_heap_ignore_region_t:
   while (start <= end) {
     cursor = (start + end) / 2;
     current_region =
         (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
                                                    cursor,
                                                    mc_heap_ignore_region_t);
-    if (current_region->address == address) {
+    if (current_region->address == region->address) {
       heap_ignore_region_free(region);
       if (!raw_mem_set)
         MC_SET_STD_HEAP;
       return;
-    } else if (current_region->address < address) {
+    } else if (current_region->address < region->address) {
       start = cursor + 1;
     } else {
       end = cursor - 1;
     }
   }
 
-  if (current_region->address < address)
+  // Insert it mc_heap_ignore_region_t:
+  if (current_region->address < region->address)
     xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, &region);
   else
     xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, &region);
@@ -129,6 +112,56 @@ void MC_ignore_heap(void *address, size_t size)
     MC_SET_STD_HEAP;
 }
 
+void MC_heap_region_ignore_send(mc_heap_ignore_region_t region)
+{
+  s_mc_ignore_region_message_t message;
+  message.type = MC_MESSAGE_IGNORE_REGION;
+  message.region = *region;
+  if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
+    xbt_die("Could not send ignored region to MCer");
+  XBT_DEBUG("Sent ignored region to the model-checker");
+}
+
+// FIXME, cross-process support? (or make this it is used on the app-side)
+void MC_ignore_heap(void *address, size_t size)
+{
+  if(!std_heap)
+    return;
+
+  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+
+  MC_SET_MC_HEAP;
+
+  mc_heap_ignore_region_t region = NULL;
+  region = xbt_new0(s_mc_heap_ignore_region_t, 1);
+  region->address = address;
+  region->size = size;
+
+  region->block =
+      ((char *) address -
+       (char *) std_heap->heapbase) / BLOCKSIZE + 1;
+
+  if (std_heap->heapinfo[region->block].type == 0) {
+    region->fragment = -1;
+    std_heap->heapinfo[region->block].busy_block.ignore++;
+  } else {
+    region->fragment =
+        ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap->
+        heapinfo[region->block].type;
+    std_heap->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
+  }
+
+  MC_heap_region_ignore_insert(region);
+
+#if 1
+  if (mc_mode == MC_MODE_CLIENT)
+    MC_heap_region_ignore_send(region);
+#endif
+
+  if (!raw_mem_set)
+    MC_SET_STD_HEAP;
+}
+
 void MC_remove_ignore_heap(void *address, size_t size)
 {
 
@@ -173,6 +206,7 @@ void MC_remove_ignore_heap(void *address, size_t size)
 
 }
 
+// FIXME, cross-process support?
 void MC_ignore_global_variable(const char *name)
 {
   mc_process_t process = &mc_model_checker->process;
@@ -180,26 +214,29 @@ void MC_ignore_global_variable(const char *name)
 
   MC_SET_MC_HEAP;
 
-  xbt_assert(process->libsimgrid_info, "MC subsystem not initialized");
+  xbt_assert(process->object_infos, "MC subsystem not initialized");
 
-  unsigned int cursor = 0;
-  dw_variable_t current_var;
-  int start = 0;
-  int end = xbt_dynar_length(process->libsimgrid_info->global_variables) - 1;
+  size_t n = process->object_infos_size;
+  for (size_t i=0; i!=n; ++i) {
+    mc_object_info_t info = process->object_infos[i];
 
-  while (start <= end) {
-    cursor = (start + end) / 2;
-    current_var =
-        (dw_variable_t) xbt_dynar_get_as(process->libsimgrid_info->global_variables,
-                                         cursor, dw_variable_t);
-    if (strcmp(current_var->name, name) == 0) {
-      xbt_dynar_remove_at(process->libsimgrid_info->global_variables, cursor, NULL);
-      start = 0;
-      end = xbt_dynar_length(process->libsimgrid_info->global_variables) - 1;
-    } else if (strcmp(current_var->name, name) < 0) {
-      start = cursor + 1;
-    } else {
-      end = cursor - 1;
+    // Binary search:
+    int start = 0;
+    int end = xbt_dynar_length(info->global_variables) - 1;
+    while (start <= end) {
+      unsigned int cursor = (start + end) / 2;
+      dw_variable_t current_var =
+          (dw_variable_t) xbt_dynar_get_as(info->global_variables,
+                                           cursor, dw_variable_t);
+      if (strcmp(current_var->name, name) == 0) {
+        xbt_dynar_remove_at(info->global_variables, cursor, NULL);
+        start = 0;
+        end = xbt_dynar_length(info->global_variables) - 1;
+      } else if (strcmp(current_var->name, name) < 0) {
+        start = cursor + 1;
+      } else {
+        end = cursor - 1;
+      }
     }
   }
 
@@ -218,6 +255,7 @@ void MC_ignore_global_variable(const char *name)
  *  \param subprogram      (possibly inlined) Subprogram of the scope
  *  \param scope           Current scope
  */
+ // FIXME, cross-process support (messaging?)
 static void mc_ignore_local_variable_in_scope(const char *var_name,
                                               const char *subprogram_name,
                                               dw_frame_t subprogram,
@@ -225,7 +263,7 @@ static void mc_ignore_local_variable_in_scope(const char *var_name,
 {
   // Processing of direct variables:
 
-  // If the current subprogram matche the given name:
+  // If the current subprogram matches the given name:
   if (!subprogram_name ||
       (subprogram->name && strcmp(subprogram_name, subprogram->name) == 0)) {
 
@@ -295,9 +333,11 @@ void MC_ignore_local_variable(const char *var_name, const char *frame_name)
 
   MC_SET_MC_HEAP;
 
-  MC_ignore_local_variable_in_object(var_name, frame_name, process->libsimgrid_info);
-  if (frame_name != NULL)
-    MC_ignore_local_variable_in_object(var_name, frame_name, process->binary_info);
+  size_t n = process->object_infos_size;
+  size_t i;
+  for (i=0; i!=n; ++i) {
+    MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]);
+  }
 
   if (!raw_mem_set)
     MC_SET_STD_HEAP;
@@ -307,7 +347,7 @@ void MC_ignore_local_variable(const char *var_name, const char *frame_name)
 /** @brief Register a stack in the model checker
  *
  *  The stacks are allocated in the heap. The MC handle them especially
- *  when we analyse/compare the content of theap so it must be told where
+ *  when we analyse/compare the content of the heap so it must be told where
  *  they are with this function.
  *
  *  @param stack
@@ -354,6 +394,7 @@ void MC_ignore(void *addr, size_t size)
 
   MC_SET_MC_HEAP;
 
+  // FIXME, cross-process support
   if (mc_checkpoint_ignore == NULL)
     mc_checkpoint_ignore =
         xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t),