Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove wrong comment
[simgrid.git] / src / surf / network_constant.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "surf_private.h"
9 #include "surf/random_mgr.h"
10 #include "xbt/dict.h"
11 #include "xbt/str.h"
12 #include "xbt/log.h"
13
14 typedef struct surf_action_network_Constant {
15   s_surf_action_t generic_action;
16   double latency;
17   double lat_init;
18   int suspended;
19 } s_surf_action_network_Constant_t, *surf_action_network_Constant_t;
20
21 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
22 static random_data_t random_latency = NULL;
23 static int host_number = 0;
24
25 static void netcste_count_hosts(void)
26 {
27   host_number++;
28 }
29
30 static void netcste_define_callbacks(const char *file)
31 {
32   surfxml_add_callback(STag_surfxml_host_cb_list, &netcste_count_hosts);
33 }
34
35 static int netcste_resource_used(void *resource_id)
36 {
37   return 0;
38 }
39
40 static int netcste_action_unref(surf_action_t action)
41 {
42   action->refcount--;
43   if (!action->refcount) {
44     xbt_swag_remove(action, action->state_set);
45     free(action);
46     return 1;
47   }
48   return 0;
49 }
50
51 static void netcste_action_cancel(surf_action_t action)
52 {
53   return;
54 }
55
56 static void netcste_action_recycle(surf_action_t action)
57 {
58   return;
59 }
60
61 static double netcste_action_get_remains(surf_action_t action)
62 {
63   return action->remains;
64 }
65
66 static double netcste_share_resources(double now)
67 {
68   surf_action_network_Constant_t action = NULL;
69   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
70   double min = -1.0;
71
72   xbt_swag_foreach(action, running_actions) {
73     if (action->latency > 0) {
74       if (min < 0)
75         min = action->latency;
76       else if (action->latency < min)
77         min = action->latency;
78     }
79   }
80
81   return min;
82 }
83
84 static void netcste_update_actions_state(double now, double delta)
85 {
86   surf_action_network_Constant_t action = NULL;
87   surf_action_network_Constant_t next_action = NULL;
88   xbt_swag_t running_actions = surf_network_model->states.running_action_set;
89
90   xbt_swag_foreach_safe(action, next_action, running_actions) {
91     if (action->latency > 0) {
92       if (action->latency > delta) {
93         double_update(&(action->latency), delta);
94       } else {
95         action->latency = 0.0;
96       }
97     }
98     double_update(&(action->generic_action.remains),
99                   action->generic_action.cost * delta / action->lat_init);
100     if (action->generic_action.max_duration != NO_MAX_DURATION)
101       double_update(&(action->generic_action.max_duration), delta);
102
103     if (action->generic_action.remains <= 0) {
104       action->generic_action.finish = surf_get_clock();
105       surf_network_model->action_state_set((surf_action_t) action,
106                                            SURF_ACTION_DONE);
107     } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
108                && (action->generic_action.max_duration <= 0)) {
109       action->generic_action.finish = surf_get_clock();
110       surf_network_model->action_state_set((surf_action_t) action,
111                                            SURF_ACTION_DONE);
112     }
113   }
114 }
115
116 static void netcste_update_resource_state(void *id,
117                                   tmgr_trace_event_t event_type,
118                                   double value, double time)
119 {
120   DIE_IMPOSSIBLE;
121 }
122
123 static surf_action_t netcste_communicate(const char *src_name, const char *dst_name,
124                                  int src, int dst, double size, double rate)
125 {
126   surf_action_network_Constant_t action = NULL;
127
128   XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
129
130   action =
131     surf_action_new(sizeof(s_surf_action_network_Constant_t), size,
132                     surf_network_model, 0);
133
134   action->suspended = 0;
135
136   action->latency = 1;          //random_generate(random_latency);
137   action->lat_init = action->latency;
138
139   if (action->latency <= 0.0) {
140     action->generic_action.state_set =
141       surf_network_model->states.done_action_set;
142     xbt_swag_insert(action, action->generic_action.state_set);
143   }
144
145   XBT_OUT;
146
147   return (surf_action_t) action;
148 }
149
150 /* returns an array of link_Constant_t */
151 static xbt_dynar_t netcste_get_route(void *src, void *dst)
152 {
153   xbt_die("Calling this function does not make any sense");
154 }
155
156 static double netcste_get_link_bandwidth(const void *link)
157 {
158   DIE_IMPOSSIBLE;
159 }
160
161 static double netcste_get_link_latency(const void *link)
162 {
163   DIE_IMPOSSIBLE;
164 }
165
166 static int link_shared(const void *link)
167 {
168   DIE_IMPOSSIBLE;
169 }
170
171 static void netcste_action_suspend(surf_action_t action)
172 {
173   ((surf_action_network_Constant_t) action)->suspended = 1;
174 }
175
176 static void netcste_action_resume(surf_action_t action)
177 {
178   if (((surf_action_network_Constant_t) action)->suspended)
179     ((surf_action_network_Constant_t) action)->suspended = 0;
180 }
181
182 static int netcste_action_is_suspended(surf_action_t action)
183 {
184   return ((surf_action_network_Constant_t) action)->suspended;
185 }
186
187 static void netcste_action_set_max_duration(surf_action_t action, double duration)
188 {
189   action->max_duration = duration;
190 }
191
192 static void netcste_finalize(void)
193 {
194   surf_model_exit(surf_network_model);
195   surf_network_model = NULL;
196 }
197
198
199
200 void surf_network_model_init_Constant(const char *filename)
201 {
202   xbt_assert(surf_network_model == NULL);
203   if (surf_network_model)
204     return;
205   surf_network_model = surf_model_init();
206
207   INFO0("Blah");
208   surf_network_model->name = "constant time network";
209   surf_network_model->action_unref = netcste_action_unref;
210   surf_network_model->action_cancel = netcste_action_cancel;
211   surf_network_model->action_recycle = netcste_action_recycle;
212   surf_network_model->get_remains = netcste_action_get_remains;
213
214   surf_network_model->model_private->resource_used = netcste_resource_used;
215   surf_network_model->model_private->share_resources = netcste_share_resources;
216   surf_network_model->model_private->update_actions_state =
217     netcste_update_actions_state;
218   surf_network_model->model_private->update_resource_state =
219     netcste_update_resource_state;
220   surf_network_model->model_private->finalize = netcste_finalize;
221
222   surf_network_model->suspend = netcste_action_suspend;
223   surf_network_model->resume = netcste_action_resume;
224   surf_network_model->is_suspended = netcste_action_is_suspended;
225   surf_cpu_model->set_max_duration = netcste_action_set_max_duration;
226
227   surf_network_model->extension.network.communicate = netcste_communicate;
228   surf_network_model->extension.network.get_link_bandwidth =
229     netcste_get_link_bandwidth;
230   surf_network_model->extension.network.get_link_latency = netcste_get_link_latency;
231   surf_network_model->extension.network.link_shared = link_shared;
232
233   if (!random_latency)
234     random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034);
235   netcste_define_callbacks(filename);
236   xbt_dynar_push(model_list, &surf_network_model);
237
238   update_model_description(surf_network_model_description,
239                            "Constant", surf_network_model);
240
241   xbt_cfg_set_string(_surf_cfg_set, "routing", "none");
242   routing_model_create(sizeof(double), NULL);
243 }