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_workstation_model_t surf_workstation_model = NULL;
19 xbt_dict_t workstation_set = NULL;
21 static workstation_CLM03_t workstation_new(const char *name,
22 void *cpu, void *card)
24 workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
26 workstation->model = (surf_model_t) surf_workstation_model;
27 workstation->name = xbt_strdup(name);
28 workstation->cpu = cpu;
29 workstation->network_card = card;
34 static void workstation_free(void *workstation)
36 free(((workstation_CLM03_t) workstation)->name);
40 void create_workstations(void)
42 xbt_dict_cursor_t cursor = NULL;
47 xbt_dict_foreach(cpu_set, cursor, name, cpu) {
48 nw_card = xbt_dict_get_or_null(network_card_set, name);
49 xbt_assert1(nw_card, "No corresponding card found for %s", name);
51 xbt_dict_set(workstation_set, name,
52 workstation_new(name, cpu, nw_card), workstation_free);
56 static void *name_service(const char *name)
58 return xbt_dict_get_or_null(workstation_set, name);
61 static const char *get_resource_name(void *resource_id)
63 return ((workstation_CLM03_t) resource_id)->name;
66 static int resource_used(void *resource_id)
68 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
71 static void parallel_action_cancel(surf_action_t action)
73 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
76 static int parallel_action_free(surf_action_t action)
78 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
81 static void parallel_action_use(surf_action_t action)
83 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
86 static int action_free(surf_action_t action)
88 if (action->model_type == (surf_model_t) surf_network_model)
89 return surf_network_model->common_public->action_free(action);
90 else if (action->model_type == (surf_model_t) surf_cpu_model)
91 return surf_cpu_model->common_public->action_free(action);
92 else if (action->model_type == (surf_model_t) surf_workstation_model)
93 return parallel_action_free(action);
99 static void action_use(surf_action_t action)
101 if (action->model_type == (surf_model_t) surf_network_model)
102 surf_network_model->common_public->action_use(action);
103 else if (action->model_type == (surf_model_t) surf_cpu_model)
104 surf_cpu_model->common_public->action_use(action);
105 else if (action->model_type == (surf_model_t) surf_workstation_model)
106 parallel_action_use(action);
112 static void action_cancel(surf_action_t action)
114 if (action->model_type == (surf_model_t) surf_network_model)
115 surf_network_model->common_public->action_cancel(action);
116 else if (action->model_type == (surf_model_t) surf_cpu_model)
117 surf_cpu_model->common_public->action_cancel(action);
118 else if (action->model_type == (surf_model_t) surf_workstation_model)
119 parallel_action_cancel(action);
125 static void action_recycle(surf_action_t action)
131 static void action_change_state(surf_action_t action,
132 e_surf_action_state_t state)
134 if (action->model_type == (surf_model_t) surf_network_model)
135 surf_network_model->common_public->action_change_state(action, state);
136 else if (action->model_type == (surf_model_t) surf_cpu_model)
137 surf_cpu_model->common_public->action_change_state(action, state);
138 else if (action->model_type == (surf_model_t) surf_workstation_model)
139 surf_action_change_state(action, state);
145 static double share_resources(double now)
150 static void update_actions_state(double now, double delta)
155 static void update_resource_state(void *id,
156 tmgr_trace_event_t event_type,
157 double value, double date)
159 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
162 static surf_action_t execute(void *workstation, double size)
164 return surf_cpu_model->
165 extension_public->execute(((workstation_CLM03_t) workstation)->cpu, size);
168 static surf_action_t action_sleep(void *workstation, double duration)
170 return surf_cpu_model->
171 extension_public->sleep(((workstation_CLM03_t) workstation)->cpu,
175 static void action_suspend(surf_action_t action)
177 if (action->model_type == (surf_model_t) surf_network_model)
178 surf_network_model->common_public->suspend(action);
179 else if (action->model_type == (surf_model_t) surf_cpu_model)
180 surf_cpu_model->common_public->suspend(action);
185 static void action_resume(surf_action_t action)
187 if (action->model_type == (surf_model_t) surf_network_model)
188 surf_network_model->common_public->resume(action);
189 else if (action->model_type == (surf_model_t) surf_cpu_model)
190 surf_cpu_model->common_public->resume(action);
195 static int action_is_suspended(surf_action_t action)
197 if (action->model_type == (surf_model_t) surf_network_model)
198 return surf_network_model->common_public->is_suspended(action);
199 if (action->model_type == (surf_model_t) surf_cpu_model)
200 return surf_cpu_model->common_public->is_suspended(action);
204 static void action_set_max_duration(surf_action_t action, double duration)
206 if (action->model_type == (surf_model_t) surf_network_model)
207 surf_network_model->common_public->set_max_duration(action, duration);
208 else if (action->model_type == (surf_model_t) surf_cpu_model)
209 surf_cpu_model->common_public->set_max_duration(action, duration);
214 static void action_set_priority(surf_action_t action, double priority)
216 if (action->model_type == (surf_model_t) surf_network_model)
217 surf_network_model->common_public->set_priority(action, priority);
218 else if (action->model_type == (surf_model_t) surf_cpu_model)
219 surf_cpu_model->common_public->set_priority(action, priority);
224 static surf_action_t communicate(void *workstation_src,
225 void *workstation_dst, double size,
228 return surf_network_model->
229 extension_public->communicate(((workstation_CLM03_t) workstation_src)->
231 ((workstation_CLM03_t) workstation_dst)->
232 network_card, size, rate);
235 static e_surf_cpu_state_t get_state(void *workstation)
237 return surf_cpu_model->
238 extension_public->get_state(((workstation_CLM03_t) workstation)->cpu);
241 static double get_speed(void *workstation, double load)
243 return surf_cpu_model->
244 extension_public->get_speed(((workstation_CLM03_t) workstation)->cpu,
248 static double get_available_speed(void *workstation)
250 return surf_cpu_model->
251 extension_public->get_available_speed(((workstation_CLM03_t)
255 static xbt_dict_t get_properties(void *workstation)
257 return surf_cpu_model->
258 common_public->get_properties(((workstation_CLM03_t) workstation)->cpu);
261 static surf_action_t execute_parallel_task(int workstation_nb,
262 void **workstation_list,
263 double *computation_amount,
264 double *communication_amount,
265 double amount, double rate)
267 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
271 /* returns an array of network_link_CM02_t */
272 static const void **get_route(void *src, void *dst)
274 workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
275 workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
276 return surf_network_model->extension_public->get_route(workstation_src->
282 static int get_route_size(void *src, void *dst)
284 workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
285 workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
286 return surf_network_model->
287 extension_public->get_route_size(workstation_src->network_card,
288 workstation_dst->network_card);
291 static const char *get_link_name(const void *link)
293 return surf_network_model->extension_public->get_link_name(link);
296 static double get_link_bandwidth(const void *link)
298 return surf_network_model->extension_public->get_link_bandwidth(link);
301 static double get_link_latency(const void *link)
303 return surf_network_model->extension_public->get_link_latency(link);
306 static int link_shared(const void *link)
308 return surf_network_model->extension_public->get_link_latency(link);
311 static void finalize(void)
313 xbt_dict_free(&workstation_set);
314 xbt_swag_free(surf_workstation_model->common_public->
315 states.ready_action_set);
316 xbt_swag_free(surf_workstation_model->common_public->
317 states.running_action_set);
318 xbt_swag_free(surf_workstation_model->common_public->
319 states.failed_action_set);
320 xbt_swag_free(surf_workstation_model->common_public->
321 states.done_action_set);
323 free(surf_workstation_model->common_public);
324 free(surf_workstation_model->common_private);
325 free(surf_workstation_model->extension_public);
327 free(surf_workstation_model);
328 surf_workstation_model = NULL;
331 static void surf_workstation_model_init_internal(void)
333 s_surf_action_t action;
335 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
337 surf_workstation_model->common_private =
338 xbt_new0(s_surf_model_private_t, 1);
339 surf_workstation_model->common_public = xbt_new0(s_surf_model_public_t, 1);
340 /* surf_workstation_model->extension_private = xbt_new0(s_surf_workstation_model_extension_private_t,1); */
341 surf_workstation_model->extension_public =
342 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
344 surf_workstation_model->common_public->states.ready_action_set =
345 xbt_swag_new(xbt_swag_offset(action, state_hookup));
346 surf_workstation_model->common_public->states.running_action_set =
347 xbt_swag_new(xbt_swag_offset(action, state_hookup));
348 surf_workstation_model->common_public->states.failed_action_set =
349 xbt_swag_new(xbt_swag_offset(action, state_hookup));
350 surf_workstation_model->common_public->states.done_action_set =
351 xbt_swag_new(xbt_swag_offset(action, state_hookup));
353 surf_workstation_model->common_public->name_service = name_service;
354 surf_workstation_model->common_public->get_resource_name =
356 surf_workstation_model->common_public->action_get_state =
357 surf_action_get_state;
358 surf_workstation_model->common_public->action_get_start_time =
359 surf_action_get_start_time;
360 surf_workstation_model->common_public->action_get_finish_time =
361 surf_action_get_finish_time;
362 surf_workstation_model->common_public->action_free = action_free;
363 surf_workstation_model->common_public->action_use = action_use;
364 surf_workstation_model->common_public->action_cancel = action_cancel;
365 surf_workstation_model->common_public->action_recycle = action_recycle;
366 surf_workstation_model->common_public->action_change_state =
368 surf_workstation_model->common_public->action_set_data =
369 surf_action_set_data;
370 surf_workstation_model->common_public->name = "Workstation";
372 surf_workstation_model->common_private->resource_used = resource_used;
373 surf_workstation_model->common_private->share_resources = share_resources;
374 surf_workstation_model->common_private->update_actions_state =
375 update_actions_state;
376 surf_workstation_model->common_private->update_resource_state =
377 update_resource_state;
378 surf_workstation_model->common_private->finalize = finalize;
380 surf_workstation_model->common_public->suspend = action_suspend;
381 surf_workstation_model->common_public->resume = action_resume;
382 surf_workstation_model->common_public->is_suspended = action_is_suspended;
383 surf_workstation_model->common_public->set_max_duration =
384 action_set_max_duration;
385 surf_workstation_model->common_public->set_priority = action_set_priority;
387 surf_workstation_model->extension_public->execute = execute;
388 surf_workstation_model->extension_public->sleep = action_sleep;
389 surf_workstation_model->extension_public->get_state = get_state;
390 surf_workstation_model->extension_public->get_speed = get_speed;
391 surf_workstation_model->extension_public->get_available_speed =
394 /*manage the properties of the workstation */
395 surf_workstation_model->common_public->get_properties = get_properties;
397 surf_workstation_model->extension_public->communicate = communicate;
398 surf_workstation_model->extension_public->execute_parallel_task =
399 execute_parallel_task;
400 surf_workstation_model->extension_public->get_route = get_route;
401 surf_workstation_model->extension_public->get_route_size = get_route_size;
402 surf_workstation_model->extension_public->get_link_name = get_link_name;
403 surf_workstation_model->extension_public->get_link_bandwidth =
405 surf_workstation_model->extension_public->get_link_latency =
407 surf_workstation_model->extension_public->link_shared = link_shared;
409 workstation_set = xbt_dict_new();
412 /********************************************************************/
413 /* The model used in MSG and presented at CCGrid03 */
414 /********************************************************************/
415 /* @InProceedings{Casanova.CLM_03, */
416 /* author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
417 /* title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
418 /* booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
419 /* publisher = {"IEEE Computer Society Press"}, */
423 void surf_workstation_model_init_CLM03(const char *filename)
425 surf_workstation_model_init_internal();
426 surf_cpu_model_init_Cas01(filename);
427 surf_network_model_init_CM02(filename);
428 update_model_description(surf_workstation_model_description,
429 "CLM03", (surf_model_t) surf_workstation_model);
430 xbt_dynar_push(model_list, &surf_workstation_model);
433 void surf_workstation_model_init_compound(const char *filename)
436 xbt_assert0(surf_cpu_model, "No CPU model defined yet!");
437 xbt_assert0(surf_network_model, "No network model defined yet!");
438 surf_workstation_model_init_internal();
440 update_model_description(surf_workstation_model_description,
441 "compound", (surf_model_t) surf_workstation_model);
443 xbt_dynar_push(model_list, &surf_workstation_model);