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();
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, SIMIX_rdv_free);
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;
68 xbt_fifo_free(rdv->comm_fifo);
72 smx_rdv_t SIMIX_rdv_get_by_name(const char *name)
74 return xbt_dict_get_or_null(rdv_points, name);
77 int SIMIX_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
79 smx_action_t comm = NULL;
80 xbt_fifo_item_t item = NULL;
83 xbt_fifo_foreach(rdv->comm_fifo, item, comm, smx_action_t) {
84 if (comm->comm.src_proc->smx_host == host)
91 smx_action_t SIMIX_rdv_get_head(smx_rdv_t rdv)
93 return xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo));
97 * \brief Push a communication request into a rendez-vous point
98 * \param rdv The rendez-vous point
99 * \param comm The communication request
101 static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm)
103 xbt_fifo_push(rdv->comm_fifo, comm);
104 comm->comm.rdv = rdv;
108 * \brief Remove a communication request from a rendez-vous point
109 * \param rdv The rendez-vous point
110 * \param comm The communication request
112 static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm)
114 xbt_fifo_remove(rdv->comm_fifo, comm);
115 comm->comm.rdv = NULL;
118 smx_action_t SIMIX_comm_get_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
119 return SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
123 * \brief Checks if there is a communication action queued in a rendez-vous matching our needs
124 * \param type The type of communication we are looking for (comm_send, comm_recv)
125 * \return The communication action if found, NULL otherwise
127 smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
128 int (*match_fun)(void *, void *), void *data)
130 // FIXME rewrite this function by using SIMIX_rdv_has_send/recv_match
132 xbt_fifo_item_t item;
133 void* req_data = NULL;
135 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
136 if (action->comm.type == SIMIX_COMM_SEND) {
137 req_data = action->comm.src_data;
138 } else if (action->comm.type == SIMIX_COMM_RECEIVE) {
139 req_data = action->comm.dst_data;
141 if (action->comm.type == type && (!match_fun || match_fun(data, req_data))) {
142 XBT_DEBUG("Found a matching communication action %p", action);
143 xbt_fifo_remove_item(rdv->comm_fifo, item);
144 xbt_fifo_free_item(item);
145 action->comm.refcount++;
146 action->comm.rdv = NULL;
149 XBT_DEBUG("Sorry, communication action %p does not match our needs:"
150 " its type is %d but we are looking for a comm of type %d",
151 action, action->comm.type, type);
153 XBT_DEBUG("No matching communication action found");
158 * \brief Checks if there is a send communication action
159 * queued in a rendez-vous matching our needs.
160 * \return 1 if found, 0 otherwise
162 int SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
165 xbt_fifo_item_t item;
167 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
168 if (action->comm.type == SIMIX_COMM_SEND
169 && (!match_fun || match_fun(data, action->comm.src_data))) {
170 XBT_DEBUG("Found a matching communication action %p", action);
174 XBT_DEBUG("No matching communication action found");
179 * \brief Checks if there is a recv communication action
180 * queued in a rendez-vous matching our needs.
181 * \return 1 if found, 0 otherwise
183 int SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
186 xbt_fifo_item_t item;
188 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
189 if (action->comm.type == SIMIX_COMM_RECEIVE
190 && (!match_fun || match_fun(data, action->comm.dst_data))) {
191 XBT_DEBUG("Found a matching communication action %p", action);
195 XBT_DEBUG("No matching communication action found");
199 /******************************************************************************/
200 /* Comunication Actions */
201 /******************************************************************************/
204 * \brief Creates a new comunicate action
205 * \param type The type of request (comm_send, comm_recv)
206 * \return The new comunicate action
208 smx_action_t SIMIX_comm_new(e_smx_comm_type_t type)
212 /* alloc structures */
213 act = xbt_mallocator_get(simix_global->action_mallocator);
214 act->type = SIMIX_ACTION_COMMUNICATE;
215 act->state = SIMIX_WAITING;
217 /* set communication */
218 act->comm.type = type;
219 act->comm.refcount = 1;
221 #ifdef HAVE_LATENCY_BOUND_TRACKING
222 //initialize with unknown value
223 act->latency_limited = -1;
227 act->category = NULL;
230 XBT_DEBUG("Create communicate action %p", act);
237 * \brief Destroy a communicate action
238 * \param action The communicate action to be destroyed
240 void SIMIX_comm_destroy(smx_action_t action)
242 XBT_DEBUG("Destroy action %p (refcount:%d)", action, action->comm.refcount);
244 if (action->comm.refcount <= 0)
245 xbt_die("the refcount of comm %p is already 0 before decreasing it. "
246 "That's a bug!", action);
248 action->comm.refcount--;
249 if (action->comm.refcount > 0)
251 XBT_DEBUG("Really free communication %p; refcount is now %d", action,
252 action->comm.refcount);
254 #ifdef HAVE_LATENCY_BOUND_TRACKING
255 action->latency_limited = SIMIX_comm_is_latency_bounded( action ) ;
259 TRACE_smx_action_destroy(action);
262 xbt_free(action->name);
263 SIMIX_comm_destroy_internal_actions(action);
265 if (action->comm.detached && action->state != SIMIX_DONE) {
266 /* the communication has failed and was detached:
267 * we have to free the buffer */
268 ((void_f_pvoid_t) action->comm.src_data)(action->comm.src_buff);
271 xbt_mallocator_release(simix_global->action_mallocator, action);
274 void SIMIX_comm_destroy_internal_actions(smx_action_t action)
276 if (action->comm.surf_comm){
277 #ifdef HAVE_LATENCY_BOUND_TRACKING
278 action->latency_limited = SIMIX_comm_is_latency_bounded(action);
280 action->comm.surf_comm->model_type->action_unref(action->comm.surf_comm);
281 action->comm.surf_comm = NULL;
284 if (action->comm.src_timeout){
285 action->comm.src_timeout->model_type->action_unref(action->comm.src_timeout);
286 action->comm.src_timeout = NULL;
289 if (action->comm.dst_timeout){
290 action->comm.dst_timeout->model_type->action_unref(action->comm.dst_timeout);
291 action->comm.dst_timeout = NULL;
295 smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
296 double task_size, double rate,
297 void *src_buff, size_t src_buff_size,
298 int (*match_fun)(void *, void *), void *data,
303 /* Look for communication request matching our needs.
304 If it is not found then create it and push it into the rendez-vous point */
305 action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_RECEIVE, match_fun, data);
308 action = SIMIX_comm_new(SIMIX_COMM_SEND);
309 SIMIX_rdv_push(rdv, action);
311 action->state = SIMIX_READY;
312 action->comm.type = SIMIX_COMM_READY;
315 /* If the communication action is detached then decrease the refcount
316 * by one, so it will be eliminated by the receivers destroy call */
318 action->comm.detached = 1;
319 action->comm.refcount--;
322 /* Setup the communication request */
323 action->comm.src_proc = src_proc;
324 action->comm.task_size = task_size;
325 action->comm.rate = rate;
326 action->comm.src_buff = src_buff;
327 action->comm.src_buff_size = src_buff_size;
328 action->comm.src_data = data;
331 action->state = SIMIX_RUNNING;
335 SIMIX_comm_start(action);
339 smx_action_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_rdv_t rdv,
340 void *dst_buff, size_t *dst_buff_size,
341 int (*match_fun)(void *, void *), void *data)
345 /* Look for communication request matching our needs.
346 * If it is not found then create it and push it into the rendez-vous point
348 action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
351 action = SIMIX_comm_new(SIMIX_COMM_RECEIVE);
352 SIMIX_rdv_push(rdv, action);
354 action->state = SIMIX_READY;
355 action->comm.type = SIMIX_COMM_READY;
358 /* Setup communication request */
359 action->comm.dst_proc = dst_proc;
360 action->comm.dst_buff = dst_buff;
361 action->comm.dst_buff_size = dst_buff_size;
362 action->comm.dst_data = data;
365 action->state = SIMIX_RUNNING;
369 SIMIX_comm_start(action);
373 void SIMIX_pre_comm_wait(smx_req_t req, smx_action_t action, double timeout, int idx)
375 /* the request may be a wait, a send or a recv */
378 /* Associate this request to the action */
379 xbt_fifo_push(action->request_list, req);
380 req->issuer->waiting_action = action;
384 action->state = SIMIX_DONE;
386 /* If we reached this point, the wait request must have a timeout */
387 /* Otherwise it shouldn't be enabled and executed by the MC */
391 if (action->comm.src_proc == req->issuer)
392 action->state = SIMIX_SRC_TIMEOUT;
394 action->state = SIMIX_DST_TIMEOUT;
397 SIMIX_comm_finish(action);
401 /* If the action has already finish perform the error handling, */
402 /* otherwise set up a waiting timeout on the right side */
403 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
404 SIMIX_comm_finish(action);
405 } 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 */
406 sleep = surf_workstation_model->extension.workstation.sleep(req->issuer->smx_host->host, timeout);
407 surf_workstation_model->action_data_set(sleep, action);
409 if (req->issuer == action->comm.src_proc)
410 action->comm.src_timeout = sleep;
412 action->comm.dst_timeout = sleep;
416 void SIMIX_pre_comm_test(smx_req_t req)
418 smx_action_t action = req->comm_test.comm;
421 req->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
422 if(req->comm_test.result){
423 action->state = SIMIX_DONE;
424 xbt_fifo_push(action->request_list, req);
425 SIMIX_comm_finish(action);
427 SIMIX_request_answer(req);
432 req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
433 if (req->comm_test.result) {
434 xbt_fifo_push(action->request_list, req);
435 SIMIX_comm_finish(action);
437 SIMIX_request_answer(req);
441 void SIMIX_pre_comm_testany(smx_req_t req, int idx)
445 xbt_dynar_t actions = req->comm_testany.comms;
446 req->comm_testany.result = -1;
450 SIMIX_request_answer(req);
452 action = xbt_dynar_get_as(actions, idx, smx_action_t);
453 req->comm_testany.result = idx;
454 xbt_fifo_push(action->request_list, req);
455 action->state = SIMIX_DONE;
456 SIMIX_comm_finish(action);
461 xbt_dynar_foreach(req->comm_testany.comms,cursor,action) {
462 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
463 req->comm_testany.result = cursor;
464 xbt_fifo_push(action->request_list, req);
465 SIMIX_comm_finish(action);
469 SIMIX_request_answer(req);
472 void SIMIX_pre_comm_waitany(smx_req_t req, int idx)
475 unsigned int cursor = 0;
476 xbt_dynar_t actions = req->comm_waitany.comms;
479 action = xbt_dynar_get_as(actions, idx, smx_action_t);
480 xbt_fifo_push(action->request_list, req);
481 req->comm_waitany.result = idx;
482 action->state = SIMIX_DONE;
483 SIMIX_comm_finish(action);
487 xbt_dynar_foreach(actions, cursor, action){
488 /* Associate this request to the action */
489 xbt_fifo_push(action->request_list, req);
490 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING){
491 SIMIX_comm_finish(action);
497 void SIMIX_waitany_req_remove_from_actions(smx_req_t req)
500 unsigned int cursor = 0;
501 xbt_dynar_t actions = req->comm_waitany.comms;
503 xbt_dynar_foreach(actions, cursor, action){
504 xbt_fifo_remove(action->request_list, req);
509 * \brief Start the simulation of a communication request
510 * \param action The communication action
513 XBT_INLINE void SIMIX_comm_start(smx_action_t action)
515 /* If both the sender and the receiver are already there, start the communication */
516 if (action->state == SIMIX_READY) {
517 smx_host_t sender = action->comm.src_proc->smx_host;
518 smx_host_t receiver = action->comm.dst_proc->smx_host;
520 XBT_DEBUG("Starting communication %p from '%s' to '%s'", action,
521 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
523 action->comm.surf_comm = surf_workstation_model->extension.workstation.
524 communicate(sender->host, receiver->host, action->comm.task_size, action->comm.rate);
526 surf_workstation_model->action_data_set(action->comm.surf_comm, action);
528 action->state = SIMIX_RUNNING;
531 TRACE_smx_action_communicate(action, action->comm.src_proc);
534 /* If a link is failed, detect it immediately */
535 if (surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
536 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
537 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
538 action->state = SIMIX_LINK_FAILURE;
539 SIMIX_comm_destroy_internal_actions(action);
542 /* If any of the process is suspend, create the action but stop its execution,
543 it will be restarted when the sender process resume */
544 if (SIMIX_process_is_suspended(action->comm.src_proc) ||
545 SIMIX_process_is_suspended(action->comm.dst_proc)) {
546 /* FIXME: check what should happen with the action state */
547 surf_workstation_model->suspend(action->comm.surf_comm);
552 void SIMIX_comm_finish(smx_action_t action)
554 unsigned int destroy_count = 0;
557 while ((req = xbt_fifo_shift(action->request_list))) {
559 /* If a waitany request is waiting for this action to finish, then remove
560 it from the other actions in the waitany list. Afterwards, get the
561 position of the actual action in the waitany request's actions dynar and
562 return it as the result of the call */
563 if (req->call == REQ_COMM_WAITANY) {
564 SIMIX_waitany_req_remove_from_actions(req);
566 req->comm_waitany.result = xbt_dynar_search(req->comm_waitany.comms, &action);
569 /* If the action is still in a rendez-vous point then remove from it */
570 if (action->comm.rdv)
571 SIMIX_rdv_remove(action->comm.rdv, action);
573 XBT_DEBUG("SIMIX_comm_finish: action state = %d", action->state);
575 /* Check out for errors */
576 switch (action->state) {
579 XBT_DEBUG("Communication %p complete!", action);
580 SIMIX_comm_copy_data(action);
583 case SIMIX_SRC_TIMEOUT:
585 THROW0(timeout_error, 0, "Communication timeouted because of sender");
587 CATCH(req->issuer->running_ctx->exception) {
588 req->issuer->doexception = 1;
592 case SIMIX_DST_TIMEOUT:
594 THROW0(timeout_error, 0, "Communication timeouted because of receiver");
596 CATCH(req->issuer->running_ctx->exception) {
597 req->issuer->doexception = 1;
601 case SIMIX_SRC_HOST_FAILURE:
603 if (req->issuer == action->comm.src_proc)
604 THROW0(host_error, 0, "Host failed");
606 THROW0(network_error, 0, "Remote peer failed");
608 CATCH(req->issuer->running_ctx->exception) {
609 req->issuer->doexception = 1;
613 case SIMIX_DST_HOST_FAILURE:
615 if (req->issuer == action->comm.dst_proc)
616 THROW0(host_error, 0, "Host failed");
618 THROW0(network_error, 0, "Remote peer failed");
620 CATCH(req->issuer->running_ctx->exception) {
621 req->issuer->doexception = 1;
625 case SIMIX_LINK_FAILURE:
627 XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p)",
628 action, action->comm.src_proc->smx_host->name, action->comm.dst_proc->smx_host->name,
629 req->issuer->name, req->issuer);
630 THROW0(network_error, 0, "Link failure");
632 CATCH(req->issuer->running_ctx->exception) {
633 req->issuer->doexception = 1;
641 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
642 if (req->issuer->doexception) {
643 if (req->call == REQ_COMM_WAITANY) {
644 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_waitany.comms, &action);
646 else if (req->call == REQ_COMM_TESTANY) {
647 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_testany.comms, &action);
651 req->issuer->waiting_action = NULL;
652 SIMIX_request_answer(req);
656 while (destroy_count-- > 0)
657 SIMIX_comm_destroy(action);
660 void SIMIX_post_comm(smx_action_t action)
662 /* Update action state */
663 if (action->comm.src_timeout &&
664 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_DONE)
665 action->state = SIMIX_SRC_TIMEOUT;
666 else if (action->comm.dst_timeout &&
667 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_DONE)
668 action->state = SIMIX_DST_TIMEOUT;
669 else if (action->comm.src_timeout &&
670 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_FAILED)
671 action->state = SIMIX_SRC_HOST_FAILURE;
672 else if (action->comm.dst_timeout &&
673 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_FAILED)
674 action->state = SIMIX_DST_HOST_FAILURE;
675 else if (action->comm.surf_comm &&
676 surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED)
677 action->state = SIMIX_LINK_FAILURE;
679 action->state = SIMIX_DONE;
681 XBT_DEBUG("SIMIX_post_comm: action state = %d", action->state);
683 /* After this point the surf actions associated with the simix communicate
684 action are no longer needed, thus we delete them. */
685 SIMIX_comm_destroy_internal_actions(action);
687 /* If there are requests associated with the action, then answer them */
688 if (xbt_fifo_size(action->request_list))
689 SIMIX_comm_finish(action);
692 void SIMIX_comm_cancel(smx_action_t action)
694 /* If the action is a waiting state means that it is still in a rdv */
695 /* so remove from it and delete it */
696 if (action->state == SIMIX_WAITING) {
697 SIMIX_rdv_remove(action->comm.rdv, action);
698 action->state = SIMIX_FAILED;
700 /* When running the MC there are no surf actions */
702 surf_workstation_model->action_cancel(action->comm.surf_comm);
706 void SIMIX_comm_suspend(smx_action_t action)
708 /*FIXME: shall we suspend also the timeout actions? */
709 surf_workstation_model->suspend(action->comm.surf_comm);
712 void SIMIX_comm_resume(smx_action_t action)
714 /*FIXME: check what happen with the timeouts */
715 surf_workstation_model->resume(action->comm.surf_comm);
719 /************* Action Getters **************/
722 * \brief get the amount remaining from the communication
723 * \param action The communication
725 double SIMIX_comm_get_remains(smx_action_t action)
729 switch (action->state) {
732 remains = surf_workstation_model->get_remains(action->comm.surf_comm);
737 remains = 0; /*FIXME: check what should be returned */
741 remains = 0; /*FIXME: is this correct? */
747 e_smx_state_t SIMIX_comm_get_state(smx_action_t action)
749 return action->state;
753 * \brief Return the user data associated to the sender of the communication
754 * \param action The communication
755 * \return the user data
757 void* SIMIX_comm_get_src_data(smx_action_t action)
759 return action->comm.src_data;
763 * \brief Return the user data associated to the receiver of the communication
764 * \param action The communication
765 * \return the user data
767 void* SIMIX_comm_get_dst_data(smx_action_t action)
769 return action->comm.dst_data;
772 smx_process_t SIMIX_comm_get_src_proc(smx_action_t action)
774 return action->comm.src_proc;
777 smx_process_t SIMIX_comm_get_dst_proc(smx_action_t action)
779 return action->comm.dst_proc;
782 #ifdef HAVE_LATENCY_BOUND_TRACKING
784 * \brief verify if communication is latency bounded
785 * \param comm The communication
787 XBT_INLINE int SIMIX_comm_is_latency_bounded(smx_action_t action)
789 if (action->comm.surf_comm){
790 XBT_DEBUG("Getting latency limited for surf_action (%p)", action->comm.surf_comm);
791 action->latency_limited = surf_workstation_model->get_latency_limited(action->comm.surf_comm);
792 XBT_DEBUG("Action limited is %d", action->latency_limited);
794 return action->latency_limited;
798 /******************************************************************************/
799 /* SIMIX_comm_copy_data callbacks */
800 /******************************************************************************/
801 static void (*SIMIX_comm_copy_data_callback) (smx_action_t, size_t) =
802 &SIMIX_comm_copy_pointer_callback;
805 SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, size_t))
807 SIMIX_comm_copy_data_callback = callback;
810 void SIMIX_comm_copy_pointer_callback(smx_action_t comm, size_t buff_size)
812 xbt_assert1((buff_size == sizeof(void *)),
813 "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
814 *(void **) (comm->comm.dst_buff) = comm->comm.src_buff;
817 void SIMIX_comm_copy_buffer_callback(smx_action_t comm, size_t buff_size)
819 memcpy(comm->comm.dst_buff, comm->comm.src_buff, buff_size);
823 * \brief Copy the communication data from the sender's buffer to the receiver's one
824 * \param comm The communication
826 void SIMIX_comm_copy_data(smx_action_t comm)
828 size_t buff_size = comm->comm.src_buff_size;
829 /* If there is no data to be copy then return */
830 if (!comm->comm.src_buff || !comm->comm.dst_buff || comm->comm.copied == 1)
833 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)",
835 comm->comm.src_proc->smx_host->name, comm->comm.src_buff,
836 comm->comm.dst_proc->smx_host->name, comm->comm.dst_buff, buff_size);
838 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
839 if (comm->comm.dst_buff_size)
840 buff_size = MIN(buff_size, *(comm->comm.dst_buff_size));
842 /* Update the receiver's buffer size to the copied amount */
843 if (comm->comm.dst_buff_size)
844 *comm->comm.dst_buff_size = buff_size;
849 (*SIMIX_comm_copy_data_callback) (comm, buff_size);
851 /* Set the copied flag so we copy data only once */
852 /* (this function might be called from both communication ends) */
853 comm->comm.copied = 1;