Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use ucontext_t instead of void* in some places
[simgrid.git] / src / mc / mc_ignore.cpp
index 5440faf..6017779 100644 (file)
@@ -1,80 +1,23 @@
-/* Copyright (c) 2008-2014. The SimGrid Team.
+/* Copyright (c) 2008-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "internal_config.h"
-#include "mc_object_info.h"
-#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"
+#include "src/internal_config.h"
+#include "src/mc/mc_object_info.h"
+#include "src/mc/mc_private.h"
+#include "src/smpi/private.h"
+#include "src/mc/mc_snapshot.h"
+#include "src/mc/mc_ignore.h"
+#include "src/mc/mc_protocol.h"
+#include "src/mc/mc_client.h"
 
 extern "C" {
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc,
                                 "Logging specific to MC ignore mechanism");
 
-
-/**************************** Global variables ******************************/
-// Those structures live with the MCer and should be moved in the model_checker
-// structure but they are currently used before the MC initialisation
-// (in standalone mode).
-
-
-extern xbt_dynar_t stacks_areas;
-
-/**************************** Structures ******************************/
-typedef struct s_mc_stack_ignore_variable {
-  char *var_name;
-  char *frame;
-} s_mc_stack_ignore_variable_t, *mc_stack_ignore_variable_t;
-
-/**************************** Free functions ******************************/
-
-static void stack_ignore_variable_free(mc_stack_ignore_variable_t v)
-{
-  xbt_free(v->var_name);
-  xbt_free(v->frame);
-  xbt_free(v);
-}
-
-static void stack_ignore_variable_free_voidp(void *v)
-{
-  stack_ignore_variable_free((mc_stack_ignore_variable_t) * (void **) v);
-}
-
-void heap_ignore_region_free(mc_heap_ignore_region_t r)
-{
-  xbt_free(r);
-}
-
-void heap_ignore_region_free_voidp(void *r)
-{
-  heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
-}
-
-static void checkpoint_ignore_region_free(mc_checkpoint_ignore_region_t r)
-{
-  xbt_free(r);
-}
-
-static void checkpoint_ignore_region_free_voidp(void *r)
-{
-  checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
-}
-
-xbt_dynar_t MC_checkpoint_ignore_new(void)
-{
-  return xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t),
-                        checkpoint_ignore_region_free_voidp);
-}
-
-/***********************************************************************/
-
 // ***** Model-checked
 
 void MC_ignore_heap(void *address, size_t size)
@@ -82,26 +25,25 @@ void MC_ignore_heap(void *address, size_t size)
   if (mc_mode != MC_MODE_CLIENT)
     return;
 
-  s_mc_heap_ignore_region_t region;
-  memset(&region, 0, sizeof(region));
-  region.address = address;
-  region.size = size;
-  region.block =
+  xbt_mheap_t heap = mmalloc_get_current_heap();
+
+  s_mc_ignore_heap_message_t message;
+  message.type = MC_MESSAGE_IGNORE_HEAP;
+  message.address = address;
+  message.size = size;
+  message.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++;
+    (char *) heap->heapbase) / BLOCKSIZE + 1;
+  if (heap->heapinfo[message.block].type == 0) {
+    message.fragment = -1;
+    heap->heapinfo[message.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]++;
+    message.fragment =
+        ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >>
+        heap->heapinfo[message.block].type;
+    heap->heapinfo[message.block].busy_frag.ignore[message.fragment]++;
   }
 
-  s_mc_ignore_heap_message_t message;
-  message.type = MC_MESSAGE_IGNORE_HEAP;
-  message.region = region;
   if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
     xbt_die("Could not send ignored region to MCer");
 }
@@ -113,143 +55,15 @@ void MC_remove_ignore_heap(void *address, size_t size)
 
   s_mc_ignore_memory_message_t message;
   message.type = MC_MESSAGE_UNIGNORE_HEAP;
-  message.addr = address;
+  message.addr = (std::uintptr_t) address;
   message.size = size;
   MC_client_send_message(&message, sizeof(message));
 }
 
