Logo AND Algorithmique Numérique Distribuée

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