Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move heap_ignore to Process
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 20 Nov 2015 12:52:24 +0000 (13:52 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 Nov 2015 15:40:08 +0000 (16:40 +0100)
14 files changed:
src/include/mc/datatypes.h
src/include/mc/mc.h
src/mc/ModelChecker.cpp
src/mc/Process.cpp
src/mc/Process.hpp
src/mc/mc_checkpoint.cpp
src/mc/mc_diff.cpp
src/mc/mc_global.cpp
src/mc/mc_ignore.cpp
src/mc/mc_protocol.h
src/mc/mc_snapshot.h
src/mc/mcer_ignore.cpp
src/mc/mcer_ignore.h [deleted file]
tools/cmake/DefinePackages.cmake

index c33ed9b..763b60d 100644 (file)
@@ -24,13 +24,6 @@ typedef struct s_mc_transition *mc_transition_t;
 
 /*********** Structures for snapshot comparison **************************/
 
-typedef struct s_mc_heap_ignore_region{
-  int block;
-  int fragment;
-  void *address;
-  size_t size;
-}s_mc_heap_ignore_region_t, *mc_heap_ignore_region_t;
-
 typedef struct s_stack_region{
   void *address;
   void *context;
index 7fb1dba..f227bae 100644 (file)
@@ -57,8 +57,6 @@ extern XBT_PRIVATE int _sg_mc_liveness;
 extern XBT_PRIVATE int _sg_mc_snapshot_fds;
 extern XBT_PRIVATE int _sg_mc_termination;
 
-extern XBT_PRIVATE xbt_dynar_t mc_heap_comparison_ignore;
-
 /********************************* Global *************************************/
 
 XBT_PRIVATE void _mc_cfg_cb_reduce(const char *name, int pos);
@@ -77,8 +75,6 @@ XBT_PRIVATE void _mc_cfg_cb_comms_determinism(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_send_determinism(const char *name, int pos);
 XBT_PRIVATE void _mc_cfg_cb_termination(const char *name, int pos);
 
-extern xbt_dynar_t mc_heap_comparison_ignore;
-
 XBT_PUBLIC(void) MC_run(void);
 XBT_PUBLIC(void) MC_init(void);
 XBT_PUBLIC(void) MC_exit(void);
index ac7f0fd..92be558 100644 (file)
@@ -28,7 +28,6 @@
 #include "mc_protocol.h"
 #include "mc_private.h"
 #include "mc_ignore.h"
-#include "mcer_ignore.h"
 #include "mc_exit.h"
 #include "src/mc/mc_liveness.h"
 
@@ -203,9 +202,13 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size)
       if (size != sizeof(message))
         xbt_die("Broken messsage");
       memcpy(&message, buffer, sizeof(message));
-      mc_heap_ignore_region_t region = xbt_new(s_mc_heap_ignore_region_t, 1);
-      *region = message.region;
-      MC_heap_region_ignore_insert(region);
+
+      IgnoredHeapRegion region;
+      region.block = message.block;
+      region.fragment = message.fragment;
+      region.address = message.address;
+      region.size = message.size;
+      process().ignore_heap(region);
       break;
     }
 
@@ -215,7 +218,7 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size)
       if (size != sizeof(message))
         xbt_die("Broken messsage");
       memcpy(&message, buffer, sizeof(message));
-      MC_heap_region_ignore_remove(
+      process().unignore_heap(
         (void *)(std::uintptr_t) message.addr, message.size);
       break;
     }
index 2a883bd..665e29e 100644 (file)
@@ -636,5 +636,67 @@ void Process::read_pagemap(uint64_t* pagemap, size_t page_start, size_t page_cou
     xbt_die("Could not read pagemap");
 }
 
