Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further untangle the msg_process creation by using a default value for auto_restart
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 16 Feb 2017 01:42:18 +0000 (02:42 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 16 Feb 2017 01:42:18 +0000 (02:42 +0100)
include/simgrid/simix.h
include/simgrid/simix.hpp
src/msg/msg_private.h
src/msg/msg_process.cpp
src/s4u/s4u_actor.cpp
src/simix/ActorImpl.cpp
src/simix/ActorImpl.hpp
src/simix/smx_host.cpp
src/surf/sg_platf.cpp
teshsuite/simix/generic_simcalls/generic_simcalls.cpp
teshsuite/simix/stack_overflow/stack_overflow.c

index 1e1e16a..69c50e7 100644 (file)
@@ -258,13 +258,9 @@ XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution);
 
 /**************************** Process simcalls ********************************/
 /* Constructor and Destructor */
-XBT_PUBLIC(smx_actor_t) simcall_process_create(const char *name,
-                                          xbt_main_func_t code,
-                                          void *data,
-                                          sg_host_t host,
-                                          int argc, char **argv,
-                                          xbt_dict_t properties,
-                                          int auto_restart);
+XBT_PUBLIC(smx_actor_t)
+simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc, char** argv,
+                       xbt_dict_t properties);
 
 XBT_PUBLIC(void) simcall_process_kill(smx_actor_t process);
 XBT_PUBLIC(void) simcall_process_killall(int reset_pid);
index ca60939..a09f323 100644 (file)
@@ -112,18 +112,13 @@ typedef smx_actor_t (*smx_creation_func_t) (
                                       /* userdata */ void*,
                                       /* hostname */ sg_host_t,
                                       /* props */ xbt_dict_t,
-                                      /* auto_restart */ int,
                                       /* parent_process */ smx_actor_t);
 
 extern "C"
 XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function);
 
-XBT_PUBLIC(smx_actor_t) simcall_process_create(const char *name,
-                                          std::function<void()> code,
-                                          void *data,
-                                          sg_host_t host,
-                                          xbt_dict_t properties,
-                                          int auto_restart);
+XBT_PUBLIC(smx_actor_t)
+simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host, xbt_dict_t properties);
 
 XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback);
 
index e24bfe0..3209072 100644 (file)
@@ -117,7 +117,7 @@ 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<void()> code, void* data,
-                                                      sg_host_t host, xbt_dict_t properties, int auto_restart,
+                                                      sg_host_t host, xbt_dict_t properties,
                                                       smx_actor_t parent_process);
 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
 
index e8cb1c5..1c36688 100644 (file)
@@ -51,12 +51,9 @@ 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<void()> code, void* data, sg_host_t host,
-                                          xbt_dict_t properties, int auto_restart, smx_actor_t parent_process)
+                                          xbt_dict_t properties, 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_auto_restart_set(p,auto_restart);
-  }
   return p;
 }
 
@@ -140,17 +137,14 @@ msg_process_t MSG_process_create_with_environment(
   xbt_assert(code != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr");
   MsgActorExt* msgExt = new MsgActorExt(data);
 
-  /* 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, properties, 0);
+  msg_process_t process = simcall_process_create(name, std::move(code), msgExt, host, properties);
 
   if (!process) { /* Undo everything */
     delete msgExt;
     return nullptr;
   }
-  else {
-    simcall_process_on_exit(process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,process);
-  }
+
+  simcall_process_on_exit(process, (int_f_pvoid_pvoid_t)TRACE_msg_process_kill, process);
   return process;
 }
 
index 4d082c1..3f1c2b8 100644 (file)
@@ -30,18 +30,16 @@ ActorPtr Actor::self()
 
 ActorPtr Actor::createActor(const char* name, s4u::Host* host, std::function<void()> 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, nullptr, 0);
-  return ActorPtr(&process->getIface());
+  smx_actor_t actor = simcall_process_create(name, std::move(code), nullptr, host, nullptr);
+  return ActorPtr(&actor->getIface());
 }
 
 ActorPtr Actor::createActor(const char* name, s4u::Host* host, const char* function, std::vector<std::string> 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, nullptr, 0);
-  return ActorPtr(&process->getIface());
+  smx_actor_t actor                         = simcall_process_create(name, std::move(code), nullptr, host, nullptr);
+  return ActorPtr(&actor->getIface());
 }
 
 // ***** Actor methods *****
index 8fdad95..a5410cc 100644 (file)
@@ -219,7 +219,6 @@ smx_actor_t SIMIX_process_create(
                           void *data,
                           sg_host_t host,
                           xbt_dict_t properties,
-                          int auto_restart,
                           smx_actor_t parent_process)
 {
   smx_actor_t process = nullptr;
@@ -260,30 +259,27 @@ smx_actor_t SIMIX_process_create(
        process->ppid = -1;
      }
 
-    /* Process data for auto-restart */
-    process->auto_restart = auto_restart;
-    process->code = code;
+     process->auto_restart = false;
+     process->code         = code;
 
-    XBT_VERB("Create context %s", process->name.c_str());
-    process->context = SIMIX_context_new(
-      std::move(code),
-      simix_global->cleanup_process_function, process);
+     XBT_VERB("Create context %s", process->name.c_str());
+     process->context = SIMIX_context_new(std::move(code), simix_global->cleanup_process_function, process);
 
-    /* Add properties */
-    process->properties = properties;
+     /* Add properties */
+     process->properties = properties;
 
-    /* Add the process to it's host process list */
-    xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+     /* Add the process to it's host process list */
+     xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
 
-    XBT_DEBUG("Start context '%s'", process->name.c_str());
+     XBT_DEBUG("Start context '%s'", process->name.c_str());
 
-    /* Now insert it in the global process list and in the process to run list */
-    simix_global->process_list[process->pid] = process;
-    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);
+     /* Now insert it in the global process list and in the process to run list */
+     simix_global->process_list[process->pid] = process;
+     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);
 
