Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3fe6281247a8893a58b955874750c55839344000
[simgrid.git] / src / simix / smx_smurf_private.h
1 /* Copyright (c) 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 _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
9
10 /********************************* Simcalls *********************************/
11
12 /* we want to build the e_smx_simcall_t enumeration and the table of the
13  * corresponding strings automatically, using macros */
14
15 #define SIMCALL_LIST1 \
16 SIMCALL_ENUM_ELEMENT(SIMCALL_NONE),\
17 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_BY_NAME),\
18 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_NAME),\
19 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_PROPERTIES),\
20 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_SPEED),\
21 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_AVAILABLE_SPEED),\
22 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_STATE),\
23 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_DATA),\
24 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_SET_DATA),\
25 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTE),\
26 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_PARALLEL_EXECUTE),\
27 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_DESTROY),\
28 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_CANCEL),\
29 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_REMAINS),\
30 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_STATE),\
31 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_SET_PRIORITY),\
32 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_WAIT),\
33 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CREATE),\
34 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILL),\
35 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILLALL),\
36 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CLEANUP),\
37 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CHANGE_HOST),\
38 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SUSPEND),\
39 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_RESUME),\
40 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_COUNT),\
41 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_DATA),\
42 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SET_DATA),\
43 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_HOST),\
44 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_NAME),\
45 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_IS_SUSPENDED),\
46 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_PROPERTIES),\
47 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SLEEP),\
48 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_ON_EXIT),\
49 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_AUTO_RESTART_SET),\
50 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_CREATE),\
51 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_DESTROY),\
52 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GEY_BY_NAME),\
53 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_COMM_COUNT_BY_HOST),\
54 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GET_HEAD),\
55 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_SEND),\
56 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_ISEND),\
57 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_RECV),\
58 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IRECV),\
59 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_DESTROY),\
60 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_CANCEL),\
61 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAITANY),\
62 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAIT),\
63 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TEST),\
64 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TESTANY),\
65 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_REMAINS),\
66 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_STATE),\
67 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_DATA),\
68 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_DATA),\
69 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_PROC),\
70 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_PROC),\
71 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_INIT),\
72 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_DESTROY),\
73 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_LOCK),\
74 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_TRYLOCK),\
75 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_UNLOCK),\
76 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_INIT),\
77 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_DESTROY),\
78 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_SIGNAL),\
79 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT),\
80 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT_TIMEOUT),\
81 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_BROADCAST),\
82 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_INIT),\
83 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_DESTROY),\
84 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_RELEASE),\
85 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_WOULD_BLOCK),\
86 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE),\
87 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE_TIMEOUT),\
88 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_GET_CAPACITY),\
89 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_READ),\
90 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_WRITE),\
91 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_OPEN),\
92 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_CLOSE),\
93 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_STAT)
94
95
96 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
97  * because they are not always present */
98 #ifdef HAVE_LATENCY_BOUND_TRACKING
99 #define SIMCALL_LIST2 \
100 ,SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IS_LATENCY_BOUNDED)
101 #else
102 #define SIMCALL_LIST2
103 #endif
104
105 #ifdef HAVE_TRACING
106 #define SIMCALL_LIST3 \
107 ,SIMCALL_ENUM_ELEMENT(SIMCALL_SET_CATEGORY)
108 #else
109 #define SIMCALL_LIST3
110 #endif
111
112 /* SIMCALL_LIST is the final macro to use */
113 #define SIMCALL_LIST SIMCALL_LIST1 SIMCALL_LIST2 SIMCALL_LIST3
114
115 /* you can redefine the following macro differently to generate something else
116  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
117 #define SIMCALL_ENUM_ELEMENT(x) x
118
119 /**
120  * \brief All possible simcalls.
121  */
122 typedef enum {
123 SIMCALL_LIST
124 } e_smx_simcall_t;
125
126 /**
127  * \brief Represents a simcall to the kernel.
128  */
129 typedef struct s_smx_simcall {
130   e_smx_simcall_t call;
131   smx_process_t issuer;
132
133   union {
134
135     struct {
136       const char *name;
137       smx_host_t result;
138     } host_get_by_name;
139
140     struct {
141       smx_host_t host;
142       const char* result;
143     } host_get_name;
144
145     struct {
146       smx_host_t host;
147       xbt_dict_t result;
148     } host_get_properties;
149
150     struct {
151       smx_host_t host;
152       double result;
153     } host_get_speed;
154
155     struct {
156       smx_host_t host;
157       double result;
158     } host_get_available_speed;
159
160     struct {
161       smx_host_t host;
162       int result;
163     } host_get_state;
164
165     struct {
166       smx_host_t host;
167       void* result;
168     } host_get_data;
169
170     struct {
171       smx_host_t host;
172       void* data;
173     } host_set_data;
174
175     struct {
176       const char* name;
177       smx_host_t host;
178       double computation_amount;
179       double priority;
180       smx_action_t result;
181     } host_execute;
182
183     struct {
184       const char *name;
185       int host_nb;
186       smx_host_t *host_list;
187       double *computation_amount;
188       double *communication_amount;
189       double amount;
190       double rate;
191       smx_action_t result;
192     } host_parallel_execute;
193
194     struct {
195       smx_action_t execution;
196     } host_execution_destroy;
197
198     struct {
199       smx_action_t execution;
200     } host_execution_cancel;
201
202     struct {
203       smx_action_t execution;
204       double result;
205     } host_execution_get_remains;
206
207     struct {
208       smx_action_t execution;
209       e_smx_state_t result;
210     } host_execution_get_state;
211
212     struct {
213       smx_action_t execution;
214       double priority;
215     } host_execution_set_priority;
216
217     struct {
218       smx_action_t execution;
219       e_smx_state_t result;
220     } host_execution_wait;
221
222     struct {
223       smx_process_t *process;
224       const char *name;
225       xbt_main_func_t code;
226       void *data;
227       const char *hostname;
228       double kill_time;
229       int argc;
230       char **argv;
231       xbt_dict_t properties;
232       int auto_restart;
233     } process_create;
234
235     struct {
236       smx_process_t process;
237     } process_kill;
238
239     struct {
240       smx_process_t process;
241     } process_cleanup;
242
243     struct {
244       smx_process_t process;
245       smx_host_t dest;
246     } process_change_host;
247
248     struct {
249       smx_process_t process;
250     } process_suspend;
251
252     struct {
253       smx_process_t process;
254     } process_resume;
255
256     struct {
257       int result;
258     } process_count;
259
260     struct {
261       smx_process_t process;
262       void* result;
263     } process_get_data;
264
265     struct {
266       smx_process_t process;
267       void* data;
268     } process_set_data;
269
270     struct {
271       smx_process_t process;
272       smx_host_t result;
273     } process_get_host;
274
275     struct {
276       smx_process_t process;
277       const char *result;
278     } process_get_name;
279
280     struct {
281       smx_process_t process;
282       int result;
283     } process_is_suspended;
284
285     struct {
286       smx_process_t process;
287       xbt_dict_t result;
288     } process_get_properties;
289
290     struct {
291       double duration;
292       e_smx_state_t result;
293     } process_sleep;
294
295     struct {
296       smx_process_t process;
297       int_f_pvoid_t fun;
298       void *data;
299     } process_on_exit;
300
301     struct {
302       smx_process_t process;
303       int auto_restart;
304     } process_auto_restart;
305
306     struct {
307       const char *name;
308       smx_rdv_t result;
309     } rdv_create;
310
311     struct {
312       smx_rdv_t rdv;
313     } rdv_destroy;
314
315     struct {
316       const char* name;
317       smx_rdv_t result;
318     } rdv_get_by_name;
319
320     struct {
321       smx_rdv_t rdv;
322       smx_host_t host;
323       unsigned int result; 
324     } rdv_comm_count_by_host;
325
326     struct {
327       smx_rdv_t rdv;
328       smx_action_t result;
329     } rdv_get_head;
330
331     struct {
332       smx_rdv_t rdv;
333       double task_size;
334       double rate;
335       void *src_buff;
336       size_t src_buff_size;
337       int (*match_fun)(void *, void *, smx_action_t);
338       void *data;
339       double timeout;
340     } comm_send;
341
342     struct {
343       smx_rdv_t rdv;
344       double task_size;
345       double rate;
346       void *src_buff;
347       size_t src_buff_size;
348       int (*match_fun)(void *, void *, smx_action_t);
349       void (*clean_fun)(void *);
350       void *data;
351       int detached;
352       smx_action_t result;
353     } comm_isend;
354
355     struct {
356       smx_rdv_t rdv;
357       void *dst_buff;
358       size_t *dst_buff_size;
359       int (*match_fun)(void *, void *, smx_action_t);
360       void *data;
361       double timeout;
362     } comm_recv;
363
364     struct {
365       smx_rdv_t rdv;
366       void *dst_buff;
367       size_t *dst_buff_size;
368       int (*match_fun)(void *, void *, smx_action_t);
369       void *data;
370       smx_action_t result;
371     } comm_irecv;
372
373     struct {
374       smx_action_t comm;
375     } comm_destroy;
376
377     struct {
378       smx_action_t comm;
379     } comm_cancel;
380
381     struct {
382       xbt_dynar_t comms;
383       unsigned int result;
384     } comm_waitany;
385
386     struct {
387       smx_action_t comm;
388       double timeout;
389     } comm_wait;
390
391     struct {
392       smx_action_t comm;
393       int result;
394     } comm_test;
395
396     struct {
397       xbt_dynar_t comms;
398       int result;
399     } comm_testany;
400
401     struct {
402       smx_action_t comm;
403       double result;
404     } comm_get_remains;
405
406     struct {
407       smx_action_t comm;
408       e_smx_state_t result;
409     } comm_get_state;
410
411     struct {
412       smx_action_t comm;
413       void *result;
414     } comm_get_src_data;
415
416     struct {
417       smx_action_t comm;
418       void *result;
419     } comm_get_dst_data;
420
421     struct {
422       smx_action_t comm;
423       smx_process_t result;
424     } comm_get_src_proc;
425
426     struct {
427       smx_action_t comm;
428       smx_process_t result;
429     } comm_get_dst_proc;
430
431 #ifdef HAVE_LATENCY_BOUND_TRACKING
432     struct {
433       smx_action_t comm;
434       int result;
435     } comm_is_latency_bounded;
436 #endif
437
438 #ifdef HAVE_TRACING
439     struct {
440       smx_action_t action;
441       const char *category;
442     } set_category;
443 #endif
444
445     struct {
446       smx_mutex_t result;
447     } mutex_init;
448
449     struct {
450       smx_mutex_t mutex;
451     } mutex_lock;
452
453     struct {
454       smx_mutex_t mutex;
455       int result;
456     } mutex_trylock;
457
458     struct {
459       smx_mutex_t mutex;
460     } mutex_unlock;
461
462     struct {
463       smx_mutex_t mutex;
464     } mutex_destroy;
465
466     struct {
467       smx_cond_t result;
468     } cond_init;
469
470     struct {
471       smx_cond_t cond;
472     } cond_destroy;
473
474     struct {
475       smx_cond_t cond;
476     } cond_signal;
477
478     struct {
479       smx_cond_t cond;
480       smx_mutex_t mutex;
481     } cond_wait;
482
483     struct {
484       smx_cond_t cond;
485       smx_mutex_t mutex;
486       double timeout;
487     } cond_wait_timeout;
488
489     struct {
490       smx_cond_t cond;
491     } cond_broadcast;
492
493     struct {
494       int capacity;
495       smx_sem_t result;
496     } sem_init;
497
498     struct {
499       smx_sem_t sem;
500     } sem_destroy;
501
502     struct {
503       smx_sem_t sem;
504     } sem_release;
505
506     struct {
507       smx_sem_t sem;
508       int result;
509     } sem_would_block;
510
511     struct {
512       smx_sem_t sem;
513     } sem_acquire;
514
515     struct {
516       smx_sem_t sem;
517       double timeout;
518     } sem_acquire_timeout;
519
520     struct {
521       smx_sem_t sem;
522       int result;
523     } sem_get_capacity;
524
525     struct {
526       void *ptr;
527       size_t size;
528       size_t nmemb;
529       smx_file_t stream;
530       double result;
531     } file_read;
532
533     struct {
534       const void *ptr;
535       size_t size;
536       size_t nmemb;
537       smx_file_t stream;
538       size_t result;
539     } file_write;
540
541     struct {
542       const char* mount;
543       const char* path;
544       const char* mode;
545       smx_file_t result;
546     } file_open;
547
548     struct {
549       smx_file_t fp;
550       int result;
551     } file_close;
552
553     struct {
554       smx_file_t fd;
555       s_file_stat_t buf;
556       int result;
557     } file_stat;
558
559   };
560 } s_smx_simcall_t, *smx_simcall_t;
561
562 /******************************** General *************************************/
563
564 void SIMIX_simcall_push(smx_process_t self);
565 void SIMIX_simcall_answer(smx_simcall_t);
566 void SIMIX_simcall_pre(smx_simcall_t, int);
567 void SIMIX_simcall_post(smx_action_t);
568 smx_simcall_t SIMIX_simcall_mine(void);
569 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
570
571 #endif
572