From: Gabriel Corona Date: Mon, 22 Feb 2016 11:22:40 +0000 (+0100) Subject: [mc] Replace ReadMode with strongly-type/safe ReadOptions X-Git-Tag: v3_13~755^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/891e867e03bb32439d42d50d0912bb16c4618e90 [mc] Replace ReadMode with strongly-type/safe ReadOptions --- diff --git a/src/mc/AddressSpace.hpp b/src/mc/AddressSpace.hpp index 41f1f8bcf5..159642fd6a 100644 --- a/src/mc/AddressSpace.hpp +++ b/src/mc/AddressSpace.hpp @@ -132,6 +132,63 @@ const int ProcessIndexDisabled = -2; */ const int ProcessIndexAny = 0; +/** Options for read operations + * + * This is a set of flags managed with bitwise operators. Only the + * meaningful operations are defined: addition, conversions to/from + * integers are not allowed. + */ +class ReadOptions { + std::uint32_t value_; + constexpr explicit ReadOptions(std::uint32_t value) : value_(value) {} +public: + constexpr ReadOptions() : value_(0) {} + + constexpr operator bool() const { return value_ != 0; } + constexpr operator!() const { return value_ == 0; } + + constexpr ReadOptions operator|(ReadOptions const& that) const + { + return ReadOptions(value_ | that.value_); + } + constexpr ReadOptions operator&(ReadOptions const& that) const + { + return ReadOptions(value_ & that.value_); + } + constexpr ReadOptions operator^(ReadOptions const& that) const + { + return ReadOptions(value_ ^ that.value_); + } + constexpr ReadOptions operator~() const + { + return ReadOptions(~value_); + } + + ReadOptions& operator|=(ReadOptions const& that) + { + value_ |= that.value_; + return *this; + } + ReadOptions& operator&=(ReadOptions const& that) + { + value_ &= that.value_; + return *this; + } + ReadOptions& operator^=(ReadOptions const& that) + { + value_ &= that.value_; + return *this; + } + + /** Copy the data to the given buffer */ + static constexpr ReadOptions none() { return ReadOptions(0); } + + /** Allows to return a pointer to another buffer where the data is + * available instead of copying the data into the buffer + */ + static constexpr ReadOptions lazy() { return ReadOptions(1); } +}; + /** A given state of a given process (abstract base class) * * Currently, this might either be: @@ -144,21 +201,6 @@ class AddressSpace { private: Process* process_; public: - enum ReadMode { - - /** Copy the data to the given buffer */ - Normal, - - /** Allows the `read_bytes` to return a pointer to another buffer - * where the data is available instead of copying the data into the - * buffer. - * - * This adds quite a level of ugliness but it was found to more - * efficient at some point. We should check if there is still - * a noticeable different and get rid of it. - */ - Lazy - }; AddressSpace(Process* process) : process_(process) {} virtual ~AddressSpace(); @@ -170,11 +212,11 @@ public: * @param size number of bytes * @param address remote source address of the data * @param process_index which process (used for SMPI privatization) - * @param mode + * @param options */ virtual const void* read_bytes(void* buffer, std::size_t size, remote_ptr address, int process_index = ProcessIndexAny, - ReadMode mode = Normal) const = 0; + ReadOptions options = ReadOptions::none()) const = 0; /** Read a given data structure from the address space */ template inline diff --git a/src/mc/Process.cpp b/src/mc/Process.cpp index d7e12bf060..2e6d79297c 100644 --- a/src/mc/Process.cpp +++ b/src/mc/Process.cpp @@ -506,7 +506,7 @@ char* Process::read_string(remote_ptr address) const const void *Process::read_bytes(void* buffer, std::size_t size, remote_ptr address, int process_index, - AddressSpace::ReadMode mode) const + ReadOptions options) const { if (process_index != simgrid::mc::ProcessIndexDisabled) { std::shared_ptr const& info = diff --git a/src/mc/Process.hpp b/src/mc/Process.hpp index 2f51240fcf..8780e3cc5a 100644 --- a/src/mc/Process.hpp +++ b/src/mc/Process.hpp @@ -75,7 +75,7 @@ public: // Read memory: const void* read_bytes(void* buffer, std::size_t size, remote_ptr address, int process_index = ProcessIndexAny, - ReadMode mode = Normal) const override; + ReadOptions options = ReadOptions::none()) const override; void read_variable(const char* name, void* target, size_t size) const; template T read_variable(const char *name) const diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index daf84c8108..dd6dd27c39 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -440,11 +440,11 @@ int snapshot_compare(void *state1, void *state2) xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes( alloca(sizeof(struct mdesc)), sizeof(struct mdesc), remote(process->heap_address), - simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy); + simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy()); xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes( alloca(sizeof(struct mdesc)), sizeof(struct mdesc), remote(process->heap_address), - simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy); + simgrid::mc::ProcessIndexMissing, simgrid::mc::ReadOptions::lazy()); res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore); if (res_init == -1) { #ifdef MC_DEBUG @@ -520,7 +520,8 @@ int snapshot_compare(void *state1, void *state2) /* Compare global variables */ is_diff = - compare_global_variables(region1->object_info( ), simgrid::mc::AddressSpace::Normal, + compare_global_variables(region1->object_info(), + simgrid::mc::ProcessIndexDisabled, region1, region2, s1, s2); diff --git a/src/mc/mc_snapshot.cpp b/src/mc/mc_snapshot.cpp index a1ea070637..ec1bd479ba 100644 --- a/src/mc/mc_snapshot.cpp +++ b/src/mc/mc_snapshot.cpp @@ -171,12 +171,12 @@ Snapshot::~Snapshot() const void* Snapshot::read_bytes(void* buffer, std::size_t size, remote_ptr address, int process_index, - AddressSpace::ReadMode mode) const + ReadOptions options) const { mc_mem_region_t region = mc_get_snapshot_region((void*)address.address(), this, process_index); if (region) { const void* res = MC_region_read(region, buffer, (void*)address.address(), size); - if (buffer == res || mode == AddressSpace::Lazy) + if (buffer == res || options & ReadOptions::lazy()) return res; else { memcpy(buffer, res, size); @@ -185,7 +185,7 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size, } else return this->process()->read_bytes( - buffer, size, address, process_index, mode); + buffer, size, address, process_index, options); } } diff --git a/src/mc/mc_snapshot.h b/src/mc/mc_snapshot.h index 5c638f6f81..8960b450a2 100644 --- a/src/mc/mc_snapshot.h +++ b/src/mc/mc_snapshot.h @@ -146,7 +146,7 @@ public: ~Snapshot(); const void* read_bytes(void* buffer, std::size_t size, remote_ptr address, int process_index = ProcessIndexAny, - ReadMode mode = Normal) const override; + ReadOptions options = ReadOptions::none()) const override; public: // To be private int num_state; std::size_t heap_bytes_used;