X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a5549091dbdecc6e56ff56e09ef922ba83b1d02..614783abcb28c771ad302252888494fe36da2bd8:/src/msg/global.c diff --git a/src/msg/global.c b/src/msg/global.c index 885ca40841..7e68c31f65 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -5,12 +5,14 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include"private.h" -#include"xbt/sysdep.h" -#include "xbt/error.h" +#include "private.h" +#include "xbt/sysdep.h" +#include "xbt/log.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(global, msg, "Logging specific to MSG (global)"); +int __stop_at_time = -1.0 ; + MSG_Global_t msg_global = NULL; /* static void MarkAsFailed(m_task_t t, TBX_HashTable_t failedProcessList); */ @@ -27,25 +29,21 @@ MSG_Global_t msg_global = NULL; /** \ingroup msg_simulation * \brief Initialize some MSG internal data. */ -void MSG_global_init(void) +void MSG_global_init_args(int *argc, char **argv) { - int argc=0; - char **argv=NULL; - - CRITICAL0("Please stop using this function. Use MSG_global_init_args instead."); - DIE_IMPOSSIBLE; - MSG_global_init_args(&argc,argv); + MSG_global_init(argc,argv); } /** \ingroup msg_simulation * \brief Initialize some MSG internal data. */ -void MSG_global_init_args(int *argc, char **argv) +void MSG_global_init(int *argc, char **argv) { if (!msg_global) { + surf_init(argc, argv); /* Initialize some common structures. Warning, it sets msg_global=NULL */ + msg_global = xbt_new0(s_MSG_Global_t,1); - surf_init(argc, argv); /* Initialize some common structures */ xbt_context_init(); msg_global->host = xbt_fifo_new(); msg_global->process_to_run = xbt_fifo_new(); @@ -197,9 +195,12 @@ void MSG_paje_output(const char *filename) const char *ext = ".trace"; int ext_len = strlen(ext); int len; + m_host_t host; + m_process_t process; + xbt_fifo_item_t item = NULL; xbt_assert0(msg_global, "Initialize MSG first\n"); - xbt_assert0(!msg_global->paje_output, "Paje output allready defined\n"); + xbt_assert0(!msg_global->paje_output, "Paje output already defined\n"); xbt_assert0(filename, "Need a real file name\n"); len = strlen(filename); @@ -208,27 +209,28 @@ void MSG_paje_output(const char *filename) filename,ext); } - xbt_assert0(filename, "Need a real file name\n"); - msg_global->paje_output=fopen(filename,"w"); xbt_assert1(msg_global->paje_output, "Failed to open %s \n",filename); fprintf(msg_global->paje_output,"%s",paje_preembule); fprintf(msg_global->paje_output,"%s",type_definitions); + + /* Channels */ for(i=0; imax_channel; i++) { fprintf(msg_global->paje_output, "6 COMM_%d Comm \"Channel %d\"\n" ,i,i); } fprintf(msg_global->paje_output, "7 0.0 CUR Sim_t 0 \"MSG simulation\"\n"); -} + /* Hosts */ + xbt_fifo_foreach(msg_global->host,item,host,m_host_t) { + PAJE_HOST_NEW(host); + } -/** \ingroup msg_simulation - * \brief Defines the verbosity of the simulation. - */ -void MSG_set_verbosity(MSG_outputmode_t mode) -{ - CRITICAL0("MSG_set_verbosity : Not implemented yet."); + /* Process */ + xbt_fifo_foreach(msg_global->process_list,item,process,m_process_t) { + PAJE_PROCESS_NEW(process); + } } /** \defgroup m_channel_management Understanding channels @@ -261,26 +263,6 @@ MSG_error_t MSG_set_channel_number(int number) return MSG_OK; } -/** \ingroup m_simulation - * \brief Set the sharing policy used for the links - * - * This function can be called to change the sharing policy used for the links - (see \ref paper_tcp). By default the store and forward mechanism is used - with a parameter equal to 0.1. This function has to be called before creating - any link. - * \param mode the sharing policy used for the links: can be either - MSG_STORE_AND_FORWARD or MSG_TCP. - * \param param a parameter for the sharing policy. It has to be >0. It is - currently used only for the MSG_STORE_AND_FORWARD flavor and represents the - granularity of the communications (i.e. the packet size). - */ -MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, double param) -{ - CRITICAL0("MSG_set_sharing_policy: this function is now deprecated and useless. Store and forward does not exist anymore. Please stop using it."); - - return MSG_OK; -} - /** \ingroup m_channel_management * \brief Return the number of channel in the simulation. * @@ -303,7 +285,7 @@ MSG_error_t MSG_main(void) m_process_t process = NULL; int nbprocess,i; double elapsed_time = 0.0; - + int state_modifications = 1; /* Clean IO before the run */ fflush(stdout); fflush(stderr); @@ -312,42 +294,79 @@ MSG_error_t MSG_main(void) /* xbt_fifo_size(msg_global->process_to_run) */ while (1) { xbt_context_empty_trash(); + if(xbt_fifo_size(msg_global->process_to_run) && (elapsed_time>0)) { + DEBUG0("**************************************************"); + } + if((__stop_at_time>0) && (MSG_get_clock() >= __stop_at_time)) { + DEBUG0("Let's stop here!"); + } + while ((process = xbt_fifo_pop(msg_global->process_to_run))) { -/* fprintf(stderr,"-> %s (%d)\n",process->name, process->simdata->PID); */ DEBUG3("Scheduling %s(%d) on %s", process->name,process->simdata->PID, process->simdata->host->name); msg_global->current_process = process; +/* fflush(NULL); */ xbt_context_schedule(process->simdata->context); msg_global->current_process = NULL; } - DEBUG1("%lg : Calling surf_solve",MSG_getClock()); - elapsed_time = surf_solve(); - DEBUG1("Elapsed_time %lg",elapsed_time); - -/* fprintf(stderr, "====== %lg =====\n",Now); */ -/* if (elapsed_time==0.0) { */ -/* fprintf(stderr, "No change in time\n"); */ -/* } */ - if (elapsed_time<0.0) { -/* fprintf(stderr, "We're done %lg\n",elapsed_time); */ - break; - } - + { surf_action_t action = NULL; surf_resource_t resource = NULL; m_task_t task = NULL; + + void *fun = NULL; + void *arg = NULL; + + xbt_dynar_foreach(resource_list, i, resource) { + if(xbt_swag_size(resource->common_public->states.failed_action_set) || + xbt_swag_size(resource->common_public->states.done_action_set)) + state_modifications = 1; + } + + if(!state_modifications) { + DEBUG1("%g : Calling surf_solve",MSG_get_clock()); + elapsed_time = surf_solve(); + DEBUG1("Elapsed_time %g",elapsed_time); + + if (elapsed_time<0.0) { + /* fprintf(stderr, "We're done %g\n",elapsed_time); */ + break; + } + } + + while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) { + DEBUG2("got %p %p", fun, arg); + if(fun==MSG_process_create_with_arguments) { + process_arg_t args = arg; + DEBUG2("Launching %s on %s", args->name, args->host->name); + process = MSG_process_create_with_arguments(args->name, args->code, + args->data, args->host, + args->argc,args->argv); + if(args->kill_time > MSG_get_clock()) { + surf_timer_resource->extension_public->set(args->kill_time, + (void*) &MSG_process_kill, + (void*) process); + } + xbt_free(args); + } + if(fun==MSG_process_kill) { + process = arg; + DEBUG3("Killing %s(%d) on %s", process->name, process->simdata->PID, + process->simdata->host->name); + MSG_process_kill(process); + } + } xbt_dynar_foreach(resource_list, i, resource) { while ((action = - xbt_swag_extract(resource->common_public->states. - failed_action_set))) { + xbt_swag_extract(resource->common_public->states. + failed_action_set))) { task = action->data; if(task) { int _cursor; DEBUG1("** %s failed **",task->name); -/* fprintf(stderr,"** %s **\n",task->name); */ xbt_dynar_foreach(task->simdata->sleeping,_cursor,process) { DEBUG3("\t preparing to wake up %s(%d) on %s", process->name,process->simdata->PID, @@ -358,13 +377,12 @@ MSG_error_t MSG_main(void) } } while ((action = - xbt_swag_extract(resource->common_public->states. - done_action_set))) { + xbt_swag_extract(resource->common_public->states. + done_action_set))) { task = action->data; if(task) { int _cursor; DEBUG1("** %s done **",task->name); -/* fprintf(stderr,"** %s **\n",task->name); */ xbt_dynar_foreach(task->simdata->sleeping,_cursor,process) { DEBUG3("\t preparing to wake up %s(%d) on %s", process->name,process->simdata->PID, @@ -376,6 +394,7 @@ MSG_error_t MSG_main(void) } } } + state_modifications = 0; } if ((nbprocess=xbt_fifo_size(msg_global->process_list)) == 0) { @@ -413,7 +432,7 @@ MSG_error_t MSG_main(void) if(p_simdata->waiting_task) { if(p_simdata->waiting_task->simdata->compute) { if(p_simdata->put_host) - fprintf(stderr,"Trying to send a task on Host %s, channel %d.\n", + fprintf(stderr,"Trying to send a task to Host %s, channel %d.\n", p_simdata->put_host->name, p_simdata->put_channel); else fprintf(stderr,"Waiting for %s to finish.\n",p_simdata->waiting_task->name); @@ -438,49 +457,6 @@ MSG_error_t MSG_main(void) } } -/* static void MarkAsFailed(m_task_t t, TBX_HashTable_t failedProcessList) */ -/* { */ -/* simdata_task_t simdata = NULL; */ -/* xbt_fifo_item_t i = NULL; */ -/* m_process_t p = NULL; */ - -/* xbt_assert0((t!=NULL),"Invalid task"); */ -/* simdata = t->simdata; */ - -/* #define KILL(task) if(task) SG_failTask(task) */ -/* KILL(simdata->compute); */ -/* KILL(simdata->TCP_comm); */ -/* KILL(simdata->s[0]); */ -/* KILL(simdata->s[1]); */ -/* KILL(simdata->s[2]); */ -/* KILL(simdata->s[3]); */ -/* KILL(simdata->sleep); */ -/* #undef KILL */ -/* /\* if(simdata->comm) SG_failEndToEndTransfer(simdata->comm); *\/ */ - -/* xbt_fifo_foreach(simdata->sleeping,i,p,m_process_t) { */ -/* if(!TBX_HashTable_isInList(failedProcessList,p,TBX_basicHash)) */ -/* TBX_HashTable_insert(failedProcessList,p,TBX_basicHash); */ -/* } */ - -/* } */ - -/* static xbt_fifo_t MSG_buildFailedHostList(double begin, double end) */ -/* { */ -/* xbt_fifo_t failedHostList = xbt_fifo_new(); */ -/* m_host_t host = NULL; */ -/* xbt_fifo_item_t i; */ - -/* xbt_fifo_foreach(msg_global->host,i,host,m_host_t) { */ -/* SG_Resource r= ((simdata_host_t) (host->simdata))->host; */ - -/* if(SG_evaluateFailureTrace(r->failure_trace,begin,end)!=-1.0) */ -/* xbt_fifo_insert(failedHostList,host); */ -/* } */ - -/* return failedHostList; */ -/* } */ - /** \ingroup msg_simulation * \brief Kill all running process @@ -490,18 +466,24 @@ MSG_error_t MSG_main(void) */ int MSG_process_killall(int reset_PIDs) { - xbt_fifo_item_t i = NULL; m_process_t p = NULL; + m_process_t self = MSG_process_self(); while((p=xbt_fifo_shift(msg_global->process_list))) { - MSG_process_kill(p); + if(p!=self) MSG_process_kill(p); } - xbt_context_empty_trash(); + if(reset_PIDs>0) { msg_global->PID = reset_PIDs; msg_global->session++; } + xbt_context_empty_trash(); + + if(self) { + xbt_context_yield(); + } + return msg_global->PID; } @@ -532,8 +514,9 @@ MSG_error_t MSG_clean(void) fclose(msg_global->paje_output); msg_global->paje_output = NULL; } - xbt_free(msg_global); - surf_finalize(); + msg_config_finalize(); + free(msg_global); + surf_exit(); return MSG_OK; } @@ -542,7 +525,7 @@ MSG_error_t MSG_clean(void) /** \ingroup msg_easier_life * \brief A clock (in second). */ -double MSG_getClock(void) { +double MSG_get_clock(void) { return surf_get_clock(); }