Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"new" memory allocator for LPs memory: DyMeLoR! #85

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ set(rscore_srcs
log/stats.c
lp/lp.c
lp/process.c
mm/auto_ckpt.c
mm/buddy/buddy.c
mm/buddy/ckpt.c
mm/buddy/multi.c
mm/buddy/multi_buddy.c
mm/dymelor/checkpoint.c
mm/dymelor/dymelor.c
mm/auto_ckpt.c
mm/model_allocator.c
mm/msg_allocator.c
parallel/parallel.c
serial/serial.c)
Expand Down
7 changes: 7 additions & 0 deletions src/ROOT-Sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ extern struct topology *vInitializeTopology(enum topology_geometry geometry, int
#define InitializeTopology(geometry, ...) vInitializeTopology(geometry, PP_NARG(__VA_ARGS__), __VA_ARGS__)
/********* TOPOLOGY LIBRARY ************/

enum mm_allocator_choice {
MM_MULTI_BUDDY,
MM_DYMELOR
};

/// A set of configurable values used by other modules
struct simulation_configuration {
/// The number of LPs to be used in the simulation
Expand All @@ -214,6 +219,8 @@ struct simulation_configuration {
unsigned n_threads;
/// The target termination logical time. Setting this value to zero means that LVT-based termination is disabled
simtime_t termination_time;

enum mm_allocator_choice mm;
/// The gvt period expressed in microseconds
unsigned gvt_period;
/// The logger verbosity level
Expand Down
10 changes: 5 additions & 5 deletions src/datatypes/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ typedef unsigned char block_bitmap;
*/
#define bitmap_count_set(bitmap, bitmap_size) \
__extension__({ \
unsigned __i = (bitmap_size) / B_BLOCK_SIZE; \
unsigned __ret = 0; \
uint_least32_t __i = (bitmap_size) / B_BLOCK_SIZE; \
uint_least32_t __ret = 0; \
B_BLOCK_TYPE *__block_b = B_UNION_CAST(bitmap); \
while(__i--) { \
__ret += intrinsics_popcount(__block_b[__i]); \
Expand Down Expand Up @@ -149,8 +149,8 @@ typedef unsigned char block_bitmap;
*/
#define bitmap_first_reset(bitmap, bitmap_size) \
__extension__({ \
unsigned __i, __blocks = (bitmap_size) / B_BLOCK_SIZE; \
unsigned __ret = UINT_MAX; \
uint_least32_t __i, __blocks = (bitmap_size) / B_BLOCK_SIZE; \
uint_least32_t __ret = UINT_MAX; \
B_BLOCK_TYPE __cur_block, *__block_b = B_UNION_CAST(bitmap); \
for(__i = 0; __i < __blocks; ++__i) { \
if((__cur_block = ~__block_b[__i])) { \
Expand All @@ -172,7 +172,7 @@ typedef unsigned char block_bitmap;
*/
#define bitmap_foreach_set(bitmap, bitmap_size, func) \
__extension__({ \
unsigned __i, __fnd, __blocks = (bitmap_size) / B_BLOCK_SIZE; \
uint_least32_t __i, __fnd, __blocks = (bitmap_size) / B_BLOCK_SIZE; \
B_BLOCK_TYPE __cur_block, *__block_b = B_UNION_CAST(bitmap); \
for(__i = 0; __i < __blocks; ++__i) { \
if((__cur_block = __block_b[__i])) { \
Expand Down
5 changes: 5 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ int RootsimInit(const struct simulation_configuration *conf)
return -1;
}

if(unlikely(global_config.mm != MM_MULTI_BUDDY && global_config.mm != MM_DYMELOR)) {
fprintf(stderr, "Incorrect model memory allocator choice\n");
return -1;
}

if(unlikely(global_config.n_threads > thread_cores_count())) {
fprintf(stderr, "Demanding %u cores, which are more than available (%u)\n", global_config.n_threads,
thread_cores_count());
Expand Down
12 changes: 6 additions & 6 deletions src/lp/lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <lp/lp.h>

#include <datatypes/msg_queue.h>
#include <mm/mm.h>
#include <core/sync.h>
#include <gvt/fossil.h>
#include <gvt/termination.h>
Expand Down Expand Up @@ -91,8 +90,8 @@ void lp_init(void)
struct lp_ctx *lp = &lps[i];
current_lp = lp;

model_allocator_lp_init();
lp->lib_ctx = rs_malloc(sizeof(*current_lp->lib_ctx));
model_allocator_lp_init(&lp->mm_state);
lp->lib_ctx = rs_malloc(sizeof(*lp->lib_ctx));

msg_queue_lp_init();
lib_lp_init();
Expand All @@ -117,12 +116,13 @@ void lp_fini(void)
sync_thread_barrier();

for(uint64_t i = lid_thread_first; i < lid_thread_end; ++i) {
current_lp = &lps[i];
struct lp_ctx *lp = &lps[i];
current_lp = lp;

process_lp_fini();
lib_lp_fini();
msg_queue_lp_fini();
model_allocator_lp_fini();
model_allocator_lp_fini(&lp->mm_state);
}

current_lp = NULL;
Expand All @@ -137,7 +137,7 @@ void lp_on_gvt(simtime_t gvt)
for(uint64_t i = lid_thread_first; i < lid_thread_end; ++i) {
struct lp_ctx *lp = &lps[i];
fossil_lp_on_gvt(lp, gvt);
auto_ckpt_lp_on_gvt(&lp->auto_ckpt, lp->mm_state.used_mem);
auto_ckpt_lp_on_gvt(&lp->auto_ckpt, model_allocator_state_size(&lp->mm_state));
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/lp/lp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

/// A complete LP context
struct lp_ctx {
/// ID of the current LP
lp_id_t id;
/// The termination time of this LP, handled by the termination module
simtime_t termination_t;
/// The additional libraries context of this LP
Expand Down
67 changes: 27 additions & 40 deletions src/lp/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ void process_fini(void)
array_fini(early_antis);
}

static inline void checkpoint_take(struct process_data *proc_p)
{
timer_uint t = timer_hr_new();
model_allocator_checkpoint_take(array_count(proc_p->p_msgs));
stats_take(STATS_CKPT_STATE_SIZE, current_lp->mm_state.used_mem);
stats_take(STATS_CKPT, 1);
stats_take(STATS_CKPT_STATE_SIZE, current_lp->mm_state.used_mem);
stats_take(STATS_CKPT_TIME, timer_hr_value(t));

}

/**
* @brief Initializes the processing module in the current LP
*/
Expand All @@ -111,8 +100,8 @@ void process_lp_init(void)
stats_take(STATS_MSG_PROCESSED, 1);

array_push(proc_p->p_msgs, msg);
model_allocator_checkpoint_next_force_full();
checkpoint_take(proc_p);
model_allocator_checkpoint_next_force_full(&lp->mm_state);
model_allocator_checkpoint_take(&lp->mm_state, array_count(lp->p.p_msgs));
}

/**
Expand Down Expand Up @@ -199,14 +188,14 @@ static inline void send_anti_messages(struct process_data *proc_p, array_count_t
array_count(proc_p->p_msgs) = past_i;
}

static void do_rollback(struct process_data *proc_p, array_count_t past_i)
static void do_rollback(struct lp_ctx *lp, array_count_t past_i)
{
timer_uint t = timer_hr_new();
send_anti_messages(proc_p, past_i);
array_count_t last_i = model_allocator_checkpoint_restore(past_i);
send_anti_messages(&lp->p, past_i);
array_count_t last_i = model_allocator_checkpoint_restore(&lp->mm_state, past_i);
stats_take(STATS_RECOVERY_TIME, timer_hr_value(t));
stats_take(STATS_ROLLBACK, 1);
silent_execution(proc_p, last_i, past_i);
silent_execution(&lp->p, last_i, past_i);
}

static inline array_count_t match_straggler_msg(const struct process_data *proc_p, const struct lp_msg *s_msg)
Expand Down Expand Up @@ -242,20 +231,20 @@ static inline array_count_t match_anti_msg(const struct process_data *proc_p, co
} while(1);
}

static inline void handle_remote_anti_msg(struct process_data *proc_p, const struct lp_msg *msg)
static inline void handle_remote_anti_msg(struct lp_ctx *lp, const struct lp_msg *msg)
{
uint32_t m_id = msg->raw_flags >> 2, m_seq = msg->m_seq;
array_count_t p_cnt = array_count(proc_p->p_msgs), past_i = 0;
array_count_t p_cnt = array_count(lp->p.p_msgs), past_i = 0;
while(likely(past_i < p_cnt)) {
array_count_t j = past_i;
struct lp_msg *amsg = array_get_at(proc_p->p_msgs, j);
struct lp_msg *amsg = array_get_at(lp->p.p_msgs, j);
while(is_msg_sent(amsg))
amsg = array_get_at(proc_p->p_msgs, ++j);
amsg = array_get_at(lp->p.p_msgs, ++j);

if(amsg->raw_flags >> 2 == m_id && amsg->m_seq == m_seq) {
// suppresses the re-insertion in the processing queue
amsg->raw_flags |= MSG_FLAG_ANTI;
do_rollback(proc_p, past_i);
do_rollback(lp, past_i);
termination_on_lp_rollback(msg->dest_t);
msg_allocator_free(amsg);
return;
Expand Down Expand Up @@ -302,48 +291,46 @@ void process_msg(void)

gvt_on_msg_extraction(msg->dest_t);

struct lp_ctx *this_lp = &lps[msg->dest];
struct process_data *proc_p = &this_lp->p;
current_lp = this_lp;
struct lp_ctx *lp = &lps[msg->dest];
current_lp = lp;

uint32_t flags = atomic_fetch_add_explicit(&msg->flags, MSG_FLAG_PROCESSED, memory_order_relaxed);

if(unlikely(flags & MSG_FLAG_ANTI)) {
if(flags > (MSG_FLAG_ANTI | MSG_FLAG_PROCESSED)) {
handle_remote_anti_msg(proc_p, msg);
auto_ckpt_register_bad(&this_lp->auto_ckpt);
handle_remote_anti_msg(lp, msg);
auto_ckpt_register_bad(&lp->auto_ckpt);
} else if(flags == (MSG_FLAG_ANTI | MSG_FLAG_PROCESSED)) {
array_count_t past_i = match_anti_msg(proc_p, msg);
do_rollback(proc_p, past_i);
array_count_t past_i = match_anti_msg(&lp->p, msg);
do_rollback(lp, past_i);
termination_on_lp_rollback(msg->dest_t);
auto_ckpt_register_bad(&this_lp->auto_ckpt);
auto_ckpt_register_bad(&lp->auto_ckpt);
}
msg_allocator_free(msg);

return;
}

if(unlikely(check_early_anti_messages(msg)))
return;

if(unlikely(array_count(proc_p->p_msgs) && msg_is_before(msg, array_peek(proc_p->p_msgs)))) {
array_count_t past_i = match_straggler_msg(proc_p, msg);
do_rollback(proc_p, past_i);
if(unlikely(array_count(lp->p.p_msgs) && msg_is_before(msg, array_peek(lp->p.p_msgs)))) {
array_count_t past_i = match_straggler_msg(&lp->p, msg);
do_rollback(lp, past_i);
termination_on_lp_rollback(msg->dest_t);
auto_ckpt_register_bad(&this_lp->auto_ckpt);
auto_ckpt_register_bad(&lp->auto_ckpt);
}
#ifndef NDEBUG
current_msg = msg;
#endif
timer_uint t = timer_hr_new();
global_config.dispatcher(msg->dest, msg->dest_t, msg->m_type, msg->pl, msg->pl_size, this_lp->lib_ctx->state_s);
global_config.dispatcher(msg->dest, msg->dest_t, msg->m_type, msg->pl, msg->pl_size, lp->lib_ctx->state_s);
stats_take(STATS_MSG_PROCESSED_TIME, timer_hr_value(t));
stats_take(STATS_MSG_PROCESSED, 1);
array_push(proc_p->p_msgs, msg);
array_push(lp->p.p_msgs, msg);

auto_ckpt_register_good(&this_lp->auto_ckpt);
if(auto_ckpt_is_needed(&this_lp->auto_ckpt))
checkpoint_take(proc_p);
auto_ckpt_register_good(&lp->auto_ckpt);
if(auto_ckpt_is_needed(&lp->auto_ckpt))
model_allocator_checkpoint_take(&lp->mm_state, array_count(lp->p.p_msgs));

termination_on_msg_process(msg->dest_t);
}
2 changes: 1 addition & 1 deletion src/mm/buddy/buddy.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file mm/buddy/buddy.c
*
* @brief A Buddy System implementation
* @brief A rollbackable Buddy System implementation
*
* SPDX-FileCopyrightText: 2008-2022 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
Expand Down
2 changes: 1 addition & 1 deletion src/mm/buddy/buddy.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file mm/buddy/buddy.h
*
* @brief A Buddy System implementation
* @brief A rollbackable Buddy System implementation
*
* SPDX-FileCopyrightText: 2008-2022 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
Expand Down
2 changes: 1 addition & 1 deletion src/mm/buddy/ckpt.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file mm/buddy/ckpt.c
*
* @brief Checkpointing capabilities
* @brief Checkpointing capabilities for the rollbackable buddy system
*
* SPDX-FileCopyrightText: 2008-2022 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
Expand Down
2 changes: 1 addition & 1 deletion src/mm/buddy/ckpt.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file mm/buddy/ckpt.h
*
* @brief Checkpointing capabilities
* @brief Checkpointing capabilities for the rollbackable buddy system
*
* SPDX-FileCopyrightText: 2008-2022 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
Expand Down
Loading