Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More debugs around process suspension
[simgrid.git] / src / simix / smx_smurf.c
1 #include "smx_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 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
9 {
10   smx_process_t issuer = SIMIX_process_self();
11   return &issuer->simcall;
12 }
13
14 /**
15  * \brief Makes the current process do a simcall to the kernel and yields
16  * until completion.
17  * \param self the current process
18  */
19 void SIMIX_simcall_push(smx_process_t self)
20 {
21   if (self != simix_global->maestro_process) {
22     XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
23               SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
24     SIMIX_process_yield(self);
25   } else {
26     SIMIX_simcall_pre(&self->simcall, 0);
27   }
28 }
29
30 void SIMIX_simcall_answer(smx_simcall_t simcall)
31 {
32   if (simcall->issuer != simix_global->maestro_process){
33     XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
34         simcall->issuer->name, simcall->issuer);
35     simcall->issuer->simcall.call = SIMCALL_NONE;
36 /*    This check should be useless and slows everyone. Reactivate if you see something
37  *    weird in process scheduling.
38  */
39 /*    if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
40     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
41 /*    else DIE_IMPOSSIBLE; */
42   }
43 }
44
45 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
46 {
47   XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
48
49   switch (simcall->call) {
50     case SIMCALL_COMM_TEST:
51       SIMIX_pre_comm_test(simcall);
52       break;
53
54     case SIMCALL_COMM_TESTANY:
55       SIMIX_pre_comm_testany(simcall, value);
56       break;
57
58     case SIMCALL_COMM_WAIT:
59       SIMIX_pre_comm_wait(simcall,
60           simcall->comm_wait.comm,
61           simcall->comm_wait.timeout,
62           value);
63       break;
64
65     case SIMCALL_COMM_WAITANY:
66       SIMIX_pre_comm_waitany(simcall, value);
67       break;
68
69     case SIMCALL_COMM_SEND:
70     {
71       smx_action_t comm = SIMIX_comm_isend(
72           simcall->issuer,
73           simcall->comm_send.rdv,
74           simcall->comm_send.task_size,
75           simcall->comm_send.rate,
76           simcall->comm_send.src_buff,
77           simcall->comm_send.src_buff_size,
78           simcall->comm_send.match_fun,
79           NULL, /* no clean function since it's not detached */
80           simcall->comm_send.data,
81           0);
82       SIMIX_pre_comm_wait(simcall, comm, simcall->comm_send.timeout, 0);
83       break;
84     }
85
86     case SIMCALL_COMM_ISEND:
87       simcall->comm_isend.result = SIMIX_comm_isend(
88           simcall->issuer,
89           simcall->comm_isend.rdv,
90           simcall->comm_isend.task_size,
91           simcall->comm_isend.rate,
92           simcall->comm_isend.src_buff,
93           simcall->comm_isend.src_buff_size,
94           simcall->comm_isend.match_fun,
95           simcall->comm_isend.clean_fun,
96           simcall->comm_isend.data,
97           simcall->comm_isend.detached);
98       SIMIX_simcall_answer(simcall);
99       break;
100
101     case SIMCALL_COMM_RECV:
102     {
103       smx_action_t comm = SIMIX_comm_irecv(
104           simcall->issuer,
105           simcall->comm_recv.rdv,
106           simcall->comm_recv.dst_buff,
107           simcall->comm_recv.dst_buff_size,
108           simcall->comm_recv.match_fun,
109           simcall->comm_recv.data);
110       SIMIX_pre_comm_wait(simcall, comm, simcall->comm_recv.timeout, 0);
111       break;
112     }
113
114     case SIMCALL_COMM_IRECV:
115       simcall->comm_irecv.result = SIMIX_comm_irecv(
116           simcall->issuer,
117           simcall->comm_irecv.rdv,
118           simcall->comm_irecv.dst_buff,
119           simcall->comm_irecv.dst_buff_size,
120           simcall->comm_irecv.match_fun,
121           simcall->comm_irecv.data);
122       SIMIX_simcall_answer(simcall);
123       break;
124
125     case SIMCALL_COMM_DESTROY:
126       SIMIX_comm_destroy(simcall->comm_destroy.comm);
127       SIMIX_simcall_answer(simcall);
128       break;
129
130     case SIMCALL_COMM_CANCEL:
131       SIMIX_comm_cancel(simcall->comm_cancel.comm);
132       SIMIX_simcall_answer(simcall);
133       break;
134
135     case SIMCALL_COMM_GET_REMAINS:
136       simcall->comm_get_remains.result =
137           SIMIX_comm_get_remains(simcall->comm_get_remains.comm);
138       SIMIX_simcall_answer(simcall);
139       break;
140
141     case SIMCALL_COMM_GET_STATE:
142       simcall->comm_get_state.result =
143           SIMIX_comm_get_state(simcall->comm_get_state.comm);
144       SIMIX_simcall_answer(simcall);
145       break;
146
147     case SIMCALL_COMM_GET_SRC_DATA:
148       simcall->comm_get_src_data.result = SIMIX_comm_get_src_data(simcall->comm_get_src_data.comm);
149       SIMIX_simcall_answer(simcall);
150       break;
151
152     case SIMCALL_COMM_GET_DST_DATA:
153       simcall->comm_get_dst_data.result = SIMIX_comm_get_dst_data(simcall->comm_get_dst_data.comm);
154       SIMIX_simcall_answer(simcall);
155       break;
156
157     case SIMCALL_COMM_GET_SRC_PROC:
158       simcall->comm_get_src_proc.result =
159           SIMIX_comm_get_src_proc(simcall->comm_get_src_proc.comm);
160       SIMIX_simcall_answer(simcall);
161       break;
162
163     case SIMCALL_COMM_GET_DST_PROC:
164       simcall->comm_get_dst_proc.result =
165           SIMIX_comm_get_dst_proc(simcall->comm_get_dst_proc.comm);
166       SIMIX_simcall_answer(simcall);
167       break;
168
169 #ifdef HAVE_LATENCY_BOUND_TRACKING
170     case SIMCALL_COMM_IS_LATENCY_BOUNDED:
171       simcall->comm_is_latency_bounded.result =
172           SIMIX_comm_is_latency_bounded(simcall->comm_is_latency_bounded.comm);
173       SIMIX_simcall_answer(simcall);
174       break;
175 #endif
176
177     case SIMCALL_RDV_CREATE:
178       simcall->rdv_create.result = SIMIX_rdv_create(simcall->rdv_create.name);
179       SIMIX_simcall_answer(simcall);
180       break;
181
182     case SIMCALL_RDV_DESTROY:
183       SIMIX_rdv_destroy(simcall->rdv_destroy.rdv);
184       SIMIX_simcall_answer(simcall);
185       break;
186
187     case SIMCALL_RDV_GEY_BY_NAME:
188       simcall->rdv_get_by_name.result =
189         SIMIX_rdv_get_by_name(simcall->rdv_get_by_name.name);
190       SIMIX_simcall_answer(simcall);
191       break;
192
193     case SIMCALL_RDV_COMM_COUNT_BY_HOST:
194       simcall->rdv_comm_count_by_host.result = SIMIX_rdv_comm_count_by_host(
195           simcall->rdv_comm_count_by_host.rdv,
196           simcall->rdv_comm_count_by_host.host);
197       SIMIX_simcall_answer(simcall);
198       break;
199
200     case SIMCALL_RDV_GET_HEAD:
201       simcall->rdv_get_head.result = SIMIX_rdv_get_head(simcall->rdv_get_head.rdv);
202       SIMIX_simcall_answer(simcall);
203       break;
204
205     case SIMCALL_HOST_GET_BY_NAME:
206       simcall->host_get_by_name.result =
207         SIMIX_host_get_by_name(simcall->host_get_by_name.name);
208       SIMIX_simcall_answer(simcall);
209       break;
210
211     case SIMCALL_HOST_GET_NAME:
212       simcall->host_get_name.result =   SIMIX_host_get_name(simcall->host_get_name.host);
213       SIMIX_simcall_answer(simcall);
214       break;
215
216     case SIMCALL_HOST_GET_PROPERTIES:
217       simcall->host_get_properties.result =
218         SIMIX_host_get_properties(simcall->host_get_properties.host);
219       SIMIX_simcall_answer(simcall);
220       break;
221
222     case SIMCALL_HOST_GET_SPEED:
223       simcall->host_get_speed.result = 
224         SIMIX_host_get_speed(simcall->host_get_speed.host);
225       SIMIX_simcall_answer(simcall);
226       break;
227
228     case SIMCALL_HOST_GET_AVAILABLE_SPEED:
229       simcall->host_get_available_speed.result =
230         SIMIX_host_get_available_speed(simcall->host_get_available_speed.host);
231       SIMIX_simcall_answer(simcall);
232       break;
233
234     case SIMCALL_HOST_GET_STATE:
235       simcall->host_get_state.result = 
236         SIMIX_host_get_state(simcall->host_get_state.host);
237       SIMIX_simcall_answer(simcall);
238       break;
239
240     case SIMCALL_HOST_GET_DATA:
241       simcall->host_get_data.result =   SIMIX_host_get_data(simcall->host_get_data.host);
242       SIMIX_simcall_answer(simcall);
243       break;
244
245     case SIMCALL_HOST_SET_DATA:
246       SIMIX_host_set_data(simcall->host_set_data.host, simcall->host_set_data.data);
247       SIMIX_simcall_answer(simcall);
248       break;
249
250     case SIMCALL_HOST_EXECUTE:
251       simcall->host_execute.result = SIMIX_host_execute(
252           simcall->host_execute.name,
253           simcall->host_execute.host,
254           simcall->host_execute.computation_amount,
255           simcall->host_execute.priority);
256       SIMIX_simcall_answer(simcall);
257       break;
258
259     case SIMCALL_HOST_PARALLEL_EXECUTE:
260       simcall->host_parallel_execute.result = SIMIX_host_parallel_execute(
261           simcall->host_parallel_execute.name,
262           simcall->host_parallel_execute.host_nb,
263           simcall->host_parallel_execute.host_list,
264           simcall->host_parallel_execute.computation_amount,
265           simcall->host_parallel_execute.communication_amount,
266           simcall->host_parallel_execute.amount,
267           simcall->host_parallel_execute.rate);
268       SIMIX_simcall_answer(simcall);
269       break;
270
271     case SIMCALL_HOST_EXECUTION_DESTROY:
272       SIMIX_host_execution_destroy(simcall->host_execution_destroy.execution);
273       SIMIX_simcall_answer(simcall);
274       break;
275
276     case SIMCALL_HOST_EXECUTION_CANCEL:
277       SIMIX_host_execution_cancel(simcall->host_execution_cancel.execution);
278       SIMIX_simcall_answer(simcall);
279       break;
280
281     case SIMCALL_HOST_EXECUTION_GET_REMAINS:
282       simcall->host_execution_get_remains.result =
283         SIMIX_host_execution_get_remains(simcall->host_execution_get_remains.execution);
284       SIMIX_simcall_answer(simcall);
285       break;
286
287     case SIMCALL_HOST_EXECUTION_GET_STATE:
288       simcall->host_execution_get_state.result =
289         SIMIX_host_execution_get_state(simcall->host_execution_get_state.execution);
290       SIMIX_simcall_answer(simcall);
291       break;
292
293     case SIMCALL_HOST_EXECUTION_SET_PRIORITY:
294       SIMIX_host_execution_set_priority(
295           simcall->host_execution_set_priority.execution,
296           simcall->host_execution_set_priority.priority);
297       SIMIX_simcall_answer(simcall);
298       break;
299
300     case SIMCALL_HOST_EXECUTION_WAIT:
301       SIMIX_pre_host_execution_wait(simcall);
302       break;
303
304     case SIMCALL_PROCESS_CREATE:
305       SIMIX_process_create(
306           simcall->process_create.process,
307           simcall->process_create.name,
308           simcall->process_create.code,
309           simcall->process_create.data,
310           simcall->process_create.hostname,
311           simcall->process_create.kill_time,
312           simcall->process_create.argc,
313           simcall->process_create.argv,
314           simcall->process_create.properties);
315       SIMIX_simcall_answer(simcall);
316       break;
317
318     case SIMCALL_PROCESS_KILL:
319       SIMIX_process_kill(simcall->process_kill.process);
320       SIMIX_simcall_answer(simcall);
321       break;
322
323     case SIMCALL_PROCESS_KILLALL:
324       SIMIX_process_killall(simcall->issuer);
325       SIMIX_simcall_answer(simcall);
326       break;
327
328     case SIMCALL_PROCESS_CLEANUP:
329       SIMIX_process_cleanup(simcall->process_cleanup.process);
330       SIMIX_simcall_answer(simcall);
331       break;
332
333     case SIMCALL_PROCESS_CHANGE_HOST:
334       SIMIX_pre_process_change_host(
335           simcall->process_change_host.process,
336           simcall->process_change_host.dest);
337       SIMIX_simcall_answer(simcall);
338       break;
339
340     case SIMCALL_PROCESS_SUSPEND:
341       SIMIX_pre_process_suspend(simcall);
342       break;
343
344     case SIMCALL_PROCESS_RESUME:
345       SIMIX_process_resume(simcall->process_resume.process, simcall->issuer);
346       SIMIX_simcall_answer(simcall);
347       break;
348
349     case SIMCALL_PROCESS_COUNT:
350       simcall->process_count.result = SIMIX_process_count();
351       SIMIX_simcall_answer(simcall);
352       break;
353
354     case SIMCALL_PROCESS_GET_DATA:
355       simcall->process_get_data.result =
356         SIMIX_process_get_data(simcall->process_get_data.process);
357       SIMIX_simcall_answer(simcall);
358       break;
359
360     case SIMCALL_PROCESS_SET_DATA:
361       SIMIX_process_set_data(
362           simcall->process_set_data.process,
363           simcall->process_set_data.data);
364       SIMIX_simcall_answer(simcall);
365       break;
366
367     case SIMCALL_PROCESS_GET_HOST:
368       simcall->process_get_host.result = SIMIX_process_get_host(simcall->process_get_host.process);
369       SIMIX_simcall_answer(simcall);
370       break;
371
372     case SIMCALL_PROCESS_GET_NAME:
373       simcall->process_get_name.result = SIMIX_process_get_name(simcall->process_get_name.process);
374       SIMIX_simcall_answer(simcall);
375       break;
376
377     case SIMCALL_PROCESS_IS_SUSPENDED:
378       simcall->process_is_suspended.result =
379         SIMIX_process_is_suspended(simcall->process_is_suspended.process);
380       SIMIX_simcall_answer(simcall);
381       break;
382
383     case SIMCALL_PROCESS_GET_PROPERTIES:
384       simcall->process_get_properties.result =
385         SIMIX_process_get_properties(simcall->process_get_properties.process);
386       SIMIX_simcall_answer(simcall);
387       break;
388
389     case SIMCALL_PROCESS_SLEEP:
390       SIMIX_pre_process_sleep(simcall);
391       break;
392
393 #ifdef HAVE_TRACING
394     case SIMCALL_SET_CATEGORY:
395       SIMIX_set_category(
396           simcall->set_category.action,
397           simcall->set_category.category);
398       SIMIX_simcall_answer(simcall);
399       break;
400 #endif
401
402     case SIMCALL_MUTEX_INIT:
403       simcall->mutex_init.result = SIMIX_mutex_init();
404       SIMIX_simcall_answer(simcall);
405       break;
406
407     case SIMCALL_MUTEX_DESTROY:
408       SIMIX_mutex_destroy(simcall->mutex_destroy.mutex);
409       SIMIX_simcall_answer(simcall);
410       break;
411
412     case SIMCALL_MUTEX_LOCK:
413       SIMIX_pre_mutex_lock(simcall);
414       break;
415
416     case SIMCALL_MUTEX_TRYLOCK:
417       simcall->mutex_trylock.result =
418               SIMIX_mutex_trylock(simcall->mutex_trylock.mutex, simcall->issuer);
419       SIMIX_simcall_answer(simcall);
420       break;
421
422     case SIMCALL_MUTEX_UNLOCK:
423       SIMIX_mutex_unlock(simcall->mutex_unlock.mutex, simcall->issuer);
424       SIMIX_simcall_answer(simcall);
425       break;
426
427     case SIMCALL_COND_INIT:
428       simcall->cond_init.result = SIMIX_cond_init();
429       SIMIX_simcall_answer(simcall);
430       break;
431
432     case SIMCALL_COND_DESTROY:
433       SIMIX_cond_destroy(simcall->cond_destroy.cond);
434       SIMIX_simcall_answer(simcall);
435       break;
436
437     case SIMCALL_COND_SIGNAL:
438       SIMIX_cond_signal(simcall->cond_signal.cond);
439       SIMIX_simcall_answer(simcall);
440       break;
441
442     case SIMCALL_COND_WAIT:
443       SIMIX_pre_cond_wait(simcall);
444       break;
445
446     case SIMCALL_COND_WAIT_TIMEOUT:
447       SIMIX_pre_cond_wait_timeout(simcall);
448       break;
449
450     case SIMCALL_COND_BROADCAST:
451       SIMIX_cond_broadcast(simcall->cond_broadcast.cond);
452       SIMIX_simcall_answer(simcall);
453       break;
454
455     case SIMCALL_SEM_INIT:
456       simcall->sem_init.result = SIMIX_sem_init(simcall->sem_init.capacity);
457       SIMIX_simcall_answer(simcall);
458       break;
459
460     case SIMCALL_SEM_DESTROY:
461       SIMIX_sem_destroy(simcall->sem_destroy.sem);
462       SIMIX_simcall_answer(simcall);
463       break;
464
465     case SIMCALL_SEM_RELEASE:
466       SIMIX_sem_release(simcall->sem_release.sem);
467       SIMIX_simcall_answer(simcall);
468       break;
469
470     case SIMCALL_SEM_WOULD_BLOCK:
471       simcall->sem_would_block.result =
472         SIMIX_sem_would_block(simcall->sem_would_block.sem);
473       SIMIX_simcall_answer(simcall);
474       break;
475
476     case SIMCALL_SEM_ACQUIRE:
477       SIMIX_pre_sem_acquire(simcall);
478       break;
479
480     case SIMCALL_SEM_ACQUIRE_TIMEOUT:
481       SIMIX_pre_sem_acquire_timeout(simcall);
482       break;
483
484     case SIMCALL_SEM_GET_CAPACITY:
485       simcall->sem_get_capacity.result = 
486         SIMIX_sem_get_capacity(simcall->sem_get_capacity.sem);
487       SIMIX_simcall_answer(simcall);
488       break;
489
490     case SIMCALL_FILE_READ:
491       SIMIX_pre_file_read(simcall);
492       break;
493
494     case SIMCALL_FILE_WRITE:
495       SIMIX_pre_file_write(simcall);
496       break;
497
498     case SIMCALL_FILE_OPEN:
499       SIMIX_pre_file_open(simcall);
500       break;
501
502     case SIMCALL_FILE_CLOSE:
503       SIMIX_pre_file_close(simcall);
504       break;
505
506     case SIMCALL_FILE_STAT:
507       SIMIX_pre_file_stat(simcall);
508       break;
509
510     case SIMCALL_NONE:
511       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
512           SIMIX_process_get_name(simcall->issuer),
513           SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
514           );
515       break;
516   }
517 }
518
519 void SIMIX_simcall_post(smx_action_t action)
520 {
521   switch (action->type) {
522
523     case SIMIX_ACTION_EXECUTE:
524     case SIMIX_ACTION_PARALLEL_EXECUTE:
525       SIMIX_post_host_execute(action);
526       break;
527
528     case SIMIX_ACTION_COMMUNICATE:
529       SIMIX_post_comm(action);
530       break;
531
532     case SIMIX_ACTION_SLEEP:
533       SIMIX_post_process_sleep(action);
534       break;
535
536     case SIMIX_ACTION_SYNCHRO:
537       SIMIX_post_synchro(action);
538       break;
539
540     case SIMIX_ACTION_IO:
541       SIMIX_post_io(action);
542       break;
543   }
544 }