+void Process::ignore_heap(IgnoredHeapRegion const& region)
+{
+  if (ignored_heap_.empty()) {
+    ignored_heap_.push_back(std::move(region));
+    return;
+  }
+
+  typedef std::vector<IgnoredHeapRegion>::size_type size_type;
+
+  size_type start = 0;
+  size_type end = ignored_heap_.size() - 1;
+
+  // Binary search the position of insertion:
+  size_type cursor;
+  while (start <= end) {
+    cursor = start + (end - start) / 2;
+    auto& current_region = ignored_heap_[cursor];
+    if (current_region.address == region.address)
+      return;
+    else if (current_region.address < region.address)
+      start = cursor + 1;
+    else if (cursor != 0)
+      end = cursor - 1;
+    // Avoid underflow:
+    else
+      break;
+  }
+
+  // Insert it mc_heap_ignore_region_t:
+  if (ignored_heap_[cursor].address < region.address)
+    ++cursor;
+  ignored_heap_.insert( ignored_heap_.begin() + cursor, region);
+}
+
+void Process::unignore_heap(void *address, size_t size)
+{
+  typedef std::vector<IgnoredHeapRegion>::size_type size_type;
+
+  size_type start = 0;
+  size_type end = ignored_heap_.size() - 1;
+
+  // Binary search:
+  size_type cursor;
+  while (start <= end) {
+    cursor = (start + end) / 2;
+    auto& region = ignored_heap_[cursor];
+    if (region.address == address) {
+      ignored_heap_.erase(ignored_heap_.begin() + cursor);
+      return;
+    } else if (region.address < address)
+      start = cursor + 1;
+    else if ((char *) region.address <= ((char *) address + size)) {
+      ignored_heap_.erase(ignored_heap_.begin() + cursor);
+      return;
+    } else if (cursor != 0)
+      end = cursor - 1;
+    // Avoid underflow:
+    else
+      break;
+  }
+}
+
 }
 }
index bb8c478..2999813 100644 (file)
@@ -54,6 +54,13 @@ struct IgnoredRegion {
   size_t size;
 };
 
+struct IgnoredHeapRegion {
+  int block;
+  int fragment;
+  void *address;
+  size_t size;
+};
+
 /** Representation of a process
  */
 class Process final : public AddressSpace {
@@ -177,6 +184,13 @@ public:
     return stack_areas_;
   }
 
+  std::vector<IgnoredHeapRegion> const& ignored_heap() const
+  {
+    return ignored_heap_;
+  }
+  void ignore_heap(IgnoredHeapRegion const& region);
+  void unignore_heap(void *address, size_t size);
+
 private:
   void init_memory_map_info();
   void refresh_heap();
@@ -193,6 +207,7 @@ private:
   int pagemap_fd_;
   bool privatized_;
   std::vector<s_stack_region_t> stack_areas_;
+  std::vector<IgnoredHeapRegion> ignored_heap_;
 
 public: // object info
   // TODO, make private (first, objectify simgrid::mc::ObjectInformation*)
index 62902b2..6bafeae 100644 (file)
@@ -446,28 +446,6 @@ static std::vector<s_mc_snapshot_stack_t> MC_take_snapshot_stacks(mc_snapshot_t
 
 }
 
