The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
buddy.c File Reference

A Buddy System implementation. More...

#include <mm/buddy/buddy.h>
#include <core/core.h>
#include <core/intrinsics.h>
#include <lp/lp.h>
#include <errno.h>
#include <stdlib.h>
+ Include dependency graph for buddy.c:

Go to the source code of this file.

Macros

#define left_child(i)   (((i) << 1U) + 1U)
 
#define right_child(i)   (((i) << 1U) + 2U)
 
#define parent(i)   ((((i) + 1) >> 1U) - 1U)
 
#define is_power_of_2(i)   (!((i) & ((i) - 1)))
 
#define next_exp_of_2(i)   (sizeof(i) * CHAR_BIT - intrinsics_clz(i))
 
#define buddy_tree_visit(longest, on_visit)
 
#define copy_block_to_ckp(i)
 
#define copy_dirty_block(i)
 
#define copy_block_from_ckp(i)
 
#define buddy_block_dirty_from_ckp(offset, len)
 
#define buddy_block_copy_to_ckp(offset, len)
 
#define buddy_block_copy_from_ckp(offset, len)
 

Functions

void model_allocator_lp_init (void)
 
void model_allocator_lp_fini (void)
 
void * malloc_mt (size_t req_size)
 
void * calloc_mt (size_t nmemb, size_t size)
 
void free_mt (void *ptr)
 
void * realloc_mt (void *ptr, size_t req_size)
 
void __write_mem (void *ptr, size_t siz)
 
static struct mm_checkpointcheckpoint_incremental_take (struct mm_state *self)
 
static void checkpoint_incremental_restore (struct mm_state *self, const struct mm_checkpoint *ckp)
 
static struct mm_checkpointcheckpoint_full_take (const struct mm_state *self)
 
static void checkpoint_full_restore (struct mm_state *self, const struct mm_checkpoint *ckp)
 
void model_allocator_checkpoint_take (array_count_t ref_i)
 
void model_allocator_checkpoint_next_force_full (void)
 
array_count_t model_allocator_checkpoint_restore (array_count_t ref_i)
 
array_count_t model_allocator_fossil_lp_collect (array_count_t tgt_ref_i)
 

Detailed Description

A Buddy System implementation.

Definition in file buddy.c.

Macro Definition Documentation

◆ buddy_block_copy_from_ckp

#define buddy_block_copy_from_ckp (   offset,
  len 
)
Value:
__extension__({ \
memcpy(self->base_mem + offset, ptr, len); \
ptr += len; \
})

◆ buddy_block_copy_to_ckp

#define buddy_block_copy_to_ckp (   offset,
  len 
)
Value:
__extension__({ \
memcpy(ptr, self->base_mem + offset, len); \
ptr += len; \
})

◆ buddy_block_dirty_from_ckp

#define buddy_block_dirty_from_ckp (   offset,
  len 
)
Value:
__extension__({ \
uint_fast32_t b_off = (offset >> B_BLOCK_EXP) + \
(1 << (B_TOTAL_EXP - 2 * B_BLOCK_EXP + 1)); \
uint_fast32_t b_len = len >> B_BLOCK_EXP; \
while (b_len--) { \
if (bitmap_check(self->dirty, b_off)) { \
memcpy(self->longest + (b_off << B_BLOCK_EXP), \
ptr, (1 << B_BLOCK_EXP)); \
} \
ptr += 1 << B_BLOCK_EXP; \
b_off++; \
} \
})

◆ buddy_tree_visit

#define buddy_tree_visit (   longest,
  on_visit 
)
Value:
__extension__({ \
bool __vis = false; \
uint_fast8_t __l = B_TOTAL_EXP; \
uint_fast32_t __i = 0; \
while (1) { \
uint_fast8_t __lon = longest[__i]; \
if (!__lon) { \
uint_fast32_t __len = 1U << __l; \
uint_fast32_t __o = \
((__i + 1) << __l) - (1 << B_TOTAL_EXP);\
on_visit(__o, __len); \
} else if(__lon != __l) { \
__i = left_child(__i) + __vis; \
__vis = false; \
__l--; \
continue; \
} \
do { \
__vis = !(__i & 1U); \
__i = parent(__i); \
__l++; \
} while(__vis); \
\
if (__l > B_TOTAL_EXP) break; \
__vis = true; \
} \
})

Definition at line 163 of file buddy.c.

◆ copy_block_from_ckp

#define copy_block_from_ckp (   i)
Value:
__extension__({ \
memcpy(self->longest + (i << B_BLOCK_EXP), cur_ckp->longest + \
(i << B_BLOCK_EXP), 1 << B_BLOCK_EXP); \
})

◆ copy_block_to_ckp

#define copy_block_to_ckp (   i)
Value:
__extension__({ \
memcpy(ptr, src + (i << B_BLOCK_EXP), 1 << B_BLOCK_EXP); \
ptr += 1 << B_BLOCK_EXP; \
})

◆ copy_dirty_block

#define copy_dirty_block (   i)
Value:
__extension__({ \
if (bitmap_check(self->dirty, i)) { \
memcpy(self->longest + (i << B_BLOCK_EXP), ptr, \
1 << B_BLOCK_EXP); \
bitmap_reset(self->dirty, i); \
bset--; \
} \
ptr += 1 << B_BLOCK_EXP; \
})
bitmap_check
#define bitmap_check(bitmap, bit_index)
Checks a bit in a bitmap.
Definition: bitmap.h:105