From: Martin Quinson Date: Thu, 16 Feb 2017 01:21:51 +0000 (+0100) Subject: start to untangle the MSG actor creation mess X-Git-Tag: v3_15~357 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0a95c78251f3ecbf1dfcb3ebe7904e44acf1beef start to untangle the MSG actor creation mess --- diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 2a768f341e..56567c440f 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -180,12 +180,7 @@ public: * * If the actor is restarted, the actor has a fresh copy of the function. */ - static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, std::function code); - - static ActorPtr createActor(const char* name, s4u::Host *host, std::function code) - { - return createActor(name, host, -1.0, std::move(code)); - } + static ActorPtr createActor(const char* name, s4u::Host* host, std::function code); /** Create an actor using code * @@ -205,14 +200,7 @@ public: // Create actor from function name: - static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, - const char* function, std::vector args); - - static ActorPtr createActor(const char* name, s4u::Host *host, const char* function, - std::vector args) - { - return createActor(name, host, -1.0, function, std::move(args)); - } + static ActorPtr createActor(const char* name, s4u::Host* host, const char* function, std::vector args); // ***** Methods ***** diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index b2b8b32d0c..1e1e16a8d9 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -262,7 +262,6 @@ XBT_PUBLIC(smx_actor_t) simcall_process_create(const char *name, xbt_main_func_t code, void *data, sg_host_t host, - double kill_time, int argc, char **argv, xbt_dict_t properties, int auto_restart); diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index b6b9a1cecf..ca6093962a 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -111,7 +111,6 @@ typedef smx_actor_t (*smx_creation_func_t) ( std::function code, /* userdata */ void*, /* hostname */ sg_host_t, - /* kill_time */ double, /* props */ xbt_dict_t, /* auto_restart */ int, /* parent_process */ smx_actor_t); @@ -123,7 +122,6 @@ XBT_PUBLIC(smx_actor_t) simcall_process_create(const char *name, std::function code, void *data, sg_host_t host, - double kill_time, xbt_dict_t properties, int auto_restart); diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 6f225e20f6..e24bfe0927 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -116,11 +116,9 @@ XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host); XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host); XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc); -XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char *name, - std::function code, void *data, - sg_host_t host, double kill_time, - xbt_dict_t properties, int auto_restart, - smx_actor_t parent_process); +XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, + sg_host_t host, xbt_dict_t properties, int auto_restart, + smx_actor_t parent_process); XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size); XBT_PRIVATE void MSG_post_create_environment(); diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 5bb743ba05..e8cb1c5bd7 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -50,14 +50,11 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor) } /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */ -smx_actor_t MSG_process_create_from_SIMIX( - const char *name, std::function code, void *data, sg_host_t host, - double kill_time, xbt_dict_t properties, - int auto_restart, smx_actor_t parent_process) +smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, sg_host_t host, + xbt_dict_t properties, int auto_restart, smx_actor_t parent_process) { msg_process_t p = MSG_process_create_with_environment(name, std::move(code), data, host, properties); if (p) { - MSG_process_set_kill_time(p,kill_time); MSG_process_auto_restart_set(p,auto_restart); } return p; @@ -145,7 +142,7 @@ msg_process_t MSG_process_create_with_environment( /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ - msg_process_t process = simcall_process_create(name, std::move(code), msgExt, host, -1, properties, 0); + msg_process_t process = simcall_process_create(name, std::move(code), msgExt, host, properties, 0); if (!process) { /* Undo everything */ delete msgExt; diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 58de67d35d..4d082c1e0b 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -28,23 +28,19 @@ ActorPtr Actor::self() return simgrid::s4u::ActorPtr(&self_context->process()->getIface()); } - -ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime, std::function code) +ActorPtr Actor::createActor(const char* name, s4u::Host* host, std::function code) { // TODO, when autorestart is used, the std::function is copied so the new // instance will get a fresh (reinitialized) state. Is this what we want? - smx_actor_t process = simcall_process_create( - name, std::move(code), nullptr, host, killTime, nullptr, 0); + smx_actor_t process = simcall_process_create(name, std::move(code), nullptr, host, nullptr, 0); return ActorPtr(&process->getIface()); } -ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime, - const char* function, std::vector args) +ActorPtr Actor::createActor(const char* name, s4u::Host* host, const char* function, std::vector args) { simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function); simgrid::simix::ActorCode code = factory(std::move(args)); - smx_actor_t process = simcall_process_create( - name, std::move(code), nullptr, host, killTime, nullptr, 0); + smx_actor_t process = simcall_process_create(name, std::move(code), nullptr, host, nullptr, 0); return ActorPtr(&process->getIface()); } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 4aaa713504..8fdad95a22 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -218,7 +218,6 @@ smx_actor_t SIMIX_process_create( std::function code, void *data, sg_host_t host, - double kill_time, xbt_dict_t properties, int auto_restart, smx_actor_t parent_process) @@ -283,13 +282,6 @@ smx_actor_t SIMIX_process_create( XBT_DEBUG("Inserting %s(%s) in the to_run list", process->cname(), host->cname()); xbt_dynar_push_as(simix_global->process_to_run, smx_actor_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->cname(), process->host->cname(), kill_time); - process->kill_timer = SIMIX_timer_set(kill_time, [=]() { - simix_global->kill_process_function(process); - }); - } - /* Tracing the process creation */ TRACE_msg_process_create(process->cname(), process->pid, process->host); } @@ -930,8 +922,12 @@ smx_actor_t SIMIX_process_restart(smx_actor_t process, smx_actor_t issuer) { SIMIX_process_kill(process, issuer); //start the new process - return simix_global->create_process_function(arg.name.c_str(), std::move(arg.code), arg.data, arg.host, - arg.kill_time, arg.properties, arg.auto_restart, nullptr); + smx_actor_t actor = simix_global->create_process_function(arg.name.c_str(), std::move(arg.code), arg.data, arg.host, + arg.properties, arg.auto_restart, nullptr); + if (arg.kill_time >= 0) + simcall_process_set_kill_time(actor, arg.kill_time); + + return actor; } void SIMIX_segment_index_set(smx_actor_t proc, int index){ @@ -959,7 +955,6 @@ smx_actor_t simcall_process_create(const char *name, xbt_main_func_t code, void *data, sg_host_t host, - double kill_time, int argc, char **argv, xbt_dict_t properties, int auto_restart) @@ -970,21 +965,17 @@ smx_actor_t simcall_process_create(const char *name, for (int i = 0; i != argc; ++i) xbt_free(argv[i]); xbt_free(argv); - smx_actor_t res = simcall_process_create(name, - std::move(wrapped_code), - data, host, kill_time, properties, auto_restart); + smx_actor_t res = simcall_process_create(name, std::move(wrapped_code), data, host, properties, auto_restart); return res; } -smx_actor_t simcall_process_create( - const char *name, std::function code, void *data, - sg_host_t host, double kill_time, - xbt_dict_t properties, int auto_restart) +smx_actor_t simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, + xbt_dict_t properties, int auto_restart) { if (name == nullptr) name = ""; smx_actor_t self = SIMIX_process_self(); - return simgrid::simix::kernelImmediate([name, code, data, host, kill_time, properties, auto_restart, self] { - return SIMIX_process_create(name, std::move(code), data, host, kill_time, properties, auto_restart, self); + return simgrid::simix::kernelImmediate([name, code, data, host, properties, auto_restart, self] { + return SIMIX_process_create(name, std::move(code), data, host, properties, auto_restart, self); }); } diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index add8ca3aca..de7ad9e1f6 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -104,7 +104,6 @@ XBT_PRIVATE smx_actor_t SIMIX_process_create( std::function code, void *data, sg_host_t host, - double kill_time, xbt_dict_t properties, int auto_restart, smx_actor_t parent_process); diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index a1461a2344..e263ffab5b 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -59,14 +59,10 @@ namespace simgrid { { for (auto arg : boot_processes) { XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->cname()); - simix_global->create_process_function(arg->name.c_str(), - arg->code, - nullptr, - arg->host, - arg->kill_time, - arg->properties, - arg->auto_restart, - nullptr); + smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, + arg->properties, arg->auto_restart, nullptr); + if (arg->kill_time >= 0) + simcall_process_set_kill_time(actor, arg->kill_time); } } @@ -145,8 +141,10 @@ void SIMIX_host_autorestart(sg_host_t host) for (auto arg : process_list) { XBT_DEBUG("Restarting Process %s@%s right now", arg->name.c_str(), arg->host->cname()); - simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, arg->kill_time, - arg->properties, arg->auto_restart, nullptr); + smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, + arg->properties, arg->auto_restart, nullptr); + if (arg->kill_time >= 0) + simcall_process_set_kill_time(actor, arg->kill_time); } process_list.clear(); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 7b0efe7da5..94fb072984 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -520,30 +520,25 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) arg->properties = current_property_set; XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->cname(), start_time); - SIMIX_timer_set(start_time, [=]() { - simix_global->create_process_function( - arg->name.c_str(), - std::move(arg->code), - arg->data, - arg->host, - arg->kill_time, - arg->properties, - arg->auto_restart, - nullptr); + SIMIX_timer_set(start_time, [arg]() { + smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(arg->code), arg->data, + arg->host, arg->properties, arg->auto_restart, nullptr); + if (arg->kill_time >= 0) + simcall_process_set_kill_time(actor, arg->kill_time); delete arg; }); } else { // start_time <= SIMIX_get_clock() XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->cname()); - process_created = simix_global->create_process_function( - arg->name.c_str(), std::move(code), nullptr, - host, kill_time, - current_property_set, auto_restart, nullptr); + process_created = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host, + current_property_set, auto_restart, nullptr); /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */ - if (!process_created) { + if (!process_created) return; - } + + if (arg->kill_time >= 0) + simcall_process_set_kill_time(process_created, arg->kill_time); } current_property_set = nullptr; } diff --git a/teshsuite/simix/generic_simcalls/generic_simcalls.cpp b/teshsuite/simix/generic_simcalls/generic_simcalls.cpp index 8d13517c0e..9477e443b5 100644 --- a/teshsuite/simix/generic_simcalls/generic_simcalls.cpp +++ b/teshsuite/simix/generic_simcalls/generic_simcalls.cpp @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]); SIMIX_function_register("master", example::master); SIMIX_create_environment(argv[1]); - simcall_process_create("master", example::master, NULL, sg_host_by_name("Tremblay"), -1, 0, NULL, NULL, 0); + simcall_process_create("master", example::master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL, 0); SIMIX_run(); return 0; } diff --git a/teshsuite/simix/stack_overflow/stack_overflow.c b/teshsuite/simix/stack_overflow/stack_overflow.c index 34318271f9..df7ccd95f2 100644 --- a/teshsuite/simix/stack_overflow/stack_overflow.c +++ b/teshsuite/simix/stack_overflow/stack_overflow.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) SIMIX_function_register("master", master); SIMIX_create_environment(argv[1]); - simcall_process_create("master", master, NULL, sg_host_by_name("Tremblay"), -1, 0, NULL, NULL, 0); + simcall_process_create("master", master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL, 0); SIMIX_run(); return 0;