X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fa222c38f9b796be07ab4351ffc810a61a8fd705..8406356fb85d1428cf121fbb99c45277af246fad:/src/mc/mc_mmu.h diff --git a/src/mc/mc_mmu.h b/src/mc/mc_mmu.h index 6968f7bd38..c7d5b976f1 100644 --- a/src/mc/mc_mmu.h +++ b/src/mc/mc_mmu.h @@ -1,5 +1,4 @@ -/* Copyright (c) 2014-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2014-2017. 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. */ @@ -7,71 +6,58 @@ #ifndef SIMGRID_MC_MMU_H #define SIMGRID_MC_MMU_H -#include -#include +#include "xbt/misc.h" // xbt_pagesize... -#include -#include +namespace simgrid { +namespace mc { +// TODO, do not depend on xbt_pagesize/xbt_pagebits but our own chunk size +namespace mmu { -#include - -SG_BEGIN_DECL() +static int chunkSize() +{ + return xbt_pagesize; +} /** @brief How many memory pages are necessary to store size bytes? * * @param size Byte size * @return Number of memory pages */ -static inline __attribute__ ((always_inline)) -size_t mc_page_count(size_t size) +static XBT_ALWAYS_INLINE std::size_t chunkCount(std::size_t size) { size_t page_count = size >> xbt_pagebits; - if (size & (xbt_pagesize-1)) { + if (size & (xbt_pagesize-1)) page_count ++; - } return page_count; } -/** @brief Get the virtual memory page number of a given address - * - * @param address Address - * @return Virtual memory page number of the given address - */ -static inline __attribute__ ((always_inline)) -size_t mc_page_number(const void* base, const void* address) +/** @brief Split into chunk number and remaining offset */ +static XBT_ALWAYS_INLINE std::pair split(std::uintptr_t offset) { - xbt_assert(address>=base, "The address is not in the range"); - return ((uintptr_t) address - (uintptr_t) base) >> xbt_pagebits; + return { + offset >> xbt_pagebits, + offset & (xbt_pagesize-1) + }; } -/** @brief Get the offset of an address within a memory page - * - * @param address Address - * @return Offset within the memory page - */ -static inline __attribute__ ((always_inline)) -size_t mc_page_offset(const void* address) +/** Merge chunk number and remaining offset info a global offset */ +static XBT_ALWAYS_INLINE std::uintptr_t join(std::size_t page, std::uintptr_t offset) { - return ((uintptr_t) address) & (xbt_pagesize-1); + return ((std::uintptr_t) page << xbt_pagebits) + offset; } -/** @brief Get the virtual address of a virtual memory page - * - * @param base Address of the first page - * @param page Index of the page - */ -static inline __attribute__ ((always_inline)) -void* mc_page_from_number(const void* base, size_t page) +static XBT_ALWAYS_INLINE std::uintptr_t join(std::pair value) { - return (void*) ((char*)base + (page << xbt_pagebits)); + return join(value.first, value.second); } -static inline __attribute__ ((always_inline)) -bool mc_same_page(const void* a, const void* b) +static XBT_ALWAYS_INLINE bool sameChunk(std::uintptr_t a, std::uintptr_t b) { - return ((uintptr_t) a >> xbt_pagebits) == ((uintptr_t) b >> xbt_pagebits); + return (a >> xbt_pagebits) == (b >> xbt_pagebits); } -SG_END_DECL() +} +} +} #endif