The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
dymelor.h File Reference

Dynamic Memory Logger and Restorer (DyMeLoR) More...

#include <math.h>
#include <string.h>
#include <core/core.h>
#include <datatypes/bitmap.h>
#include <mm/state.h>
#include <core/timer.h>
+ Include dependency graph for dymelor.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _malloc_area
 This structure let DyMeLoR handle one malloc area (for serving given-size memory requests) More...
 
struct  _malloc_state
 Definition of the memory map. More...
 

Macros

#define LP_PREALLOCATION_INITIAL_ADDRESS   (void *)0x0000008000000000
 
#define MASK   0x00000001
 
#define MIN_CHUNK_SIZE   128
 
#define MAX_CHUNK_SIZE   4194304
 
#define NUM_AREAS   (log2(MAX_CHUNK_SIZE) - log2(MIN_CHUNK_SIZE) + 1)
 
#define MAX_NUM_AREAS   (NUM_AREAS * 32)
 
#define MAX_LIMIT_NUM_AREAS   MAX_NUM_AREAS
 
#define MIN_NUM_CHUNKS   512
 
#define MAX_NUM_CHUNKS   4096
 
#define MAX_LOG_THRESHOLD   1.7
 
#define MIN_LOG_THRESHOLD   1.7
 
#define INCREMENTAL_GRANULARITY   50
 
#define LITTLE_SIZE   32
 
#define CHECK_SIZE   0.25
 
#define GET_CACHE_LINE_NUMBER(P)   ((unsigned long)((P >> 4) & (CACHE_SIZE - 1)))
 
#define SET_LOG_MODE_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size |= (MASK << 0))
 
#define RESET_LOG_MODE_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size &= ~(MASK << 0))
 
#define CHECK_LOG_MODE_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size & (MASK << 0))
 
#define SET_AREA_LOCK_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size |= (MASK << 1))
 
#define RESET_AREA_LOCK_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size &= ~(MASK << 1))
 
#define CHECK_AREA_LOCK_BIT(m_area)   (((malloc_area*)(m_area))->chunk_size & (MASK << 1))
 
#define UNTAGGED_CHUNK_SIZE(m_area)   (((malloc_area*)(m_area))->chunk_size & ~((MASK << 0) | (MASK << 1)))
 
#define POWEROF2(x)   (1UL << (1 + (63 - __builtin_clzl((x) - 1))))
 
#define IS_POWEROF2(x)   ((x) != 0 && ((x) & ((x) - 1)) == 0)
 
#define is_incremental(ckpt)   (((malloc_state *)ckpt)->is_incremental == true)
 
#define get_top_pointer(ptr)   ((unsigned long long *)((char *)ptr - sizeof(unsigned long long)))
 
#define get_area_top_pointer(ptr)   ( (malloc_area **)(*get_top_pointer(ptr)) )
 
#define get_area(ptr)   ( *(get_area_top_pointer(ptr)) )
 

Typedefs

typedef struct _malloc_area malloc_area
 
typedef struct _malloc_state malloc_state
 

Functions

void set_force_full (unsigned int, int)
 
void dirty_mem (void *, int)
 
size_t get_state_size (int)
 
size_t get_log_size (malloc_state *)
 
size_t get_inc_log_size (void *)
 
int get_granularity (void)
 
size_t dirty_size (unsigned int, void *, double *)
 
malloc_statemalloc_state_init (void)
 
void malloc_state_wipe (malloc_state **)
 
void * do_malloc (struct lp_struct *, size_t)
 
void do_free (struct lp_struct *, void *ptr)
 
void * allocate_lp_memory (struct lp_struct *, size_t)
 
void free_lp_memory (struct lp_struct *, void *)
 
void * log_full (struct lp_struct *)
 
void * log_state (struct lp_struct *)
 
void log_restore (struct lp_struct *, state_t *)
 
void log_delete (void *)
 
void * __wrap_malloc (size_t)
 
void __wrap_free (void *)
 
void * __wrap_realloc (void *, size_t)
 
void * __wrap_calloc (size_t, size_t)
 
void clean_buffers_on_gvt (struct lp_struct *, simtime_t)
 
void * rsalloc (size_t)
 
void rsfree (void *)
 
void * rsrealloc (void *, size_t)
 
void * rscalloc (size_t, size_t)
 
void ecs_init (void)
 

Detailed Description

Dynamic Memory Logger and Restorer (DyMeLoR)

LP's memory manager.

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.

ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Roberto Toccaceli
Alessandro Pellegrini
Roberto Vitali
Francesco Quaglia
Date
April 02, 2008

Definition in file dymelor.h.

Function Documentation

void* __wrap_calloc ( size_t  nmemb,
size_t  size 
)

This is the wrapper of the real stdlib calloc(). Whenever the application level software calls calloc, the call is redirected to this piece of code which relies on wrap_malloc

Author
Roberto Vitali
Parameters
nmembThe number of elements to be allocated
sizeThe size of each allocated member
Returns
A pointer to the newly allocated buffer

Definition at line 677 of file dymelor.c.

+ Here is the call graph for this function:

void __wrap_free ( void *  ptr)

This is the wrapper of the real stdlib free(). Whenever the application level software calls free, the call is redirected to this piece of code which will set the chunk in the corresponding malloc_area as not allocated.

For further information, please see the paper: R. Toccaceli, F. Quaglia DyMeLoR: Dynamic Memory Logger and Restorer Library for Optimistic Simulation Objects with Generic Memory Layout Proceedings of the 22nd Workshop on Principles of Advanced and Distributed Simulation 2008

