X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/dd89516cade805920cd23e69dd7eadabe83cad85..3595431d9a94c0b3833f488667f286529449b5ef:/src/msg/m_process.c diff --git a/src/msg/m_process.c b/src/msg/m_process.c index d3e1dbd1f8..2131afab83 100644 --- a/src/msg/m_process.c +++ b/src/msg/m_process.c @@ -11,7 +11,49 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(m_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. + * + * We need to simulate many independent scheduling decisions, so + * the concept of process is at the heart of the + * simulator. A process may be defined as a code, with + * some private data, executing in a location. + * \see m_process_t + */ + /******************************** Process ************************************/ +/** \ingroup m_process_management + * \brief Creates and runs a new #m_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 + */ +m_process_t MSG_process_create(const char *name, + m_process_code_t code, void *data, + m_host_t host) +{ + return MSG_process_create_with_arguments(name, code, data, host, -1, NULL); +} + +static void MSG_process_cleanup(void *arg) +{ + + while(((m_process_t)arg)->simdata->paje_state) { + PAJE_PROCESS_POP_STATE((m_process_t)arg); + } + + PAJE_PROCESS_FREE(arg); + + xbt_fifo_remove(msg_global->process_list, arg); + xbt_fifo_remove(msg_global->process_to_run, arg); + xbt_fifo_remove(((m_process_t) arg)->simdata->host->simdata->process_list, arg); + free(((m_process_t) arg)->name); + free(((m_process_t) arg)->simdata); + free(arg); +} + /** \ingroup m_process_management * \brief Creates and runs a new #m_process_t. @@ -31,29 +73,30 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(m_process, msg, 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 * \return The new corresponding object. */ -m_process_t MSG_process_create(const char *name, - m_process_code_t code, void *data, - m_host_t host) +m_process_t MSG_process_create_with_arguments(const char *name, + m_process_code_t code, void *data, + m_host_t host, int argc, char **argv) { simdata_process_t simdata = xbt_new0(s_simdata_process_t,1); m_process_t process = xbt_new0(s_m_process_t,1); m_process_t self = NULL; - static int PID = 1; xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters"); /* Simulator Data */ - simdata->PID = PID++; + simdata->PID = msg_global->PID++; simdata->host = host; simdata->waiting_task = NULL; - simdata->put_host = NULL; - simdata->put_channel = -1; - simdata->argc = -1; - simdata->argv = NULL; - simdata->context = xbt_context_new(code, simdata->argc, simdata->argv); + simdata->argc = argc; + simdata->argv = argv; + simdata->context = xbt_context_new(code, NULL, NULL, + MSG_process_cleanup, process, + simdata->argc, simdata->argv); if((self=msg_global->current_process)) { simdata->PPID = MSG_process_get_PID(self); @@ -74,9 +117,65 @@ m_process_t MSG_process_create(const char *name, self = msg_global->current_process; xbt_context_start(process->simdata->context); msg_global->current_process = self; + + xbt_fifo_push(msg_global->process_list, process); + xbt_fifo_push(msg_global->process_to_run, process); + + PAJE_PROCESS_NEW(process); + return process; } +/** \ingroup m_process_management + * \param process poor victim + * + * This function simply kills a \a process... scarry isn't it ? :) + */ +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; + +/* fprintf(stderr,"Killing %s(%d) on %s.\n",process->name, */ +/* p_simdata->PID,p_simdata->host->name); */ + + for (i=0; imax_channel; i++) { + if (h_simdata->sleeping[i] == process) { + h_simdata->sleeping[i] = NULL; + break; + } + } + if (i==msg_global->max_channel) { + 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); + else + CRITICAL0("UNKNOWN STATUS. Please report this bug."); + } else { /* Must be trying to put a task somewhere */ + if(process==MSG_process_self()) { + return; + } else { + CRITICAL0("UNKNOWN STATUS. Please report this bug."); + } + } + } + + xbt_fifo_remove(msg_global->process_to_run,process); + xbt_fifo_remove(msg_global->process_list,process); + xbt_context_free(process->simdata->context); +} + /** \ingroup m_process_management * \brief Migrates an agent to another location. * @@ -175,7 +274,6 @@ int MSG_process_get_PID(m_process_t process) return (((simdata_process_t) process->simdata)->PID); } - /** \ingroup m_process_management * \brief Returns the process ID of the parent of \a process. * @@ -231,7 +329,7 @@ int MSG_process_self_PPID(void) */ m_process_t MSG_process_self(void) { - return msg_global->current_process; + return msg_global ? msg_global->current_process : NULL; } /** \ingroup m_process_management @@ -248,6 +346,8 @@ MSG_error_t MSG_process_suspend(m_process_t process) xbt_assert0(((process) && (process->simdata)), "Invalid parameters"); + PAJE_PROCESS_PUSH_STATE(process,"S"); + if(process!=MSG_process_self()) { simdata = process->simdata; @@ -255,21 +355,27 @@ MSG_error_t MSG_process_suspend(m_process_t process) simdata_task = simdata->waiting_task->simdata; + simdata->suspended = 1; + if(simdata->blocked) return MSG_OK; + xbt_assert0(((simdata_task->compute)||(simdata_task->comm))&& - !((simdata_task->comm)&&(simdata_task->comm)), + !((simdata_task->compute)&&(simdata_task->comm)), "Got a problem in deciding which action to choose !"); + simdata->suspended = 1; if(simdata_task->compute) - surf_workstation_resource->extension_public->suspend(simdata_task->compute); - else - surf_workstation_resource->extension_public->suspend(simdata_task->comm); - + surf_workstation_resource->common_public->suspend(simdata_task->compute); + else + surf_workstation_resource->common_public->suspend(simdata_task->comm); } else { m_task_t dummy = MSG_TASK_UNINITIALIZED; - dummy = MSG_task_create("suspended", 0.01, 0, NULL); + dummy = MSG_task_create("suspended", 0.0, 0, NULL); + simdata = process->simdata; + simdata->suspended = 1; __MSG_task_execute(process,dummy); - surf_workstation_resource->extension_public->suspend(dummy->simdata->compute); + surf_workstation_resource->common_public->suspend(dummy->simdata->compute); __MSG_wait_for_computation(process,dummy); + simdata->suspended = 0; MSG_task_destroy(dummy); } @@ -292,16 +398,30 @@ MSG_error_t MSG_process_resume(m_process_t process) CHECK_HOST(); simdata = process->simdata; + + + if(simdata->blocked) { + PAJE_PROCESS_POP_STATE(process); + + simdata->suspended = 0; /* He'll wake up by itself */ + MSG_RETURN(MSG_OK); + } + if(!(simdata->waiting_task)) { xbt_assert0(0,"Process not waiting for anything else. Weird !"); return MSG_WARNING; } simdata_task = simdata->waiting_task->simdata; - if(simdata_task->compute) - surf_workstation_resource->extension_public->resume(simdata_task->compute); - else - surf_workstation_resource->extension_public->resume(simdata_task->comm); + + if(simdata_task->compute) { + surf_workstation_resource->common_public->resume(simdata_task->compute); + PAJE_PROCESS_POP_STATE(process); + } + else { + PAJE_PROCESS_POP_STATE(process); + surf_workstation_resource->common_public->resume(simdata_task->comm); + } MSG_RETURN(MSG_OK); } @@ -313,23 +433,63 @@ MSG_error_t MSG_process_resume(m_process_t process) * task on which it was waiting for the completion. */ int MSG_process_isSuspended(m_process_t process) +{ + xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + + return (process->simdata->suspended); +} + +MSG_error_t __MSG_process_block(void) +{ + m_process_t process = MSG_process_self(); + + m_task_t dummy = MSG_TASK_UNINITIALIZED; + dummy = MSG_task_create("blocked", 0.0, 0, NULL); + + PAJE_PROCESS_PUSH_STATE(process,"B"); + + process->simdata->blocked=1; + __MSG_task_execute(process,dummy); + surf_workstation_resource->common_public->suspend(dummy->simdata->compute); + __MSG_wait_for_computation(process,dummy); + process->simdata->blocked=0; + + if(process->simdata->suspended) + MSG_process_suspend(process); + + MSG_task_destroy(dummy); + + return MSG_OK; +} + +MSG_error_t __MSG_process_unblock(m_process_t process) { simdata_process_t simdata = NULL; simdata_task_t simdata_task = NULL; int i; - + xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + CHECK_HOST(); simdata = process->simdata; if(!(simdata->waiting_task)) { xbt_assert0(0,"Process not waiting for anything else. Weird !"); - return 0; + return MSG_WARNING; } - simdata_task = simdata->waiting_task->simdata; - if(simdata_task->compute) - return surf_workstation_resource->extension_public->is_suspended(simdata_task->compute); - else - return surf_workstation_resource->extension_public->is_suspended(simdata_task->comm); + xbt_assert0(simdata->blocked,"Process not blocked"); + + surf_workstation_resource->common_public->resume(simdata_task->compute); + + PAJE_PROCESS_POP_STATE(process); + + MSG_RETURN(MSG_OK); +} + +int __MSG_process_isBlocked(m_process_t process) +{ + xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + + return (process->simdata->blocked); }