From 5942182c3a29de424e91a87f019a596b3a2e71bf Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Fri, 20 May 2016 12:23:15 +0200 Subject: [PATCH 1/1] [simix] C++-based ownership of process name and arguments * Process and ProcessArg now use a std::string instead of a a char*. A consequence it that there now no difference bewteen the "" name and the nullptr process name (only the former is possible). * simix::simgrid::args now always copy the arguments. * simix::simgrid::args now as a .to_argv() method used to copy its argv. --- examples/msg/io-storage/io-storage.tesh | 182 ++++++++++++------------ include/simgrid/simix.hpp | 45 +++++- src/msg/instr_msg_process.cpp | 4 +- src/msg/msg_process.cpp | 2 +- src/simix/libsmx.cpp | 7 +- src/simix/popping.cpp | 2 +- src/simix/popping_bodies.cpp | 138 +++++++++--------- src/simix/smx_global.cpp | 4 +- src/simix/smx_host.cpp | 56 +++----- src/simix/smx_network.cpp | 6 +- src/simix/smx_process.cpp | 125 ++++++++-------- src/simix/smx_process_private.h | 21 ++- src/simix/smx_vm.cpp | 10 +- src/surf/sg_platf.cpp | 23 ++- 14 files changed, 308 insertions(+), 317 deletions(-) diff --git a/examples/msg/io-storage/io-storage.tesh b/examples/msg/io-storage/io-storage.tesh index 0f1f69d14c..cf79aa250e 100644 --- a/examples/msg/io-storage/io-storage.tesh +++ b/examples/msg/io-storage/io-storage.tesh @@ -1,17 +1,17 @@ #! ./tesh $ ${bindir:=.}/io-storage$EXEEXT ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:(null)@denise) *** Storage info on denise *** -> [ 0.000000] (1:(null)@denise) Storage name: Disk2, mount name: c: -> [ 0.000000] (1:(null)@denise) Total size: 536870912000 bytes -> [ 0.000000] (1:(null)@denise) Free size: 534479374867 bytes -> [ 0.000000] (1:(null)@denise) Used size: 2391537133 bytes -> [ 0.000000] (1:(null)@denise) Storage name: Disk4, mount name: /home -> [ 0.000000] (1:(null)@denise) Total size: 536870912000 bytes -> [ 0.000000] (1:(null)@denise) Free size: 536857690006 bytes -> [ 0.000000] (1:(null)@denise) Used size: 13221994 bytes -> [ 0.003333] (1:(null)@denise) Create a 200000 bytes file named '/home/tmp/data.txt' on /sd1 -> [ 0.003333] (1:(null)@denise) File Descriptor information: +> [ 0.000000] (1:@denise) *** Storage info on denise *** +> [ 0.000000] (1:@denise) Storage name: Disk2, mount name: c: +> [ 0.000000] (1:@denise) Total size: 536870912000 bytes +> [ 0.000000] (1:@denise) Free size: 534479374867 bytes +> [ 0.000000] (1:@denise) Used size: 2391537133 bytes +> [ 0.000000] (1:@denise) Storage name: Disk4, mount name: /home +> [ 0.000000] (1:@denise) Total size: 536870912000 bytes +> [ 0.000000] (1:@denise) Free size: 536857690006 bytes +> [ 0.000000] (1:@denise) Used size: 13221994 bytes +> [ 0.003333] (1:@denise) Create a 200000 bytes file named '/home/tmp/data.txt' on /sd1 +> [ 0.003333] (1:@denise) File Descriptor information: > Full path: '/home/tmp/data.txt' > Size: 200000 > Mount point: '/home' @@ -19,11 +19,11 @@ $ ${bindir:=.}/io-storage$EXEEXT ${srcdir:=.}/storage/storage.xml "--log=root.fm > Storage Type: 'single_SSD' > Content Type: 'txt_unix' > File Descriptor Id: 0 -> [ 0.003333] (1:(null)@denise) Free size: 536857490006 bytes -> [ 0.003333] (1:(null)@denise) Used size: 13421994 bytes -> [ 0.004333] (1:(null)@denise) Read 200000 bytes on /home/tmp/data.txt -> [ 0.006000] (1:(null)@denise) Write 100000 bytes on /home/tmp/data.txt -> [ 0.006000] (1:(null)@denise) File Descriptor information: +> [ 0.003333] (1:@denise) Free size: 536857490006 bytes +> [ 0.003333] (1:@denise) Used size: 13421994 bytes +> [ 0.004333] (1:@denise) Read 200000 bytes on /home/tmp/data.txt +> [ 0.006000] (1:@denise) Write 100000 bytes on /home/tmp/data.txt +> [ 0.006000] (1:@denise) File Descriptor information: > Full path: '/home/tmp/data.txt' > Size: 300000 > Mount point: '/home' @@ -31,79 +31,79 @@ $ ${bindir:=.}/io-storage$EXEEXT ${srcdir:=.}/storage/storage.xml "--log=root.fm > Storage Type: 'single_SSD' > Content Type: 'txt_unix' > File Descriptor Id: 0 -> [ 0.006000] (1:(null)@denise) *** Move '/tmp/data.txt' into '/tmp/simgrid.readme' -> [ 0.006000] (1:(null)@denise) User data attached to the file: 777 -> [ 0.006000] (1:(null)@denise) *** Get/set data for storage element: Disk4 *** -> [ 0.006000] (1:(null)@denise) Get storage data: '(null)' -> [ 0.006000] (1:(null)@denise) Set and get data: 'Some user data' -> [ 0.006000] (1:(null)@denise) *** Dump content of denise *** -> [ 0.006000] (1:(null)@denise) Print the content of mount point: c: -> [ 0.006000] (1:(null)@denise) \Windows\win.ini size: 92 bytes -> [ 0.006000] (1:(null)@denise) \Windows\mib.bin size: 43131 bytes -> [ 0.006000] (1:(null)@denise) \Windows\DtcInstall.log size: 1955 bytes -> [ 0.006000] (1:(null)@denise) \Windows\vmgcoinstall.log size: 1585 bytes -> [ 0.006000] (1:(null)@denise) \Windows\Starter.xml size: 31537 bytes -> [ 0.006000] (1:(null)@denise) \Windows\_isusr32.dll size: 180320 bytes -> [ 0.006000] (1:(null)@denise) \Windows\winhlp32.exe size: 10752 bytes -> [ 0.006000] (1:(null)@denise) \Windows\setuperr.log size: 0 bytes -> [ 0.006000] (1:(null)@denise) \Windows\system.ini size: 219 bytes -> [ 0.006000] (1:(null)@denise) \Windows\hapint.exe size: 382056 bytes -> [ 0.006000] (1:(null)@denise) \Windows\Professional.xml size: 31881 bytes -> [ 0.006000] (1:(null)@denise) \Windows\regedit.exe size: 159232 bytes -> [ 0.006000] (1:(null)@denise) \Windows\setupact.log size: 101663 bytes -> [ 0.006000] (1:(null)@denise) \Windows\WindowsUpdate.log size: 1518934 bytes -> [ 0.006000] (1:(null)@denise) \Windows\explorer.exe size: 2380944 bytes -> [ 0.006000] (1:(null)@denise) \Windows\DirectX.log size: 10486 bytes -> [ 0.006000] (1:(null)@denise) \Windows\WMSysPr9.prx size: 316640 bytes -> [ 0.006000] (1:(null)@denise) \Windows\PFRO.log size: 6770 bytes -> [ 0.006000] (1:(null)@denise) \Windows\csup.txt size: 12 bytes -> [ 0.006000] (1:(null)@denise) \Windows\WLXPGSS.SCR size: 322048 bytes -> [ 0.006000] (1:(null)@denise) \Windows\avastSS.scr size: 41664 bytes -> [ 0.006000] (1:(null)@denise) \Windows\font1.sii size: 4907 bytes -> [ 0.006000] (1:(null)@denise) \Windows\write.exe size: 10752 bytes -> [ 0.006000] (1:(null)@denise) \Windows\font2.sii size: 8698 bytes -> [ 0.006000] (1:(null)@denise) \Windows\CoreSingleLanguage.xml size: 31497 bytes -> [ 0.006000] (1:(null)@denise) \Windows\dchcfg64.exe size: 335464 bytes -> [ 0.006000] (1:(null)@denise) \Windows\notepad.exe size: 243712 bytes -> [ 0.006000] (1:(null)@denise) \Windows\HelpPane.exe size: 883712 bytes -> [ 0.006000] (1:(null)@denise) \Windows\hh.exe size: 17408 bytes -> [ 0.006000] (1:(null)@denise) \Windows\DPINST.LOG size: 18944 bytes -> [ 0.006000] (1:(null)@denise) \Windows\bfsvc.exe size: 75264 bytes -> [ 0.006000] (1:(null)@denise) \Windows\splwow64.exe size: 126464 bytes -> [ 0.006000] (1:(null)@denise) \Windows\MEMORY.DMP size: 2384027342 bytes -> [ 0.006000] (1:(null)@denise) \Windows\dcmdev64.exe size: 93288 bytes -> [ 0.006000] (1:(null)@denise) \Windows\twain_32.dll size: 50176 bytes -> [ 0.006000] (1:(null)@denise) \Windows\bootstat.dat size: 67584 bytes -> [ 0.006000] (1:(null)@denise) Print the content of mount point: /home -> [ 0.006000] (1:(null)@denise) /include/simix/simix.h size: 13003 bytes -> [ 0.006000] (1:(null)@denise) /include/mc/modelchecker.h size: 96 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/msg/README size: 4805 bytes -> [ 0.006000] (1:(null)@denise) /include/instr/instr.h size: 5750 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/mc_bugged2.c size: 1387 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/html/group__XBT__str.html size: 36192 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/EP/README size: 347 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/DT/README size: 999 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/FT/README size: 276 bytes -> [ 0.006000] (1:(null)@denise) /lib/libsimgrid.so.3.6.2 size: 12710497 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/sys/README size: 1461 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/msg/alias/masterslave_forwarder_with_alias.c size: 6217 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/SP/README size: 926 bytes -> [ 0.006000] (1:(null)@denise) /tmp/simgrid.readme size: 300000 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/msg/parallel_task/test_ptask_deployment.xml size: 654 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/msg/icomms/small_platform.xml size: 972 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/MG/README size: 5465 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/msg/trace/test9.xml size: 598 bytes -> [ 0.006000] (1:(null)@denise) /include/smpi/mpif.h size: 4826 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/README size: 1857 bytes -> [ 0.006000] (1:(null)@denise) /bin/tesh size: 356434 bytes -> [ 0.006000] (1:(null)@denise) /include/simdag/simdag.h size: 10325 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/xbt/sem_basic.c size: 1970 bytes -> [ 0.006000] (1:(null)@denise) /include/xbt/fifo.h size: 3626 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/common/randdp.c size: 1441 bytes -> [ 0.006000] (1:(null)@denise) /include/msg/datatypes.h size: 4635 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/EP/randlc.c size: 3300 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/smpi/NAS/MPI_dummy/README size: 2406 bytes -> [ 0.006000] (1:(null)@denise) /doc/simgrid/examples/platforms/g5k.xml size: 17028 bytes -> [ 0.006000] (1:(null)@denise) /include/surf/simgrid_dtd.h size: 23583 bytes -> [ 0.006000] (1:(null)@denise) /bin/smpicc size: 918 bytes +> [ 0.006000] (1:@denise) *** Move '/tmp/data.txt' into '/tmp/simgrid.readme' +> [ 0.006000] (1:@denise) User data attached to the file: 777 +> [ 0.006000] (1:@denise) *** Get/set data for storage element: Disk4 *** +> [ 0.006000] (1:@denise) Get storage data: '(null)' +> [ 0.006000] (1:@denise) Set and get data: 'Some user data' +> [ 0.006000] (1:@denise) *** Dump content of denise *** +> [ 0.006000] (1:@denise) Print the content of mount point: c: +> [ 0.006000] (1:@denise) \Windows\win.ini size: 92 bytes +> [ 0.006000] (1:@denise) \Windows\mib.bin size: 43131 bytes +> [ 0.006000] (1:@denise) \Windows\DtcInstall.log size: 1955 bytes +> [ 0.006000] (1:@denise) \Windows\vmgcoinstall.log size: 1585 bytes +> [ 0.006000] (1:@denise) \Windows\Starter.xml size: 31537 bytes +> [ 0.006000] (1:@denise) \Windows\_isusr32.dll size: 180320 bytes +> [ 0.006000] (1:@denise) \Windows\winhlp32.exe size: 10752 bytes +> [ 0.006000] (1:@denise) \Windows\setuperr.log size: 0 bytes +> [ 0.006000] (1:@denise) \Windows\system.ini size: 219 bytes +> [ 0.006000] (1:@denise) \Windows\hapint.exe size: 382056 bytes +> [ 0.006000] (1:@denise) \Windows\Professional.xml size: 31881 bytes +> [ 0.006000] (1:@denise) \Windows\regedit.exe size: 159232 bytes +> [ 0.006000] (1:@denise) \Windows\setupact.log size: 101663 bytes +> [ 0.006000] (1:@denise) \Windows\WindowsUpdate.log size: 1518934 bytes +> [ 0.006000] (1:@denise) \Windows\explorer.exe size: 2380944 bytes +> [ 0.006000] (1:@denise) \Windows\DirectX.log size: 10486 bytes +> [ 0.006000] (1:@denise) \Windows\WMSysPr9.prx size: 316640 bytes +> [ 0.006000] (1:@denise) \Windows\PFRO.log size: 6770 bytes +> [ 0.006000] (1:@denise) \Windows\csup.txt size: 12 bytes +> [ 0.006000] (1:@denise) \Windows\WLXPGSS.SCR size: 322048 bytes +> [ 0.006000] (1:@denise) \Windows\avastSS.scr size: 41664 bytes +> [ 0.006000] (1:@denise) \Windows\font1.sii size: 4907 bytes +> [ 0.006000] (1:@denise) \Windows\write.exe size: 10752 bytes +> [ 0.006000] (1:@denise) \Windows\font2.sii size: 8698 bytes +> [ 0.006000] (1:@denise) \Windows\CoreSingleLanguage.xml size: 31497 bytes +> [ 0.006000] (1:@denise) \Windows\dchcfg64.exe size: 335464 bytes +> [ 0.006000] (1:@denise) \Windows\notepad.exe size: 243712 bytes +> [ 0.006000] (1:@denise) \Windows\HelpPane.exe size: 883712 bytes +> [ 0.006000] (1:@denise) \Windows\hh.exe size: 17408 bytes +> [ 0.006000] (1:@denise) \Windows\DPINST.LOG size: 18944 bytes +> [ 0.006000] (1:@denise) \Windows\bfsvc.exe size: 75264 bytes +> [ 0.006000] (1:@denise) \Windows\splwow64.exe size: 126464 bytes +> [ 0.006000] (1:@denise) \Windows\MEMORY.DMP size: 2384027342 bytes +> [ 0.006000] (1:@denise) \Windows\dcmdev64.exe size: 93288 bytes +> [ 0.006000] (1:@denise) \Windows\twain_32.dll size: 50176 bytes +> [ 0.006000] (1:@denise) \Windows\bootstat.dat size: 67584 bytes +> [ 0.006000] (1:@denise) Print the content of mount point: /home +> [ 0.006000] (1:@denise) /include/simix/simix.h size: 13003 bytes +> [ 0.006000] (1:@denise) /include/mc/modelchecker.h size: 96 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/msg/README size: 4805 bytes +> [ 0.006000] (1:@denise) /include/instr/instr.h size: 5750 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/mc_bugged2.c size: 1387 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/html/group__XBT__str.html size: 36192 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/EP/README size: 347 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/DT/README size: 999 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/FT/README size: 276 bytes +> [ 0.006000] (1:@denise) /lib/libsimgrid.so.3.6.2 size: 12710497 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/sys/README size: 1461 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/msg/alias/masterslave_forwarder_with_alias.c size: 6217 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/SP/README size: 926 bytes +> [ 0.006000] (1:@denise) /tmp/simgrid.readme size: 300000 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/msg/parallel_task/test_ptask_deployment.xml size: 654 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/msg/icomms/small_platform.xml size: 972 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/MG/README size: 5465 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/msg/trace/test9.xml size: 598 bytes +> [ 0.006000] (1:@denise) /include/smpi/mpif.h size: 4826 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/README size: 1857 bytes +> [ 0.006000] (1:@denise) /bin/tesh size: 356434 bytes +> [ 0.006000] (1:@denise) /include/simdag/simdag.h size: 10325 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/xbt/sem_basic.c size: 1970 bytes +> [ 0.006000] (1:@denise) /include/xbt/fifo.h size: 3626 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/common/randdp.c size: 1441 bytes +> [ 0.006000] (1:@denise) /include/msg/datatypes.h size: 4635 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/EP/randlc.c size: 3300 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/smpi/NAS/MPI_dummy/README size: 2406 bytes +> [ 0.006000] (1:@denise) /doc/simgrid/examples/platforms/g5k.xml size: 17028 bytes +> [ 0.006000] (1:@denise) /include/surf/simgrid_dtd.h size: 23583 bytes +> [ 0.006000] (1:@denise) /bin/smpicc size: 918 bytes > [ 0.006000] (0:maestro@) Simulated time: 0.006 diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 4149a350e5..c28bf8b12a 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -82,13 +82,37 @@ typename std::result_of::type kernel(F&& code) class args { private: - int argc_; - char** argv_; + int argc_ = 0; + char** argv_ = nullptr; public: // Main constructors - args() : argc_(0), argv_(nullptr) {} - args(int argc, char** argv) : argc_(argc), argv_(argv) {} + args() {} + + void assign(int argc, const char*const* argv) + { + clear(); + char** new_argv = xbt_new(char*,argc + 1); + for (int i = 0; i < argc; i++) + new_argv[i] = xbt_strdup(argv[i]); + new_argv[argc] = nullptr; + this->argc_ = argc; + this->argv_ = new_argv; + } + args(int argc, const char*const* argv) + { + this->assign(argc, argv); + } + + char** to_argv() const + { + const int argc = argc_; + char** argv = xbt_new(char*, argc + 1); + for (int i=0; i< argc; i++) + argv[i] = xbt_strdup(argv_[i]); + argv[argc] = nullptr; + return argv; + } // Free void clear() @@ -102,8 +126,15 @@ public: ~args() { clear(); } // Copy - args(args const& that) = delete; - args& operator=(args const& that) = delete; + args(args const& that) + { + this->assign(that.argc(), that.argv()); + } + args& operator=(args const& that) + { + this->assign(that.argc(), that.argv()); + return *this; + } // Move: args(args&& that) : argc_(that.argc_), argv_(that.argv_) @@ -127,7 +158,7 @@ public: }; inline -std::function wrap_main(xbt_main_func_t code, int argc, char **argv) +std::function wrap_main(xbt_main_func_t code, int argc, const char*const* argv) { if (code) { auto arg = std::make_shared(argc, argv); diff --git a/src/msg/instr_msg_process.cpp b/src/msg/instr_msg_process.cpp index c784fa4d57..6767f99335 100644 --- a/src/msg/instr_msg_process.cpp +++ b/src/msg/instr_msg_process.cpp @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process"); char *instr_process_id (msg_process_t proc, char *str, int len) { - return instr_process_id_2 (proc->name, proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len); + return instr_process_id_2 (proc->name.c_str(), proc->pid, str, len);//MSG_process_get_name(proc), MSG_process_get_PID(proc), str, len); } char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len) @@ -81,7 +81,7 @@ void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t proc { if (TRACE_msg_process_is_enabled() && status==SMX_EXIT_FAILURE){ //kill means that this process no longer exists, let's destroy it - TRACE_msg_process_destroy(process->name, process->pid); + TRACE_msg_process_destroy(process->name.c_str(), process->pid); } } diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 51b79295fb..1b4599d78f 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -40,7 +40,7 @@ void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc) simcall_process_set_data(smx_proc, NULL); } - TRACE_msg_process_destroy(smx_proc->name, smx_proc->pid); + TRACE_msg_process_destroy(smx_proc->name.c_str(), smx_proc->pid); // free the data if a function was provided if (msg_proc && msg_proc->data && msg_global->process_data_cleanup) { msg_global->process_data_cleanup(msg_proc->data); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index bbea457dd7..aa0a3c42a7 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -33,7 +33,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix); void simcall_call(smx_process_t process) { if (process != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", process->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", process->name.c_str(), SIMIX_simcall_name(process->simcall.call), (int)process->simcall.call); SIMIX_process_yield(process); } else { @@ -375,6 +375,8 @@ smx_process_t simcall_process_create(const char *name, xbt_dict_t properties, int auto_restart) { + if (name == nullptr) + name = ""; return (smx_process_t) simcall_BODY_process_create(name, code, data, hostname, kill_time, argc, argv, properties, auto_restart); @@ -534,7 +536,8 @@ void simcall_process_set_kill_time(smx_process_t process, double kill_time) if (kill_time > SIMIX_get_clock()) { if (simix_global->kill_process_function) { - XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name, + XBT_DEBUG("Set kill time %f for process %s(%s)", + kill_time, process->name.c_str(), sg_host_get_name(process->host)); process->kill_timer = SIMIX_timer_set(kill_time, kill_process_from_timer, process); } diff --git a/src/simix/popping.cpp b/src/simix/popping.cpp index 631bc80f22..832686daa6 100644 --- a/src/simix/popping.cpp +++ b/src/simix/popping.cpp @@ -24,7 +24,7 @@ void SIMIX_simcall_answer(smx_simcall_t simcall) { if (simcall->issuer != simix_global->maestro_process){ XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call, - simcall->issuer->name, simcall->issuer); + simcall->issuer->name.c_str(), simcall->issuer); simcall->issuer->simcall.call = SIMCALL_NONE; /* This check should be useless and slows everyone. Reactivate if you see something * weird in process scheduling. diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 57e3e9aa4d..8f88cb1dbe 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -31,7 +31,7 @@ inline static void simcall_BODY_vm_suspend(sg_host_t ind_vm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) ind_vm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -52,7 +52,7 @@ inline static void simcall_BODY_vm_resume(sg_host_t ind_vm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) ind_vm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -73,7 +73,7 @@ inline static void simcall_BODY_vm_shutdown(sg_host_t ind_vm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) ind_vm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -94,7 +94,7 @@ inline static void simcall_BODY_vm_save(sg_host_t ind_vm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) ind_vm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -115,7 +115,7 @@ inline static void simcall_BODY_vm_restore(sg_host_t ind_vm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) ind_vm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -144,7 +144,7 @@ inline static void* simcall_BODY_process_create(const char* name, xbt_main_func_ self->simcall.args[7].dp = (void*) properties; self->simcall.args[8].i = (int) auto_restart; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -165,7 +165,7 @@ inline static void simcall_BODY_process_kill(smx_process_t process) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -186,7 +186,7 @@ inline static void simcall_BODY_process_killall(int reset_pid) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].i = (int) reset_pid; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -207,7 +207,7 @@ inline static void simcall_BODY_process_cleanup(smx_process_t process) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -228,7 +228,7 @@ inline static void simcall_BODY_process_suspend(smx_process_t process) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -249,7 +249,7 @@ inline static void simcall_BODY_process_resume(smx_process_t process) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -271,7 +271,7 @@ inline static void simcall_BODY_process_set_host(smx_process_t process, sg_host_ self->simcall.args[0].dp = (void*) process; self->simcall.args[1].dp = (void*) dest; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -292,7 +292,7 @@ inline static int simcall_BODY_process_is_suspended(smx_process_t process) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -314,7 +314,7 @@ inline static int simcall_BODY_process_join(smx_process_t process, double timeou self->simcall.args[0].dp = (void*) process; self->simcall.args[1].d = (double) timeout; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -335,7 +335,7 @@ inline static int simcall_BODY_process_sleep(double duration) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].d = (double) duration; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -360,7 +360,7 @@ inline static smx_synchro_t simcall_BODY_execution_start(const char* name, doubl self->simcall.args[3].d = (double) bound; self->simcall.args[4].ul = (unsigned long) affinity_mask; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -387,7 +387,7 @@ inline static smx_synchro_t simcall_BODY_execution_parallel_start(const char* na self->simcall.args[5].d = (double) amount; self->simcall.args[6].d = (double) rate; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -408,7 +408,7 @@ inline static void simcall_BODY_execution_cancel(smx_synchro_t execution) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) execution; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -430,7 +430,7 @@ inline static void simcall_BODY_execution_set_priority(smx_synchro_t execution, self->simcall.args[0].dp = (void*) execution; self->simcall.args[1].d = (double) priority; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -452,7 +452,7 @@ inline static void simcall_BODY_execution_set_bound(smx_synchro_t execution, dou self->simcall.args[0].dp = (void*) execution; self->simcall.args[1].d = (double) bound; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -475,7 +475,7 @@ inline static void simcall_BODY_execution_set_affinity(smx_synchro_t execution, self->simcall.args[1].dp = (void*) ws; self->simcall.args[2].ul = (unsigned long) mask; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -496,7 +496,7 @@ inline static int simcall_BODY_execution_wait(smx_synchro_t execution) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) execution; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -519,7 +519,7 @@ inline static void simcall_BODY_process_on_exit(smx_process_t process, int_f_pvo self->simcall.args[1].fp = (FPtr) fun; self->simcall.args[2].dp = (void*) data; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -541,7 +541,7 @@ inline static void simcall_BODY_process_auto_restart_set(smx_process_t process, self->simcall.args[0].dp = (void*) process; self->simcall.args[1].i = (int) auto_restart; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -562,7 +562,7 @@ inline static smx_process_t simcall_BODY_process_restart(smx_process_t process) memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) process; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -583,7 +583,7 @@ inline static smx_mailbox_t simcall_BODY_mbox_create(const char* name) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].cc = (const char*) name; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -605,7 +605,7 @@ inline static void simcall_BODY_mbox_set_receiver(smx_mailbox_t mbox, smx_proces self->simcall.args[0].dp = (void*) mbox; self->simcall.args[1].dp = (void*) receiver; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -631,7 +631,7 @@ inline static smx_synchro_t simcall_BODY_comm_iprobe(smx_mailbox_t mbox, int typ self->simcall.args[4].fp = (FPtr) match_fun; self->simcall.args[5].dp = (void*) data; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -661,7 +661,7 @@ inline static void simcall_BODY_comm_send(smx_process_t sender, smx_mailbox_t mb self->simcall.args[8].dp = (void*) data; self->simcall.args[9].d = (double) timeout; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -692,7 +692,7 @@ inline static smx_synchro_t simcall_BODY_comm_isend(smx_process_t sender, smx_ma self->simcall.args[9].dp = (void*) data; self->simcall.args[10].i = (int) detached; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -721,7 +721,7 @@ inline static void simcall_BODY_comm_recv(smx_process_t receiver, smx_mailbox_t self->simcall.args[7].d = (double) timeout; self->simcall.args[8].d = (double) rate; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -749,7 +749,7 @@ inline static smx_synchro_t simcall_BODY_comm_irecv(smx_process_t receiver, smx_ self->simcall.args[6].dp = (void*) data; self->simcall.args[7].d = (double) rate; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -770,7 +770,7 @@ inline static int simcall_BODY_comm_waitany(xbt_dynar_t comms) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) comms; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -792,7 +792,7 @@ inline static void simcall_BODY_comm_wait(smx_synchro_t comm, double timeout) { self->simcall.args[0].dp = (void*) comm; self->simcall.args[1].d = (double) timeout; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -813,7 +813,7 @@ inline static int simcall_BODY_comm_test(smx_synchro_t comm) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) comm; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -834,7 +834,7 @@ inline static int simcall_BODY_comm_testany(xbt_dynar_t comms) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) comms; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -855,7 +855,7 @@ inline static smx_mutex_t simcall_BODY_mutex_init() { memset(self->simcall.args, 0, sizeof(self->simcall.args)); if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -876,7 +876,7 @@ inline static void simcall_BODY_mutex_lock(smx_mutex_t mutex) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) mutex; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -897,7 +897,7 @@ inline static int simcall_BODY_mutex_trylock(smx_mutex_t mutex) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) mutex; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -918,7 +918,7 @@ inline static void simcall_BODY_mutex_unlock(smx_mutex_t mutex) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) mutex; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -939,7 +939,7 @@ inline static smx_cond_t simcall_BODY_cond_init() { memset(self->simcall.args, 0, sizeof(self->simcall.args)); if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -960,7 +960,7 @@ inline static void simcall_BODY_cond_signal(smx_cond_t cond) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) cond; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -982,7 +982,7 @@ inline static void simcall_BODY_cond_wait(smx_cond_t cond, smx_mutex_t mutex) { self->simcall.args[0].dp = (void*) cond; self->simcall.args[1].dp = (void*) mutex; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1005,7 +1005,7 @@ inline static void simcall_BODY_cond_wait_timeout(smx_cond_t cond, smx_mutex_t m self->simcall.args[1].dp = (void*) mutex; self->simcall.args[2].d = (double) timeout; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1026,7 +1026,7 @@ inline static void simcall_BODY_cond_broadcast(smx_cond_t cond) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) cond; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1047,7 +1047,7 @@ inline static smx_sem_t simcall_BODY_sem_init(unsigned int capacity) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].ui = (unsigned int) capacity; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1068,7 +1068,7 @@ inline static void simcall_BODY_sem_release(smx_sem_t sem) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) sem; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1089,7 +1089,7 @@ inline static int simcall_BODY_sem_would_block(smx_sem_t sem) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) sem; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1110,7 +1110,7 @@ inline static void simcall_BODY_sem_acquire(smx_sem_t sem) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) sem; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1132,7 +1132,7 @@ inline static void simcall_BODY_sem_acquire_timeout(smx_sem_t sem, double timeou self->simcall.args[0].dp = (void*) sem; self->simcall.args[1].d = (double) timeout; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1153,7 +1153,7 @@ inline static int simcall_BODY_sem_get_capacity(smx_sem_t sem) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) sem; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1176,7 +1176,7 @@ inline static sg_size_t simcall_BODY_file_read(smx_file_t fd, sg_size_t size, sg self->simcall.args[1].sgsz = (sg_size_t) size; self->simcall.args[2].dp = (void*) host; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1199,7 +1199,7 @@ inline static sg_size_t simcall_BODY_file_write(smx_file_t fd, sg_size_t size, s self->simcall.args[1].sgsz = (sg_size_t) size; self->simcall.args[2].dp = (void*) host; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1221,7 +1221,7 @@ inline static smx_file_t simcall_BODY_file_open(const char* fullpath, sg_host_t self->simcall.args[0].cc = (const char*) fullpath; self->simcall.args[1].dp = (void*) host; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1243,7 +1243,7 @@ inline static int simcall_BODY_file_close(smx_file_t fd, sg_host_t host) { self->simcall.args[0].dp = (void*) fd; self->simcall.args[1].dp = (void*) host; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1265,7 +1265,7 @@ inline static int simcall_BODY_file_unlink(smx_file_t fd, sg_host_t host) { self->simcall.args[0].dp = (void*) fd; self->simcall.args[1].dp = (void*) host; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1286,7 +1286,7 @@ inline static sg_size_t simcall_BODY_file_get_size(smx_file_t fd) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) fd; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1307,7 +1307,7 @@ inline static sg_size_t simcall_BODY_file_tell(smx_file_t fd) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) fd; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1330,7 +1330,7 @@ inline static int simcall_BODY_file_seek(smx_file_t fd, sg_offset_t offset, int self->simcall.args[1].sgoff = (sg_offset_t) offset; self->simcall.args[2].i = (int) origin; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1351,7 +1351,7 @@ inline static xbt_dynar_t simcall_BODY_file_get_info(smx_file_t fd) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) fd; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1373,7 +1373,7 @@ inline static int simcall_BODY_file_move(smx_file_t fd, const char* fullpath) { self->simcall.args[0].dp = (void*) fd; self->simcall.args[1].cc = (const char*) fullpath; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1394,7 +1394,7 @@ inline static sg_size_t simcall_BODY_storage_get_free_size(smx_storage_t storage memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) storage; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1415,7 +1415,7 @@ inline static sg_size_t simcall_BODY_storage_get_used_size(smx_storage_t name) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) name; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1436,7 +1436,7 @@ inline static xbt_dict_t simcall_BODY_storage_get_properties(smx_storage_t stora memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) storage; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1457,7 +1457,7 @@ inline static xbt_dict_t simcall_BODY_storage_get_content(smx_storage_t storage) memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) storage; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1478,7 +1478,7 @@ inline static xbt_dict_t simcall_BODY_asr_get_properties(const char* name) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].cc = (const char*) name; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1500,7 +1500,7 @@ inline static int simcall_BODY_mc_random(int min, int max) { self->simcall.args[0].i = (int) min; self->simcall.args[1].i = (int) max; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1522,7 +1522,7 @@ inline static void simcall_BODY_set_category(smx_synchro_t synchro, const char* self->simcall.args[0].dp = (void*) synchro; self->simcall.args[1].cc = (const char*) category; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { @@ -1543,7 +1543,7 @@ inline static void simcall_BODY_run_kernel(void* code) { memset(self->simcall.args, 0, sizeof(self->simcall.args)); self->simcall.args[0].dp = (void*) code; if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, + XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(), SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); SIMIX_process_yield(self); } else { diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index dbfb7f9bbd..9771e894a2 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -631,12 +631,12 @@ void SIMIX_display_process_status(void) */ XBT_INFO("Process %lu (%s@%s): waiting for %s synchro %p (%s) in state %d to finish", - process->pid, process->name, sg_host_get_name(process->host), + process->pid, process->name.c_str(), sg_host_get_name(process->host), synchro_description, process->waiting_synchro, process->waiting_synchro->name, (int)process->waiting_synchro->state); } else { - XBT_INFO("Process %lu (%s@%s)", process->pid, process->name, sg_host_get_name(process->host)); + XBT_INFO("Process %lu (%s@%s)", process->pid, process->name.c_str(), sg_host_get_name(process->host)); } } } diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 24adbc5c09..1fdde2763f 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -49,31 +49,25 @@ void SIMIX_host_on(sg_host_t h) unsigned int cpt; smx_process_arg_t arg; xbt_dynar_foreach(host->boot_processes,cpt,arg) { - - char** argv = xbt_new(char*, arg->argc); - for (int i=0; iargc; i++) - argv[i] = xbt_strdup(arg->argv[i]); - - XBT_DEBUG("Booting Process %s(%s) right now", arg->argv[0], arg->hostname); + XBT_DEBUG("Booting Process %s(%s) right now", + arg->name.c_str(), arg->hostname); if (simix_global->create_process_function) { - simix_global->create_process_function(argv[0], + simix_global->create_process_function(arg->name.c_str(), arg->code, NULL, arg->hostname, arg->kill_time, - arg->argc, - argv, + arg->args.argc(), arg->args.to_argv(), arg->properties, arg->auto_restart, NULL); } else { - simcall_process_create(arg->argv[0], + simcall_process_create(arg->name.c_str(), arg->code, NULL, arg->hostname, arg->kill_time, - arg->argc, - argv, + arg->args.argc(), arg->args.to_argv(), arg->properties, arg->auto_restart); } @@ -100,11 +94,13 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer) smx_process_t process = NULL; xbt_swag_foreach(process, host->process_list) { SIMIX_process_kill(process, issuer); - XBT_DEBUG("Killing %s on %s by %s", process->name, sg_host_get_name(process->host), issuer->name); + XBT_DEBUG("Killing %s on %s by %s", + process->name.c_str(), sg_host_get_name(process->host), + issuer->name.c_str()); } } } else { - XBT_INFO("Host %s is already off",h->name().c_str()); + XBT_INFO("Host %s is already off", h->name().c_str()); } } @@ -126,7 +122,7 @@ void SIMIX_host_destroy(void *h) smx_process_t process = NULL; xbt_swag_foreach(process, host->process_list) { - tmp = bprintf("%s\n\t%s", msg, process->name); + tmp = bprintf("%s\n\t%s", msg, process->name.c_str()); free(msg); msg = tmp; } @@ -162,9 +158,6 @@ const char* SIMIX_host_self_get_name(void) void _SIMIX_host_free_process_arg(void *data) { smx_process_arg_t arg = *(smx_process_arg_t*)data; - for (int i = 0; i < arg->argc; i++) - xbt_free(arg->argv[i]); - xbt_free(arg->argv); delete arg; } /** @@ -193,14 +186,7 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host, arg->data = data; arg->hostname = hostname; arg->kill_time = kill_time; - arg->argc = argc; - - arg->argv = xbt_new(char*,argc + 1); - - for (int i = 0; i < argc; i++) - arg->argv[i] = xbt_strdup(argv[i]); - arg->argv[argc] = NULL; - + arg->args.assign(argc, argv); arg->properties = properties; arg->auto_restart = auto_restart; @@ -223,35 +209,27 @@ void SIMIX_host_autorestart(sg_host_t host) xbt_dynar_foreach (process_list, cpt, arg) { - XBT_DEBUG("Restarting Process %s(%s) right now", arg->argv[0], arg->hostname); + XBT_DEBUG("Restarting Process %s(%s) right now", arg->name.c_str(), arg->hostname); if (simix_global->create_process_function) { - simix_global->create_process_function(arg->argv[0], + simix_global->create_process_function(arg->name.c_str(), arg->code, NULL, arg->hostname, arg->kill_time, - arg->argc, - arg->argv, + arg->args.argc(), arg->args.to_argv(), arg->properties, arg->auto_restart, NULL); } else { - simcall_process_create(arg->argv[0], + simcall_process_create(arg->name.c_str(), (xbt_main_func_t) arg->code, NULL, arg->hostname, arg->kill_time, - arg->argc, - arg->argv, + arg->args.argc(), arg->args.to_argv(), arg->properties, arg->auto_restart); - } - /* arg->argv is used by the process created above. Hide it to - * _SIMIX_host_free_process_arg() which is called by xbt_dynar_reset() - * below. */ - arg->argc = 0; - arg->argv = NULL; } xbt_dynar_reset(process_list); } diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index ebccbd1a17..569d72f0b1 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -550,10 +550,10 @@ static inline void SIMIX_comm_start(smx_synchro_t synchro) if (SIMIX_process_is_suspended(comm->src_proc) || SIMIX_process_is_suspended(comm->dst_proc)) { if (SIMIX_process_is_suspended(comm->src_proc)) XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the communication", - comm->src_proc->name, sg_host_get_name(comm->src_proc->host)); + comm->src_proc->name.c_str(), sg_host_get_name(comm->src_proc->host)); else XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the communication", - comm->dst_proc->name, sg_host_get_name(comm->dst_proc->host)); + comm->dst_proc->name.c_str(), sg_host_get_name(comm->dst_proc->host)); comm->surf_comm->suspend(); } @@ -635,7 +635,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro) synchro, comm->src_proc ? sg_host_get_name(comm->src_proc->host) : NULL, comm->dst_proc ? sg_host_get_name(comm->dst_proc->host) : NULL, - simcall->issuer->name, simcall->issuer, comm->detached); + simcall->issuer->name.c_str(), simcall->issuer, comm->detached); if (comm->src_proc == simcall->issuer) { XBT_DEBUG("I'm source"); } else if (comm->dst_proc == simcall->issuer) { diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 0effb83035..76ec52f9f8 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -55,7 +55,7 @@ int SIMIX_process_has_pending_comms(smx_process_t process) { void SIMIX_process_cleanup(smx_process_t process) { XBT_DEBUG("Cleanup process %s (%p), waiting synchro %p", - process->name, process, process->waiting_synchro); + process->name.c_str(), process, process->waiting_synchro); SIMIX_process_on_exit_runall(process); @@ -135,7 +135,6 @@ void SIMIX_process_empty_trash(void) xbt_dynar_free(&process->on_exit); - xbt_free(process->name); delete process; } } @@ -150,7 +149,7 @@ void create_maestro(std::function code) maestro = new simgrid::simix::Process(); maestro->pid = simix_process_maxpid++; maestro->ppid = -1; - maestro->name = (char*) ""; + maestro->name = ""; maestro->data = nullptr; maestro->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t)); XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx); @@ -191,13 +190,15 @@ void SIMIX_process_stop(smx_process_t arg) { SIMIX_process_on_exit_runall(arg); /* Add the process to the list of process to restart, only if the host is down */ if (arg->auto_restart && arg->host->isOff()) { - SIMIX_host_add_auto_restart_process(arg->host,arg->name,arg->code, arg->data, + SIMIX_host_add_auto_restart_process(arg->host, arg->name.c_str(), + arg->code, arg->data, sg_host_get_name(arg->host), SIMIX_timer_get_date(arg->kill_timer), - arg->argc,arg->argv,arg->properties, + arg->args.argc(), arg->args.argv(), arg->properties, arg->auto_restart); } - XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_get_name(arg->host)); + XBT_DEBUG("Process %s (%s) is dead", + arg->name.c_str(), sg_host_get_name(arg->host)); arg->context->stop(); } @@ -259,7 +260,7 @@ smx_process_t SIMIX_process_create( xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters"); /* Process data */ process->pid = simix_process_maxpid++; - process->name = xbt_strdup(name); + process->name = std::string(name); process->host = host; process->data = data; process->comms = xbt_fifo_new(); @@ -287,15 +288,17 @@ smx_process_t SIMIX_process_create( /* Process data for auto-restart */ process->auto_restart = auto_restart; process->code = code; - process->argc = argc; - process->argv = argv; + process->args.assign(argc, argv); - - XBT_VERB("Create context %s", process->name); + XBT_VERB("Create context %s", process->name.c_str()); process->context = SIMIX_context_new( simgrid::simix::wrap_main(code, argc, argv), simix_global->cleanup_process_function, process); + for (int i = 0; i < argc; i++) + free(argv[i]); + free(argv); + process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t)); XBT_RUNNING_CTX_INITIALIZE(process->running_ctx); @@ -309,21 +312,22 @@ smx_process_t SIMIX_process_create( /* Add the process to it's host process list */ xbt_swag_insert(process, sg_host_simix(host)->process_list); - XBT_DEBUG("Start context '%s'", process->name); + XBT_DEBUG("Start context '%s'", process->name.c_str()); /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(process, simix_global->process_list); - XBT_DEBUG("Inserting %s(%s) in the to_run list", process->name, sg_host_get_name(host)); + XBT_DEBUG("Inserting %s(%s) in the to_run list", + process->name.c_str(), sg_host_get_name(host)); xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) { - XBT_DEBUG("Process %s(%s) will be kill at time %f", process->name, - sg_host_get_name(process->host), kill_time); + XBT_DEBUG("Process %s(%s) will be kill at time %f", + process->name.c_str(), sg_host_get_name(process->host), kill_time); process->kill_timer = SIMIX_timer_set(kill_time, kill_process, process); } /* Tracing the process creation */ - TRACE_msg_process_create(process->name, process->pid, process->host); + TRACE_msg_process_create(process->name.c_str(), process->pid, process->host); } return process; } @@ -350,7 +354,7 @@ smx_process_t SIMIX_process_attach( smx_process_t process = new simgrid::simix::Process(); /* Process data */ process->pid = simix_process_maxpid++; - process->name = xbt_strdup(name); + process->name = std::string(name); process->host = host; process->data = data; process->comms = xbt_fifo_new(); @@ -376,10 +380,8 @@ smx_process_t SIMIX_process_attach( /* Process data for auto-restart */ process->auto_restart = false; process->code = nullptr; - process->argc = 0; - process->argv = nullptr; - XBT_VERB("Create context %s", process->name); + XBT_VERB("Create context %s", process->name.c_str()); if (!simix_global) xbt_die("simix is not initialized, please call MSG_init first"); process->context = simix_global->context_factory->attach( @@ -400,11 +402,12 @@ smx_process_t SIMIX_process_attach( /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(process, simix_global->process_list); - XBT_DEBUG("Inserting %s(%s) in the to_run list", process->name, sg_host_get_name(host)); + XBT_DEBUG("Inserting %s(%s) in the to_run list", + process->name.c_str(), sg_host_get_name(host)); xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); /* Tracing the process creation */ - TRACE_msg_process_create(process->name, process->pid, process->host); + TRACE_msg_process_create(process->name.c_str(), process->pid, process->host); auto context = dynamic_cast(process->context); if (!context) @@ -465,7 +468,8 @@ void simcall_HANDLER_process_kill(smx_simcall_t simcall, smx_process_t process) */ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { - XBT_DEBUG("Killing process %s on %s", process->name, sg_host_get_name(process->host)); + XBT_DEBUG("Killing process %s on %s", + process->name.c_str(), sg_host_get_name(process->host)); process->context->iwannadie = 1; process->blocked = 0; @@ -511,7 +515,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { process->waiting_synchro = NULL; } if(!xbt_dynar_member(simix_global->process_to_run, &(process)) && process != issuer) { - XBT_DEBUG("Inserting %s in the to_run list", process->name); + XBT_DEBUG("Inserting %s in the to_run list", process->name.c_str()); xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); } @@ -547,7 +551,7 @@ void SIMIX_process_throw(smx_process_t process, xbt_errcat_t cat, int value, con if (sleep != nullptr) { SIMIX_process_sleep_destroy(process->waiting_synchro); if (!xbt_dynar_member(simix_global->process_to_run, &(process)) && process != SIMIX_process_self()) { - XBT_DEBUG("Inserting %s in the to_run list", process->name); + XBT_DEBUG("Inserting %s in the to_run list", process->name.c_str()); xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); } } @@ -622,7 +626,7 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_process_t proces smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer) { if (process->suspended) { - XBT_DEBUG("Process '%s' is already suspended", process->name); + XBT_DEBUG("Process '%s' is already suspended", process->name.c_str()); return NULL; } @@ -742,16 +746,14 @@ const char* SIMIX_process_self_get_name(void) { const char* SIMIX_process_get_name(smx_process_t process) { - return process->name; + return process->name.c_str(); } smx_process_t SIMIX_process_get_by_name(const char* name) { smx_process_t proc; - - xbt_swag_foreach(proc, simix_global->process_list) - { - if(!strcmp(name, proc->name)) + xbt_swag_foreach(proc, simix_global->process_list) { + if (proc->name == name) return proc; } return NULL; @@ -859,13 +861,13 @@ void SIMIX_process_sleep_destroy(smx_synchro_t synchro) */ void SIMIX_process_yield(smx_process_t self) { - XBT_DEBUG("Yield process '%s'", self->name); + XBT_DEBUG("Yield process '%s'", self->name.c_str()); /* Go into sleep and return control to maestro */ self->context->suspend(); /* Ok, maestro returned control to us */ - XBT_DEBUG("Control returned to me: '%s'", self->name); + XBT_DEBUG("Control returned to me: '%s'", self->name.c_str()); if (self->new_host) { SIMIX_process_change_host(self, self->new_host); @@ -988,53 +990,38 @@ smx_process_t simcall_HANDLER_process_restart(smx_simcall_t simcall, smx_process } /** @brief Restart a process, starting it again from the beginning. */ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) { - XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_get_name(process->host)); + XBT_DEBUG("Restarting process %s on %s", + process->name.c_str(), sg_host_get_name(process->host)); + //retrieve the arguments of the old process //FIXME: Factorize this with SIMIX_host_add_auto_restart_process ? simgrid::simix::ProcessArg arg; + arg.name = process->name; arg.code = process->code; arg.hostname = sg_host_get_name(process->host); arg.kill_time = SIMIX_timer_get_date(process->kill_timer); - arg.argc = process->argc; arg.data = process->data; - int i; - arg.argv = xbt_new(char*,process->argc + 1); - for (i = 0; i < arg.argc; i++) { - arg.argv[i] = xbt_strdup(process->argv[i]); - } - arg.argv[process->argc] = NULL; arg.properties = NULL; arg.auto_restart = process->auto_restart; + arg.args = process->args; + //kill the old process - SIMIX_process_kill(process,issuer); - //start the new process - smx_process_t new_process; - if (simix_global->create_process_function) { - new_process = simix_global->create_process_function( - arg.argv[0], - arg.code, - arg.data, - arg.hostname, - arg.kill_time, - arg.argc, - arg.argv, - arg.properties, - arg.auto_restart, - NULL); - } else { - new_process = simcall_process_create( - arg.argv[0], - arg.code, - arg.data, - arg.hostname, - arg.kill_time, - arg.argc, - arg.argv, - arg.properties, - arg.auto_restart); + SIMIX_process_kill(process, issuer); - } - return new_process; + //start the new process + if (simix_global->create_process_function) + return simix_global->create_process_function( + arg.name.c_str(), arg.code, arg.data, + arg.hostname, arg.kill_time, + arg.args.argc(), arg.args.to_argv(), + arg.properties, arg.auto_restart, + nullptr); + else + return simcall_process_create( + arg.name.c_str(), arg.code, arg.data, + arg.hostname, arg.kill_time, + arg.args.argc(), arg.args.to_argv(), + arg.properties, arg.auto_restart); } void SIMIX_segment_index_set(smx_process_t proc, int index){ diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 8803cd71a2..204eb3dc45 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -11,6 +11,7 @@ #include +#include #include "simgrid/simix.h" #include "popping_private.h" @@ -25,14 +26,13 @@ namespace simix { class ProcessArg { public: std::string name; - xbt_main_func_t code; - void *data; - const char *hostname; - int argc; - char **argv; - double kill_time; - xbt_dict_t properties; - unsigned auto_restart:1; + xbt_main_func_t code = nullptr; + simgrid::simix::args args; + void *data = nullptr; + const char *hostname = nullptr; + double kill_time = 0.0; + xbt_dict_t properties = nullptr; + bool auto_restart = false; }; class Process { @@ -46,7 +46,7 @@ public: unsigned long pid = 0; unsigned long ppid = 0; - char *name = nullptr; /**< @brief process name if any */ + std::string name; sg_host_t host = nullptr; /* the host on which the process is running */ smx_context_t context = nullptr; /* the context (uctx/raw/thread) that executes the user function */ xbt_running_ctx_t *running_ctx = nullptr; @@ -66,8 +66,7 @@ public: xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */ xbt_main_func_t code = nullptr; - int argc = 0; - char **argv = nullptr; + simgrid::simix::args args; smx_timer_t kill_timer = nullptr; int segment_index = 0; /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/ }; diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index ba2d44483d..7b417fcd46 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -203,7 +203,7 @@ void SIMIX_vm_suspend(sg_host_t ind_vm, smx_process_t issuer) smx_process_t smx_process, smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(ind_vm)->process_list) { - XBT_DEBUG("suspend %s", smx_process->name); + XBT_DEBUG("suspend %s", smx_process->name.c_str()); SIMIX_process_suspend(smx_process, issuer); } @@ -243,7 +243,7 @@ void SIMIX_vm_resume(sg_host_t ind_vm, smx_process_t issuer) smx_process_t smx_process, smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(ind_vm)->process_list) { - XBT_DEBUG("resume %s", smx_process->name); + XBT_DEBUG("resume %s", smx_process->name.c_str()); SIMIX_process_resume(smx_process, issuer); } } @@ -276,7 +276,7 @@ void SIMIX_vm_save(sg_host_t ind_vm, smx_process_t issuer) smx_process_t smx_process, smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(ind_vm)->process_list) { - XBT_DEBUG("suspend %s", smx_process->name); + XBT_DEBUG("suspend %s", smx_process->name.c_str()); SIMIX_process_suspend(smx_process, issuer); } } @@ -307,7 +307,7 @@ void SIMIX_vm_restore(sg_host_t ind_vm, smx_process_t issuer) smx_process_t smx_process, smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(ind_vm)->process_list) { - XBT_DEBUG("resume %s", smx_process->name); + XBT_DEBUG("resume %s", smx_process->name.c_str()); SIMIX_process_resume(smx_process, issuer); } } @@ -337,7 +337,7 @@ void SIMIX_vm_shutdown(sg_host_t ind_vm, smx_process_t issuer) smx_process_t smx_process, smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(ind_vm)->process_list) { - XBT_DEBUG("kill %s", smx_process->name); + XBT_DEBUG("kill %s", smx_process->name.c_str()); SIMIX_process_kill(smx_process, issuer); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 3ac46e59d0..8ccd61c856 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -576,15 +576,11 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) smx_process_t process_created = NULL; arg = new simgrid::simix::ProcessArg(); + arg->name = std::string(process->argv[0]); arg->code = parse_code; arg->data = NULL; arg->hostname = sg_host_get_name(host); - arg->argc = process->argc; - arg->argv = xbt_new(char *,process->argc); - int i; - for (i=0; iargc; i++) - arg->argv[i] = xbt_strdup(process->argv[i]); - arg->name = arg->argv[0]; + arg->args.assign(process->argc, process->argv); arg->kill_time = kill_time; arg->properties = current_property_set; if (!sg_host_simix(host)->boot_processes) @@ -594,12 +590,11 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) if (start_time > SIMIX_get_clock()) { arg = new simgrid::simix::ProcessArg(); - arg->name = process->argv[0]; + arg->name = std::string(process->argv[0]); arg->code = parse_code; arg->data = NULL; arg->hostname = sg_host_get_name(host); - arg->argc = process->argc; - arg->argv = (char**)(process->argv); + arg->args.assign(process->argc, process->argv); arg->kill_time = kill_time; arg->properties = current_property_set; @@ -613,8 +608,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) arg->data, arg->hostname, arg->kill_time, - arg->argc, - arg->argv, + arg->args.argc(), arg->args.to_argv(), arg->properties, arg->auto_restart, NULL); @@ -631,14 +625,13 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) NULL, sg_host_get_name(host), kill_time, - process->argc, - (char**)(process->argv), + arg->args.argc(), arg->args.to_argv(), current_property_set, auto_restart, NULL); else process_created = simcall_process_create( - arg->name.c_str(), parse_code, NULL, sg_host_get_name(host), kill_time, process->argc, - (char**)process->argv, current_property_set,auto_restart); + arg->name.c_str(), parse_code, NULL, sg_host_get_name(host), kill_time, + arg->args.argc(), arg->args.to_argv(), current_property_set,auto_restart); /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */ if (!process_created) { -- 2.20.1