Author
Roberto Toccaceli
Francesco Quaglia
Parameters
ptrA memory buffer to be free'd

Definition at line 602 of file dymelor.c.

+ Here is the caller graph for this function:

void* __wrap_malloc ( size_t  size)

This is the wrapper of the real stdlib malloc(). Whenever the application level software calls malloc, the call is redirected to this piece of code which uses the memory preallocated by the DyMeLoR subsystem for serving the request. If the memory in the malloc_area is exhausted, a new one is created, relying on the stdlib malloc. In future releases, this wrapper will be integrated with the Memory Management subsystem, which is not yet ready for production.

Author
Roberto Toccaceli
Francesco Quaglia
Parameters
sizeSize of the allocation
Returns
A pointer to the allocated memory

Definition at line 566 of file dymelor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* __wrap_realloc ( void *  ptr,
size_t  size 
)

This is the wrapper of the real stdlib realloc(). Whenever the application level software calls realloc, the call is redirected to this piece of code which rely on wrap_malloc

Author
Roberto Vitali
Parameters
ptrThe pointer to be buffer to be reallocated
sizeThe size of the allocation
Returns
A pointer to the newly allocated buffer

Definition at line 628 of file dymelor.c.

+ Here is the call graph for this function:

void dirty_mem ( void *  base,
int  size 
)

This function marks a memory chunk as dirty. It is invoked from assembly modules invoked by calls injected by the instrumentor, and from the third-party library wrapper. Invocations from other parts of the kernel should be handled with great care.

Author
Alessandro Pellegrini
Roberto Vitali
Parameters
baseThe initial to the start address of the update
sizeThe number of bytes being updated

Definition at line 453 of file dymelor.c.

void* do_malloc ( struct lp_struct ,
size_t   
)

Definition at line 172 of file dymelor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t get_log_size ( malloc_state logged_state)

This function returns the whole size of a state. It can be used as the total size to pack a log

Author
Alessandro Pellegrini
Roberto Vitali
Parameters
logged_stateThe pointer to the log, or to the state
Returns
The whole size of the state (metadata included)

Definition at line 534 of file dymelor.c.

+ Here is the caller graph for this function:

void log_delete ( void *  ckpt)

This function is called directly from the simulation platform kernel to delete a certain log during the fossil collection.

Author
Alessandro Pellegrini
Roberto Vitali
Parameters
ckpta pointer to the simulation state which must be deleted

Definition at line 374 of file checkpoints.c.

+ Here is the caller graph for this function:

void* log_full ( struct lp_struct lp)

This function creates a full log of the current simulation states and returns a pointer to it. The algorithm behind this function is based on packing of the really allocated memory chunks into a contiguous memory area, exploiting some threshold-based approach to fasten it up even more. The contiguous copy is performed precomputing the size of the full log, and then scanning it using a pointer for storing the relevant information.

For further information, please see the paper: R. Toccaceli, F. Quaglia DyMeLoR: Dynamic Memory Logger and Restorer Library for Optimistic Simulation Objects with Generic Memory Layout Proceedings of the 22nd Workshop on Principles of Advanced and Distributed Simulation 2008

To fully understand the changes in this function to support the incremental logging as well, please point to the paper: A. Pellegrini, R. Vitali, F. Quaglia Di-DyMeLoR: Logging only Dirty Chunks for Efficient Management of Dynamic Memory Based Optimistic Simulation Objects Proceedings of the 23rd Workshop on Principles of Advanced and Distributed Simulation 2009

Author
Roberto Toccaceli
Francesco Quaglia
Alessandro Pellegrini
Roberto Vitali
Parameters
lpA pointer to the lp_struct of the LP for which we are taking a full log of the buffers keeping the current simulation state.
Returns
A pointer to a malloc()'d memory area which contains the full log of the current simulation state, along with the relative meta-data which can be used to perform a restore operation.

Definition at line 76 of file checkpoints.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void log_restore ( struct lp_struct lp,
state_t state_queue_node 
)

Upon the decision of performing a rollback operation, this function is invoked by the simulation kernel to perform a restore operation. This function checks the mark in the malloc_state telling whether we're dealing with a full or partial log, and calls the proper function accordingly

Author
Alessandro Pellegrini
Roberto Vitali
Parameters
lpA pointer to the lp_struct of the LP for which we are restoring model-specific buffers keeping the simulation state
state_queue_nodea pointer to a node in the state queue keeping the state which must be restored in the logical process live image

Definition at line 358 of file checkpoints.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* log_state ( struct lp_struct lp)

This function is the only log function which should be called from the simulation platform. Actually, it is a demultiplexer which calls the correct function depending on the current configuration of the platform. Note that this function only returns a pointer to a malloc'd area which contains the state buffers. This means that this memory area cannot be used as-is, but should be wrapped into a state_t structure, which gives information about the simulation state pointer (defined via SetState() by the application-level code and the lvt associated with the log. This is done implicitly by the LogState() function, which in turn connects the newly taken snapshot with the currencly-scheduled LP. Therefore, any point of the simulator which wants to take a (real) log, shouldn't call directly this function, rather LogState() should be used, after having correctly set current and current_lvt.

Author
Alessandro Pellegrini
Parameters
lpA pointer to the lp_struct of the LP for which we want to take a snapshot of the buffers used by the model to keep state variables.
Returns
A pointer to a malloc()'d memory area which contains the log of the current simulation state, along with the relative meta-data which can be used to perform a restore operation.

Definition at line 195 of file checkpoints.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

malloc_state* malloc_state_init ( void  )

This function inizializes a malloc_state.

Definition at line 77 of file dymelor.c.

+ Here is the call graph for this function: