}
t_simdata = t->simdata;
- /* *task = __MSG_task_copy(t); */
+ t_simdata->receiver = process;
*task=t;
SIMIX_mutex_lock(t_simdata->mutex);
t_simdata->using++;
/* create SIMIX action to the communication */
t_simdata->comm = SIMIX_action_communicate(t_simdata->sender->simdata->host->simdata->host,
- process->simdata->host->simdata->host,t->name, t_simdata->message_size, t_simdata->rate);
- /*
+ process->simdata->host->simdata->host,t->name, t_simdata->message_size,
+ t_simdata->rate);
+ /* if the process is suspend, create the action but stop its execution, it will be restart when the sender process resume */
if (MSG_process_is_suspended(t_simdata->sender)) {
- SIMIX_set_priority(t_simdata->comm,0);
- t_simdata->comm = SIMIX_action_communicate(t_simdata->sender->simdata->host->simdata->host,
- process->simdata->host->simdata->host,t->name, t_simdata->message_size, t_simdata->rate);
+ DEBUG1("Process sender (%s) suspended", t_simdata->sender->name);
+ SIMIX_action_set_priority(t_simdata->comm,0);
}
- */
- /* if the process is suspend, create the action but stop its execution, it will be restart when the sender process resume */
+ process->simdata->waiting_task = t;
SIMIX_register_action_to_condition(t_simdata->comm, t_simdata->cond);
SIMIX_register_condition_to_action(t_simdata->comm, t_simdata->cond);
SIMIX_cond_wait(t_simdata->cond,t_simdata->mutex);
-
- /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
- t->simdata->comm = NULL;
- t->simdata->compute = NULL;
+ process->simdata->waiting_task = NULL;
+
+ /* the task has already finished and the pointer must be null*/
+ if (t->simdata->sender) {
+ t->simdata->sender->simdata->waiting_task = NULL;
+ /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+ t->simdata->comm = NULL;
+ t->simdata->compute = NULL;
+ }
+ /* for this process, don't need to change in get function*/
+ t->simdata->receiver = NULL;
SIMIX_mutex_unlock(t_simdata->mutex);
-
- //MSG_task_destroy(t);
-
MSG_RETURN(MSG_OK);
}
*/
int MSG_task_probe_from_host(int channel, m_host_t host)
{
- xbt_die("not implemented yet");
- return 0;
+ xbt_fifo_item_t item;
+ m_task_t t;
+ int count = 0;
+ m_host_t h = NULL;
+
+ xbt_assert1((channel>=0) && (channel < msg_global->max_channel),"Invalid channel %d",channel);
+ CHECK_HOST();
+ h = MSG_host_self();
+
+ DEBUG2("Probing on channel %d (%s)", channel,h->name);
+
+ xbt_fifo_foreach(h->simdata->mbox[channel],item,t,m_task_t) {
+ if(t->simdata->source==host) count++;
+ }
+
+ return count;
}
/** \ingroup msg_gos_functions \brief Put a task on a channel of an
process->simdata->put_channel = channel;
SIMIX_mutex_lock(task->simdata->mutex);
// DEBUG4("Task sent (%g kB) from %s to %s on channel %d, waiting...", task->simdata->message_size/1000,local_host->name, remote_host->name, channel);
- DEBUG0("Waiting action finish!");
+
+ process->simdata->waiting_task = task;
if (max_duration >0) {
SIMIX_cond_wait_timeout(task->simdata->cond,task->simdata->mutex,max_duration);
}
}
DEBUG1("Action terminated %s",task->name);
task->simdata->using--;
+ process->simdata->waiting_task = NULL;
+ /* the task has already finished and the pointer must be null*/
+ if (task->simdata->receiver) {
+ task->simdata->receiver->simdata->waiting_task = NULL;
+ /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+ task->simdata->comm = NULL;
+ task->simdata->compute = NULL;
+ }
+ /* for this process, don't need to change in get function*/
+ task->simdata->sender = NULL;
SIMIX_mutex_unlock(task->simdata->mutex);
MSG_RETURN(MSG_OK);
}
+
/** \ingroup msg_gos_functions
* \brief Put a task on a channel of an host and waits for the end of the
* transmission.
MSG_error_t MSG_task_execute(m_task_t task)
{
simdata_task_t simdata = NULL;
-
+ m_process_t self = MSG_process_self();
CHECK_HOST();
simdata = task->simdata;
simdata->compute = SIMIX_action_execute(SIMIX_host_self(), task->name, simdata->computation_amount);
SIMIX_action_set_priority(simdata->compute, simdata->priority);
+ self->simdata->waiting_task = task;
SIMIX_register_action_to_condition(simdata->compute, simdata->cond);
SIMIX_register_condition_to_action(simdata->compute, simdata->cond);
-
SIMIX_cond_wait(simdata->cond, simdata->mutex);
+ self->simdata->waiting_task = NULL;
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
simdata->comm = NULL;
smx_cond_t cond;
smx_mutex_t mutex; /* Task mutex */
m_process_t sender;
+ m_process_t receiver;
m_host_t source;
double priority;
double rate;
int PPID; /* The parent PID */
m_host_t put_host; /* used for debugging purposes */
m_channel_t put_channel; /* used for debugging purposes */
+ m_task_t waiting_task;
int argc; /* arguments number if any */
char **argv; /* arguments table if any */
MSG_error_t last_errno; /* the last value returned by a MSG_function */
#include "xbt/sysdep.h"
#include "xbt/log.h"
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_process, msg, "Logging specific to MSG (process)");
+
/** \defgroup m_process_management Management Functions of Agents
* \brief This section describes the agent structure of MSG
* (#m_process_t) and the functions for managing it.
/* Simulator Data */
simdata->PID = msg_global->PID++;
+ simdata->waiting_task = NULL;
simdata->host = host;
simdata->argc = argc;
simdata->argv = argv;
*/
void MSG_process_kill(m_process_t process)
{
-
- /*
- int i;
simdata_process_t p_simdata = process->simdata;
- simdata_host_t h_simdata= p_simdata->host->simdata;
- int _cursor;
- m_process_t proc = NULL;
DEBUG3("Killing %s(%d) on %s",process->name, p_simdata->PID, p_simdata->host->name);
- for (i=0; i<msg_global->max_channel; i++) {
- if (h_simdata->sleeping[i] == process) {
- h_simdata->sleeping[i] = NULL;
- break;
- }
- }
-
- if(p_simdata->waiting_task) {
- xbt_dynar_foreach(p_simdata->waiting_task->simdata->sleeping,_cursor,proc) {
- if(proc==process)
- xbt_dynar_remove_at(p_simdata->waiting_task->simdata->sleeping,_cursor,&proc);
- }
- if(p_simdata->waiting_task->simdata->compute)
- surf_workstation_resource->common_public->
- action_free(p_simdata->waiting_task->simdata->compute);
+ if(p_simdata->waiting_task) {
+ DEBUG1("Canceling waiting task %s",p_simdata->waiting_task->name);
+ if(p_simdata->waiting_task->simdata->compute) {
+ SIMIX_action_cancel(p_simdata->waiting_task->simdata->compute);
+ }
else if (p_simdata->waiting_task->simdata->comm) {
- surf_workstation_resource->common_public->
- action_change_state(p_simdata->waiting_task->simdata->comm,SURF_ACTION_FAILED);
- surf_workstation_resource->common_public->
- action_free(p_simdata->waiting_task->simdata->comm);
- } else {
- xbt_die("UNKNOWN STATUS. Please report this bug.");
- }
- }
-
- if ((i==msg_global->max_channel) && (process!=MSG_process_self()) &&
- (!p_simdata->waiting_task)) {
- xbt_die("UNKNOWN STATUS. Please report this bug.");
+ SIMIX_action_cancel(p_simdata->waiting_task->simdata->comm);
+ }
}
-*/
+
xbt_fifo_remove(msg_global->process_list,process);
SIMIX_process_kill(process->simdata->smx_process);
smx_process_t proc = SIMIX_process_self();
if (proc != NULL) {
return (m_process_t)proc->data;
- }
+ }
else {
return NULL;
}
"Logging specific to SIMIX (action)");
/************************************* Actions *********************************/
-
+/** \brief Creates a new SIMIX action to communicate two hosts.
+ *
+ * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a network_error exception if the host is unavailable.
+ * \param sender SIMIX host sender
+ * \param receiver SIMIX host receiver
+ * \param name Action name
+ * \param size Communication size (in bytes)
+ * \param rate Communication rate between hosts.
+ * \return A new SIMIX action
+ * */
smx_action_t SIMIX_action_communicate(smx_host_t sender,smx_host_t receiver,char * name, double size, double rate)
{
/* check if the host is active */
/* initialize them */
act->name = xbt_strdup(name);
+ simdata->source = sender;
simdata->surf_action = surf_workstation_resource->extension_public->
return act;
}
+/** \brief Creates a new SIMIX action to execute an action.
+ *
+ * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a host_error exception if the host crashed.
+ * \param host SIMIX host where the action will be executed
+ * \param name Action name
+ * \param amount Task amount (in bytes)
+ * \return A new SIMIX action
+ * */
smx_action_t SIMIX_action_execute(smx_host_t host, char * name, double amount)
{
/* check if the host is active */
return act;
}
-
+/** \brief Creates a new sleep SIMIX action.
+ *
+ * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a host_error exception if the host crashed. The default SIMIX name of the action is "sleep".
+ * \param host SIMIX host where the sleep will run.
+ * \param duration Time duration of the sleep.
+ * \return A new SIMIX action
+ * */
smx_action_t SIMIX_action_sleep(smx_host_t host, double duration)
-{
+{
char name[] = "sleep";
/* check if the host is active */
return act;
}
-
+/**
+ * \brief Cancels an action.
+ *
+ * This functions stops the execution of an action. It calls a surf functions.
+ * \param action The SIMIX action
+ */
void SIMIX_action_cancel(smx_action_t action)
{
xbt_assert0((action != NULL), "Invalid parameter");
return;
}
+/**
+ * \brief Changes the action's priority
+ *
+ * This functions changes the priority only. It calls a surf functions.
+ * \param action The SIMIX action
+ * \param priority The new priority
+ */
void SIMIX_action_set_priority(smx_action_t action, double priority)
{
xbt_assert0( (action != NULL) && (action->simdata != NULL), "Invalid parameter" );
return;
}
+/**
+ * \brief Destroys an action
+ *
+ * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
+ * \param action The SIMIX action
+ */
void SIMIX_action_destroy(smx_action_t action)
{
return;
}
+/**
+ * \brief Set an action to a condition
+ *
+ * Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending.
+ * \param action SIMIX action
+ * \param cond SIMIX cond
+ */
void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond)
{
xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");
xbt_fifo_push(cond->actions,action);
}
+/**
+ * \brief Return how much remais to be done in the action.
+ *
+ * \param action The SIMIX action
+ * \return Remains cost
+ */
double SIMIX_action_get_remains(smx_action_t action)
{
xbt_assert0((action != NULL), "Invalid parameter");
_simix_init_status = 0;
}
-/** \brief set a configuration variable
+/** \brief Set a configuration variable
*
- * Currently existing configuation variable:
+ * Currently existing configuration variable:
* - surf_workstation_model (string): Model of workstation to use.
* Possible values (defaults to "KCCFLN05"):
* - "CLM03": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + support for parallel tasks
* - "KCCFLN05": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file.
*
- * Example:
- * MSG_config("surf_workstation_model","KCCFLN05");
+ * \param name Configuration variable name that will change.
+ * \param pa A va_list with the others parameters
*/
void SIMIX_config(const char *name, va_list pa)
{
}
}
-/** \ingroup msg_easier_life
+/**
* \brief An application deployer.
*
* Creates the process described in \a file.
*
* \include small_deployment.xml
*
- * Have a look in the directory examples/msg/ to have a bigger example.
*/
void SIMIX_launch_application(const char *file)
{
surf_parse_close();
}
-/** \ingroup msg_easier_life
- * \brief Registers a #m_process_code_t code in a global table.
+/**
+ * \brief Registers a #smx_process_code_t code in a global table.
*
* Registers a code function in a global table.
- * This table is then used by #MSG_launch_application.
+ * This table is then used by #SIMIX_launch_application.
* \param name the reference name of the function.
* \param code the function
*/
xbt_dict_set(simix_global->registered_functions,name,code,NULL);
}
-/** \ingroup msg_easier_life
- * \brief Registers a #m_process_t code in a global table.
+/**
+ * \brief Gets a #smx_process_t code from the global table.
*
- * Registers a code function in a global table.
- * This table is then used by #MSG_launch_application.
+ * Gets a code function from the global table. Returns NULL if there are no function registered with the name.
+ * This table is then used by #SIMIX_launch_application.
* \param name the reference name of the function.
+ * \return The #smx_process_t or NULL.
*/
smx_process_code_t SIMIX_get_registered_function(const char *name)
{
#include "xbt/log.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix,
"Logging specific to SIMIX (environment)");
-/** \defgroup msg_easier_life Platform and Application management
- * \brief This section describes functions to manage the platform creation
- * and the application deployment. You should also have a look at
- * \ref MSG_examples to have an overview of their usage.
- * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Platforms and Applications" --> \endhtmlonly
- *
- */
/********************************* SIMIX **************************************/
-
-
-/** \ingroup msg_easier_life
+/**
* \brief A platform constructor.
*
* Creates a new platform, including hosts, links and the
*
* \include small_platform.xml
*
- * Have a look in the directory examples/msg/ to have a big example.
*/
void SIMIX_create_environment(const char *file)
{
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix,
"Logging specific to SIMIX (kernel)");
-
SIMIX_Global_t simix_global = NULL;
-
-/** \defgroup simix_simulation SIMIX simulation Functions
- * \brief This section describes the functions you need to know to
- * set up a simulation. You should have a look at \ref SIMIX_examples
- * to have an overview of their usage.
- * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Simulation functions" --> \endhtmlonly
- */
-
/********************************* SIMIX **************************************/
-/** \ingroup simix_simulation
+/**
* \brief Initialize some SIMIX internal data.
+ *
+ * \param argc Argc
+ * \param argv Argv
*/
void SIMIX_global_init_args(int *argc, char **argv)
{
SIMIX_global_init(argc,argv);
}
-/** \ingroup simix_simulation
+/**
* \brief Initialize some SIMIX internal data.
+ *
+ * \param argc Argc
+ * \param argv Argv
*/
void SIMIX_global_init(int *argc, char **argv)
{
exit(1);
}
-/** \ingroup msg_simulation
- * \brief Launch the SIMIX simulation
+/**
+ * \brief Launch the SIMIX simulation, debug purpose
*/
void __SIMIX_main(void)
{
return;
}
-/** \ingroup msg_simulation
+/**
* \brief Kill all running process
-
- * \param reset_PIDs should we reset the PID numbers. A negative
- * number means no reset and a positive number will be used to set the PID
- * of the next newly created process.
+ *
*/
void SIMIX_process_killall()
{
return;
}
-/** \ingroup msg_simulation
+/**
* \brief Clean the SIMIX simulation
+ *
+ * This functions remove all memories needed to the SIMIX execution
*/
void SIMIX_clean(void)
{
}
-/** \ingroup msg_easier_life
+/**
* \brief A clock (in second).
+ *
+ * \return Return the clock.
*/
double SIMIX_get_clock(void)
{
return surf_get_clock();
}
+/**
+ * \brief Does a turn of the simulation
+ *
+ * Executes a step in the surf simulation, adding to the two lists all the actions that finished on this turn. Schedules all processus in the process_to_run list.
+ * \param actions_done List of actions done
+ * \param actions_failed List of actions failed
+ * \return The time spent to execute the simulation or -1 if the simulation ended
+ */
double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
{
return elapsed_time;
}
-
+/**
+ * \brief Set the date to execute a function
+ *
+ * Set the date to execute the function on the surf.
+ * \param date Date to execute function
+ * \param function Function to be executed
+ * \param arg Parameters of the function
+ *
+ */
void SIMIX_timer_set (double date, void *function, void *arg)
{
surf_timer_resource->extension_public->set(date, function, arg);
return surf_timer_resource->extension_public->get(function, arg);
}
-
+/**
+ * \brief Registers a function to create a process.
+ *
+ * This function registers an user function to be called when a new process is created. The user function have to call the SIMIX_create_process function.
+ * \param function Create process function
+ *
+ */
void SIMIX_function_register_process_create(void * function)
{
xbt_assert0((simix_global->create_process_function == NULL), "Data already set");
return ;
}
+
+/**
+ * \brief Registers a function to kill a process.
+ *
+ * This function registers an user function to be called when a new process is killed. The user function have to call the SIMIX_kill_process function.
+ * \param function Kill process function
+ *
+ */
void SIMIX_function_register_process_kill(void * function)
{
xbt_assert0((simix_global->kill_process_function == NULL), "Data already set");
#include "xbt/sysdep.h"
#include "xbt/log.h"
-/** \defgroup m_host_management Management functions of Hosts
- * \brief This section describes the host structure of MSG
- *
- * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
- * (#m_host_t) and the functions for managing it.
- *
- * A <em>location</em> (or <em>host</em>) is any possible place where
- * a process may run. Thus it may be represented as a
- * <em>physical resource with computing capabilities</em>, some
- * <em>mailboxes</em> to enable running process to communicate with
- * remote ones, and some <em>private data</em> that can be only
- * accessed by local process.
- * \see m_host_t
- */
/********************************* Host **************************************/
smx_host_t __SIMIX_host_create(const char *name,
return host;
}
-/** \ingroup m_host_management
+/**
+ * \brief Set the user data of a #smx_host_t.
*
- * \brief Set the user data of a #m_host_t.
+ * This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
+ * \param host SIMIX host
+ * \param data User data
*
- * This functions checks whether some data has already been associated to \a host
- or not and attach \a data to \a host if it is possible.
*/
void SIMIX_host_set_data(smx_host_t host, void *data)
{
return ;
}
-/** \ingroup m_host_management
- *
- * \brief Return the user data of a #m_host_t.
+/**
+ * \brief Return the user data of a #smx_host_t.
*
- * This functions checks whether \a host is a valid pointer or not and return
- the user data associated to \a host if it is possible.
+ * This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
+ * \param host SIMIX host
*/
void *SIMIX_host_get_data(smx_host_t host)
{
-
xbt_assert0((host != NULL), "Invalid parameters");
/* Return data */
return (host->data);
}
-/** \ingroup m_host_management
+/**
+ * \brief Return the name of the #smx_host_t.
*
- * \brief Return the name of the #m_host_t.
- *
- * This functions checks whether \a host is a valid pointer or not and return
- its name.
+ * This functions checks whether \a host is a valid pointer or not and return its name.
+ * \param host SIMIX host
*/
const char *SIMIX_host_get_name(smx_host_t host)
{
return (host->name);
}
-/** \ingroup m_host_management
- *
+/**
* \brief Return the location on which the current process is executed.
+ *
+ * Return the host, more details in #SIMIX_process_get_host
+ * \return SIMIX host
*/
smx_host_t SIMIX_host_self(void)
{
return;
}
-/** \ingroup m_host_management
- * \brief Return the current number of #m_host_t.
+/**
+ * \brief Return the current number of #smx_host_t.
+ *
+ * \return Number of hosts
*/
int SIMIX_host_get_number(void)
{
return (xbt_fifo_size(simix_global->host));
}
-/** \ingroup m_host_management
- * \brief Return a array of all the #m_host_t.
+/**
+ * \brief Return a array of all the #smx_host_t.
+ *
+ * \return List of all hosts
*/
smx_host_t *SIMIX_host_get_table(void)
{
}
-/** \ingroup m_host_management
- * \brief Return the speed of the processor (in Mflop/s), regardless of
- the current load on the machine.
+/**
+ * \brief Return the speed of the processor.
+ *
+ * Return the speed (in Mflop/s), regardless of the current load on the machine.
+ * \param host SIMIX host
+ * \return Speed
*/
double SIMIX_host_get_speed(smx_host_t host)
{
extension_public->get_speed(host->simdata->host,1.0));
}
+/**
+ * \brief Return the available speed of the processor.
+ *
+ * Return the available speed (in Mflop/s).
+ * \return Speed
+ */
double SIMIX_host_get_available_speed(smx_host_t host)
{
xbt_assert0((host!= NULL), "Invalid parameters");
extension_public->get_available_speed(host->simdata->host));
}
-/** \ingroup msg_gos_functions
- * \brief Determine if a host is available.
- *
- * \param h host to test
- */
-
-/** \ingroup msg_easier_life
- * \brief A name directory service...
+/**
+ * \brief Return the host by its name
*
- * Finds a m_host_t using its name.
- * \param name the name of an host.
- * \return the corresponding host
+ * Finds a smx_host_t using its name.
+ * \param name The name of an host.
+ * \return The corresponding host
*/
-
smx_host_t SIMIX_host_get_by_name(const char *name)
{
xbt_fifo_item_t i = NULL;
return NULL;
}
+/**
+ * \brief Return the state of a workstation
+ *
+ * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
+ * \param host The SIMIX host
+ * \return 1 if host is available or 0 if not.
+ */
int SIMIX_host_get_state(smx_host_t host)
{
xbt_assert0((host!= NULL), "Invalid parameters");
#include "private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
"Logging specific to SIMIX (process)");
-/** \defgroup m_process_management Management Functions of Agents
- * \brief This section describes the agent structure of MSG
- * (#m_process_t) and the functions for managing it.
- * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Agents" --> \endhtmlonly
- *
- * We need to simulate many independent scheduling decisions, so
- * the concept of <em>process</em> is at the heart of the
- * simulator. A process may be defined as a <em>code</em>, with
- * some <em>private data</em>, executing in a <em>location</em>.
- * \see m_process_t
- */
/******************************** Process ************************************/
-/** \ingroup m_process_management
- * \brief Creates and runs a new #m_process_t.
+/**
+ * \brief Creates and runs a new #smx_process_t.
*
- * Does exactly the same as #MSG_process_create_with_arguments but without
- providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time).
- * \sa MSG_process_create_with_arguments
+ * Does exactly the same as #SIMIX_process_create_with_arguments but without
+ providing standard arguments (\a argc, \a argv).
+ * \see SIMIX_process_create_with_arguments
*/
smx_process_t SIMIX_process_create(const char *name,
smx_process_code_t code, void *data,
free(arg);
}
-/** \ingroup m_process_management
- * \brief Creates and runs a new #m_process_t.
-
- * A constructor for #m_process_t taking four arguments and returning the
- * corresponding object. The structure (and the corresponding thread) is
- * created, and put in the list of ready process.
- * \param name a name for the object. It is for user-level information
- and can be NULL.
- * \param code is a function describing the behavior of the agent. It
- should then only use functions described in \ref
- m_process_management (to create a new #m_process_t for example),
- in \ref m_host_management (only the read-only functions i.e. whose
- name contains the word get), in \ref m_task_management (to create
- or destroy some #m_task_t for example) and in \ref
- msg_gos_functions (to handle file transfers and task processing).
- * \param data a pointer to any data one may want to attach to the new
- object. It is for user-level information and can be NULL. It can
- be retrieved with the function \ref MSG_process_get_data.
+/**
+ * \brief Creates and runs a new #smx_process_t.
+ *
+ * A constructor for #m_process_t taking four arguments and returning the corresponding object. The structure (and the corresponding thread) is created, and put in the list of ready process.
+ *
+ * \param name a name for the object. It is for user-level information and can be NULL.
+* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL. It can be retrieved with the function \ref MSG_process_get_data.
* \param host the location where the new agent is executed.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code
- * \see m_process_t
+ * \param clean_process_function The cleanup function of user process. It will be called when the process finish. This function have to call the SIMIX_process_cleanup.
+ * \see smx_process_t
* \return The new corresponding object.
*/
smx_process_t SIMIX_process_create_with_arguments(const char *name,
/* Simulator Data */
simdata->host = host;
+ simdata->mutex = NULL;
+ simdata->cond = NULL;
simdata->argc = argc;
simdata->argv = argv;
if (clean_process_function) {
SIMIX_process_cleanup, process,
simdata->argc, simdata->argv);
}
- //simdata->last_errno=SIMIX_OK;
-
/* Process structure */
process->name = xbt_strdup(name);
}
-
-
-/** \ingroup m_process_management
+/** \brief Kill a SIMIX process
+ *
+ * This function simply kills a \a process... scarry isn't it ? :). Removes it from the mutex or condition that it can be blocked.
* \param process poor victim
*
- * This function simply kills a \a process... scarry isn't it ? :)
*/
void SIMIX_process_kill(smx_process_t process)
-{
- //int i;
+{
smx_simdata_process_t p_simdata = process->simdata;
- //simdata_host_t h_simdata= p_simdata->host->simdata;
- //int _cursor;
- //smx_process_t proc = NULL;
DEBUG2("Killing %s on %s",process->name, p_simdata->host->name);
if (p_simdata->cond) {
xbt_swag_remove(process,p_simdata->cond->sleeping);
}
- /*
-
- if(p_simdata->waiting_task) {
- xbt_dynar_foreach(p_simdata->waiting_task->simdata->sleeping,_cursor,proc) {
- if(proc==process)
- xbt_dynar_remove_at(p_simdata->waiting_task->simdata->sleeping,_cursor,&proc);
- }
- if(p_simdata->waiting_task->simdata->compute)
- surf_workstation_resource->common_public->
- action_free(p_simdata->waiting_task->simdata->compute);
- else if (p_simdata->waiting_task->simdata->comm) {
- surf_workstation_resource->common_public->
- action_change_state(p_simdata->waiting_task->simdata->comm,SURF_ACTION_FAILED);
- surf_workstation_resource->common_public->
- action_free(p_simdata->waiting_task->simdata->comm);
- } else {
- xbt_die("UNKNOWN STATUS. Please report this bug.");
- }
- }
-
- if ((i==msg_global->max_channel) && (process!=MSG_process_self()) &&
- (!p_simdata->waiting_task)) {
- xbt_die("UNKNOWN STATUS. Please report this bug.");
- }
-*/
xbt_swag_remove(process,simix_global->process_to_run);
xbt_swag_remove(process,simix_global->process_list);
xbt_context_kill(process->simdata->context);
}
}
-/** \ingroup m_process_management
- * \brief Return the user data of a #m_process_t.
+/**
+ * \brief Return the user data of a #smx_process_t.
*
- * This functions checks whether \a process is a valid pointer or not
- and return the user data associated to \a process if it is possible.
+ * This functions checks whether \a process is a valid pointer or not and return the user data associated to \a process if it is possible.
+ * \param process SIMIX process
+ * \return A void pointer to the user data
*/
void *SIMIX_process_get_data(smx_process_t process)
{
return (process->data);
}
-/** \ingroup m_process_management
+/**
* \brief Set the user data of a #m_process_t.
*
- * This functions checks whether \a process is a valid pointer or not
- and set the user data associated to \a process if it is possible.
+ * This functions checks whether \a process is a valid pointer or not and set the user data associated to \a process if it is possible.
+ * \param process SIMIX process
+ * \param data User data
*/
void SIMIX_process_set_data(smx_process_t process,void *data)
{
return ;
}
-/** \ingroup m_process_management
+/**
* \brief Return the location on which an agent is running.
*
- * This functions checks whether \a process is a valid pointer or not
- and return the m_host_t corresponding to the location on which \a
- process is running.
+ * This functions checks whether \a process is a valid pointer or not and return the m_host_t corresponding to the location on which \a process is running.
+ * \param process SIMIX process
+ * \return SIMIX host
*/
smx_host_t SIMIX_process_get_host(smx_process_t process)
{
return (process->simdata->host);
}
-/** \ingroup m_process_management
+/**
* \brief Return the name of an agent.
*
- * This functions checks whether \a process is a valid pointer or not
- and return its name.
+ * This functions checks whether \a process is a valid pointer or not and return its name.
+ * \param process SIMIX process
+ * \return The process name
*/
const char *SIMIX_process_get_name(smx_process_t process)
{
return (process->name);
}
-/** \ingroup m_process_management
+/**
* \brief Return the current agent.
*
- * This functions returns the currently running #m_process_t.
+ * This functions returns the currently running #smx_process_t.
+ * \return The SIMIX process
*/
smx_process_t SIMIX_process_self(void)
{
return simix_global ? simix_global->current_process : NULL;
}
-/** \ingroup m_process_management
+/**
* \brief Suspend the process.
*
- * This functions suspend the process by suspending the task on which
- * it was waiting for the completion.
+ * This functions suspend the process by suspending the action on which it was waiting for the completion.
+ * \param process SIMIX process
*/
void SIMIX_process_suspend(smx_process_t process)
{
return ;
}
-/** \ingroup m_process_management
+/**
* \brief Resume a suspended process.
*
- * This functions resume a suspended process by resuming the task on
- * which it was waiting for the completion.
+ * This functions resume a suspended process by resuming the task on which it was waiting for the completion.
+ * \param process SIMIX process
*/
void SIMIX_process_resume(smx_process_t process)
{
}
-/** \ingroup m_process_management
+/**
* \brief Returns true if the process is suspended .
*
- * This checks whether a process is suspended or not by inspecting the
- * task on which it was waiting for the completion.
+ * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
+ * \param process SIMIX process
+ * \return 1, if the process is suspended, else 0.
*/
int SIMIX_process_is_suspended(smx_process_t process)
{
void SIMIX_mutex_lock(smx_mutex_t mutex)
{
smx_process_t self = SIMIX_process_self();
-
xbt_assert0((mutex != NULL), "Invalid parameters");
+
if (mutex->using) {
/* somebody using the mutex, block */
xbt_swag_insert(self, mutex->sleeping);
self->simdata->mutex = mutex;
/* wait for some process make the unlock and wake up me from mutex->sleeping */
xbt_context_yield();
+ self->simdata->mutex = NULL;
+
/* verify if the process was suspended */
while (self->simdata->suspended) {
xbt_context_yield();
}
- self->simdata->mutex = NULL;
mutex->using = 1;
}
else {
void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
{
- smx_process_t self = SIMIX_process_self();
smx_action_t act_sleep;
xbt_assert0((mutex != NULL), "Invalid parameters");
__SIMIX_cond_wait(cond);
}
/* get the mutex again */
- self->simdata->mutex = cond->mutex;
SIMIX_mutex_lock(cond->mutex);
return;
xbt_assert0((cond != NULL), "Invalid parameters");
/* process status */
- self->simdata->cond = cond;
+ self->simdata->cond = cond;
xbt_swag_insert(self, cond->sleeping);
xbt_context_yield();
self->simdata->cond = NULL;
void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration)
{
- smx_process_t self = SIMIX_process_self();
xbt_assert0((mutex != NULL), "Invalid parameters");
smx_action_t act_sleep;
__SIMIX_cond_wait(cond);
/* get the mutex again */
- self->simdata->mutex = cond->mutex;
SIMIX_mutex_lock(cond->mutex);
return;