3 /* Copyright (c) 2007 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. */
10 #include "surf_private.h"
11 /* extern lmm_system_t maxmin_system; */
14 SURF_WORKSTATION_RESOURCE_CPU,
15 SURF_WORKSTATION_RESOURCE_LINK,
16 } e_surf_workstation_model_type_t;
18 /**************************************/
19 /********* cpu object *****************/
20 /**************************************/
21 typedef struct cpu_L07 {
22 surf_model_t model; /* Do not move this field */
23 e_surf_workstation_model_type_t type; /* Do not move this field */
24 char *name; /* Do not move this field */
25 lmm_constraint_t constraint; /* Do not move this field */
28 tmgr_trace_event_t power_event;
29 e_surf_cpu_state_t state_current;
30 tmgr_trace_event_t state_event;
31 int id; /* cpu and network card are a single object... */
32 xbt_dict_t properties;
33 } s_cpu_L07_t, *cpu_L07_t;
35 /**************************************/
36 /*********** network object ***********/
37 /**************************************/
39 typedef struct network_link_L07 {
40 surf_model_t model; /* Do not move this field */
41 e_surf_workstation_model_type_t type; /* Do not move this field */
42 char *name; /* Do not move this field */
43 lmm_constraint_t constraint; /* Do not move this field */
45 tmgr_trace_event_t lat_event;
47 tmgr_trace_event_t bw_event;
48 e_surf_network_link_state_t state_current;
49 tmgr_trace_event_t state_event;
50 /*holds the property list that can be associated with the link*/
51 xbt_dict_t properties;
52 } s_network_link_L07_t, *network_link_L07_t;
55 typedef struct s_route_L07 {
56 network_link_L07_t *links;
58 } s_route_L07_t, *route_L07_t;
60 /**************************************/
61 /*************** actions **************/
62 /**************************************/
63 typedef struct surf_action_workstation_L07 {
64 s_surf_action_t generic_action;
65 lmm_variable_t variable;
67 cpu_L07_t *workstation_list;
68 double *computation_amount;
69 double *communication_amount;
73 } s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
76 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
78 static int nb_workstation = 0;
79 static s_route_L07_t *routing_table = NULL;
80 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
81 static network_link_L07_t loopback = NULL;
82 static xbt_dict_t parallel_task_network_link_set = NULL;
83 lmm_system_t ptask_maxmin_system = NULL;
86 static void update_action_bound(surf_action_workstation_L07_t action)
88 int workstation_nb = action->workstation_nb;
89 double lat_current = 0.0;
90 double lat_bound = -1.0;
93 for (i = 0; i < workstation_nb; i++) {
94 for (j = 0; j < workstation_nb; j++) {
95 cpu_L07_t card_src = action->workstation_list[i];
96 cpu_L07_t card_dst = action->workstation_list[j];
97 int route_size = ROUTE(card_src->id, card_dst->id).size;
98 network_link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
101 if (action->communication_amount[i * workstation_nb + j] > 0) {
102 for (k = 0; k < route_size; k++) {
103 lat += route[k]->lat_current;
105 lat_current=MAX(lat_current,lat*action->communication_amount[i * workstation_nb + j]);
109 lat_bound = SG_TCP_CTE_GAMMA / (2.0 * lat_current);
110 DEBUG2("action (%p) : lat_bound = %g", action, lat_bound);
111 if ((action->latency == 0.0) && (action->suspended == 0)) {
112 if (action->rate < 0)
113 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
116 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
117 min(action->rate,lat_bound));
121 /**************************************/
122 /******* Resource Public **********/
123 /**************************************/
125 static void *name_service(const char *name)
127 return xbt_dict_get_or_null(workstation_set, name);
130 static const char *get_resource_name(void *resource_id)
132 /* We can freely cast as a cpu_L07_t because it has the same
133 prefix as network_link_L07_t. However, only cpu_L07_t
134 will theoretically be given as an argument here. */
136 return ((cpu_L07_t) resource_id)->name;
139 /* action_get_state is inherited from the surf module */
141 static void action_use(surf_action_t action)
147 static int action_free(surf_action_t action)
151 if (!action->using) {
152 xbt_swag_remove(action, action->state_set);
153 if (((surf_action_workstation_L07_t) action)->variable)
154 lmm_variable_free(ptask_maxmin_system,
155 ((surf_action_workstation_L07_t) action)->
157 free(((surf_action_workstation_L07_t)action)->workstation_list);
158 free(((surf_action_workstation_L07_t)action)->communication_amount);
159 free(((surf_action_workstation_L07_t)action)->computation_amount);
166 static void action_cancel(surf_action_t action)
168 surf_action_change_state(action, SURF_ACTION_FAILED);
172 static void action_recycle(surf_action_t action)
178 /* action_change_state is inherited from the surf module */
179 /* action_set_data is inherited from the surf module */
181 static void action_suspend(surf_action_t action)
183 XBT_IN1("(%p))", action);
184 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
185 ((surf_action_workstation_L07_t) action)->suspended = 1;
186 lmm_update_variable_weight(ptask_maxmin_system,
187 ((surf_action_workstation_L07_t)
188 action)->variable, 0.0);
193 static void action_resume(surf_action_t action)
195 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
197 XBT_IN1("(%p)", act);
198 if (act->suspended != 2) {
199 lmm_update_variable_weight(ptask_maxmin_system,act->variable, 1.0);
205 static int action_is_suspended(surf_action_t action)
207 return (((surf_action_workstation_L07_t) action)->suspended == 1);
210 static void action_set_max_duration(surf_action_t action, double duration)
211 { /* FIXME: should inherit */
212 XBT_IN2("(%p,%g)", action, duration);
213 action->max_duration = duration;
218 static void action_set_priority(surf_action_t action, double priority)
219 { /* FIXME: should inherit */
220 XBT_IN2("(%p,%g)", action, priority);
221 action->priority = priority;
225 /**************************************/
226 /******* Resource Private **********/
227 /**************************************/
229 static int resource_used(void *resource_id)
231 /* We can freely cast as a network_link_L07_t because it has
232 the same prefix as cpu_L07_t */
233 return lmm_constraint_used(ptask_maxmin_system,
234 ((network_link_L07_t) resource_id)->
239 static double share_resources(double now)
241 s_surf_action_workstation_L07_t s_action;
242 surf_action_workstation_L07_t action = NULL;
244 xbt_swag_t running_actions =
245 surf_workstation_model->common_public->states.running_action_set;
246 double min = generic_maxmin_share_resources(running_actions,
247 xbt_swag_offset(s_action,
252 xbt_swag_foreach(action, running_actions) {
253 if (action->latency > 0) {
255 min = action->latency;
256 DEBUG3("Updating min (value) with %p (start %f): %f", action,
257 action->generic_action.start, min);
258 } else if (action->latency < min) {
259 min = action->latency;
260 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
261 action->generic_action.start, min);
266 DEBUG1("min value : %f", min);
271 static void update_actions_state(double now, double delta)
274 surf_action_workstation_L07_t action = NULL;
275 surf_action_workstation_L07_t next_action = NULL;
276 xbt_swag_t running_actions =
277 surf_workstation_model->common_public->states.running_action_set;
279 xbt_swag_foreach_safe(action, next_action, running_actions) {
281 if (action->latency > 0) {
282 if (action->latency > deltap) {
283 double_update(&(action->latency), deltap);
286 double_update(&(deltap), action->latency);
287 action->latency = 0.0;
289 if ((action->latency == 0.0) && (action->suspended == 0)) {
290 update_action_bound(action);
291 lmm_update_variable_weight(ptask_maxmin_system,action->variable, 1.0);
294 DEBUG3("Action (%p) : remains (%g) updated by %g.",
295 action, action->generic_action.remains,
296 lmm_variable_getvalue(action->variable) * delta);
297 double_update(&(action->generic_action.remains),
298 lmm_variable_getvalue(action->variable) * delta);
300 if (action->generic_action.max_duration != NO_MAX_DURATION)
301 double_update(&(action->generic_action.max_duration), delta);
303 DEBUG2("Action (%p) : remains (%g).",
304 action, action->generic_action.remains);
305 if ((action->generic_action.remains <= 0) &&
306 (lmm_get_variable_weight(action->variable) > 0)) {
307 action->generic_action.finish = surf_get_clock();
308 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
309 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
310 (action->generic_action.max_duration <= 0)) {
311 action->generic_action.finish = surf_get_clock();
312 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
314 /* Need to check that none of the model has failed */
315 lmm_constraint_t cnst = NULL;
317 void *constraint_id = NULL;
320 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
322 constraint_id = lmm_constraint_id(cnst);
324 /* if(((network_link_L07_t)constraint_id)->type== */
325 /* SURF_WORKSTATION_RESOURCE_LINK) { */
326 /* DEBUG2("Checking for link %s (%p)", */
327 /* ((network_link_L07_t)constraint_id)->name, */
328 /* ((network_link_L07_t)constraint_id)); */
330 /* if(((cpu_L07_t)constraint_id)->type== */
331 /* SURF_WORKSTATION_RESOURCE_CPU) { */
332 /* DEBUG3("Checking for cpu %s (%p) : %s", */
333 /* ((cpu_L07_t)constraint_id)->name, */
334 /* ((cpu_L07_t)constraint_id), */
335 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
338 if (((((network_link_L07_t) constraint_id)->type ==
339 SURF_WORKSTATION_RESOURCE_LINK) &&
340 (((network_link_L07_t) constraint_id)->state_current ==
341 SURF_NETWORK_LINK_OFF)) ||
342 ((((cpu_L07_t) constraint_id)->type ==
343 SURF_WORKSTATION_RESOURCE_CPU) &&
344 (((cpu_L07_t) constraint_id)->state_current ==
346 DEBUG1("Action (%p) Failed!!", action);
347 action->generic_action.finish = surf_get_clock();
348 surf_action_change_state((surf_action_t) action,
358 static void update_resource_state(void *id,
359 tmgr_trace_event_t event_type,
363 network_link_L07_t nw_link = id;
365 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
366 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
367 if (event_type == nw_link->bw_event) {
368 nw_link->bw_current = value;
369 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
370 nw_link->bw_current);
371 } else if (event_type == nw_link->lat_event) {
372 lmm_variable_t var = NULL;
373 surf_action_workstation_L07_t action = NULL;
375 nw_link->lat_current = value;
376 while (lmm_get_var_from_cnst
377 (ptask_maxmin_system, nw_link->constraint, &var)) {
380 action = lmm_variable_id(var);
381 update_action_bound(action);
384 } else if (event_type == nw_link->state_event) {
386 nw_link->state_current = SURF_NETWORK_LINK_ON;
388 nw_link->state_current = SURF_NETWORK_LINK_OFF;
390 CRITICAL0("Unknown event ! \n");
394 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
395 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
396 if (event_type == cpu->power_event) {
397 cpu->power_current = value;
398 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
400 } else if (event_type == cpu->state_event) {
402 cpu->state_current = SURF_CPU_ON;
404 cpu->state_current = SURF_CPU_OFF;
406 CRITICAL0("Unknown event ! \n");
416 static void finalize(void)
420 xbt_dict_free(&network_link_set);
421 xbt_dict_free(&workstation_set);
422 if (parallel_task_network_link_set != NULL) {
423 xbt_dict_free(¶llel_task_network_link_set);
425 xbt_swag_free(surf_workstation_model->common_public->states.
427 xbt_swag_free(surf_workstation_model->common_public->states.
429 xbt_swag_free(surf_workstation_model->common_public->states.
431 xbt_swag_free(surf_workstation_model->common_public->states.
434 free(surf_workstation_model->common_public);
435 free(surf_workstation_model->common_private);
436 free(surf_workstation_model->extension_public);
438 free(surf_workstation_model);
439 surf_workstation_model = NULL;
441 for (i = 0; i < nb_workstation; i++)
442 for (j = 0; j < nb_workstation; j++)
443 free(ROUTE(i, j).links);
445 routing_table = NULL;
448 if (ptask_maxmin_system) {
449 lmm_system_free(ptask_maxmin_system);
450 ptask_maxmin_system = NULL;
454 /**************************************/
455 /******* Resource Private **********/
456 /**************************************/
458 static e_surf_cpu_state_t resource_get_state(void *cpu)
460 return ((cpu_L07_t) cpu)->state_current;
463 static double get_speed(void *cpu, double load)
465 return load * (((cpu_L07_t) cpu)->power_scale);
468 static double get_available_speed(void *cpu)
470 return ((cpu_L07_t) cpu)->power_current;
473 static xbt_dict_t get_properties(void *cpu)
475 return ((cpu_L07_t) cpu)->properties;
479 static surf_action_t execute_parallel_task(int workstation_nb,
480 void **workstation_list,
481 double *computation_amount,
482 double *communication_amount,
483 double amount, double rate)
485 surf_action_workstation_L07_t action = NULL;
489 double latency = 0.0;
491 if (parallel_task_network_link_set == NULL) {
492 parallel_task_network_link_set =
493 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
496 xbt_dict_reset(parallel_task_network_link_set);
498 /* Compute the number of affected resources... */
499 for (i = 0; i < workstation_nb; i++) {
500 for (j = 0; j < workstation_nb; j++) {
501 cpu_L07_t card_src = workstation_list[i];
502 cpu_L07_t card_dst = workstation_list[j];
503 int route_size = ROUTE(card_src->id, card_dst->id).size;
504 network_link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
507 if (communication_amount[i * workstation_nb + j] > 0)
508 for (k = 0; k < route_size; k++) {
509 lat += route[k]->lat_current;
510 xbt_dict_set(parallel_task_network_link_set, route[k]->name,
513 latency=MAX(latency,lat);
517 nb_link = xbt_dict_length(parallel_task_network_link_set);
518 xbt_dict_reset(parallel_task_network_link_set);
520 for (i = 0; i < workstation_nb; i++)
521 if (computation_amount[i] > 0)
524 action = xbt_new0(s_surf_action_workstation_L07_t, 1);
525 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
526 action, workstation_nb, nb_link);
527 action->generic_action.using = 1;
528 action->generic_action.cost = amount;
529 action->generic_action.remains = amount;
530 action->generic_action.max_duration = NO_MAX_DURATION;
531 action->generic_action.start = surf_get_clock();
532 action->generic_action.finish = -1.0;
533 action->generic_action.model_type =
534 (surf_model_t) surf_workstation_model;
535 action->suspended = 0; /* Should be useless because of the
536 calloc but it seems to help valgrind... */
537 action->workstation_nb = workstation_nb;
538 action->workstation_list = (cpu_L07_t *)workstation_list;
539 action->computation_amount = computation_amount;
540 action->communication_amount = communication_amount;
541 action->latency = latency;
542 action->generic_action.state_set =
543 surf_workstation_model->common_public->states.running_action_set;
545 xbt_swag_insert(action, action->generic_action.state_set);
548 if (action->rate > 0)
550 lmm_variable_new(ptask_maxmin_system, action, 1.0, -1.0,
551 workstation_nb + nb_link);
554 lmm_variable_new(ptask_maxmin_system, action, 1.0, action->rate,
555 workstation_nb + nb_link);
557 if (action->latency > 0)
558 lmm_update_variable_weight(ptask_maxmin_system,action->variable,0.0);
560 for (i = 0; i < workstation_nb; i++)
561 lmm_expand(ptask_maxmin_system,
562 ((cpu_L07_t) workstation_list[i])->constraint,
563 action->variable, computation_amount[i]);
565 for (i = 0; i < workstation_nb; i++) {
566 for (j = 0; j < workstation_nb; j++) {
567 cpu_L07_t card_src = workstation_list[i];
568 cpu_L07_t card_dst = workstation_list[j];
569 int route_size = ROUTE(card_src->id, card_dst->id).size;
570 network_link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
572 if (communication_amount[i * workstation_nb + j] == 0.0)
574 for (k = 0; k < route_size; k++) {
575 lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
577 communication_amount[i * workstation_nb + j]);
582 if (nb_link + nb_host == 0) {
583 action->generic_action.cost = 1.0;
584 action->generic_action.remains = 0.0;
587 return (surf_action_t) action;
590 static surf_action_t execute(void *cpu, double size)
592 void **workstation_list = xbt_new0(void *, 1);
593 double *computation_amount = xbt_new0(double, 1);
594 double *communication_amount = xbt_new0(double, 1);
596 workstation_list[0] = cpu;
597 communication_amount[0] = 0.0;
598 computation_amount[0] = size;
600 return execute_parallel_task(1, workstation_list, computation_amount,
601 communication_amount, 1, -1);
604 static surf_action_t communicate(void *src, void *dst, double size,
607 void **workstation_list = xbt_new0(void *, 2);
608 double *computation_amount = xbt_new0(double, 2);
609 double *communication_amount = xbt_new0(double, 4);
610 surf_action_t res = NULL;
612 workstation_list[0] = src;
613 workstation_list[1] = dst;
614 communication_amount[1] = size;
616 res = execute_parallel_task(2, workstation_list,
617 computation_amount, communication_amount,
623 static surf_action_t action_sleep(void *cpu, double duration)
625 surf_action_workstation_L07_t action = NULL;
627 XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->name, duration);
629 action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
630 action->generic_action.max_duration = duration;
631 action->suspended = 2;
632 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
635 return (surf_action_t) action;
638 /* returns an array of network_link_L07_t */
639 static const void **get_route(void *src, void *dst)
641 cpu_L07_t card_src = src;
642 cpu_L07_t card_dst = dst;
643 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
645 return (const void **) route->links;
648 static int get_route_size(void *src, void *dst)
650 cpu_L07_t card_src = src;
651 cpu_L07_t card_dst = dst;
652 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
656 static const char *get_link_name(const void *link)
658 return ((network_link_L07_t) link)->name;
661 static double get_link_bandwidth(const void *link)
663 return ((network_link_L07_t) link)->bw_current;
666 static double get_link_latency(const void *link)
668 return ((network_link_L07_t) link)->lat_current;
672 static xbt_dict_t get_link_properties(void *link)
674 return ((network_link_L07_t) link)->properties;
678 /**************************************/
679 /*** Resource Creation & Destruction **/
680 /**************************************/
682 static void cpu_free(void *cpu)
684 free(((cpu_L07_t) cpu)->name);
688 static cpu_L07_t cpu_new(const char *name, double power_scale,
689 double power_initial,
690 tmgr_trace_t power_trace,
691 e_surf_cpu_state_t state_initial,
692 tmgr_trace_t state_trace,
693 xbt_dict_t cpu_properties)
695 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
697 cpu->model = (surf_model_t) surf_workstation_model;
698 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
699 cpu->name = xbt_strdup(name);
700 cpu->id = nb_workstation++;
702 cpu->power_scale = power_scale;
703 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
705 cpu->power_current = power_initial;
708 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
710 cpu->state_current = state_initial;
713 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
716 lmm_constraint_new(ptask_maxmin_system, cpu,
717 cpu->power_current * cpu->power_scale);
719 /*add the property set*/
720 cpu->properties = current_property_set;
722 xbt_dict_set(workstation_set, name, cpu, cpu_free);
726 static void create_routing_table(void)
728 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
731 static void parse_cpu_init(void)
733 double power_scale = 0.0;
734 double power_initial = 0.0;
735 tmgr_trace_t power_trace = NULL;
736 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
737 tmgr_trace_t state_trace = NULL;
739 surf_parse_get_double(&power_scale, A_surfxml_host_power);
740 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
741 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
743 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
744 (A_surfxml_host_state == A_surfxml_host_state_OFF),
746 if (A_surfxml_host_state == A_surfxml_host_state_ON)
747 state_initial = SURF_CPU_ON;
748 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
749 state_initial = SURF_CPU_OFF;
750 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
752 current_property_set = xbt_dict_new();
753 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
754 state_initial, state_trace,/*add the properties*/current_property_set);
757 static void network_link_free(void *nw_link)
759 free(((network_link_L07_t) nw_link)->name);
763 static network_link_L07_t network_link_new(char *name,
765 tmgr_trace_t bw_trace,
767 tmgr_trace_t lat_trace,
768 e_surf_network_link_state_t
770 tmgr_trace_t state_trace,
771 e_surf_network_link_sharing_policy_t
772 policy, xbt_dict_t properties)
774 network_link_L07_t nw_link = xbt_new0(s_network_link_L07_t, 1);
777 nw_link->model = (surf_model_t) surf_workstation_model;
778 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
779 nw_link->name = name;
780 nw_link->bw_current = bw_initial;
783 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
784 nw_link->state_current = state_initial;
785 nw_link->lat_current = lat_initial;
788 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
790 nw_link->state_event =
791 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
793 nw_link->constraint =
794 lmm_constraint_new(ptask_maxmin_system, nw_link,
795 nw_link->bw_current);
797 if (policy == SURF_NETWORK_LINK_FATPIPE)
798 lmm_constraint_shared(nw_link->constraint);
800 nw_link->properties = properties;
802 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
807 static void parse_network_link_init(void)
811 tmgr_trace_t bw_trace;
813 tmgr_trace_t lat_trace;
814 e_surf_network_link_state_t state_initial_link = SURF_NETWORK_LINK_ON;
815 e_surf_network_link_sharing_policy_t policy_initial_link = SURF_NETWORK_LINK_SHARED;
816 tmgr_trace_t state_trace;
818 name_link = xbt_strdup(A_surfxml_link_id);
819 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
820 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
821 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
822 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
824 xbt_assert0((A_surfxml_link_state ==
825 A_surfxml_link_state_ON)
826 || (A_surfxml_link_state ==
827 A_surfxml_link_state_OFF), "Invalid state");
828 if (A_surfxml_link_state == A_surfxml_link_state_ON)
829 state_initial_link = SURF_NETWORK_LINK_ON;
830 else if (A_surfxml_link_state ==
831 A_surfxml_link_state_OFF)
832 state_initial_link = SURF_NETWORK_LINK_OFF;
834 if (A_surfxml_link_sharing_policy ==
835 A_surfxml_link_sharing_policy_SHARED)
836 policy_initial_link = SURF_NETWORK_LINK_SHARED;
837 else if (A_surfxml_link_sharing_policy ==
838 A_surfxml_link_sharing_policy_FATPIPE)
839 policy_initial_link = SURF_NETWORK_LINK_FATPIPE;
841 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
843 current_property_set = xbt_dict_new();
844 network_link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
845 state_initial_link, state_trace, policy_initial_link, current_property_set);
849 static void route_new(int src_id, int dst_id,
850 network_link_L07_t * link_list, int nb_link)
852 route_L07_t route = &(ROUTE(src_id, dst_id));
854 route->size = nb_link;
855 route->links = link_list =
856 xbt_realloc(link_list, sizeof(network_link_L07_t) * nb_link);
860 static int link_list_capacity;
861 static network_link_L07_t *link_list = NULL;
862 static int src_id = -1;
863 static int dst_id = -1;
864 static int is_first =0;
866 static void parse_route_set_endpoints(void)
868 cpu_L07_t cpu_tmp = NULL;
870 if (!is_first) create_routing_table();
873 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
874 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
876 src_id = cpu_tmp->id;
878 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
879 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
881 dst_id = cpu_tmp->id;
884 link_list_capacity = 1;
885 link_list = xbt_new(network_link_L07_t, link_list_capacity);
888 static void parse_route_elem(void)
891 if (nb_link == link_list_capacity) {
892 link_list_capacity *= 2;
894 xbt_realloc(link_list,
895 (link_list_capacity) * sizeof(network_link_L07_t));
898 link_list[nb_link++] =
899 xbt_dict_get(network_link_set, A_surfxml_link_c_ctn_id);
902 RETHROW1("Link %s not found (dict raised this exception: %s)",
903 A_surfxml_link_c_ctn_id);
907 static void parse_route_set_route(void)
909 if (src_id != -1 && dst_id != -1)
910 route_new(src_id, dst_id, link_list, nb_link);
913 static void parse_file(const char *file)
917 /* Adding callback functions */
918 surf_parse_reset_parser();
919 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
920 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
921 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_network_link_init);
922 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
923 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
924 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
927 surf_parse_open(file);
928 xbt_assert1((!surf_parse()), "Parse error in %s", file);
931 /* Adding loopback if needed */
932 for (i = 0; i < nb_workstation; i++)
933 if (!ROUTE(i, i).size) {
935 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
936 498000000, NULL, 0.000015, NULL,
937 SURF_NETWORK_LINK_ON, NULL,
938 SURF_NETWORK_LINK_FATPIPE,NULL);
940 ROUTE(i, i).size = 1;
941 ROUTE(i, i).links = xbt_new0(network_link_L07_t, 1);
942 ROUTE(i, i).links[0] = loopback;
946 /**************************************/
947 /********* Module creation ***********/
948 /**************************************/
950 static void model_init_internal(void)
952 s_surf_action_t action;
954 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
956 surf_workstation_model->common_private =
957 xbt_new0(s_surf_model_private_t, 1);
958 surf_workstation_model->common_public =
959 xbt_new0(s_surf_model_public_t, 1);
960 surf_workstation_model->extension_public =
961 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
963 surf_workstation_model->common_public->states.ready_action_set =
964 xbt_swag_new(xbt_swag_offset(action, state_hookup));
965 surf_workstation_model->common_public->states.running_action_set =
966 xbt_swag_new(xbt_swag_offset(action, state_hookup));
967 surf_workstation_model->common_public->states.failed_action_set =
968 xbt_swag_new(xbt_swag_offset(action, state_hookup));
969 surf_workstation_model->common_public->states.done_action_set =
970 xbt_swag_new(xbt_swag_offset(action, state_hookup));
972 surf_workstation_model->common_public->name_service = name_service;
973 surf_workstation_model->common_public->get_resource_name =
975 surf_workstation_model->common_public->action_get_state =
976 surf_action_get_state;
977 surf_workstation_model->common_public->action_get_start_time =
978 surf_action_get_start_time;
979 surf_workstation_model->common_public->action_get_finish_time =
980 surf_action_get_finish_time;
981 surf_workstation_model->common_public->action_use = action_use;
982 surf_workstation_model->common_public->action_free = action_free;
983 surf_workstation_model->common_public->action_cancel = action_cancel;
984 surf_workstation_model->common_public->action_recycle =
986 surf_workstation_model->common_public->action_change_state =
987 surf_action_change_state;
988 surf_workstation_model->common_public->action_set_data =
989 surf_action_set_data;
990 surf_workstation_model->common_public->suspend = action_suspend;
991 surf_workstation_model->common_public->resume = action_resume;
992 surf_workstation_model->common_public->is_suspended =
994 surf_workstation_model->common_public->set_max_duration =
995 action_set_max_duration;
996 surf_workstation_model->common_public->set_priority =
998 surf_workstation_model->common_public->name = "Workstation ptask_L07";
1000 surf_workstation_model->common_private->resource_used = resource_used;
1001 surf_workstation_model->common_private->share_resources =
1003 surf_workstation_model->common_private->update_actions_state =
1004 update_actions_state;
1005 surf_workstation_model->common_private->update_resource_state =
1006 update_resource_state;
1007 surf_workstation_model->common_private->finalize = finalize;
1009 surf_workstation_model->extension_public->execute = execute;
1010 surf_workstation_model->extension_public->sleep = action_sleep;
1011 surf_workstation_model->extension_public->get_state =
1013 surf_workstation_model->extension_public->get_speed = get_speed;
1014 surf_workstation_model->extension_public->get_available_speed =
1015 get_available_speed;
1016 surf_workstation_model->extension_public->communicate = communicate;
1017 surf_workstation_model->extension_public->execute_parallel_task =
1018 execute_parallel_task;
1019 surf_workstation_model->extension_public->get_route = get_route;
1020 surf_workstation_model->extension_public->get_route_size =
1022 surf_workstation_model->extension_public->get_link_name =
1024 surf_workstation_model->extension_public->get_link_bandwidth =
1026 surf_workstation_model->extension_public->get_link_latency =
1029 surf_workstation_model->common_public->get_link_properties = get_link_properties;
1030 surf_workstation_model->common_public->get_cpu_properties = get_properties;
1032 workstation_set = xbt_dict_new();
1033 network_link_set = xbt_dict_new();
1035 if (!ptask_maxmin_system)
1036 ptask_maxmin_system = lmm_system_new();
1039 /**************************************/
1040 /*************** Generic **************/
1041 /**************************************/
1042 void surf_workstation_model_init_ptask_L07(const char *filename)
1044 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1045 xbt_assert0(!surf_network_model,
1046 "network model type already defined");
1047 model_init_internal();
1048 parse_file(filename);
1050 update_model_description(surf_workstation_model_description,
1051 surf_workstation_model_description_size,
1053 (surf_model_t) surf_workstation_model);
1054 xbt_dynar_push(model_list, &surf_workstation_model);