-static std::vector<s_mc_heap_ignore_region_t> MC_take_snapshot_ignore()
-{
-  std::vector<s_mc_heap_ignore_region_t> res;
-
-  if (mc_heap_comparison_ignore == NULL)
-    return std::move(res);
-
-  unsigned int cursor = 0;
-  mc_heap_ignore_region_t current_region;
-
-  xbt_dynar_foreach(mc_heap_comparison_ignore, cursor, current_region) {
-    s_mc_heap_ignore_region_t new_region;
-    new_region.address = current_region->address;
-    new_region.size = current_region->size;
-    new_region.block = current_region->block;
-    new_region.fragment = current_region->fragment;
-    res.push_back(std::move(new_region));
-  }
-
-  return std::move(res);
-}
-
 static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
 {
   xbt_assert(snapshot->process());
@@ -604,7 +582,7 @@ mc_snapshot_t MC_take_snapshot(int num_state)
   if (use_soft_dirty)
     mc_process->reset_soft_dirty();
 
-  snapshot->to_ignore = MC_take_snapshot_ignore();
+  snapshot->to_ignore = mc_model_checker->process().ignored_heap();
 
   if (_sg_mc_visited > 0 || strcmp(_sg_mc_property_file, "")) {
     snapshot->stacks =
index 6cf5993..f1694c4 100644 (file)
@@ -24,8 +24,6 @@ extern "C" {
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
                                 "Logging specific to mc_diff in mc");
 
-xbt_dynar_t mc_heap_comparison_ignore;
-
 /*********************************** Heap comparison ***********************************/
 /***************************************************************************************/
 
@@ -36,8 +34,8 @@ struct XBT_PRIVATE s_mc_diff {
   std::size_t heaplimit;
   // Number of blocks in the heaps:
   std::size_t heapsize1, heapsize2;
-  std::vector<s_mc_heap_ignore_region_t>* to_ignore1;
-  std::vector<s_mc_heap_ignore_region_t>* to_ignore2;
+  std::vector<simgrid::mc::IgnoredHeapRegion>* to_ignore1;
+  std::vector<simgrid::mc::IgnoredHeapRegion>* to_ignore2;
   s_heap_area_t *equals_to1, *equals_to2;
   simgrid::mc::Type **types1;
   simgrid::mc::Type **types2;
@@ -119,15 +117,16 @@ static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
   return 0;
 }
 
-static ssize_t heap_comparison_ignore_size(std::vector<s_mc_heap_ignore_region_t>* ignore_list,
-                                           const void *address)
+static ssize_t heap_comparison_ignore_size(
+  std::vector<simgrid::mc::IgnoredHeapRegion>* ignore_list,
+  const void *address)
 {
   int start = 0;
   int end = ignore_list->size() - 1;
 
   while (start <= end) {
     unsigned int cursor = (start + end) / 2;
-    s_mc_heap_ignore_region_t region = (*ignore_list)[cursor];
+    simgrid::mc::IgnoredHeapRegion const& region = (*ignore_list)[cursor];
     if (region.address == address)
       return region.size;
     if (region.address < address)
@@ -225,8 +224,8 @@ static int equal_fragments(struct s_mc_diff *state, int b1, int f1, int b2,
 }
 
 int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
-                          std::vector<s_mc_heap_ignore_region_t>* i1,
-                          std::vector<s_mc_heap_ignore_region_t>* i2)
+                          std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
+                          std::vector<simgrid::mc::IgnoredHeapRegion>* i2)
 {
   if (mc_diff_info == NULL) {
     mc_diff_info = xbt_new0(struct s_mc_diff, 1);
index 2c484c1..154e5c6 100644 (file)
@@ -40,7 +40,6 @@
 #include "mc_private.h"
 #include "mc_unw.h"
 #include "mc_smx.h"
-#include "mcer_ignore.h"
 #endif
 #include "mc_record.h"
 #include "mc_protocol.h"
index d758c7f..debb2a4 100644 (file)
@@ -27,26 +27,23 @@ void MC_ignore_heap(void *address, size_t size)
 
   xbt_mheap_t heap = mmalloc_get_current_heap();
 
-  s_mc_heap_ignore_region_t region;
-  memset(&region, 0, sizeof(region));
-  region.address = address;
-  region.size = size;
-  region.block =
+  s_mc_ignore_heap_message_t message;
+  message.type = MC_MESSAGE_IGNORE_HEAP;
+  message.address = address;
+  message.size = size;
+  message.block =
    ((char *) address -
     (char *) heap->heapbase) / BLOCKSIZE + 1;
-  if (heap->heapinfo[region.block].type == 0) {
-    region.fragment = -1;
-    heap->heapinfo[region.block].busy_block.ignore++;
+  if (heap->heapinfo[message.block].type == 0) {
+    message.fragment = -1;
+    heap->heapinfo[message.block].busy_block.ignore++;
   } else {
-    region.fragment =
+    message.fragment =
         ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >>
-        heap->heapinfo[region.block].type;
-    heap->heapinfo[region.block].busy_frag.ignore[region.fragment]++;
+        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");
 }
index ee0d433..64b0e70 100644 (file)
@@ -77,7 +77,10 @@ typedef struct s_mc_int_message {
 
 typedef struct s_mc_ignore_heap_message {
   e_mc_message_type type;
-  s_mc_heap_ignore_region_t region;
+  int block;
+  int fragment;
+  void *address;
+  size_t size;
 } s_mc_ignore_heap_message_t, *mc_ignore_heap_message_t;
 
 typedef struct s_mc_ignore_memory_message {
index 1168934..1653250 100644 (file)
@@ -155,7 +155,7 @@ public: // To be private
   int privatization_index;
   std::vector<std::size_t> stack_sizes;
   std::vector<s_mc_snapshot_stack_t> stacks;
-  std::vector<s_mc_heap_ignore_region_t> to_ignore;
+  std::vector<simgrid::mc::IgnoredHeapRegion> to_ignore;
   std::uint64_t hash;
   std::vector<s_mc_snapshot_ignored_data> ignored_data;
   std::vector<s_fd_infos_t> current_fds;
@@ -260,7 +260,7 @@ void* MC_region_read_pointer(mc_mem_region_t region, const void* addr)
 SG_END_DECL()
 
 XBT_PRIVATE int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2,
-                          std::vector<s_mc_heap_ignore_region_t>* i1,
-                          std::vector<s_mc_heap_ignore_region_t>* i2);
+                          std::vector<simgrid::mc::IgnoredHeapRegion>* i1,
+                          std::vector<simgrid::mc::IgnoredHeapRegion>* i2);
 
 #endif
index 838e5c4..1ef7852 100644 (file)
@@ -24,93 +24,6 @@ extern "C" {
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc,
                                 "Logging specific to MC ignore mechanism");
 
-// ***** Ignore heap chunks
-
-extern XBT_PRIVATE xbt_dynar_t mc_heap_comparison_ignore;
-
-static void heap_ignore_region_free(mc_heap_ignore_region_t r)
-{
-  xbt_free(r);
-}
-
-static void heap_ignore_region_free_voidp(void *r)
-{
-  heap_ignore_region_free((mc_heap_ignore_region_t) * (void **) r);
-}
-
-
-XBT_PRIVATE void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
-{
-  if (mc_heap_comparison_ignore == NULL) {
-    mc_heap_comparison_ignore =
-        xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
-                      heap_ignore_region_free_voidp);
-    xbt_dynar_push(mc_heap_comparison_ignore, &region);
-    return;
-  }
-
-  unsigned int cursor = 0;
-  mc_heap_ignore_region_t current_region = NULL;
-  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 == region->address) {
-      heap_ignore_region_free(region);
-      return;
-    } else if (current_region->address < region->address) {
-      start = cursor + 1;
-    } else {
-      end = cursor - 1;
-    }
-  }
-
-  // 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);
-}
-
-XBT_PRIVATE void MC_heap_region_ignore_remove(void *address, size_t size)
-{
-  unsigned int cursor = 0;
-  int start = 0;
-  int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
-  mc_heap_ignore_region_t region;
-  int ignore_found = 0;
-
-  while (start <= end) {
-    cursor = (start + end) / 2;
-    region =
-        (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
-                                                   cursor,
-                                                   mc_heap_ignore_region_t);
-    if (region->address == address) {
-      ignore_found = 1;
-      break;
-    } else if (region->address < address) {
-      start = cursor + 1;
-    } else {
-      if ((char *) region->address <= ((char *) address + size)) {
-        ignore_found = 1;
-        break;
-      } else {
-        end = cursor - 1;
-      }
-    }
-  }
-
-  if (ignore_found == 1) {
-    xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
-    MC_remove_ignore_heap(address, size);
-  }
 }
 
 // ***** Ignore local variables
@@ -123,6 +36,7 @@ static void MC_ignore_local_variable_in_object(const char *var_name,
                                                const char *subprogram_name,
                                                simgrid::mc::ObjectInformation* info);
 
+extern "C"
 void MC_ignore_local_variable(const char *var_name, const char *frame_name)
 {
   simgrid::mc::Process* process = &mc_model_checker->process();
@@ -201,6 +115,4 @@ static void mc_ignore_local_variable_in_scope(const char *var_name,
     mc_ignore_local_variable_in_scope(var_name, subprogram_name,
                                       nested_subprogram, &nested_scope);
   }
-}
-
-}
+}
\ No newline at end of file
diff --git a/src/mc/mcer_ignore.h b/src/mc/mcer_ignore.h
deleted file mode 100644 (file)
index 1961f4b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (c) 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. */
-
-#ifndef SIMGRID_MCER_IGNORE_H
-#define SIMGRID_MCER_IGNORE_H
-
-#include <xbt/dynar.h>
-
-#include "mc/datatypes.h"
-#include "src/mc/Process.hpp"
-
-#include "xbt/misc.h"           /* SG_BEGIN_DECL */
-
-SG_BEGIN_DECL();
-
-XBT_PRIVATE void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region);
-XBT_PRIVATE void MC_heap_region_ignore_remove(void *address, size_t size);
-
-SG_END_DECL();
-
-#endif
\ No newline at end of file
index f00067f..7e9bd31 100644 (file)
@@ -660,7 +660,6 @@ set(MC_SRC
   src/mc/mc_hash.cpp
   src/mc/mc_ignore.cpp
   src/mc/mcer_ignore.cpp
-  src/mc/mcer_ignore.h
   src/mc/mc_ignore.h
   src/mc/mc_liveness.h
   src/mc/LocationList.hpp