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 "surf_private.h"
12 #include "network_common.h"
14 typedef struct workstation_CLM03 {
15 s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
18 } s_workstation_CLM03_t, *workstation_CLM03_t;
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
21 "Logging specific to the SURF workstation module");
23 surf_model_t surf_workstation_model = NULL;
25 static workstation_CLM03_t workstation_new(const char *name,
28 workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
30 workstation->generic_resource.model = surf_workstation_model;
31 workstation->generic_resource.name = xbt_strdup(name);
32 workstation->cpu = cpu;
35 xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
36 workstation, surf_resource_free);
41 void create_workstations(void)
43 xbt_dict_cursor_t cursor = NULL;
47 xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
48 int *id = xbt_dict_get_or_null(used_routing->host_id,name);
49 xbt_assert1(id, "No host %s found in the platform file", name);
51 workstation_new(name, cpu, *id);
55 static int resource_used(void *resource_id)
57 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
60 static void parallel_action_cancel(surf_action_t action)
62 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
65 static int parallel_action_free(surf_action_t action)
67 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
70 static int action_unref(surf_action_t action)
72 if (action->model_type == surf_network_model)
73 return surf_network_model->action_unref(action);
74 else if (action->model_type == surf_cpu_model)
75 return surf_cpu_model->action_unref(action);
76 else if (action->model_type == surf_workstation_model)
77 return parallel_action_free(action);
83 static void action_cancel(surf_action_t action)
85 if (action->model_type == surf_network_model)
86 surf_network_model->action_cancel(action);
87 else if (action->model_type == surf_cpu_model)
88 surf_cpu_model->action_cancel(action);
89 else if (action->model_type == surf_workstation_model)
90 parallel_action_cancel(action);
96 static void ws_action_state_set(surf_action_t action,
97 e_surf_action_state_t state)
99 if (action->model_type == surf_network_model)
100 surf_network_model->action_state_set(action, state);
101 else if (action->model_type == surf_cpu_model)
102 surf_cpu_model->action_state_set(action, state);
103 else if (action->model_type == surf_workstation_model)
104 surf_action_state_set(action, state);
110 static double share_resources(double now)
115 static void update_actions_state(double now, double delta)
120 static void update_resource_state(void *id,
121 tmgr_trace_event_t event_type,
122 double value, double date)
124 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
127 static surf_action_t execute(void *workstation, double size)
129 return surf_cpu_model->extension.
130 cpu.execute(((workstation_CLM03_t) workstation)->cpu, size);
133 static surf_action_t action_sleep(void *workstation, double duration)
135 return surf_cpu_model->extension.
136 cpu.sleep(((workstation_CLM03_t) workstation)->cpu, duration);
139 static void action_suspend(surf_action_t action)
141 if (action->model_type == surf_network_model)
142 surf_network_model->suspend(action);
143 else if (action->model_type == surf_cpu_model)
144 surf_cpu_model->suspend(action);
149 static void action_resume(surf_action_t action)
151 if (action->model_type == surf_network_model)
152 surf_network_model->resume(action);
153 else if (action->model_type == surf_cpu_model)
154 surf_cpu_model->resume(action);
159 static int action_is_suspended(surf_action_t action)
161 if (action->model_type == surf_network_model)
162 return surf_network_model->is_suspended(action);
163 if (action->model_type == surf_cpu_model)
164 return surf_cpu_model->is_suspended(action);
168 static void action_set_max_duration(surf_action_t action, double duration)
170 if (action->model_type == surf_network_model)
171 surf_network_model->set_max_duration(action, duration);
172 else if (action->model_type == surf_cpu_model)
173 surf_cpu_model->set_max_duration(action, duration);
178 static void action_set_priority(surf_action_t action, double priority)
180 if (action->model_type == surf_network_model)
181 surf_network_model->set_priority(action, priority);
182 else if (action->model_type == surf_cpu_model)
183 surf_cpu_model->set_priority(action, priority);
188 static surf_action_t communicate(void *workstation_src,
189 void *workstation_dst, double size,
192 workstation_CLM03_t src = (workstation_CLM03_t) workstation_src;
193 workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst;
194 return surf_network_model->extension.
195 network.communicate(surf_resource_name(src->cpu),surf_resource_name(dst->cpu),
200 static e_surf_cpu_state_t get_state(void *workstation)
202 return surf_cpu_model->extension.
203 cpu.get_state(((workstation_CLM03_t) workstation)->cpu);
206 static double get_speed(void *workstation, double load)
208 return surf_cpu_model->extension.
209 cpu.get_speed(((workstation_CLM03_t) workstation)->cpu, load);
212 static double get_available_speed(void *workstation)
214 return surf_cpu_model->extension.
215 cpu.get_available_speed(((workstation_CLM03_t)
219 static xbt_dict_t get_properties(void *workstation)
221 return surf_cpu_model->get_properties(((workstation_CLM03_t) workstation)->
225 static surf_action_t execute_parallel_task(int workstation_nb,
226 void **workstation_list,
227 double *computation_amount,
228 double *communication_amount,
229 double amount, double rate)
231 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
235 /* returns an array of network_link_CM02_t */
236 static xbt_dynar_t get_route(void *src, void *dst)
238 workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
239 workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
240 return surf_network_model->extension.network.get_route(workstation_src->id,
241 workstation_dst->id);
244 static double get_link_bandwidth(const void *link)
246 return surf_network_model->extension.network.get_link_bandwidth(link);
249 static double get_link_latency(const void *link)
251 return surf_network_model->extension.network.get_link_latency(link);
254 static int link_shared(const void *link)
256 return surf_network_model->extension.network.get_link_latency(link);
259 static void finalize(void)
261 surf_model_exit(surf_workstation_model);
262 surf_workstation_model = NULL;
265 static void surf_workstation_model_init_internal(void)
267 surf_workstation_model = surf_model_init();
269 surf_workstation_model->name = "Workstation";
270 surf_workstation_model->action_unref = action_unref;
271 surf_workstation_model->action_cancel = action_cancel;
272 surf_workstation_model->action_state_set = ws_action_state_set;
274 surf_workstation_model->model_private->resource_used = resource_used;
275 surf_workstation_model->model_private->share_resources = share_resources;
276 surf_workstation_model->model_private->update_actions_state =
277 update_actions_state;
278 surf_workstation_model->model_private->update_resource_state =
279 update_resource_state;
280 surf_workstation_model->model_private->finalize = finalize;
282 surf_workstation_model->suspend = action_suspend;
283 surf_workstation_model->resume = action_resume;
284 surf_workstation_model->is_suspended = action_is_suspended;
285 surf_workstation_model->set_max_duration = action_set_max_duration;
286 surf_workstation_model->set_priority = action_set_priority;
288 surf_workstation_model->extension.workstation.execute = execute;
289 surf_workstation_model->extension.workstation.sleep = action_sleep;
290 surf_workstation_model->extension.workstation.get_state = get_state;
291 surf_workstation_model->extension.workstation.get_speed = get_speed;
292 surf_workstation_model->extension.workstation.get_available_speed =
295 /*manage the properties of the workstation */
296 surf_workstation_model->get_properties = get_properties;
298 surf_workstation_model->extension.workstation.communicate = communicate;
299 surf_workstation_model->extension.workstation.get_route = get_route;
300 surf_workstation_model->extension.workstation.execute_parallel_task =
301 execute_parallel_task;
302 surf_workstation_model->extension.workstation.get_link_bandwidth =
304 surf_workstation_model->extension.workstation.get_link_latency =
306 surf_workstation_model->extension.workstation.link_shared = link_shared;
309 /********************************************************************/
310 /* The model used in MSG and presented at CCGrid03 */
311 /********************************************************************/
312 /* @InProceedings{Casanova.CLM_03, */
313 /* author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
314 /* title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
315 /* booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
316 /* publisher = {"IEEE Computer Society Press"}, */
320 void surf_workstation_model_init_CLM03(const char *filename)
322 surf_workstation_model_init_internal();
323 surf_cpu_model_init_Cas01(filename);
324 surf_network_model_init_CM02(filename);
325 update_model_description(surf_workstation_model_description,
326 "CLM03", surf_workstation_model);
327 xbt_dynar_push(model_list, &surf_workstation_model);
330 void surf_workstation_model_init_compound(const char *filename)
333 xbt_assert0(surf_cpu_model, "No CPU model defined yet!");
334 xbt_assert0(surf_network_model, "No network model defined yet!");
335 surf_workstation_model_init_internal();
337 update_model_description(surf_workstation_model_description,
338 "compound", surf_workstation_model);
340 xbt_dynar_push(model_list, &surf_workstation_model);