X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/07c319ec54d6fc778ee3cc5e75a747242006723e..633f3ab4f0f29940ea9759bfe3dc4f8ec37595e8:/src/mc/mc_checkpoint.c diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index d416f72a16..dcf1a36d5f 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -1,18 +1,26 @@ -#include "private.h" +#include +#include "mc_private.h" -static mc_mem_region_t MC_region_new(void *start_addr, size_t size); + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, + "Logging specific to mc_checkpoint"); + +static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size); static void MC_region_restore(mc_mem_region_t reg); static void MC_region_destroy(mc_mem_region_t reg); -static void MC_snapshot_add_region(mc_snapshot_t snapshot, void *start_addr, size_t size); +static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size); -static mc_mem_region_t MC_region_new(void *start_addr, size_t size) +static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size) { mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1); + new_reg->type = type; new_reg->start_addr = start_addr; new_reg->size = size; new_reg->data = xbt_malloc0(size); + XBT_DEBUG("New reg data %p, start_addr %p, size %zu", new_reg->data, start_addr, size); memcpy(new_reg->data, start_addr, size); + return new_reg; } @@ -20,7 +28,32 @@ static void MC_region_restore(mc_mem_region_t reg) { /*FIXME: check if start_addr is still mapped, if it is not, then map it before copying the data */ - memcpy(reg->start_addr, reg->data, reg->size); + if(reg->type == 3){ + memory_map_t maps = get_memory_map(); + MC_UNSET_RAW_MEM; + unsigned int i=0; + s_map_region r; + while(i < maps->mapsize){ + r = maps->regions[i]; + if (maps->regions[i].pathname != NULL){ + if (!memcmp(maps->regions[i].pathname, "[stack]", 7)){ + size_t diff = (char*)reg->start_addr - (char*)r.start_addr; + void *segment = malloc(reg->size + diff); + XBT_DEBUG("Size of segment : %zu", sizeof(segment)); + memcpy((char *)segment + diff, reg->data, reg->size); + memcpy(r.start_addr, segment, sizeof(segment)); + XBT_DEBUG("Memcpy region ok"); + break; + } + } + i++; + } + }else{ + XBT_DEBUG("Memcpy : dest %p, src %p, size %zu", reg->start_addr, reg->data, reg->size); + memcpy(reg->start_addr, reg->data, reg->size); + } + + return; } static void MC_region_destroy(mc_mem_region_t reg) @@ -29,9 +62,20 @@ static void MC_region_destroy(mc_mem_region_t reg) xbt_free(reg); } -static void MC_snapshot_add_region(mc_snapshot_t snapshot, void *start_addr, size_t size) +static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size) { - mc_mem_region_t new_reg = MC_region_new(start_addr, size); + switch(type){ + case 0 : + XBT_DEBUG("New region heap (%zu)", size); + break; + case 1 : + XBT_DEBUG("New region libsimgrid (%zu)", size); + break; + case 2 : + XBT_DEBUG("New region program data (%zu)", size); + break; + } + mc_mem_region_t new_reg = MC_region_new(type, start_addr, size); snapshot->regions = xbt_realloc(snapshot->regions, (snapshot->num_reg + 1) * sizeof(mc_mem_region_t)); snapshot->regions[snapshot->num_reg] = new_reg; snapshot->num_reg++; @@ -40,28 +84,122 @@ static void MC_snapshot_add_region(mc_snapshot_t snapshot, void *start_addr, siz void MC_take_snapshot(mc_snapshot_t snapshot) { - unsigned int i; + unsigned int i = 0; + s_map_region reg; + memory_map_t maps = get_memory_map(); + + /* Save the std heap and the writable mapped pages of libsimgrid */ + while (i < maps->mapsize) { + reg = maps->regions[i]; + if ((reg.prot & PROT_WRITE)){ + if (maps->regions[i].pathname == NULL){ + if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) + MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + } else { + if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ + MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + } + } + i++; + } + + /* FIXME: free the memory map */ +} + + +void MC_take_snapshot_liveness(mc_snapshot_t snapshot) +{ + unsigned int i = 0; + s_map_region reg; + memory_map_t maps = get_memory_map(); + + for(i=0; i< snapshot->num_reg; i++){ + MC_region_destroy(snapshot->regions[i]); + } + + snapshot->num_reg = 0; + + i = 0; + + /* Save the std heap and the writable mapped pages of libsimgrid */ + while (i < maps->mapsize) { + reg = maps->regions[i]; + if ((reg.prot & PROT_WRITE)){ + if (maps->regions[i].pathname == NULL){ + if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) + MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + }else { + if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ + MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + } + } + i++; + } + + /* FIXME: free the memory map */ +} + +void MC_take_snapshot_to_restore_liveness(mc_snapshot_t snapshot) +{ + unsigned int i = 0; s_map_region reg; memory_map_t maps = get_memory_map(); - /* Save all the writable mapped pages except the and the stack */ - for (i = 0; i < maps->mapsize; i++) { + for(i=0; i< snapshot->num_reg; i++){ + MC_region_destroy(snapshot->regions[i]); + } + + snapshot->num_reg = 0; + + i = 0; + + /* Save the std heap and the writable mapped pages of libsimgrid */ + while (i < maps->mapsize) { reg = maps->regions[i]; - if((reg.prot & PROT_WRITE) - && (reg.pathname == NULL - || (strncmp(reg.pathname, "/dev/zero", 9) - && strncmp(reg.pathname, "[stack]", 7)))){ - MC_snapshot_add_region(snapshot, reg.start_addr, - (char*)reg.end_addr - (char*)reg.start_addr); + if ((reg.prot & PROT_WRITE)){ + if (maps->regions[i].pathname == NULL){ + if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) + MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + } else { + if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ + MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } else { + if (!memcmp(basename(maps->regions[i].pathname), basename(prog_name), strlen(basename(prog_name)))){ + MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); + } + } + } } + i++; } + + /* FIXME: free the memory map */ } void MC_restore_snapshot(mc_snapshot_t snapshot) { unsigned int i; - for(i=0; i < snapshot->num_reg; i++) + for(i=0; i < snapshot->num_reg; i++){ MC_region_restore(snapshot->regions[i]); + switch(snapshot->regions[i]->type){ + case 0 : + XBT_DEBUG("heap restored"); + break; + case 1: + XBT_DEBUG("libsimgrid (data) restored"); + break; + case 2: + XBT_DEBUG("data program restored"); + break; + } + + } + } void MC_free_snapshot(mc_snapshot_t snapshot) @@ -72,3 +210,5 @@ void MC_free_snapshot(mc_snapshot_t snapshot) xbt_free(snapshot); } + +