Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an hide option "enable_pcre" for enable or not pcre lib.
[simgrid.git] / src / simix / smx_smurf.c
1 #include "private.h"
2 #include "xbt/fifo.h"
3 #include "xbt/xbt_os_thread.h"
4
5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
6                                 "Logging specific to SIMIX (SMURF)");
7
8 /* Requests to handle at the end of this round of scheduling user processes */
9 static xbt_heap_t req_todo;
10 /* to protect the write actions in the heap */
11 static xbt_os_mutex_t sync_req_positions;
12
13 void SIMIX_request_init(void)
14 {
15   req_todo = xbt_heap_new(5,NULL);
16   sync_req_positions = xbt_os_mutex_init();
17 }
18
19 void SIMIX_request_destroy(void)
20 {
21   xbt_heap_free(req_todo);
22   xbt_os_mutex_destroy(sync_req_positions);
23 }
24
25 /* FIXME: we may want to save the initialization of issuer... */
26 XBT_INLINE smx_req_t SIMIX_req_mine() {
27   smx_process_t issuer = SIMIX_process_self();
28   return &issuer->request;
29 }
30
31 void SIMIX_request_push()
32 {
33   smx_process_t issuer = SIMIX_process_self();
34   if (issuer != simix_global->maestro_process){
35     issuer->request.issuer = issuer;
36
37     if (_surf_parallel_contexts)
38       xbt_os_mutex_acquire(sync_req_positions);
39     xbt_heap_push(req_todo,&issuer->request,issuer->pid);
40     DEBUG3("Pushed request %d of %s; now %d requests waiting",
41         issuer->request.call,issuer->name,xbt_heap_size(req_todo));
42     if (_surf_parallel_contexts)
43       xbt_os_mutex_release(sync_req_positions);
44
45     DEBUG2("Yield process '%s' on request of type %d", issuer->name, issuer->request.call);
46     SIMIX_process_yield();
47   } else {
48     SIMIX_request_pre(&issuer->request);
49   }
50 }
51
52 smx_req_t SIMIX_request_pop(void)
53 {
54   return xbt_heap_pop(req_todo);
55 }
56
57 void SIMIX_request_answer(smx_req_t req)
58 {
59   if (req->issuer != simix_global->maestro_process){
60     req->issuer->request.call = REQ_NO_REQ;
61     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer);
62   }
63 }
64
65 int SIMIX_request_is_visible(smx_req_t req)
66 {
67   return req->call == REQ_COMM_ISEND
68      || req->call == REQ_COMM_IRECV
69      || req->call == REQ_COMM_WAIT
70      || req->call == REQ_COMM_WAITANY
71      || req->call == REQ_COMM_TEST;
72 }
73
74 int SIMIX_request_is_enabled(smx_req_t req)
75 {
76   unsigned int index = 0;
77   smx_action_t act;
78
79   switch (req->call) {
80
81     case REQ_COMM_WAIT:
82       /* FIXME: check also that src and dst processes are not suspended */
83       if (req->comm_wait.comm->comm.src_proc 
84          && req->comm_wait.comm->comm.dst_proc)
85         return TRUE;
86       return FALSE;
87       break;
88
89     case REQ_COMM_WAITANY:
90       xbt_dynar_foreach(req->comm_waitany.comms, index, act) {
91         if (act->comm.src_proc && act->comm.dst_proc){
92           return TRUE;
93         }
94       }
95       return FALSE;
96       break;
97
98     default:    
99       return TRUE;
100   }
101 }
102
103
104 void SIMIX_request_pre(smx_req_t req)
105 {
106   switch (req->call) {
107   case REQ_NO_REQ:
108     xbt_die("Asked to do the noop syscall");
109     break;
110
111     case REQ_HOST_GET_BY_NAME:
112       req->host_get_by_name.result =
113         SIMIX_host_get_by_name(req->host_get_by_name.name);
114       SIMIX_request_answer(req);
115       break;
116
117     case REQ_HOST_GET_NAME:
118       req->host_get_name.result =       SIMIX_host_get_name(req->host_get_name.host);
119       SIMIX_request_answer(req);
120       break;
121
122     case REQ_HOST_GET_PROPERTIES:
123       req->host_get_properties.result =
124         SIMIX_host_get_properties(req->host_get_properties.host);
125       SIMIX_request_answer(req);
126       break;
127
128     case REQ_HOST_GET_SPEED:
129       req->host_get_speed.result = 
130         SIMIX_host_get_speed(req->host_get_speed.host);
131       SIMIX_request_answer(req);
132       break;
133
134     case REQ_HOST_GET_AVAILABLE_SPEED:
135       req->host_get_available_speed.result =
136         SIMIX_host_get_available_speed(req->host_get_available_speed.host);
137       SIMIX_request_answer(req);
138       break;
139
140     case REQ_HOST_GET_STATE:
141       req->host_get_state.result = 
142         SIMIX_host_get_state(req->host_get_state.host);
143       SIMIX_request_answer(req);
144       break;
145
146     case REQ_HOST_GET_DATA:
147       req->host_get_data.result =       SIMIX_host_get_data(req->host_get_data.host);
148       SIMIX_request_answer(req);
149       break;
150
151     case REQ_HOST_SET_DATA:
152       SIMIX_host_set_data(req->host_set_data.host, req->host_set_data.data);
153       SIMIX_request_answer(req);
154       break;
155
156     case REQ_HOST_EXECUTE:
157       req->host_execute.result = SIMIX_host_execute(
158           req->host_execute.name,
159           req->host_execute.host,
160           req->host_execute.computation_amount);
161       SIMIX_request_answer(req);
162       break;
163
164     case REQ_HOST_PARALLEL_EXECUTE:
165       req->host_parallel_execute.result = SIMIX_host_parallel_execute(
166           req->host_parallel_execute.name,
167           req->host_parallel_execute.host_nb,
168           req->host_parallel_execute.host_list,
169           req->host_parallel_execute.computation_amount,
170           req->host_parallel_execute.communication_amount,
171           req->host_parallel_execute.amount,
172           req->host_parallel_execute.rate);
173       SIMIX_request_answer(req);
174       break;
175
176     case REQ_HOST_EXECUTION_DESTROY:
177       SIMIX_host_execution_destroy(req->host_execution_destroy.execution);
178       SIMIX_request_answer(req);
179       break;
180
181     case REQ_HOST_EXECUTION_CANCEL:
182       SIMIX_host_execution_cancel(req->host_execution_cancel.execution);
183       SIMIX_request_answer(req);
184       break;
185
186     case REQ_HOST_EXECUTION_GET_REMAINS:
187       req->host_execution_get_remains.result =
188         SIMIX_host_execution_get_remains(req->host_execution_get_remains.execution);
189       SIMIX_request_answer(req);
190       break;
191
192     case REQ_HOST_EXECUTION_GET_STATE:
193       req->host_execution_get_state.result =
194         SIMIX_host_execution_get_state(req->host_execution_get_state.execution);
195       SIMIX_request_answer(req);
196       break;
197
198     case REQ_HOST_EXECUTION_SET_PRIORITY:
199       SIMIX_host_execution_set_priority(
200           req->host_execution_set_priority.execution,
201           req->host_execution_set_priority.priority);
202       SIMIX_request_answer(req);
203       break;
204
205     case REQ_HOST_EXECUTION_WAIT:
206       SIMIX_pre_host_execution_wait(req);
207       break;
208
209     case REQ_PROCESS_CREATE:
210       req->process_create.result = SIMIX_process_create(
211           req->process_create.name,
212           req->process_create.code,
213           req->process_create.data,
214           req->process_create.hostname,
215           req->process_create.argc,
216           req->process_create.argv,
217           req->process_create.properties);
218       SIMIX_request_answer(req);
219       break;
220
221     case REQ_PROCESS_KILL:
222       SIMIX_process_kill(req->process_kill.process, req->issuer);
223       SIMIX_request_answer(req);
224       break;
225
226     case REQ_PROCESS_CHANGE_HOST:
227       SIMIX_process_change_host(
228           req->process_change_host.process,
229           req->process_change_host.source,
230           req->process_change_host.dest);
231       SIMIX_request_answer(req);
232       break;
233
234     case REQ_PROCESS_SUSPEND:
235       SIMIX_pre_process_suspend(req);
236       break;
237
238     case REQ_PROCESS_RESUME:
239       SIMIX_process_resume(req->process_resume.process, req->issuer);
240       SIMIX_request_answer(req);
241       break;
242
243     case REQ_PROCESS_COUNT:
244       req->process_count.result = SIMIX_process_count();
245       SIMIX_request_answer(req);
246       break;
247
248     case REQ_PROCESS_GET_DATA:
249       req->process_get_data.result =
250         SIMIX_process_get_data(req->process_get_data.process);
251       SIMIX_request_answer(req);
252       break;
253
254     case REQ_PROCESS_SET_DATA:
255       SIMIX_process_set_data(
256           req->process_set_data.process,
257           req->process_set_data.data);
258       SIMIX_request_answer(req);
259       break;
260
261     case REQ_PROCESS_GET_HOST:
262       req->process_get_host.result = SIMIX_process_get_host(req->process_get_host.process);
263       SIMIX_request_answer(req);
264       break;
265
266     case REQ_PROCESS_GET_NAME:
267       req->process_get_name.result = SIMIX_process_get_name(req->process_get_name.process);
268       SIMIX_request_answer(req);
269       break;
270
271     case REQ_PROCESS_IS_SUSPENDED:
272       req->process_is_suspended.result =
273         SIMIX_process_is_suspended(req->process_is_suspended.process);
274       SIMIX_request_answer(req);
275       break;
276
277     case REQ_PROCESS_GET_PROPERTIES:
278       req->process_get_properties.result =
279         SIMIX_process_get_properties(req->process_get_properties.process);
280       SIMIX_request_answer(req);
281       break;
282
283     case REQ_PROCESS_SLEEP:
284       SIMIX_pre_process_sleep(req);
285       break;
286
287     case REQ_RDV_CREATE:
288       req->rdv_create.result = SIMIX_rdv_create(req->rdv_create.name);
289       SIMIX_request_answer(req);
290       break;
291
292     case REQ_RDV_DESTROY:
293       SIMIX_rdv_destroy(req->rdv_destroy.rdv);
294       SIMIX_request_answer(req);
295       break;
296
297     case REQ_RDV_GEY_BY_NAME:
298       req->rdv_get_by_name.result = 
299         SIMIX_rdv_get_by_name(req->rdv_get_by_name.name);
300       SIMIX_request_answer(req);
301       break;
302
303     case REQ_RDV_COMM_COUNT_BY_HOST:
304       req->rdv_comm_count_by_host.result = SIMIX_rdv_comm_count_by_host(
305           req->rdv_comm_count_by_host.rdv,
306           req->rdv_comm_count_by_host.host);
307       SIMIX_request_answer(req);
308       break;
309
310     case REQ_RDV_GET_HEAD:
311       req->rdv_get_head.result =        SIMIX_rdv_get_head(req->rdv_get_head.rdv);
312       SIMIX_request_answer(req);
313       break;
314
315     case REQ_COMM_ISEND:
316       req->comm_isend.result = SIMIX_comm_isend(
317           req->issuer,
318           req->comm_isend.rdv,
319           req->comm_isend.task_size,
320           req->comm_isend.rate,
321           req->comm_isend.src_buff,
322           req->comm_isend.src_buff_size,
323           req->comm_isend.match_fun,
324           req->comm_isend.data);
325       SIMIX_request_answer(req);
326       break;
327
328     case REQ_COMM_IRECV:
329       req->comm_irecv.result = SIMIX_comm_irecv(
330           req->issuer,
331           req->comm_irecv.rdv,
332           req->comm_irecv.dst_buff,
333           req->comm_irecv.dst_buff_size,
334           req->comm_irecv.match_fun,
335           req->comm_irecv.data);
336       SIMIX_request_answer(req);
337       break;
338
339     case REQ_COMM_DESTROY:
340       SIMIX_comm_destroy(req->comm_destroy.comm);
341       SIMIX_request_answer(req);
342       break;
343
344     case REQ_COMM_CANCEL:
345       SIMIX_comm_cancel(req->comm_cancel.comm);
346       SIMIX_request_answer(req);
347       break;
348
349     case REQ_COMM_WAITANY:
350       SIMIX_pre_comm_waitany(req);
351       break;
352
353     case REQ_COMM_WAIT:
354       SIMIX_pre_comm_wait(req);
355       break;
356
357     case REQ_COMM_TEST:
358       SIMIX_pre_comm_test(req);
359       break;
360
361     case REQ_COMM_TESTANY:
362       SIMIX_pre_comm_testany(req);
363       break;
364
365     case REQ_COMM_GET_REMAINS:
366       req->comm_get_remains.result = 
367         SIMIX_comm_get_remains(req->comm_get_remains.comm);
368       SIMIX_request_answer(req);
369       break;
370
371     case REQ_COMM_GET_STATE:
372       req->comm_get_state.result = 
373         SIMIX_comm_get_state(req->comm_get_state.comm);
374       SIMIX_request_answer(req);
375       break;
376
377     case REQ_COMM_GET_SRC_DATA:
378       req->comm_get_src_data.result = SIMIX_comm_get_src_data(req->comm_get_src_data.comm);
379       SIMIX_request_answer(req);
380       break;
381
382     case REQ_COMM_GET_DST_DATA:
383       req->comm_get_dst_data.result = SIMIX_comm_get_dst_data(req->comm_get_dst_data.comm);
384       SIMIX_request_answer(req);
385       break;
386
387     case REQ_COMM_GET_SRC_BUFF:
388       req->comm_get_src_buff.result =
389         SIMIX_comm_get_src_buff(req->comm_get_src_buff.comm);
390       SIMIX_request_answer(req);
391       break;
392
393     case REQ_COMM_GET_DST_BUFF:
394       req->comm_get_dst_buff.result =
395         SIMIX_comm_get_dst_buff(req->comm_get_dst_buff.comm);
396       SIMIX_request_answer(req);
397       break;
398
399     case REQ_COMM_GET_SRC_BUFF_SIZE:
400       req->comm_get_src_buff_size.result = 
401         SIMIX_comm_get_src_buff_size(req->comm_get_src_buff_size.comm);
402       SIMIX_request_answer(req);
403       break;
404
405     case REQ_COMM_GET_DST_BUFF_SIZE:
406       req->comm_get_dst_buff_size.result =
407         SIMIX_comm_get_dst_buff_size(req->comm_get_dst_buff_size.comm);
408       SIMIX_request_answer(req);
409       break;
410
411     case REQ_COMM_GET_SRC_PROC:
412       req->comm_get_src_proc.result = 
413         SIMIX_comm_get_src_proc(req->comm_get_src_proc.comm);
414       SIMIX_request_answer(req);
415       break;
416
417     case REQ_COMM_GET_DST_PROC:
418       req->comm_get_dst_proc.result =
419         SIMIX_comm_get_dst_proc(req->comm_get_dst_proc.comm);
420       SIMIX_request_answer(req);
421       break;
422
423 #ifdef HAVE_LATENCY_BOUND_TRACKING
424     case REQ_COMM_IS_LATENCY_BOUNDED:
425       req->comm_is_latency_bounded.result =
426         SIMIX_comm_is_latency_bounded(req->comm_is_latency_bounded.comm);
427       SIMIX_request_answer(req);
428       break;
429 #endif
430
431 #ifdef HAVE_TRACING
432     case REQ_SET_CATEGORY:
433       SIMIX_set_category(
434           req->set_category.action,
435           req->set_category.category);
436       SIMIX_request_answer(req);
437       break;
438 #endif
439
440     case REQ_MUTEX_INIT:
441       req->mutex_init.result = SIMIX_mutex_init();
442       SIMIX_request_answer(req);
443       break;
444
445     case REQ_MUTEX_DESTROY:
446       SIMIX_mutex_destroy(req->mutex_destroy.mutex);
447       SIMIX_request_answer(req);
448       break;
449
450     case REQ_MUTEX_LOCK:
451       SIMIX_pre_mutex_lock(req);
452       break;
453
454     case REQ_MUTEX_TRYLOCK:
455       req->mutex_trylock.result =
456               SIMIX_mutex_trylock(req->mutex_trylock.mutex, req->issuer);
457       SIMIX_request_answer(req);
458       break;
459
460     case REQ_MUTEX_UNLOCK:
461       SIMIX_mutex_unlock(req->mutex_unlock.mutex, req->issuer);
462       SIMIX_request_answer(req);
463       break;
464
465     case REQ_COND_INIT:
466       req->cond_init.result = SIMIX_cond_init();
467       SIMIX_request_answer(req);
468       break;
469
470     case REQ_COND_DESTROY:
471       SIMIX_cond_destroy(req->cond_destroy.cond);
472       SIMIX_request_answer(req);
473       break;
474
475     case REQ_COND_SIGNAL:
476       SIMIX_cond_signal(req->cond_signal.cond);
477       SIMIX_request_answer(req);
478       break;
479
480     case REQ_COND_WAIT:
481       SIMIX_pre_cond_wait(req);
482       break;
483
484     case REQ_COND_WAIT_TIMEOUT:
485       SIMIX_pre_cond_wait_timeout(req);
486       break;
487
488     case REQ_COND_BROADCAST:
489       SIMIX_cond_broadcast(req->cond_broadcast.cond);
490       SIMIX_request_answer(req);
491       break;
492
493     case REQ_SEM_INIT:
494       req->sem_init.result = SIMIX_sem_init(req->sem_init.capacity);
495       SIMIX_request_answer(req);
496       break;
497
498     case REQ_SEM_DESTROY:
499       SIMIX_sem_destroy(req->sem_destroy.sem);
500       SIMIX_request_answer(req);
501       break;
502
503     case REQ_SEM_RELEASE:
504       SIMIX_sem_release(req->sem_release.sem);
505       SIMIX_request_answer(req);
506       break;
507
508     case REQ_SEM_WOULD_BLOCK:
509       req->sem_would_block.result =
510         SIMIX_sem_would_block(req->sem_would_block.sem);
511       SIMIX_request_answer(req);
512       break;
513
514     case REQ_SEM_ACQUIRE:
515       SIMIX_pre_sem_acquire(req);
516       break;
517
518     case REQ_SEM_ACQUIRE_TIMEOUT:
519       SIMIX_pre_sem_acquire_timeout(req);
520       break;
521
522     case REQ_SEM_GET_CAPACITY:
523       req->sem_get_capacity.result = 
524         SIMIX_sem_get_capacity(req->sem_get_capacity.sem);
525       SIMIX_request_answer(req);
526       break;
527   }
528 }
529
530 void SIMIX_request_post(smx_action_t action)
531 {
532   switch (action->type) {
533
534     case SIMIX_ACTION_EXECUTE:
535     case SIMIX_ACTION_PARALLEL_EXECUTE:
536       SIMIX_post_host_execute(action);
537       break;
538
539     case SIMIX_ACTION_COMMUNICATE:
540       SIMIX_post_comm(action);
541       break;
542
543     case SIMIX_ACTION_SLEEP:
544       SIMIX_post_process_sleep(action);
545       break;
546
547     case SIMIX_ACTION_SYNCHRO:
548       SIMIX_post_synchro(action);
549       break;
550
551     case SIMIX_ACTION_IO:
552       break;
553   }
554 }