1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix,
13 "Logging specific to SIMIX (network)");
15 static xbt_dict_t rdv_points = NULL;
16 unsigned long int smx_total_comms = 0;
18 static void SIMIX_waitany_req_remove_from_actions(smx_req_t req);
19 static void SIMIX_comm_copy_data(smx_action_t comm);
20 static smx_action_t SIMIX_comm_new(e_smx_comm_type_t type);
21 static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm);
22 static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm);
23 static smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
24 int (*match_fun)(void *, void *), void *);
25 static void SIMIX_rdv_free(void *data);
27 void SIMIX_network_init(void)
29 rdv_points = xbt_dict_new_homogeneous(SIMIX_rdv_free);
32 void SIMIX_network_exit(void)
34 xbt_dict_free(&rdv_points);
37 /******************************************************************************/
38 /* Rendez-Vous Points */
39 /******************************************************************************/
41 smx_rdv_t SIMIX_rdv_create(const char *name)
43 /* two processes may have pushed the same rdv_create request at the same time */
44 smx_rdv_t rdv = name ? xbt_dict_get_or_null(rdv_points, name) : NULL;
47 rdv = xbt_new0(s_smx_rvpoint_t, 1);
48 rdv->name = name ? xbt_strdup(name) : NULL;
49 rdv->comm_fifo = xbt_fifo_new();
52 xbt_dict_set(rdv_points, rdv->name, rdv, NULL);
57 void SIMIX_rdv_destroy(smx_rdv_t rdv)
60 xbt_dict_remove(rdv_points, rdv->name);
63 void SIMIX_rdv_free(void *data)
65 smx_rdv_t rdv = (smx_rdv_t) data;
67 xbt_fifo_free(rdv->comm_fifo);
71 smx_rdv_t SIMIX_rdv_get_by_name(const char *name)
73 return xbt_dict_get_or_null(rdv_points, name);
76 int SIMIX_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
78 smx_action_t comm = NULL;
79 xbt_fifo_item_t item = NULL;
82 xbt_fifo_foreach(rdv->comm_fifo, item, comm, smx_action_t) {
83 if (comm->comm.src_proc->smx_host == host)
90 smx_action_t SIMIX_rdv_get_head(smx_rdv_t rdv)
92 return xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo));
96 * \brief Push a communication request into a rendez-vous point
97 * \param rdv The rendez-vous point
98 * \param comm The communication request
100 static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm)
102 xbt_fifo_push(rdv->comm_fifo, comm);
103 comm->comm.rdv = rdv;
107 * \brief Remove a communication request from a rendez-vous point
108 * \param rdv The rendez-vous point
109 * \param comm The communication request
111 static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm)
113 xbt_fifo_remove(rdv->comm_fifo, comm);
114 comm->comm.rdv = NULL;
118 * \brief Wrapper to SIMIX_rdv_get_request
120 smx_action_t SIMIX_comm_get_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
121 return SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
125 * \brief Checks if there is a communication action queued in a rendez-vous matching our needs
126 * \param type The type of communication we are looking for (comm_send, comm_recv)
127 * \return The communication action if found, NULL otherwise
129 smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
130 int (*match_fun)(void *, void *), void *data)
132 // FIXME rewrite this function by using SIMIX_rdv_has_send/recv_match
134 xbt_fifo_item_t item;
135 void* req_data = NULL;
137 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t) {
138 if (action->comm.type == SIMIX_COMM_SEND) {
139 req_data = action->comm.src_data;
140 } else if (action->comm.type == SIMIX_COMM_RECEIVE) {
141 req_data = action->comm.dst_data;
143 if (action->comm.type == type && (!match_fun || match_fun(data, req_data))) {
144 XBT_DEBUG("Found a matching communication action %p", action);
145 xbt_fifo_remove_item(rdv->comm_fifo, item);
146 xbt_fifo_free_item(item);
147 action->comm.refcount++;
148 action->comm.rdv = NULL;
151 XBT_DEBUG("Sorry, communication action %p does not match our needs:"
152 " its type is %d but we are looking for a comm of type %d",
153 action, action->comm.type, type);
155 XBT_DEBUG("No matching communication action found");
160 * \brief Checks if there is a send communication action
161 * queued in a rendez-vous matching our needs.
162 * \return 1 if found, 0 otherwise
164 int SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
167 xbt_fifo_item_t item;
169 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
170 if (action->comm.type == SIMIX_COMM_SEND
171 && (!match_fun || match_fun(data, action->comm.src_data))) {
172 XBT_DEBUG("Found a matching communication action %p", action);
176 XBT_DEBUG("No matching communication action found");
181 * \brief Checks if there is a recv communication action
182 * queued in a rendez-vous matching our needs.
183 * \return 1 if found, 0 otherwise
185 int SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
188 xbt_fifo_item_t item;
190 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t) {
191 if (action->comm.type == SIMIX_COMM_RECEIVE
192 && (!match_fun || match_fun(data, action->comm.dst_data))) {
193 XBT_DEBUG("Found a matching communication action %p", action);
197 XBT_DEBUG("No matching communication action found");
201 /******************************************************************************/
202 /* Comunication Actions */
203 /******************************************************************************/
206 * \brief Creates a new comunicate action
207 * \param type The type of request (comm_send, comm_recv)
208 * \return The new comunicate action
210 smx_action_t SIMIX_comm_new(e_smx_comm_type_t type)
214 /* alloc structures */
215 act = xbt_mallocator_get(simix_global->action_mallocator);
217 act->type = SIMIX_ACTION_COMMUNICATE;
218 act->state = SIMIX_WAITING;
220 /* set communication */
221 act->comm.type = type;
222 act->comm.refcount = 1;
224 #ifdef HAVE_LATENCY_BOUND_TRACKING
225 //initialize with unknown value
226 act->latency_limited = -1;
230 act->category = NULL;
233 XBT_DEBUG("Create communicate action %p", act);
240 * \brief Destroy a communicate action
241 * \param action The communicate action to be destroyed
243 void SIMIX_comm_destroy(smx_action_t action)
245 XBT_DEBUG("Destroy action %p (refcount: %d), state: %d",
246 action, action->comm.refcount, action->state);
248 if (action->comm.refcount <= 0) {
249 xbt_backtrace_display_current();
250 xbt_die("the refcount of comm %p is already 0 before decreasing it. "
251 "That's a bug!", action);
253 action->comm.refcount--;
254 if (action->comm.refcount > 0)
256 XBT_DEBUG("Really free communication %p; refcount is now %d", action,
257 action->comm.refcount);
259 #ifdef HAVE_LATENCY_BOUND_TRACKING
260 action->latency_limited = SIMIX_comm_is_latency_bounded( action ) ;
263 xbt_free(action->name);
264 SIMIX_comm_destroy_internal_actions(action);
266 if (action->comm.detached && action->state != SIMIX_DONE) {
267 /* the communication has failed and was detached:
268 * we have to free the buffer */
269 action->comm.clean_fun(action->comm.src_buff);
270 action->comm.src_buff = NULL;
273 xbt_mallocator_release(simix_global->action_mallocator, action);
276 void SIMIX_comm_destroy_internal_actions(smx_action_t action)
278 if (action->comm.surf_comm){
279 #ifdef HAVE_LATENCY_BOUND_TRACKING
280 action->latency_limited = SIMIX_comm_is_latency_bounded(action);
282 action->comm.surf_comm->model_type->action_unref(action->comm.surf_comm);
283 action->comm.surf_comm = NULL;
286 if (action->comm.src_timeout){
287 action->comm.src_timeout->model_type->action_unref(action->comm.src_timeout);
288 action->comm.src_timeout = NULL;
291 if (action->comm.dst_timeout){
292 action->comm.dst_timeout->model_type->action_unref(action->comm.dst_timeout);
293 action->comm.dst_timeout = NULL;
297 smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
298 double task_size, double rate,
299 void *src_buff, size_t src_buff_size,
300 int (*match_fun)(void *, void *),
301 void (*clean_fun)(void *), // used to free the action in case of problem after a detached send
307 /* Look for communication request matching our needs.
308 If it is not found then create it and push it into the rendez-vous point */
309 action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_RECEIVE, match_fun, data);
312 action = SIMIX_comm_new(SIMIX_COMM_SEND);
313 SIMIX_rdv_push(rdv, action);
315 action->state = SIMIX_READY;
316 action->comm.type = SIMIX_COMM_READY;
318 xbt_fifo_push(src_proc->comms, action);
320 /* if the communication action is detached then decrease the refcount
321 * by one, so it will be eliminated by the receiver's destroy call */
323 action->comm.detached = 1;
324 action->comm.refcount--;
325 action->comm.clean_fun = clean_fun;
327 action->comm.clean_fun = NULL;
330 /* Setup the communication request */
331 action->comm.src_proc = src_proc;
332 action->comm.task_size = task_size;
333 action->comm.rate = rate;
334 action->comm.src_buff = src_buff;
335 action->comm.src_buff_size = src_buff_size;
336 action->comm.src_data = data;
339 action->state = SIMIX_RUNNING;
343 SIMIX_comm_start(action);
344 return (detached ? NULL : action);
347 smx_action_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_rdv_t rdv,
348 void *dst_buff, size_t *dst_buff_size,
349 int (*match_fun)(void *, void *), void *data)
353 /* Look for communication request matching our needs.
354 * If it is not found then create it and push it into the rendez-vous point
356 action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
359 action = SIMIX_comm_new(SIMIX_COMM_RECEIVE);
360 SIMIX_rdv_push(rdv, action);
362 action->state = SIMIX_READY;
363 action->comm.type = SIMIX_COMM_READY;
365 xbt_fifo_push(dst_proc->comms, action);
367 /* Setup communication request */
368 action->comm.dst_proc = dst_proc;
369 action->comm.dst_buff = dst_buff;
370 action->comm.dst_buff_size = dst_buff_size;
371 action->comm.dst_data = data;
374 action->state = SIMIX_RUNNING;
378 SIMIX_comm_start(action);
382 void SIMIX_pre_comm_wait(smx_req_t req, smx_action_t action, double timeout, int idx)
385 /* the request may be a wait, a send or a recv */
388 /* Associate this request to the action */
389 xbt_fifo_push(action->request_list, req);
390 req->issuer->waiting_action = action;
394 action->state = SIMIX_DONE;
396 /* If we reached this point, the wait request must have a timeout */
397 /* Otherwise it shouldn't be enabled and executed by the MC */
401 if (action->comm.src_proc == req->issuer)
402 action->state = SIMIX_SRC_TIMEOUT;
404 action->state = SIMIX_DST_TIMEOUT;
407 SIMIX_comm_finish(action);
411 /* If the action has already finish perform the error handling, */
412 /* otherwise set up a waiting timeout on the right side */
413 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
414 SIMIX_comm_finish(action);
415 } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
416 sleep = surf_workstation_model->extension.workstation.sleep(req->issuer->smx_host->host, timeout);
417 surf_workstation_model->action_data_set(sleep, action);
419 if (req->issuer == action->comm.src_proc)
420 action->comm.src_timeout = sleep;
422 action->comm.dst_timeout = sleep;
426 void SIMIX_pre_comm_test(smx_req_t req)
428 smx_action_t action = req->comm_test.comm;
431 req->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
432 if(req->comm_test.result){
433 action->state = SIMIX_DONE;
434 xbt_fifo_push(action->request_list, req);
435 SIMIX_comm_finish(action);
437 SIMIX_request_answer(req);
442 req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
443 if (req->comm_test.result) {
444 xbt_fifo_push(action->request_list, req);
445 SIMIX_comm_finish(action);
447 SIMIX_request_answer(req);
451 void SIMIX_pre_comm_testany(smx_req_t req, int idx)
455 xbt_dynar_t actions = req->comm_testany.comms;
456 req->comm_testany.result = -1;
460 SIMIX_request_answer(req);
462 action = xbt_dynar_get_as(actions, idx, smx_action_t);
463 req->comm_testany.result = idx;
464 xbt_fifo_push(action->request_list, req);
465 action->state = SIMIX_DONE;
466 SIMIX_comm_finish(action);
471 xbt_dynar_foreach(req->comm_testany.comms,cursor,action) {
472 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
473 req->comm_testany.result = cursor;
474 xbt_fifo_push(action->request_list, req);
475 SIMIX_comm_finish(action);
479 SIMIX_request_answer(req);
482 void SIMIX_pre_comm_waitany(smx_req_t req, int idx)
485 unsigned int cursor = 0;
486 xbt_dynar_t actions = req->comm_waitany.comms;
489 action = xbt_dynar_get_as(actions, idx, smx_action_t);
490 xbt_fifo_push(action->request_list, req);
491 req->comm_waitany.result = idx;
492 action->state = SIMIX_DONE;
493 SIMIX_comm_finish(action);
497 xbt_dynar_foreach(actions, cursor, action){
498 /* Associate this request to the action */
499 xbt_fifo_push(action->request_list, req);
500 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING){
501 SIMIX_comm_finish(action);
507 void SIMIX_waitany_req_remove_from_actions(smx_req_t req)
510 unsigned int cursor = 0;
511 xbt_dynar_t actions = req->comm_waitany.comms;
513 xbt_dynar_foreach(actions, cursor, action){
514 xbt_fifo_remove(action->request_list, req);
519 * \brief Start the simulation of a communication request
520 * \param action The communication action
523 XBT_INLINE void SIMIX_comm_start(smx_action_t action)
525 /* If both the sender and the receiver are already there, start the communication */
526 if (action->state == SIMIX_READY) {
528 smx_host_t sender = action->comm.src_proc->smx_host;
529 smx_host_t receiver = action->comm.dst_proc->smx_host;
531 XBT_DEBUG("Starting communication %p from '%s' to '%s'", action,
532 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
534 action->comm.surf_comm = surf_workstation_model->extension.workstation.
535 communicate(sender->host, receiver->host, action->comm.task_size, action->comm.rate);
537 surf_workstation_model->action_data_set(action->comm.surf_comm, action);
539 action->state = SIMIX_RUNNING;
541 /* If a link is failed, detect it immediately */
542 if (surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
543 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
544 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
545 action->state = SIMIX_LINK_FAILURE;
546 SIMIX_comm_destroy_internal_actions(action);
549 /* If any of the process is suspend, create the action but stop its execution,
550 it will be restarted when the sender process resume */
551 if (SIMIX_process_is_suspended(action->comm.src_proc) ||
552 SIMIX_process_is_suspended(action->comm.dst_proc)) {
553 /* FIXME: check what should happen with the action state */
554 surf_workstation_model->suspend(action->comm.surf_comm);
560 * \brief Answers the SIMIX requests associated to a communication action.
561 * \param action a finished communication action
563 void SIMIX_comm_finish(smx_action_t action)
565 volatile unsigned int destroy_count = 0;
568 while ((req = xbt_fifo_shift(action->request_list))) {
570 /* If a waitany request is waiting for this action to finish, then remove
571 it from the other actions in the waitany list. Afterwards, get the
572 position of the actual action in the waitany request's actions dynar and
573 return it as the result of the call */
574 if (req->call == REQ_COMM_WAITANY) {
575 SIMIX_waitany_req_remove_from_actions(req);
577 req->comm_waitany.result = xbt_dynar_search(req->comm_waitany.comms, &action);
580 /* If the action is still in a rendez-vous point then remove from it */
581 if (action->comm.rdv)
582 SIMIX_rdv_remove(action->comm.rdv, action);
584 XBT_DEBUG("SIMIX_comm_finish: action state = %d", action->state);
586 /* Check out for errors */
587 switch (action->state) {
590 XBT_DEBUG("Communication %p complete!", action);
591 SIMIX_comm_copy_data(action);
594 case SIMIX_SRC_TIMEOUT:
596 THROWF(timeout_error, 0, "Communication timeouted because of sender");
598 CATCH(req->issuer->running_ctx->exception) {
599 req->issuer->doexception = 1;
603 case SIMIX_DST_TIMEOUT:
605 THROWF(timeout_error, 0, "Communication timeouted because of receiver");
607 CATCH(req->issuer->running_ctx->exception) {
608 req->issuer->doexception = 1;
612 case SIMIX_SRC_HOST_FAILURE:
614 if (req->issuer == action->comm.src_proc)
615 THROWF(host_error, 0, "Host failed");
617 THROWF(network_error, 0, "Remote peer failed");
619 CATCH(req->issuer->running_ctx->exception) {
620 req->issuer->doexception = 1;
624 case SIMIX_DST_HOST_FAILURE:
626 if (req->issuer == action->comm.dst_proc)
627 THROWF(host_error, 0, "Host failed");
629 THROWF(network_error, 0, "Remote peer failed");
631 CATCH(req->issuer->running_ctx->exception) {
632 req->issuer->doexception = 1;
636 case SIMIX_LINK_FAILURE:
638 XBT_INFO("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d",
640 action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL,
641 action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL,
642 req->issuer->name, req->issuer,action->comm.detached);
643 if (action->comm.src_proc == req->issuer) {
644 XBT_INFO("I'm source");
645 } else if (action->comm.dst_proc == req->issuer) {
646 XBT_INFO("I'm dest");
648 XBT_INFO("I'm neither source nor dest");
650 THROWF(network_error, 0, "Link failure");
652 CATCH(req->issuer->running_ctx->exception) {
653 req->issuer->doexception = 1;
659 if (req->issuer == action->comm.dst_proc) {
660 THROWF(cancel_error, 0, "Communication canceled by the sender");
663 THROWF(cancel_error, 0, "Communication canceled by the receiver");
666 CATCH(req->issuer->running_ctx->exception) {
667 req->issuer->doexception = 1;
672 xbt_die("Unexpected action state in SIMIX_comm_finish: %d", action->state);
675 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
676 if (req->issuer->doexception) {
677 if (req->call == REQ_COMM_WAITANY) {
678 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_waitany.comms, &action);
680 else if (req->call == REQ_COMM_TESTANY) {
681 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_testany.comms, &action);
685 req->issuer->waiting_action = NULL;
686 xbt_fifo_remove(req->issuer->comms, action);
687 SIMIX_request_answer(req);
691 while (destroy_count-- > 0)
692 SIMIX_comm_destroy(action);
696 * \brief This function is called when a Surf communication action is finished.
697 * \param action the corresponding Simix communication
699 void SIMIX_post_comm(smx_action_t action)
701 /* Update action state */
702 if (action->comm.src_timeout &&
703 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_DONE)
704 action->state = SIMIX_SRC_TIMEOUT;
705 else if (action->comm.dst_timeout &&
706 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_DONE)
707 action->state = SIMIX_DST_TIMEOUT;
708 else if (action->comm.src_timeout &&
709 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_FAILED)
710 action->state = SIMIX_SRC_HOST_FAILURE;
711 else if (action->comm.dst_timeout &&
712 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_FAILED)
713 action->state = SIMIX_DST_HOST_FAILURE;
714 else if (action->comm.surf_comm &&
715 surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
716 XBT_INFO("Puta madre. Surf says that the link broke");
717 action->state = SIMIX_LINK_FAILURE;
719 action->state = SIMIX_DONE;
721 XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
722 action, action->state, action->comm.src_proc, action->comm.dst_proc, action->comm.detached);
724 /* destroy the surf actions associated with the Simix communication */
725 SIMIX_comm_destroy_internal_actions(action);
727 /* remove the communication action from the list of pending communications
728 * of both processes (if they still exist) */
729 if (action->comm.src_proc) {
730 xbt_fifo_remove(action->comm.src_proc->comms, action);
732 if (action->comm.dst_proc) {
733 xbt_fifo_remove(action->comm.dst_proc->comms, action);
736 /* if there are requests associated with the action, then answer them */
737 if (xbt_fifo_size(action->request_list)) {
738 SIMIX_comm_finish(action);
742 void SIMIX_comm_cancel(smx_action_t action)
744 /* if the action is a waiting state means that it is still in a rdv */
745 /* so remove from it and delete it */
746 if (action->state == SIMIX_WAITING) {
747 SIMIX_rdv_remove(action->comm.rdv, action);
748 action->state = SIMIX_CANCELED;
750 else if (!MC_IS_ENABLED /* when running the MC there are no surf actions */
751 && (action->state == SIMIX_READY || action->state == SIMIX_RUNNING)) {
753 surf_workstation_model->action_cancel(action->comm.surf_comm);
757 void SIMIX_comm_suspend(smx_action_t action)
759 /*FIXME: shall we suspend also the timeout actions? */
760 surf_workstation_model->suspend(action->comm.surf_comm);
763 void SIMIX_comm_resume(smx_action_t action)
765 /*FIXME: check what happen with the timeouts */
766 surf_workstation_model->resume(action->comm.surf_comm);
770 /************* Action Getters **************/
773 * \brief get the amount remaining from the communication
774 * \param action The communication
776 double SIMIX_comm_get_remains(smx_action_t action)
784 switch (action->state) {
787 remains = surf_workstation_model->get_remains(action->comm.surf_comm);
792 remains = 0; /*FIXME: check what should be returned */
796 remains = 0; /*FIXME: is this correct? */
802 e_smx_state_t SIMIX_comm_get_state(smx_action_t action)
804 return action->state;
808 * \brief Return the user data associated to the sender of the communication
809 * \param action The communication
810 * \return the user data
812 void* SIMIX_comm_get_src_data(smx_action_t action)
814 return action->comm.src_data;
818 * \brief Return the user data associated to the receiver of the communication
819 * \param action The communication
820 * \return the user data
822 void* SIMIX_comm_get_dst_data(smx_action_t action)
824 return action->comm.dst_data;
827 smx_process_t SIMIX_comm_get_src_proc(smx_action_t action)
829 return action->comm.src_proc;
832 smx_process_t SIMIX_comm_get_dst_proc(smx_action_t action)
834 return action->comm.dst_proc;
837 #ifdef HAVE_LATENCY_BOUND_TRACKING
839 * \brief verify if communication is latency bounded
840 * \param comm The communication
842 XBT_INLINE int SIMIX_comm_is_latency_bounded(smx_action_t action)
847 if (action->comm.surf_comm){
848 XBT_DEBUG("Getting latency limited for surf_action (%p)", action->comm.surf_comm);
849 action->latency_limited = surf_workstation_model->get_latency_limited(action->comm.surf_comm);
850 XBT_DEBUG("Action limited is %d", action->latency_limited);
852 return action->latency_limited;
856 /******************************************************************************/
857 /* SIMIX_comm_copy_data callbacks */
858 /******************************************************************************/
859 static void (*SIMIX_comm_copy_data_callback) (smx_action_t, size_t) =
860 &SIMIX_comm_copy_pointer_callback;
863 SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, size_t))
865 SIMIX_comm_copy_data_callback = callback;
868 void SIMIX_comm_copy_pointer_callback(smx_action_t comm, size_t buff_size)
870 xbt_assert((buff_size == sizeof(void *)),
871 "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
872 *(void **) (comm->comm.dst_buff) = comm->comm.src_buff;
875 void SIMIX_comm_copy_buffer_callback(smx_action_t comm, size_t buff_size)
877 XBT_DEBUG("Copy the data over");
878 memcpy(comm->comm.dst_buff, comm->comm.src_buff, buff_size);
881 void smpi_comm_copy_data_callback(smx_action_t comm, size_t buff_size)
883 XBT_DEBUG("Copy the data over");
884 memcpy(comm->comm.dst_buff, comm->comm.src_buff, buff_size);
885 if (comm->comm.detached) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the original buffer available to the application ASAP
886 comm->comm.clean_fun(comm->comm.src_buff);
887 comm->comm.src_buff = NULL;
892 * \brief Copy the communication data from the sender's buffer to the receiver's one
893 * \param comm The communication
895 void SIMIX_comm_copy_data(smx_action_t comm)
897 size_t buff_size = comm->comm.src_buff_size;
898 /* If there is no data to be copy then return */
899 if (!comm->comm.src_buff || !comm->comm.dst_buff || comm->comm.copied == 1)
902 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)",
904 comm->comm.src_proc->smx_host->name, comm->comm.src_buff,
905 comm->comm.dst_proc->smx_host->name, comm->comm.dst_buff, buff_size);
907 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
908 if (comm->comm.dst_buff_size)
909 buff_size = MIN(buff_size, *(comm->comm.dst_buff_size));
911 /* Update the receiver's buffer size to the copied amount */
912 if (comm->comm.dst_buff_size)
913 *comm->comm.dst_buff_size = buff_size;
916 SIMIX_comm_copy_data_callback (comm, buff_size);
918 /* Set the copied flag so we copy data only once */
919 /* (this function might be called from both communication ends) */
920 comm->comm.copied = 1;