Logo AND Algorithmique Numérique Distribuée

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