* Add SIMIX_process_set_name() to change the name of the current
process in the log messages.
* Store smx_hosts in a dict since we only retrieve them by name
+ * Move the configuration infrastructure to surf
+
+ SIMDAG:
+ * Move the configuration infrastructure to surf
XBT:
* Also include strbuff from xbt.h public header
This allows to do more with the given exception afterward.
Users should call xbt_ex_free() themselves.
- SMPI:
+ SMPI:
* Massive internal cleanups:
- Store internal structures on processes instead of hosts (allows
to have more than one process per host, in addition of being more
- Move queues from global tables to process data fields
* Improve smpirun:
- now accept -platform and -hostfile arguments
- - Pass the right rank value to processes according on hostfile
+ - Pass the right rank value to processes according to the hostfile
+ * Compile the examples by default, and use them as regression tests
Build Chain:
* Do not require doxygen in maintainer mode
#ifndef _XBT_CONFIG_H_
#define _XBT_CONFIG_H_
+#include <stdarg.h>
#include "xbt/dynar.h"
SG_BEGIN_DECL()
/** @addtogroup XBT_config
* @brief Changing the configuration of SimGrid components (grounding feature)
*
- * All modules of the SimGrid toolkit can be configured with this API.
- * User modules and libraries can also use these facilities to handle
+ * All modules of the SimGrid toolkit can be configured with this API.
+ * User modules and libraries can also use these facilities to handle
* their own configuration.
*
* A configuration set contain several \e variables which have a unique name
- * in the set and can take a given type of value. For example, it may
- * contain a \a size variable, accepting \e int values.
+ * in the set and can take a given type of value. For example, it may
+ * contain a \a size variable, accepting \e int values.
*
* It is impossible to set a value to a variable which has not been registered before.
* Usually, the module registers all the options it accepts in the configuration set,
* during its initialization and user code then set and unset values.
*
- * The easiest way to register a variable is to use the xbt_str_register_str function,
- * which accepts a string representation of the config element descriptor. The syntax
+ * The easiest way to register a variable is to use the xbt_str_register_str function,
+ * which accepts a string representation of the config element descriptor. The syntax
* is the following: \verbatim <name>:<min nb>_to_<max nb>_<type>\endverbatim
*
- * For example, <tt>size:1_to_1_int</tt> describes a variable called \e size which
- * must take exactly one value, and the value being an integer. Set the maximum to 0 to
+ * For example, <tt>size:1_to_1_int</tt> describes a variable called \e size which
+ * must take exactly one value, and the value being an integer. Set the maximum to 0 to
* disable the upper bound on data count.
*
* Another example could be <tt>outputfiles:0_to_10_string</tt> which describes a variable
* called \e outputfiles and which can take between 0 and 10 strings as value.
*
* To some extend, configuration sets can be seen as typed hash structures.
- *
+ *
* \todo This great mechanism is not used in SimGrid yet...
*
*
* \skip dyn
* \until cfg_free
*
- * All those functions throws mismatch_error if asked to deal with an
+ * All those functions throws mismatch_error if asked to deal with an
* unregistered variable.
* \skip myset
* \until cfg_free
- *
+ *
*/
/** @defgroup XBT_cfg_use User interface: changing values
* @ingroup XBT_config
*
- * This is the only interface you should use unless you want to let your
+ * This is the only interface you should use unless you want to let your
* own code become configurable with this.
*
- * If the variable accept at most one value, those functions replace the
- * current value with the provided one. If max>1, the provided value is
+ * If the variable accept at most one value, those functions replace the
+ * current value with the provided one. If max>1, the provided value is
* appended to the list.
*
* string values are strdup'ed before use, so you can (and should) free
- * your copy
+ * your copy
*
* @{
*/
/** @defgroup XBT_cfg_register Registering stuff
* @ingroup XBT_config
*
- * This how to add new variables to an existing configuration set. Use it to make your code
+ * This how to add new variables to an existing configuration set. Use it to make your code
* configurable.
*
* @{
*/
XBT_PUBLIC(void) xbt_cfg_register(xbt_cfg_t cfg,
- const char *name, e_xbt_cfgelm_type_t type,
+ const char *name, const char *description,
+ e_xbt_cfgelm_type_t type,
int min, int max,
xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm);
XBT_PUBLIC(void) xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
/** @defgroup XBT_cfg_get Getting the stored values
* @ingroup XBT_config
*
- * This is how to retrieve the values stored in the configuration set. This is only
+ * This is how to retrieve the values stored in the configuration set. This is only
* intended to configurable code, naturally.
*
- * Note that those function return a pointer to the values actually stored
- * in the set. Do not modify them unless you really know what you're doing.
+ * Note that those function return a pointer to the values actually stored
+ * in the set. Do not modify them unless you really know what you're doing.
* Likewise, do not free the strings after use, they are not copy of the data,
* but the data themselves.
*
xbt/xbt_sg_time.c
SURF_SRC= \
+ surf/surf_config.c \
surf/maxmin.c \
- surf/fair_bottleneck.c \
+ surf/fair_bottleneck.c \
surf/lagrange.c \
surf/trace_mgr.c \
- surf/random_mgr.c \
+ surf/random_mgr.c \
surf/surf.c \
surf/surfxml_parse.c \
surf/cpu.c surf/network.c surf/network_constant.c surf/workstation.c \
SIMIX_SRC= \
simix/smx_global.c \
simix/smx_deployment.c \
- simix/smx_config.c \
simix/smx_environment.c \
simix/smx_host.c \
simix/smx_process.c \
/************************** Global ******************************************/
-XBT_PUBLIC(void) SIMIX_config(const char *name, va_list pa);
XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
XBT_PUBLIC(void) SIMIX_clean(void);
XBT_PUBLIC(void) SIMIX_function_register(const char *name,
#include "xbt/dict.h"
#include "xbt/misc.h"
#include "portable.h"
+#include "xbt/config.h"
SG_BEGIN_DECL()
/* Actions and models are higly connected structures... */
/** \brief Action datatype
* \ingroup SURF_actions
- *
+ *
* An action is some working amount on a model.
* It is represented as a cost, a priority, a duration and a state.
*
/** \brief Model datatype
* \ingroup SURF_models
- *
+ *
* Generic data structure for a model. The workstations,
* the CPUs and the network links are examples of models.
*/
*
* Never create s_surf_action_t by yourself ! The actions are created
* on the fly when you call execute or communicate on a model.
- *
+ *
* \see e_surf_action_state_t
*/
typedef struct surf_action {
/** \brief Model datatype
* \ingroup SURF_models
- *
+ *
* Generic data structure for a model. The workstations,
* the CPUs and the network links are examples of models.
*/
/** \brief CPU model extension public
* \ingroup SURF_models
- *
+ *
* Public functions specific to the CPU model.
*/
typedef struct surf_cpu_model_extension_public {
* \ingroup SURF_models
* \param filename XML platform file name
*
- * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
+ * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
* to the proportional fairness.
*
* Reference:
*
* Reference:
*
- * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
+ * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
* Semi-definite programming approach for bandwidth allocation and routing in networks.
* Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
*
/*******************************************/
/*** SURF Globals **************************/
/*******************************************/
+xbt_cfg_t _surf_cfg_set;
/** \brief Initialize SURF
* \ingroup SURF_simulation
*/
XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
+/** \brief Initialize the used models.
+ *
+ * Must be called after the surf_init so that configuration infrastructure is created
+ * Must be called before parsing/creating the environment
+ * Must not be called within the initialization process so that the use get a chance to change the settings from
+ * its code between, say, MSG_init and MSG_create_environment using MSG_config
+ */
+XBT_PUBLIC(void) surf_config_models_setup(const char *platform_file);
+
+/** \brief create the elements of the models
+ *
+ * Must be called after parsing the platform file and before using any elements
+ */
+XBT_PUBLIC(void) surf_config_models_create_elms(void);
+
/** \brief Finish simulation initialization
* \ingroup SURF_simulation
*
#include "simix/simix.h"
/** \brief set a configuration variable
- *
+ *
* Currently existing configuation variable:
- * - workstation_model (string): Model of workstation to use.
+ * - 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.
* - "KCCFLN05_proportional": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file. Uses the proportional approahc as described in the Corine Touati's PhD Thesis.
* - "KCCFLN05_Vegas": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file. Uses the fairness adapted to the TCP Vegas flow control.
* - "KCCFLN05_Reno": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file. Uses the fairness adapted to the TCP Reno flow control.
- *
+ *
* Example:
* MSG_config("workstation_model","KCCFLN05");
*/
"ERROR: Please call MSG_init() before using MSG_config()\n");
abort();
}
-
-
-
- /* xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set); */
va_start(pa, name);
-
- SIMIX_config(name, pa);
-
+ xbt_cfg_set_vargs(_surf_cfg_set,name,pa);
va_end(pa);
return;
}
/* 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. */
-static int _sd_init_status = 0; /* 0: beginning of time;
- 1: pre-inited (cfg_set created);
- 2: inited (running) */
-static xbt_cfg_t _sd_cfg_set = NULL;
-
-/* callback of the workstation_model variable */
-static void _sd_cfg_cb__workstation_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_sd_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_sd_cfg_set, name);
- find_model_description(surf_workstation_model_description, val);
-}
-
-/* callback of the cpu_model variable */
-static void _sd_cfg_cb__cpu_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_sd_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_sd_cfg_set, name);
- find_model_description(surf_cpu_model_description, val);
-}
-
-/* callback of the workstation_model variable */
-static void _sd_cfg_cb__network_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_sd_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_sd_cfg_set, name);
- find_model_description(surf_network_model_description, val);
-}
-
XBT_LOG_EXTERNAL_CATEGORY(sd_kernel);
XBT_LOG_EXTERNAL_CATEGORY(sd_task);
XBT_LOG_EXTERNAL_CATEGORY(sd_workstation);
-/* create the config set and register what should be */
-static void sd_config_init(void)
-{
-
- if (_sd_init_status)
- return; /* Already inited, nothing to do */
-
- /* Connect our log channels: that must be done manually under windows */
- XBT_LOG_CONNECT(sd_kernel, sd);
- XBT_LOG_CONNECT(sd_task, sd);
- XBT_LOG_CONNECT(sd_workstation, sd);
-
- _sd_init_status = 1;
- _sd_cfg_set = xbt_cfg_new();
-
- xbt_cfg_register(_sd_cfg_set,
- "workstation_model", xbt_cfgelm_string, 1, 1,
- &_sd_cfg_cb__workstation_model, NULL);
-
- xbt_cfg_register(_sd_cfg_set,
- "cpu_model", xbt_cfgelm_string, 1, 1,
- &_sd_cfg_cb__cpu_model, NULL);
- xbt_cfg_register(_sd_cfg_set,
- "network_model", xbt_cfgelm_string, 1, 1,
- &_sd_cfg_cb__network_model, NULL);
-
- xbt_cfg_set_string(_sd_cfg_set, "workstation_model", "ptask_L07");
-}
-
-static void sd_config_finalize(void)
-{
-
- if (!_sd_init_status)
- return; /* Not initialized yet. Nothing to do */
-
- xbt_cfg_free(&_sd_cfg_set);
- _sd_init_status = 0;
-}
-
-static void sd_config(const char *name, va_list pa)
-{
- if (!_sd_init_status) {
- sd_config_init();
- }
- xbt_cfg_set_vargs(_sd_cfg_set, name, pa);
-}
-
-
-static void __sd_config_helper(const char *name, ...)
-{
- va_list pa;
- va_start(pa, name);
-
- sd_config(name, pa);
-
- va_end(pa);
-}
-
-static void sd_cfg_control_set(const char *control_string)
-{
- /* To split the string in commands, and the cursors */
- xbt_dynar_t set_strings;
- char *str;
- unsigned int cpt;
-
- if (!control_string)
- return;
- DEBUG1("Parse log settings '%s'", control_string);
-
- /* split the string, and remove empty entries */
- set_strings = xbt_str_split_quoted(control_string);
-
- if (xbt_dynar_length(set_strings) == 0) { /* vicious user! */
- xbt_dynar_free(&set_strings);
- return;
- }
- /* Parse each entry and either use it right now (if the category was already
- created), or store it for further use */
- xbt_dynar_foreach(set_strings, cpt, str) {
- char *control_string, *control_string_sav, *name, *value;
-
-
- control_string = control_string_sav = strdup(str);
- control_string += strspn(control_string, " ");
- name = control_string;
- control_string += strcspn(str, ":=");
- value = control_string;
- *value = 0;
- value++;
-
- xbt_assert1(strlen(name) != 0, "Invalid name for configuration: '%s'",
- name);
- xbt_assert1(strlen(value) != 0,
- "Invalid value for configuration: '%s'", value);
- INFO2("setting '%s' to '%s'", name, value);
-
- __sd_config_helper(name, value);
-
- free(control_string_sav);
- }
- xbt_dynar_free(&set_strings);
-}
-
-static void sd_cfg_init(int *argc, char **argv)
-{
- int i, j;
- char *opt;
-
- for (i = 1; i < *argc; i++) {
- if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
- opt = strchr(argv[i], '=');
- opt++;
-
- sd_cfg_control_set(opt);
- DEBUG1("Did apply '%s' as config setting", opt);
- /*remove this from argv */
-
- for (j = i + 1; j < *argc; j++) {
- argv[j - 1] = argv[j];
- }
-
- argv[j - 1] = NULL;
- (*argc)--;
- i--; /* compensate effect of next loop incrementation */
- }
- }
-}
-
/**
* \brief Initialises SD internal data
*
xbt_assert0(!SD_INITIALISED(), "SD_init() already called");
+ /* Connect our log channels: that must be done manually under windows */
+ XBT_LOG_CONNECT(sd_kernel, sd);
+ XBT_LOG_CONNECT(sd_task, sd);
+ XBT_LOG_CONNECT(sd_workstation, sd);
+
+
sd_global = xbt_new(s_SD_global_t, 1);
sd_global->workstations = xbt_dict_new();
sd_global->workstation_count = 0;
sd_global->task_number = 0;
surf_init(argc, argv);
- sd_cfg_init(argc, argv);
+ xbt_cfg_set_string(_surf_cfg_set, "workstation_model", "ptask_L07");
}
/**
* \brief Reinits the application part of the simulation (experimental feature)
- *
- * This function allows you to run several simulations on the same platform
- * by resetting the part describing the application.
- *
+ *
+ * This function allows you to run several simulations on the same platform
+ * by resetting the part describing the application.
+ *
* @warning: this function is still experimental and not perfect. For example,
* the simulation clock (and traces usage) is not reset. So, do not use it if
* you use traces in your simulation, and do not use absolute timing after using it.
*
* \include simgrid.dtd
*
- * Here is a small example of such a platform:
+ * Here is a small example of such a platform:
*
* \include small_platform.xml
*/
char *name = NULL;
void *surf_workstation = NULL;
void *surf_link = NULL;
- char *workstation_model_name;
- int workstation_id = -1;
SD_CHECK_INIT_DONE();
DEBUG0("SD_create_environment");
- sd_config_init();
surf_timer_model_init(platform_file);
-
- workstation_model_name =
- xbt_cfg_get_string(_sd_cfg_set, "workstation_model");
-
- DEBUG1("Model : %s", workstation_model_name);
- workstation_id =
- find_model_description(surf_workstation_model_description,
- workstation_model_name);
- if (!strcmp(workstation_model_name, "compound")) {
- xbt_ex_t e;
- char *network_model_name = NULL;
- char *cpu_model_name = NULL;
- int network_id = -1;
- int cpu_id = -1;
-
- TRY {
- cpu_model_name = xbt_cfg_get_string(_sd_cfg_set, "cpu_model");
- } CATCH(e) {
- if (e.category == bound_error) {
- xbt_assert0(0,
- "Set a cpu model to use with the 'compound' workstation model");
- xbt_ex_free(e);
- } else {
- RETHROW;
- }
- }
-
- TRY {
- network_model_name = xbt_cfg_get_string(_sd_cfg_set, "network_model");
- }
- CATCH(e) {
- if (e.category == bound_error) {
- xbt_assert0(0,
- "Set a network model to use with the 'compound' workstation model");
- xbt_ex_free(e);
- } else {
- RETHROW;
- }
- }
-
- network_id =
- find_model_description(surf_network_model_description,
- network_model_name);
- cpu_id =
- find_model_description(surf_cpu_model_description, cpu_model_name);
-
- surf_cpu_model_description[cpu_id].model_init(platform_file);
- surf_network_model_description[network_id].model_init(platform_file);
- }
-
- DEBUG0("Call workstation_model_init");
- surf_workstation_model_description[workstation_id].model_init
- (platform_file);
+ surf_config_models_setup(platform_file);
parse_platform_file(platform_file);
- _sd_init_status = 2;
-
/* now let's create the SD wrappers for workstations and links */
xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
__SD_workstation_create(surf_workstation, NULL);
* The simulation will be stopped when its time reaches \a how_long,
* when a watch point is reached, or when no more task can be executed.
* Then you can call SD_simulate() again.
- *
+ *
* \param how_long maximum duration of the simulation (a negative value means no time limit)
* \return a NULL-terminated array of \ref SD_task_t whose state has changed.
* \see SD_task_schedule(), SD_task_watch()
#include "xbt/swag.h"
#include "xbt/dict.h"
#include "xbt/context.h"
-#include "xbt/config.h"
#include "xbt/function_types.h"
/******************************* Datatypes **********************************/
-/******************************* Configuration support **********************************/
-
-void simix_config_init(void); /* create the config set, call this before use! */
-void simix_config_finalize(void); /* destroy the config set, call this at cleanup. */
-extern int _simix_init_status; /* 0: beginning of time;
- 1: pre-inited (cfg_set created);
- 2: inited (running) */
-extern xbt_cfg_t _simix_cfg_set;
+/******************************* Other **********************************/
#define SIMIX_CHECK_HOST() xbt_assert0(surf_workstation_model->extension_public-> \
+++ /dev/null
-/* $Id$ */
-
-/* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
- All rights reserved. */
-
-/* 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/log.h"
-
-int _simix_init_status = 0; /* 0: beginning of time;
- 1: pre-inited (cfg_set created);
- 2: inited (running) */
-xbt_cfg_t _simix_cfg_set = NULL;
-
-/* callback of the workstation_model variable */
-static void _simix_cfg_cb__workstation_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_simix_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_simix_cfg_set, name);
- /* New Module missing */
-
- find_model_description(surf_workstation_model_description, val);
-}
-
-/* callback of the cpu_model variable */
-static void _simix_cfg_cb__cpu_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_simix_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_simix_cfg_set, name);
- /* New Module missing */
- find_model_description(surf_cpu_model_description, val);
-}
-
-/* callback of the workstation_model variable */
-static void _simix_cfg_cb__network_model(const char *name, int pos)
-{
- char *val;
-
- xbt_assert0(_simix_init_status < 2,
- "Cannot change the model after the initialization");
-
- val = xbt_cfg_get_string(_simix_cfg_set, name);
- /* New Module missing */
- find_model_description(surf_network_model_description, val);
-}
-
-XBT_LOG_EXTERNAL_CATEGORY(simix);
-XBT_LOG_EXTERNAL_CATEGORY(simix_action);
-XBT_LOG_EXTERNAL_CATEGORY(simix_deployment);
-XBT_LOG_EXTERNAL_CATEGORY(simix_environment);
-XBT_LOG_EXTERNAL_CATEGORY(simix_host);
-XBT_LOG_EXTERNAL_CATEGORY(simix_kernel);
-XBT_LOG_EXTERNAL_CATEGORY(simix_process);
-XBT_LOG_EXTERNAL_CATEGORY(simix_synchro);
-
-/* create the config set and register what should be */
-void simix_config_init(void)
-{
-
- if (_simix_init_status)
- return; /* Already inited, nothing to do */
-
- /* Connect our log channels: that must be done manually under windows */
- XBT_LOG_CONNECT(simix_action, simix);
- XBT_LOG_CONNECT(simix_deployment, simix);
- XBT_LOG_CONNECT(simix_environment, simix);
- XBT_LOG_CONNECT(simix_host, simix);
- XBT_LOG_CONNECT(simix_kernel, simix);
- XBT_LOG_CONNECT(simix_process, simix);
- XBT_LOG_CONNECT(simix_synchro, simix);
-
- _simix_init_status = 1;
- _simix_cfg_set = xbt_cfg_new();
-
- xbt_cfg_register(_simix_cfg_set,
- "workstation_model", xbt_cfgelm_string, 1, 1,
- &_simix_cfg_cb__workstation_model, NULL);
-
- xbt_cfg_register(_simix_cfg_set,
- "cpu_model", xbt_cfgelm_string, 1, 1,
- &_simix_cfg_cb__cpu_model, NULL);
- xbt_cfg_register(_simix_cfg_set,
- "network_model", xbt_cfgelm_string, 1, 1,
- &_simix_cfg_cb__network_model, NULL);
-
- xbt_cfg_set_string(_simix_cfg_set, "workstation_model", "CLM03");
-}
-
-void simix_config_finalize(void)
-{
-
- if (!_simix_init_status)
- return; /* Not initialized yet. Nothing to do */
-
- xbt_cfg_free(&_simix_cfg_set);
- _simix_init_status = 0;
-}
-
-/** \brief Set a configuration variable
- *
- * FIXME
-
- * Currently existing configuration variable:
- * - 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.
- * - compound
- * \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)
-{
- if (!_simix_init_status) {
- simix_config_init();
- }
- xbt_cfg_set_vargs(_simix_cfg_set, name, pa);
-}
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/xbt_os_time.h"
+#include "xbt/config.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix,
"Logging specific to SIMIX (environment)");
/********************************* SIMIX **************************************/
-/**
+/**
* \brief A platform constructor.
*
* Creates a new platform, including hosts, links and the
- * routing_table.
- * \param file a filename of a xml description of a platform. This file
+ * routing_table.
+ * \param file a filename of a xml description of a platform. This file
* follows this DTD :
*
* \include surfxml.dtd
*
- * Here is a small example of such a platform
+ * Here is a small example of such a platform
*
* \include small_platform.xml
*
*/
void SIMIX_create_environment(const char *file)
{
- xbt_dict_cursor_t cursor = NULL;
+ xbt_dict_cursor_t cursor = NULL;
char *name = NULL;
void *workstation = NULL;
- char *workstation_model_name;
- int workstation_id = -1;
+
double start, end;
- simix_config_init(); /* make sure that our configuration set is created */
surf_timer_model_init(file);
-
- /* which model do you want today? */
- workstation_model_name =
- xbt_cfg_get_string(_simix_cfg_set, "workstation_model");
-
- DEBUG1("Model : %s", workstation_model_name);
- workstation_id =
- find_model_description(surf_workstation_model_description,
- workstation_model_name);
- if (!strcmp(workstation_model_name, "compound")) {
- xbt_ex_t e;
- char *network_model_name = NULL;
- char *cpu_model_name = NULL;
- int network_id = -1;
- int cpu_id = -1;
-
- TRY {
- cpu_model_name = xbt_cfg_get_string(_simix_cfg_set, "cpu_model");
- } CATCH(e) {
- if (e.category == bound_error) {
- xbt_assert0(0,
- "Set a cpu model to use with the 'compound' workstation model");
- xbt_ex_free(e);
- } else {
- RETHROW;
- }
- }
-
- TRY {
- network_model_name =
- xbt_cfg_get_string(_simix_cfg_set, "network_model");
- }
- CATCH(e) {
- if (e.category == bound_error) {
- xbt_assert0(0,
- "Set a network model to use with the 'compound' workstation model");
- xbt_ex_free(e);
- } else {
- RETHROW;
- }
- }
-
- network_id =
- find_model_description(surf_network_model_description,
- network_model_name);
- cpu_id =
- find_model_description(surf_cpu_model_description, cpu_model_name);
-
- surf_cpu_model_description[cpu_id].model_init(file);
- surf_network_model_description[network_id].model_init(file);
-
-
- }
- surf_workstation_model_description[workstation_id].model_init(file);
-
- start = xbt_os_time();
+ surf_config_models_setup(file);
parse_platform_file(file);
+ surf_config_models_create_elms();
+ start = xbt_os_time();
- if (surf_workstation_model_description[workstation_id].create_ws != NULL)
- surf_workstation_model_description[workstation_id].create_ws();
end = xbt_os_time();
DEBUG1("PARSE TIME: %lg", (end - start));
- _simix_init_status = 2; /* inited; don't change settings now */
-
xbt_dict_foreach(workstation_set, cursor, name, workstation) {
- __SIMIX_host_create(name, workstation, NULL);
+ __SIMIX_host_create(name, workstation, NULL);
}
return;
#include "xbt/log.h"
#include "xbt/str.h"
#include "xbt/ex.h" /* ex_backtrace_display */
+XBT_LOG_EXTERNAL_CATEGORY(simix);
+XBT_LOG_EXTERNAL_CATEGORY(simix_action);
+XBT_LOG_EXTERNAL_CATEGORY(simix_deployment);
+XBT_LOG_EXTERNAL_CATEGORY(simix_environment);
+XBT_LOG_EXTERNAL_CATEGORY(simix_host);
+XBT_LOG_EXTERNAL_CATEGORY(simix_process);
+XBT_LOG_EXTERNAL_CATEGORY(simix_synchro);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix,
"Logging specific to SIMIX (kernel)");
SIMIX_Global_t simix_global = NULL;
-/********************************* SIMIX **************************************/
-static void __simix_config_helper(const char *name, ...)
-{
- va_list pa;
- va_start(pa, name);
-
- SIMIX_config(name, pa);
-
- va_end(pa);
-}
-
-static void simix_cfg_control_set(const char *control_string)
-{
- /* To split the string in commands, and the cursors */
- xbt_dynar_t set_strings;
- char *str;
- unsigned int cpt;
-
- if (!control_string)
- return;
- DEBUG1("Parse log settings '%s'", control_string);
-
- /* split the string, and remove empty entries */
- set_strings = xbt_str_split_quoted(control_string);
-
- if (xbt_dynar_length(set_strings) == 0) { /* vicious user! */
- xbt_dynar_free(&set_strings);
- return;
- }
- /* Parse each entry and either use it right now (if the category was already
- created), or store it for further use */
- xbt_dynar_foreach(set_strings, cpt, str) {
- char *control_string, *control_string_sav, *name, *value;
-
-
- control_string = control_string_sav = strdup(str);
- control_string += strspn(control_string, " ");
- name = control_string;
- control_string += strcspn(str, ":=");
- value = control_string;
- *value = 0;
- value++;
-
- xbt_assert1(strlen(name) != 0, "Invalid name for configuration: '%s'",
- name);
- xbt_assert1(strlen(value) != 0,
- "Invalid value for configuration: '%s'", value);
- INFO2("setting '%s' to '%s'", name, value);
-
- __simix_config_helper(name, value);
-
- free(control_string_sav);
- }
- xbt_dynar_free(&set_strings);
-}
-
-static void simix_cfg_init(int *argc, char **argv)
-{
- int i, j;
- char *opt;
-
- for (i = 1; i < *argc; i++) {
- if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
- opt = strchr(argv[i], '=');
- opt++;
-
- simix_cfg_control_set(opt);
- DEBUG1("Did apply '%s' as config setting", opt);
- /*remove this from argv */
-
- for (j = i + 1; j < *argc; j++) {
- argv[j - 1] = argv[j];
- }
-
- argv[j - 1] = NULL;
- (*argc)--;
- i--; /* compensate effect of next loop incrementation */
- }
- }
-}
/* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */
#include <signal.h>
exit(1);
}
+/********************************* SIMIX **************************************/
/**
- * \brief Initialize some SIMIX internal data.
+ * \brief Initialize SIMIX internal data.
*
* \param argc Argc
* \param argv Argv
s_smx_process_t proc;
if (!simix_global) {
- surf_init(argc, argv); /* Initialize some common structures. Warning, it sets simix_global=NULL */
- simix_cfg_init(argc, argv);
+ /* Connect our log channels: that must be done manually under windows */
+ XBT_LOG_CONNECT(simix_action, simix);
+ XBT_LOG_CONNECT(simix_deployment, simix);
+ XBT_LOG_CONNECT(simix_environment, simix);
+ XBT_LOG_CONNECT(simix_host, simix);
+ XBT_LOG_CONNECT(simix_kernel, simix);
+ XBT_LOG_CONNECT(simix_process, simix);
+ XBT_LOG_CONNECT(simix_synchro, simix);
simix_global = xbt_new0(s_SIMIX_Global_t, 1);
/* Prepare to display some more info when dying on Ctrl-C pressing */
signal(SIGINT, inthandler);
+ surf_init(argc, argv); /* Initialize SURF structures */
}
}
xbt_swag_free(simix_global->process_to_run);
xbt_swag_free(simix_global->process_list);
xbt_dict_free(&(simix_global->registered_functions));
- simix_config_finalize();
free(simix_global);
simix_global = NULL;
cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1);
xbt_assert1(!xbt_dict_get_or_null(cpu_set, name),
"Host '%s' declared several times in the platform file", name);
-
cpu->model = (surf_model_t) surf_cpu_model;
cpu->name = name;
cpu->power_scale = power_scale;
action->generic_action.start = surf_get_clock();
action->generic_action.finish = -1.0;
action->generic_action.model_type = (surf_model_t) surf_cpu_model;
- action->suspended = 0; /* Should be useless because of the
+ action->suspended = 0; /* Should be useless because of the
calloc but it seems to help valgrind... */
if (CPU->state_current == SURF_CPU_ON)
"SURF_ACTION_NOT_IN_THE_SYSTEM"
};
-
+/* Don't forget to update the option description in smx_config when you change this */
s_surf_model_description_t surf_network_model_description[] = {
{"Constant", NULL, surf_network_model_init_Constant},
{"CM02", NULL, surf_network_model_init_CM02},
XBT_LOG_EXTERNAL_CATEGORY(surf_parse);
XBT_LOG_EXTERNAL_CATEGORY(surf_timer);
XBT_LOG_EXTERNAL_CATEGORY(surf_workstation);
+XBT_LOG_EXTERNAL_CATEGORY(surf_config);
+
#ifdef HAVE_SDP
XBT_LOG_EXTERNAL_CATEGORY(surf_sdp_out);
XBT_LOG_CONNECT(surf_parse, surf);
XBT_LOG_CONNECT(surf_timer, surf);
XBT_LOG_CONNECT(surf_workstation, surf);
+ XBT_LOG_CONNECT(surf_config, surf);
#ifdef HAVE_SDP
XBT_LOG_CONNECT(surf_sdp_out, surf);
model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
if (!history)
history = tmgr_history_new();
+
+ surf_config_init(argc,argv);
}
static char *path_name = NULL;
unsigned int iter;
surf_model_t model = NULL;
+ surf_config_finalize();
+
xbt_dynar_foreach(model_list, iter, model) {
model->common_private->finalize();
}
--- /dev/null
+/* $Id$ */
+
+/* Copyright (c) 2009 The SimGrid team. All rights reserved. */
+
+/* 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. */
+
+/* surf_config: configuration infrastructure for the simulation world */
+
+#include "xbt/config.h"
+#include "xbt/str.h"
+#include "surf/surf_private.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config,surf,"About the configuration of surf (and the rest of the simulation)");
+
+xbt_cfg_t _surf_cfg_set = NULL;
+
+int _surf_init_status = 0; /* 0: beginning of time;
+ 1: pre-inited (cfg_set created);
+ 2: inited (running) */
+
+/* callback of the workstation_model variable */
+static void _surf_cfg_cb__workstation_model(const char *name, int pos)
+{
+ char *val;
+
+ xbt_assert0(_surf_init_status < 2,
+ "Cannot change the model after the initialization");
+
+ val = xbt_cfg_get_string(_surf_cfg_set, name);
+ /* New Module missing */
+
+ find_model_description(surf_workstation_model_description, val);
+}
+
+/* callback of the cpu_model variable */
+static void _surf_cfg_cb__cpu_model(const char *name, int pos)
+{
+ char *val;
+
+ xbt_assert0(_surf_init_status < 2,
+ "Cannot change the model after the initialization");
+
+ val = xbt_cfg_get_string(_surf_cfg_set, name);
+ /* New Module missing */
+ find_model_description(surf_cpu_model_description, val);
+}
+
+/* callback of the workstation_model variable */
+static void _surf_cfg_cb__network_model(const char *name, int pos)
+{
+ char *val;
+
+ xbt_assert0(_surf_init_status < 2,
+ "Cannot change the model after the initialization");
+
+ val = xbt_cfg_get_string(_surf_cfg_set, name);
+ /* New Module missing */
+ find_model_description(surf_network_model_description, val);
+}
+
+/* Parse the command line, looking for options */
+static void surf_config_cmd_line(int *argc,char **argv)
+{
+ int i, j;
+ char *opt;
+
+ for (i = 1; i < *argc; i++) {
+ if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
+ opt = strchr(argv[i], '=');
+ opt++;
+
+ xbt_cfg_set_parse(_surf_cfg_set,opt);
+ DEBUG1("Did apply '%s' as config setting", opt);
+ /*remove this from argv */
+
+ for (j = i + 1; j < *argc; j++) {
+ argv[j - 1] = argv[j];
+ }
+
+ argv[j - 1] = NULL;
+ (*argc)--;
+ i--; /* compensate effect of next loop incrementation */
+ }
+ }
+}
+
+/* create the config set, register what should be and parse the command line*/
+void surf_config_init(int *argc, char **argv) {
+
+ /* Create the configuration support */
+ if (!_surf_cfg_set) { /* Only create stuff if not already inited */
+ _surf_cfg_set = xbt_cfg_new();
+ _surf_init_status = 1;
+
+ char *description = xbt_malloc(1024), *p = description;
+ int i;
+ sprintf(description,"The model to use for the workstation. Possible values: ");
+ while (*(++p) != '\0');
+ for (i=0;surf_workstation_model_description[i].name;i++)
+ p+=sprintf(p,"%s%s",(i==0?"":", "),surf_workstation_model_description[i].name);
+
+ xbt_cfg_register(_surf_cfg_set,
+ "workstation_model", description, xbt_cfgelm_string, 1, 1,
+ &_surf_cfg_cb__workstation_model, NULL);
+
+ sprintf(description,"The model to use for the CPU. Possible values: ");
+ p = description;
+ while (*(++p) != '\0');
+ for (i=0;surf_cpu_model_description[i].name;i++)
+ p+=sprintf(p,"%s%s",(i==0?"":", "),surf_cpu_model_description[i].name);
+ xbt_cfg_register(_surf_cfg_set,
+ "cpu_model", description, xbt_cfgelm_string, 1, 1,
+ &_surf_cfg_cb__cpu_model, NULL);
+
+ sprintf(description,"The model to use for the network. Possible values: ");
+ p = description;
+ while (*(++p) != '\0');
+ for (i=0;surf_network_model_description[i].name;i++)
+ p+=sprintf(p,"%s%s",(i==0?"":", "),surf_network_model_description[i].name);
+ xbt_cfg_register(_surf_cfg_set,
+ "network_model", description, xbt_cfgelm_string, 1, 1,
+ &_surf_cfg_cb__network_model, NULL);
+
+ xbt_cfg_set_string(_surf_cfg_set, "workstation_model", "CLM03");
+
+ surf_config_cmd_line(argc,argv);
+ }
+}
+void surf_config_finalize(void)
+{
+ if (!_surf_init_status)
+ return; /* Not initialized yet. Nothing to do */
+
+ xbt_cfg_free(&_surf_cfg_set);
+ _surf_init_status = 0;
+}
+
+void surf_config_models_setup(const char *platform_file){
+ char *workstation_model_name;
+ int workstation_id = -1;
+
+ workstation_model_name =
+ xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
+
+ DEBUG1("Model : %s", workstation_model_name);
+ workstation_id =
+ find_model_description(surf_workstation_model_description,
+ workstation_model_name);
+ if (!strcmp(workstation_model_name, "compound")) {
+ xbt_ex_t e;
+ char *network_model_name = NULL;
+ char *cpu_model_name = NULL;
+ int network_id = -1;
+ int cpu_id = -1;
+
+ TRY {
+ cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu_model");
+ } CATCH(e) {
+ if (e.category == bound_error) {
+ xbt_assert0(0,
+ "Set a cpu model to use with the 'compound' workstation model");
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
+
+ TRY {
+ network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network_model");
+ }
+ CATCH(e) {
+ if (e.category == bound_error) {
+ xbt_assert0(0,
+ "Set a network model to use with the 'compound' workstation model");
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
+
+ network_id =
+ find_model_description(surf_network_model_description,
+ network_model_name);
+ cpu_id =
+ find_model_description(surf_cpu_model_description, cpu_model_name);
+
+ surf_cpu_model_description[cpu_id].model_init(platform_file);
+ surf_network_model_description[network_id].model_init(platform_file);
+ }
+
+ DEBUG0("Call workstation_model_init");
+ surf_workstation_model_description[workstation_id].model_init(platform_file);
+}
+
+void surf_config_models_create_elms(void) {
+ char *workstation_model_name = xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
+ int workstation_id =
+ find_model_description(surf_workstation_model_description,
+ workstation_model_name);
+ if (surf_workstation_model_description[workstation_id].create_ws != NULL)
+ surf_workstation_model_description[workstation_id].create_ws();
+}
extern tmgr_history_t history;
extern xbt_dynar_t surf_path;
+void surf_config_init(int *argc,char **argv);
+void surf_config_finalize(void);
+void surf_config(const char *name, va_list pa);
+
+
/*
* Returns the initial path. On Windows the initial path is
* the current directory for the current process in the other
defend my thesis. */
typedef struct {
+ /* Description */
+ const char *desc;
+
/* Allowed type of the variable */
e_xbt_cfgelm_type_t type;
int min, max;
xbt_assert0(tocopy, "cannot copy NULL config");
xbt_dict_foreach((xbt_dict_t) tocopy, cursor, name, variable) {
- xbt_cfg_register(*whereto, name, variable->type, variable->min,
+ xbt_cfg_register(*whereto, name, variable->desc, variable->type, variable->min,
variable->max, variable->cb_set, variable->cb_rm);
}
}
void
xbt_cfg_register(xbt_cfg_t cfg,
- const char *name, e_xbt_cfgelm_type_t type,
+ const char *name, const char *desc, e_xbt_cfgelm_type_t type,
int min, int max, xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm)
{
xbt_cfgelm_t res;
}
res = xbt_new(s_xbt_cfgelm_t, 1);
- DEBUG7("Register cfg elm %s (%d to %d %s (=%d) @%p in set %p)",
- name, min, max, xbt_cfgelm_type_name[type], type, res, cfg);
+ DEBUG8("Register cfg elm %s (%s) (%d to %d %s (=%d) @%p in set %p)",
+ name, desc, min, max, xbt_cfgelm_type_name[type], type, res, cfg);
+ res->desc = desc;
res->type = type;
res->min = min;
res->max = max;
* The string may consist in several variable descriptions separated by a space.
* Each of them must use the following syntax: \<name\>:\<min nb\>_to_\<max nb\>_\<type\>
* with type being one of 'string','int', 'peer' or 'double'.
+ *
+ * @fixme: this does not allow to set the description
*/
void xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry)
"Invalid type in config element descriptor: %s%s", entry,
"; Should be one of 'string', 'int', 'peer' or 'double'.");
- xbt_cfg_register(cfg, entrycpy, type, min, max, NULL, NULL);
+ xbt_cfg_register(cfg, entrycpy, NULL, type, min, max, NULL, NULL);
free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
}
*
* \arg cfg config set to fill
* \arg options a string containing the content to add to the config set. This
- * is a '\\t',' ' or '\\n' separated list of variables. Each individual variable is
+ * is a '\\t',' ' or '\\n' or ',' separated list of variables. Each individual variable is
* like "[name]:[value]" where [name] is the name of an already registred
* variable, and [value] conforms to the data type under which this variable was
* registred.
/* Pass the value */
while (option - name <= (len - 1) && *option != ' ' && *option != '\n'
- && *option != '\t') {
+ && *option != '\t' && *option != ',') {
DEBUG1("Take %c.", *option);
option++;
}
}
*(val++) = '\0';
- DEBUG2("name='%s';val='%s'", name, val);
+ INFO2("Configuration change: Set '%s' to '%s'", name, val);
TRY {
variable = xbt_dict_get((xbt_dict_t) cfg, name);
#include "xbt.h"
#include "xbt/ex.h"
+XBT_LOG_EXTERNAL_CATEGORY(xbt_cfg);
+
XBT_TEST_SUITE("config", "Configuration support");
static xbt_cfg_t make_set()
{
xbt_cfg_t set = NULL;
+ xbt_log_threshold_set(&_XBT_LOGV(xbt_cfg),xbt_log_priority_critical);
set = xbt_cfg_new();
xbt_cfg_register_str(set, "speed:1_to_2_int");
xbt_cfg_register_str(set, "peername:1_to_1_string");