Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remote support for MC_deadlock_check() using MC_MESSAGE_DEADLOCK_CHECK IPC message
[simgrid.git] / src / mc / mc_page_store.h
index 092ad23..2f79705 100644 (file)
@@ -6,19 +6,26 @@
 
 #include <stdint.h>
 
+#ifdef __cplusplus
 #include <vector>
 
+#include <boost/array.hpp>
 #include <boost/utility.hpp>
 #include <boost/unordered_map.hpp>
 #include <boost/unordered_set.hpp>
+#endif
 
 #include <xbt.h>
 
-#include "mc_private.h"
 #include "mc_mmu.h"
+#include "mc_forward.h"
+
+#ifndef MC_PAGE_STORE_H
+#define MC_PAGE_STORE_H
 
-#ifndef MC_PAGE_SNAPSHOT_H
-#define MC_PAGE_SNAPSHOT_H
+struct s_mc_pages_store;
+
+#ifdef __cplusplus
 
 /** @brief Storage for snapshot memory pages
  *
  *
  */
 struct s_mc_pages_store {
-private: // Types
+public: // Types
+#ifdef MC_PAGE_STORE_MD4
+  typedef boost::array<uint64_t,2> hash_type;
+#else
   typedef uint64_t hash_type;
-  typedef boost ::unordered_set<size_t> page_set_type;
+#endif
+private: // Types
+#ifdef MC_PAGE_STORE_MD4
+  // We are using a secure hash to identify a page.
+  // We assume there will not be any collision: we need to map a hash
+  // to a single page index.
+  typedef boost::unordered_map<hash_type, size_t> pages_map_type;
+#else
+  // We are using a cheap hash to index a page.
+  // We should expect collision and we need to associate multiple page indices
+  // to the same hash.
+  typedef boost::unordered_set<size_t> page_set_type;
   typedef boost::unordered_map<hash_type, page_set_type> pages_map_type;
+#endif
 
 private: // Fields:
-  /** First page */
+  /** First page
+   *
+   *  mc_page_store_get_page expects that this is the first field.
+   * */
   void* memory_;
   /** Number of available pages in virtual memory */
   size_t capacity_;
@@ -112,11 +137,7 @@ public: // Methods
    * it is added to the `free_pages_` list and removed from the `hash_index_`.
    *
    * */
-  void unref_page(size_t pageno) {
-    if ((--this->page_counts_[pageno]) == 0) {
-      this->remove_page(pageno);
-    }
-  }
+  void unref_page(size_t pageno);
 
   /** @brief Increment the refcount for a given page
    *
@@ -128,9 +149,7 @@ public: // Methods
    * changed since the previous cnapshot/restoration and we can avoid
    * hashing the page, comparing byte-per-byte to candidates.
    * */
-  void ref_page(size_t pageno) {
-    ++this->page_counts_[pageno];
-  }
+  void ref_page(size_t pageno);
 
   /** @brief Store a page in the page store */
   size_t store_page(void* page);
@@ -140,31 +159,73 @@ public: // Methods
    *  @param Number of the memory page in the store
    *  @return Start of the page
    */
-  const void* get_page(size_t pageno) const {
-    return mc_page_from_number(this->memory_, pageno);
-  }
+  const void* get_page(size_t pageno) const;
 
 public: // Debug/test methods
 
   /** @brief Get the number of references for a page */
-  size_t get_ref(size_t pageno) {
-    return this->page_counts_[pageno];
-  }
+  size_t get_ref(size_t pageno);
 
   /** @brief Get the number of used pages */
-  size_t size() {
-    return this->top_index_ - this->free_pages_.size();
-  }
+  size_t size();
 
   /** @brief Get the capacity of the page store
    *
    *  The capacity is expanded by a system call (mremap).
    * */
-  size_t capacity() {
-    return this->capacity_;
-  }
+  size_t capacity();
 
 };
 
+inline __attribute__((always_inline))
+void s_mc_pages_store::unref_page(size_t pageno) {
+  if ((--this->page_counts_[pageno]) == 0) {
+    this->remove_page(pageno);
+  }
+}
+
+inline __attribute__((always_inline))
+void s_mc_pages_store::ref_page(size_t pageno) {
+  ++this->page_counts_[pageno];
+}
+
+inline __attribute__((always_inline))
+const void* s_mc_pages_store::get_page(size_t pageno) const {
+  return mc_page_from_number(this->memory_, pageno);
+}
+
+inline __attribute__((always_inline))
+size_t s_mc_pages_store::get_ref(size_t pageno)  {
+  return this->page_counts_[pageno];
+}
+
+inline __attribute__((always_inline))
+size_t s_mc_pages_store::size() {
+  return this->top_index_ - this->free_pages_.size();
+}
+
+inline __attribute__((always_inline))
+size_t s_mc_pages_store::capacity() {
+  return this->capacity_;
+}
+
 #endif
 
+SG_BEGIN_DECL()
+
+mc_pages_store_t mc_pages_store_new(void);
+void mc_pages_store_delete(mc_pages_store_t store);
+
+/**
+ */
+static inline __attribute__((always_inline))
+const void* mc_page_store_get_page(mc_pages_store_t page_store, size_t pageno)
+{
+  // This is page_store->memory_:
+  void* memory = *(void**)page_store;
+  return mc_page_from_number(memory, pageno);
+}
+
+SG_END_DECL()
+
+#endif