From: Zitagcc Date: Mon, 2 Oct 2017 16:02:10 +0000 (+0200) Subject: Merge branch 'master' into async-wait X-Git-Tag: v3_17~48^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a001b13d7aa269a90f035f58c71778c6812b07f6?hp=5c220417dce14036ddf5e8279b4912051a16a74f Merge branch 'master' into async-wait --- diff --git a/.gitignore b/.gitignore index 7275993d6d..39d1cd7abf 100644 --- a/.gitignore +++ b/.gitignore @@ -121,12 +121,9 @@ doc/msg-tuto-src/masterworker1 doc/msg-tuto-src/masterworker2 doc/msg-tuto-src/masterworker3 doc/msg-tuto-src/masterworker4 -examples/msg/actions-comm/actions-comm -examples/msg/actions-storage/actions-storage examples/msg/async-wait/async-wait examples/msg/async-waitall/async-waitall examples/msg/async-waitany/async-waitany -examples/msg/app-bittorrent/bittorrent examples/msg/app-chainsend/chainsend examples/msg/cloud-capping/cloud-capping examples/msg/cloud-masterworker/cloud-masterworker @@ -189,6 +186,8 @@ examples/msg/trace-masterworker/trace-masterworker examples/msg/trace-process-migration/trace-process-migration examples/msg/trace-platform/trace-platform examples/msg/trace-host-user-variables/trace-host-user-variables +examples/msg/*.pcap +examples/msg/*.tr examples/s4u/actions-comm/s4u-actions-comm examples/s4u/actions-storage/s4u-actions-storage examples/s4u/actor-create/s4u-actor-create @@ -196,6 +195,7 @@ examples/s4u/actor-daemon/s4u-actor-daemon examples/s4u/actor-kill/s4u-actor-kill examples/s4u/actor-migration/s4u-actor-migration examples/s4u/actor-suspend/s4u-actor-suspend +examples/s4u/app-bittorrent/s4u-bittorrent examples/s4u/app-masterworker/s4u-app-masterworker examples/s4u/app-pingpong/s4u-app-pingpong examples/s4u/app-token-ring/s4u-app-token-ring @@ -207,6 +207,7 @@ examples/s4u/basic/s4u-basic_function examples/s4u/dht-chord/s4u-dht-chord examples/s4u/io/s4u-io examples/s4u/mutex/s4u-mutex +examples/s4u/plugin-hostload/s4u-plugin-hostload examples/simdag/daxload/sd_daxload examples/simdag/dag-dotload/sd_dag-dotload examples/simdag/ptg-dotload/sd_ptg-dotload @@ -234,6 +235,7 @@ examples/smpi/mc/send_deterministic examples/smpi/NAS/dt examples/smpi/NAS/ep examples/smpi/NAS/is +examples/smpi/replay_multiple/deployment.xml examples/smpi/replay_multiple/replay_multiple examples/smpi/replay/one_trace examples/smpi/ring_c @@ -246,13 +248,16 @@ examples/smpi/trace_simple/smpi_trace_simple examples/smpi/trace_call_location/smpi_trace_call_location testall teshsuite/datadesc_usage.out -teshsuite/java/semaphoreGC/semaphoreGC_compiled -teshsuite/java/sleepHostOff/sleepHostOff_compiled +teshsuite/java/semaphoregc/java-semaphoregc_compiled +teshsuite/java/sleephostoff/java-sleephostoff_compiled teshsuite/mc/dwarf/dwarf teshsuite/mc/dwarf-expression/dwarf-expression teshsuite/mc/random-bug/random-bug teshsuite/mc/mutex-handling/mutex-handling teshsuite/mc/mutex-handling/without-mutex-handling +teshsuite/msg/actions-comm/actions-comm +teshsuite/msg/actions-storage/actions-storage +teshsuite/msg/app-bittorrent/bittorrent teshsuite/msg/cloud-sharing/cloud-sharing teshsuite/msg/concurrent_rw/concurrent_rw teshsuite/msg/get_sender/get_sender @@ -687,6 +692,7 @@ teshsuite/smpi/mpich3-test/f77/rma/c2f2cwinf teshsuite/smpi/mpich3-test/f77/rma/winaccf teshsuite/smpi/mpich3-test/f77/rma/winfencef teshsuite/smpi/mpich3-test/f77/rma/wingetf +teshsuite/smpi/mpich3-test/f77/rma/wingroupf teshsuite/smpi/mpich3-test/f77/rma/winnamef teshsuite/smpi/mpich3-test/f77/rma/winscale1f teshsuite/smpi/mpich3-test/f77/topo/cartcrf @@ -729,6 +735,7 @@ teshsuite/smpi/mpich3-test/f90/rma/c2f2cwinf90 teshsuite/smpi/mpich3-test/f90/rma/winaccf90 teshsuite/smpi/mpich3-test/f90/rma/winfencef90 teshsuite/smpi/mpich3-test/f90/rma/wingetf90 +teshsuite/smpi/mpich3-test/f90/rma/wingroupf90 teshsuite/smpi/mpich3-test/f90/rma/winnamef90 teshsuite/smpi/mpich3-test/f90/rma/winscale1f90 teshsuite/smpi/mpich3-test/group/groupcreate @@ -1083,29 +1090,29 @@ tools/tesh/tesh unit_tmgr ######################################### ## touched files to track the dependencies of java examples -examples/java/app/bittorrent/java_app_bittorrent_compiled -examples/java/app/centralizedmutex/java_app_centralizedmutex_compiled -examples/java/app/masterworker/java_app_masterworker_compiled -examples/java/app/pingpong/java_app_pingpong_compiled -examples/java/app/tokenring/java_app_tokenring_compiled -examples/java/async/yield/java_async_yield_compiled -examples/java/async/dsend/java_async_dsend_compiled -examples/java/async/waitall/java_async_waitall_compiled -examples/java/dht/chord/java_dht_chord_compiled -examples/java/dht/kademlia/java_dht_kademlia_compiled -examples/java/cloud/masterworker/java_cloud_masterworker_compiled -examples/java/cloud/migration/java_cloud_migration_compiled -examples/java/energy/consumption/java_energy_consumption_compiled -examples/java/energy/pstate/java_energy_pstate_compiled -examples/java/energy/vm/java_energy_vm_compiled -examples/java/io/file/java_io_file_compiled -examples/java/io/storage/java_io_storage_compiled -examples/java/process/kill/java_process_kill_compiled -examples/java/process/migration/java_process_migration_compiled -examples/java/process/suspend/java_process_suspend_compiled -examples/java/process/startkilltime/java_process_startkilltime_compiled -examples/java/task/priority/java_task_priority_compiled -examples/java/trace/pingpong/java_trace_pingpong_compiled +examples/java/app/bittorrent/java-app-bittorrent_compiled +examples/java/app/centralizedmutex/java-app-centralizedmutex_compiled +examples/java/app/masterworker/java-app-masterworker_compiled +examples/java/app/pingpong/java-app-pingpong_compiled +examples/java/app/tokenring/java-app-tokenring_compiled +examples/java/async/yield/java-async-yield_compiled +examples/java/async/dsend/java-async-dsend_compiled +examples/java/async/waitall/java-async-waitall_compiled +examples/java/dht/chord/java-dht-chord_compiled +examples/java/dht/kademlia/java-dht-kademlia_compiled +examples/java/cloud/masterworker/java-cloud-masterworker_compiled +examples/java/cloud/migration/java-cloud-migration_compiled +examples/java/energy/consumption/java-energy-consumption_compiled +examples/java/energy/pstate/java-energy-pstate_compiled +examples/java/energy/vm/java-energy-vm_compiled +examples/java/io/file/java-io-file_compiled +examples/java/io/storage/java-io-storage_compiled +examples/java/process/kill/java-process-kill_compiled +examples/java/process/migration/java-process-migration_compiled +examples/java/process/suspend/java-process-suspend_compiled +examples/java/process/startkilltime/java-process-startkilltime_compiled +examples/java/task/priority/java-task-priority_compiled +examples/java/trace/pingpong/java-trace-pingpong_compiled /CMakeCache.txt examples/smpi/mc/smpi_bugged1 examples/smpi/mc/smpi_bugged1_liveness diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f813d5175..e2bb276f16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,16 +273,8 @@ endif() find_package(Boost COMPONENTS context) set(Boost_FOUND 1) # This component is optional if(Boost_CONTEXT_FOUND) - if (Boost_VERSION LESS 105600) - message("Found Boost.Context API v1") - set(HAVE_BOOST_CONTEXTS 1) - elseif(Boost_VERSION LESS 106100) - message("Found Boost.Context API v2") - set(HAVE_BOOST_CONTEXTS 2) - else() - message(" WARNING : our implementation of Boost context factory is not compatible with Boost >=1.61 yet.") - set(HAVE_BOOST_CONTEXTS 0) - endif() + message("Found Boost.Context") + set(HAVE_BOOST_CONTEXTS 1) else() message (" boost : found.") message (" boost-context: missing. Install libboost-context-dev for this optional feature.") @@ -683,6 +675,11 @@ else() set(GIT_VERSION "none, release version") endif() +### Setup gcc & clang flags +if (NOT MSVC) + include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GCCFlags.cmake) +endif() + ### Generate the required headers and scripts ############################################# @@ -874,11 +871,6 @@ include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake) include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake) include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake) -### Setup gcc & clang flags -if (NOT MSVC) - include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GCCFlags.cmake) -endif() - ### Make Libs if(NOT WIN32) include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake) diff --git a/ChangeLog b/ChangeLog index 44c39b1f88..7e2610f39a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,18 @@ SimGrid (3.17) UNRELEASED (release target: September 22 2017) + The Drained Leaks release: (almost) no known leaks despite the tests. + + Even very long simulations will preserve your memory: our testsuite + stresses SimGrid for over 45mn on fast machines, and there is only + one single known leak, of about 4kb. + + S4U - - Comm.detach(): start and forget about asynchronous emission + - Comm.detach(): start and forget about asynchronous emission. A cleanup + handler may be given to free resources if the comm cannot be completed. - this_actor::send(mailbox) is now mailbox->put() - New: simgrid::s4u::Comm::wait_all() + - New: Host.execute() for remote executions. SURF - Unused option network/sender-gap is removed. @@ -12,6 +21,31 @@ SimGrid (3.17) UNRELEASED (release target: September 22 2017) - Deprecate MSG_task_isend_with_matching(): This unused feature really complicates our internals. Will be removed in v3.20. + Simix + - Improved context termination. It is now possible to free resources, even + when a process is forcibly killed. + - ContextBoost: add support for Boost versions above 1.61. + + XBT + - Bring back run-time option --cfg=exception/cutpath to remove exception + backtraces. + + Misc + - Removed header files obsolete since SimGrid 3.12: + msg/datatypes.h, msg/msg.h, simdag/datatypes.h, simdag/simdag.h. + - Fix many bugs: + - #3: SD_exit should be made optional + - #120: Memory leak when the processes are forcefully killed + - #159: Threading test regression in Actor refcounting + - #170: simgrid::s4u::Comm::wait_any() returns too many comms + - #185: simgrid::s4u::Engine::instance()->shutdown() segfaults + - #186: Actor::killAll() segfaults if some process is blocked on wait() + - #191: VM migration and pstate + - #192: Updating the energy consumptions of all hosts crashes with VMs + - #195: All actors have PID=0 in the logs + - #204: Sometimes segfault with thread contexts and mmap privatization + - #222: Actor::kill() doesn't really kill and segfaults + SimGrid (3.16) Released June 22. 2017. The Blooming Spring Release: developments are budding. diff --git a/contrib/benchmarking_code_block/inject.h b/contrib/benchmarking_code_block/inject.h index a79ac2863d..4828114e48 100644 --- a/contrib/benchmarking_code_block/inject.h +++ b/contrib/benchmarking_code_block/inject.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2014. The SimGrid Team. +/* Copyright (c) 2013-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -66,7 +66,8 @@ static inline void xbt_inject_init(char *inputfile) if (fgets(line, 200, fpInput) == NULL) printf("Error input file is empty!"); // Skipping first row while (fgets(line, 200, fpInput) != NULL) { - key = strtok(line, "\t"); + char *saveptr = NULL; /* for strtok_r() */ + key = strtok_r(line, "\t", &saveptr); xbt_hist_t* data = xbt_dict_get_or_null(mydict, key); if (data) @@ -75,16 +76,16 @@ static inline void xbt_inject_init(char *inputfile) data = (xbt_hist_t*)xbt_new(xbt_hist_t, 1); data->block_id = key; - data->counts = atoi(strtok(NULL, "\t")); - data->mean = atof(strtok(NULL, "\t")); - data->n = atoi(strtok(NULL, "\t")); + data->counts = atoi(strtok_r(NULL, "\t", &saveptr)); + data->mean = atof(strtok_r(NULL, "\t", &saveptr)); + data->n = atoi(strtok_r(NULL, "\t", &saveptr)); data->breaks = (double*)malloc(sizeof(double) * data->n); data->percentage = (double*)malloc(sizeof(double) * (data->n - 1)); for (int i = 0; i < data->n; i++) - data->breaks[i] = atof(strtok(NULL, "\t")); + data->breaks[i] = atof(strtok_r(NULL, "\t", &saveptr)); for (int i = 0; i < (data->n - 1); i++) - data->percentage[i] = atof(strtok(NULL, "\t")); + data->percentage[i] = atof(strtok_r(NULL, "\t", &saveptr)); xbt_dict_set(mydict, key, data, NULL); } @@ -118,7 +119,8 @@ static inline void inject_init_starpu(char *inputfile, xbt_dict_t *dict, RngStre } while (fgets(line, MAX_LINE_INJ, fpInput) != NULL) { - key = strtok(line, "\t"); + char *saveptr = NULL; /* for strtok_r() */ + key = strtok_r(line, "\t", &saveptr); xbt_hist_t* data = xbt_dict_get_or_null(mydict, key); if (data) @@ -126,16 +128,16 @@ static inline void inject_init_starpu(char *inputfile, xbt_dict_t *dict, RngStre data = (xbt_hist_t*)xbt_new(xbt_hist_t, 1); data->block_id = key; - data->counts = atoi(strtok(NULL, "\t")); - data->mean = atof(strtok(NULL, "\t")); - data->n = atoi(strtok(NULL, "\t")); + data->counts = atoi(strtok_r(NULL, "\t", &saveptr)); + data->mean = atof(strtok_r(NULL, "\t", &saveptr)); + data->n = atoi(strtok_r(NULL, "\t", &saveptr)); data->breaks = (double*)malloc(sizeof(double) * data->n); data->percentage = (double*)malloc(sizeof(double) * (data->n - 1)); for (int i = 0; i < data->n; i++) - data->breaks[i] = atof(strtok(NULL, "\t")); + data->breaks[i] = atof(strtok_r(NULL, "\t", &saveptr)); for (int i = 0; i < (data->n - 1); i++) { - data->percentage[i] = atof(strtok(NULL, "\t")); + data->percentage[i] = atof(strtok_r(NULL, "\t", &saveptr)); } xbt_dict_set(mydict, key, data, NULL); diff --git a/doc/doxygen/options.doc b/doc/doxygen/options.doc index e0eb74791a..64ce0db6f5 100644 --- a/doc/doxygen/options.doc +++ b/doc/doxygen/options.doc @@ -1292,7 +1292,7 @@ when \b verbose-exit is set to 0 (it is to 1 by default). \subsection options_exception_cutpath Truncate local path from exception backtrace \verbatim ---cfg=exceptions/cutpath:1 +--cfg=exception/cutpath:1 \endverbatim This configuration option is used to remove the path from the diff --git a/doc/doxygen/uhood.doc b/doc/doxygen/uhood.doc index 7a750df1fb..67632a5d26 100644 --- a/doc/doxygen/uhood.doc +++ b/doc/doxygen/uhood.doc @@ -208,7 +208,7 @@ The current implementation of the model-checker uses two distinct processes: - it spaws a child process for the SimGrid simulator/maestro and the simulated processes. -They communicate using a `AF_UNIX` `SOCK_DGRAM` socket and exchange messages +They communicate using a `AF_UNIX` `SOCK_SEQPACKET` socket and exchange messages defined in `mc_protocol.h`. The `SIMGRID_MC_SOCKET_FD` environment variable it set to the file descriptor of this socket in the child process. diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 0c8162e086..0e1967b218 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -1,34 +1,34 @@ -set(app_bittorrent_files Main Common Connection MessageTask Peer Tracker TrackerTask) -set(app_centralizedmutex_files Main Coordinator GrantTask Node ReleaseTask RequestTask) -set(app_masterworker_files Main Master Worker) -set(app_pingpong_files Main PingPongTask Receiver Sender) -set(app_tokenring_files Main RelayRunner) -set(async_waitall_files Main Receiver Sender) -set(async_yield_files Main Yielder) -set(async_dsend_files Main Receiver Sender) -set(cloud_masterworker_files Main Master Worker) -set(cloud_migration_files Main Daemon Test TestHostOnOff XVM) -set(dht_chord_files Main ChordTask Common FindSuccessorAnswerTask FindSuccessorTask +set(app-bittorrent_files Main Common Connection MessageTask Peer Tracker TrackerTask) +set(app-centralizedmutex_files Main Coordinator GrantTask Node ReleaseTask RequestTask) +set(app-masterworker_files Main Master Worker) +set(app-pingpong_files Main PingPongTask Receiver Sender) +set(app-tokenring_files Main RelayRunner) +set(async-waitall_files Main Receiver Sender) +set(async-yield_files Main Yielder) +set(async-dsend_files Main Receiver Sender) +set(cloud-masterworker_files Main Master Worker) +set(cloud-migration_files Main Daemon Test TestHostOnOff XVM) +set(dht-chord_files Main ChordTask Common FindSuccessorAnswerTask FindSuccessorTask GetPredecessorAnswerTask GetPredecessorTask Node NotifyTask) -set(dht_kademlia_files Main Answer Bucket Common Contact FindNodeAnswerTask FindNodeTask +set(dht-kademlia_files Main Answer Bucket Common Contact FindNodeAnswerTask FindNodeTask KademliaTask Node PingAnswerTask PingTask RoutingTable) -set(trace_pingpong_files Main PingPongTask Receiver Sender) -set(energy_consumption_files Main EnergyConsumer) -set(energy_pstate_files Main PstateRunner) -set(energy_vm_files Main EnergyVMRunner) -set(io_file_files Main Node) -set(io_storage_files Main Client) -set(process_kill_files Main Killer Victim) -set(process_migration_files Main Emigrant Policeman) -set(process_startkilltime_files Main Sleeper) -set(process_suspend_files Main DreamMaster LazyGuy) -set(task_priority_files Main Test) +set(trace-pingpong_files Main PingPongTask Receiver Sender) +set(energy-consumption_files Main EnergyConsumer) +set(energy-pstate_files Main PstateRunner) +set(energy-vm_files Main EnergyVMRunner) +set(io-file_files Main Node) +set(io-storage_files Main Client) +set(process-kill_files Main Killer Victim) +set(process-migration_files Main Emigrant Policeman) +set(process-startkilltime_files Main Sleeper) +set(process-suspend_files Main DreamMaster LazyGuy) +set(task-priority_files Main Test) -foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend - cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage - process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong) - string (REPLACE "_" "/" example_dir ${example}) +foreach (example app-bittorrent app-centralizedmutex app-masterworker app-pingpong app-tokenring async-yield async-waitall async-dsend + cloud-migration cloud-masterworker dht-chord dht-kademlia energy-consumption energy-pstate energy-vm io-file io-storage + process-kill process-migration process-startkilltime process-suspend task-priority trace-pingpong) + string (REPLACE "-" "/" example_dir ${example}) set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/${example_dir}) foreach (filename ${${example}_files} ) set( ${example}_sources "${${example}_sources}" "${srcdir}/${filename}.java") @@ -36,15 +36,15 @@ foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpo if(enable_java) add_custom_command( - COMMENT "Building java_${example}..." - OUTPUT ${example_dir}/java_${example}_compiled + COMMENT "Building java-${example}..." + OUTPUT ${example_dir}/java-${example}_compiled DEPENDS ${example_sources} simgrid-java_jar ${SIMGRID_JAR} COMMAND ${CMAKE_COMMAND} -E make_directory ${example_dir} COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR} -d ${CMAKE_CURRENT_BINARY_DIR} ${${example}_sources} - COMMAND ${CMAKE_COMMAND} -E remove ${example_dir}/java_${example}_compiled - COMMAND ${CMAKE_COMMAND} -E touch ${example_dir}/java_${example}_compiled + COMMAND ${CMAKE_COMMAND} -E remove ${example_dir}/java-${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example_dir}/java-${example}_compiled ) - add_custom_target(${example} ALL DEPENDS ${example_dir}/java_${example}_compiled) + add_custom_target(java-${example} ALL DEPENDS ${example_dir}/java-${example}_compiled) endif() set(examples_src ${examples_src} ${${example}_sources}) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example_dir}/${example}.tesh) @@ -64,10 +64,10 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/app/bittorrent/bi ${CMAKE_CURRENT_SOURCE_DIR}/task/priority/priority.xml PARENT_SCOPE) if(enable_java) - foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend - cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage - process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong) - string (REPLACE "_" "/" example_dir ${example}) + foreach (example app-bittorrent app-centralizedmutex app-masterworker app-pingpong app-tokenring async-yield async-waitall async-dsend + cloud-migration cloud-masterworker dht-chord dht-kademlia energy-consumption energy-pstate energy-vm io-file io-storage + process-kill process-migration process-startkilltime process-suspend task-priority trace-pingpong) + string (REPLACE "-" "/" example_dir ${example}) ADD_TESH(java-${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java/${example_dir} ${CMAKE_HOME_DIRECTORY}/examples/java/${example_dir}/${example}.tesh) endforeach() endif() diff --git a/examples/java/app/bittorrent/app_bittorrent.tesh b/examples/java/app/bittorrent/app-bittorrent.tesh similarity index 100% rename from examples/java/app/bittorrent/app_bittorrent.tesh rename to examples/java/app/bittorrent/app-bittorrent.tesh diff --git a/examples/java/app/centralizedmutex/app_centralizedmutex.tesh b/examples/java/app/centralizedmutex/app-centralizedmutex.tesh similarity index 100% rename from examples/java/app/centralizedmutex/app_centralizedmutex.tesh rename to examples/java/app/centralizedmutex/app-centralizedmutex.tesh diff --git a/examples/java/app/masterworker/app_masterworker.tesh b/examples/java/app/masterworker/app-masterworker.tesh similarity index 100% rename from examples/java/app/masterworker/app_masterworker.tesh rename to examples/java/app/masterworker/app-masterworker.tesh diff --git a/examples/java/app/pingpong/app_pingpong.tesh b/examples/java/app/pingpong/app-pingpong.tesh similarity index 100% rename from examples/java/app/pingpong/app_pingpong.tesh rename to examples/java/app/pingpong/app-pingpong.tesh diff --git a/examples/java/app/tokenring/app_tokenring.tesh b/examples/java/app/tokenring/app-tokenring.tesh similarity index 100% rename from examples/java/app/tokenring/app_tokenring.tesh rename to examples/java/app/tokenring/app-tokenring.tesh diff --git a/examples/java/async/dsend/async_dsend.tesh b/examples/java/async/dsend/async-dsend.tesh similarity index 100% rename from examples/java/async/dsend/async_dsend.tesh rename to examples/java/async/dsend/async-dsend.tesh diff --git a/examples/java/async/waitall/async_waitall.tesh b/examples/java/async/waitall/async-waitall.tesh similarity index 100% rename from examples/java/async/waitall/async_waitall.tesh rename to examples/java/async/waitall/async-waitall.tesh diff --git a/examples/java/async/yield/async_yield.tesh b/examples/java/async/yield/async-yield.tesh similarity index 100% rename from examples/java/async/yield/async_yield.tesh rename to examples/java/async/yield/async-yield.tesh diff --git a/examples/java/cloud/masterworker/cloud_masterworker.tesh b/examples/java/cloud/masterworker/cloud-masterworker.tesh similarity index 100% rename from examples/java/cloud/masterworker/cloud_masterworker.tesh rename to examples/java/cloud/masterworker/cloud-masterworker.tesh diff --git a/examples/java/cloud/migration/cloud_migration.tesh b/examples/java/cloud/migration/cloud-migration.tesh similarity index 100% rename from examples/java/cloud/migration/cloud_migration.tesh rename to examples/java/cloud/migration/cloud-migration.tesh diff --git a/examples/java/dht/chord/dht_chord.tesh b/examples/java/dht/chord/dht-chord.tesh similarity index 100% rename from examples/java/dht/chord/dht_chord.tesh rename to examples/java/dht/chord/dht-chord.tesh diff --git a/examples/java/dht/kademlia/dht_kademlia.tesh b/examples/java/dht/kademlia/dht-kademlia.tesh similarity index 100% rename from examples/java/dht/kademlia/dht_kademlia.tesh rename to examples/java/dht/kademlia/dht-kademlia.tesh diff --git a/examples/java/energy/consumption/energy_consumption.tesh b/examples/java/energy/consumption/energy-consumption.tesh similarity index 100% rename from examples/java/energy/consumption/energy_consumption.tesh rename to examples/java/energy/consumption/energy-consumption.tesh diff --git a/examples/java/energy/pstate/energy_pstate.tesh b/examples/java/energy/pstate/energy-pstate.tesh similarity index 100% rename from examples/java/energy/pstate/energy_pstate.tesh rename to examples/java/energy/pstate/energy-pstate.tesh diff --git a/examples/java/energy/vm/energy_vm.tesh b/examples/java/energy/vm/energy-vm.tesh similarity index 100% rename from examples/java/energy/vm/energy_vm.tesh rename to examples/java/energy/vm/energy-vm.tesh diff --git a/examples/java/io/file/io_file.tesh b/examples/java/io/file/io-file.tesh similarity index 100% rename from examples/java/io/file/io_file.tesh rename to examples/java/io/file/io-file.tesh diff --git a/examples/java/io/storage/io_storage.tesh b/examples/java/io/storage/io-storage.tesh similarity index 100% rename from examples/java/io/storage/io_storage.tesh rename to examples/java/io/storage/io-storage.tesh diff --git a/examples/java/process/kill/process_kill.tesh b/examples/java/process/kill/process-kill.tesh similarity index 100% rename from examples/java/process/kill/process_kill.tesh rename to examples/java/process/kill/process-kill.tesh diff --git a/examples/java/process/migration/process_migration.tesh b/examples/java/process/migration/process-migration.tesh similarity index 100% rename from examples/java/process/migration/process_migration.tesh rename to examples/java/process/migration/process-migration.tesh diff --git a/examples/java/process/startkilltime/process_startkilltime.tesh b/examples/java/process/startkilltime/process-startkilltime.tesh similarity index 100% rename from examples/java/process/startkilltime/process_startkilltime.tesh rename to examples/java/process/startkilltime/process-startkilltime.tesh diff --git a/examples/java/process/suspend/process_suspend.tesh b/examples/java/process/suspend/process-suspend.tesh similarity index 100% rename from examples/java/process/suspend/process_suspend.tesh rename to examples/java/process/suspend/process-suspend.tesh diff --git a/examples/java/task/priority/task_priority.tesh b/examples/java/task/priority/task-priority.tesh similarity index 100% rename from examples/java/task/priority/task_priority.tesh rename to examples/java/task/priority/task-priority.tesh diff --git a/examples/java/trace/pingpong/trace_pingpong.tesh b/examples/java/trace/pingpong/trace-pingpong.tesh similarity index 100% rename from examples/java/trace/pingpong/trace_pingpong.tesh rename to examples/java/trace/pingpong/trace-pingpong.tesh diff --git a/examples/msg/CMakeLists.txt b/examples/msg/CMakeLists.txt index fc994e39e4..af786dcfc5 100644 --- a/examples/msg/CMakeLists.txt +++ b/examples/msg/CMakeLists.txt @@ -96,10 +96,10 @@ foreach (x categories route-user-variables link-user-variables masterworker plat ADD_TESH(msg-trace-${x} --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/trace-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/trace-${x} trace-${x}.tesh) endforeach() -ADD_TESH_FACTORIES(msg-dht-kademlia-parallel "thread;ucontext;raw" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/dht-kademlia --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/dht-kademlia dht-kademlia.tesh) +ADD_TESH_FACTORIES(msg-dht-kademlia-parallel "thread;ucontext;raw;boost" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/dht-kademlia --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/dht-kademlia dht-kademlia.tesh) ADD_TESH_FACTORIES(msg-energy-pstate-ptask "thread;ucontext;raw;boost" --cfg host/model:ptask_L07 --log xbt_cfg.threshold:critical --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy-pstate/energy-pstate.tesh) ADD_TESH_FACTORIES(msg-energy-consumption-ptask "thread;ucontext;raw;boost" --cfg host/model:ptask_L07 --log xbt_cfg.threshold:critical --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy-consumption/energy-consumption.tesh) -ADD_TESH_FACTORIES(msg-energy-ptask "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy-ptask/energy-ptask.tesh) +ADD_TESH_FACTORIES(msg-energy-ptask "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/energy-ptask/energy-ptask.tesh) ADD_TESH_FACTORIES(msg-plugin-hostload "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/ ${CMAKE_HOME_DIRECTORY}/examples/msg/plugin-hostload/plugin-hostload.tesh) if(NOT WIN32) ADD_TESH_FACTORIES(msg-maestro-set "thread" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/maestro-set/maestro-set.tesh) diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index d3ce9a6a11..0ee6b1e500 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -31,7 +31,6 @@ endforeach() set(examples_src ${examples_src} PARENT_SCOPE) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh - ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany.tesh diff --git a/examples/s4u/actions-comm/s4u-actions-comm.cpp b/examples/s4u/actions-comm/s4u-actions-comm.cpp index 2779185680..f620071304 100644 --- a/examples/s4u/actions-comm/s4u-actions-comm.cpp +++ b/examples/s4u/actions-comm/s4u-actions-comm.cpp @@ -85,7 +85,7 @@ public: int main(int argc, char *argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s platform_file deployment_file [action_files]\n" "\t# if all actions are in the same file\n" @@ -94,11 +94,11 @@ int main(int argc, char *argv[]) "\tExample: %s msg_platform.xml msg_deployment.xml ", argv[0], argv[0], argv[0]); - e->loadPlatform(argv[1]); - e->registerDefault(&simgrid::xbt::replay_runner); - e->registerFunction("p0"); - e->registerFunction("p1"); - e->loadDeployment(argv[2]); + e.loadPlatform(argv[1]); + e.registerDefault(&simgrid::xbt::replay_runner); + e.registerFunction("p0"); + e.registerFunction("p1"); + e.loadDeployment(argv[2]); /* Action registration */ xbt_replay_action_register("compute", Replayer::compute); @@ -109,15 +109,14 @@ int main(int argc, char *argv[]) simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in); } - e->run(); + e.run(); if (argv[3]) { delete simgrid::xbt::action_fs; simgrid::xbt::action_fs = nullptr; } - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actions-storage/s4u-actions-storage.cpp b/examples/s4u/actions-storage/s4u-actions-storage.cpp index 85ffb9d975..79a8ababd3 100644 --- a/examples/s4u/actions-storage/s4u-actions-storage.cpp +++ b/examples/s4u/actions-storage/s4u-actions-storage.cpp @@ -102,7 +102,7 @@ public: int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 3, "Usage: %s platform_file deployment_file [action_files]\n" "\texample: %s platform.xml deployment.xml actions # if all actions are in the same file\n" @@ -110,10 +110,10 @@ int main(int argc, char* argv[]) "\texample: %s platform.xml deployment.xml", argv[0], argv[0], argv[0]); - e->loadPlatform(argv[1]); - e->registerDefault(&simgrid::xbt::replay_runner); - e->registerFunction("p0"); - e->loadDeployment(argv[2]); + e.loadPlatform(argv[1]); + e.registerDefault(&simgrid::xbt::replay_runner); + e.registerFunction("p0"); + e.loadDeployment(argv[2]); /* Action registration */ xbt_replay_action_register("open", Replayer::open); @@ -124,15 +124,14 @@ int main(int argc, char* argv[]) simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in); } - e->run(); + e.run(); if (argv[3]) { delete simgrid::xbt::action_fs; simgrid::xbt::action_fs = nullptr; } - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index ca6cd9b171..33ed245dac 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2017. 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. */ @@ -87,10 +87,10 @@ public: int main(int argc, char** argv) { /* When your program starts, you have to first start a new simulation engine, as follows */ - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); /* Then you should load a platform file, describing your simulated platform */ - e->loadPlatform("../../platforms/small_platform.xml"); + e.loadPlatform("../../platforms/small_platform.xml"); /* And now you have to ask SimGrid to actually start your actors. * @@ -100,21 +100,19 @@ int main(int argc, char** argv) simgrid::s4u::Actor::createActor("sender1", simgrid::s4u::Host::by_name("Tremblay"), Sender()); /* The second way is to first register your function, and then retrieve it */ - e->registerFunction("sender"); // The sender is passed as a template parameter here + e.registerFunction("sender"); // The sender is passed as a template parameter here std::vector args; // Here we declare the parameter that the actor will get args.push_back("GloubiBoulga"); // Add a parameter to the set (we could have done it in the first approach too) simgrid::s4u::Actor::createActor("sender2", simgrid::s4u::Host::by_name("Jupiter"), "sender", args); /* The third way to start your actors is to use a deployment file. */ - e->registerFunction("receiver"); // You first have to register the actor as with the second approach - e->loadDeployment("s4u-actor-create_d.xml"); // And then, you load the deployment file + e.registerFunction("receiver"); // You first have to register the actor as with the second approach + e.loadDeployment("s4u-actor-create_d.xml"); // And then, you load the deployment file /* Once every actors are started in the engine, the simulation can start */ - e->run(); + e.run(); /* Once the simulation is done, the program is ended */ - delete e; - return 0; } diff --git a/examples/s4u/actor-daemon/s4u-actor-daemon.cpp b/examples/s4u/actor-daemon/s4u-actor-daemon.cpp index b415f288b4..4c8d19ca20 100644 --- a/examples/s4u/actor-daemon/s4u-actor-daemon.cpp +++ b/examples/s4u/actor-daemon/s4u-actor-daemon.cpp @@ -31,14 +31,12 @@ static void my_daemon() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Boivin"), worker); simgrid::s4u::Actor::createActor("daemon", simgrid::s4u::Host::by_name("Tremblay"), my_daemon); - e->run(); - - delete e; + e.run(); return 0; } diff --git a/examples/s4u/actor-kill/s4u-actor-kill.cpp b/examples/s4u/actor-kill/s4u-actor-kill.cpp index e6a77aaf7f..fe726b40ae 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.cpp +++ b/examples/s4u/actor-kill/s4u-actor-kill.cpp @@ -7,8 +7,15 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_kill, "Messages specific for this s4u example"); +static int on_exit(void*, void*) +{ + XBT_INFO("I have been killed!"); + return 0; +} + static void victim() { + simgrid::s4u::this_actor::onExit(on_exit, nullptr); XBT_INFO("Hello!"); XBT_INFO("Suspending myself"); simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */ @@ -24,11 +31,16 @@ static void killer() simgrid::s4u::Actor::createActor("victim", simgrid::s4u::Host::by_name("Fafard"), victim); simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */ - XBT_INFO("Resume process"); /* - Resume it from its suspended state */ + XBT_INFO("Resume the victim"); /* - Resume it from its suspended state */ poor_victim->resume(); + simgrid::s4u::this_actor::sleep_for(2); - XBT_INFO("Kill process"); /* - and then kill it */ + XBT_INFO("Kill the victim"); /* - and then kill it */ poor_victim->kill(); + simgrid::s4u::this_actor::sleep_for(1); + + XBT_INFO("Killing everybody but myself"); + simgrid::s4u::Actor::killAll(); XBT_INFO("OK, goodbye now. I commit a suicide."); simgrid::s4u::this_actor::kill(); @@ -38,17 +50,20 @@ static void killer() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ /* - Create and deploy killer process, that will create the victim process */ simgrid::s4u::Actor::createActor("killer", simgrid::s4u::Host::by_name("Tremblay"), killer); + simgrid::s4u::Actor::createActor("Alice", simgrid::s4u::Host::by_name("Jupiter"), victim); + simgrid::s4u::Actor::createActor("Bob", simgrid::s4u::Host::by_name("Ginette"), victim); + simgrid::s4u::Actor::createActor("Carol", simgrid::s4u::Host::by_name("Bourassa"), victim); + simgrid::s4u::Actor::createActor("Dave", simgrid::s4u::Host::by_name("Boivin"), victim); - e->run(); /* - Run the simulation */ + e.run(); /* - Run the simulation */ - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-kill/s4u-actor-kill.tesh b/examples/s4u/actor-kill/s4u-actor-kill.tesh index 0c876df6d8..0f68771e0f 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.tesh +++ b/examples/s4u/actor-kill/s4u-actor-kill.tesh @@ -2,9 +2,24 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-kill ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" > [ 0.000000] (killer@Tremblay) Hello! +> [ 0.000000] (Alice@Jupiter) Hello! +> [ 0.000000] (Alice@Jupiter) Suspending myself +> [ 0.000000] (Bob@Ginette) Hello! +> [ 0.000000] (Bob@Ginette) Suspending myself +> [ 0.000000] (Carol@Bourassa) Hello! +> [ 0.000000] (Carol@Bourassa) Suspending myself +> [ 0.000000] (Dave@Boivin) Hello! +> [ 0.000000] (Dave@Boivin) Suspending myself > [ 0.000000] (victim@Fafard) Hello! > [ 0.000000] (victim@Fafard) Suspending myself -> [ 10.000000] (killer@Tremblay) Resume process -> [ 10.000000] (killer@Tremblay) Kill process -> [ 10.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide. -> [ 10.000000] (maestro@) Simulation time 10 +> [ 10.000000] (killer@Tremblay) Resume the victim +> [ 10.000000] (victim@Fafard) OK, OK. Let's work +> [ 12.000000] (killer@Tremblay) Kill the victim +> [ 12.000000] (victim@Fafard) I have been killed! +> [ 13.000000] (killer@Tremblay) Killing everybody but myself +> [ 13.000000] (Alice@Jupiter) I have been killed! +> [ 13.000000] (Bob@Ginette) I have been killed! +> [ 13.000000] (Carol@Bourassa) I have been killed! +> [ 13.000000] (Dave@Boivin) I have been killed! +> [ 13.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide. +> [ 13.000000] (maestro@) Simulation time 13 diff --git a/examples/s4u/actor-migration/s4u-actor-migration.cpp b/examples/s4u/actor-migration/s4u-actor-migration.cpp index 102843c2cd..5db7924478 100644 --- a/examples/s4u/actor-migration/s4u-actor-migration.cpp +++ b/examples/s4u/actor-migration/s4u-actor-migration.cpp @@ -58,9 +58,9 @@ static void policeman() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ /* - Create and deploy the emigrant and policeman processes */ simgrid::s4u::Actor::createActor("emigrant", simgrid::s4u::Host::by_name("Jacquelin"), emigrant); @@ -68,10 +68,9 @@ int main(int argc, char* argv[]) checkpoint = simgrid::s4u::Mutex::createMutex(); /* - Initiate the mutex and conditions */ identification = simgrid::s4u::ConditionVariable::createConditionVariable(); - e->run(); + e.run(); - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp index 9d98a4a83b..b663e8e026 100644 --- a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp +++ b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp @@ -66,16 +66,15 @@ static void dream_master() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /* - Load the platform description */ + e.loadPlatform(argv[1]); /* - Load the platform description */ std::vector list; - e->getHostList(&list); + e.getHostList(&list); simgrid::s4u::Actor::createActor("dream_master", list.front(), dream_master); - e->run(); /* - Run the simulation */ + e.run(); /* - Run the simulation */ - delete e; return 0; } diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp index d205165aa6..38709b0be3 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp @@ -12,12 +12,12 @@ simgrid::xbt::Extension HostBittorrent::EXTE int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); /* Check the arguments */ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file", argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create(); @@ -26,12 +26,11 @@ int main(int argc, char* argv[]) for (auto const& host : list) host->extension_set(new HostBittorrent(host)); - e->registerFunction("tracker"); - e->registerFunction("peer"); - e->loadDeployment(argv[2]); + e.registerFunction("tracker"); + e.registerFunction("peer"); + e.loadDeployment(argv[2]); - e->run(); + e.run(); - delete e; return 0; } diff --git a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp index c0ce006b50..d360480ac7 100644 --- a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp @@ -85,20 +85,19 @@ public: int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); /** - Load the platform description */ - e->registerFunction("master"); - e->registerFunction("worker"); /** - Register the function to be executed by the processes */ - e->loadDeployment(argv[2]); /** - Deploy the application */ + e.loadPlatform(argv[1]); /** - Load the platform description */ + e.registerFunction("master"); + e.registerFunction("worker"); /** - Register the function to be executed by the processes */ + e.loadDeployment(argv[2]); /** - Deploy the application */ - e->run(); /** - Run the simulation */ + e.run(); /** - Run the simulation */ - XBT_INFO("Simulation time %g", e->getClock()); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp index d47ff48d45..a644f694fd 100644 --- a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp +++ b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp @@ -54,9 +54,9 @@ static void ponger(std::vector args) int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); std::vector args; args.push_back("Jupiter"); simgrid::s4u::Actor::createActor("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, args); @@ -66,10 +66,9 @@ int main(int argc, char* argv[]) simgrid::s4u::Actor::createActor("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, args); - e->run(); + e.run(); - XBT_INFO("Total simulation time: %.3f", e->getClock()); - delete e; + XBT_INFO("Total simulation time: %.3f", e.getClock()); return 0; } diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index a5c3d7fa4a..ce84f9c540 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -55,22 +55,21 @@ public: int main(int argc, char** argv) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); - XBT_INFO("Number of hosts '%zu'", e->getHostCount()); + XBT_INFO("Number of hosts '%zu'", e.getHostCount()); int id = 0; std::vector list; - e->getHostList(&list); + e.getHostList(&list); for (auto const& host : list) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */ simgrid::s4u::Actor::createActor((std::to_string(id)).c_str(), host, RelayRunner()); id++; } - e->run(); - XBT_INFO("Simulation time %g", e->getClock()); + e.run(); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; } diff --git a/examples/s4u/async-waitall/s4u-async-waitall.cpp b/examples/s4u/async-waitall/s4u-async-waitall.cpp index 332ce0ab6d..55f645e4e1 100644 --- a/examples/s4u/async-waitall/s4u-async-waitall.cpp +++ b/examples/s4u/async-waitall/s4u-async-waitall.cpp @@ -102,16 +102,15 @@ void operator()() int main(int argc, char *argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]); - e->registerFunction("sender"); - e->registerFunction("receiver"); + simgrid::s4u::Engine e(&argc, argv); + e.registerFunction("sender"); + e.registerFunction("receiver"); - e->loadPlatform(argv[1]); - e->loadDeployment(argv[2]); - e->run(); + e.loadPlatform(argv[1]); + e.loadDeployment(argv[2]); + e.run(); return 0; } diff --git a/examples/s4u/async-waitany/s4u-async-waitany.cpp b/examples/s4u/async-waitany/s4u-async-waitany.cpp index e47ef260f3..9081044659 100644 --- a/examples/s4u/async-waitany/s4u-async-waitany.cpp +++ b/examples/s4u/async-waitany/s4u-async-waitany.cpp @@ -118,16 +118,15 @@ void operator()() int main(int argc, char *argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]); - e->registerFunction("sender"); - e->registerFunction("receiver"); + simgrid::s4u::Engine e(&argc, argv); + e.registerFunction("sender"); + e.registerFunction("receiver"); - e->loadPlatform(argv[1]); - e->loadDeployment(argv[2]); - e->run(); + e.loadPlatform(argv[1]); + e.loadDeployment(argv[2]); + e.run(); return 0; } diff --git a/examples/s4u/dht-chord/node.cpp b/examples/s4u/dht-chord/node.cpp index de23d95433..a31877fa62 100644 --- a/examples/s4u/dht-chord/node.cpp +++ b/examples/s4u/dht-chord/node.cpp @@ -40,6 +40,11 @@ static int is_in_interval(int id, int start, int end) return i <= e; } +void ChordMessage::destroy(void* message) +{ + delete static_cast(message); +} + /* Initializes the current node as the first one of the system */ Node::Node(std::vector args) { @@ -389,7 +394,7 @@ void Node::remoteNotify(int notify_id, int predecessor_candidate_id) // send a "Notify" request to notify_id XBT_DEBUG("Sending a 'Notify' request to %d", notify_id); simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(notify_id)); - mailbox->put_init(message, 10)->detach(); + mailbox->put_init(message, 10)->detach(ChordMessage::destroy); } /* This function is called periodically. It checks the immediate successor of the current node. */ @@ -429,14 +434,14 @@ void Node::handleMessage(ChordMessage* message) XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d", message->issuer_host_name.c_str(), message->answer_to->getName(), message->request_id, message->answer_id); - message->answer_to->put_init(message, 10)->detach(); + message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); } else { // otherwise, forward the request to the closest preceding finger in my table int closest = closestPrecedingFinger(message->request_id); XBT_DEBUG("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d", message->request_id, closest); simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(closest)); - mailbox->put_init(message, 10)->detach(); + mailbox->put_init(message, 10)->detach(ChordMessage::destroy); } break; @@ -446,7 +451,7 @@ void Node::handleMessage(ChordMessage* message) message->answer_id = pred_id_; XBT_DEBUG("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d", message->issuer_host_name.c_str(), message->answer_to->getName(), message->answer_id); - message->answer_to->put_init(message, 10)->detach(); + message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); break; case NOTIFY: @@ -484,7 +489,7 @@ void Node::handleMessage(ChordMessage* message) message->type = PREDECESSOR_ALIVE_ANSWER; XBT_DEBUG("Sending back a 'Predecessor Alive Answer' to %s (mailbox %s)", message->issuer_host_name.c_str(), message->answer_to->getName()); - message->answer_to->put_init(message, 10)->detach(); + message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); break; default: diff --git a/examples/s4u/dht-chord/s4u-dht-chord.cpp b/examples/s4u/dht-chord/s4u-dht-chord.cpp index 96bae87f1f..5c819f1f7b 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.cpp @@ -41,7 +41,7 @@ static void chord_exit() int main(int argc, char* argv[]) { - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc > 2, "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n" "\tExample: %s ../msg_platform.xml chord.xml\n", argv[0], argv[0]); @@ -63,19 +63,18 @@ int main(int argc, char* argv[]) options++; } - e->loadPlatform(options[0]); + e.loadPlatform(options[0]); chord_init(); - e->registerFunction("node"); - e->loadDeployment(options[1]); + e.registerFunction("node"); + e.loadDeployment(options[1]); - e->run(); + e.run(); - XBT_INFO("Simulated time: %g", e->getClock()); + XBT_INFO("Simulated time: %g", e.getClock()); chord_exit(); - delete e; return 0; } diff --git a/examples/s4u/dht-chord/s4u-dht-chord.hpp b/examples/s4u/dht-chord/s4u-dht-chord.hpp index 04f0c224e2..4c44d8fc98 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.hpp @@ -69,6 +69,8 @@ public: } ~ChordMessage() = default; + + static void destroy(void* message); }; class Node { @@ -85,6 +87,7 @@ class Node { public: explicit Node(std::vector args); + Node(const Node&) = delete; ~Node(); void join(int known_id); void leave(); @@ -159,8 +162,11 @@ public: } now = simgrid::s4u::Engine::getClock(); } - if (data != nullptr) { - delete static_cast(data); + if (comm_receive != nullptr) { + if (comm_receive->test()) + delete static_cast(data); + else + comm_receive->cancel(); } // leave the ring leave(); diff --git a/examples/s4u/dht-chord/s4u-dht-chord.tesh b/examples/s4u/dht-chord/s4u-dht-chord.tesh index 7c8349f156..3096c45a7d 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.tesh +++ b/examples/s4u/dht-chord/s4u-dht-chord.tesh @@ -177,61 +177,61 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-dht-chord$EXEEXT -nb_bits=3 ${srcdir:=.}/clust > [ 360.18115] (node@node-0.acme.org) Predecessor: 533744 > [ 420.23459] (node@node-2.acme.org) Well Guys! I Think it's time for me to leave ;) > [ 425.22668] (node@node-0.acme.org) My new predecessor is 42 -> [ 475.23449] (node@node-0.acme.org) My new finger #0 is 42 -> [ 480.23439] (node@node-0.acme.org) My new predecessor is 16728096 -> [ 480.23439] (node@node-0.acme.org) My finger table: -> [ 480.23439] (node@node-0.acme.org) Start | Succ -> [ 480.23439] (node@node-0.acme.org) 3 | 42 -> [ 480.23439] (node@node-0.acme.org) 4 | 16509405 -> [ 480.23439] (node@node-0.acme.org) 6 | 533744 -> [ 480.23439] (node@node-0.acme.org) Predecessor: 16728096 -> [ 485.24209] (node@node-6.acme.org) My new finger #2 is 42 -> [ 485.24209] (node@node-6.acme.org) My finger table: -> [ 485.24209] (node@node-6.acme.org) Start | Succ -> [ 485.24209] (node@node-6.acme.org) 1 | 42 -> [ 485.24209] (node@node-6.acme.org) 2 | 42 -> [ 485.24209] (node@node-6.acme.org) 4 | 42 -> [ 485.24209] (node@node-6.acme.org) Predecessor: -1 -> [ 495.24970] (node@node-0.acme.org) My new finger #0 is 16728096 -> [ 575.26471] (node@node-6.acme.org) My new predecessor is 42 -> [ 575.26471] (node@node-6.acme.org) My finger table: -> [ 575.26471] (node@node-6.acme.org) Start | Succ -> [ 575.26471] (node@node-6.acme.org) 1 | 42 -> [ 575.26471] (node@node-6.acme.org) 2 | 42 -> [ 575.26471] (node@node-6.acme.org) 4 | 42 -> [ 575.26471] (node@node-6.acme.org) Predecessor: 42 -> [ 600.27202] (node@node-0.acme.org) My new finger #1 is 16728096 -> [ 600.27202] (node@node-0.acme.org) My finger table: -> [ 600.27202] (node@node-0.acme.org) Start | Succ -> [ 600.27202] (node@node-0.acme.org) 3 | 16728096 -> [ 600.27202] (node@node-0.acme.org) 4 | 16728096 -> [ 600.27202] (node@node-0.acme.org) 6 | 533744 -> [ 600.27202] (node@node-0.acme.org) Predecessor: 16728096 -> [ 720.36329] (node@node-0.acme.org) My new finger #2 is 16728096 -> [ 720.36329] (node@node-0.acme.org) My finger table: -> [ 720.36329] (node@node-0.acme.org) Start | Succ -> [ 720.36329] (node@node-0.acme.org) 3 | 16728096 -> [ 720.36329] (node@node-0.acme.org) 4 | 16728096 -> [ 720.36329] (node@node-0.acme.org) 6 | 16728096 -> [ 720.36329] (node@node-0.acme.org) Predecessor: 16728096 -> [ 855.46207] (node@node-6.acme.org) My new finger #2 is 16728096 -> [ 855.46207] (node@node-6.acme.org) My finger table: -> [ 855.46207] (node@node-6.acme.org) Start | Succ -> [ 855.46207] (node@node-6.acme.org) 1 | 42 -> [ 855.46207] (node@node-6.acme.org) 2 | 42 -> [ 855.46207] (node@node-6.acme.org) 4 | 16728096 -> [ 855.46207] (node@node-6.acme.org) Predecessor: 42 -> [ 860.46197] (node@node-6.acme.org) Well Guys! I Think it's time for me to leave ;) -> [ 865.45406] (node@node-0.acme.org) My new predecessor is 42 -> [ 890.43115] (node@node-5.acme.org) Well Guys! I Think it's time for me to leave ;) -> [ 915.45406] (node@node-0.acme.org) My new finger #0 is 42 -> [ 940.45356] (node@node-0.acme.org) My new finger #0 is 16509405 -> [ 990.45356] (node@node-0.acme.org) My new finger #1 is 16509405 -> [ 990.45356] (node@node-0.acme.org) My finger table: -> [ 990.45356] (node@node-0.acme.org) Start | Succ -> [ 990.45356] (node@node-0.acme.org) 3 | 16509405 -> [ 990.45356] (node@node-0.acme.org) 4 | 16509405 -> [ 990.45356] (node@node-0.acme.org) 6 | 16728096 -> [ 990.45356] (node@node-0.acme.org) Predecessor: 42 -> [1040.45356] (node@node-0.acme.org) Well Guys! I Think it's time for me to leave ;) -> [1090.45356] (maestro@) Simulated time: 1090.45 +> [ 475.22668] (node@node-0.acme.org) My new finger #0 is 42 +> [ 480.22658] (node@node-0.acme.org) My new predecessor is 16728096 +> [ 480.22658] (node@node-0.acme.org) My finger table: +> [ 480.22658] (node@node-0.acme.org) Start | Succ +> [ 480.22658] (node@node-0.acme.org) 3 | 42 +> [ 480.22658] (node@node-0.acme.org) 4 | 16509405 +> [ 480.22658] (node@node-0.acme.org) 6 | 533744 +> [ 480.22658] (node@node-0.acme.org) Predecessor: 16728096 +> [ 485.23429] (node@node-6.acme.org) My new finger #2 is 42 +> [ 485.23429] (node@node-6.acme.org) My finger table: +> [ 485.23429] (node@node-6.acme.org) Start | Succ +> [ 485.23429] (node@node-6.acme.org) 1 | 42 +> [ 485.23429] (node@node-6.acme.org) 2 | 42 +> [ 485.23429] (node@node-6.acme.org) 4 | 42 +> [ 485.23429] (node@node-6.acme.org) Predecessor: -1 +> [ 495.24189] (node@node-0.acme.org) My new finger #0 is 16728096 +> [ 575.25691] (node@node-6.acme.org) My new predecessor is 42 +> [ 575.25691] (node@node-6.acme.org) My finger table: +> [ 575.25691] (node@node-6.acme.org) Start | Succ +> [ 575.25691] (node@node-6.acme.org) 1 | 42 +> [ 575.25691] (node@node-6.acme.org) 2 | 42 +> [ 575.25691] (node@node-6.acme.org) 4 | 42 +> [ 575.25691] (node@node-6.acme.org) Predecessor: 42 +> [ 600.26421] (node@node-0.acme.org) My new finger #1 is 16728096 +> [ 600.26421] (node@node-0.acme.org) My finger table: +> [ 600.26421] (node@node-0.acme.org) Start | Succ +> [ 600.26421] (node@node-0.acme.org) 3 | 16728096 +> [ 600.26421] (node@node-0.acme.org) 4 | 16728096 +> [ 600.26421] (node@node-0.acme.org) 6 | 533744 +> [ 600.26421] (node@node-0.acme.org) Predecessor: 16728096 +> [ 720.35548] (node@node-0.acme.org) My new finger #2 is 16728096 +> [ 720.35548] (node@node-0.acme.org) My finger table: +> [ 720.35548] (node@node-0.acme.org) Start | Succ +> [ 720.35548] (node@node-0.acme.org) 3 | 16728096 +> [ 720.35548] (node@node-0.acme.org) 4 | 16728096 +> [ 720.35548] (node@node-0.acme.org) 6 | 16728096 +> [ 720.35548] (node@node-0.acme.org) Predecessor: 16728096 +> [ 855.45426] (node@node-6.acme.org) My new finger #2 is 16728096 +> [ 855.45426] (node@node-6.acme.org) My finger table: +> [ 855.45426] (node@node-6.acme.org) Start | Succ +> [ 855.45426] (node@node-6.acme.org) 1 | 42 +> [ 855.45426] (node@node-6.acme.org) 2 | 42 +> [ 855.45426] (node@node-6.acme.org) 4 | 16728096 +> [ 855.45426] (node@node-6.acme.org) Predecessor: 42 +> [ 860.45416] (node@node-6.acme.org) Well Guys! I Think it's time for me to leave ;) +> [ 865.44626] (node@node-0.acme.org) My new predecessor is 42 +> [ 890.42334] (node@node-5.acme.org) Well Guys! I Think it's time for me to leave ;) +> [ 915.44626] (node@node-0.acme.org) My new finger #0 is 42 +> [ 940.44576] (node@node-0.acme.org) My new finger #0 is 16509405 +> [ 990.44576] (node@node-0.acme.org) My new finger #1 is 16509405 +> [ 990.44576] (node@node-0.acme.org) My finger table: +> [ 990.44576] (node@node-0.acme.org) Start | Succ +> [ 990.44576] (node@node-0.acme.org) 3 | 16509405 +> [ 990.44576] (node@node-0.acme.org) 4 | 16509405 +> [ 990.44576] (node@node-0.acme.org) 6 | 16728096 +> [ 990.44576] (node@node-0.acme.org) Predecessor: 42 +> [1040.44576] (node@node-0.acme.org) Well Guys! I Think it's time for me to leave ;) +> [1090.44576] (maestro@) Simulated time: 1090.45 diff --git a/examples/s4u/io/s4u-io.cpp b/examples/s4u/io/s4u-io.cpp index 789bf1cdb0..fb4bc28113 100644 --- a/examples/s4u/io/s4u-io.cpp +++ b/examples/s4u/io/s4u-io.cpp @@ -83,10 +83,10 @@ public: int main(int argc, char **argv) { - simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv); - e->loadPlatform("../../platforms/storage/storage.xml"); + simgrid::s4u::Engine e(&argc, argv); + e.loadPlatform("../../platforms/storage/storage.xml"); simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("denise"), MyHost()); - e->run(); - delete e; + e.run(); + return 0; } diff --git a/examples/s4u/mutex/s4u-mutex.cpp b/examples/s4u/mutex/s4u-mutex.cpp index 2f2afd9ccd..b1e352334f 100644 --- a/examples/s4u/mutex/s4u-mutex.cpp +++ b/examples/s4u/mutex/s4u-mutex.cpp @@ -60,11 +60,10 @@ static void master() int main(int argc, char **argv) { - simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv); - e->loadPlatform("../../platforms/two_hosts.xml"); + simgrid::s4u::Engine e(&argc, argv); + e.loadPlatform("../../platforms/two_hosts.xml"); simgrid::s4u::Actor::createActor("main", simgrid::s4u::Host::by_name("Tremblay"), master); - e->run(); + e.run(); - delete e; return 0; } diff --git a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp b/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp index 3f6efc4de8..5ddec37fdd 100644 --- a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp +++ b/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2007-2010, 2013-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. 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. */ @@ -69,17 +68,16 @@ static void execute_load_test() int main(int argc, char* argv[]) { sg_host_load_plugin_init(); - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test); - e->run(); + e.run(); XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::getClock()); - delete e; return 0; } diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index dcb0e17745..ff9f2685ad 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -102,6 +102,12 @@ public: /** Start the comm, and ignore its result. It can be completely forgotten after that. */ void detach(); + /** Start the comm, and ignore its result. It can be completely forgotten after that. */ + void detach(void (*cleanFunction)(void*)) + { + cleanFunction_ = cleanFunction; + detach(); + } /** Sets the maximal communication rate (in byte/sec). Must be done before start */ void setRate(double rate); diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index b27c954e0c..09c55ec295 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -105,6 +105,13 @@ public: void routeTo(Host * dest, std::vector * links, double* latency); void routeTo(Host * dest, std::vector * links, double* latency); + /** Block the calling actor on an execution located on the called host + * + * It is not a problem if the actor is not located on the called host. + * The actor will not be migrated in this case. Such remote execution are easy in simulation. + */ + void execute(double flops); + private: simgrid::xbt::string name_ = "noname"; std::unordered_map* mounts = nullptr; // caching diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index de1ac3ad5f..4d551932c5 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -65,9 +65,9 @@ typedef enum { /* Process creation/destruction callbacks */ typedef void (*void_pfn_smxprocess_t) (smx_actor_t); -extern int smx_context_stack_size; +extern unsigned smx_context_stack_size; extern int smx_context_stack_size_was_set; -extern int smx_context_guard_size; +extern unsigned smx_context_guard_size; extern int smx_context_guard_size_was_set; SG_BEGIN_DECL() diff --git a/include/xbt/heap.h b/include/xbt/heap.h index 7e4ea84cc3..27c2a81a58 100644 --- a/include/xbt/heap.h +++ b/include/xbt/heap.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2007, 2009-2011, 2013-2015. The SimGrid Team. +/* Copyright (c) 2004-2007, 2009-2011, 2013-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -29,7 +29,7 @@ XBT_PUBLIC(int) xbt_heap_size(xbt_heap_t H); XBT_PUBLIC(void) xbt_heap_push(xbt_heap_t H, void *content, double key); XBT_PUBLIC(void *) xbt_heap_pop(xbt_heap_t H); -XBT_PUBLIC(void) xbt_heap_rm_elm(xbt_heap_t H, void *content, double key); +XBT_PUBLIC(void *) xbt_heap_rm_elm(xbt_heap_t H, void *content, double key); XBT_PUBLIC(double) xbt_heap_maxkey(xbt_heap_t H); XBT_PUBLIC(void *) xbt_heap_maxcontent(xbt_heap_t H); diff --git a/sonar-project.properties b/sonar-project.properties index 1bcfe40cb8..a465888023 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -13,7 +13,7 @@ sonar.sources=src,examples,include,teshsuite # Disable some rules on some files -sonar.issue.ignore.multicriteria=j1,j2,jni1,jni2,c1,c2a,c2b,c3,c4a,c4b,c5a,c5b,f1 +sonar.issue.ignore.multicriteria=j1,j2,jni1,jni2,c1,c2a,c2b,c3,c4a,c4b,c5a,c5b,c6a,c6b,f1 # The Object.finalize() method should not be overriden # But we need to clean the native memory with JNI @@ -67,6 +67,13 @@ sonar.issue.ignore.multicriteria.c5a.resourceKey=**/*.cpp sonar.issue.ignore.multicriteria.c5b.ruleKey=cpp:S3659 sonar.issue.ignore.multicriteria.c5b.resourceKey=**/*.hpp +# Dynamically allocated memory should be released +# We have better ways to detect memleaks in SimGrid +# This is not disabled in example/ because our code should be nice looking +sonar.issue.ignore.multicriteria.c6a.ruleKey=cpp:S3584 +sonar.issue.ignore.multicriteria.c6a.resourceKey=src/**/*.cpp +sonar.issue.ignore.multicriteria.c6a.ruleKey=cpp:S3584 +sonar.issue.ignore.multicriteria.c6a.resourceKey=teshsuite/**/*.cpp # "reinterpret_cast" should not be used # But we need this to interface C and Fortran @@ -96,7 +103,8 @@ sonar.cfamily.gcov.reportsPath=Testing/CoverageInfo # Files to ignore from coverage analysis: # - foreign test suites # - platform files (I fail to get sonar ignore *.xml files) -sonar.coverage.exclusions=teshsuite/smpi/isp/**,teshsuite/smpi/mpich3-test/**,examples/platforms/** +# - Java code and examples +sonar.coverage.exclusions=teshsuite/smpi/isp/**,teshsuite/smpi/mpich3-test/**,examples/platforms/**,src/bindings/java/**,examples/java/** # Encoding of the source files sonar.sourceEncoding=UTF-8 diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 3e229a12c2..cf20d44e74 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -143,8 +143,7 @@ int TRACE_end() /* destroy all data structures of tracing (and free) */ PJ_container_free_all(); - recursiveDestroyType (PJ_type_get_root()); - PJ_container_release(); + delete PJ_type_get_root(); rootType = nullptr; /* close the trace files */ diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 3f079eb995..121b6f912b 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -183,7 +183,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar if (not mark_value) THROWF (tracing_error, 1, "mark_value is nullptr"); - simgrid::instr::Type* type = PJ_type_get(mark_type, PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild(mark_type); if (not type) { THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type); } @@ -193,7 +193,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar mark_color = white; XBT_DEBUG("MARK,declare_value %s %s %s", mark_type, mark_value, mark_color); - simgrid::instr::Value rett(mark_value, mark_color, type); + new simgrid::instr::Value(mark_value, mark_color, type); } /** \ingroup TRACE_mark @@ -239,7 +239,7 @@ void TRACE_mark(const char *mark_type, const char *mark_value) THROWF (tracing_error, 1, "mark_value is nullptr"); //check if mark_type is already declared - simgrid::instr::Type* type = PJ_type_get(mark_type, PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild(mark_type); if (not type) { THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type); } @@ -283,7 +283,7 @@ static void instr_user_variable(double time, const char* resource, const char* v char valuestr[100]; snprintf(valuestr, 100, "%g", value); container_t container = PJ_container_get(resource); - simgrid::instr::Type* type = PJ_type_get(variable, container->type_); + simgrid::instr::Type* type = container->type_->getChild(variable); switch (what){ case INSTR_US_SET: new simgrid::instr::SetVariableEvent(time, container, type, value); @@ -946,7 +946,7 @@ void TRACE_host_state_declare_value (const char *state, const char *value, const void TRACE_host_set_state(const char* host, const char* state, const char* value_str) { container_t container = PJ_container_get(host); - simgrid::instr::Type* type = PJ_type_get(state, container->type_); + simgrid::instr::Type* type = container->type_->getChild(state); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new( value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */ new simgrid::instr::SetStateEvent(MSG_get_clock(), container, type, val); @@ -966,7 +966,7 @@ void TRACE_host_set_state(const char* host, const char* state, const char* value void TRACE_host_push_state(const char* host, const char* state, const char* value_str) { container_t container = PJ_container_get(host); - simgrid::instr::Type* type = PJ_type_get(state, container->type_); + simgrid::instr::Type* type = container->type_->getChild(state); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new( value_str, nullptr, type); /* if user didn't declare a value with a color, use nullptr color */ new simgrid::instr::PushStateEvent(MSG_get_clock(), container, type, val); @@ -985,7 +985,7 @@ void TRACE_host_push_state(const char* host, const char* state, const char* valu void TRACE_host_pop_state (const char *host, const char *state) { container_t container = PJ_container_get(host); - simgrid::instr::Type* type = PJ_type_get(state, container->type_); + simgrid::instr::Type* type = container->type_->getChild(state); new simgrid::instr::PopStateEvent(MSG_get_clock(), container, type); } diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 9208684f97..7541e6b35d 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -10,10 +10,13 @@ #include "src/instr/instr_private.h" +#include + XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing event system (containers)"); static container_t rootContainer = nullptr; /* the root container */ -static xbt_dict_t allContainers = nullptr; /* all created containers indexed by name */ +static std::unordered_map + allContainers; /* all created containers indexed by name */ std::set trivaNodeTypes; /* all host types defined */ std::set trivaEdgeTypes; /* all link types defined */ @@ -23,16 +26,6 @@ long long int instr_new_paje_id () return type_id++; } -void PJ_container_alloc () -{ - allContainers = xbt_dict_new_homogeneous(nullptr); -} - -void PJ_container_release () -{ - xbt_dict_free (&allContainers); -} - void PJ_container_set_root (container_t root) { rootContainer = root; @@ -78,7 +71,7 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain char as_typename[INSTR_DEFAULT_STR_SIZE]; snprintf(as_typename, INSTR_DEFAULT_STR_SIZE, "L%d", this->level_); if (this->father_) { - this->type_ = simgrid::instr::Type::getOrNull(as_typename, this->father_->type_); + this->type_ = this->father_->type_->getChildOrNull(as_typename); if (this->type_ == nullptr) { this->type_ = simgrid::instr::Type::containerNew(as_typename, this->father_->type_); } @@ -114,7 +107,7 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain THROWF (tracing_error, 0, "new container kind is unknown."); break; } - simgrid::instr::Type* type = simgrid::instr::Type::getOrNull(typeNameBuff, this->father_->type_); + simgrid::instr::Type* type = this->father_->type_->getChildOrNull(typeNameBuff); if (type == nullptr){ this->type_ = simgrid::instr::Type::containerNew(typeNameBuff, this->father_->type_); }else{ @@ -128,11 +121,10 @@ simgrid::instr::Container::Container(const char* name, simgrid::instr::e_contain } //register all kinds by name - if (xbt_dict_get_or_null(allContainers, this->name_) != nullptr) { + if (not allContainers.emplace(this->name_, this).second) { THROWF(tracing_error, 1, "container %s already present in allContainers data structure", this->name_); } - xbt_dict_set(allContainers, this->name_, this, nullptr); XBT_DEBUG("Add container name '%s'", this->name_); //register NODE types for triva configuration @@ -158,7 +150,7 @@ simgrid::instr::Container::~Container() } // remove it from allContainers data structure - xbt_dict_remove(allContainers, name_); + allContainers.erase(name_); // free xbt_free(name_); @@ -166,7 +158,7 @@ simgrid::instr::Container::~Container() xbt_dict_free(&children_); } -container_t PJ_container_get (const char *name) +simgrid::instr::Container* PJ_container_get(const char* name) { container_t ret = PJ_container_get_or_null (name); if (ret == nullptr){ @@ -175,12 +167,13 @@ container_t PJ_container_get (const char *name) return ret; } -container_t PJ_container_get_or_null (const char *name) +simgrid::instr::Container* PJ_container_get_or_null(const char* name) { - return static_cast(name != nullptr ? xbt_dict_get_or_null(allContainers, name) : nullptr); + auto cont = allContainers.find(name); + return cont == allContainers.end() ? nullptr : cont->second; } -container_t PJ_container_get_root () +simgrid::instr::Container* PJ_container_get_root() { return rootContainer; } @@ -223,7 +216,7 @@ void PJ_container_free_all () rootContainer = nullptr; //checks - if (not xbt_dict_is_empty(allContainers)) { + if (not allContainers.empty()) { THROWF(tracing_error, 0, "some containers still present even after destroying all of them"); } } diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index 8d10295cb1..3e7c28234a 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -763,11 +763,6 @@ void simgrid::instr::ResetStateEvent::print() } } -simgrid::instr::StartLinkEvent::~StartLinkEvent() -{ - free(value); - free(key); -} simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type, container_t sourceContainer, const char* value, const char* key) : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1) @@ -776,17 +771,17 @@ simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t con simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type, container_t sourceContainer, const char* value, const char* key, int size) + : container_(container) + , type_(type) + , sourceContainer_(sourceContainer) + , value_(value) + , key_(key) + , size_(size) { eventType_ = PAJE_StartLink; this->timestamp_ = timestamp; - this->type = type; - this->container = container; - this->sourceContainer = sourceContainer; - this->value = xbt_strdup(value); - this->key = xbt_strdup(key); - this->size = size; - XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__, (int)eventType_, this->timestamp_, this->value); + XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__, (int)eventType_, this->timestamp_, this->value_.c_str()); insert_into_buffer (this); } @@ -798,11 +793,11 @@ void simgrid::instr::StartLinkEvent::print() stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); - stream << " " << type->id_ << " " << container->id_ << " " << value; - stream << " " << sourceContainer->id_ << " " << key; + stream << " " << type_->id_ << " " << container_->id_ << " " << value_; + stream << " " << sourceContainer_->id_ << " " << key_; if (TRACE_display_sizes()) { - stream << " " << size; + stream << " " << size_; } print_row(); } else if (instr_fmt_type == instr_fmt_TI) { diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 2ee897097a..e8b59fa77a 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -10,11 +10,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event sy static simgrid::instr::Type* rootType = nullptr; /* the root type */ -void PJ_type_release () -{ - rootType = nullptr; -} - simgrid::instr::Type* PJ_type_get_root() { return rootType; @@ -33,9 +28,7 @@ simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, const char this->values_ = xbt_dict_new_homogeneous(nullptr); this->color_ = xbt_strdup(color); - char str_id[INSTR_DEFAULT_STR_SIZE]; - snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id()); - this->id_ = xbt_strdup(str_id); + this->id_ = bprintf("%lld", instr_new_paje_id()); if (father != nullptr){ xbt_dict_set(father->children_, key, this, nullptr); @@ -43,59 +36,48 @@ simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, const char } } -void PJ_type_free(simgrid::instr::Type* type) +simgrid::instr::Type::~Type() { simgrid::instr::Value* val; char *value_name; xbt_dict_cursor_t cursor = nullptr; - xbt_dict_foreach (type->values_, cursor, value_name, val) { + xbt_dict_foreach (values_, cursor, value_name, val) { XBT_DEBUG("free value %s, child of %s", val->name_, val->father_->name_); - xbt_free(val); + delete val; } - xbt_dict_free(&type->values_); - xbt_free(type->name_); - xbt_free(type->id_); - xbt_free(type->color_); - xbt_dict_free(&type->children_); - delete type; -} - -void recursiveDestroyType(simgrid::instr::Type* type) -{ - XBT_DEBUG("recursiveDestroyType %s", type->name_); - xbt_dict_cursor_t cursor = nullptr; + xbt_dict_free(&values_); simgrid::instr::Type* child; char *child_name; - xbt_dict_foreach (type->children_, cursor, child_name, child) { - recursiveDestroyType (child); + xbt_dict_foreach (children_, cursor, child_name, child) { + delete child; } - PJ_type_free(type); + xbt_dict_free(&children_); + xbt_free(name_); + xbt_free(id_); + xbt_free(color_); } -simgrid::instr::Type* PJ_type_get(const char* name, simgrid::instr::Type* father) +simgrid::instr::Type* simgrid::instr::Type::getChild(const char* name) { - simgrid::instr::Type* ret = simgrid::instr::Type::getOrNull(name, father); - if (ret == nullptr){ - THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name_); - } + simgrid::instr::Type* ret = this->getChildOrNull(name); + if (ret == nullptr) + THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, this->name_); return ret; } -simgrid::instr::Type* simgrid::instr::Type::getOrNull(const char* name, simgrid::instr::Type* father) +simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(const char* name) { - if (name == nullptr || father == nullptr){ - THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father"); - } + xbt_assert(name != nullptr, "can't get type with a nullptr name"); simgrid::instr::Type* ret = nullptr; simgrid::instr::Type* child; char *child_name; xbt_dict_cursor_t cursor = nullptr; - xbt_dict_foreach (father->children_, cursor, child_name, child) { + xbt_dict_foreach (children_, cursor, child_name, child) { if (strcmp(child->name_, name) == 0) { - if (ret != nullptr){ + if (ret != nullptr) { THROWF (tracing_error, 0, "there are two children types with the same name?"); - }else{ + } else { ret = child; } } diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 066d77f3c5..a0b4a1adf0 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -15,27 +15,22 @@ simgrid::instr::Value::Value(const char* name, const char* color, simgrid::instr if (name == nullptr || father == nullptr){ THROWF (tracing_error, 0, "can't create a value with a nullptr name (or a nullptr father)"); } - this->ret_ = xbt_new0(Value, 1); - this->ret_->name_ = xbt_strdup(name); - this->ret_->father_ = father; - this->ret_->color_ = xbt_strdup(color); + this->name_ = xbt_strdup(name); + this->father_ = father; + this->color_ = xbt_strdup(color); - char str_id[INSTR_DEFAULT_STR_SIZE]; - snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id()); - this->ret_->id_ = xbt_strdup(str_id); + this->id_ = bprintf("%lld", instr_new_paje_id()); - xbt_dict_set(father->values_, name, ret_, nullptr); - XBT_DEBUG("new value %s, child of %s", ret_->name_, ret_->father_->name_); - LogEntityValue(this->ret_); + xbt_dict_set(father->values_, name, this, nullptr); + XBT_DEBUG("new value %s, child of %s", name_, father_->name_); + LogEntityValue(this); }; simgrid::instr::Value::~Value() { - /* FIXME: this should be cleanable - xbt_free(name); - xbt_free(color); - xbt_free(id); - */ + xbt_free(name_); + xbt_free(color_); + xbt_free(id_); } simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const char* color, @@ -46,8 +41,7 @@ simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const ret = Value::get(name, father); } catch(xbt_ex& e) { - Value rett(name, color, father); - ret = rett.ret_; + ret = new Value(name, color, father); } return ret; } diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index ea77f8bda7..f611d228d8 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -13,6 +13,7 @@ #include "simgrid_config.h" #include "src/internal_config.h" #include +#include /* Need to define function drand48 for Windows */ /* FIXME: use _drand48() defined in src/surf/random_mgr.c instead */ @@ -69,7 +70,10 @@ public: xbt_dict_t children_; xbt_dict_t values_; // valid for all types except variable and container Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind, Type* father); - static Type* getOrNull(const char* name, Type* father); + ~Type(); + Type* getChild(const char* name); + Type* getChildOrNull(const char* name); + static Type* containerNew(const char* name, Type* father); static Type* eventNew(const char* name, Type* father); static Type* variableNew(const char* name, const char* color, Type* father); @@ -85,7 +89,6 @@ public: char* color_; Type* father_; - Value* ret_; Value(const char* name, const char* color, Type* father); ~Value(); static Value* get_or_new(const char* name, const char* color, Type* father); @@ -217,21 +220,19 @@ public: }; class StartLinkEvent : public PajeEvent { - public: - Container* container; - Type* type; - Container* sourceContainer; - char* value; - char* key; - int size; + Container* container_; + Type* type_; + Container* sourceContainer_; + std::string value_; + std::string key_; + int size_; - public: - ~StartLinkEvent(); - StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value, - const char* key); - StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value, - const char* key, int size); - void print() override; +public: + StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value, + const char* key); + StartLinkEvent(double timestamp, Container* container, Type* type, Container* sourceContainer, const char* value, + const char* key, int size); + void print() override; }; class EndLinkEvent : public PajeEvent { @@ -326,24 +327,17 @@ XBT_PUBLIC(void) TRACE_surf_resource_utilization_alloc(); extern XBT_PRIVATE std::set trivaNodeTypes; extern XBT_PRIVATE std::set trivaEdgeTypes; XBT_PRIVATE long long int instr_new_paje_id (); -XBT_PRIVATE void PJ_container_alloc (); -XBT_PRIVATE void PJ_container_release (); XBT_PUBLIC(container_t) PJ_container_get (const char *name); -XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name); +XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name); XBT_PUBLIC(container_t) PJ_container_get_root (); XBT_PUBLIC(void) PJ_container_set_root (container_t root); XBT_PUBLIC(void) PJ_container_free_all (void); XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container); /* instr_paje_types.c */ -XBT_PRIVATE void PJ_type_release (); XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get_root(); -XBT_PUBLIC(simgrid::instr::Type*) PJ_type_get(const char* name, simgrid::instr::Type* father); -XBT_PRIVATE XBT_PRIVATE void PJ_type_free(simgrid::instr::Type* type); /* instr_config.c */ -XBT_PRIVATE void recursiveDestroyType(simgrid::instr::Type* type); - XBT_PRIVATE void TRACE_TI_start(); XBT_PRIVATE void TRACE_TI_end(); diff --git a/src/instr/instr_resource_utilization.cpp b/src/instr/instr_resource_utilization.cpp index bca73a0973..6b7bfec6fe 100644 --- a/src/instr/instr_resource_utilization.cpp +++ b/src/instr/instr_resource_utilization.cpp @@ -28,7 +28,7 @@ static void __TRACE_surf_check_variable_set_to_zero(double now, const char *vari // check if key exists: if it doesn't, set the variable to zero and mark this in the dict if (platform_variables.find(key) == platform_variables.end()) { container_t container = PJ_container_get (resource); - simgrid::instr::Type* type = PJ_type_get(variable, container->type_); + simgrid::instr::Type* type = container->type_->getChild(variable); new simgrid::instr::SetVariableEvent(now, container, type, 0); platform_variables[key] = std::string(""); } @@ -54,7 +54,7 @@ void TRACE_surf_link_set_utilization(const char *resource, const char *category, if (TRACE_uncategorized()){ XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value); container_t container = PJ_container_get (resource); - simgrid::instr::Type* type = PJ_type_get("bandwidth_used", container->type_); + simgrid::instr::Type* type = container->type_->getChild("bandwidth_used"); instr_event (now, delta, type, container, value); } @@ -67,7 +67,7 @@ void TRACE_surf_link_set_utilization(const char *resource, const char *category, snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", category); XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value); container_t container = PJ_container_get (resource); - simgrid::instr::Type* type = PJ_type_get(category_type, container->type_); + simgrid::instr::Type* type = container->type_->getChild(category_type); instr_event (now, delta, type, container, value); } } @@ -83,7 +83,7 @@ void TRACE_surf_host_set_utilization(const char *resource, const char *category, //trace uncategorized host utilization if (TRACE_uncategorized()){ XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value); - simgrid::instr::Type* type = PJ_type_get("power_used", container->type_); + simgrid::instr::Type* type = container->type_->getChild("power_used"); instr_event (now, delta, type, container, value); } @@ -95,7 +95,7 @@ void TRACE_surf_host_set_utilization(const char *resource, const char *category, char category_type[INSTR_DEFAULT_STR_SIZE]; snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", category); XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value); - simgrid::instr::Type* type = PJ_type_get(category_type, container->type_); + simgrid::instr::Type* type = container->type_->getChild(category_type); instr_event (now, delta, type, container, value); } } diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index 8102fb130e..c184df4a34 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -80,6 +80,13 @@ namespace context { void_pfn_smxprocess_t cleanup_func_ = nullptr; smx_actor_t process_ = nullptr; public: + class StopRequest { + /** @brief Exception launched to kill a process, in order to properly unwind its stack and release RAII stuff + * + * Nope, Sonar, this should not inherit of std::exception. + * Otherwise, users may accidentally catch it with a try {} catch (std::exception) + */ + }; bool iwannadie; Context(std::function code, @@ -156,12 +163,12 @@ XBT_PUBLIC_DATA(char sigsegv_stack[SIGSTKSZ]); /* We are using the bottom of the stack to save some information, like the * valgrind_stack_id. Define smx_context_usable_stack_size to give the remaining - * size for the stack. */ + * size for the stack. Round its value to a multiple of 16 (asan wants the stacks to be aligned this way). */ #if HAVE_VALGRIND_H -# define smx_context_usable_stack_size \ - (smx_context_stack_size - sizeof(unsigned int)) /* for valgrind_stack_id */ +#define smx_context_usable_stack_size \ + ((smx_context_stack_size - sizeof(unsigned int)) & ~0xf) /* for valgrind_stack_id */ #else -# define smx_context_usable_stack_size smx_context_stack_size +#define smx_context_usable_stack_size (smx_context_stack_size & ~0xf) #endif /** @brief Executes all the processes to run (in parallel if possible). */ diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index 3028445dd9..8e1eabd20d 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -18,6 +18,18 @@ #include "src/internal_config.h" #include "src/kernel/context/ContextBoost.hpp" +#if HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT +#include +#define ASAN_EVAL(expr) (expr) +#define ASAN_START_SWITCH(fake_stack_save, bottom, size) __sanitizer_start_switch_fiber(fake_stack_save, bottom, size) +#define ASAN_FINISH_SWITCH(fake_stack_save, bottom_old, size_old) \ + __sanitizer_finish_switch_fiber(fake_stack_save, bottom_old, size_old) +#else +#define ASAN_EVAL(expr) (void)0 +#define ASAN_START_SWITCH(fake_stack_save, bottom, size) (void)0 +#define ASAN_FINISH_SWITCH(fake_stack_save, bottom_old, size_old) (void)(fake_stack_save) +#endif + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); namespace simgrid { @@ -30,7 +42,6 @@ public: void_pfn_smxprocess_t cleanup_func, smx_actor_t process) : BoostContext(std::move(code), cleanup_func, process) {} - void stop() override; void suspend() override; }; @@ -41,7 +52,6 @@ public: void_pfn_smxprocess_t cleanup_func, smx_actor_t process) : BoostContext(std::move(code), cleanup_func, process) {} - void stop() override; void suspend() override; void resume() override; }; @@ -63,10 +73,9 @@ BoostContextFactory::BoostContextFactory() BoostContext::parallel_ = SIMIX_context_is_parallel(); if (BoostContext::parallel_) { #if HAVE_THREAD_CONTEXTS - int nthreads = SIMIX_context_get_nthreads(); - BoostContext::parmap_ = new simgrid::xbt::Parmap(nthreads, SIMIX_context_get_parallel_mode()); + BoostContext::parmap_ = nullptr; BoostContext::workers_context_.clear(); - BoostContext::workers_context_.resize(nthreads, nullptr); + BoostContext::workers_context_.resize(SIMIX_context_get_nthreads(), nullptr); BoostContext::maestro_context_ = nullptr; xbt_os_thread_key_create(&BoostContext::worker_id_key_); #else @@ -78,10 +87,8 @@ BoostContextFactory::BoostContextFactory() BoostContextFactory::~BoostContextFactory() { #if HAVE_THREAD_CONTEXTS - if (BoostContext::parmap_) { - delete BoostContext::parmap_; - BoostContext::parmap_ = nullptr; - } + delete BoostContext::parmap_; + BoostContext::parmap_ = nullptr; BoostContext::workers_context_.clear(); #endif } @@ -106,6 +113,9 @@ void BoostContextFactory::run_all() #if HAVE_THREAD_CONTEXTS if (BoostContext::parallel_) { BoostContext::threads_working_ = 0; + if (not BoostContext::parmap_) + BoostContext::parmap_ = + new simgrid::xbt::Parmap(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode()); BoostContext::parmap_->apply( [](smx_actor_t process) { BoostContext* context = static_cast(process->context); @@ -127,11 +137,41 @@ void BoostContextFactory::run_all() // BoostContext -static void smx_ctx_boost_wrapper(std::intptr_t arg) +void BoostContext::smx_ctx_boost_wrapper(BoostContext::ctx_arg_type arg) { - BoostContext* context = (BoostContext*)(arg); - (*context)(); - context->stop(); +#if BOOST_VERSION < 106100 + BoostContext* context = reinterpret_cast(arg); +#else + ASAN_FINISH_SWITCH(nullptr, &static_cast(arg.data)[0]->asan_stack_, + &static_cast(arg.data)[0]->asan_stack_size_); + static_cast(arg.data)[0]->fc_ = arg.fctx; + BoostContext* context = static_cast(arg.data)[1]; +#endif + try { + (*context)(); + context->Context::stop(); + } catch (StopRequest const&) { + XBT_DEBUG("Caught a StopRequest"); + } + ASAN_EVAL(context->asan_stop_ = true); + context->suspend(); +} + +inline void BoostContext::smx_ctx_boost_jump_fcontext(BoostContext* from, BoostContext* to) +{ +#if BOOST_VERSION < 105600 + boost::context::jump_fcontext(from->fc_, to->fc_, reinterpret_cast(to)); +#elif BOOST_VERSION < 106100 + boost::context::jump_fcontext(&from->fc_, to->fc_, reinterpret_cast(to)); +#else + BoostContext* ctx[2] = {from, to}; + void* fake_stack; + ASAN_START_SWITCH(from->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_); + boost::context::detail::transfer_t arg = boost::context::detail::jump_fcontext(to->fc_, ctx); + ASAN_FINISH_SWITCH(fake_stack, &static_cast(arg.data)[0]->asan_stack_, + &static_cast(arg.data)[0]->asan_stack_size_); + static_cast(arg.data)[0]->fc_ = arg.fctx; +#endif } BoostContext::BoostContext(std::function code, @@ -145,16 +185,18 @@ BoostContext::BoostContext(std::function code, // We need to pass the bottom of the stack to make_fcontext, depending on the stack direction it may be the lower // or higher address: #if PTH_STACKGROWTH == -1 - void* stack = static_cast(this->stack_) + smx_context_usable_stack_size - 1; + void* stack = static_cast(this->stack_) + smx_context_usable_stack_size; #else void* stack = this->stack_; #endif - this->fc_ = boost::context::make_fcontext( - stack, - smx_context_usable_stack_size, - smx_ctx_boost_wrapper); + ASAN_EVAL(this->asan_stack_ = stack); +#if BOOST_VERSION < 106100 + this->fc_ = boost::context::make_fcontext(stack, smx_context_usable_stack_size, smx_ctx_boost_wrapper); +#else + this->fc_ = boost::context::detail::make_fcontext(stack, smx_context_usable_stack_size, smx_ctx_boost_wrapper); +#endif } else { -#if HAVE_BOOST_CONTEXTS == 1 +#if BOOST_VERSION < 105600 this->fc_ = new boost::context::fcontext_t(); #endif if (BoostContext::maestro_context_ == nullptr) @@ -164,7 +206,7 @@ BoostContext::BoostContext(std::function code, BoostContext::~BoostContext() { -#if HAVE_BOOST_CONTEXTS == 1 +#if BOOST_VERSION < 105600 if (not this->stack_) delete this->fc_; #endif @@ -175,21 +217,23 @@ BoostContext::~BoostContext() // BoostSerialContext +void BoostContext::stop() +{ + Context::stop(); + throw StopRequest(); +} + void BoostContext::resume() { SIMIX_context_set_current(this); -#if HAVE_BOOST_CONTEXTS == 1 - boost::context::jump_fcontext(maestro_context_->fc_, this->fc_, (intptr_t) this); -#else - boost::context::jump_fcontext(&maestro_context_->fc_, this->fc_, (intptr_t) this); -#endif + smx_ctx_boost_jump_fcontext(maestro_context_, this); } void BoostSerialContext::suspend() { /* determine the next context */ - BoostSerialContext* next_context = nullptr; - unsigned long int i = process_index_; + BoostSerialContext* next_context; + unsigned long int i = process_index_; process_index_++; if (i < simix_global->process_to_run.size()) { @@ -201,18 +245,8 @@ void BoostSerialContext::suspend() XBT_DEBUG("No more process to run"); next_context = static_cast(maestro_context_); } - SIMIX_context_set_current((smx_context_t) next_context); -#if HAVE_BOOST_CONTEXTS == 1 - boost::context::jump_fcontext(this->fc_, next_context->fc_, (intptr_t) next_context); -#else - boost::context::jump_fcontext(&this->fc_, next_context->fc_, (intptr_t) next_context); -#endif -} - -void BoostSerialContext::stop() -{ - BoostContext::stop(); - this->suspend(); + SIMIX_context_set_current(static_cast(next_context)); + smx_ctx_boost_jump_fcontext(this, next_context); } // BoostParallelContext @@ -228,38 +262,24 @@ void BoostParallelContext::suspend() next_context = static_cast(next_work.get()->context); } else { XBT_DEBUG("No more processes to run"); - uintptr_t worker_id = (uintptr_t)xbt_os_thread_get_specific(worker_id_key_); + uintptr_t worker_id = reinterpret_cast(xbt_os_thread_get_specific(worker_id_key_)); next_context = static_cast(workers_context_[worker_id]); } - SIMIX_context_set_current(static_cast (next_context)); -#if HAVE_BOOST_CONTEXTS == 1 - boost::context::jump_fcontext(this->fc_, next_context->fc_, (intptr_t)(next_context)); -#else - boost::context::jump_fcontext(&this->fc_, next_context->fc_, (intptr_t)(next_context)); -#endif -} - -void BoostParallelContext::stop() -{ - BoostContext::stop(); - this->suspend(); + SIMIX_context_set_current(static_cast(next_context)); + smx_ctx_boost_jump_fcontext(this, next_context); } void BoostParallelContext::resume() { uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1); - xbt_os_thread_set_specific(worker_id_key_, (void*) worker_id); + xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast(worker_id)); BoostParallelContext* worker_context = static_cast(SIMIX_context_self()); workers_context_[worker_id] = worker_context; SIMIX_context_set_current(this); -#if HAVE_BOOST_CONTEXTS == 1 - boost::context::jump_fcontext(worker_context->fc_, this->fc_, (intptr_t) this); -#else - boost::context::jump_fcontext(&worker_context->fc_, this->fc_, (intptr_t) this); -#endif + smx_ctx_boost_jump_fcontext(worker_context, this); } #endif diff --git a/src/kernel/context/ContextBoost.hpp b/src/kernel/context/ContextBoost.hpp index e8a34c2229..0c31944bd3 100644 --- a/src/kernel/context/ContextBoost.hpp +++ b/src/kernel/context/ContextBoost.hpp @@ -6,6 +6,12 @@ #ifndef SIMGRID_SIMIX_BOOST_CONTEXT_HPP #define SIMGRID_SIMIX_BOOST_CONTEXT_HPP +#include +#if BOOST_VERSION < 106100 +#include +#else +#include +#endif #include #include @@ -34,11 +40,25 @@ protected: // static static unsigned long process_index_; static BoostContext* maestro_context_; -#if HAVE_BOOST_CONTEXTS == 1 +#if BOOST_VERSION < 105600 boost::context::fcontext_t* fc_ = nullptr; -#else + typedef intptr_t ctx_arg_type; +#elif BOOST_VERSION < 106100 boost::context::fcontext_t fc_; + typedef intptr_t ctx_arg_type; +#else + boost::context::detail::fcontext_t fc_; + typedef boost::context::detail::transfer_t ctx_arg_type; #endif + static void smx_ctx_boost_wrapper(ctx_arg_type); + static void smx_ctx_boost_jump_fcontext(BoostContext*, BoostContext*); + +#if HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT + const void* asan_stack_ = nullptr; + size_t asan_stack_size_ = 0; + bool asan_stop_ = false; +#endif + void* stack_ = nullptr; public: friend BoostContextFactory; @@ -46,6 +66,7 @@ public: void_pfn_smxprocess_t cleanup_func, smx_actor_t process); ~BoostContext() override; + void stop() override; virtual void resume(); private: static void wrapper(int first, ...); diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index 53726aa300..244fdd448a 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -291,8 +291,13 @@ RawContext* RawContextFactory::create_context(std::function code, void RawContext::wrapper(void* arg) { RawContext* context = static_cast(arg); - (*context)(); - context->stop(); + try { + (*context)(); + context->Context::stop(); + } catch (StopRequest const&) { + XBT_DEBUG("Caught a StopRequest"); + } + context->suspend(); } RawContext::RawContext(std::function code, @@ -323,7 +328,7 @@ RawContext::~RawContext() void RawContext::stop() { Context::stop(); - this->suspend(); + throw StopRequest(); } void RawContextFactory::run_all() diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 67a641879e..8e9ee722d6 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -151,9 +151,22 @@ void *ThreadContext::wrapper(void *param) if (smx_ctx_thread_sem) /* parallel run */ xbt_os_sem_acquire(smx_ctx_thread_sem); - (*context)(); - context->stop(); + try { + (*context)(); + context->Context::stop(); + } catch (StopRequest const&) { + XBT_DEBUG("Caught a StopRequest"); + } + + if (smx_ctx_thread_sem) + xbt_os_sem_release(smx_ctx_thread_sem); + // Signal to the maestro that it has finished: + xbt_os_sem_release(context->end_); +#ifndef WIN32 + stack.ss_flags = SS_DISABLE; + sigaltstack(&stack, nullptr); +#endif return nullptr; } @@ -179,6 +192,10 @@ void *ThreadContext::maestro_wrapper(void *param) // Tell main that we have finished: xbt_os_sem_release(context->end_); +#ifndef WIN32 + stack.ss_flags = SS_DISABLE; + sigaltstack(&stack, nullptr); +#endif return nullptr; } @@ -192,13 +209,7 @@ void ThreadContext::start() void ThreadContext::stop() { Context::stop(); - if (smx_ctx_thread_sem) - xbt_os_sem_release(smx_ctx_thread_sem); - - // Signal to the maestro that it has finished: - xbt_os_sem_release(this->end_); - - xbt_os_thread_exit(nullptr); + throw StopRequest(); } void ThreadContext::suspend() diff --git a/src/kernel/context/ContextThread.hpp b/src/kernel/context/ContextThread.hpp index 096a01ccd3..3449f88a59 100644 --- a/src/kernel/context/ContextThread.hpp +++ b/src/kernel/context/ContextThread.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2015. The SimGrid Team. +/* Copyright (c) 2009-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index ec26e437ce..0ee4c14a1c 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -81,6 +81,7 @@ public: UContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process); ~UContext() override; + void stop() override; }; class SerialUContext : public UContext { @@ -89,7 +90,6 @@ public: void_pfn_smxprocess_t cleanup_func, smx_actor_t process) : UContext(std::move(code), cleanup_func, process) {} - void stop() override; void suspend() override; void resume(); }; @@ -100,7 +100,6 @@ public: void_pfn_smxprocess_t cleanup_func, smx_actor_t process) : UContext(std::move(code), cleanup_func, process) {} - void stop() override; void suspend() override; void resume(); }; @@ -230,6 +229,11 @@ UContext::~UContext() SIMIX_context_stack_delete(this->stack_); } +void UContext::stop() +{ + Context::stop(); + throw StopRequest(); +} }}} // namespace simgrid::kernel::context static void smx_ctx_sysv_wrapper(int first, ...) @@ -247,20 +251,19 @@ static void smx_ctx_sysv_wrapper(int first, ...) } memcpy(&context, ctx_addr, sizeof(simgrid::kernel::context::UContext*)); - (*context)(); - context->stop(); + try { + (*context)(); + context->Context::stop(); + } catch (simgrid::kernel::context::Context::StopRequest const&) { + XBT_DEBUG("Caught a StopRequest"); + } + context->suspend(); } namespace simgrid { namespace kernel { namespace context { -void SerialUContext::stop() -{ - Context::stop(); - this->suspend(); -} - void SerialUContext::suspend() { /* determine the next context */ @@ -288,12 +291,6 @@ void SerialUContext::resume() swapcontext(&static_cast(sysv_maestro_context)->uc_, &this->uc_); } -void ParallelUContext::stop() -{ - UContext::stop(); - this->suspend(); -} - /** Run one particular simulated process on the current thread. */ void ParallelUContext::resume() { diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index a82fa8f8bc..8de1553f8c 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -147,7 +147,7 @@ void ModelChecker::shutdown() simgrid::mc::RemoteClient* process = &this->process(); if (process->running()) { XBT_DEBUG("Killing process"); - kill(process->pid(), SIGTERM); + kill(process->pid(), SIGKILL); process->terminate(); } } diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index 810351b139..ce79e7c120 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -140,7 +140,7 @@ Session* Session::fork(std::function code) // process: int res; int sockets[2]; - res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets); + res = socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets); if (res == -1) throw simgrid::xbt::errno_error("Could not create socketpair"); diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index 6e9bd0913f..1b405a1e89 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -522,7 +522,7 @@ void CommunicationDeterminismChecker::main() /* Check for deadlocks */ if (mc_model_checker->checkDeadlock()) { MC_show_deadlock(); - throw new simgrid::mc::DeadlockError(); + throw simgrid::mc::DeadlockError(); } while (not stack_.empty()) { diff --git a/src/mc/compare.cpp b/src/mc/compare.cpp index 2a1ddae3d0..90ecfb2f0a 100644 --- a/src/mc/compare.cpp +++ b/src/mc/compare.cpp @@ -102,10 +102,8 @@ struct HeapArea : public HeapLocation { int block = 0; int fragment = 0; HeapArea() {} - HeapArea(int block) - : valid(true), block(block) {} - HeapArea(int block, int fragment = 0) - : valid(true), block(block), fragment(fragment) {} + explicit HeapArea(int block) : valid(true), block(block) {} + HeapArea(int block, int fragment) : valid(true), block(block), fragment(fragment) {} }; struct ProcessComparisonState { @@ -331,7 +329,6 @@ int mmalloc_compare_heap( int nb_diff1 = 0; int nb_diff2 = 0; int equal; - int res_compare = 0; /* Check busy blocks */ i1 = 1; @@ -387,14 +384,13 @@ int mmalloc_compare_heap( i2 = 1; equal = 0; - res_compare = 0; /* Try first to associate to same block in the other heap */ if (heapinfo2->type == heapinfo1->type && state.equals_to2_(i1, 0).valid == 0) { addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, snapshot1, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { for (k = 1; k < heapinfo2->busy_block.size; k++) state.equals_to2_(i1 + k, 0) = HeapArea(i1, -1); @@ -426,9 +422,8 @@ int mmalloc_compare_heap( continue; } - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, - addr_block1, addr_block2, snapshot1, snapshot2, - nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_block1, addr_block2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { for (k = 1; k < heapinfo2b->busy_block.size; k++) @@ -471,8 +466,8 @@ int mmalloc_compare_heap( addr_frag2 = (void *) ((char *) addr_block2 + (j1 << heapinfo2->type)); - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot1, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, + snapshot1, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) equal = 1; } @@ -511,8 +506,8 @@ int mmalloc_compare_heap( addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; addr_frag2 = (void*)((char*)addr_block2 + (j2 << heapinfo2b->type)); - res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, snapshot2, - snapshot2, nullptr, nullptr, 0); + int res_compare = compare_heap_area(state, simgrid::mc::ProcessIndexMissing, addr_frag1, addr_frag2, + snapshot2, snapshot2, nullptr, nullptr, 0); if (res_compare != 1) { equal = 1; break; @@ -525,7 +520,6 @@ int mmalloc_compare_heap( if (not equal) { XBT_DEBUG("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n", i1, j1, heapinfo1->busy_frag.frag_size[j1], addr_frag1); - i2 = state.heaplimit + 1; i1 = state.heaplimit + 1; nb_diff1++; break; @@ -967,18 +961,11 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, { simgrid::mc::RemoteClient* process = &mc_model_checker->process(); - int res_compare; ssize_t block1; - ssize_t frag1; ssize_t block2; - ssize_t frag2; ssize_t size; int check_ignore = 0; - void* real_addr_block1; - void* real_addr_block2; - void* real_addr_frag1; - void* real_addr_frag2; int type_size = -1; int offset1 = 0; int offset2 = 0; @@ -1024,8 +1011,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, } // Process address of the block: - real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; - real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; + void* real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; + void* real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase; if (type) { if (type->full_type) @@ -1065,9 +1052,6 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, // TODO, lookup variable type from block type as done for fragmented blocks - offset1 = (char*)area1 - (char*)real_addr_block1; - offset2 = (char*)area2 - (char*)real_addr_block2; - if (state.equals_to1_(block1, 0).valid && state.equals_to2_(block2, 0).valid && state.blocksEqual(block1, block2)) { if (match_pairs) state.match_equals(previous); @@ -1110,9 +1094,6 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, return 0; } - frag1 = -1; - frag2 = -1; - if (heapinfo1->busy_block.ignore > 0 && heapinfo2->busy_block.ignore == heapinfo1->busy_block.ignore) check_ignore = heapinfo1->busy_block.ignore; @@ -1120,12 +1101,12 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, } else if ((heapinfo1->type > 0) && (heapinfo2->type > 0)) { /* Fragmented block */ // Fragment number: - frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type; - frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type; + ssize_t frag1 = ((uintptr_t)(ADDR2UINT(area1) % (BLOCKSIZE))) >> heapinfo1->type; + ssize_t frag2 = ((uintptr_t)(ADDR2UINT(area2) % (BLOCKSIZE))) >> heapinfo2->type; // Process address of the fragment: - real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type)); - real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type)); + void* real_addr_frag1 = (void*)((char*)real_addr_block1 + (frag1 << heapinfo1->type)); + void* real_addr_frag2 = (void*)((char*)real_addr_block2 + (frag2 << heapinfo2->type)); // Check the size of the fragments against the size of the type: if (type_size != -1) { @@ -1173,8 +1154,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, // The type of the variable is already known: if (type) { - new_type1 = type; - new_type2 = type; + new_type1 = new_type2 = type; } // Type inference from the block type. else if (state.types1_(block1, frag1) != nullptr || state.types2_(block2, frag2) != nullptr) { @@ -1249,6 +1229,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, /* Start comparison */ + int res_compare; if (type) res_compare = compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2, previous, type, size, check_ignore, pointer_level); diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 3e022306ee..f2b9548a60 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -97,14 +97,9 @@ bool actor_is_enabled(smx_actor_t actor) } case SIMCALL_COMM_WAITANY: { - xbt_dynar_t comms; - simgrid::kernel::activity::CommImpl* act = - static_cast(simcall_comm_wait__getraw__comm(req)); - - comms = simcall_comm_waitany__get__comms(req); - + xbt_dynar_t comms = simcall_comm_waitany__get__comms(req); for (unsigned int index = 0; index < comms->used; ++index) { - act = xbt_dynar_get_as(comms, index, simgrid::kernel::activity::CommImpl*); + simgrid::kernel::activity::CommImpl* act = xbt_dynar_get_as(comms, index, simgrid::kernel::activity::CommImpl*); if (act->src_proc && act->dst_proc) return true; } diff --git a/src/mc/remote/Channel.hpp b/src/mc/remote/Channel.hpp index c3fb006ad4..c9de6d6ac9 100644 --- a/src/mc/remote/Channel.hpp +++ b/src/mc/remote/Channel.hpp @@ -19,7 +19,7 @@ namespace mc { /** A channel for exchanging messages between model-checker and model-checked * * This abstracts away the way the messages are transferred. Currently, they - * are sent over a (connected) `SOCK_DGRAM` socket. + * are sent over a (connected) `SOCK_SEQPACKET` socket. */ class Channel { int socket_ = -1; diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index 20b9c2dcbb..93f0bc0cf1 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -61,7 +61,7 @@ Client* Client::initialize() socklen_t socklen = sizeof(type); if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) != 0) xbt_die("Could not check socket type"); - if (type != SOCK_DGRAM) + if (type != SOCK_SEQPACKET) xbt_die("Unexpected socket type %i", type); XBT_DEBUG("Model-checked application found expected socket type"); diff --git a/src/mc/remote/mc_protocol.h b/src/mc/remote/mc_protocol.h index bac7981555..8a2a089d9a 100644 --- a/src/mc/remote/mc_protocol.h +++ b/src/mc/remote/mc_protocol.h @@ -51,7 +51,7 @@ typedef enum { /** Basic structure for a MC message * * The current version of the client/server protocol sends C structures over `AF_LOCAL` - * `SOCK_DGRAM` sockets. This means that the protocol is ABI/architecture specific: + * `SOCK_SEQPACKET` sockets. This means that the protocol is ABI/architecture specific: * we currently can't model-check a x86 process from a x86_64 process. * * Moreover the protocol is not stable. The same version of the library should be used diff --git a/src/msg/instr_msg_process.cpp b/src/msg/instr_msg_process.cpp index af391fb2d6..a3a69f9d24 100644 --- a/src/msg/instr_msg_process.cpp +++ b/src/msg/instr_msg_process.cpp @@ -37,7 +37,7 @@ void TRACE_msg_process_change_host(msg_process_t process, msg_host_t new_host) //start link container_t msg = PJ_container_get (instr_process_id(process, str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_LINK", PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild("MSG_PROCESS_LINK"); new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key); //destroy existing container of this process @@ -48,7 +48,7 @@ void TRACE_msg_process_change_host(msg_process_t process, msg_host_t new_host) //end link msg = PJ_container_get(instr_process_id(process, str, len)); - type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root()); + type = PJ_type_get_root()->getChild("MSG_PROCESS_LINK"); new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key); } } @@ -94,7 +94,7 @@ void TRACE_msg_process_suspend(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(process, str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get("suspend", type); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); } @@ -107,7 +107,7 @@ void TRACE_msg_process_resume(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(process, str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); } } @@ -119,7 +119,7 @@ void TRACE_msg_process_sleep_in(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(process, str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get("sleep", type); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); } @@ -132,7 +132,7 @@ void TRACE_msg_process_sleep_out(msg_process_t process) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(process, str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); } } diff --git a/src/msg/instr_msg_task.cpp b/src/msg/instr_msg_task.cpp index 8b35b94e3d..49f94db619 100644 --- a/src/msg/instr_msg_task.cpp +++ b/src/msg/instr_msg_task.cpp @@ -53,7 +53,7 @@ void TRACE_msg_task_execute_start(msg_task_t task) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get("task_execute", type); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); } @@ -68,7 +68,7 @@ void TRACE_msg_task_execute_end(msg_task_t task) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); } } @@ -93,7 +93,7 @@ void TRACE_msg_task_get_start() char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get("receive", type); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); } @@ -108,12 +108,12 @@ void TRACE_msg_task_get_end(double start_time, msg_task_t task) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); char key[INSTR_DEFAULT_STR_SIZE]; snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter); - type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root()); + type = PJ_type_get_root()->getChild("MSG_PROCESS_TASK_LINK"); new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key); } } @@ -128,13 +128,13 @@ int TRACE_msg_task_put_start(msg_task_t task) char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get("send", type); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); char key[INSTR_DEFAULT_STR_SIZE]; snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter); - type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root()); + type = PJ_type_get_root()->getChild("MSG_PROCESS_TASK_LINK"); new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key); } @@ -150,7 +150,7 @@ void TRACE_msg_task_put_end() char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); - simgrid::instr::Type* type = PJ_type_get("MSG_PROCESS_STATE", process_container->type_); + simgrid::instr::Type* type = process_container->type_->getChild("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); } } diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index be46babecb..c385ac7087 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -187,7 +187,7 @@ void MSG_vm_start(msg_vm_t vm) vm->start(); if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->getCname()); - simgrid::instr::Type* type = PJ_type_get("MSG_VM_STATE", vm_container->type_); + simgrid::instr::Type* type = vm_container->type_->getChild("MSG_VM_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("start", "0 0 1", type); // start is blue new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, type, val); } @@ -296,7 +296,7 @@ static int migration_rx_fun(int argc, char *argv[]) // start link container_t msg = PJ_container_get(vm->getCname()); - simgrid::instr::Type* type = PJ_type_get("MSG_VM_LINK", PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild("MSG_VM_LINK"); new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key); // destroy existing container of this vm @@ -310,7 +310,7 @@ static int migration_rx_fun(int argc, char *argv[]) // end link msg = PJ_container_get(vm->getCname()); - type = PJ_type_get("MSG_VM_LINK", PJ_type_get_root()); + type = PJ_type_get_root()->getChild("MSG_VM_LINK"); new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key); } @@ -775,7 +775,7 @@ void MSG_vm_suspend(msg_vm_t vm) if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->getCname()); - simgrid::instr::Type* type = PJ_type_get("MSG_VM_STATE", vm_container->type_); + simgrid::instr::Type* type = vm_container->type_->getChild("MSG_VM_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("suspend", "1 0 0", type); // suspend is red new simgrid::instr::PushStateEvent(MSG_get_clock(), vm_container, type, val); } @@ -792,7 +792,7 @@ void MSG_vm_resume(msg_vm_t vm) if (TRACE_msg_vm_is_enabled()) { container_t vm_container = PJ_container_get(vm->getCname()); - simgrid::instr::Type* type = PJ_type_get("MSG_VM_STATE", vm_container->type_); + simgrid::instr::Type* type = vm_container->type_->getChild("MSG_VM_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), vm_container, type); } } diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index ea9a040ef7..b60dfc3e1d 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -44,6 +44,23 @@ std::deque VirtualMachineImpl::allVms_; // const double virt_overhead = 0.95; const double virt_overhead = 1; +static void hostStateChange(s4u::Host& host) +{ + if (host.isOff()) { // just turned off. + std::vector trash; + /* Find all VMs living on that host */ + for (s4u::VirtualMachine* const& vm : VirtualMachineImpl::allVms_) + if (vm->getPm() == &host) + trash.push_back(vm); + for (s4u::VirtualMachine* vm : trash) + vm->pimpl_vm_->shutdown(SIMIX_process_self()); + } +} +VMModel::VMModel() +{ + s4u::Host::onStateChange.connect(hostStateChange); +} + double VMModel::nextOccuringEvent(double now) { /* TODO: update action's cost with the total cost of processes on the VM. */ @@ -224,7 +241,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) THROW_IMPOSSIBLE; break; } - XBT_VERB("Shuting down the VM %s even if it's not running but %s", piface_->getCname(), stateName); + XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName); } xbt_swag_t process_list = piface_->extension()->process_list; @@ -233,7 +250,8 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) smx_actor_t smx_process; smx_actor_t smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { - XBT_DEBUG("kill %s", smx_process->cname()); + XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process->cname(), smx_process->host->getCname(), + issuer->cname()); SIMIX_process_kill(smx_process, issuer); } diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 1063bf1ff8..79c3affb1d 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -121,6 +121,7 @@ protected: */ class VMModel : public surf::HostModel { public: + VMModel(); void ignoreEmptyVmInPmLMM() override{}; double nextOccuringEvent(double now) override; diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 2bb3ab15d5..763fe9841c 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -255,5 +255,14 @@ std::unordered_map const& Host::getMountedStorages() return *mounts; } +void Host::execute(double flops) +{ + Host* host_list[1] = {this}; + double flops_list[1] = {flops}; + smx_activity_t s = simcall_execution_parallel_start(nullptr /*name*/, 1, host_list, flops_list, + nullptr /*comm_sizes */, -1.0, -1 /*timeout*/); + simcall_execution_wait(s); +} + } // namespace simgrid } // namespace s4u diff --git a/src/simdag/sd_dotloader.cpp b/src/simdag/sd_dotloader.cpp index 663dcb0466..8e3f73676e 100644 --- a/src/simdag/sd_dotloader.cpp +++ b/src/simdag/sd_dotloader.cpp @@ -212,7 +212,7 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched if(schedule){ if (schedule_success) { - const sg_host_t *workstations = sg_host_list (); + sg_host_t* workstations = sg_host_list(); for (auto const& elm : computers) { SD_task_t previous_task = nullptr; for (auto const& task : *elm.second) { @@ -227,6 +227,7 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched } delete elm.second; } + xbt_free(workstations); } else { XBT_WARN("The scheduling is ignored"); for (auto const& elm : computers) diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 930d90e43e..49d14cbada 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -73,8 +73,10 @@ void SIMIX_process_cleanup(smx_actor_t process) SIMIX_process_on_exit_runall(process); /* Unregister from the kill timer if any */ - if (process->kill_timer != nullptr) + if (process->kill_timer != nullptr) { SIMIX_timer_remove(process->kill_timer); + process->kill_timer = nullptr; + } xbt_os_mutex_acquire(simix_global->mutex); @@ -185,7 +187,7 @@ simgrid::s4u::Actor* ActorImpl::restart() // start the new process ActorImpl* actor = simix_global->create_process_function(arg.name.c_str(), std::move(arg.code), arg.data, arg.host, - arg.properties, nullptr); + arg.properties.get(), nullptr); if (arg.kill_time >= 0) simcall_process_set_kill_time(actor, arg.kill_time); if (arg.auto_restart) @@ -428,16 +430,10 @@ void SIMIX_process_detach() if (not context) xbt_die("Not a suitable context"); - simix_global->cleanup_process_function(context->process()); - - // Let maestro ignore we are still alive: - // xbt_swag_remove(context->process(), simix_global->process_list); - - // TODO, Remove from proces list: - // xbt_swag_remove(process, sg_host_simix(host)->process_list); - + auto process = context->process(); + simix_global->cleanup_process_function(process); context->attach_stop(); - // delete context; + delete process; } /** @@ -510,13 +506,6 @@ void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) { xbt_die("Unknown type of activity"); } - /* - switch (process->waiting_synchro->type) { - case SIMIX_SYNC_JOIN: - SIMIX_process_sleep_destroy(process->waiting_synchro); - break; - } */ - process->waiting_synchro = nullptr; } if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), process) == @@ -598,10 +587,6 @@ void SIMIX_process_killall(smx_actor_t issuer, int reset_pid) if (reset_pid > 0) simix_process_maxpid = reset_pid; - - SIMIX_context_runall(); - - SIMIX_process_empty_trash(); } void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest) @@ -683,49 +668,19 @@ void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, do simcall->issuer->waiting_synchro = sync; } -static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* synchro) -{ - simgrid::kernel::activity::SleepImpl* sleep = static_cast(synchro); - - if (sleep->surf_sleep) { - sleep->surf_sleep->cancel(); - - while (not sleep->simcalls.empty()) { - smx_simcall_t simcall = sleep->simcalls.front(); - sleep->simcalls.pop_front(); - simcall_process_sleep__set__result(simcall, SIMIX_DONE); - simcall->issuer->waiting_synchro = nullptr; - if (simcall->issuer->suspended) { - XBT_DEBUG("Wait! This process is suspended and can't wake up now."); - simcall->issuer->suspended = 0; - simcall_HANDLER_process_suspend(simcall, simcall->issuer); - } else { - SIMIX_simcall_answer(simcall); - } - } - sleep->surf_sleep->unref(); - sleep->surf_sleep = nullptr; - } - // intrusive_ptr_release(process); // FIXME: We are leaking here. See comment in SIMIX_process_join() - return 0; -} - smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout) { smx_activity_t res = issuer->sleep(timeout); intrusive_ptr_add_ref(res.get()); - /* We are leaking the process here, but if we don't take the ref, we get a "use after free". - * The correct solution would be to derivate the type SynchroSleep into a SynchroProcessJoin, - * but the code is not clean enough for now for this. - * The C API should first be properly replaced with the C++ one, which is a fair amount of work. - */ - intrusive_ptr_add_ref(process); SIMIX_process_on_exit(process, [](void*, void* arg) { - return simgrid::simix::kernelImmediate( - [&] { return SIMIX_process_join_finish(SMX_EXIT_SUCCESS, arg); }); + auto sleep = static_cast(arg); + if (sleep->surf_sleep) + sleep->surf_sleep->finish(simgrid::surf::Action::State::done); + intrusive_ptr_release(sleep); + return 0; }, - &*res); + res.get()); return res; } @@ -834,8 +789,8 @@ void SIMIX_process_on_exit_runall(smx_actor_t process) { smx_process_exit_status_t exit_status = (process->context->iwannadie) ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS; while (not process->on_exit.empty()) { s_smx_process_exit_fun_t exit_fun = process->on_exit.back(); - (exit_fun.fun)((void*)exit_status, exit_fun.arg); process->on_exit.pop_back(); + (exit_fun.fun)((void*)exit_status, exit_fun.arg); } } diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 3d7285f148..dcdea7a9d1 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -29,7 +29,7 @@ public: void *data = nullptr; sg_host_t host = nullptr; double kill_time = 0.0; - std::map* properties = nullptr; + std::shared_ptr> properties; bool auto_restart = false; }; diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 5906e9d9d1..e3991634b7 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -79,9 +79,9 @@ static simgrid::config::Flag context_factory_name( (std::string("Possible values: ")+contexts_list()).c_str(), context_factories[0].first); -int smx_context_stack_size; +unsigned smx_context_stack_size; int smx_context_stack_size_was_set = 0; -int smx_context_guard_size; +unsigned smx_context_guard_size; int smx_context_guard_size_was_set = 0; #if HAVE_THREAD_LOCAL_STORAGE static XBT_THREAD_LOCAL smx_context_t smx_current_context_parallel; diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index dd8daa8d6f..61469fb447 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -86,7 +86,7 @@ static void segvhandler(int signum, siginfo_t *siginfo, void *context) fprintf(stderr, "Access violation detected.\n" "This probably comes from a programming error in your code, or from a stack\n" "overflow. If you are certain of your code, try increasing the stack size\n" - " --cfg=contexts/stack-size=XXX (current size is %d KiB).\n" + " --cfg=contexts/stack-size=XXX (current size is %u KiB).\n" "\n" "If it does not help, this may have one of the following causes:\n" "a bug in SimGrid, a bug in the OS or a bug in a third-party libraries.\n" @@ -286,6 +286,8 @@ void SIMIX_clean() } /* Kill all processes (but maestro) */ SIMIX_process_killall(simix_global->maestro_process, 1); + SIMIX_context_runall(); + SIMIX_process_empty_trash(); /* Exit the SIMIX network module */ SIMIX_mailbox_exit(); @@ -502,7 +504,7 @@ void SIMIX_run() } time = SIMIX_timer_next(); - if (time > -1.0 || simix_global->process_list.empty() == false) { + if (time > -1.0 || not simix_global->process_list.empty()) { XBT_DEBUG("Calling surf_solve"); time = surf_solve(time); XBT_DEBUG("Moving time ahead : %g", time); @@ -539,7 +541,7 @@ void SIMIX_run() } while (time > -1.0 || not simix_global->process_to_run.empty()); - if (simix_global->process_list.size() != 0) { + if (not simix_global->process_list.empty()) { TRACE_end(); @@ -575,7 +577,7 @@ smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task callback) /** @brief cancels a timer that was added earlier */ void SIMIX_timer_remove(smx_timer_t timer) { - xbt_heap_rm_elm(simix_timers, timer, timer->getDate()); + delete static_cast(xbt_heap_rm_elm(simix_timers, timer, timer->getDate())); } /** @brief Returns the date at which the timer will trigger (or 0 if nullptr timer) */ diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index d89dd0da79..86985418e0 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -28,7 +28,7 @@ namespace simgrid { Host::~Host() { - /* Clean Simulator data */ + /* All processes should be gone when the host is turned off (by the end of the simulation). */ if (xbt_swag_size(process_list) != 0) { std::string msg = std::string("Shutting down host, but it's not empty:"); smx_actor_t process = nullptr; @@ -56,7 +56,7 @@ namespace simgrid { for (auto const& arg : boot_processes) { XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->getCname()); smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, - arg->properties, nullptr); + arg->properties.get(), nullptr); if (arg->kill_time >= 0) simcall_process_set_kill_time(actor, arg->kill_time); if (arg->auto_restart) @@ -81,7 +81,8 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer) smx_actor_t process = nullptr; xbt_swag_foreach(process, host->process_list) { SIMIX_process_kill(process, issuer); - XBT_DEBUG("Killing %s@%s on behalf of %s", process->cname(), process->host->getCname(), issuer->cname()); + XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process->cname(), + process->host->getCname(), issuer->cname()); } } } else { @@ -122,7 +123,7 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std:: arg->data = data; arg->host = host; arg->kill_time = kill_time; - arg->properties = properties; + arg->properties.reset(properties, [](decltype(properties)) {}); arg->auto_restart = auto_restart; if (host->isOff() && watched_hosts.find(host->getCname()) == watched_hosts.end()) { @@ -140,7 +141,7 @@ void SIMIX_host_autorestart(sg_host_t host) for (auto const& arg : process_list) { XBT_DEBUG("Restarting Process %s@%s right now", arg->name.c_str(), arg->host->getCname()); smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, - arg->properties, nullptr); + arg->properties.get(), nullptr); if (arg->kill_time >= 0) simcall_process_set_kill_time(actor, arg->kill_time); if (arg->auto_restart) diff --git a/src/smpi/colls/smpi_automatic_selector.cpp b/src/smpi/colls/smpi_automatic_selector.cpp index df6832b729..b6b3693767 100644 --- a/src/smpi/colls/smpi_automatic_selector.cpp +++ b/src/smpi/colls/smpi_automatic_selector.cpp @@ -16,7 +16,7 @@ #define TRACE_AUTO_COLL(cat) \ if (TRACE_is_enabled()) { \ - simgrid::instr::Type* type = simgrid::instr::Type::getOrNull(#cat, PJ_type_get_root()); \ + simgrid::instr::Type* type = PJ_type_get_root()->getChildOrNull(#cat); \ if (not type) { \ type = simgrid::instr::Type::eventNew(#cat, PJ_type_get_root()); \ } \ diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 288a8e3267..69ffcb27b3 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -236,7 +236,7 @@ void TRACE_smpi_collective_in(int rank, const char *operation, instr_extra_data char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); const char *color = instr_find_color (operation); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(operation, color, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); @@ -250,7 +250,7 @@ void TRACE_smpi_collective_out(int rank, const char *operation) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); new simgrid::instr::PopStateEvent(SIMIX_get_clock(), container, type); } @@ -264,7 +264,7 @@ void TRACE_smpi_computing_init(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get(str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); const char* color = instr_find_color("computing"); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, simgrid::instr::Value::get_or_new("computing", color, type)); @@ -281,7 +281,7 @@ void TRACE_smpi_computing_in(int rank, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("computing", nullptr, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); } @@ -293,7 +293,7 @@ void TRACE_smpi_computing_out(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); new simgrid::instr::PopStateEvent(SIMIX_get_clock(), container, type); } @@ -306,7 +306,7 @@ void TRACE_smpi_sleeping_init(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); const char *color = instr_find_color ("sleeping"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("sleeping", color, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val); @@ -323,7 +323,7 @@ void TRACE_smpi_sleeping_in(int rank, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("sleeping", nullptr, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); } @@ -335,7 +335,7 @@ void TRACE_smpi_sleeping_out(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); new simgrid::instr::PopStateEvent(SIMIX_get_clock(), container, type); } @@ -350,7 +350,7 @@ void TRACE_smpi_testing_in(int rank, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new("test", nullptr, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); } @@ -362,7 +362,7 @@ void TRACE_smpi_testing_out(int rank) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); new simgrid::instr::PopStateEvent(SIMIX_get_clock(), container, type); } @@ -376,7 +376,7 @@ void TRACE_smpi_ptp_in(int rank, const char *operation, instr_extra_data extra) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); const char *color = instr_find_color (operation); simgrid::instr::Value* val = simgrid::instr::Value::get_or_new(operation, color, type); new simgrid::instr::PushStateEvent(SIMIX_get_clock(), container, type, val, static_cast(extra)); @@ -390,7 +390,7 @@ void TRACE_smpi_ptp_out(int rank, int dst, const char *operation) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_STATE", container->type_); + simgrid::instr::Type* type = container->type_->getChild("MPI_STATE"); new simgrid::instr::PopStateEvent(SIMIX_get_clock(), container, type); } @@ -406,7 +406,7 @@ void TRACE_smpi_send(int rank, int src, int dst, int tag, int size) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(src, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_LINK", PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild("MPI_LINK"); XBT_DEBUG("Send tracing from %d to %d, tag %d, with key %s", src, dst, tag, key); new simgrid::instr::StartLinkEvent(SIMIX_get_clock(), PJ_container_get_root(), type, container, "PTP", key, size); } @@ -422,7 +422,7 @@ void TRACE_smpi_recv(int src, int dst, int tag) char str[INSTR_DEFAULT_STR_SIZE]; smpi_container(dst, str, INSTR_DEFAULT_STR_SIZE); container_t container = PJ_container_get (str); - simgrid::instr::Type* type = PJ_type_get("MPI_LINK", PJ_type_get_root()); + simgrid::instr::Type* type = PJ_type_get_root()->getChild("MPI_LINK"); XBT_DEBUG("Recv tracing from %d to %d, tag %d, with key %s", src, dst, tag, key); new simgrid::instr::EndLinkEvent(SIMIX_get_clock(), PJ_container_get_root(), type, container, "PTP", key); } diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 107430771d..5b05ac59db 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -264,7 +264,18 @@ unsigned long long smpi_rastro_timestamp () } /* ****************************** Functions related to the SMPI_SAMPLE_ macros ************************************/ -typedef struct { +namespace { +class SampleLocation : public std::string { +public: + SampleLocation(bool global, const char* file, int line) : std::string(std::string(file) + ":" + std::to_string(line)) + { + if (not global) + this->append(":" + std::to_string(smpi_process()->index())); + } +}; + +class LocalData { +public: double threshold; /* maximal stderr requested (if positive) */ double relstderr; /* observed stderr so far */ double mean; /* mean of benched times, to be used if the block is disabled */ @@ -272,94 +283,85 @@ typedef struct { double sum_pow2; /* sum of the square of the benched times (to compute the stderr) */ int iters; /* amount of requested iterations */ int count; /* amount of iterations done so far */ - int benching; /* 1: we are benchmarking; 0: we have enough data, no bench anymore */ -} local_data_t; - -std::unordered_map samples; /* Allocated on first use */ + bool benching; /* true: we are benchmarking; false: we have enough data, no bench anymore */ -static std::string sample_location(int global, const char* file, int line) -{ - if (global) { - return std::string(file) + ":" + std::to_string(line); - } else { - return std::string(file) + ":" + std::to_string(line) + ":" + std::to_string(smpi_process()->index()); - } + bool need_more_benchs() const; +}; } -static int sample_enough_benchs(local_data_t *data) { - int res = data->count >= data->iters; - if (data->threshold>0.0) { - if (data->count <2) - res = 0; // not enough data - if (data->relstderr > data->threshold) - res = 0; // stderr too high yet - } +std::unordered_map> samples; + +bool LocalData::need_more_benchs() const +{ + bool res = (count < iters) || (threshold > 0.0 && (count < 2 || // not enough data + relstderr > threshold // stderr too high yet + )); XBT_DEBUG("%s (count:%d iter:%d stderr:%f thres:%f mean:%fs)", - (res?"enough benchs":"need more data"), data->count, data->iters, data->relstderr, data->threshold, data->mean); + (res ? "need more data" : "enough benchs"), count, iters, relstderr, threshold, mean); return res; } void smpi_sample_1(int global, const char *file, int line, int iters, double threshold) { - std::string loc = sample_location(global, file, line); + SampleLocation loc(global, file, line); smpi_bench_end(); /* Take time from previous, unrelated computation into account */ smpi_process()->set_sampling(1); - auto ld = samples.find(loc); - local_data_t* data; - if (ld == samples.end()) { - xbt_assert(threshold>0 || iters>0, - "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)"); - data = static_cast(xbt_new(local_data_t, 1)); - data->count = 0; - data->sum = 0.0; - data->sum_pow2 = 0.0; - data->iters = iters; - data->threshold = threshold; - data->benching = 1; // If we have no data, we need at least one - data->mean = 0; - samples[loc] = data; + auto insert = samples.emplace(loc, LocalData{ + threshold, // threshold + 0.0, // relstderr + 0.0, // mean + 0.0, // sum + 0.0, // sum_pow2 + iters, // iters + 0, // count + true // benching (if we have no data, we need at least one) + }); + LocalData& data = insert.first->second; + if (insert.second) { XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str()); + xbt_assert(threshold > 0 || iters > 0, + "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)"); } else { - data = ld->second; - if (data->iters != iters || data->threshold != threshold) { + if (data.iters != iters || data.threshold != threshold) { XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. " "How did you manage to give two numbers at the same line??", - loc.c_str(), data->iters, data->threshold, iters, threshold); + loc.c_str(), data.iters, data.threshold, iters, threshold); THROW_IMPOSSIBLE; } // if we already have some data, check whether sample_2 should get one more bench or whether it should emulate // the computation instead - data->benching = (sample_enough_benchs(data) == 0); + data.benching = data.need_more_benchs(); XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc.c_str(), - (data->benching ? "more benching needed" : "we have enough data, skip computes")); + (data.benching ? "more benching needed" : "we have enough data, skip computes")); } } int smpi_sample_2(int global, const char *file, int line) { - std::string loc = sample_location(global, file, line); + SampleLocation loc(global, file, line); int res; - xbt_assert(not samples.empty(), - "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); - local_data_t* data = samples.at(loc); XBT_DEBUG("sample2 %s", loc.c_str()); + auto sample = samples.find(loc); + if (sample == samples.end()) + xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); + LocalData& data = sample->second; - if (data->benching==1) { + if (data.benching) { // we need to run a new bench XBT_DEBUG("benchmarking: count:%d iter:%d stderr:%f thres:%f; mean:%f", - data->count, data->iters, data->relstderr, data->threshold, data->mean); + data.count, data.iters, data.relstderr, data.threshold, data.mean); res = 1; } else { // Enough data, no more bench (either we got enough data from previous visits to this benched nest, or we just //ran one bench and need to bail out now that our job is done). Just sleep instead XBT_DEBUG("No benchmark (either no need, or just ran one): count >= iter (%d >= %d) or stderrcount, data->iters, data->relstderr, data->threshold, data->mean); - smpi_execute(data->mean); + data.count, data.iters, data.relstderr, data.threshold, data.mean); + smpi_execute(data.mean); smpi_process()->set_sampling(0); res = 0; // prepare to capture future, unrelated computations } @@ -369,36 +371,37 @@ int smpi_sample_2(int global, const char *file, int line) void smpi_sample_3(int global, const char *file, int line) { - std::string loc = sample_location(global, file, line); + SampleLocation loc(global, file, line); - xbt_assert(not samples.empty(), - "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); - local_data_t* data = samples.at(loc); XBT_DEBUG("sample3 %s", loc.c_str()); + auto sample = samples.find(loc); + if (sample == samples.end()) + xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); + LocalData& data = sample->second; - if (data->benching==0) + if (not data.benching) THROW_IMPOSSIBLE; // ok, benchmarking this loop is over xbt_os_threadtimer_stop(smpi_process()->timer()); // update the stats - data->count++; - double sample = xbt_os_timer_elapsed(smpi_process()->timer()); - data->sum += sample; - data->sum_pow2 += sample * sample; - double n = static_cast(data->count); - data->mean = data->sum / n; - data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean; - if (sample_enough_benchs(data)==0) { - data->mean = sample; // Still in benching process; We want sample_2 to simulate the exact time of this loop + data.count++; + double period = xbt_os_timer_elapsed(smpi_process()->timer()); + data.sum += period; + data.sum_pow2 += period * period; + double n = static_cast(data.count); + data.mean = data.sum / n; + data.relstderr = sqrt((data.sum_pow2 / n - data.mean * data.mean) / n) / data.mean; + if (data.need_more_benchs()) { + data.mean = period; // Still in benching process; We want sample_2 to simulate the exact time of this loop // occurrence before leaving, not the mean over the history } - XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data->count, - data->mean, data->relstderr, sample); + XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", + data.count, data.mean, data.relstderr, period); // That's enough for now, prevent sample_2 to run the same code over and over - data->benching = 0; + data.benching = false; } extern "C" { /** These functions will be called from the user code **/ @@ -432,6 +435,5 @@ void smpi_trace_set_call_location__(const char* file, int* line) void smpi_bench_destroy() { - for (auto const& elm : samples) - xbt_free(elm.second); + samples.clear(); } diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index d816b3c653..fcc5cc2751 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -21,6 +21,7 @@ #include #include +#include "src/internal_config.h" #include "src/xbt/memory_map.hpp" #include "private.h" @@ -68,6 +69,27 @@ void smpi_get_executable_global_size() } #endif +#if HAVE_SANITIZE_ADDRESS +#include +static void* asan_safe_memcpy(void* dest, void* src, size_t n) +{ + char* psrc = static_cast(src); + char* pdest = static_cast(dest); + for (size_t i = 0; i < n;) { + while (i < n && __asan_address_is_poisoned(psrc + i)) + ++i; + if (i < n) { + char* p = static_cast(__asan_region_is_poisoned(psrc + i, n - i)); + size_t j = p ? (p - psrc) : n; + memcpy(pdest + i, psrc + i, j - i); + i = j; + } + } + return dest; +} +#else +#define asan_safe_memcpy(dest, src, n) memcpy(dest, src, n) +#endif /** Map a given SMPI privatization segment (make a SMPI process active) */ void smpi_switch_data_segment(int dest) { @@ -91,7 +113,7 @@ void smpi_really_switch_data_segment(int dest) #if HAVE_PRIVATIZATION if(smpi_loaded_page==-1){//initial switch, do the copy from the real page here for (int i=0; i< smpi_process_count(); i++){ - memcpy(smpi_privatization_regions[i].address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe); + asan_safe_memcpy(smpi_privatization_regions[i].address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe); } } @@ -172,7 +194,7 @@ Ask the Internet about tutorials on how to increase the files limit such as: htt xbt_die("Impossible to unlink temporary file for memory mapping"); // initialize the values - memcpy(address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe); + asan_safe_memcpy(address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe); // store the address of the mapping for further switches smpi_privatization_regions[i].file_descriptor = file_descriptor; diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index f8c5f8b9dc..9291073b24 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -66,58 +66,28 @@ namespace{ * This information is used by SMPI_SHARED_MALLOC to allocate some shared memory for all simulated processes. */ -class smpi_source_location { +class smpi_source_location : public std::string { public: - smpi_source_location(const char* filename, int line) - : filename(xbt_strdup(filename)), filename_length(strlen(filename)), line(line) + smpi_source_location(const char* filename, int line) : std::string(std::string(filename) + ":" + std::to_string(line)) { } - - /** Pointer to a static string containing the file name */ - char* filename = nullptr; - int filename_length = 0; - int line = 0; - - bool operator==(smpi_source_location const& that) const - { - return filename_length == that.filename_length && line == that.line && - std::memcmp(filename, that.filename, filename_length) == 0; - } - bool operator!=(smpi_source_location const& that) const { return not(*this == that); } -}; -} - -namespace std { - -template <> class hash { -public: - typedef smpi_source_location argument_type; - typedef std::size_t result_type; - result_type operator()(smpi_source_location const& loc) const - { - return xbt_str_hash_ext(loc.filename, loc.filename_length) ^ - xbt_str_hash_ext((const char*)&loc.line, sizeof(loc.line)); - } }; -} -namespace{ - -typedef struct { +struct shared_data_t { int fd = -1; int count = 0; -} shared_data_t; +}; -std::unordered_map allocs; -typedef std::unordered_map::value_type shared_data_key_type; +std::unordered_map> allocs; +typedef decltype(allocs)::value_type shared_data_key_type; -typedef struct { +struct shared_metadata_t { size_t size; size_t allocated_size; void *allocated_ptr; std::vector> private_blocks; shared_data_key_type* data; -} shared_metadata_t; +}; std::map allocs_metadata; std::map calls; diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index e8282cbba4..7a6dc74f85 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015. The SimGrid Team. +/* Copyright (c) 2013-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -34,12 +34,11 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/) action->getLastUpdate(), now - action->getLastUpdate()); } - action->finish(); + action->finish(Action::State::done); XBT_CDEBUG(surf_kernel, "Action %p finished", action); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); - action->setState(Action::State::done); } if (TRACE_is_enabled()) { //defining the last timestamp that we can safely dump to trace file @@ -84,8 +83,7 @@ void CpuModel::updateActionsStateFull(double now, double delta) if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } } } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 5366483665..454efa886d 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015. The SimGrid Team. +/* Copyright (c) 2013-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -380,10 +380,9 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/) while ((xbt_heap_size(tiActionHeap_) > 0) && (xbt_heap_maxkey(tiActionHeap_) <= now)) { CpuTiAction *action = static_cast(xbt_heap_pop(tiActionHeap_)); XBT_DEBUG("Action %p: finish", action); - action->finish(); + action->finish(Action::State::done); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); - action->setState(Action::State::done); /* update remaining amount of all actions */ action->cpu_->updateRemainingAmount(surf_get_clock()); } diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 1106ad91da..fb1a77b1fe 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -103,10 +103,9 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter) char link_typename[INSTR_DEFAULT_STR_SIZE]; snprintf(link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s", father->type_->name_, src->type_->name_, src->type_->id_, dst->type_->name_, dst->type_->id_); - simgrid::instr::Type* link_type = simgrid::instr::Type::getOrNull(link_typename, father->type_); - if (link_type == nullptr){ + simgrid::instr::Type* link_type = father->type_->getChildOrNull(link_typename); + if (link_type == nullptr) link_type = simgrid::instr::Type::linkNew(link_typename, father->type_, src->type_, dst->type_); - } //register EDGE types for triva configuration trivaEdgeTypes.insert(link_type->name_); @@ -166,12 +165,11 @@ static void sg_instr_AS_begin(simgrid::s4u::NetZone& netzone) const char* id = netzone.getCname(); if (PJ_container_get_root() == nullptr){ - PJ_container_alloc (); container_t root = new simgrid::instr::Container(id, simgrid::instr::INSTR_AS, nullptr); PJ_container_set_root (root); if (TRACE_smpi_is_enabled()) { - simgrid::instr::Type* mpi = simgrid::instr::Type::getOrNull("MPI", root->type_); + simgrid::instr::Type* mpi = root->type_->getChildOrNull("MPI"); if (mpi == nullptr){ mpi = simgrid::instr::Type::containerNew("MPI", root->type_); if (not TRACE_smpi_is_grouped()) @@ -212,22 +210,19 @@ static void instr_routing_parse_start_link(simgrid::s4u::Link& link) container_t container = new simgrid::instr::Container(link.name(), simgrid::instr::INSTR_LINK, father); if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_link())) { - simgrid::instr::Type* bandwidth = simgrid::instr::Type::getOrNull("bandwidth", container->type_); - if (bandwidth == nullptr) { + simgrid::instr::Type* bandwidth = container->type_->getChildOrNull("bandwidth"); + if (bandwidth == nullptr) bandwidth = simgrid::instr::Type::variableNew("bandwidth", nullptr, container->type_); - } - simgrid::instr::Type* latency = simgrid::instr::Type::getOrNull("latency", container->type_); - if (latency == nullptr) { + simgrid::instr::Type* latency = container->type_->getChildOrNull("latency"); + if (latency == nullptr) latency = simgrid::instr::Type::variableNew("latency", nullptr, container->type_); - } new simgrid::instr::SetVariableEvent(0, container, bandwidth, bandwidth_value); new simgrid::instr::SetVariableEvent(0, container, latency, latency_value); } if (TRACE_uncategorized()) { - simgrid::instr::Type* bandwidth_used = simgrid::instr::Type::getOrNull("bandwidth_used", container->type_); - if (bandwidth_used == nullptr) { + simgrid::instr::Type* bandwidth_used = container->type_->getChildOrNull("bandwidth_used"); + if (bandwidth_used == nullptr) simgrid::instr::Type::variableNew("bandwidth_used", "0.5 0.5 0.5", container->type_); - } } } @@ -237,7 +232,7 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) container_t container = new simgrid::instr::Container(host.getCname(), simgrid::instr::INSTR_HOST, father); if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) { - simgrid::instr::Type* speed = simgrid::instr::Type::getOrNull("power", container->type_); + simgrid::instr::Type* speed = container->type_->getChildOrNull("power"); if (speed == nullptr){ speed = simgrid::instr::Type::variableNew("power", nullptr, container->type_); } @@ -246,14 +241,14 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) new simgrid::instr::SetVariableEvent(0, container, speed, current_speed_state); } if (TRACE_uncategorized()){ - simgrid::instr::Type* speed_used = simgrid::instr::Type::getOrNull("power_used", container->type_); + simgrid::instr::Type* speed_used = container->type_->getChildOrNull("power_used"); if (speed_used == nullptr){ simgrid::instr::Type::variableNew("power_used", "0.5 0.5 0.5", container->type_); } } if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()){ - simgrid::instr::Type* mpi = simgrid::instr::Type::getOrNull("MPI", container->type_); + simgrid::instr::Type* mpi = container->type_->getChildOrNull("MPI"); if (mpi == nullptr){ mpi = simgrid::instr::Type::containerNew("MPI", container->type_); simgrid::instr::Type::stateNew("MPI_STATE", mpi); @@ -261,11 +256,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) } if (TRACE_msg_process_is_enabled()) { - simgrid::instr::Type* msg_process = simgrid::instr::Type::getOrNull("MSG_PROCESS", container->type_); + simgrid::instr::Type* msg_process = container->type_->getChildOrNull("MSG_PROCESS"); if (msg_process == nullptr){ msg_process = simgrid::instr::Type::containerNew("MSG_PROCESS", container->type_); simgrid::instr::Type* state = simgrid::instr::Type::stateNew("MSG_PROCESS_STATE", msg_process); - simgrid::instr::Value PJ_value("suspend", "1 0 1", state); + new simgrid::instr::Value("suspend", "1 0 1", state); simgrid::instr::Value::get_or_new("sleep", "1 1 0", state); simgrid::instr::Value::get_or_new("receive", "1 0 0", state); simgrid::instr::Value::get_or_new("send", "0 0 1", state); @@ -276,11 +271,11 @@ static void sg_instr_new_host(simgrid::s4u::Host& host) } if (TRACE_msg_vm_is_enabled()) { - simgrid::instr::Type* msg_vm = simgrid::instr::Type::getOrNull("MSG_VM", container->type_); + simgrid::instr::Type* msg_vm = container->type_->getChildOrNull("MSG_VM"); if (msg_vm == nullptr){ msg_vm = simgrid::instr::Type::containerNew("MSG_VM", container->type_); simgrid::instr::Type* state = simgrid::instr::Type::stateNew("MSG_VM_STATE", msg_vm); - simgrid::instr::Value PJ_value("suspend", "1 0 1", state); + new simgrid::instr::Value("suspend", "1 0 1", state); simgrid::instr::Value::get_or_new("sleep", "1 1 0", state); simgrid::instr::Value::get_or_new("receive", "1 0 0", state); simgrid::instr::Value::get_or_new("send", "0 0 1", state); @@ -403,7 +398,7 @@ static void recursiveNewValueForUserStateType(const char* type_name, const char* simgrid::instr::Type* root) { if (not strcmp(root->name_, type_name)) { - simgrid::instr::Value PJ_value(val, color, root); + new simgrid::instr::Value(val, color, root); } xbt_dict_cursor_t cursor = nullptr; simgrid::instr::Type* child_type; diff --git a/src/surf/instr_surf.cpp b/src/surf/instr_surf.cpp index d82ef1b992..83f7e1e227 100644 --- a/src/surf/instr_surf.cpp +++ b/src/surf/instr_surf.cpp @@ -13,7 +13,7 @@ void TRACE_surf_host_set_speed(double date, const char *resource, double speed) { if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) { container_t container = PJ_container_get(resource); - simgrid::instr::Type* type = PJ_type_get("power", container->type_); + simgrid::instr::Type* type = container->type_->getChild("power"); new simgrid::instr::SetVariableEvent(date, container, type, speed); } } @@ -22,7 +22,7 @@ void TRACE_surf_link_set_bandwidth(double date, const char *resource, double ban { if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) { container_t container = PJ_container_get(resource); - simgrid::instr::Type* type = PJ_type_get("bandwidth", container->type_); + simgrid::instr::Type* type = container->type_->getChild("bandwidth"); new simgrid::instr::SetVariableEvent(date, container, type, bandwidth); } } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index e0ae4e41af..d3e8809e05 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -204,8 +204,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) // assume that flows that reached max_duration have remaining of 0 XBT_DEBUG("Action %p finished", action); action->setRemains(0); - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); action->heapRemove(actionHeap_); } } @@ -259,8 +258,7 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta) if (((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } } } @@ -492,8 +490,7 @@ void NetworkCm02Action::updateRemainingLazy(double now) if ((remains_ <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) || ((maxDuration_ > NO_MAX_DURATION) && (maxDuration_ <= 0))) { - finish(); - setState(Action::State::done); + finish(Action::State::done); heapRemove(getModel()->getActionHeap()); } diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 35a66b6bd0..dcbc87f1d0 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -68,8 +68,7 @@ void NetworkConstantModel::updateActionsState(double /*now*/, double delta) if (((action->getRemainsNoUpdate() <= 0) || ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)))) { - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } } } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index fe0fdee60f..a9139b1bad 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -237,8 +237,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta) if(sgFlow->finished_){ xbt_dynar_push(socket_to_destroy,&ns3Socket); XBT_DEBUG("Destroy socket %p of action %p", ns3Socket, action); - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } } diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index c1750d7333..b3d5beab5b 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -129,8 +129,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) { if (((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } else { /* Need to check that none of the model has failed */ int i = 0; @@ -140,8 +139,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) { void *constraint_id = lmm_constraint_id(cnst); if (static_cast(constraint_id)->isOff()) { XBT_DEBUG("Action (%p) Failed!!", action); - action->finish(); - action->setState(Action::State::failed); + action->finish(Action::State::failed); break; } cnst = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 6966739b7b..234920087c 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -446,6 +446,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) std::vector args(process->argv, process->argv + process->argc); std::function code = factory(std::move(args)); + std::shared_ptr> properties(process->properties); smx_process_arg_t arg = nullptr; @@ -455,7 +456,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) arg->data = nullptr; arg->host = host; arg->kill_time = kill_time; - arg->properties = process->properties; + arg->properties = properties; host->extension()->boot_processes.push_back(arg); @@ -467,12 +468,12 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) arg->data = nullptr; arg->host = host; arg->kill_time = kill_time; - arg->properties = process->properties; + arg->properties = properties; XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->getCname(), start_time); SIMIX_timer_set(start_time, [arg, auto_restart]() { smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(arg->code), arg->data, - arg->host, arg->properties, nullptr); + arg->host, arg->properties.get(), nullptr); if (arg->kill_time >= 0) simcall_process_set_kill_time(actor, arg->kill_time); if (auto_restart) @@ -483,7 +484,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->getCname()); smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host, - arg->properties, nullptr); + arg->properties.get(), nullptr); /* The actor creation will fail if the host is currently dead, but that's fine */ if (actor != nullptr) { @@ -493,7 +494,6 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) SIMIX_process_auto_restart_set(actor, auto_restart); } } - current_property_set = nullptr; } void sg_platf_new_peer(PeerCreationArgs* peer) diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index a27852bd47..d8bfca3039 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -98,12 +98,10 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) if (action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && action->storage_->usedSize_ == action->storage_->getSize()) { - action->finish(); - action->setState(Action::State::failed); + action->finish(Action::State::failed); } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { - action->finish(); - action->setState(Action::State::done); + action->finish(Action::State::done); } } } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index a8a7239d2c..b0007c14e0 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -634,8 +634,10 @@ Action::~Action() { xbt_free(category_); } -void Action::finish() { +void Action::finish(Action::State state) +{ finishTime_ = surf_get_clock(); + setState(state); } Action::State Action::getState() @@ -880,8 +882,7 @@ void Action::updateRemainingLazy(double now) //FIXME: duplicated code if (((remains_ <= 0) && (lmm_get_variable_weight(getVariable()) > 0)) || ((maxDuration_ > NO_MAX_DURATION) && (maxDuration_ <= 0))) { - finish(); - setState(Action::State::done); + finish(Action::State::done); heapRemove(getModel()->getActionHeap()); } } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 65eea27d30..0d3c6fd9f1 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -118,8 +118,12 @@ public: /** @brief Destructor */ virtual ~Action(); - /** @brief Mark that the action is now finished */ - void finish(); + /** + * @brief Mark that the action is now finished + * + * @param state the new [state](\ref simgrid::surf::Action::State) of the current Action + */ + void finish(Action::State state); /** @brief Get the [state](\ref simgrid::surf::Action::State) of the current Action */ Action::State getState(); /**< get the state*/ diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 565fbe422a..93958801c9 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -1,6 +1,6 @@ /* platf_private.h - Interface to the SimGrid platforms which visibility should be limited to this directory */ -/* Copyright (c) 2004-2015. The SimGrid Team. +/* Copyright (c) 2004-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -191,9 +191,6 @@ public: int routing; }; -/* The default current property receiver. Setup in the corresponding opening callbacks. */ -extern std::map* current_property_set; - /********** Routing **********/ void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb); /*** END of the parsing cruft ***/ diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index e1dd4f6875..a123599abd 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -1026,9 +1026,11 @@ void ETag_surfxml_actor() s_sg_platf_process_cbarg_t actor; memset(&actor,0,sizeof(actor)); + actor.properties = current_property_set; + current_property_set = nullptr; + actor.argc = argc; actor.argv = (const char **)argv; - actor.properties = current_property_set; actor.host = A_surfxml_actor_host; actor.function = A_surfxml_actor_function; actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time); @@ -1053,8 +1055,6 @@ void ETag_surfxml_actor() xbt_free(argv[i]); xbt_free(argv); argv = nullptr; - - current_property_set = nullptr; } void STag_surfxml_argument(){ diff --git a/src/xbt/automaton/automaton.c b/src/xbt/automaton/automaton.c index 7f3c7463d5..eb1e879f74 100644 --- a/src/xbt/automaton/automaton.c +++ b/src/xbt/automaton/automaton.c @@ -395,7 +395,6 @@ void xbt_automaton_propositional_symbol_free_voidp(void *ps){ xbt_automaton_propositional_symbol_t symbol = (xbt_automaton_propositional_symbol_t) * (void **) ps; if (symbol->free_function) symbol->free_function(symbol->data); - xbt_free(symbol->pred); xbt_automaton_propositional_symbol_free(symbol); } diff --git a/src/xbt/automaton/automatonparse_promela.c b/src/xbt/automaton/automatonparse_promela.c index dffb34e9e9..f35835daad 100644 --- a/src/xbt/automaton/automatonparse_promela.c +++ b/src/xbt/automaton/automatonparse_promela.c @@ -17,15 +17,15 @@ static xbt_automaton_t parsed_automaton; char* state_id_src; static void new_state(char* id, int src){ - + char* saveptr = NULL; // for strtok_r() char* id_copy = xbt_strdup(id); - char* first_part = strtok(id_copy,"_"); + char* first_part = strtok_r(id_copy, "_", &saveptr); int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state if(strcmp(first_part,"accept")==0){ type = 1; }else{ - char* second_part = strtok(NULL,"_"); + char* second_part = strtok_r(NULL, "_", &saveptr); if(strcmp(second_part,"init")==0){ type = -1; } diff --git a/src/xbt/exception.cpp b/src/xbt/exception.cpp index 5483ae5370..a1c6d0b52b 100644 --- a/src/xbt/exception.cpp +++ b/src/xbt/exception.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2005-2016. The SimGrid Team. +/* Copyright (c) 2005-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include #include @@ -47,7 +49,7 @@ void logException( XBT_LOG(prio, "%s %s: %s", context, name.get(), exception.what()); // Do we have a backtrace? - if (with_context != nullptr) { + if (with_context != nullptr && not xbt_cfg_get_boolean("exception/cutpath")) { auto backtrace = simgrid::xbt::resolveBacktrace( with_context->backtrace().data(), with_context->backtrace().size()); for (std::string const& s : backtrace) @@ -76,6 +78,10 @@ void logException( static void showBacktrace(std::vector& bt) { + if (xbt_cfg_get_boolean("exception/cutpath")) { + XBT_LOG(xbt_log_priority_critical, "Display of current backtrace disabled by --cfg=exception/cutpath."); + return; + } std::vector res = resolveBacktrace(&bt[0], bt.size()); XBT_LOG(xbt_log_priority_critical, "Current backtrace:"); for (std::string const& s : res) diff --git a/src/xbt/heap.c b/src/xbt/heap.c index 5bd06f3d8a..2d4964aa5f 100644 --- a/src/xbt/heap.c +++ b/src/xbt/heap.c @@ -158,18 +158,19 @@ void *xbt_heap_remove(xbt_heap_t H, int i) return xbt_heap_pop(H); } + /** @brief Remove an arbitrary element from the heap - * @param H the heap we're working on - * @param content the object you want to add to the heap - * @param key the key associated to this object + * \param H the heap we're working on + * \param content the object you want to remove from the heap + * \param key the key associated to this object + * \return the removed element if found, NULL otherwise */ -void xbt_heap_rm_elm(xbt_heap_t H, void *content, double key) { +void *xbt_heap_rm_elm(xbt_heap_t H, void *content, double key) +{ int i=0; while (i < H->count && (KEY(H, i) != key || CONTENT(H, i) != content)) i++; - if (i == H->count) - return; - xbt_heap_remove(H,i); + return xbt_heap_remove(H, i); } /** diff --git a/src/xbt/log.c b/src/xbt/log.c index 30d72a92e6..04772a3afa 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -355,44 +355,47 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) xbt_assert(ev->priority < sizeof(xbt_log_priority_names), "Priority %d is greater than the biggest allowed value", ev->priority); - do { + while (1) { xbt_log_appender_t appender = cat->appender; - if (!appender) - continue; /* No appender, try next */ - - xbt_assert(cat->layout, "No valid layout for the appender of category %s", cat->name); - - /* First, try with a static buffer */ - if (XBT_LOG_STATIC_BUFFER_SIZE) { - char buff[XBT_LOG_STATIC_BUFFER_SIZE]; - ev->buffer = buff; - ev->buffer_size = sizeof buff; - va_start(ev->ap, fmt); - int done = cat->layout->do_layout(cat->layout, ev, fmt); - va_end(ev->ap); - if (done) { - appender->do_append(appender, buff); - continue; /* Ok, that worked: go next */ + if (appender != NULL) { + xbt_assert(cat->layout, "No valid layout for the appender of category %s", cat->name); + + /* First, try with a static buffer */ + int done = 0; + if (XBT_LOG_STATIC_BUFFER_SIZE) { + char buff[XBT_LOG_STATIC_BUFFER_SIZE]; + ev->buffer = buff; + ev->buffer_size = sizeof buff; + va_start(ev->ap, fmt); + done = cat->layout->do_layout(cat->layout, ev, fmt); + va_end(ev->ap); + if (done) + appender->do_append(appender, buff); } - } - /* The static buffer was too small, use a dynamically expanded one */ - ev->buffer_size = XBT_LOG_DYNAMIC_BUFFER_SIZE; - ev->buffer = xbt_malloc(ev->buffer_size); - while (1) { - va_start(ev->ap, fmt); - int done = cat->layout->do_layout(cat->layout, ev, fmt); - va_end(ev->ap); - if (done) - break; /* Got it */ - ev->buffer_size *= 2; - ev->buffer = xbt_realloc(ev->buffer, ev->buffer_size); + if (!done) { + /* The static buffer was too small, use a dynamically expanded one */ + ev->buffer_size = XBT_LOG_DYNAMIC_BUFFER_SIZE; + ev->buffer = xbt_malloc(ev->buffer_size); + while (1) { + va_start(ev->ap, fmt); + done = cat->layout->do_layout(cat->layout, ev, fmt); + va_end(ev->ap); + if (done) + break; /* Got it */ + ev->buffer_size *= 2; + ev->buffer = xbt_realloc(ev->buffer, ev->buffer_size); + } + appender->do_append(appender, ev->buffer); + xbt_free(ev->buffer); + } } - appender->do_append(appender, ev->buffer); - xbt_free(ev->buffer); - } while (cat->additivity && (cat = cat->parent, 1)); + if (!cat->additivity) + break; + cat = cat->parent; + } } #undef XBT_LOG_DYNAMIC_BUFFER_SIZE diff --git a/src/xbt/memory_map.cpp b/src/xbt/memory_map.cpp index b2185d7266..73e2d8d487 100644 --- a/src/xbt/memory_map.cpp +++ b/src/xbt/memory_map.cpp @@ -193,12 +193,13 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) line[read - 1] = '\0'; /* Tokenize the line using spaces as delimiters and store each token in lfields array. We expect 5 tokens for 6 fields */ + char* saveptr = nullptr; // for strtok_r() char* lfields[6]; - lfields[0] = strtok(line, " "); + lfields[0] = strtok_r(line, " ", &saveptr); int i; for (i = 1; i < 6 && lfields[i - 1] != nullptr; i++) { - lfields[i] = std::strtok(nullptr, " "); + lfields[i] = strtok_r(nullptr, " ", &saveptr); } /* Check to see if we got the expected amount of columns */ @@ -207,7 +208,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* Ok we are good enough to try to get the info we need */ /* First get the start and the end address of the map */ - char *tok = std::strtok(lfields[0], "-"); + char* tok = strtok_r(lfields[0], "-", &saveptr); if (tok == nullptr) xbt_die("Start and end address of the map are not concatenated by a hyphen (-). Recovery impossible."); @@ -218,7 +219,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) if (*endptr != '\0') xbt_abort(); - tok = std::strtok(nullptr, "-"); + tok = strtok_r(nullptr, "-", &saveptr); if (tok == nullptr) xbt_abort(); @@ -268,7 +269,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) xbt_abort(); /* Get the device major:minor bytes */ - tok = std::strtok(lfields[3], ":"); + tok = strtok_r(lfields[3], ":", &saveptr); if (tok == nullptr) xbt_abort(); @@ -277,7 +278,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) if (*endptr != '\0') xbt_abort(); - tok = std::strtok(nullptr, ":"); + tok = strtok_r(nullptr, ":", &saveptr); if (tok == nullptr) xbt_abort(); diff --git a/teshsuite/java/CMakeLists.txt b/teshsuite/java/CMakeLists.txt index 2d9d5dfb7b..de2af46938 100644 --- a/teshsuite/java/CMakeLists.txt +++ b/teshsuite/java/CMakeLists.txt @@ -1,7 +1,7 @@ -set(semaphoreGC_files SemaphoreGC) -set(sleepHostOff_files SleepHostOff) +set(semaphoregc_files SemaphoreGC) +set(sleephostoff_files SleepHostOff) -foreach(example semaphoreGC sleepHostOff) +foreach(example semaphoregc sleephostoff) foreach (filename ${${example}_files} ) set(sources "${${example}_sources}" "${CMAKE_CURRENT_SOURCE_DIR}/${example}/${filename}.java") endforeach() @@ -11,14 +11,14 @@ foreach(example semaphoreGC sleepHostOff) if(enable_java) add_custom_command( COMMENT "Building ${example}..." - OUTPUT ${example}_compiled + OUTPUT java-${example}_compiled DEPENDS ${sources} simgrid-java_jar ${SIMGRID_JAR} COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR} -d ${CMAKE_CURRENT_BINARY_DIR} ${sources} - COMMAND ${CMAKE_COMMAND} -E remove ${example}/${example}_compiled - COMMAND ${CMAKE_COMMAND} -E touch ${example}/${example}_compiled + COMMAND ${CMAKE_COMMAND} -E remove ${example}/java-${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example}/java-${example}_compiled ) - add_custom_target(${example} ALL DEPENDS ${example}_compiled) - set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example}) + add_custom_target(java-${example} ALL DEPENDS java-${example}_compiled) + set_target_properties(java-${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example}) endif() set(examples_src ${examples_src} ${sources}) endforeach() @@ -27,6 +27,6 @@ set(examples_src ${examples_src} ${sources} set(tesh_files ${tesh_files} PARENT_SCOPE) if(enable_java) - ADD_TESH(tesh-java-semaphoreGC --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java/semaphoreGC ${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphoreGC/semaphoreGC.tesh) - ADD_TESH(tesh-java-sleepHostOff --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java/sleepHostOff ${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleepHostOff/sleepHostOff.tesh) + ADD_TESH(tesh-java-semaphoregc --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java/semaphoregc ${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphoregc/semaphoregc.tesh) + ADD_TESH(tesh-java-sleephostoff --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java/sleephostoff ${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleephostoff/sleephostoff.tesh) endif() diff --git a/teshsuite/java/semaphoreGC/SemaphoreGC.java b/teshsuite/java/semaphoregc/SemaphoreGC.java similarity index 93% rename from teshsuite/java/semaphoreGC/SemaphoreGC.java rename to teshsuite/java/semaphoregc/SemaphoreGC.java index cf18ab252f..21cad25706 100644 --- a/teshsuite/java/semaphoreGC/SemaphoreGC.java +++ b/teshsuite/java/semaphoregc/SemaphoreGC.java @@ -7,7 +7,7 @@ * This was reported as bug #19893 on gforge. */ -package semaphoreGC; +package semaphoregc; import org.simgrid.msg.*; import org.simgrid.msg.Process; @@ -37,7 +37,7 @@ public class SemaphoreGC { public static void main(String[] args) throws Exception { Msg.init(args); if (args.length < 1) { - Msg.info("Usage: java -cp simgrid.jar:. semaphoreGC.SemaphoreGC "); + Msg.info("Usage: java -cp simgrid.jar:. semaphoregc.SemaphoreGC "); System.exit(1); } Msg.createEnvironment(args[0]); diff --git a/teshsuite/java/semaphoreGC/semaphoreGC.tesh b/teshsuite/java/semaphoregc/semaphoregc.tesh similarity index 86% rename from teshsuite/java/semaphoreGC/semaphoreGC.tesh rename to teshsuite/java/semaphoregc/semaphoregc.tesh index d3d9f3ef66..a321b134ad 100644 --- a/teshsuite/java/semaphoreGC/semaphoreGC.tesh +++ b/teshsuite/java/semaphoregc/semaphoregc.tesh @@ -1,6 +1,6 @@ ! timeout 15 -$ java -classpath ${classpath:=.} semaphoreGC.SemaphoreGC ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.4r]%e(%i:%P@%h)%e%m%n" +$ java -classpath ${classpath:=.} semaphoregc.SemaphoreGC ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.4r]%e(%i:%P@%h)%e%m%n" > [ 0.0000] (0:maestro@) Using regular java threads. > [ 0.0000] (1:SemCreator@Fafard) Creating 50 new Semaphores, yielding and triggering a GC after each > [ 500.0000] (1:SemCreator@Fafard) It worked, we survived. The test is passed. diff --git a/teshsuite/java/sleepHostOff/SleepHostOff.java b/teshsuite/java/sleephostoff/SleepHostOff.java similarity index 95% rename from teshsuite/java/sleepHostOff/SleepHostOff.java rename to teshsuite/java/sleephostoff/SleepHostOff.java index 78c95a5581..16ab628585 100644 --- a/teshsuite/java/sleepHostOff/SleepHostOff.java +++ b/teshsuite/java/sleephostoff/SleepHostOff.java @@ -3,7 +3,7 @@ /* 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. */ -package sleepHostOff; +package sleephostoff; import org.simgrid.msg.*; import org.simgrid.msg.Process; @@ -55,7 +55,7 @@ public class SleepHostOff { Msg.init(args); if (args.length < 1) { - Msg.info("Usage: java -cp simgrid.jar:. sleepHostOff.SleepHostOff "); + Msg.info("Usage: java -cp simgrid.jar:. sleephostoff.SleepHostOff "); System.exit(1); } diff --git a/teshsuite/java/sleepHostOff/sleepHostOff.tesh b/teshsuite/java/sleephostoff/sleephostoff.tesh similarity index 93% rename from teshsuite/java/sleepHostOff/sleepHostOff.tesh rename to teshsuite/java/sleephostoff/sleephostoff.tesh index 8286614a0d..55aabb59da 100644 --- a/teshsuite/java/sleepHostOff/sleepHostOff.tesh +++ b/teshsuite/java/sleephostoff/sleephostoff.tesh @@ -1,4 +1,4 @@ -$ java -classpath ${classpath:=.} sleepHostOff.SleepHostOff ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ java -classpath ${classpath:=.} sleephostoff.SleepHostOff ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Using regular java threads. > [ 0.000000] (1:TestRunner@Fafard) **** **** **** ***** ***** Test Sleep ***** ***** **** **** **** > [ 0.000000] (1:TestRunner@Fafard) Test sleep: Create a process on Tremblay that simply make periodic sleep, turn off Tremblay diff --git a/teshsuite/lua/lua_platforms.tesh b/teshsuite/lua/lua_platforms.tesh index 17e7aecdb0..1ca79927ff 100644 --- a/teshsuite/lua/lua_platforms.tesh +++ b/teshsuite/lua/lua_platforms.tesh @@ -1,4 +1,4 @@ -$ ${bindir:=.}/../../examples/msg/app-masterworker/app-masterworker ${srcdir:=.}/../../examples/platforms/small_platform.lua ${srcdir:=.}/../../examples/msg/app-masterworker/app-masterworker_d.xml +$ ${bindir:=.}/msg/app-masterworker/app-masterworker ${srcdir:=.}/../../examples/platforms/small_platform.lua ${srcdir:=.}/../../examples/msg/app-masterworker/app-masterworker_d.xml > [Tremblay:master:(1) 0.000000] [msg_app_masterworker/INFO] Got 5 workers and 20 tasks to process > [Tremblay:master:(1) 0.000000] [msg_app_masterworker/INFO] Sending "Task_0" (of 20) to mailbox "worker-0" > [Tremblay:master:(1) 0.002265] [msg_app_masterworker/INFO] Sending "Task_1" (of 20) to mailbox "worker-1" @@ -28,7 +28,7 @@ $ ${bindir:=.}/../../examples/msg/app-masterworker/app-masterworker ${srcdir:=.} > [Bourassa:worker:(6) 5.133855] [msg_app_masterworker/INFO] I'm done. See you! > [5.133855] [msg_app_masterworker/INFO] Simulation time 5.13386 -$ $SG_TEST_EXENV ${bindir:=.}/../../examples/msg/app-token-ring/app-token-ring ${srcdir:=.}/../../examples/platforms/routing_cluster.lua "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ $SG_TEST_EXENV ${bindir:=.}/msg/app-token-ring/app-token-ring ${srcdir:=.}/../../examples/platforms/routing_cluster.lua "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Number of hosts '6' > [ 0.000000] (1:0@host1) Host "0" send 'Token' to Host "1" > [ 0.017354] (2:1@host2) Host "1" received "Token" diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index be9c437bdb..39b4e94075 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -52,7 +52,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/acti ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml PARENT_SCOPE) foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv task_destroy_cancel task_listen_from trace_integration) - ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh) + ADD_TESH_FACTORIES(tesh-msg-${x} "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh) endforeach() foreach(x actions-comm actions-storage app-bittorrent) @@ -64,4 +64,4 @@ foreach(x cloud-sharing) ADD_TESH(tesh-msg-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh) endforeach() -ADD_TESH_FACTORIES(tesh-app-bittorrent-parallel "thread;ucontext;raw" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/msg/app-bittorrent --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/app-bittorrent app-bittorrent.tesh) +ADD_TESH_FACTORIES(tesh-app-bittorrent-parallel "thread;ucontext;raw;boost" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/msg/app-bittorrent --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/app-bittorrent app-bittorrent.tesh) diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c index 9b5bcd2722..680b014b1b 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c @@ -10,13 +10,22 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example") xbt_dynar_t tests; int tasks_done = 0; +static void task_cleanup_handler(void *task) +{ + if (task) + MSG_task_destroy(task); +} + static int process_daemon(int argc, char *argv[]) { + msg_process_t self = MSG_process_self(); XBT_INFO(" Start daemon on %s (%f)", MSG_host_get_name(MSG_host_self()), MSG_host_get_speed(MSG_host_self())); for(;;){ msg_task_t task = MSG_task_create("daemon", MSG_host_get_speed(MSG_host_self()), 0, NULL); + MSG_process_set_data(self, task); XBT_INFO(" Execute daemon"); MSG_task_execute(task); + MSG_process_set_data(self, NULL); MSG_task_destroy(task); tasks_done ++; } @@ -39,7 +48,7 @@ static int commTX(int argc, char *argv[]) const char * mailbox = "comm"; XBT_INFO(" Start TX"); msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL); - MSG_task_isend(task, mailbox); + MSG_task_dsend(task, mailbox, task_cleanup_handler); // We should wait a bit (if not the process will end before the communication, hence an exception on the other side). MSG_process_sleep(30); XBT_INFO(" TX done"); @@ -54,6 +63,7 @@ static int commRX(int argc, char *argv[]) msg_error_t error = MSG_task_receive(&(task), mailbox); if (error==MSG_OK) { XBT_INFO(" Receive message: %s", task->name); + MSG_task_destroy(task); } else if (error==MSG_HOST_FAILURE) { XBT_INFO(" Receive message: HOST_FAILURE"); } else if (error==MSG_TRANSFER_FAILURE) { @@ -162,11 +172,12 @@ static int test_launcher(int argc, char *argv[]) MSG_process_sleep(10); XBT_INFO(" Turn Jupiter off"); MSG_host_off(jupiter); - XBT_INFO("Test 5 seems ok, cool !(number of Process : %d, it should be 2", MSG_process_get_number()); + XBT_INFO("Test 5 seems ok (number of Process: %d, it should be 2)", MSG_process_get_number()); } test =6; if (xbt_dynar_search_or_negative(tests, &test)!=-1){ + MSG_process_set_data_cleanup(NULL); /* FIXME: we are leaking here, but removing this line changes the test output */ XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node"); // Create VM0 @@ -225,11 +236,13 @@ int main(int argc, char *argv[]) MSG_create_environment(argv[1]); + MSG_process_set_data_cleanup(task_cleanup_handler); MSG_process_create("test_launcher", test_launcher, NULL, MSG_get_host_by_name("Tremblay")); res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); + xbt_dynar_free(&tests); return res != MSG_OK; } diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh index 13b028d28b..5d5d220c5a 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh @@ -61,7 +61,7 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platfor > [Tremblay:commTX:(3) 10.000000] [msg_test/INFO] Start TX > [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] number of processes: 3 > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Turn Jupiter off -> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok, cool !(number of Process : 2, it should be 2 +> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok (number of Process: 2, it should be 2) > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test done. See you! > [Tremblay:commTX:(3) 40.000000] [msg_test/INFO] TX done > [40.000000] [msg_test/INFO] Simulation time 40 diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index a1ed94a19a..539a53ab1e 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -10,7 +10,7 @@ endforeach() ## Some need to be run with all factories, some need not tesh to run foreach(x actor concurrent_rw) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) - ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) + ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) endforeach() foreach(x host_on_off_wait listen_async pid storage_client_server) diff --git a/teshsuite/simix/CMakeLists.txt b/teshsuite/simix/CMakeLists.txt index c4669759b6..60536259ca 100644 --- a/teshsuite/simix/CMakeLists.txt +++ b/teshsuite/simix/CMakeLists.txt @@ -25,9 +25,11 @@ ELSE() ADD_TESH(tesh-simix-factory-default --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simix/check_defaults --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simix/check_defaults factory_thread.tesh) ENDIF() +if (NOT enable_memcheck AND NOT enable_address_sanitizer) + ADD_TESH_FACTORIES(stack-overflow "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simix/stack_overflow --setenv srcdir=${CMAKE_HOME_DIRECTORY} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simix/stack_overflow stack_overflow.tesh) +endif() if (NOT enable_memcheck) -ADD_TESH_FACTORIES(stack-overflow "thread;ucontext;boost;raw" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simix/stack_overflow --setenv srcdir=${CMAKE_HOME_DIRECTORY} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simix/stack_overflow stack_overflow.tesh) -ADD_TESH_FACTORIES(generic-simcalls "thread;ucontext;boost;raw" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simix/generic_simcalls --setenv srcdir=${CMAKE_HOME_DIRECTORY} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simix/generic_simcalls generic_simcalls.tesh) + ADD_TESH_FACTORIES(generic-simcalls "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simix/generic_simcalls --setenv srcdir=${CMAKE_HOME_DIRECTORY} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simix/generic_simcalls generic_simcalls.tesh) endif() foreach (factory raw thread boost ucontext) diff --git a/teshsuite/simix/generic_simcalls/generic_simcalls.cpp b/teshsuite/simix/generic_simcalls/generic_simcalls.cpp index 1b872574b1..3ae06a0a6b 100644 --- a/teshsuite/simix/generic_simcalls/generic_simcalls.cpp +++ b/teshsuite/simix/generic_simcalls/generic_simcalls.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2016. The SimGrid Team. +/* Copyright (c) 2016-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -40,7 +40,7 @@ static int master(int argc, char *argv[]) XBT_INFO("kernel, returned"); // Synchronize on a successful Future: - simgrid::simix::kernelSync([&] { + simgrid::simix::kernelSync([] { return kernel_wait_until(10).then([](simgrid::kernel::Future future) { future.get(); XBT_INFO("kernelSync with void"); @@ -50,7 +50,7 @@ static int master(int argc, char *argv[]) // Synchronize on a failing Future: try { - simgrid::simix::kernelSync([&] { + simgrid::simix::kernelSync([] { return kernel_wait_until(20).then([](simgrid::kernel::Future future) { future.get(); throw std::runtime_error("Exception throwed from kernel_defer"); @@ -63,7 +63,7 @@ static int master(int argc, char *argv[]) } // Synchronize on a successul Future and get the value: - int res = simgrid::simix::kernelSync([&] { + int res = simgrid::simix::kernelSync([] { return kernel_wait_until(30).then([](simgrid::kernel::Future future) { future.get(); XBT_INFO("kernelSync with value"); @@ -73,7 +73,7 @@ static int master(int argc, char *argv[]) XBT_INFO("kernelSync with value returned with %i", res); // Synchronize on a successul Future and get the value: - simgrid::simix::Future future = simgrid::simix::kernelAsync([&] { + simgrid::simix::Future future = simgrid::simix::kernelAsync([] { return kernel_wait_until(50).then([](simgrid::kernel::Future future) { future.get(); XBT_INFO("kernelAsync with value"); @@ -84,7 +84,7 @@ static int master(int argc, char *argv[]) XBT_INFO("kernelAsync with value returned with %i", res); // Synchronize on a successul Future and get the value: - future = simgrid::simix::kernelAsync([&] { + future = simgrid::simix::kernelAsync([] { return kernel_wait_until(60).then([](simgrid::kernel::Future future) { future.get(); XBT_INFO("kernelAsync with value"); diff --git a/teshsuite/smpi/isp/umpire/CMakeLists.txt b/teshsuite/smpi/isp/umpire/CMakeLists.txt index e43d774758..fcf19e452b 100644 --- a/teshsuite/smpi/isp/umpire/CMakeLists.txt +++ b/teshsuite/smpi/isp/umpire/CMakeLists.txt @@ -28,7 +28,6 @@ set(umpire_tests_passing no-error-wait-any_src3 no-error-wait-any_src4 no-error-waitany-any_src - partial-recv sendrecv-deadlock send-recv-ok irecv-isend-ok @@ -37,6 +36,7 @@ set(umpire_tests_passing set(umpire_tests_passing_broken irecv-isend-ok2 + partial-recv ) # These are supposed to deadlock but ISP does not find deadlock diff --git a/teshsuite/smpi/mpich3-test/coll/CMakeLists.txt b/teshsuite/smpi/mpich3-test/coll/CMakeLists.txt index 5aedd5f62d..e9d42a1a51 100644 --- a/teshsuite/smpi/mpich3-test/coll/CMakeLists.txt +++ b/teshsuite/smpi/mpich3-test/coll/CMakeLists.txt @@ -232,9 +232,9 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite) endif() # Test MPICH selector: dlopen privatization and PTHREAD if exists (without priv and with raw if not) - if(HAVE_PRIVATIZATION AND HAVE_THREAD_CONTEXTS) - ADD_TEST(test-smpi-mpich3-coll-mpich-thread-dlopen ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/coll ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests ${TESH_OPTION} -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/coll -tests=testlist -execarg=--cfg=contexts/factory:thread -execarg=--cfg=smpi/coll-selector:mpich -execarg=--cfg=smpi/privatization:dlopen) - SET_TESTS_PROPERTIES(test-smpi-mpich3-coll-mpich-thread-dlopen PROPERTIES PASS_REGULAR_EXPRESSION "tests passed!") + if(HAVE_PRIVATIZATION AND HAVE_BOOST_CONTEXTS) + ADD_TEST(test-smpi-mpich3-coll-mpich-boost-dlopen ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/coll ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests ${TESH_OPTION} -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/coll -tests=testlist -execarg=--cfg=contexts/factory:boost -execarg=--cfg=smpi/coll-selector:mpich -execarg=--cfg=smpi/privatization:dlopen) + SET_TESTS_PROPERTIES(test-smpi-mpich3-coll-mpich-boost-dlopen PROPERTIES PASS_REGULAR_EXPRESSION "tests passed!") else() if(HAVE_RAW_CONTEXTS) ADD_TEST(test-smpi-mpich3-coll-mpich-raw ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/coll ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests ${TESH_OPTION} -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/coll -tests=testlist -execarg=--cfg=contexts/factory:raw -execarg=--cfg=smpi/coll-selector:mpich -execarg=--cfg=smpi/privatization:${HAVE_PRIVATIZATION}) diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 7280d5da8e..247836ac98 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1050,6 +1050,7 @@ set(CMAKE_SOURCE_FILES tools/cmake/scripts/update_tesh.pl tools/cmake/UnitTesting.cmake tools/cmake/src/internal_config.h.in + tools/cmake/test_prog/prog_asan.cpp tools/cmake/test_prog/prog_gnu_dynlinker.c tools/cmake/test_prog/prog_makecontext.c tools/cmake/test_prog/prog_mutex_timedlock.c diff --git a/tools/cmake/GCCFlags.cmake b/tools/cmake/GCCFlags.cmake index a6ec7a90b9..432441c9b7 100644 --- a/tools/cmake/GCCFlags.cmake +++ b/tools/cmake/GCCFlags.cmake @@ -192,6 +192,12 @@ if(enable_address_sanitizer) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -fsanitize=address") set(TESH_OPTION --enable-sanitizers) + try_compile(HAVE_SANITIZE_ADDRESS ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_asan.cpp) + try_compile(HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_asan.cpp + COMPILE_DEFINITIONS -DCHECK_FIBER_SUPPORT) +else() + set(HAVE_SANITIZE_ADDRESS FALSE CACHE INTERNAL "") + set(HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT FALSE CACHE INTERNAL "") endif() if(enable_thread_sanitizer) diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index 58a2304072..6aed72c998 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -44,25 +44,6 @@ endif() if(SIMGRID_HAVE_LUA) ADD_CUSTOM_TARGET(link_simgrid_lua ALL DEPENDS simgrid - ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} - ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} - ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} - ) - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} - ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} - ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} - COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/ - COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test - - COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/ - COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test - - COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/ - COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test ) SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}") endif() diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index a6aea406a0..8d4d570a37 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -82,8 +82,8 @@ ENDIF() IF(SIMGRID_HAVE_LUA) # Tests testing simulation from C but using lua for platform files. Executed like this # ~$ ./masterslave platform.lua deploy.lua - ADD_TESH(lua-platform-masterslave --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/lua --cd ${CMAKE_BINARY_DIR}/examples/lua ${CMAKE_HOME_DIRECTORY}/teshsuite/lua/lua_platforms.tesh) - SET_TESTS_PROPERTIES(lua-platform-masterslave PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/examples/lua/?.so") + ADD_TESH(lua-platform-masterslave --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/lua --cd ${CMAKE_BINARY_DIR}/examples ${CMAKE_HOME_DIRECTORY}/teshsuite/lua/lua_platforms.tesh) + SET_TESTS_PROPERTIES(lua-platform-masterslave PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/lib/lib?.${LIB_EXE}") ENDIF() ADD_TEST(testall ${CMAKE_BINARY_DIR}/testall) @@ -98,4 +98,4 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND) else() set(EXTRA_DIST ${EXTRA_DIST} src/surf/trace_mgr_test.cpp) -endif() \ No newline at end of file +endif() diff --git a/tools/cmake/src/internal_config.h.in b/tools/cmake/src/internal_config.h.in index b98161a411..aac7ce0a3e 100644 --- a/tools/cmake/src/internal_config.h.in +++ b/tools/cmake/src/internal_config.h.in @@ -3,7 +3,7 @@ /* Warning: The file internal_config.h is AUTOMATICALLY GENERATED by Cmake. * Edit the template instead: tools/cmake/src/internal_config.h.in */ -/* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2017. 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. */ @@ -24,6 +24,10 @@ /* */ #cmakedefine01 HAVE_VALGRIND_H +/* Address Sanitizer */ +#cmakedefine01 HAVE_SANITIZE_ADDRESS +#cmakedefine01 HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT + /* Time portability */ /* Function gettimeofday */ #cmakedefine01 HAVE_GETTIMEOFDAY diff --git a/tools/cmake/test_prog/prog_asan.cpp b/tools/cmake/test_prog/prog_asan.cpp new file mode 100644 index 0000000000..67d8adf8fe --- /dev/null +++ b/tools/cmake/test_prog/prog_asan.cpp @@ -0,0 +1,29 @@ +/* Copyright (c) 2017. 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. */ + +/* Check availability of AddressSanitizer */ + +#if defined(__has_feature) +#define HAS_FEATURE(x) __has_feature(x) +#else +#define HAS_FEATURE(x) 0 +#endif + +#if not HAS_FEATURE(address_sanitizer) && not defined(__SANITIZE_ADDRESS__) +#error "ASan feature not found." +#endif + +#include + +#if defined(CHECK_FIBER_SUPPORT) +// Verify the existence of the fiber annotation interface, with the expected signature +void (*start_fiber)(void**, const void*, size_t) = __sanitizer_start_switch_fiber; +void (*finish_fiber)(void*, const void**, size_t*) = __sanitizer_finish_switch_fiber; +#endif + +int main(void) +{ +} diff --git a/tools/simgrid.supp b/tools/simgrid.supp index 6a0800b289..287d7bf513 100644 --- a/tools/simgrid.supp +++ b/tools/simgrid.supp @@ -18,8 +18,13 @@ { Memory leak in cmake Memcheck:Leak + match-leak-kinds:reachable + ... + fun:_Znwm + fun:_ZN4Json5Value13nullSingletonEv + obj:*/libjsoncpp.so* ... - obj:cmake + fun:_dl_init } # There's a constant leak of 56 bytes in the depths of libc which @@ -81,7 +86,7 @@ #SMPI leaks the dlopen handle used to load the program { - dlopen handle leaks (1/2) + dlopen handle leaks (1/3) Memcheck:Leak match-leak-kinds:reachable fun:malloc @@ -90,7 +95,7 @@ } { - dlopen handle leaks (2/2) + dlopen handle leaks (2/3) Memcheck:Leak match-leak-kinds:reachable fun:calloc @@ -98,6 +103,15 @@ fun:dlopen@@GLIBC_* } +{ + dlopen handle leaks (3/3) + Memcheck:Leak + match-leak-kinds:reachable + fun:realloc + ... + fun:dlopen@@GLIBC_* +} + # Memory leaks appearing to be in libcgraph. They can be seen with the # following simple program: # ,---- diff --git a/tools/tesh/tesh.py b/tools/tesh/tesh.py index 5000d65dee..fd5b08836a 100755 --- a/tools/tesh/tesh.py +++ b/tools/tesh/tesh.py @@ -402,8 +402,8 @@ if __name__ == '__main__': group1.add_argument('teshfile', nargs='?', help='Name of teshfile, stdin if omitted') group1.add_argument('--cd', metavar='some/directory', help='ask tesh to switch the working directory before launching the tests') group1.add_argument('--setenv', metavar='var=value', action='append', help='set a specific environment variable') - group1.add_argument('--cfg', metavar='arg', help='add parameter --cfg=arg to each command line') - group1.add_argument('--log', metavar='arg', help='add parameter --log=arg to each command line') + group1.add_argument('--cfg', metavar='arg', action='append', help='add parameter --cfg=arg to each command line') + group1.add_argument('--log', metavar='arg', action='append', help='add parameter --log=arg to each command line') group1.add_argument('--ignore-jenkins', action='store_true', help='ignore all cruft generated on SimGrid continous integration servers') group1.add_argument('--wrapper', metavar='arg', help='Run each command in the provided wrapper (eg valgrind)') group1.add_argument('--keep', action='store_true', help='Keep the obtained output when it does not match the expected one') @@ -418,18 +418,18 @@ if __name__ == '__main__': if options.ignore_jenkins: print("Ignore all cruft seen on SimGrid's continous integration servers") + # Note: regexps should match at the beginning of lines TeshState().ignore_regexps_common = [ - re.compile("^profiling:"), - re.compile(".*WARNING: ASan doesn\'t fully support"), - re.compile("Unable to clean temporary file C:.*"), + re.compile("profiling:"), + re.compile("Unable to clean temporary file C:"), re.compile(".*Configuration change: Set \'contexts/"), - re.compile(".*Picked up JAVA_TOOL_OPTIONS.*"), - re.compile("Picked up _JAVA_OPTIONS: .*"), - - re.compile("==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top:"), + re.compile("Picked up JAVA_TOOL_OPTIONS: "), + re.compile("Picked up _JAVA_OPTIONS: "), + re.compile("==[0-9]+== ?WARNING: ASan doesn\'t fully support"), + re.compile("==[0-9]+== ?WARNING: ASan is ignoring requested __asan_handle_no_return: stack top:"), re.compile("False positive error reports may follow"), - re.compile("For details see http://code.google.com/p/address-sanitizer/issues/detail?id=189"), - + re.compile("For details see http://code.google.com/p/address-sanitizer/issues/detail\\?id=189"), + re.compile("For details see https://github.com/google/sanitizers/issues/189"), re.compile("Python runtime initialized with LC_CTYPE=C .*"), ] TeshState().jenkins = True # This is a Jenkins build @@ -449,9 +449,11 @@ if __name__ == '__main__': setenv(e) if options.cfg is not None: - TeshState().args_suffix += " --cfg="+options.cfg + for c in options.cfg: + TeshState().args_suffix += " --cfg=" + c if options.log is not None: - TeshState().args_suffix += " --log="+options.log + for l in options.log: + TeshState().args_suffix += " --log=" + l if options.wrapper is not None: TeshState().wrapper = options.wrapper