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 void SIMIX_comm_remove_from_processes(smx_action_t action);
22 static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm);
23 static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm);
24 static smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
25 int (*match_fun)(void *, void *), void *);
26 static void SIMIX_rdv_free(void *data);
28 void SIMIX_network_init(void)
30 rdv_points = xbt_dict_new();
33 void SIMIX_network_exit(void)
35 xbt_dict_free(&rdv_points);
38 /******************************************************************************/
39 /* Rendez-Vous Points */
40 /******************************************************************************/
42 smx_rdv_t SIMIX_rdv_create(const char *name)
44 /* two processes may have pushed the same rdv_create request at the same time */
45 smx_rdv_t rdv = name ? xbt_dict_get_or_null(rdv_points, name) : NULL;
48 rdv = xbt_new0(s_smx_rvpoint_t, 1);
49 rdv->name = name ? xbt_strdup(name) : NULL;
50 rdv->comm_fifo = xbt_fifo_new();
53 xbt_dict_set(rdv_points, rdv->name, rdv, SIMIX_rdv_free);
58 void SIMIX_rdv_destroy(smx_rdv_t rdv)
61 xbt_dict_remove(rdv_points, rdv->name);
64 void SIMIX_rdv_free(void *data)
66 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;
119 * \brief Wrapper to SIMIX_rdv_get_request
121 smx_action_t SIMIX_comm_get_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
122 return SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
126 * \brief Checks if there is a communication action queued in a rendez-vous matching our needs
127 * \param type The type of communication we are looking for (comm_send, comm_recv)
128 * \return The communication action if found, NULL otherwise
130 smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
131 int (*match_fun)(void *, void *), void *data)
133 // FIXME rewrite this function by using SIMIX_rdv_has_send/recv_match
135 xbt_fifo_item_t item;
136 void* req_data = NULL;
138 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
139 if (action->comm.type == SIMIX_COMM_SEND) {
140 req_data = action->comm.src_data;
141 } else if (action->comm.type == SIMIX_COMM_RECEIVE) {
142 req_data = action->comm.dst_data;
144 if (action->comm.type == type && (!match_fun || match_fun(data, req_data))) {
145 XBT_DEBUG("Found a matching communication action %p", action);
146 xbt_fifo_remove_item(rdv->comm_fifo, item);
147 xbt_fifo_free_item(item);
148 action->comm.refcount++;
149 action->comm.rdv = NULL;
152 XBT_DEBUG("Sorry, communication action %p does not match our needs:"
153 " its type is %d but we are looking for a comm of type %d",
154 action, action->comm.type, type);
156 XBT_DEBUG("No matching communication action found");
161 * \brief Checks if there is a send communication action
162 * queued in a rendez-vous matching our needs.
163 * \return 1 if found, 0 otherwise
165 int SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
168 xbt_fifo_item_t item;
170 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
171 if (action->comm.type == SIMIX_COMM_SEND
172 && (!match_fun || match_fun(data, action->comm.src_data))) {
173 XBT_DEBUG("Found a matching communication action %p", action);
177 XBT_DEBUG("No matching communication action found");
182 * \brief Checks if there is a recv communication action
183 * queued in a rendez-vous matching our needs.
184 * \return 1 if found, 0 otherwise
186 int SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) {
189 xbt_fifo_item_t item;
191 xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){
192 if (action->comm.type == SIMIX_COMM_RECEIVE
193 && (!match_fun || match_fun(data, action->comm.dst_data))) {
194 XBT_DEBUG("Found a matching communication action %p", action);
198 XBT_DEBUG("No matching communication action found");
202 /******************************************************************************/
203 /* Comunication Actions */
204 /******************************************************************************/
207 * \brief Creates a new comunicate action
208 * \param type The type of request (comm_send, comm_recv)
209 * \return The new comunicate action
211 smx_action_t SIMIX_comm_new(e_smx_comm_type_t type)
215 /* alloc structures */
216 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)", action, action->comm.refcount);
247 if (action->comm.refcount <= 0)
248 xbt_die("the refcount of comm %p is already 0 before decreasing it. "
249 "That's a bug!", action);
251 action->comm.refcount--;
252 if (action->comm.refcount > 0)
254 XBT_DEBUG("Really free communication %p; refcount is now %d", action,
255 action->comm.refcount);
257 #ifdef HAVE_LATENCY_BOUND_TRACKING
258 action->latency_limited = SIMIX_comm_is_latency_bounded( action ) ;
261 xbt_free(action->name);
262 SIMIX_comm_destroy_internal_actions(action);
264 if (action->comm.detached && action->state != SIMIX_DONE) {
265 /* the communication has failed and was detached:
266 * we have to free the buffer */
267 ((void_f_pvoid_t) action->comm.src_data)(action->comm.src_buff);
270 xbt_mallocator_release(simix_global->action_mallocator, action);
273 void SIMIX_comm_destroy_internal_actions(smx_action_t action)
275 if (action->comm.surf_comm){
276 #ifdef HAVE_LATENCY_BOUND_TRACKING
277 action->latency_limited = SIMIX_comm_is_latency_bounded(action);
279 action->comm.surf_comm->model_type->action_unref(action->comm.surf_comm);
280 action->comm.surf_comm = NULL;
283 if (action->comm.src_timeout){
284 action->comm.src_timeout->model_type->action_unref(action->comm.src_timeout);
285 action->comm.src_timeout = NULL;
288 if (action->comm.dst_timeout){
289 action->comm.dst_timeout->model_type->action_unref(action->comm.dst_timeout);
290 action->comm.dst_timeout = NULL;
294 smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
295 double task_size, double rate,
296 void *src_buff, size_t src_buff_size,
297 int (*match_fun)(void *, void *), void *data,
302 /* Look for communication request matching our needs.
303 If it is not found then create it and push it into the rendez-vous point */
304 action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_RECEIVE, match_fun, data);
307 action = SIMIX_comm_new(SIMIX_COMM_SEND);
308 SIMIX_rdv_push(rdv, action);
310 action->state = SIMIX_READY;
311 action->comm.type = SIMIX_COMM_READY;
313 xbt_fifo_push(src_proc->comms, action);
315 /* if the communication action is detached then decrease the refcount
316 * by one, so it will be eliminated by the receiver's 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;
357 xbt_fifo_push(dst_proc->comms, action);
359 /* Setup communication request */
360 action->comm.dst_proc = dst_proc;
361 action->comm.dst_buff = dst_buff;
362 action->comm.dst_buff_size = dst_buff_size;
363 action->comm.dst_data = data;
366 action->state = SIMIX_RUNNING;
370 SIMIX_comm_start(action);
374 void SIMIX_pre_comm_wait(smx_req_t req, smx_action_t action, double timeout, int idx)
376 /* the request may be a wait, a send or a recv */
379 /* Associate this request to the action */
380 xbt_fifo_push(action->request_list, req);
381 req->issuer->waiting_action = action;
385 action->state = SIMIX_DONE;
387 /* If we reached this point, the wait request must have a timeout */
388 /* Otherwise it shouldn't be enabled and executed by the MC */
392 if (action->comm.src_proc == req->issuer)
393 action->state = SIMIX_SRC_TIMEOUT;
395 action->state = SIMIX_DST_TIMEOUT;
398 SIMIX_comm_finish(action);
402 /* If the action has already finish perform the error handling, */
403 /* otherwise set up a waiting timeout on the right side */
404 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
405 SIMIX_comm_finish(action);
406 } 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 */
407 sleep = surf_workstation_model->extension.workstation.sleep(req->issuer->smx_host->host, timeout);
408 surf_workstation_model->action_data_set(sleep, action);
410 if (req->issuer == action->comm.src_proc)
411 action->comm.src_timeout = sleep;
413 action->comm.dst_timeout = sleep;
417 void SIMIX_pre_comm_test(smx_req_t req)
419 smx_action_t action = req->comm_test.comm;
422 req->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
423 if(req->comm_test.result){
424 action->state = SIMIX_DONE;
425 xbt_fifo_push(action->request_list, req);
426 SIMIX_comm_finish(action);
428 SIMIX_request_answer(req);
433 req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
434 if (req->comm_test.result) {
435 xbt_fifo_push(action->request_list, req);
436 SIMIX_comm_finish(action);
438 SIMIX_request_answer(req);
442 void SIMIX_pre_comm_testany(smx_req_t req, int idx)
446 xbt_dynar_t actions = req->comm_testany.comms;
447 req->comm_testany.result = -1;
451 SIMIX_request_answer(req);
453 action = xbt_dynar_get_as(actions, idx, smx_action_t);
454 req->comm_testany.result = idx;
455 xbt_fifo_push(action->request_list, req);
456 action->state = SIMIX_DONE;
457 SIMIX_comm_finish(action);
462 xbt_dynar_foreach(req->comm_testany.comms,cursor,action) {
463 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
464 req->comm_testany.result = cursor;
465 xbt_fifo_push(action->request_list, req);
466 SIMIX_comm_finish(action);
470 SIMIX_request_answer(req);
473 void SIMIX_pre_comm_waitany(smx_req_t req, int idx)
476 unsigned int cursor = 0;
477 xbt_dynar_t actions = req->comm_waitany.comms;
480 action = xbt_dynar_get_as(actions, idx, smx_action_t);
481 xbt_fifo_push(action->request_list, req);
482 req->comm_waitany.result = idx;
483 action->state = SIMIX_DONE;
484 SIMIX_comm_finish(action);
488 xbt_dynar_foreach(actions, cursor, action){
489 /* Associate this request to the action */
490 xbt_fifo_push(action->request_list, req);
491 if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING){
492 SIMIX_comm_finish(action);
498 void SIMIX_waitany_req_remove_from_actions(smx_req_t req)
501 unsigned int cursor = 0;
502 xbt_dynar_t actions = req->comm_waitany.comms;
504 xbt_dynar_foreach(actions, cursor, action){
505 xbt_fifo_remove(action->request_list, req);
510 * \brief Start the simulation of a communication request
511 * \param action The communication action
514 XBT_INLINE void SIMIX_comm_start(smx_action_t action)
516 /* If both the sender and the receiver are already there, start the communication */
517 if (action->state == SIMIX_READY) {
519 smx_host_t sender = action->comm.src_proc->smx_host;
520 smx_host_t receiver = action->comm.dst_proc->smx_host;
522 XBT_DEBUG("Starting communication %p from '%s' to '%s'", action,
523 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
525 action->comm.surf_comm = surf_workstation_model->extension.workstation.
526 communicate(sender->host, receiver->host, action->comm.task_size, action->comm.rate);
528 surf_workstation_model->action_data_set(action->comm.surf_comm, action);
530 action->state = SIMIX_RUNNING;
532 /* If a link is failed, detect it immediately */
533 if (surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
534 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
535 SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
536 action->state = SIMIX_LINK_FAILURE;
537 SIMIX_comm_destroy_internal_actions(action);
540 /* If any of the process is suspend, create the action but stop its execution,
541 it will be restarted when the sender process resume */
542 if (SIMIX_process_is_suspended(action->comm.src_proc) ||
543 SIMIX_process_is_suspended(action->comm.dst_proc)) {
544 /* FIXME: check what should happen with the action state */
545 surf_workstation_model->suspend(action->comm.surf_comm);
550 void SIMIX_comm_finish(smx_action_t action)
552 unsigned int destroy_count = 0;
555 SIMIX_comm_remove_from_processes(action);
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 THROWF(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 THROWF(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 THROWF(host_error, 0, "Host failed");
606 THROWF(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 THROWF(host_error, 0, "Host failed");
618 THROWF(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)",
629 action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL,
630 action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL,
631 req->issuer->name, req->issuer);
632 THROWF(network_error, 0, "Link failure");
634 CATCH(req->issuer->running_ctx->exception) {
635 req->issuer->doexception = 1;
643 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
644 if (req->issuer->doexception) {
645 if (req->call == REQ_COMM_WAITANY) {
646 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_waitany.comms, &action);
648 else if (req->call == REQ_COMM_TESTANY) {
649 req->issuer->running_ctx->exception.value = xbt_dynar_search(req->comm_testany.comms, &action);
653 req->issuer->waiting_action = NULL;
654 SIMIX_request_answer(req);
658 while (destroy_count-- > 0)
659 SIMIX_comm_destroy(action);
662 void SIMIX_post_comm(smx_action_t action)
664 /* Update action state */
665 if (action->comm.src_timeout &&
666 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_DONE)
667 action->state = SIMIX_SRC_TIMEOUT;
668 else if (action->comm.dst_timeout &&
669 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_DONE)
670 action->state = SIMIX_DST_TIMEOUT;
671 else if (action->comm.src_timeout &&
672 surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_FAILED)
673 action->state = SIMIX_SRC_HOST_FAILURE;
674 else if (action->comm.dst_timeout &&
675 surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_FAILED)
676 action->state = SIMIX_DST_HOST_FAILURE;
677 else if (action->comm.surf_comm &&
678 surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED)
679 action->state = SIMIX_LINK_FAILURE;
681 action->state = SIMIX_DONE;
683 XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
684 action, action->state, action->comm.src_proc, action->comm.dst_proc, action->comm.detached);
686 /* destroy the surf actions associated with the Simix communication */
687 SIMIX_comm_destroy_internal_actions(action);
689 /* if there are requests associated with the action, then answer them */
690 if (xbt_fifo_size(action->request_list)) {
691 SIMIX_comm_finish(action);
694 SIMIX_comm_remove_from_processes(action);
699 * \brief Removes a communication action from the list of pending communications
700 * of both processes (if they still exist)
701 * \param action a communication action
703 static void SIMIX_comm_remove_from_processes(smx_action_t action) {
705 if (action->comm.src_proc) {
706 xbt_fifo_remove(action->comm.src_proc->comms, action);
708 if (action->comm.dst_proc) {
709 xbt_fifo_remove(action->comm.dst_proc->comms, action);
713 void SIMIX_comm_cancel(smx_action_t action)
715 /* if the action is a waiting state means that it is still in a rdv */
716 /* so remove from it and delete it */
717 if (action->state == SIMIX_WAITING) {
718 SIMIX_rdv_remove(action->comm.rdv, action);
719 action->state = SIMIX_CANCELED;
721 else if (!MC_IS_ENABLED
722 && (action->state == SIMIX_READY || action->state == SIMIX_RUNNING)) {
724 /* when running the MC there are no surf actions */
725 surf_workstation_model->action_cancel(action->comm.surf_comm);
729 void SIMIX_comm_suspend(smx_action_t action)
731 /*FIXME: shall we suspend also the timeout actions? */
732 surf_workstation_model->suspend(action->comm.surf_comm);
735 void SIMIX_comm_resume(smx_action_t action)
737 /*FIXME: check what happen with the timeouts */
738 surf_workstation_model->resume(action->comm.surf_comm);
742 /************* Action Getters **************/
745 * \brief get the amount remaining from the communication
746 * \param action The communication
748 double SIMIX_comm_get_remains(smx_action_t action)
756 switch (action->state) {
759 remains = surf_workstation_model->get_remains(action->comm.surf_comm);
764 remains = 0; /*FIXME: check what should be returned */
768 remains = 0; /*FIXME: is this correct? */
774 e_smx_state_t SIMIX_comm_get_state(smx_action_t action)
776 return action->state;
780 * \brief Return the user data associated to the sender of the communication
781 * \param action The communication
782 * \return the user data
784 void* SIMIX_comm_get_src_data(smx_action_t action)
786 return action->comm.src_data;
790 * \brief Return the user data associated to the receiver of the communication
791 * \param action The communication
792 * \return the user data
794 void* SIMIX_comm_get_dst_data(smx_action_t action)
796 return action->comm.dst_data;
799 smx_process_t SIMIX_comm_get_src_proc(smx_action_t action)
801 return action->comm.src_proc;
804 smx_process_t SIMIX_comm_get_dst_proc(smx_action_t action)
806 return action->comm.dst_proc;
809 #ifdef HAVE_LATENCY_BOUND_TRACKING
811 * \brief verify if communication is latency bounded
812 * \param comm The communication
814 XBT_INLINE int SIMIX_comm_is_latency_bounded(smx_action_t action)
819 if (action->comm.surf_comm){
820 XBT_DEBUG("Getting latency limited for surf_action (%p)", action->comm.surf_comm);
821 action->latency_limited = surf_workstation_model->get_latency_limited(action->comm.surf_comm);
822 XBT_DEBUG("Action limited is %d", action->latency_limited);
824 return action->latency_limited;
828 /******************************************************************************/
829 /* SIMIX_comm_copy_data callbacks */
830 /******************************************************************************/
831 static void (*SIMIX_comm_copy_data_callback) (smx_action_t, size_t) =
832 &SIMIX_comm_copy_pointer_callback;
835 SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, size_t))
837 SIMIX_comm_copy_data_callback = callback;
840 void SIMIX_comm_copy_pointer_callback(smx_action_t comm, size_t buff_size)
842 xbt_assert((buff_size == sizeof(void *)),
843 "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
844 *(void **) (comm->comm.dst_buff) = comm->comm.src_buff;
847 void SIMIX_comm_copy_buffer_callback(smx_action_t comm, size_t buff_size)
849 memcpy(comm->comm.dst_buff, comm->comm.src_buff, buff_size);
853 * \brief Copy the communication data from the sender's buffer to the receiver's one
854 * \param comm The communication
856 void SIMIX_comm_copy_data(smx_action_t comm)
858 size_t buff_size = comm->comm.src_buff_size;
859 /* If there is no data to be copy then return */
860 if (!comm->comm.src_buff || !comm->comm.dst_buff || comm->comm.copied == 1)
863 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)",
865 comm->comm.src_proc->smx_host->name, comm->comm.src_buff,
866 comm->comm.dst_proc->smx_host->name, comm->comm.dst_buff, buff_size);
868 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
869 if (comm->comm.dst_buff_size)
870 buff_size = MIN(buff_size, *(comm->comm.dst_buff_size));
872 /* Update the receiver's buffer size to the copied amount */
873 if (comm->comm.dst_buff_size)
874 *comm->comm.dst_buff_size = buff_size;
879 (*SIMIX_comm_copy_data_callback) (comm, buff_size);
881 /* Set the copied flag so we copy data only once */
882 /* (this function might be called from both communication ends) */
883 comm->comm.copied = 1;