From 20f2291e7c83e26eebe9aeb61a91b76b5aed5a64 Mon Sep 17 00:00:00 2001 From: Jonathan Rouzaud-Cornabas Date: Wed, 30 Jan 2013 00:25:05 +0100 Subject: [PATCH 1/1] Add dsend_bounded send_with_timeout_bounded --- include/msg/msg.h | 5 +++ src/msg/msg_gos.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/include/msg/msg.h b/include/msg/msg.h index 3be2d06513..5f0077ed1a 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -231,6 +231,7 @@ XBT_PUBLIC(msg_comm_t) MSG_task_isend_with_matching(msg_task_t task, void *match_data); XBT_PUBLIC(void) MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup); +XBT_PUBLIC(void) MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate); XBT_PUBLIC(msg_comm_t) MSG_task_irecv(msg_task_t * task, const char *alias); XBT_PUBLIC(int) MSG_comm_test(msg_comm_t comm); XBT_PUBLIC(int) MSG_comm_testany(xbt_dynar_t comms); @@ -250,6 +251,10 @@ XBT_PUBLIC(int) MSG_task_listen_from_host(const char *alias, XBT_PUBLIC(msg_error_t) MSG_task_send_with_timeout(msg_task_t task, const char *alias, double timeout); + +XBT_PUBLIC(msg_error_t) + MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias, + double timeout, double maxrate); XBT_PUBLIC(msg_error_t) MSG_task_send(msg_task_t task, const char *alias); diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index e26738e156..d5ba36ef22 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -407,6 +407,66 @@ void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup) #endif } + +/** \ingroup msg_task_usage + * \brief Sends a task on a mailbox with a maximal rate. + * + * This is a non blocking detached send function. + * Think of it as a best effort send. Keep in mind that the third parameter + * is only called if the communication fails. If the communication does work, + * it is responsibility of the receiver code to free anything related to + * the task, as usual. More details on this can be obtained on + * this thread + * in the SimGrid-user mailing list archive. + * + * \param task a #msg_task_t to send on another location. + * \param alias name of the mailbox to sent the task to + * \param cleanup a function to destroy the task if the + * communication fails, e.g. MSG_task_destroy + * (if NULL, no function will be called) + * \param maxrate the maximum communication rate for sending this task + * + */ +void MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate) +{ + task->simdata->rate = maxrate; + + simdata_task_t t_simdata = NULL; + msg_process_t process = MSG_process_self(); + msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); + + /* Prepare the task to send */ + t_simdata = task->simdata; + t_simdata->sender = process; + t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host; + + xbt_assert(t_simdata->isused == 0, + "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); + + t_simdata->isused = 1; + t_simdata->comm = NULL; + msg_global->sent_msg++; + +#ifdef HAVE_TRACING + int call_end = TRACE_msg_task_put_start(task); +#endif + + /* Send it by calling SIMIX network layer */ + smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size, + t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1); + t_simdata->comm = comm; +#ifdef HAVE_TRACING + if (TRACE_is_enabled()) { + simcall_set_category(comm, task->category); + } +#endif + +#ifdef HAVE_TRACING + if (call_end) + TRACE_msg_task_put_end(); +#endif +} + /** \ingroup msg_task_usage * \brief Starts listening for receiving a task from an asynchronous communication. * @@ -763,6 +823,29 @@ MSG_task_send_with_timeout(msg_task_t task, const char *alias, task, timeout); } +/** \ingroup msg_task_usage + * \brief Sends a task to a mailbox with a timeout and with a maximum rate + * + * This is a blocking function, the execution flow will be blocked + * until the task is sent or the timeout is achieved. + * + * \param task the task to be sent + * \param alias the mailbox name to where the task is sent + * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send) + * \param maxrate the maximum communication rate for sending this task + * + * \return Returns #MSG_OK if the task was successfully sent, + * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise. + */ +msg_error_t +MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias, + double timeout, double maxrate) +{ + task->simdata->rate = maxrate; + return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), + task, timeout); +} + /** \ingroup msg_task_usage * \brief Check if there is a communication going on in a mailbox. * -- 2.20.1