Logo AND Algorithmique Numérique Distribuée

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