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,
21 void *cpu, void *card)
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;
28 workstation->network_card = card;
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;
43 xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
44 nw_card = surf_model_resource_by_name(surf_network_model, name);
45 xbt_assert1(nw_card, "No corresponding card found for %s", name);
47 workstation_new(name, cpu, nw_card);
51 static int resource_used(void *resource_id)
53 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
56 static void parallel_action_cancel(surf_action_t action)
58 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
61 static int parallel_action_free(surf_action_t action)
63 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
66 static int action_unref(surf_action_t action)
68 if (action->model_type == surf_network_model)
69 return surf_network_model->action_unref(action);
70 else if (action->model_type == surf_cpu_model)
71 return surf_cpu_model->action_unref(action);
72 else if (action->model_type == surf_workstation_model)
73 return parallel_action_free(action);
79 static void action_cancel(surf_action_t action)
81 if (action->model_type == surf_network_model)
82 surf_network_model->action_cancel(action);
83 else if (action->model_type == surf_cpu_model)
84 surf_cpu_model->action_cancel(action);
85 else if (action->model_type == surf_workstation_model)
86 parallel_action_cancel(action);
92 static void ws_action_state_set(surf_action_t action,
93 e_surf_action_state_t state)
95 if (action->model_type == surf_network_model)
96 surf_network_model->action_state_set(action, state);
97 else if (action->model_type == surf_cpu_model)
98 surf_cpu_model->action_state_set(action, state);
99 else if (action->model_type == surf_workstation_model)
100 surf_action_state_set(action, state);
106 static double share_resources(double now)
111 static void update_actions_state(double now, double delta)
116 static void update_resource_state(void *id,
117 tmgr_trace_event_t event_type,
118 double value, double date)
120 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
123 static surf_action_t execute(void *workstation, double size)
125 return surf_cpu_model->extension.
126 cpu.execute(((workstation_CLM03_t) workstation)->cpu, size);
129 static surf_action_t action_sleep(void *workstation, double duration)
131 return surf_cpu_model->extension.
132 cpu.sleep(((workstation_CLM03_t) workstation)->cpu, duration);
135 static void action_suspend(surf_action_t action)
137 if (action->model_type == surf_network_model)
138 surf_network_model->suspend(action);
139 else if (action->model_type == surf_cpu_model)
140 surf_cpu_model->suspend(action);
145 static void action_resume(surf_action_t action)
147 if (action->model_type == surf_network_model)
148 surf_network_model->resume(action);
149 else if (action->model_type == surf_cpu_model)
150 surf_cpu_model->resume(action);
155 static int action_is_suspended(surf_action_t action)
157 if (action->model_type == surf_network_model)
158 return surf_network_model->is_suspended(action);
159 if (action->model_type == surf_cpu_model)
160 return surf_cpu_model->is_suspended(action);
164 static void action_set_max_duration(surf_action_t action, double duration)
166 if (action->model_type == surf_network_model)
167 surf_network_model->set_max_duration(action, duration);
168 else if (action->model_type == surf_cpu_model)
169 surf_cpu_model->set_max_duration(action, duration);
174 static void action_set_priority(surf_action_t action, double priority)
176 if (action->model_type == surf_network_model)
177 surf_network_model->set_priority(action, priority);
178 else if (action->model_type == surf_cpu_model)
179 surf_cpu_model->set_priority(action, priority);
184 static surf_action_t communicate(void *workstation_src,
185 void *workstation_dst, double size,
188 return surf_network_model->extension.
189 network.communicate(((workstation_CLM03_t) workstation_src)->network_card,
190 ((workstation_CLM03_t) workstation_dst)->network_card,
194 static e_surf_cpu_state_t get_state(void *workstation)
196 return surf_cpu_model->extension.
197 cpu.get_state(((workstation_CLM03_t) workstation)->cpu);
200 static double get_speed(void *workstation, double load)
202 return surf_cpu_model->extension.
203 cpu.get_speed(((workstation_CLM03_t) workstation)->cpu, load);
206 static double get_available_speed(void *workstation)
208 return surf_cpu_model->extension.
209 cpu.get_available_speed(((workstation_CLM03_t)
213 static xbt_dict_t get_properties(void *workstation)
215 return surf_cpu_model->get_properties(((workstation_CLM03_t) workstation)->
219 static surf_action_t execute_parallel_task(int workstation_nb,
220 void **workstation_list,
221 double *computation_amount,
222 double *communication_amount,
223 double amount, double rate)
225 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
229 /* returns an array of network_link_CM02_t */
230 static xbt_dynar_t get_route(void *src, void *dst)
232 workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
233 workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
234 return surf_network_model->extension.network.get_route(workstation_src->
240 static double get_link_bandwidth(const void *link)
242 return surf_network_model->extension.network.get_link_bandwidth(link);
245 static double get_link_latency(const void *link)
247 return surf_network_model->extension.network.get_link_latency(link);
250 static int link_shared(const void *link)
252 return surf_network_model->extension.network.get_link_latency(link);
255 static void finalize(void)
257 surf_model_exit(surf_workstation_model);
258 surf_workstation_model = NULL;
261 static void surf_workstation_model_init_internal(void)
263 surf_workstation_model = surf_model_init();
265 surf_workstation_model->name = "Workstation";
266 surf_workstation_model->action_unref = action_unref;
267 surf_workstation_model->action_cancel = action_cancel;
268 surf_workstation_model->action_state_set = ws_action_state_set;
270 surf_workstation_model->model_private->resource_used = resource_used;
271 surf_workstation_model->model_private->share_resources = share_resources;
272 surf_workstation_model->model_private->update_actions_state =
273 update_actions_state;
274 surf_workstation_model->model_private->update_resource_state =
275 update_resource_state;
276 surf_workstation_model->model_private->finalize = finalize;
278 surf_workstation_model->suspend = action_suspend;
279 surf_workstation_model->resume = action_resume;
280 surf_workstation_model->is_suspended = action_is_suspended;
281 surf_workstation_model->set_max_duration = action_set_max_duration;
282 surf_workstation_model->set_priority = action_set_priority;
284 surf_workstation_model->extension.workstation.execute = execute;
285 surf_workstation_model->extension.workstation.sleep = action_sleep;
286 surf_workstation_model->extension.workstation.get_state = get_state;
287 surf_workstation_model->extension.workstation.get_speed = get_speed;
288 surf_workstation_model->extension.workstation.get_available_speed =
291 /*manage the properties of the workstation */
292 surf_workstation_model->get_properties = get_properties;
294 surf_workstation_model->extension.workstation.communicate = communicate;
295 surf_workstation_model->extension.workstation.execute_parallel_task =
296 execute_parallel_task;
297 surf_workstation_model->extension.workstation.get_route = get_route;
298 surf_workstation_model->extension.workstation.get_link_bandwidth =
300 surf_workstation_model->extension.workstation.get_link_latency =
302 surf_workstation_model->extension.workstation.link_shared = link_shared;
305 /********************************************************************/
306 /* The model used in MSG and presented at CCGrid03 */
307 /********************************************************************/
308 /* @InProceedings{Casanova.CLM_03, */
309 /* author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
310 /* title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
311 /* booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
312 /* publisher = {"IEEE Computer Society Press"}, */
316 void surf_workstation_model_init_CLM03(const char *filename)
318 surf_workstation_model_init_internal();
319 surf_cpu_model_init_Cas01(filename);
320 surf_network_model_init_CM02(filename);
321 update_model_description(surf_workstation_model_description,
322 "CLM03", surf_workstation_model);
323 xbt_dynar_push(model_list, &surf_workstation_model);
326 void surf_workstation_model_init_compound(const char *filename)
329 xbt_assert0(surf_cpu_model, "No CPU model defined yet!");
330 xbt_assert0(surf_network_model, "No network model defined yet!");
331 surf_workstation_model_init_internal();
333 update_model_description(surf_workstation_model_description,
334 "compound", surf_workstation_model);
336 xbt_dynar_push(model_list, &surf_workstation_model);