From: Gabriel Corona Date: Thu, 5 Feb 2015 14:03:51 +0000 (+0100) Subject: [mc] Communication of heap_area_to_ignore to the remote MCer X-Git-Tag: v3_12~732^2~134 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cf9a823f1cfd8b0098a039bff8ff6567e9beac91 [mc] Communication of heap_area_to_ignore to the remote MCer --- diff --git a/src/mc/mc_client.c b/src/mc/mc_client.c index 120c05bda4..55cc2ca388 100644 --- a/src/mc/mc_client.c +++ b/src/mc/mc_client.c @@ -19,12 +19,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic"); -s_mc_client_t mc_client; +mc_client_t mc_client; void MC_client_init(void) { - mc_client.fd = -1; - mc_client.active = 1; + if (mc_client) { + XBT_WARN("MC_client_init called more than once."); + return; + } + char* fd_env = getenv(MC_ENV_SOCKET_FD); if (!fd_env) xbt_die("MC socket not found"); @@ -40,13 +43,15 @@ void MC_client_init(void) xbt_die("Unexpected socket type %i", type); XBT_DEBUG("Model-checked application found expected socket type"); - mc_client.fd = fd; + mc_client = xbt_new0(s_mc_client_t, 1); + mc_client->fd = fd; + mc_client->active = 1; } void MC_client_hello(void) { XBT_DEBUG("Greeting the MC server"); - if (MC_protocol_hello(mc_client.fd) != 0) + if (MC_protocol_hello(mc_client->fd) != 0) xbt_die("Could not say hello the MC server"); XBT_DEBUG("Greeted the MC server"); } @@ -58,7 +63,7 @@ void MC_client_handle_messages(void) char message_buffer[MC_MESSAGE_LENGTH]; size_t s; - if ((s = recv(mc_client.fd, &message_buffer, sizeof(message_buffer), 0)) == -1) + if ((s = recv(mc_client->fd, &message_buffer, sizeof(message_buffer), 0)) == -1) xbt_die("Could not receive commands from the model-checker: %s", strerror(errno)); diff --git a/src/mc/mc_client.h b/src/mc/mc_client.h index fc1cf671ed..12234edeac 100644 --- a/src/mc/mc_client.h +++ b/src/mc/mc_client.h @@ -14,9 +14,9 @@ SG_BEGIN_DECL() typedef struct s_mc_client { int active; int fd; -} s_mc_client_t, mc_client_t; +} s_mc_client_t, *mc_client_t; -extern s_mc_client_t mc_client; +extern mc_client_t mc_client; void MC_client_init(void); void MC_client_hello(void); diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index 901bfd6bb2..3b1367023b 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -111,7 +111,8 @@ mc_model_checker_t MC_model_checker_new(pid_t pid, int socket) return mc; } -void MC_model_checker_delete(mc_model_checker_t mc) { +void MC_model_checker_delete(mc_model_checker_t mc) +{ mc_pages_store_delete(mc->pages); if(mc->record) xbt_dynar_free(&mc->record); @@ -119,6 +120,11 @@ void MC_model_checker_delete(mc_model_checker_t mc) { } void MC_init() +{ + MC_init_pid(getpid(), -1); +} + +void MC_init_pid(pid_t pid, int socket) { if (mc_mode == MC_MODE_NONE) { if (getenv(MC_ENV_SOCKET_FD)) { @@ -128,18 +134,6 @@ void MC_init() } } - MC_init_pid(getpid(), -1); - - if (mc_mode == MC_MODE_CLIENT) { - MC_client_init(); - MC_client_hello(); - // This will move somehwere else: - MC_client_handle_messages(); - } -} - -void MC_init_pid(pid_t pid, int socket) -{ int raw_mem_set = (mmalloc_get_current_heap() == mc_heap); mc_time = xbt_new0(double, simix_process_maxpid); @@ -222,6 +216,11 @@ void MC_init_pid(pid_t pid, int socket) if (raw_mem_set) MC_SET_MC_HEAP; + if (mc_mode == MC_MODE_CLIENT) { + // This will move somehwere else: + MC_client_handle_messages(); + } + } /******************************* Core of MC *******************************/ diff --git a/src/mc/mc_ignore.c b/src/mc/mc_ignore.c index e16383a23e..5f8ea90b6f 100644 --- a/src/mc/mc_ignore.c +++ b/src/mc/mc_ignore.c @@ -9,6 +9,9 @@ #include "mc_private.h" #include "smpi/private.h" #include "mc/mc_snapshot.h" +#include "mc_ignore.h" +#include "mc_protocol.h" +#include "mc_client.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc, "Logging specific to MC ignore mechanism"); @@ -61,35 +64,10 @@ static void checkpoint_ignore_region_free_voidp(void *r) /***********************************************************************/ -// FIXME, cross-process support? (or make this it is used on the app-side) -void MC_ignore_heap(void *address, size_t size) +void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region) { - if(!std_heap) - return; - int raw_mem_set = (mmalloc_get_current_heap() == mc_heap); - MC_SET_MC_HEAP; - - mc_heap_ignore_region_t region = NULL; - region = xbt_new0(s_mc_heap_ignore_region_t, 1); - region->address = address; - region->size = size; - - region->block = - ((char *) address - - (char *) std_heap->heapbase) / BLOCKSIZE + 1; - - if (std_heap->heapinfo[region->block].type == 0) { - region->fragment = -1; - std_heap->heapinfo[region->block].busy_block.ignore++; - } else { - region->fragment = - ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap-> - heapinfo[region->block].type; - std_heap->heapinfo[region->block].busy_frag.ignore[region->fragment]++; - } - if (mc_heap_comparison_ignore == NULL) { mc_heap_comparison_ignore = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), @@ -105,25 +83,27 @@ void MC_ignore_heap(void *address, size_t size) int start = 0; int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1; + // Find the position where we want to insert the mc_heap_ignore_region_t: while (start <= end) { cursor = (start + end) / 2; current_region = (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t); - if (current_region->address == address) { + if (current_region->address == region->address) { heap_ignore_region_free(region); if (!raw_mem_set) MC_SET_STD_HEAP; return; - } else if (current_region->address < address) { + } else if (current_region->address < region->address) { start = cursor + 1; } else { end = cursor - 1; } } - if (current_region->address < address) + // Insert it mc_heap_ignore_region_t: + if (current_region->address < region->address) xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion); else xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion); @@ -132,6 +112,56 @@ void MC_ignore_heap(void *address, size_t size) MC_SET_STD_HEAP; } +void MC_heap_region_ignore_send(mc_heap_ignore_region_t region) +{ + s_mc_ignore_region_message_t message; + message.type = MC_MESSAGE_IGNORE_REGION; + message.region = *region; + if (MC_protocol_send(mc_client->fd, &message, sizeof(message))) + xbt_die("Could not send ignored region to MCer"); + XBT_DEBUG("Sent ignored region to the model-checker"); +} + +// FIXME, cross-process support? (or make this it is used on the app-side) +void MC_ignore_heap(void *address, size_t size) +{ + if(!std_heap) + return; + + int raw_mem_set = (mmalloc_get_current_heap() == mc_heap); + + MC_SET_MC_HEAP; + + mc_heap_ignore_region_t region = NULL; + region = xbt_new0(s_mc_heap_ignore_region_t, 1); + region->address = address; + region->size = size; + + region->block = + ((char *) address - + (char *) std_heap->heapbase) / BLOCKSIZE + 1; + + if (std_heap->heapinfo[region->block].type == 0) { + region->fragment = -1; + std_heap->heapinfo[region->block].busy_block.ignore++; + } else { + region->fragment = + ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap-> + heapinfo[region->block].type; + std_heap->heapinfo[region->block].busy_frag.ignore[region->fragment]++; + } + + MC_heap_region_ignore_insert(region); + +#if 1 + if (mc_mode == MC_MODE_CLIENT) + MC_heap_region_ignore_send(region); +#endif + + if (!raw_mem_set) + MC_SET_STD_HEAP; +} + void MC_remove_ignore_heap(void *address, size_t size) { diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 6e3dac7a8f..d568b5ae78 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -4,6 +4,8 @@ /* 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. */ +#include + #include "smx_private.h" #include "xbt/heap.h" #include "xbt/sysdep.h" @@ -15,6 +17,9 @@ #ifdef HAVE_MC #include "mc/mc_private.h" +#include "mc/mc_model_checker.h" +#include "mc/mc_protocol.h" +#include "mc/mc_client.h" #endif #include "mc/mc_record.h" @@ -206,6 +211,20 @@ void SIMIX_global_init(int *argc, char **argv) if (sg_cfg_get_boolean("clean_atexit")) atexit(SIMIX_clean); +#ifdef HAVE_MC + // The communication initialisation is done ASAP. + // We need to commuicate initialisation of the different layers to the model-checker. + if (mc_mode == MC_MODE_NONE) { + if (getenv(MC_ENV_SOCKET_FD)) { + mc_mode = MC_MODE_CLIENT; + MC_client_init(); + MC_client_hello(); + } else { + mc_mode = MC_MODE_STANDALONE; + } + } +#endif + if (_sg_cfg_exit_asap) exit(0); }