Logo AND Algorithmique Numérique Distribuée

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