Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First try at actually using the configuration stuff. MSG acts as cobaye here
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 29 Jun 2005 20:46:05 +0000 (20:46 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 29 Jun 2005 20:46:05 +0000 (20:46 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1479 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/msg/environment.c
src/msg/msg_config.c [new file with mode: 0644]
src/msg/private.h

index ee94d94..9d6bbd8 100644 (file)
@@ -60,13 +60,22 @@ void MSG_create_environment(const char *file) {
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   void *workstation = NULL;
+  char *workstation_model_name;
 
+  msg_config_init(); /* make sure that our configuration set is created */
   surf_timer_resource_init(file);
-#ifdef ALVIN_SURF_SPECIAL
-  surf_workstation_resource_init_KCCFLN05(file);
-#else
-  surf_workstation_resource_init_CLM03(file);
-#endif
+
+  /* which model do you want today? */
+  xbt_cfg_get_string (_msg_cfg_set, "surf_workstation_model",
+                     &workstation_model_name);
+  if (!strcmp(workstation_model_name,"KCCFLN05")) {
+    surf_workstation_resource_init_KCCFLN05(file);
+  } else if (!strcmp(workstation_model_name,"CLM03")) {
+    surf_workstation_resource_init_CLM03(file);
+  } else {
+    xbt_assert0(0,"The impossible happened (once again)");
+  }
+  _msg_init_status = 2; /* inited; don't change settings now */
 
   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
     __MSG_host_create(name, workstation, NULL);
diff --git a/src/msg/msg_config.c b/src/msg/msg_config.c
new file mode 100644 (file)
index 0000000..4f5cbf7
--- /dev/null
@@ -0,0 +1,81 @@
+/* $Id$ */
+
+/* msg_config.c - support for MSG user configuration                        */
+
+/* Copyright (c) 2005 Martin Quinson.                                       */
+/* 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/error.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_cfg, msg,
+                               "Configuration support in \ref MSG");
+
+
+int _msg_init_status = 0; /* 0: beginning of time; 
+                             1: pre-inited (cfg_set created); 
+                             2: inited (running) */
+xbt_cfg_t _msg_cfg_set = NULL;
+
+/* callback of the surf_workstation_model variable */
+static void _msg_cfg_cb__surf_workstation_model(const char *name, int pos) {
+  xbt_error_t errcode;
+  char *val;
+
+  xbt_assert0(_msg_init_status<2, "Cannot change the model after the initialization");
+  
+  TRYFAIL(xbt_cfg_get_string (_msg_cfg_set, name, &val));
+  
+  xbt_assert1(!strcmp(val, "CLM03") ||
+              !strcmp(val, "KCCFLN05"),
+              "Unknown workstation model: %s (either 'CLM03' or 'KCCFLN05'",val);
+}
+
+/* create the config set and register what should be */
+void msg_config_init(void) {
+  xbt_error_t errcode;
+
+  if (_msg_init_status) 
+    return; /* Already inited, nothing to do */
+
+  _msg_init_status = 1;
+  _msg_cfg_set = xbt_cfg_new();
+  
+  xbt_cfg_register (_msg_cfg_set, 
+                    "surf_workstation_model", xbt_cfgelm_string, 1,1,
+                    &_msg_cfg_cb__surf_workstation_model,NULL);
+                    
+  TRYFAIL(xbt_cfg_set_string(_msg_cfg_set,"surf_workstation_model", "CLM03"));
+}
+
+/** \brief set a configuration variable
+ * 
+ * Currently existing configuation variable:
+ *   - surf_workstation_model (string): Model of workstation to use.  
+ *     Possible values (defaults to "CLM03"):
+ *     - "CLM03": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03])
+ *     - "KCCFLN05": simple network model (no latency) but interference 
+ *       between computations and communications (UNSTABLE, DONT USE)
+ * 
+ * Example:
+ * MSG_config("surf_workstation_model","CLM03");
+ */
+xbt_error_t
+MSG_config(const char *name, ...) {
+  va_list pa;
+  xbt_error_t errcode;
+    
+  if (!_msg_init_status) {
+    msg_config_init();
+  }
+xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set);
+  va_start(pa,name);
+  errcode=xbt_cfg_set_vargs(_msg_cfg_set,name,pa);
+  va_end(pa);
+  
+  return errcode;
+}
index c7732a6..29d30a0 100644 (file)
@@ -15,6 +15,7 @@
 #include "xbt/swag.h"
 #include "xbt/dict.h"
 #include "xbt/context.h"
+#include "xbt/config.h"
 
 /**************** datatypes **********************************/
 
@@ -83,6 +84,12 @@ typedef struct MSG_Global {
 
 extern MSG_Global_t msg_global;
       
+/************************** Configuration support ********************************/
+void msg_config_init(void); /* create the config set, call this before use! */
+extern int _msg_init_status; /* 0: beginning of time; 
+                                1: pre-inited (cfg_set created); 
+                                2: inited (running) */
+extern xbt_cfg_t _msg_cfg_set;
 
 /*************************************************************/