-// ***** Model-checker:
-
 void MC_ignore_global_variable(const char *name)
 {
-  mc_process_t process = &mc_model_checker->process();
-  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
-  xbt_assert(process->object_infos, "MC subsystem not initialized");
-
-  size_t n = process->object_infos_size;
-  for (size_t i=0; i!=n; ++i) {
-    mc_object_info_t info = process->object_infos[i];
-
-    // 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;
-      }
-    }
-  }
-  mmalloc_set_current_heap(heap);
-}
-
-/** \brief Ignore a local variable in a scope
- *
- *  Ignore all instances of variables with a given name in
- *  any (possibly inlined) subprogram with a given namespaced
- *  name.
- *
- *  \param var_name        Name of the local variable (or parameter to ignore)
- *  \param subprogram_name Name of the subprogram fo ignore (NULL for any)
- *  \param subprogram      (possibly inlined) Subprogram of the scope
- *  \param scope           Current scope
- */
-static void mc_ignore_local_variable_in_scope(const char *var_name,
-                                              const char *subprogram_name,
-                                              dw_frame_t subprogram,
-                                              dw_frame_t scope)
-{
-  // Processing of direct variables:
-
-  // If the current subprogram matches the given name:
-  if (!subprogram_name ||
-      (subprogram->name && strcmp(subprogram_name, subprogram->name) == 0)) {
-
-    // Try to find the variable and remove it:
-    int start = 0;
-    int end = xbt_dynar_length(scope->variables) - 1;
-
-    // Dichotomic search:
-    while (start <= end) {
-      int cursor = (start + end) / 2;
-      dw_variable_t current_var =
-          (dw_variable_t) xbt_dynar_get_as(scope->variables, cursor,
-                                           dw_variable_t);
-
-      int compare = strcmp(current_var->name, var_name);
-      if (compare == 0) {
-        // Variable found, remove it:
-        xbt_dynar_remove_at(scope->variables, cursor, NULL);
-
-        // and start again:
-        start = 0;
-        end = xbt_dynar_length(scope->variables) - 1;
-      } else if (compare < 0) {
-        start = cursor + 1;
-      } else {
-        end = cursor - 1;
-      }
-    }
-
-  }
-  // And recursive processing in nested scopes:
-  unsigned cursor = 0;
-  dw_frame_t nested_scope = NULL;
-  xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
-    // The new scope may be an inlined subroutine, in this case we want to use its
-    // namespaced name in recursive calls:
-    dw_frame_t nested_subprogram =
-        nested_scope->tag ==
-        DW_TAG_inlined_subroutine ? nested_scope : subprogram;
-
-    mc_ignore_local_variable_in_scope(var_name, subprogram_name,
-                                      nested_subprogram, nested_scope);
-  }
-}
-
-static void MC_ignore_local_variable_in_object(const char *var_name,
-                                               const char *subprogram_name,
-                                               mc_object_info_t info)
-{
-  xbt_dict_cursor_t cursor2;
-  dw_frame_t frame;
-  char *key;
-  xbt_dict_foreach(info->subprograms, cursor2, key, frame) {
-    mc_ignore_local_variable_in_scope(var_name, subprogram_name, frame, frame);
-  }
-}
-
-// MCer
-void MC_ignore_local_variable(const char *var_name, const char *frame_name)
-{
-  mc_process_t process = &mc_model_checker->process();
-  if (strcmp(frame_name, "*") == 0)
-    frame_name = NULL;
-  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
-
-  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]);
-  }
-
-  mmalloc_set_current_heap(heap);
-}
-
-void MC_stack_area_add(stack_region_t stack_area)
-{
-  if (stacks_areas == NULL)
-    stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
-  xbt_dynar_push(stacks_areas, &stack_area);
+  // TODO, send a message to the model_checker
+  xbt_die("Unimplemented");
 }
 
 /** @brief Register a stack in the model checker
@@ -263,87 +77,32 @@ void MC_stack_area_add(stack_region_t stack_area)
  *  @param context
  *  @param size    Size of the stack
  */
-void MC_new_stack_area(void *stack, smx_process_t process, void *context, size_t size)
+void MC_register_stack_area(void *stack, smx_process_t process, ucontext_t* context, size_t size)
 {
-  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+  if (mc_mode != MC_MODE_CLIENT)
+    return;
+
+  xbt_mheap_t heap = mmalloc_get_current_heap();
 
-  stack_region_t region = xbt_new0(s_stack_region_t, 1);
-  region->address = stack;
-  region->context = context;
-  region->size = size;
-  region->block =
+  s_stack_region_t region;
+  memset(&region, 0, sizeof(region));
+  region.address = stack;
+  region.context = context;
+  region.size = size;
+  region.block =
       ((char *) stack -
-       (char *) std_heap->heapbase) / BLOCKSIZE + 1;
+       (char *) heap->heapbase) / BLOCKSIZE + 1;
 #ifdef HAVE_SMPI
   if (smpi_privatize_global_variables && process) {
-    region->process_index = smpi_process_index_of_smx_process(process);
+    region.process_index = smpi_process_index_of_smx_process(process);
   } else
 #endif
-  region->process_index = -1;
-
-  if (mc_mode == MC_MODE_CLIENT) {
-    s_mc_stack_region_message_t message;
-    message.type = MC_MESSAGE_STACK_REGION;
-    message.stack_region = *region;
-    MC_client_send_message(&message, sizeof(message));
-  }
+  region.process_index = -1;
 
-  MC_stack_area_add(region);
-
-  mmalloc_set_current_heap(heap);
-}
-
-void MC_process_ignore_memory(mc_process_t process, void *addr, size_t size)
-{
-  xbt_dynar_t checkpoint_ignore = process->checkpoint_ignore;
-  mc_checkpoint_ignore_region_t region =
-      xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
-  region->addr = addr;
-  region->size = size;
-
-  if (xbt_dynar_is_empty(checkpoint_ignore)) {
-    xbt_dynar_push(checkpoint_ignore, &region);
-  } else {
-
-    unsigned int cursor = 0;
-    int start = 0;
-    int end = xbt_dynar_length(checkpoint_ignore) - 1;
-    mc_checkpoint_ignore_region_t current_region = NULL;
-
-    while (start <= end) {
-      cursor = (start + end) / 2;
-      current_region =
-          (mc_checkpoint_ignore_region_t) xbt_dynar_get_as(checkpoint_ignore,
-                                                           cursor,
-                                                           mc_checkpoint_ignore_region_t);
-      if (current_region->addr == addr) {
-        if (current_region->size == size) {
-          checkpoint_ignore_region_free(region);
-          return;
-        } else if (current_region->size < size) {
-          start = cursor + 1;
-        } else {
-          end = cursor - 1;
-        }
-      } else if (current_region->addr < addr) {
-        start = cursor + 1;
-      } else {
-        end = cursor - 1;
-      }
-    }
-
-    if (current_region->addr == addr) {
-      if (current_region->size < size) {
-        xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, &region);
-      } else {
-        xbt_dynar_insert_at(checkpoint_ignore, cursor, &region);
-      }
-    } else if (current_region->addr < addr) {
-      xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, &region);
-    } else {
-      xbt_dynar_insert_at(checkpoint_ignore, cursor, &region);
-    }
-  }
+  s_mc_stack_region_message_t message;
+  message.type = MC_MESSAGE_STACK_REGION;
+  message.stack_region = region;
+  MC_client_send_message(&message, sizeof(message));
 }
 
 }