3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifndef SIMIX_PRIVATE_H
10 #define SIMIX_PRIVATE_H
12 #include "simix/simix.h"
13 #include "surf/surf.h"
17 #include "xbt/context.h"
18 #include "xbt/config.h"
20 /******************************* Datatypes **********************************/
23 /********************************** Host ************************************/
25 typedef struct s_simdata_host {
26 void *host; /* SURF modeling */
27 xbt_swag_t process_list;
30 /********************************* Simix Global ******************************/
32 typedef struct SIMIX_Global {
34 xbt_swag_t process_to_run;
35 xbt_swag_t process_list;
36 /* xbt_swag_t process_sleeping; */
38 smx_process_t current_process;
39 xbt_dict_t registered_functions;
42 } s_SIMIX_Global_t, *SIMIX_Global_t;
44 extern SIMIX_Global_t simix_global;
46 /******************************* Process *************************************/
48 typedef struct s_simdata_process {
49 smx_host_t host; /* the host on which the process is running */
50 xbt_context_t context; /* the context that executes the scheduler fonction */
53 smx_mutex_t mutex; /* mutex on which the process is blocked */
54 smx_cond_t cond; /* cond on which the process is blocked */
55 smx_host_t put_host; /* used for debugging purposes */
56 smx_action_t block_action; /* action that block the process when it does a mutex_lock or cond_wait */
57 int argc; /* arguments number if any */
58 char **argv; /* arguments table if any */
59 // SIMIX_error_t last_errno; /* the last value returned by a MSG_function */
60 // int paje_state; /* the number of states stacked with Paje */
61 } s_simdata_process_t;
63 typedef struct process_arg {
65 smx_process_code_t code;
71 } s_process_arg_t, *process_arg_t;
73 /********************************* Mutex and Conditional ****************************/
75 typedef struct s_smx_mutex {
76 xbt_swag_t sleeping; /* list of sleeping process */
81 typedef struct s_smx_cond {
82 xbt_swag_t sleeping; /* list of sleeping process */
84 xbt_fifo_t actions; /* list of actions */
88 /********************************* Action **************************************/
90 typedef struct s_simdata_action {
91 surf_action_t surf_action; /* SURF modeling of computation */
93 xbt_fifo_t cond_list; /* conditional variables that must be signaled when the action finish. */
96 /* control needed when the action blocks a process(__SIMIX_process_block). For each process that is blocked a new action is created, the process is stocked in cond_process variable and the "boolean" action_block is marked to 1 */
97 int action_block; /* simix control variable, system action or not */
98 smx_process_t cond_process; /* system process will wake up */
99 smx_cond_t timeout_cond; /* useful to remove the process from the sleeping list when a timeout occurs */
101 } s_simdata_action_t;
105 /******************************* Configuration support **********************************/
107 void simix_config_init(void); /* create the config set, call this before use! */
108 void simix_config_finalize(void); /* destroy the config set, call this at cleanup. */
109 extern int _simix_init_status; /* 0: beginning of time;
110 1: pre-inited (cfg_set created);
111 2: inited (running) */
112 extern xbt_cfg_t _simix_cfg_set;
119 //#define PROCESS_SET_ERRNO(val) (SIMIX_process_self()->simdata->last_errno=val)
120 //#define PROCESS_GET_ERRNO() (SIMIX_process_self()->simdata->last_errno)
121 //#define SIMIX_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
122 /* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
124 #define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \
125 get_state(SIMIX_host_self()->simdata->host)==SURF_CPU_ON,\
126 "Host failed, you cannot call this function.")
128 smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);
129 void __SIMIX_host_destroy(smx_host_t host);
131 int __SIMIX_process_block(double max_duration);
132 void __SIMIX_process_unblock(smx_process_t process);
133 int __SIMIX_process_isBlocked(smx_process_t process);
135 void __SIMIX_display_process_status(void);
137 void __SIMIX_wait_for_action(smx_process_t process, smx_action_t action);
141 void __MSG_task_execute(smx_process_t process, m_task_t task);
142 MSG_error_t __MSG_task_wait_event(smx_process_t process, m_task_t task);