Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Expose (and use) hostCreatedCallbacks in C
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 30 Nov 2015 13:15:47 +0000 (14:15 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 30 Nov 2015 14:34:00 +0000 (15:34 +0100)
12 files changed:
src/bindings/lua/lua_platf.c
src/msg/msg_environment.c
src/msg/msg_global.c
src/simgrid/host.cpp
src/simix/smx_environment.c
src/simix/smx_global.c
src/simix/smx_host.c
src/simix/smx_host_private.h
src/simix/smx_vm.c
src/surf/callbacks.cpp [new file with mode: 0644]
src/surf/callbacks.h [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

index 79f81fb..f0bb012 100644 (file)
@@ -56,23 +56,6 @@ int console_open(lua_State *L) {
 int console_close(lua_State *L) {
   sg_platf_end();
   sg_platf_exit();
 int console_close(lua_State *L) {
   sg_platf_end();
   sg_platf_exit();
-
-  xbt_lib_cursor_t cursor;
-  void **data;
-  char *name;
-
-  /* Initialize MSG and WKS hosts */
-  XBT_DEBUG("Initialize MSG and WKS hosts");
-  xbt_lib_foreach(host_lib, cursor, name, data) {
-    if(data[SURF_HOST_LEVEL]){
-      XBT_DEBUG("\tSee surf host %s",name);
-      SIMIX_host_create(name);
-      // THIS IS BRAINDEAD. There is no sg_host_t in that level, but a smx_host_priv. So commenting out for now.
-      // Lua is broken anyway. Christian will fix it
-      // __MSG_host_create((sg_host_t)data[SIMIX_HOST_LEVEL]);
-    }
-  }
-
   return 0;
 }
 
   return 0;
 }
 
index fcff801..4fa76e9 100644 (file)
@@ -42,11 +42,6 @@ void MSG_post_create_environment(void) {
   void **data;
   char *name;
 
   void **data;
   char *name;
 
-  /* Initialize MSG hosts */
-  xbt_lib_foreach(host_lib, cursor, name, data) {
-       __MSG_host_create(xbt_dict_cursor_get_elm(cursor));
-  }
-
   /* Initialize MSG storages */
   xbt_lib_foreach(storage_lib, cursor, name, data) {
     if(data[SIMIX_STORAGE_LEVEL])
   /* Initialize MSG storages */
   xbt_lib_foreach(storage_lib, cursor, name, data) {
     if(data[SIMIX_STORAGE_LEVEL])
index 98e0c95..99e62cb 100644 (file)
@@ -14,7 +14,7 @@
 #include "xbt/ex.h"             /* ex_backtrace_display */
 #include "xbt/replay.h"
 #include "simgrid/sg_config.h" /* Configuration mechanism of SimGrid */
 #include "xbt/ex.h"             /* ex_backtrace_display */
 #include "xbt/replay.h"
 #include "simgrid/sg_config.h" /* Configuration mechanism of SimGrid */
-
+#include "src/surf/callbacks.h"
 
 XBT_LOG_NEW_CATEGORY(msg, "All MSG categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_kernel, msg,
 
 XBT_LOG_NEW_CATEGORY(msg, "All MSG categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_kernel, msg,
@@ -30,6 +30,11 @@ static void _sg_cfg_cb_msg_debug_multiple_use(const char *name, int pos)
   msg_global->debug_multiple_use = xbt_cfg_get_boolean(_sg_cfg_set, name);
 }
 
   msg_global->debug_multiple_use = xbt_cfg_get_boolean(_sg_cfg_set, name);
 }
 
+static void MSG_host_create_(sg_host_t host)
+{
+  __MSG_host_create(host);
+}
+
 /**
  * \ingroup msg_simulation
  * \brief Initialize MSG with less verifications
 /**
  * \ingroup msg_simulation
  * \brief Initialize MSG with less verifications
@@ -62,6 +67,7 @@ void MSG_init_nocheck(int *argc, char **argv) {
     SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX);
 
     sg_platf_postparse_add_cb(MSG_post_create_environment);
     SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX);
 
     sg_platf_postparse_add_cb(MSG_post_create_environment);
+    surf_host_created_callback(MSG_host_create_);
   }
 
   if(MC_is_active()){
   }
 
   if(MC_is_active()){
index d22a8f3..c8f1907 100644 (file)
@@ -103,7 +103,8 @@ smx_host_priv_t sg_host_simix(sg_host_t host){
   return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
 }
 void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) {
   return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
 }
 void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) {
-       xbt_lib_set(host_lib,host->key,SIMIX_HOST_LEVEL,smx_host);
+  xbt_assert(xbt_lib_get_or_null(host_lib,host->key,SIMIX_HOST_LEVEL) == NULL);
+  xbt_lib_set(host_lib,host->key,SIMIX_HOST_LEVEL,smx_host);
 }
 void sg_host_simix_destroy(sg_host_t host) {
        xbt_lib_unset(host_lib,host->key,SIMIX_HOST_LEVEL,1);
 }
 void sg_host_simix_destroy(sg_host_t host) {
        xbt_lib_unset(host_lib,host->key,SIMIX_HOST_LEVEL,1);
index 6d14352..9217866 100644 (file)
@@ -43,19 +43,12 @@ void SIMIX_create_environment(const char *file)
 
 }
 
 
 }
 
-void SIMIX_post_create_environment(void) {
-
-  void **host = NULL;
+void SIMIX_post_create_environment(void)
+{
   void **storage = NULL;
   xbt_lib_cursor_t cursor = NULL;
   char *name = NULL;
 
   void **storage = NULL;
   xbt_lib_cursor_t cursor = NULL;
   char *name = NULL;
 
-  /* Create host at SIMIX level */
-  xbt_lib_foreach(host_lib, cursor, name, host) {
-    if(host[SURF_HOST_LEVEL])
-      SIMIX_host_create(name);
-  }
-
   /* Create storage at SIMIX level */
   xbt_lib_foreach(storage_lib, cursor, name, storage) {
     if(storage[SURF_STORAGE_LEVEL])
   /* Create storage at SIMIX level */
   xbt_lib_foreach(storage_lib, cursor, name, storage) {
     if(storage[SURF_STORAGE_LEVEL])
index dba3029..83ef7f3 100644 (file)
@@ -21,6 +21,8 @@
 #include "src/mc/mc_replay.h"
 #include "simgrid/sg_config.h"
 
 #include "src/mc/mc_replay.h"
 #include "simgrid/sg_config.h"
 
+#include "src/surf/callbacks.h"
+
 #ifdef HAVE_MC
 #include "src/mc/mc_private.h"
 #include "src/mc/mc_protocol.h"
 #ifdef HAVE_MC
 #include "src/mc/mc_private.h"
 #include "src/mc/mc_protocol.h"
@@ -219,6 +221,7 @@ void SIMIX_global_init(int *argc, char **argv)
     /* register a function to be called by SURF after the environment creation */
     sg_platf_init();
     sg_platf_postparse_add_cb(SIMIX_post_create_environment);
     /* register a function to be called by SURF after the environment creation */
     sg_platf_init();
     sg_platf_postparse_add_cb(SIMIX_post_create_environment);
+    surf_host_created_callback(SIMIX_host_create);
 
   }
   if (!simix_timers) {
 
   }
   if (!simix_timers) {
index f4f4779..982545b 100644 (file)
@@ -20,9 +20,8 @@ static void SIMIX_execution_finish(smx_synchro_t synchro);
  * \brief Internal function to create a SIMIX host.
  * \param name name of the host to create
  */
  * \brief Internal function to create a SIMIX host.
  * \param name name of the host to create
  */
-void SIMIX_host_create(const char *name) // FIXME: braindead prototype. Take sg_host as parameter
+void SIMIX_host_create(sg_host_t host) // FIXME: braindead prototype. Take sg_host as parameter
 {
 {
-  sg_host_t host = xbt_lib_get_elm_or_null(host_lib, name);
   smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
   s_smx_process_t proc;
 
   smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
   s_smx_process_t proc;
 
index 1d80023..1cac10f 100644 (file)
@@ -22,7 +22,7 @@ typedef struct s_smx_host_priv {
 } s_smx_host_priv_t;
 
 XBT_PRIVATE void _SIMIX_host_free_process_arg(void *);
 } s_smx_host_priv_t;
 
 XBT_PRIVATE void _SIMIX_host_free_process_arg(void *);
-XBT_PRIVATE void SIMIX_host_create(const char *name);
+XBT_PRIVATE void SIMIX_host_create(sg_host_t host);
 XBT_PRIVATE void SIMIX_host_destroy(void *host);
 
 XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host,
 XBT_PRIVATE void SIMIX_host_destroy(void *host);
 
 XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host,
index 401565c..d430a96 100644 (file)
@@ -24,13 +24,13 @@ sg_host_t SIMIX_vm_create(const char *name, sg_host_t ind_phys_host)
 {
   /* Create surf associated resource */
   surf_vm_model_create(name, ind_phys_host);
 {
   /* Create surf associated resource */
   surf_vm_model_create(name, ind_phys_host);
-
-  SIMIX_host_create(name);
+  sg_host_t host = sg_host_by_name(name);
+  SIMIX_host_create(host);
 
   /* We will be able to register the VM to its physical host, so that we can promptly
    * retrieve the list VMs on the physical host. */
 
 
   /* We will be able to register the VM to its physical host, so that we can promptly
    * retrieve the list VMs on the physical host. */
 
-  return sg_host_by_name(name);
+  return host;
 }
 
 
 }
 
 
diff --git a/src/surf/callbacks.cpp b/src/surf/callbacks.cpp
new file mode 100644 (file)
index 0000000..d8d48c7
--- /dev/null
@@ -0,0 +1,21 @@
+/* Copyright (c) 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 <xbt/asserts.h>
+
+#include "src/surf/callbacks.h"
+#include "src/surf/surf_interface.hpp"
+#include "src/surf/host_interface.hpp"
+
+void surf_host_created_callback(void (*callback)(sg_host_t))
+{
+  hostCreatedCallbacks.connect([callback](Host* host) {
+    const char* id = host->getName();
+    sg_host_t h = sg_host_by_name(id);
+    xbt_assert(h != NULL, "Host not found for name %s", id);
+    callback(h);
+  });
+}
diff --git a/src/surf/callbacks.h b/src/surf/callbacks.h
new file mode 100644 (file)
index 0000000..efc947b
--- /dev/null
@@ -0,0 +1,24 @@
+/* Copyright (c) 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. */
+
+#ifndef SIMGRID_SURF_CALLBACKS_H
+#define SIMGRID_SURF_CALLBACKS_H
+
+/** \file callbacks.h
+ *
+ *  C interface for the C++ SURF callbacks.
+ */
+
+#include <xbt/base.h>
+#include "simgrid/host.h"
+
+SG_BEGIN_DECL();
+
+XBT_PRIVATE void surf_host_created_callback(void (*callback)(sg_host_t));
+
+SG_END_DECL();
+
+#endif
index 4ee2810..68a711f 100644 (file)
@@ -307,6 +307,8 @@ set(NS3_SRC
   )
 
 set(SURF_SRC
   )
 
 set(SURF_SRC
+  src/surf/callbacks.h
+  src/surf/callbacks.cpp
   src/surf/cpu_cas01.cpp
   src/surf/cpu_interface.cpp
   src/surf/cpu_ti.cpp
   src/surf/cpu_cas01.cpp
   src/surf/cpu_interface.cpp
   src/surf/cpu_ti.cpp