From: Frederic Suter Date: Fri, 24 Mar 2017 16:23:33 +0000 (+0100) Subject: TESH: msg to s4u - act 1 X-Git-Tag: v3.16~452 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/db176451b42c9d524f82e6bb9951447e098dd492 TESH: msg to s4u - act 1 --- diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index e57c18555a..58e1b4b76e 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -220,6 +220,12 @@ public: /** If set to true, the actor will automatically restart when its host reboots */ void setAutoRestart(bool autorestart); + + /** Add a function to the list of "on_exit" functions for the current actor. The on_exit functions are the functions + * executed when your actor is killed. You should use them to free the data used by your process. + */ + void onExit(int_f_pvoid_pvoid_t fun, void* data); + /** Sets the time at which that actor should be killed */ void setKillTime(double time); /** Retrieves the time at which that actor will be killed (or -1 if not set) */ @@ -249,6 +255,7 @@ public: /** Ask kindly to all actors to die. Only the issuer will survive. */ static void killAll(); + static void killAll(int resetPid); /** Returns the internal implementation of this actor */ simix::ActorImpl* getImpl(); @@ -317,6 +324,9 @@ namespace this_actor { /** @brief kill the actor. */ XBT_PUBLIC(void) kill(); + /** @brief Add a function to the list of "on_exit" functions. */ + XBT_PUBLIC(void) onExit(int_f_pvoid_pvoid_t fun, void* data); + /** @brief Migrate the actor to a new host. */ XBT_PUBLIC(void) migrate(Host* new_host); }; diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 1c171d590d..4a3141e567 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -52,6 +52,11 @@ void Actor::setAutoRestart(bool autorestart) { simcall_process_auto_restart_set(pimpl_,autorestart); } +void Actor::onExit(int_f_pvoid_pvoid_t fun, void* data) +{ + simcall_process_on_exit(pimpl_, fun, data); +} + void Actor::migrate(Host* new_host) { simcall_process_set_host(pimpl_, new_host); @@ -131,10 +136,16 @@ ActorPtr Actor::byPid(int pid) return ActorPtr(); } -void Actor::killAll() { +void Actor::killAll() +{ simcall_process_killall(1); } +void Actor::killAll(int resetPid) +{ + simcall_process_killall(resetPid); +} + // ***** this_actor ***** namespace this_actor { @@ -209,6 +220,11 @@ void kill() simcall_process_kill(SIMIX_process_self()); } +void onExit(int_f_pvoid_pvoid_t fun, void* data) +{ + simcall_process_on_exit(SIMIX_process_self(), fun, data); +} + void migrate(Host* new_host) { simcall_process_set_host(SIMIX_process_self(), new_host); diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 24df2329ab..eb337340fb 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -1,5 +1,5 @@ # C examples -foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async pid +foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async storage_client_server trace_integration) add_executable (${x} ${x}/${x}.c) target_link_libraries(${x} simgrid) @@ -34,7 +34,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml PARENT_SCOPE) -foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async pid +foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async process storage_client_server task_destroy_cancel 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) endforeach() diff --git a/teshsuite/msg/pid/pid.c b/teshsuite/msg/pid/pid.c deleted file mode 100644 index ebe6b3afa1..0000000000 --- a/teshsuite/msg/pid/pid.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (c) 2009-2010, 2013-2015. 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. */ - -#include "simgrid/msg.h" - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -const char* mailbox = "mailbox"; -#define task_comp_size 1000 -#define task_comm_size 100000 - -static int my_onexit(smx_process_exit_status_t status, int *pid){ - XBT_INFO("Process \"%d\" killed.", *pid); - return 0; -} - -static int sendpid(int argc, char *argv[]) -{ - int pid = MSG_process_self_PID(); - MSG_process_on_exit((int_f_pvoid_pvoid_t)my_onexit, &pid); - msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid); - XBT_INFO("Sending pid of \"%d\".", pid); - MSG_task_send(task, mailbox); - XBT_INFO("Send of pid \"%d\" done.", pid); - MSG_process_suspend(MSG_process_self()); - return 0; -} - -static int killall(int argc, char *argv[]){ - msg_task_t task = NULL; - - for (int i=0; i<3;i++) { - MSG_task_receive(&(task), mailbox); - int pid = *(int*)MSG_task_get_data(task); - MSG_task_destroy(task); - XBT_INFO("Killing process \"%d\".", pid); - MSG_process_kill(MSG_process_from_PID(pid)); - task = NULL; - } - return 0; -} - -int main(int argc, char* argv[]) -{ - MSG_init(&argc, argv); - - xbt_assert(argc >= 2, "Usage: pid platform pid_to_kill"); - - MSG_process_killall(atoi(argv[2])); - - MSG_create_environment(argv[1]); - MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay")); - MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay")); - MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay")); - MSG_process_create("killall", killall, NULL, MSG_get_host_by_name("Tremblay")); - - return MSG_main() != MSG_OK; -} diff --git a/teshsuite/msg/pid/pid.tesh b/teshsuite/msg/pid/pid.tesh deleted file mode 100644 index 6752d80733..0000000000 --- a/teshsuite/msg/pid/pid.tesh +++ /dev/null @@ -1,27 +0,0 @@ -$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:sendpid@Tremblay) Sending pid of "1". -> [ 0.000000] (2:sendpid@Tremblay) Sending pid of "2". -> [ 0.000000] (3:sendpid@Tremblay) Sending pid of "3". -> [ 0.000402] (4:killall@Tremblay) Killing process "1". -> [ 0.000402] (1:sendpid@Tremblay) Send of pid "1" done. -> [ 0.000402] (1:sendpid@Tremblay) Process "1" killed. -> [ 0.000804] (2:sendpid@Tremblay) Send of pid "2" done. -> [ 0.000804] (4:killall@Tremblay) Killing process "2". -> [ 0.000804] (2:sendpid@Tremblay) Process "2" killed. -> [ 0.001206] (3:sendpid@Tremblay) Send of pid "3" done. -> [ 0.001206] (4:killall@Tremblay) Killing process "3". -> [ 0.001206] (3:sendpid@Tremblay) Process "3" killed. - -$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (2:sendpid@Tremblay) Sending pid of "2". -> [ 0.000000] (3:sendpid@Tremblay) Sending pid of "3". -> [ 0.000000] (4:sendpid@Tremblay) Sending pid of "4". -> [ 0.000402] (5:killall@Tremblay) Killing process "2". -> [ 0.000402] (2:sendpid@Tremblay) Send of pid "2" done. -> [ 0.000402] (2:sendpid@Tremblay) Process "2" killed. -> [ 0.000804] (3:sendpid@Tremblay) Send of pid "3" done. -> [ 0.000804] (5:killall@Tremblay) Killing process "3". -> [ 0.000804] (3:sendpid@Tremblay) Process "3" killed. -> [ 0.001206] (4:sendpid@Tremblay) Send of pid "4" done. -> [ 0.001206] (5:killall@Tremblay) Killing process "4". -> [ 0.001206] (4:sendpid@Tremblay) Process "4" killed. diff --git a/teshsuite/s4u/pid/pid.cpp b/teshsuite/s4u/pid/pid.cpp new file mode 100644 index 0000000000..4b45749d3e --- /dev/null +++ b/teshsuite/s4u/pid/pid.cpp @@ -0,0 +1,60 @@ +/* Copyright (c) 2009-2010, 2013-2015. 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. */ + +#include "simgrid/s4u.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this msg example"); + +simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox"); +double comp_size = 1000; +double comm_size = 100000; + +static int my_onexit(smx_process_exit_status_t status, int* pid) +{ + XBT_INFO("Process \"%d\" killed.", *pid); + return 0; +} + +static void sendpid() +{ + int pid = simgrid::s4u::this_actor::pid(); + simgrid::s4u::this_actor::onExit((int_f_pvoid_pvoid_t)my_onexit, &pid); + + XBT_INFO("Sending pid of \"%d\".", pid); + simgrid::s4u::this_actor::send(mailbox, &pid, comm_size); + XBT_INFO("Send of pid \"%d\" done.", pid); + + simgrid::s4u::this_actor::suspend(); +} + +static void killall() +{ + for (int i = 0; i < 3; i++) { + int* pid = static_cast(simgrid::s4u::this_actor::recv(mailbox)); + XBT_INFO("Killing process \"%d\".", *pid); + simgrid::s4u::Actor::byPid(*pid)->kill(); + } +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + e->loadPlatform(argv[1]); + + if (argc > 2) + simgrid::s4u::Actor::killAll(atoi(argv[2])); + else + simgrid::s4u::Actor::killAll(); + + simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid); + simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid); + simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid); + simgrid::s4u::Actor::createActor("killall", simgrid::s4u::Host::by_name("Tremblay"), killall); + + e->run(); + + return 0; +} diff --git a/teshsuite/s4u/pid/pid.tesh b/teshsuite/s4u/pid/pid.tesh new file mode 100644 index 0000000000..5826a28a21 --- /dev/null +++ b/teshsuite/s4u/pid/pid.tesh @@ -0,0 +1,27 @@ +$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" +> [ 0.000000] (sendpid@Tremblay) Sending pid of "1". +> [ 0.000000] (sendpid@Tremblay) Sending pid of "2". +> [ 0.000000] (sendpid@Tremblay) Sending pid of "3". +> [ 0.000402] (killall@Tremblay) Killing process "1". +> [ 0.000402] (sendpid@Tremblay) Send of pid "1" done. +> [ 0.000402] (sendpid@Tremblay) Process "1" killed. +> [ 0.000804] (sendpid@Tremblay) Send of pid "2" done. +> [ 0.000804] (killall@Tremblay) Killing process "2". +> [ 0.000804] (sendpid@Tremblay) Process "2" killed. +> [ 0.001206] (sendpid@Tremblay) Send of pid "3" done. +> [ 0.001206] (killall@Tremblay) Killing process "3". +> [ 0.001206] (sendpid@Tremblay) Process "3" killed. + +$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" +> [ 0.000000] (sendpid@Tremblay) Sending pid of "2". +> [ 0.000000] (sendpid@Tremblay) Sending pid of "3". +> [ 0.000000] (sendpid@Tremblay) Sending pid of "4". +> [ 0.000402] (killall@Tremblay) Killing process "2". +> [ 0.000402] (sendpid@Tremblay) Send of pid "2" done. +> [ 0.000402] (sendpid@Tremblay) Process "2" killed. +> [ 0.000804] (sendpid@Tremblay) Send of pid "3" done. +> [ 0.000804] (killall@Tremblay) Killing process "3". +> [ 0.000804] (sendpid@Tremblay) Process "3" killed. +> [ 0.001206] (sendpid@Tremblay) Send of pid "4" done. +> [ 0.001206] (killall@Tremblay) Killing process "4". +> [ 0.001206] (sendpid@Tremblay) Process "4" killed. diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index eeb58b7757..e7ab091d90 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -972,6 +972,7 @@ set(CMAKEFILES_TXT teshsuite/java/CMakeLists.txt teshsuite/mc/CMakeLists.txt teshsuite/msg/CMakeLists.txt + teshsuite/s4u/CMakeLists.txt teshsuite/simdag/CMakeLists.txt teshsuite/simix/CMakeLists.txt teshsuite/smpi/CMakeLists.txt