From: Augustin Degomme <26892-adegomme@users.noreply.framagit.org> Date: Fri, 22 Jul 2022 14:38:49 +0000 (+0000) Subject: Merge branch 'support-sendrecv-ti' into 'master' X-Git-Tag: v3.32~137 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f285c709071d6f01cc15e89c7fb974f6a7d5027e?hp=52bd452d0037d90d50f48280b256628ae86eb576 Merge branch 'support-sendrecv-ti' into 'master' Quick and dirty support of SendRecv in time-independent traces See merge request simgrid/simgrid!115 --- diff --git a/include/simgrid/modelchecker.h b/include/simgrid/modelchecker.h index 661fc12b1b..ea97b21955 100644 --- a/include/simgrid/modelchecker.h +++ b/include/simgrid/modelchecker.h @@ -44,7 +44,6 @@ XBT_PUBLIC void MC_assert(int); XBT_PUBLIC void MC_automaton_new_propositional_symbol(const char* id, int (*fct)(void)); XBT_PUBLIC void MC_automaton_new_propositional_symbol_pointer(const char* id, int* value); -XBT_PUBLIC void MC_cut(void); XBT_PUBLIC void MC_ignore(void* addr, size_t size); XBT_PUBLIC void MC_ignore_heap(void* address, size_t size); @@ -59,7 +58,6 @@ XBT_PUBLIC void MC_ignore_global_variable(const char* var_name); #define MC_assert(a) xbt_assert(a) #define MC_automaton_new_propositional_symbol(a, b) ((void)0) #define MC_automaton_new_propositional_symbol_pointer(a, b) ((void)0) -#define MC_cut() ((void)0) #define MC_ignore(a, b) ((void)0) #define MC_ignore_heap(a,s) ((void)0) diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 5d2b646406..507a2cbf30 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -48,6 +48,12 @@ public final class NativeLib { NativeLib.nativeInit("simgrid"); NativeLib.nativeInit("simgrid-java"); isNativeInited = true; + + /* Don't leak the files on disk */ + if (tempDir != null) { + FileCleaner fclean = new FileCleaner(tempDir.toFile()); + fclean.run(); + } } /** Helper function trying to load one requested library */ @@ -108,8 +114,6 @@ public final class NativeLib { } tempDir = Files.createTempDirectory(tempPrefix); - // don't leak the files on disk, but remove it on JVM shutdown - Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile()))); } /* For each possible filename of the given library on all possible OSes, try it */ diff --git a/src/include/xbt/mmalloc.h b/src/include/xbt/mmalloc.h index f2b85acfbd..6a872fec87 100644 --- a/src/include/xbt/mmalloc.h +++ b/src/include/xbt/mmalloc.h @@ -11,12 +11,17 @@ #include "src/internal_config.h" +/** Environment variable name used to pass the communication socket. + * + * It is set by `simgrid-mc` to enable MC support in the children processes. + * + * It is placed in this file so that it's visible from mmalloc and MC without sharing anythin of xbt in mmalloc + */ +#define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD" + #include /* for NULL */ #include /* for size_t */ -#include "xbt/dict.h" -#include "xbt/dynar.h" - SG_BEGIN_DECL /* Datatype representing a separate heap. The whole point of the mmalloc module is to allow several such heaps in the diff --git a/src/include/xbt/xbt_modinter.h b/src/include/xbt/xbt_modinter.h index 254f554448..5913b170c5 100644 --- a/src/include/xbt/xbt_modinter.h +++ b/src/include/xbt/xbt_modinter.h @@ -20,9 +20,6 @@ void xbt_log_postexit(void); void xbt_dict_preinit(void); void xbt_dict_postexit(void); -xbt_mheap_t mmalloc_preinit(void); -void mmalloc_postexit(void); - extern int xbt_initialized; SG_END_DECL diff --git a/src/mc/api.cpp b/src/mc/api.cpp index a29dbf2497..ce024e6e62 100644 --- a/src/mc/api.cpp +++ b/src/mc/api.cpp @@ -37,9 +37,18 @@ simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map< int i = 1; while (argv[i] != nullptr && argv[i][0] == '-') i++; + if (env.find("LD_PRELOAD") == env.end()) + setenv("LD_PRELOAD", "libsgmalloc.so", 1); + for (auto const& [key, val] : env) { - XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str()); - setenv(key.c_str(), val.c_str(), 1); + if (key == "LD_PRELOAD") { + auto v2 = std::string("libsgmalloc.so:") + val; + XBT_INFO("setenv '%s'='%s'", key.c_str(), v2.c_str()); + setenv(key.c_str(), v2.c_str(), 1); + } else { + XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str()); + setenv(key.c_str(), val.c_str(), 1); + } } xbt_assert(argv[i] != nullptr, "Unable to find a binary to exec on the command line. Did you only pass config flags?"); diff --git a/src/mc/mc_client_api.cpp b/src/mc/mc_client_api.cpp index 7d110408b0..d8044c33d2 100644 --- a/src/mc/mc_client_api.cpp +++ b/src/mc/mc_client_api.cpp @@ -31,15 +31,6 @@ void MC_assert(int prop) } } -void MC_cut() -{ - xbt_assert(mc_model_checker == nullptr); - if (not MC_is_active()) - return; - // FIXME, We want to do this in the model-checker: - xbt_die("MC_cut() not implemented"); -} - void MC_ignore(void* addr, size_t size) { xbt_assert(mc_model_checker == nullptr); diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index 2d4dfbea70..929c97cd5d 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -73,7 +73,7 @@ AppSide* AppSide::initialize(xbt_dynar_t actors_addr) xbt_assert(errno == 0 && raise(SIGSTOP) == 0, "Could not wait for the model-checker (errno = %d: %s)", errno, strerror(errno)); - s_mc_message_initial_addresses_t message{MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), + s_mc_message_initial_addresses_t message{MessageType::INITIAL_ADDRESSES, mmalloc_get_current_heap(), kernel::actor::ActorImpl::get_maxpid_addr(), actors_addr}; xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses."); diff --git a/src/mc/remote/mc_protocol.h b/src/mc/remote/mc_protocol.h index e83a281459..c04acc1c03 100644 --- a/src/mc/remote/mc_protocol.h +++ b/src/mc/remote/mc_protocol.h @@ -8,12 +8,6 @@ // ***** Environment variables for passing context to the model-checked process -/** Environment variable name used to pass the communication socket. - * - * It is set by `simgrid-mc` to enable MC support in the children processes - */ -#define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD" - #ifdef __cplusplus #include "src/kernel/actor/SimcallObserver.hpp" diff --git a/src/sthread/sthread.c b/src/sthread/sthread.c index 5b31764ceb..a52fec8081 100644 --- a/src/sthread/sthread.c +++ b/src/sthread/sthread.c @@ -70,7 +70,7 @@ int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_ return raw_pthread_create(thread, attr, start_routine, arg); sthread_inside_simgrid = 1; - int res = sthread_create(thread, attr, start_routine, arg); + int res = sthread_create((sthread_t*)thread, attr, start_routine, arg); sthread_inside_simgrid = 0; return res; } @@ -83,7 +83,7 @@ int pthread_join(pthread_t thread, void** retval) return raw_pthread_join(thread, retval); sthread_inside_simgrid = 1; - int res = sthread_join(thread, retval); + int res = sthread_join((sthread_t)thread, retval); sthread_inside_simgrid = 0; return res; } @@ -229,11 +229,6 @@ int sem_post(sem_t *sem) { return raw_sem_post(sem); } -int pthread_join(pthread_t thread, void **retval) { - sg_actor_join(thread, -1); - return 0; -} - int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) { *cond = sg_cond_init(); return 0; diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 768a0d55d5..7721982343 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -166,11 +166,6 @@ int sem_post(sem_t *sem) { return raw_sem_post(sem); } -int pthread_join(pthread_t thread, void **retval) { - sg_actor_join(thread, -1); - return 0; -} - int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) { *cond = sg_cond_init(); return 0; diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index 10c47ff2b9..48638782e1 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -11,7 +11,6 @@ Heavily modified Mar 1992 by Fred Fish. (fnf@cygnus.com) */ #include "mmprivate.h" -#include "xbt/ex.h" #include "mc/mc.h" /* Return memory to the heap. @@ -39,12 +38,14 @@ void mfree(struct mdesc *mdp, void *ptr) switch (type) { case MMALLOC_TYPE_HEAPINFO: UNLOCK(mdp); - THROW("Asked to free a fragment in a heapinfo block. I'm confused.\n"); + fprintf(stderr, "Asked to free a fragment in a heapinfo block. I'm confused.\n"); + abort(); break; case MMALLOC_TYPE_FREE: /* Already free */ UNLOCK(mdp); - THROW("Asked to free a fragment in a block that is already free. I'm puzzled.\n"); + fprintf(stderr, "Asked to free a fragment in a block that is already free. I'm puzzled.\n"); + abort(); break; case MMALLOC_TYPE_UNFRAGMENTED: @@ -167,7 +168,8 @@ void mfree(struct mdesc *mdp, void *ptr) if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){ UNLOCK(mdp); - THROW("Asked to free a fragment that is already free. I'm puzzled\n"); + fprintf(stderr, "Asked to free a fragment that is already free. I'm puzzled\n"); + abort(); } if (MC_is_active() && mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0) diff --git a/src/xbt/mmalloc/mm_interface.c b/src/xbt/mmalloc/mm_interface.c new file mode 100644 index 0000000000..28534b08fb --- /dev/null +++ b/src/xbt/mmalloc/mm_interface.c @@ -0,0 +1,59 @@ +/* External interface to a mmap'd malloc managed region. */ + +/* Copyright (c) 2012-2022. The SimGrid Team. All rights reserved. */ + +/* 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. */ + +/* Copyright 1992, 2000 Free Software Foundation, Inc. + + Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include /* After sys/types.h, at least for dpx/2. */ +#include +#include +#include + +#include "mmprivate.h" + +// This is the underlying implementation of mmalloc_get_bytes_used_remote. +// Is it used directly to evaluate the bytes used from a different process. +size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo) +{ + int bytes = 0; + for (size_t i = 0; i < heaplimit; ++i) { + if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED) { + if (heapinfo[i].busy_block.busy_size > 0) + bytes += heapinfo[i].busy_block.busy_size; + } else if (heapinfo[i].type > 0) { + for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo[i].type); j++) { + if (heapinfo[i].busy_frag.frag_size[j] > 0) + bytes += heapinfo[i].busy_frag.frag_size[j]; + } + } + } + return bytes; +} + +__attribute__((weak)) xbt_mheap_t mmalloc_get_current_heap(void) +{ + fprintf(stderr, "Fake mmalloc_get_current_heap()\n"); + return NULL; +} \ No newline at end of file diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index 3228074080..84a7eb4526 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -1,5 +1,4 @@ -/* Copyright (c) 2010-2022. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -7,19 +6,16 @@ /* Redefine the classical malloc/free/realloc functions so that they fit well in the mmalloc framework */ #define _GNU_SOURCE -#include +#include "mmprivate.h" #include - -#include "mmprivate.h" -#include "src/internal_config.h" -#include "src/mc/remote/mc_protocol.h" -#include "xbt/xbt_modinter.h" #include +#include /* ***** Whether to use `mmalloc` of the underlying malloc ***** */ static int __malloc_use_mmalloc; +int mmalloc_pagesize = 0; int malloc_use_mmalloc(void) { @@ -43,8 +39,6 @@ xbt_mheap_t mmalloc_get_current_heap(void) } /* Override the malloc-like functions if MC is activated at compile time */ -#if SIMGRID_HAVE_MC - /* ***** Temporary allocator * * This is used before we have found the real malloc implementation with dlsym. @@ -132,6 +126,8 @@ XBT_ATTRIB_CONSTRUCTOR(101) static void mm_legacy_constructor() mm_real_calloc = dlsym(RTLD_NEXT, "calloc"); #endif } + mmalloc_pagesize = getpagesize(); + mm_initializing = 0; mm_initialized = 1; } @@ -238,4 +234,3 @@ void free(void *p) mfree(mdp, p); UNLOCK(mdp); } -#endif /* SIMGRID_HAVE_MC */ diff --git a/src/xbt/mmalloc/mm_module.c b/src/xbt/mmalloc/mm_module.c index 8358d43f24..d8b53599ac 100644 --- a/src/xbt/mmalloc/mm_module.c +++ b/src/xbt/mmalloc/mm_module.c @@ -27,14 +27,11 @@ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "src/internal_config.h" #include #include /* After sys/types.h, at least for dpx/2. */ #include #include #include "mmprivate.h" -#include "xbt/ex.h" -#include "xbt/xbt_modinter.h" /* declarations of mmalloc_preinit and friends that live here */ /* Initialize access to a mmalloc managed region. @@ -49,7 +46,7 @@ so that users of the package don't have to worry about the actual implementation details. - On failure returns NULL. */ + On failure, returns NULL. */ xbt_mheap_t xbt_mheap_new(void* baseaddr, int options) { @@ -189,48 +186,24 @@ static void mmalloc_fork_child(void) } } -/* Initialize the default malloc descriptor. */ +/* Initialize the default malloc descriptor. + * + * There is no malloc_postexit() destroying the default mdp, because it would break ldl trying to free its memory + */ xbt_mheap_t mmalloc_preinit(void) { if (__mmalloc_default_mdp == NULL) { - if(!xbt_pagesize) - xbt_pagesize = getpagesize(); - unsigned long mask = ~((unsigned long)xbt_pagesize - 1); + if (!mmalloc_pagesize) + mmalloc_pagesize = getpagesize(); + unsigned long mask = ~((unsigned long)mmalloc_pagesize - 1); void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask); __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET); // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child); - xbt_assert(res == 0, "pthread_atfork() failed: return value %d", res); + mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res); } - xbt_assert(__mmalloc_default_mdp != NULL); + mmalloc_assert(__mmalloc_default_mdp != NULL, "__mmalloc_default_mdp cannot be NULL"); return __mmalloc_default_mdp; } - -void mmalloc_postexit(void) -{ - /* Do not destroy the default mdp or ldl won't be able to free the memory it - * allocated since we're in memory */ - // xbt_mheap_destroy_no_free(__mmalloc_default_mdp) -} - -// This is the underlying implementation of mmalloc_get_bytes_used_remote. -// Is it used directly in order to evaluate the bytes used from a different -// process. -size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo) -{ - int bytes = 0; - for (size_t i=0; i < heaplimit; ++i){ - if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED){ - if (heapinfo[i].busy_block.busy_size > 0) - bytes += heapinfo[i].busy_block.busy_size; - } else if (heapinfo[i].type > 0) { - for (size_t j=0; j < (size_t) (BLOCKSIZE >> heapinfo[i].type); j++){ - if(heapinfo[i].busy_frag.frag_size[j] > 0) - bytes += heapinfo[i].busy_frag.frag_size[j]; - } - } - } - return bytes; -} diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index e1db0d43d7..be0070f87b 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -51,7 +51,7 @@ static void* mmalloc_aligned(struct mdesc* mdp, size_t size) static void initialize_heapinfo_heapinfo(const s_xbt_mheap_t* mdp) { // Update heapinfo about the heapinfo pages (!): - xbt_assert((uintptr_t) mdp->heapinfo % BLOCKSIZE == 0); + mmalloc_assert((uintptr_t)mdp->heapinfo % BLOCKSIZE == 0, "Failed assert in initialize_heapinfo_heapinfo()"); size_t block = BLOCK(mdp->heapinfo); size_t nblocks = mdp->heapsize * sizeof(malloc_info) / BLOCKSIZE; // Mark them as free: @@ -214,8 +214,9 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size) for (candidate_frag=0;candidate_frag<(size_t) (BLOCKSIZE >> log);candidate_frag++) if (candidate_info->busy_frag.frag_size[candidate_frag] == -1) break; - xbt_assert(candidate_frag < (size_t) (BLOCKSIZE >> log), - "Block %zu was registered as containing free fragments of type %zu, but I can't find any",candidate_block,log); + mmalloc_assert(candidate_frag < (size_t)(BLOCKSIZE >> log), + "Block %zu was registered as containing free fragments of type %zu, but I can't find any", + candidate_block, log); result = (void*) (((char*)ADDRESS(candidate_block)) + (candidate_frag << log)); diff --git a/src/xbt/mmalloc/mmorecore.c b/src/xbt/mmalloc/mmorecore.c index 828e2f505e..fcb2fa0394 100644 --- a/src/xbt/mmalloc/mmorecore.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -10,7 +10,6 @@ Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com */ -#include "src/internal_config.h" #include #include #include @@ -23,8 +22,7 @@ #define MAP_ANONYMOUS MAP_ANON #endif -#define PAGE_ALIGN(addr) (void*) (((long)(addr) + xbt_pagesize - 1) & \ - ~((long)xbt_pagesize - 1)) +#define PAGE_ALIGN(addr) (void*)(((long)(addr) + mmalloc_pagesize - 1) & ~((long)mmalloc_pagesize - 1)) /** @brief Add memory to this heap * @@ -49,6 +47,10 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) return mdp->breakval; } + if (mmalloc_pagesize == 0) { // Not initialized yet + mmalloc_pagesize = (int)sysconf(_SC_PAGESIZE); + } + if (size < 0) { /* We are deallocating memory. If the amount requested would cause us to try to deallocate back past the base of * the mmap'd region then die verbosely. Otherwise, deallocate the memory and return the old break value. */ @@ -76,7 +78,8 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) if (mapto == MAP_FAILED) { char buff[1024]; - fprintf(stderr, "Internal error: mmap returned MAP_FAILED! error: %s\n", strerror(errno)); + fprintf(stderr, "Internal error: mmap returned MAP_FAILED! pagesize:%d error: %s\n", mmalloc_pagesize, + strerror(errno)); snprintf(buff, 1024, "cat /proc/%d/maps", getpid()); int status = system(buff); if (status == -1 || !(WIFEXITED(status) && WEXITSTATUS(status) == 0)) diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index 648bd1fe4b..2756de438e 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -13,19 +13,27 @@ #ifndef XBT_MMPRIVATE_H #define XBT_MMPRIVATE_H 1 -#include -#include - #include "swag.h" #include "src/internal_config.h" #include "xbt/mmalloc.h" -#include "xbt/ex.h" -#include "xbt/dynar.h" +#include #include #include +#include +#include -#include +// This macro is veery similar to xbt_assert, but with no dependency on XBT +#define mmalloc_assert(cond, ...) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, __VA_ARGS__); \ + abort(); \ + } \ + } while (0) + +XBT_PUBLIC_DATA int mmalloc_pagesize; +XBT_PRIVATE xbt_mheap_t mmalloc_preinit(void); #define MMALLOC_MAGIC "mmalloc" /* Mapped file magic number */ #define MMALLOC_MAGIC_SIZE 8 /* Size of magic number buf */ @@ -48,11 +56,13 @@ * information are kept in fixed length arrays. Here is the computation of * that size. * - * Never make SMALLEST_POSSIBLE_MALLOC smaller than sizeof(list) because we - * need to enlist the free fragments. + * Never make SMALLEST_POSSIBLE_MALLOC too small because we need to enlist + * the free fragments. + * + * FIXME: what's the correct size, actually? The used one is a guess. */ -#define SMALLEST_POSSIBLE_MALLOC (16*sizeof(struct list)) +#define SMALLEST_POSSIBLE_MALLOC (32 * sizeof(void*)) #define MAX_FRAGMENT_PER_BLOCK (BLOCKSIZE / SMALLEST_POSSIBLE_MALLOC) /* The difference between two pointers is a signed int. On machines where @@ -90,12 +100,6 @@ SG_BEGIN_DECL -/* Doubly linked lists of free fragments. */ -struct list { - struct list *next; - struct list *prev; -}; - /* Statistics available to the user. */ struct mstats { diff --git a/src/xbt/mmalloc/swag.c b/src/xbt/mmalloc/swag.c index a3cdcb982d..550b89b8e4 100644 --- a/src/xbt/mmalloc/swag.c +++ b/src/xbt/mmalloc/swag.c @@ -1,5 +1,4 @@ -/* Copyright (c) 2004-2022. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -11,7 +10,7 @@ /* This type should be added to a type that is to be used in such a swag */ #include "swag.h" -#include "xbt/asserts.h" +#include "mmprivate.h" // mmalloc_assert typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t; typedef struct xbt_swag* xbt_swag_t; @@ -63,11 +62,12 @@ static inline void xbt_swag_init(xbt_swag_t swag, size_t offset) */ static inline void xbt_swag_insert(void *obj, xbt_swag_t swag) { - xbt_assert(!xbt_swag_belongs(obj, swag) || swag->tail, - "This object belongs to an empty swag! Did you correctly initialize the object's hookup?"); + + mmalloc_assert(!xbt_swag_belongs(obj, swag) || swag->tail, + "This object belongs to an empty swag! Did you correctly initialize the object's hookup?"); if (!swag->head) { - xbt_assert(!(swag->tail), "Inconsistent swag."); + mmalloc_assert(!(swag->tail), "Inconsistent swag."); swag->head = obj; swag->tail = obj; swag->count++; diff --git a/src/xbt/mmalloc/swag.h b/src/xbt/mmalloc/swag.h index c88a9966bd..032c7413b6 100644 --- a/src/xbt/mmalloc/swag.h +++ b/src/xbt/mmalloc/swag.h @@ -9,8 +9,6 @@ #ifndef XBT_SWAG_H #define XBT_SWAG_H -#include "xbt/sysdep.h" /* size_t */ - /* * XBT_swag: a O(1) set based on linked lists * diff --git a/src/xbt/xbt_main.cpp b/src/xbt/xbt_main.cpp index 8ee72a4f07..15a5959565 100644 --- a/src/xbt/xbt_main.cpp +++ b/src/xbt/xbt_main.cpp @@ -115,9 +115,6 @@ static void xbt_postexit() xbt_initialized--; xbt_dict_postexit(); xbt_log_postexit(); -#if SIMGRID_HAVE_MC - mmalloc_postexit(); -#endif } /** @brief Initialize the xbt mechanisms. */ diff --git a/teshsuite/smpi/coll-allreduce/coll-allreduce-automatic.tesh b/teshsuite/smpi/coll-allreduce/coll-allreduce-automatic.tesh index 940489f77a..fff9336f24 100644 --- a/teshsuite/smpi/coll-allreduce/coll-allreduce-automatic.tesh +++ b/teshsuite/smpi/coll-allreduce/coll-allreduce-automatic.tesh @@ -2,7 +2,7 @@ p Test allreduce ! output sort -$ ${bindir:=.}/../../../smpi_script/bin/smpirun -map -hostfile ../hostfile_coll -platform ${platfdir:=.}/small_platform.xml -np 16 --log=xbt_cfg.thres:critical ${bindir:=.}/coll-allreduce --log=smpi_config.thres:warning --log=smpi_coll.thres:error --cfg=smpi/allreduce:automatic --cfg=smpi/async-small-thresh:65536 --cfg=smpi/send-is-detached-thresh:128000 --cfg=smpi/simulate-computation:no "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=smpi_mpi.thres:error --log=smpi_pmpi.thres:error +$ ${bindir:=.}/../../../smpi_script/bin/smpirun -map -hostfile ../hostfile_coll -platform ${platfdir:=.}/small_platform.xml -np 16 --log=xbt_cfg.thres:critical ${bindir:=.}/coll-allreduce --log=smpi_config.thres:warning --log=smpi_coll.thres:error --cfg=smpi/allreduce:automatic --cfg=smpi/async-small-thresh:65536 --cfg=smpi/send-is-detached-thresh:128000 --cfg=smpi/simulate-computation:no "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=smpi_mpi.thres:error --log=smpi_pmpi.thres:error --log=root.app:stdout > [ 0.000000] (0:maestro@) [rank 0] -> Tremblay > [ 0.000000] (0:maestro@) [rank 1] -> Tremblay > [ 0.000000] (0:maestro@) [rank 2] -> Tremblay diff --git a/teshsuite/xbt/CMakeLists.txt b/teshsuite/xbt/CMakeLists.txt index 1d9a841427..fb10524cdb 100644 --- a/teshsuite/xbt/CMakeLists.txt +++ b/teshsuite/xbt/CMakeLists.txt @@ -21,7 +21,7 @@ endforeach() if(HAVE_MMALLOC) add_executable (mmalloc_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_test.cpp) - target_link_libraries(mmalloc_test simgrid) + target_link_libraries(mmalloc_test simgrid sgmalloc) set_target_properties(mmalloc_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mmalloc) set_property(TARGET mmalloc_test APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") add_dependencies(tests mmalloc_test) diff --git a/teshsuite/xbt/mmalloc/mmalloc_32.tesh b/teshsuite/xbt/mmalloc/mmalloc_32.tesh index 06bc5435dd..8bb9bac8a7 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_32.tesh +++ b/teshsuite/xbt/mmalloc/mmalloc_32.tesh @@ -104,7 +104,6 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n > All blocks were correctly allocated. Free every second block > Memset every second block to zero (yeah, they are not currently allocated :) > Re-allocate every second block -> free all blocks (each one twice, to check that double free are correctly caught) -> free again all blocks (to really check that double free are correctly caught) +> free all blocks > Let's try different codepaths for mrealloc > Damnit, I cannot break mmalloc this time. That's SO disappointing. diff --git a/teshsuite/xbt/mmalloc/mmalloc_64.tesh b/teshsuite/xbt/mmalloc/mmalloc_64.tesh index 17356ee80a..ec276c3e92 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_64.tesh +++ b/teshsuite/xbt/mmalloc/mmalloc_64.tesh @@ -104,7 +104,6 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n > All blocks were correctly allocated. Free every second block > Memset every second block to zero (yeah, they are not currently allocated :) > Re-allocate every second block -> free all blocks (each one twice, to check that double free are correctly caught) -> free again all blocks (to really check that double free are correctly caught) +> free all blocks > Let's try different codepaths for mrealloc > Damnit, I cannot break mmalloc this time. That's SO disappointing. diff --git a/teshsuite/xbt/mmalloc/mmalloc_test.cpp b/teshsuite/xbt/mmalloc/mmalloc_test.cpp index 22ec93369d..6f798f06d8 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_test.cpp +++ b/teshsuite/xbt/mmalloc/mmalloc_test.cpp @@ -70,28 +70,9 @@ int main(int argc, char**argv) pointers[i] = mmalloc(heapA, size); } - XBT_INFO("free all blocks (each one twice, to check that double free are correctly caught)"); - for (i = 0; i < TESTSIZE; i++) { - bool gotit = false; + XBT_INFO("free all blocks"); + for (i = 0; i < TESTSIZE; i++) mfree(heapA, pointers[i]); - try { - mfree(heapA, pointers[i]); - } catch (const simgrid::Exception&) { - gotit = true; - } - xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i)); - } - - XBT_INFO("free again all blocks (to really check that double free are correctly caught)"); - for (i = 0; i < TESTSIZE; i++) { - bool gotit = false; - try { - mfree(heapA, pointers[i]); - } catch (const simgrid::Exception&) { - gotit = true; - } - xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i)); - } XBT_INFO("Let's try different codepaths for mrealloc"); for (i = 0; i < TESTSIZE; i++) { diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 2fbe5397fb..813d8292de 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -288,7 +288,7 @@ set(XBT_SRC ) if(HAVE_MMALLOC) - set(XBT_SRC ${XBT_SRC} src/xbt/mmalloc/mm.c ) + set(SGMALLOC_SRC src/xbt/mmalloc/mm.c) else() set(EXTRA_DIST ${EXTRA_DIST} src/xbt/mmalloc/mm.c) endif() @@ -655,6 +655,8 @@ set(MC_SRC src/mc/mc_smx.cpp src/mc/udpor_global.cpp src/mc/udpor_global.hpp + + src/xbt/mmalloc/mm_interface.c ) set(MC_SIMGRID_MC_SRC src/mc/explo/simgrid_mc.cpp) diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index c50bd886ba..551c48eb5e 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -35,6 +35,12 @@ else() set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC}) endif() +if(HAVE_MMALLOC) + add_library(sgmalloc SHARED ${SGMALLOC_SRC}) + set_property(TARGET sgmalloc + APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") +endif() + if(enable_model-checking) add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC}) target_link_libraries(simgrid-mc simgrid)