-    /* Tracing the process creation */
-    TRACE_msg_process_create(process->cname(), process->pid, process->host);
+     /* Tracing the process creation */
+     TRACE_msg_process_create(process->cname(), process->pid, process->host);
   }
   return process;
 }
@@ -923,9 +919,11 @@ smx_actor_t SIMIX_process_restart(smx_actor_t process, smx_actor_t issuer) {
 
   //start the new process
   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);
+                                                            arg.properties, nullptr);
   if (arg.kill_time >= 0)
     simcall_process_set_kill_time(actor, arg.kill_time);
+  if (arg.auto_restart)
+    simcall_process_auto_restart_set(actor, arg.auto_restart);
 
   return actor;
 }
@@ -951,13 +949,8 @@ void SIMIX_segment_index_set(smx_actor_t proc, int index){
  * \param properties the properties of the process
  * \param auto_restart either it is autorestarting or not.
  */
-smx_actor_t simcall_process_create(const char *name,
-                              xbt_main_func_t code,
-                              void *data,
-                              sg_host_t host,
-                              int argc, char **argv,
-                              xbt_dict_t properties,
-                              int auto_restart)
+smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc,
+                                   char** argv, xbt_dict_t properties)
 {
   if (name == nullptr)
     name = "";
@@ -965,17 +958,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, properties, auto_restart);
+  smx_actor_t res = simcall_process_create(name, std::move(wrapped_code), data, host, properties);
   return res;
 }
 
 smx_actor_t simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
-                                   xbt_dict_t properties, int auto_restart)
+                                   xbt_dict_t properties)
 {
   if (name == nullptr)
     name = "";
   smx_actor_t self = SIMIX_process_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);
+  return simgrid::simix::kernelImmediate([name, code, data, host, properties, self] {
+    return SIMIX_process_create(name, std::move(code), data, host, properties, self);
   });
 }
index de7ad9e..5c40a41 100644 (file)
@@ -105,7 +105,6 @@ XBT_PRIVATE smx_actor_t SIMIX_process_create(
                           void *data,
                           sg_host_t host,
                           xbt_dict_t properties,
-                          int auto_restart,
                           smx_actor_t parent_process);
 
 XBT_PRIVATE void SIMIX_process_runall();
index e263ffa..eca8a19 100644 (file)
@@ -60,9 +60,11 @@ namespace simgrid {
       for (auto arg : boot_processes) {
         XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->cname());
         smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host,
-                                                                  arg->properties, arg->auto_restart, nullptr);
+                                                                  arg->properties, nullptr);
         if (arg->kill_time >= 0)
           simcall_process_set_kill_time(actor, arg->kill_time);
+        if (arg->auto_restart)
+          simcall_process_auto_restart_set(actor, arg->auto_restart);
       }
     }
 
@@ -142,9 +144,11 @@ 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());
     smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host,
-                                                              arg->properties, arg->auto_restart, nullptr);
+                                                              arg->properties, nullptr);
     if (arg->kill_time >= 0)
       simcall_process_set_kill_time(actor, arg->kill_time);
+    if (arg->auto_restart)
+      simcall_process_auto_restart_set(actor, arg->auto_restart);
   }
   process_list.clear();
 }
index 94fb072..6303d9c 100644 (file)
@@ -497,7 +497,6 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
   std::function<void()> code = factory(std::move(args));
 
   smx_process_arg_t arg = nullptr;
-  smx_actor_t process_created = nullptr;
 
   arg = new simgrid::simix::ProcessArg();
   arg->name = std::string(process->argv[0]);
@@ -520,25 +519,28 @@ 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, [arg]() {
+    SIMIX_timer_set(start_time, [arg, auto_restart]() {
       smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(arg->code), arg->data,
-                                                                arg->host, arg->properties, arg->auto_restart, nullptr);
+                                                                arg->host, arg->properties, nullptr);
       if (arg->kill_time >= 0)
         simcall_process_set_kill_time(actor, arg->kill_time);
+      if (auto_restart)
+        SIMIX_process_auto_restart_set(actor, auto_restart);
       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,
-                                                            current_property_set, auto_restart, nullptr);
+    smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host,
+                                                              current_property_set, 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)
-      return;
-
-    if (arg->kill_time >= 0)
-      simcall_process_set_kill_time(process_created, arg->kill_time);
+    /* The actor creation will fail if the host is currently dead, but that's fine */
+    if (actor != nullptr) {
+      if (arg->kill_time >= 0)
+        simcall_process_set_kill_time(actor, arg->kill_time);
+      if (auto_restart)
+        SIMIX_process_auto_restart_set(actor, auto_restart);
+    }
   }
   current_property_set = nullptr;
 }
index 9477e44..1b87257 100644 (file)
@@ -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"), 0, NULL, NULL, 0);
+  simcall_process_create("master", example::master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL);
   SIMIX_run();
   return 0;
 }
index df7ccd9..bb8b899 100644 (file)
@@ -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"), 0, NULL, NULL, 0);
+  simcall_process_create("master", master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL);
   SIMIX_run();
 
   return 0;