X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/274b996ead50456d7519b1cbd5d4f86e0a9154ec..6a6209ae617ba25152ddd80cd3b79d72748d7bd5:/src/msg/msg_gos.c diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 72eb74e981..d5ba36ef22 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg, * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED * or #MSG_HOST_FAILURE otherwise */ -MSG_error_t MSG_task_execute(msg_task_t task) +msg_error_t MSG_task_execute(msg_task_t task) { return MSG_parallel_task_execute(task); } @@ -34,14 +34,14 @@ MSG_error_t MSG_task_execute(msg_task_t task) * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED * or #MSG_HOST_FAILURE otherwise */ -MSG_error_t MSG_parallel_task_execute(msg_task_t task) +msg_error_t MSG_parallel_task_execute(msg_task_t task) { xbt_ex_t e; simdata_task_t simdata = task->simdata; msg_process_t self = SIMIX_process_self(); simdata_process_t p_simdata = SIMIX_process_self_get_data(self); e_smx_state_t comp_state; - MSG_error_t status = MSG_OK; + msg_error_t status = MSG_OK; #ifdef HAVE_TRACING TRACE_msg_task_execute_start(task); @@ -75,7 +75,7 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task) XBT_DEBUG("Parallel execution action created: %p", simdata->compute); } else { simdata->compute = simcall_host_execute(task->name, - p_simdata->m_host->smx_host, + p_simdata->m_host, simdata->computation_amount, simdata->priority); @@ -123,9 +123,9 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task) * * \param nb_sec a number of second */ -MSG_error_t MSG_process_sleep(double nb_sec) +msg_error_t MSG_process_sleep(double nb_sec) { - MSG_error_t status = MSG_OK; + msg_error_t status = MSG_OK; /*msg_process_t proc = MSG_process_self();*/ #ifdef HAVE_TRACING @@ -179,7 +179,7 @@ MSG_error_t MSG_process_sleep(double nb_sec) * #MSG_OK if the task was successfully received, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise. */ -MSG_error_t +msg_error_t MSG_task_receive_from_host(msg_task_t * task, const char *alias, msg_host_t host) { @@ -200,7 +200,7 @@ MSG_task_receive_from_host(msg_task_t * task, const char *alias, * #MSG_OK if the task was successfully received, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise. */ -MSG_error_t MSG_task_receive(msg_task_t * task, const char *alias) +msg_error_t MSG_task_receive(msg_task_t * task, const char *alias) { return MSG_task_receive_with_timeout(task, alias, -1); } @@ -221,7 +221,7 @@ MSG_error_t MSG_task_receive(msg_task_t * task, const char *alias) * #MSG_OK if the task was successfully received, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise. */ -MSG_error_t +msg_error_t MSG_task_receive_with_timeout(msg_task_t * task, const char *alias, double timeout) { @@ -245,7 +245,7 @@ MSG_task_receive_with_timeout(msg_task_t * task, const char *alias, * #MSG_OK if the task was successfully received, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise. */ -MSG_error_t +msg_error_t MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout, msg_host_t host) { @@ -271,6 +271,25 @@ msg_comm_t MSG_task_isend(msg_task_t task, const char *alias) return MSG_task_isend_with_matching(task,alias,NULL,NULL); } +/** \ingroup msg_task_usage + * \brief Sends a task on a mailbox with a maximum rate + * + * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() + * to end the communication. The maxrate parameter allows the application + * to limit the bandwidth utilization of network links when sending the task. + * + * \param task a #msg_task_t to send on another location. + * \param alias name of the mailbox to sent the task to + * \param maxrate the maximum communication rate for sending this task . + * \return the msg_comm_t communication created + */ +msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias, double maxrate) +{ + task->simdata->rate = maxrate; + return MSG_task_isend_with_matching(task,alias,NULL,NULL); +} + + /** \ingroup msg_task_usage * \brief Sends a task on a mailbox, with support for matching requests * @@ -294,7 +313,9 @@ XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char * msg_process_t process = MSG_process_self(); msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); - /* FIXME: these functions are not traceable */ +#ifdef HAVE_TRACING + int call_end = TRACE_msg_task_put_start(task); +#endif /* Prepare the task to send */ t_simdata = task->simdata; @@ -317,6 +338,16 @@ XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char * simcall_comm_isend(mailbox, t_simdata->message_size, t_simdata->rate, task, sizeof(void *), match_fun, NULL, match_data, 0); t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */ +#ifdef HAVE_TRACING + if (TRACE_is_enabled()) { + simcall_set_category(comm->s_comm, task->category); + } +#endif + +#ifdef HAVE_TRACING + if (call_end) + TRACE_msg_task_put_end(); +#endif return comm; } @@ -344,7 +375,65 @@ void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup) msg_process_t process = MSG_process_self(); msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); - /* FIXME: these functions are not traceable */ + /* 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 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; @@ -358,10 +447,24 @@ void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup) 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 @@ -409,6 +512,7 @@ int MSG_comm_test(msg_comm_t comm) { xbt_ex_t e; int finished = 0; + TRY { finished = simcall_comm_test(comm->s_comm); @@ -458,7 +562,7 @@ int MSG_comm_testany(xbt_dynar_t comms) xbt_dynar_push(s_comms, &comm->s_comm); } - MSG_error_t status = MSG_OK; + msg_error_t status = MSG_OK; TRY { finished_index = simcall_comm_testany(s_comms); } @@ -511,9 +615,9 @@ void MSG_comm_destroy(msg_comm_t comm) * \param comm the communication to wait. * \param timeout Wait until the communication terminates or the timeout * occurs. You can provide a -1 timeout to obtain an infinite timeout. - * \return MSG_error_t + * \return msg_error_t */ -MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) +msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout) { xbt_ex_t e; TRY { @@ -577,7 +681,7 @@ int MSG_comm_waitany(xbt_dynar_t comms) xbt_dynar_push(s_comms, &comm->s_comm); } - MSG_error_t status = MSG_OK; + msg_error_t status = MSG_OK; TRY { finished_index = simcall_comm_waitany(s_comms); } @@ -621,7 +725,7 @@ int MSG_comm_waitany(xbt_dynar_t comms) * \return the status of the communication, or #MSG_OK if no error occured * during the communication */ -MSG_error_t MSG_comm_get_status(msg_comm_t comm) { +msg_error_t MSG_comm_get_status(msg_comm_t comm) { return comm->status; } @@ -640,7 +744,7 @@ msg_task_t MSG_comm_get_task(msg_comm_t comm) } /** - * \brief This function is called by SIMIX to copy the data of a comm. + * \brief This function is called by SIMIX in kernel mode to copy the data of a comm. * \param comm the comm * \param buff the data copied * \param buff_size size of the buffer @@ -671,7 +775,7 @@ void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_si * \return Returns #MSG_OK if the task was successfully sent, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise. */ -MSG_error_t MSG_task_send(msg_task_t task, const char *alias) +msg_error_t MSG_task_send(msg_task_t task, const char *alias) { XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias); return MSG_task_send_with_timeout(task, alias, -1); @@ -691,7 +795,7 @@ MSG_error_t MSG_task_send(msg_task_t task, const char *alias) * \return Returns #MSG_OK if the task was successfully sent, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise. */ -MSG_error_t +msg_error_t MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate) { task->simdata->rate = maxrate; @@ -711,7 +815,7 @@ MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate) * \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_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, double timeout) { @@ -719,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. * @@ -779,7 +906,7 @@ int MSG_task_listen_from(const char *alias) * previously declared with the function #TRACE_category * (or with #TRACE_category_with_color). * - * See \ref tracing_tracing for details on how to trace + * See \ref tracing for details on how to trace * the (categorized) resource utilization. * * \param task the task that is going to be categorized @@ -813,13 +940,49 @@ const char *MSG_task_get_category (msg_task_t task) #endif } +/** + * \brief Returns the value of a given AS or router property + * + * \param asr the name of a router or AS + * \param name a property name + * \return value of a property (or NULL if property not set) + */ +const char *MSG_as_router_get_property_value(const char* asr, const char *name) +{ + return xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name); +} + +/** + * \brief Returns a xbt_dict_t consisting of the list of properties assigned to + * a the AS or router + * + * \param asr the name of a router or AS + * \return a dict containing the properties + */ +xbt_dict_t MSG_as_router_get_properties(const char* asr) +{ + return (simcall_asr_get_properties(asr)); +} + +/** + * \brief Change the value of a given AS or router + * + * \param asr the name of a router or AS + * \param name a property name + * \param value what to change the property to + * \param free_ctn the freeing function to use to kill the value on need + */ +void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) { + xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn); +} + #ifdef MSG_USE_DEPRECATED /** \ingroup msg_deprecated_functions * * \brief Return the last value returned by a MSG function (except * MSG_get_errno...). */ -MSG_error_t MSG_get_errno(void) +msg_error_t MSG_get_errno(void) { return PROCESS_GET_ERRNO(); } @@ -849,7 +1012,7 @@ MSG_error_t MSG_get_errno(void) * #MSG_TRANSFER_FAILURE if the transfer could not be properly done * (network failure, dest failure) or #MSG_OK if it succeeded. */ -MSG_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel) +msg_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel) { XBT_WARN("DEPRECATED! Now use MSG_task_send"); return MSG_task_put_with_timeout(task, dest, channel, -1.0); @@ -861,7 +1024,7 @@ MSG_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel) * * \sa MSG_task_put */ -MSG_error_t +msg_error_t MSG_task_put_bounded(msg_task_t task, msg_host_t dest, m_channel_t channel, double maxrate) { @@ -900,7 +1063,7 @@ this function was called was shut down, #MSG_TRANSFER_FAILURE if the transfer could not be properly done (network failure, dest failure, timeout...) or #MSG_OK if the communication succeeded. */ -MSG_error_t +msg_error_t MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest, m_channel_t channel, double timeout) { @@ -1002,9 +1165,9 @@ int MSG_task_probe_from_host(int channel, msg_host_t host) listening. This value has to be >=0 and < than the maximal number of channels fixed with MSG_set_channel_number(). * \param host the host that is to be watched. - * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. + * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. */ -MSG_error_t +msg_error_t MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host) { XBT_WARN("DEPRECATED! Now use MSG_task_receive_from_host"); @@ -1022,9 +1185,9 @@ MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host) * \param channel the channel on which the process should be listening. This value has to be >=0 and < than the maximal number of channels fixed with MSG_set_channel_number(). - * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. + * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. */ -MSG_error_t MSG_task_get(msg_task_t * task, m_channel_t channel) +msg_error_t MSG_task_get(msg_task_t * task, m_channel_t channel) { XBT_WARN("DEPRECATED! Now use MSG_task_receive"); return MSG_task_get_with_timeout(task, channel, -1); @@ -1045,9 +1208,9 @@ MSG_error_t MSG_task_get(msg_task_t * task, m_channel_t channel) up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task will not be modified and will still be equal to \c NULL when returning. - * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. + * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise. */ -MSG_error_t +msg_error_t MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel, double max_duration) { @@ -1055,7 +1218,7 @@ MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel, return MSG_task_get_ext(task, channel, max_duration, NULL); } -MSG_error_t +msg_error_t MSG_task_get_ext(msg_task_t * task, m_channel_t channel, double timeout, msg_host_t host) {