#include <sys/types.h>
#include <simgrid_config.h>
-#include <xbt/dynar.h>
+#include <xbt/dict.h>
#include "mc_forward.h"
#include "mc_process.h"
// TODO, use std::unordered_set with heterogeneous comparison lookup (C++14)
xbt_dict_t /* <hostname, NULL> */ hostnames_;
// This is the parent snapshot of the current state:
- s_mc_pages_store_t page_store_;
- s_mc_process_t process_;
+ PageStore page_store_;
+ Process process_;
public:
ModelChecker(ModelChecker const&) = delete;
ModelChecker& operator=(ModelChecker const&) = delete;
ModelChecker(pid_t pid, int socket);
~ModelChecker();
- s_mc_process_t& process()
+ Process& process()
{
return process_;
}
static inline __attribute__ ((always_inline))
PageStore::hash_type mc_hash_page(const void* data)
{
- const uint64_t* values = (const uint64_t*) data;
- size_t n = xbt_pagesize / sizeof(uint64_t);
+ const std::uint64_t* values = (const uint64_t*) data;
+ std::size_t n = xbt_pagesize / sizeof(uint64_t);
// This djb2:
- uint64_t hash = 5381;
- for (size_t i=0; i!=n; ++i) {
+ std::uint64_t hash = 5381;
+ for (std::size_t i = 0; i != n; ++i) {
hash = ((hash << 5) + hash) + values[i];
}
return hash;
// Using mmap in order to be able to expand the region
// by relocating it somewhere else in the virtual memory
// space:
- void * memory = ::mmap(NULL, size << xbt_pagebits, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
- if (memory==MAP_FAILED) {
+ void* memory = ::mmap(NULL, size << xbt_pagebits, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
+ if (memory == MAP_FAILED) {
xbt_die("Could not mmap initial snapshot pages.");
}
::munmap(this->memory_, this->capacity_ << xbt_pagebits);
}
-void PageStore::resize(size_t size)
+void PageStore::resize(std::size_t size)
{
size_t old_bytesize = this->capacity_ << xbt_pagebits;
size_t new_bytesize = size << xbt_pagebits;
*
* @return index of the free page
*/
-size_t PageStore::alloc_page()
+std::size_t PageStore::alloc_page()
{
if (this->free_pages_.empty()) {
}
}
-void PageStore::remove_page(size_t pageno)
+void PageStore::remove_page(std::size_t pageno)
{
this->free_pages_.push_back(pageno);
const void* page = this->get_page(pageno);
}
/** Store a page in memory */
-size_t PageStore::store_page(void* page)
+std::size_t PageStore::store_page(void* page)
{
xbt_assert(top_index_ <= this->capacity_, "top_index is not consistent");
// Otherwise, a new page is allocated in the page store and the content
// of the page is `memcpy()`-ed to this new page.
- size_t pageno = alloc_page();
+ std::size_t pageno = alloc_page();
xbt_assert(this->page_counts_[pageno]==0, "Allocated page is already used");
void* snapshot_page = (void*) this->get_page(pageno);
memcpy(snapshot_page, page, xbt_pagesize);
#ifdef SIMGRID_TEST
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
+#include <cstring>
+#include <cstdint>
+
#include <unistd.h>
#include <sys/mman.h>
static int value = 0;
-static void new_content(void* data, size_t size)
+static void new_content(void* data, std::size_t size)
{
- memset(data, ++value, size);
+ ::memset(data, ++value, size);
}
static void* getpage()
XBT_TEST_UNIT("base", test_mc_page_store, "Test adding/removing pages in the store")
{
+ using simgrid::mc::PageStore;
+
xbt_test_add("Init");
- size_t pagesize = (size_t) getpagesize();
- std::unique_ptr<simgrid::mc::PageStore> store
- = std::unique_ptr<simgrid::mc::PageStore>(new simgrid::mc::PageStore(500));
+ std::size_t pagesize = (size_t) getpagesize();
+ std::unique_ptr<PageStore> store
+ = std::unique_ptr<PageStore>(new simgrid::mc::PageStore(500));
void* data = getpage();
xbt_test_assert(store->size()==0, "Bad size");
size_t pageno1 = store->store_page(data);
xbt_test_assert(store->get_ref(pageno1)==1, "Bad refcount");
const void* copy = store->get_page(pageno1);
- xbt_test_assert(memcmp(data, copy, pagesize)==0, "Page data should be the same");
+ xbt_test_assert(::memcmp(data, copy, pagesize)==0, "Page data should be the same");
xbt_test_assert(store->size()==1, "Bad size");
xbt_test_add("Store the same page again");
#ifndef SIMGRID_MC_PAGESTORE_HPP
#define SIMGRID_MC_PAGESTORE_HPP
-#include <stdint.h>
-
+#include <cstdint>
#include <vector>
-#include <boost/array.hpp>
-#include <boost/utility.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
-#include <xbt.h>
-
#include "mc_mmu.h"
#include "mc_forward.h"
*/
class PageStore {
public: // Types
- typedef uint64_t hash_type;
+ typedef std::uint64_t hash_type;
private: // Types
// 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_set<std::size_t> page_set_type;
typedef boost::unordered_map<hash_type, page_set_type> pages_map_type;
private: // Fields:
- /** First page
- *
- * mc_page_store_get_page expects that this is the first field.
- * */
+ /** First page */
void* memory_;
/** Number of available pages in virtual memory */
- size_t capacity_;
+ std::size_t capacity_;
/** Top of the used pages (index of the next available page) */
- size_t top_index_;
+ std::size_t top_index_;
/** Page reference count */
- std::vector<uint64_t> page_counts_;
+ std::vector<std::uint64_t> page_counts_;
/** Index of available pages before the top */
- std::vector<size_t> free_pages_;
+ std::vector<std::size_t> free_pages_;
/** Index from page hash to page index */
pages_map_type hash_index_;
private: // Methods
- void resize(size_t size);
- size_t alloc_page();
- void remove_page(size_t pageno);
+ void resize(std::size_t size);
+ std::size_t alloc_page();
+ void remove_page(std::size_t pageno);
public: // Constructors
PageStore(PageStore const&) = delete;
PageStore& operator=(PageStore const&) = delete;
- explicit PageStore(size_t size);
+ explicit PageStore(std::size_t size);
~PageStore();
public: // Methods
* it is added to the `free_pages_` list and removed from the `hash_index_`.
*
* */
- void unref_page(size_t pageno);
+ void unref_page(std::size_t pageno);
/** @brief Increment the refcount for a given page
*
* @param Number of the memory page in the store
* @return Start of the page
*/
- const void* get_page(size_t pageno) const;
+ const void* get_page(std::size_t pageno) const;
public: // Debug/test methods
/** @brief Get the number of references for a page */
- size_t get_ref(size_t pageno);
+ std::size_t get_ref(std::size_t pageno);
/** @brief Get the number of used pages */
- size_t size();
+ std::size_t size();
/** @brief Get the capacity of the page store
*
* The capacity is expanded by a system call (mremap).
* */
- size_t capacity();
+ std::size_t capacity();
};
inline __attribute__((always_inline))
-void PageStore::unref_page(size_t pageno) {
- if ((--this->page_counts_[pageno]) == 0) {
+void PageStore::unref_page(std::size_t pageno) {
+ if ((--this->page_counts_[pageno]) == 0)
this->remove_page(pageno);
- }
}
inline __attribute__((always_inline))
-void PageStore::ref_page(size_t pageno) {
+void PageStore::ref_page(size_t pageno)
+{
++this->page_counts_[pageno];
}
inline __attribute__((always_inline))
-const void* PageStore::get_page(size_t pageno) const {
+const void* PageStore::get_page(std::size_t pageno) const
+{
return mc_page_from_number(this->memory_, pageno);
}
inline __attribute__((always_inline))
-size_t PageStore::get_ref(size_t pageno) {
+std::size_t PageStore::get_ref(std::size_t pageno)
+{
return this->page_counts_[pageno];
}
}
inline __attribute__((always_inline))
-size_t PageStore::capacity() {
+std::size_t PageStore::capacity()
+{
return this->capacity_;
}