3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
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. */
11 #include "workstation_private.h"
12 #include "cpu_private.h"
13 #include "network_common.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
16 "Logging specific to the SURF workstation module");
18 surf_model_t surf_workstation_model = NULL;
20 static workstation_CLM03_t workstation_new(const char *name,
23 workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
25 workstation->generic_resource.model = surf_workstation_model;
26 workstation->generic_resource.name = xbt_strdup(name);
27 workstation->cpu = cpu;
30 xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
31 workstation, surf_resource_free);
36 void create_workstations(void)
38 xbt_dict_cursor_t cursor = NULL;
42 xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
43 int *id = xbt_dict_get_or_null(used_routing->host_id,name);
44 xbt_assert1(id, "No host %s found in the platform file", name);
46 workstation_new(name, cpu, *id);
50 static int resource_used(void *resource_id)
52 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
55 static void parallel_action_cancel(surf_action_t action)
57 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
60 static int parallel_action_free(surf_action_t action)
62 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
65 static int action_unref(surf_action_t action)
67 if (action->model_type == surf_network_model)
68 return surf_network_model->action_unref(action);
69 else if (action->model_type == surf_cpu_model)
70 return surf_cpu_model->action_unref(action);
71 else if (action->model_type == surf_workstation_model)
72 return parallel_action_free(action);
78 static void action_cancel(surf_action_t action)
80 if (action->model_type == surf_network_model)
81 surf_network_model->action_cancel(action);
82 else if (action->model_type == surf_cpu_model)
83 surf_cpu_model->action_cancel(action);
84 else if (action->model_type == surf_workstation_model)
85 parallel_action_cancel(action);
91 static void ws_action_state_set(surf_action_t action,
92 e_surf_action_state_t state)
94 if (action->model_type == surf_network_model)
95 surf_network_model->action_state_set(action, state);
96 else if (action->model_type == surf_cpu_model)
97 surf_cpu_model->action_state_set(action, state);
98 else if (action->model_type == surf_workstation_model)
99 surf_action_state_set(action, state);
105 static double share_resources(double now)
110 static void update_actions_state(double now, double delta)
115 static void update_resource_state(void *id,
116 tmgr_trace_event_t event_type,
117 double value, double date)
119 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
122 static surf_action_t execute(void *workstation, double size)
124 return surf_cpu_model->extension.
125 cpu.execute(((workstation_CLM03_t) workstation)->cpu, size);
128 static surf_action_t action_sleep(void *workstation, double duration)
130 return surf_cpu_model->extension.
131 cpu.sleep(((workstation_CLM03_t) workstation)->cpu, duration);
134 static void action_suspend(surf_action_t action)
136 if (action->model_type == surf_network_model)
137 surf_network_model->suspend(action);
138 else if (action->model_type == surf_cpu_model)
139 surf_cpu_model->suspend(action);
144 static void action_resume(surf_action_t action)
146 if (action->model_type == surf_network_model)
147 surf_network_model->resume(action);
148 else if (action->model_type == surf_cpu_model)
149 surf_cpu_model->resume(action);
154 static int action_is_suspended(surf_action_t action)
156 if (action->model_type == surf_network_model)
157 return surf_network_model->is_suspended(action);
158 if (action->model_type == surf_cpu_model)
159 return surf_cpu_model->is_suspended(action);
163 static void action_set_max_duration(surf_action_t action, double duration)
165 if (action->model_type == surf_network_model)
166 surf_network_model->set_max_duration(action, duration);
167 else if (action->model_type == surf_cpu_model)
168 surf_cpu_model->set_max_duration(action, duration);
173 static void action_set_priority(surf_action_t action, double priority)
175 if (action->model_type == surf_network_model)
176 surf_network_model->set_priority(action, priority);
177 else if (action->model_type == surf_cpu_model)
178 surf_cpu_model->set_priority(action, priority);
183 static surf_action_t communicate(void *workstation_src,
184 void *workstation_dst, double size,
187 workstation_CLM03_t src = (workstation_CLM03_t) workstation_src;
188 workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst;
189 return surf_network_model->extension.
190 network.communicate(surf_resource_name(src->cpu),surf_resource_name(dst->cpu),
195 static e_surf_cpu_state_t get_state(void *workstation)
197 return surf_cpu_model->extension.
198 cpu.get_state(((workstation_CLM03_t) workstation)->cpu);
201 static double get_speed(void *workstation, double load)
203 return surf_cpu_model->extension.
204 cpu.get_speed(((workstation_CLM03_t) workstation)->cpu, load);
207 static double get_available_speed(void *workstation)
209 return surf_cpu_model->extension.
210 cpu.get_available_speed(((workstation_CLM03_t)
214 static xbt_dict_t get_properties(void *workstation)
216 return surf_cpu_model->get_properties(((workstation_CLM03_t) workstation)->
220 static surf_action_t execute_parallel_task(int workstation_nb,
221 void **workstation_list,
222 double *computation_amount,
223 double *communication_amount,
224 double amount, double rate)
226 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
230 /* returns an array of network_link_CM02_t */
231 static xbt_dynar_t get_route(void *src, void *dst)
233 workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
234 workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
235 return surf_network_model->extension.network.get_route(workstation_src->id,
236 workstation_dst->id);
239 static double get_link_bandwidth(const void *link)
241 return surf_network_model->extension.network.get_link_bandwidth(link);
244 static double get_link_latency(const void *link)
246 return surf_network_model->extension.network.get_link_latency(link);
249 static int link_shared(const void *link)
251 return surf_network_model->extension.network.get_link_latency(link);
254 static void finalize(void)
256 surf_model_exit(surf_workstation_model);
257 surf_workstation_model = NULL;
260 static void surf_workstation_model_init_internal(void)
262 surf_workstation_model = surf_model_init();
264 surf_workstation_model->name = "Workstation";
265 surf_workstation_model->action_unref = action_unref;
266 surf_workstation_model->action_cancel = action_cancel;
267 surf_workstation_model->action_state_set = ws_action_state_set;
269 surf_workstation_model->model_private->resource_used = resource_used;
270 surf_workstation_model->model_private->share_resources = share_resources;
271 surf_workstation_model->model_private->update_actions_state =
272 update_actions_state;
273 surf_workstation_model->model_private->update_resource_state =
274 update_resource_state;
275 surf_workstation_model->model_private->finalize = finalize;
277 surf_workstation_model->suspend = action_suspend;
278 surf_workstation_model->resume = action_resume;
279 surf_workstation_model->is_suspended = action_is_suspended;
280 surf_workstation_model->set_max_duration = action_set_max_duration;
281 surf_workstation_model->set_priority = action_set_priority;
283 surf_workstation_model->extension.workstation.execute = execute;
284 surf_workstation_model->extension.workstation.sleep = action_sleep;
285 surf_workstation_model->extension.workstation.get_state = get_state;
286 surf_workstation_model->extension.workstation.get_speed = get_speed;
287 surf_workstation_model->extension.workstation.get_available_speed =
290 /*manage the properties of the workstation */
291 surf_workstation_model->get_properties = get_properties;
293 surf_workstation_model->extension.workstation.communicate = communicate;
294 surf_workstation_model->extension.workstation.get_route = get_route;
295 surf_workstation_model->extension.workstation.execute_parallel_task =
296 execute_parallel_task;
297 surf_workstation_model->extension.workstation.get_link_bandwidth =
299 surf_workstation_model->extension.workstation.get_link_latency =
301 surf_workstation_model->extension.workstation.link_shared = link_shared;
304 /********************************************************************/
305 /* The model used in MSG and presented at CCGrid03 */
306 /********************************************************************/
307 /* @InProceedings{Casanova.CLM_03, */
308 /* author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
309 /* title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
310 /* booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
311 /* publisher = {"IEEE Computer Society Press"}, */
315 void surf_workstation_model_init_CLM03(const char *filename)
317 surf_workstation_model_init_internal();
318 surf_cpu_model_init_Cas01(filename);
319 surf_network_model_init_CM02(filename);
320 update_model_description(surf_workstation_model_description,
321 "CLM03", surf_workstation_model);
322 xbt_dynar_push(model_list, &surf_workstation_model);
325 void surf_workstation_model_init_compound(const char *filename)
328 xbt_assert0(surf_cpu_model, "No CPU model defined yet!");
329 xbt_assert0(surf_network_model, "No network model defined yet!");
330 surf_workstation_model_init_internal();
332 update_model_description(surf_workstation_model_description,
333 "compound", surf_workstation_model);
335 xbt_dynar_push(model_list, &surf_workstation_model);