Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix SIMIX_post_io. For now SIMIX_req_file_read makes a Surf sleep action.
[simgrid.git] / src / simix / private.h
index 068baf4..2897aeb 100644 (file)
 #include "xbt/fifo.h"
 #include "xbt/swag.h"
 #include "xbt/dict.h"
+#include "xbt/mallocator.h"
 #include "xbt/config.h"
 #include "xbt/function_types.h"
 #include "xbt/ex_interface.h"
-#include "instr/private.h"
+#include "instr/instr_private.h"
 #include "process_private.h"
 #include "host_private.h"
+#include "io_private.h"
 #include "network_private.h"
 #include "smurf_private.h"
 #include "synchro_private.h"
+#include "simix/context.h"
 
-/********************************** Simix Global ******************************/
-
-typedef struct s_smx_context_factory *smx_context_factory_t;
+/* Define only for SimGrid benchmarking purposes */
+#undef TIME_BENCH
 
+/********************************** Simix Global ******************************/
 typedef struct s_smx_global {
   smx_context_factory_t context_factory;
-  xbt_dict_t host;
-  xbt_swag_t process_to_run;
+  xbt_dynar_t process_to_run;
+  xbt_dynar_t process_that_ran;
   xbt_swag_t process_list;
   xbt_swag_t process_to_destroy;
   smx_process_t maestro_process;
   xbt_dict_t registered_functions;
   smx_creation_func_t create_process_function;
-  void_f_pvoid_t kill_process_function;
+  void_pfn_smxprocess_t kill_process_function;
   void_pfn_smxprocess_t cleanup_process_function;
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-  xbt_dict_t latency_limited_dict;
-#endif
+  xbt_mallocator_t action_mallocator;
 } s_smx_global_t, *smx_global_t;
 
 extern smx_global_t simix_global;
-
+extern unsigned long simix_process_maxpid;
 
 /*********************************** Time ************************************/
 
@@ -92,6 +93,9 @@ typedef struct s_smx_action {
       e_smx_comm_type_t type;         /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
       smx_rdv_t rdv;                  /* Rendez-vous where the comm is queued */
       int refcount;                   /* Number of processes involved in the cond */
+      int detached;                   /* If detached or not */
+
+      void (*clean_fun)(void*);       /* Function to clean the detached src_buf if something goes wrong */
 
       /* Surf action data */
       surf_action_t surf_comm;        /* The Surf communication action encapsulated */
@@ -109,7 +113,8 @@ typedef struct s_smx_action {
       size_t *dst_buff_size;
       char copied;
 
-      void *data;                     /* User data associated to communication */
+      void* src_data;                     /* User data associated to communication */
+      void* dst_data;
     } comm;    
 
     struct {
@@ -121,10 +126,17 @@ typedef struct s_smx_action {
       surf_action_t sleep;
     } synchro;
 
+    struct {
+      smx_host_t host;
+      surf_action_t surf_io;
+    } io;
   };
 
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  int latency_limited;
+#endif
+
 #ifdef HAVE_TRACING
-  long long int counter;              /* simix action unique identifier for instrumentation */
   char *category;                     /* simix action category for instrumentation */
 #endif
 } s_smx_action_t;
@@ -146,44 +158,16 @@ static XBT_INLINE e_smx_state_t SIMIX_action_map_state(e_surf_action_state_t sta
   }
 }
 
