Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "The latency is constant with the constant network model."
[simgrid.git] / src / surf / network_constant.c
index df8eaf5..4d2fd38 100644 (file)
@@ -1,6 +1,5 @@
-/*     $Id$     */
-
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+/* Copyright (c) 2008, 2009, 2010. 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. */
@@ -20,54 +19,42 @@ typedef struct surf_action_network_Constant {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 static random_data_t random_latency = NULL;
-static int host_number = 0;
+static int host_number_int = 0;
 
-static void count_hosts(void)
-{
-  host_number++;
+static void netcste_count_hosts(sg_platf_host_cbarg_t h) {
+  host_number_int++;
 }
 
-static void define_callbacks(const char *file)
-{
-  /* Figuring out the network links */
-  surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
+static void netcste_define_callbacks(void) {
+  sg_platf_host_add_cb(netcste_count_hosts);
 }
 
-static int resource_used(void *resource_id)
+static int netcste_resource_used(void *resource_id)
 {
   return 0;
 }
 
-static int action_unref(surf_action_t action)
+static int netcste_action_unref(surf_action_t action)
 {
   action->refcount--;
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
-    free(action);
+    surf_action_free(&action);
     return 1;
   }
   return 0;
 }
 
-static void action_cancel(surf_action_t action)
-{
-  return;
-}
-
-static void action_recycle(surf_action_t action)
+static void netcste_action_cancel(surf_action_t action)
 {
   return;
 }
 
-static double action_get_remains(surf_action_t action)
-{
-  return action->remains;
-}
-
-static double share_resources(double now)
+static double netcste_share_resources(double now)
 {
   surf_action_network_Constant_t action = NULL;
-  xbt_swag_t running_actions = surf_network_model->states.running_action_set;
+  xbt_swag_t running_actions =
+      surf_network_model->states.running_action_set;
   double min = -1.0;
 
   xbt_swag_foreach(action, running_actions) {
@@ -82,11 +69,12 @@ static double share_resources(double now)
   return min;
 }
 
-static void update_actions_state(double now, double delta)
+static void netcste_update_actions_state(double now, double delta)
 {
   surf_action_network_Constant_t action = NULL;
   surf_action_network_Constant_t next_action = NULL;
-  xbt_swag_t running_actions = surf_network_model->states.running_action_set;
+  xbt_swag_t running_actions =
+      surf_network_model->states.running_action_set;
 
   xbt_swag_foreach_safe(action, next_action, running_actions) {
     if (action->latency > 0) {
@@ -114,52 +102,54 @@ static void update_actions_state(double now, double delta)
   }
 }
 
-static void update_resource_state(void *id,
-                                  tmgr_trace_event_t event_type,
-                                  double value, double time)
+static void netcste_update_resource_state(void *id,
+                                          tmgr_trace_event_t event_type,
+                                          double value, double time)
 {
   DIE_IMPOSSIBLE;
 }
 
-static surf_action_t communicate(const char *src_name, const char *dst_name,
-                                 int src, int dst, double size, double rate)
+static surf_action_t netcste_communicate(const char *src_name,
+                                         const char *dst_name, double size,
+                                         double rate)
 {
   surf_action_network_Constant_t action = NULL;
 
-  XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
+  XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
 
   action =
-    surf_action_new(sizeof(s_surf_action_network_Constant_t), size,
-                    surf_network_model, 0);
+      surf_action_new(sizeof(s_surf_action_network_Constant_t), size,
+                      surf_network_model, 0);
 
   action->suspended = 0;
 
-  action->latency = 1;          //random_generate(random_latency);
+  action->latency = sg_latency_factor;          //random_generate(random_latency);
   action->lat_init = action->latency;
 
   if (action->latency <= 0.0) {
     action->generic_action.state_set =
-      surf_network_model->states.done_action_set;
+        surf_network_model->states.done_action_set;
     xbt_swag_insert(action, action->generic_action.state_set);
   }
 
-  XBT_OUT;
+  XBT_OUT();
 
   return (surf_action_t) action;
 }
 
-/* returns an array of link_Constant_t */
-static xbt_dynar_t get_route(void *src, void *dst)
+#ifdef HAVE_TRACING
+static void netcste_action_set_category(surf_action_t action, const char *category)
 {
-  xbt_die("Calling this function does not make any sense");
+  //ignore completely the categories in constant model, they are not traced
 }
+#endif
 
-static double get_link_bandwidth(const void *link)
+static double netcste_get_link_bandwidth(const void *link)
 {
   DIE_IMPOSSIBLE;
 }
 
-static double get_link_latency(const void *link)
+static double netcste_get_link_latency(const void *link)
 {
   DIE_IMPOSSIBLE;
 }
@@ -169,28 +159,23 @@ static int link_shared(const void *link)
   DIE_IMPOSSIBLE;
 }
 
-static void action_suspend(surf_action_t action)
+static void netcste_action_suspend(surf_action_t action)
 {
   ((surf_action_network_Constant_t) action)->suspended = 1;
 }
 
-static void action_resume(surf_action_t action)
+static void netcste_action_resume(surf_action_t action)
 {
   if (((surf_action_network_Constant_t) action)->suspended)
     ((surf_action_network_Constant_t) action)->suspended = 0;
 }
 
-static int action_is_suspended(surf_action_t action)
+static int netcste_action_is_suspended(surf_action_t action)
 {
   return ((surf_action_network_Constant_t) action)->suspended;
 }
 
-static void action_set_max_duration(surf_action_t action, double duration)
-{
-  action->max_duration = duration;
-}
-
-static void finalize(void)
+static void netcste_finalize(void)
 {
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
@@ -198,47 +183,51 @@ static void finalize(void)
 
 
 
-void surf_network_model_init_Constant(const char *filename)
+void surf_network_model_init_Constant()
 {
   xbt_assert(surf_network_model == NULL);
   if (surf_network_model)
     return;
   surf_network_model = surf_model_init();
 
-  INFO0("Blah");
   surf_network_model->name = "constant time network";
-  surf_network_model->action_unref = action_unref;
-  surf_network_model->action_cancel = action_cancel;
-  surf_network_model->action_recycle = action_recycle;
-  surf_network_model->get_remains = action_get_remains;
-
-  surf_network_model->model_private->resource_used = resource_used;
-  surf_network_model->model_private->share_resources = share_resources;
+  surf_network_model->action_unref = netcste_action_unref;
+  surf_network_model->action_cancel = netcste_action_cancel;
+  surf_network_model->action_recycle = net_action_recycle;
+  surf_network_model->get_remains = net_action_get_remains;
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  surf_network_model->get_latency_limited = net_get_link_latency_limited;
+#endif
+
+  surf_network_model->model_private->resource_used = netcste_resource_used;
+  surf_network_model->model_private->share_resources =
+      netcste_share_resources;
   surf_network_model->model_private->update_actions_state =
-    update_actions_state;
+      netcste_update_actions_state;
   surf_network_model->model_private->update_resource_state =
-    update_resource_state;
-  surf_network_model->model_private->finalize = finalize;
+      netcste_update_resource_state;
+  surf_network_model->model_private->finalize = netcste_finalize;
 
-  surf_network_model->suspend = action_suspend;
-  surf_network_model->resume = action_resume;
-  surf_network_model->is_suspended = action_is_suspended;
-  surf_cpu_model->set_max_duration = action_set_max_duration;
+  surf_network_model->suspend = netcste_action_suspend;
+  surf_network_model->resume = netcste_action_resume;
+  surf_network_model->is_suspended = netcste_action_is_suspended;
+  surf_cpu_model->set_max_duration = net_action_set_max_duration;
 
-  surf_network_model->extension.network.communicate = communicate;
+  surf_network_model->extension.network.communicate = netcste_communicate;
   surf_network_model->extension.network.get_link_bandwidth =
-    get_link_bandwidth;
-  surf_network_model->extension.network.get_link_latency = get_link_latency;
+      netcste_get_link_bandwidth;
+  surf_network_model->extension.network.get_link_latency =
+      netcste_get_link_latency;
   surf_network_model->extension.network.link_shared = link_shared;
+#ifdef HAVE_TRACING
+  surf_network_model->set_category = netcste_action_set_category;
+#endif
 
   if (!random_latency)
     random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034);
-  define_callbacks(filename);
+  netcste_define_callbacks();
   xbt_dynar_push(model_list, &surf_network_model);
 
-  update_model_description(surf_network_model_description,
-                           "Constant", surf_network_model);
-
   xbt_cfg_set_string(_surf_cfg_set, "routing", "none");
   routing_model_create(sizeof(double), NULL);
 }