Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the affinity setting function for a VM
[simgrid.git] / src / msg / msg_private.h
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef METASIMGRID_PRIVATE_H
8 #define METASIMGRID_PRIVATE_H
9
10 #include "msg/msg.h"
11 #include "simgrid/simix.h"
12 #include "surf/surf.h"
13 #include "xbt/fifo.h"
14 #include "xbt/dynar.h"
15 #include "xbt/swag.h"
16 #include "xbt/dict.h"
17 #include "xbt/config.h"
18 #include "instr/instr_private.h"
19 SG_BEGIN_DECL()
20
21 /**************** datatypes **********************************/
22
23 /********************************* Task **************************************/
24
25 typedef struct simdata_task {
26   smx_action_t compute;         /* SIMIX modeling of computation */
27   smx_action_t comm;            /* SIMIX modeling of communication */
28   double message_size;          /* Data size */
29   double computation_amount;    /* Computation size */
30   msg_process_t sender;
31   msg_process_t receiver;
32   msg_host_t source;
33   double priority;
34   double bound; /* Capping for CPU resource */
35   double rate;  /* Capping for network resource */
36   unsigned long affinity_mask; /* CPU affinity */
37   int isused;  /* Indicates whether the task is used in SIMIX currently */
38   int host_nb;                  /* ==0 if sequential task; parallel task if not */
39   /*******  Parallel Tasks Only !!!! *******/
40   smx_host_t *host_list;
41   double *comp_amount;
42   double *comm_amount;
43 } s_simdata_task_t;
44
45 /********************************* File **************************************/
46 typedef struct simdata_file {
47   smx_file_t smx_file;
48 } s_simdata_file_t;
49
50 /*************** Begin GPU ***************/
51 typedef struct simdata_gpu_task {
52   double computation_amount;    /* Computation size */
53   double dispatch_latency;
54   double collect_latency;
55   int isused;  /* Indicates whether the task is used in SIMIX currently */
56 } s_simdata_gpu_task_t;
57 /*************** End GPU ***************/
58
59 /******************************* Process *************************************/
60
61 typedef struct simdata_process {
62   msg_host_t m_host;              /* the host on which the process is running */
63   msg_host_t put_host;            /* used for debugging purposes */
64 #ifdef MSG_USE_DEPRECATED
65   m_channel_t put_channel;      /* used for debugging purposes */
66 #endif
67   smx_action_t waiting_action;
68   msg_task_t waiting_task;
69   char **argv;                  /* arguments table if any */
70   int argc;                     /* arguments number if any */
71   msg_error_t last_errno;       /* the last value returned by a MSG_function */
72
73   void* data;                   /* user data */
74 } s_simdata_process_t, *simdata_process_t;
75
76 typedef struct process_arg {
77   const char *name;
78   xbt_main_func_t code;
79   void *data;
80   msg_host_t m_host;
81   int argc;
82   char **argv;
83   double kill_time;
84 } s_process_arg_t, *process_arg_t;
85
86 typedef struct msg_comm {
87   smx_action_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
88   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
89   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
90   msg_error_t status;           /* status of the communication once finished */
91 } s_msg_comm_t;
92
93
94 /******************************* VM *************************************/
95 typedef struct dirty_page {
96   double prev_clock;
97   double prev_remaining;
98   msg_task_t task;
99 } s_dirty_page, *dirty_page_t;
100
101 XBT_PUBLIC_DATA(const char*) MSG_vm_get_property_value(msg_vm_t vm, const char *name);
102 XBT_PUBLIC_DATA(xbt_dict_t) MSG_vm_get_properties(msg_vm_t vm);
103 XBT_PUBLIC_DATA(void) MSG_vm_set_property_value(msg_vm_t vm, const char *name, void *value, void_f_pvoid_t free_ctn);
104 XBT_PUBLIC_DATA(msg_vm_t) MSG_vm_get_by_name(const char *name);
105 XBT_PUBLIC_DATA(const char*) MSG_vm_get_name(msg_vm_t vm);
106
107 /************************** Global variables ********************************/
108 typedef struct MSG_Global {
109   xbt_fifo_t host;
110 #ifdef MSG_USE_DEPRECATED
111   int max_channel;
112 #endif
113   int session;
114   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
115   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
116   void_f_pvoid_t process_data_cleanup;
117 } s_MSG_Global_t, *MSG_Global_t;
118
119 /*extern MSG_Global_t msg_global;*/
120 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
121
122
123 /*************************************************************/
124
125 #ifdef MSG_USE_DEPRECATED
126 #  define PROCESS_SET_ERRNO(val) \
127   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno=val)
128 #  define PROCESS_GET_ERRNO() \
129   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno)
130 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
131 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
132
133 #else
134 #  define MSG_RETURN(val) return(val)
135 #endif
136
137 msg_host_t __MSG_host_create(smx_host_t workstation);
138 void __MSG_host_destroy(msg_host_t host);
139
140 void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
141 void MSG_process_create_from_SIMIX(smx_process_t *process, const char *name,
142                                    xbt_main_func_t code, void *data,
143                                    const char *hostname, double kill_time,  int argc,
144                                    char **argv, xbt_dict_t properties, int auto_restart);
145 void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_size);
146
147 void _MSG_action_init(void);
148 void _MSG_action_exit(void);
149
150 void MSG_post_create_environment(void);
151
152 static inline void *msg_host_resource_priv(const void *host) {
153   return xbt_lib_get_level((void *)host, MSG_HOST_LEVEL);
154 }
155
156 void MSG_host_add_task(msg_host_t host, msg_task_t task);
157 void MSG_host_del_task(msg_host_t host, msg_task_t task);
158
159 /********** Tracing **********/
160 /* declaration of instrumentation functions from msg_task_instr.c */
161 void TRACE_msg_set_task_category(msg_task_t task, const char *category);
162 void TRACE_msg_task_create(msg_task_t task);
163 void TRACE_msg_task_execute_start(msg_task_t task);
164 void TRACE_msg_task_execute_end(msg_task_t task);
165 void TRACE_msg_task_destroy(msg_task_t task);
166 void TRACE_msg_task_get_start(void);
167 void TRACE_msg_task_get_end(double start_time, msg_task_t task);
168 int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
169 void TRACE_msg_task_put_end(void);
170
171 /* declaration of instrumentation functions from msg_process_instr.c */
172 char *instr_process_id (msg_process_t proc, char *str, int len);
173 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
174 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host,
175                                    msg_host_t new_host);
176 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
177 void TRACE_msg_process_destroy (const char *process_name, int process_pid, msg_host_t host);
178 void TRACE_msg_process_kill(msg_process_t process);
179 void TRACE_msg_process_suspend(msg_process_t process);
180 void TRACE_msg_process_resume(msg_process_t process);
181 void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
182 void TRACE_msg_process_sleep_out(msg_process_t process);
183 void TRACE_msg_process_end(msg_process_t process);
184
185 /* declaration of instrumentation functions from instr_msg_vm.c */
186 char *instr_vm_id(msg_vm_t vm, char *str, int len);
187 char *instr_vm_id_2(const char *vm_name, char *str, int len);
188 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host,
189                                    msg_host_t new_host);
190 void TRACE_msg_vm_start(msg_vm_t vm);
191 void TRACE_msg_vm_create(const char *vm_name, msg_host_t host);
192 void TRACE_msg_vm_kill(msg_vm_t process);
193 void TRACE_msg_vm_suspend(msg_vm_t vm);
194 void TRACE_msg_vm_resume(msg_vm_t vm);
195 void TRACE_msg_vm_save(msg_vm_t vm);
196 void TRACE_msg_vm_restore(msg_vm_t vm);
197 void TRACE_msg_vm_end(msg_vm_t vm);
198
199 SG_END_DECL()
200 #endif