-/******************************** Context *************************************/
-
-/* The following function pointer types describe the interface that any context
-   factory should implement */
-
-
-typedef smx_context_t(*smx_pfn_context_factory_create_context_t)
-  (xbt_main_func_t, int, char **, void_pfn_smxprocess_t, void* data);
-typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
-typedef void (*smx_pfn_context_free_t) (smx_context_t);
-typedef void (*smx_pfn_context_start_t) (smx_context_t);
-typedef void (*smx_pfn_context_stop_t) (smx_context_t);
-typedef void (*smx_pfn_context_suspend_t) (smx_context_t context);
-typedef void (*smx_pfn_context_runall_t) (xbt_swag_t processes);
-typedef smx_context_t (*smx_pfn_context_self_t) (void);
-typedef void* (*smx_pfn_context_get_data_t) (smx_context_t context);
-
-/* interface of the context factories */
-typedef struct s_smx_context_factory {
-  const char *name;
-  smx_pfn_context_factory_create_context_t create_context;
-  smx_pfn_context_factory_finalize_t finalize;
-  smx_pfn_context_free_t free;
-  smx_pfn_context_stop_t stop;
-  smx_pfn_context_suspend_t suspend;
-  smx_pfn_context_runall_t runall;
-  smx_pfn_context_self_t self;
-  smx_pfn_context_get_data_t get_data;
-} s_smx_context_factory_t;
-
-
 void SIMIX_context_mod_init(void);
 void SIMIX_context_mod_exit(void);
 
+XBT_INLINE void SIMIX_context_set_current(smx_context_t context);
+XBT_INLINE smx_context_t SIMIX_context_get_current(void);
 
 /* All factories init */
 void SIMIX_ctx_thread_factory_init(smx_context_factory_t *factory);
 void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory);
+void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory);
 
 /* ****************************** */
 /* context manipulation functions */
@@ -220,8 +204,10 @@ static XBT_INLINE smx_context_t SIMIX_context_new(xbt_main_func_t code,
                                                   smx_process_t simix_process)
 {
 
-  return (*(simix_global->context_factory->create_context))
-      (code, argc, argv, cleanup_func, simix_process);
+  return simix_global->context_factory->create_context(code,
+                                                       argc, argv,
+                                                       cleanup_func,
+                                                       simix_process);
 }
 
 /**
@@ -231,7 +217,7 @@ static XBT_INLINE smx_context_t SIMIX_context_new(xbt_main_func_t code,
  */
 static XBT_INLINE void SIMIX_context_free(smx_context_t context)
 {
-  (*(simix_global->context_factory->free)) (context);
+  simix_global->context_factory->free(context);
 }
 
 /**
@@ -240,7 +226,7 @@ static XBT_INLINE void SIMIX_context_free(smx_context_t context)
  */
 static XBT_INLINE void SIMIX_context_stop(smx_context_t context)
 {
-  (*(simix_global->context_factory->stop)) (context);
+  simix_global->context_factory->stop(context);
 }
 
 /**
@@ -250,16 +236,15 @@ static XBT_INLINE void SIMIX_context_stop(smx_context_t context)
  */
 static XBT_INLINE void SIMIX_context_suspend(smx_context_t context)
 {
-  (*(simix_global->context_factory->suspend)) (context);
+  simix_global->context_factory->suspend(context);
 }
 
 /**
- \brief executes all the processes (in parallel if possible)
- \param processes the swag of processes to execute
+ \brief Executes all the processes to run (in parallel if possible).
  */
-static XBT_INLINE void SIMIX_context_runall(xbt_swag_t processes)
+static XBT_INLINE void SIMIX_context_runall()
 {
-  (*(simix_global->context_factory->runall)) (processes);
+  simix_global->context_factory->runall();
 }
 
 /**
@@ -267,11 +252,11 @@ static XBT_INLINE void SIMIX_context_runall(xbt_swag_t processes)
  */
 static XBT_INLINE smx_context_t SIMIX_context_self(void)
 {
-  if (simix_global->context_factory == NULL) {
-    return NULL;
+  if (simix_global && simix_global->context_factory != NULL) {
+    return simix_global->context_factory->self();
   }
 
-  return (*(simix_global->context_factory->self))();
+  return NULL;
 }
 
 /**
@@ -281,7 +266,8 @@ static XBT_INLINE smx_context_t SIMIX_context_self(void)
  */
 static XBT_INLINE void* SIMIX_context_get_data(smx_context_t context)
 {
-  return (*(simix_global->context_factory->get_data))(context);
+  return simix_global->context_factory->get_data(context);
 }
 
+XBT_PUBLIC(int) SIMIX_process_get_maxpid(void);
 #endif