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. */
11 #include "surf_private.h"
12 /* extern lmm_system_t maxmin_system; */
15 SURF_WORKSTATION_RESOURCE_CPU,
16 SURF_WORKSTATION_RESOURCE_LINK,
17 } e_surf_workstation_model_type_t;
19 /**************************************/
20 /********* cpu object *****************/
21 /**************************************/
22 typedef struct cpu_L07 {
23 surf_model_t model; /* Do not move this field: must match model_obj_t */
24 xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
25 e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
26 char *name; /* Do not move this field: must match link_L07_t */
27 lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
30 tmgr_trace_event_t power_event;
31 e_surf_cpu_state_t state_current;
32 tmgr_trace_event_t state_event;
33 int id; /* cpu and network card are a single object... */
34 } s_cpu_L07_t, *cpu_L07_t;
36 /**************************************/
37 /*********** network object ***********/
38 /**************************************/
40 typedef struct link_L07 {
41 surf_model_t model; /* Do not move this field: must match model_obj_t */
42 xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
43 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
44 char *name; /* Do not move this field: must match cpu_L07_t */
45 lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
47 tmgr_trace_event_t lat_event;
49 tmgr_trace_event_t bw_event;
50 e_surf_link_state_t state_current;
51 tmgr_trace_event_t state_event;
52 } s_link_L07_t, *link_L07_t;
55 typedef struct s_route_L07 {
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 link_L07_t loopback = NULL;
82 static xbt_dict_t parallel_task_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 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 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;
138 static xbt_dict_t get_properties(void *r) {
139 /* We can freely cast as a cpu_L07_t since it has the same prefix than link_L07_t */
140 return ((cpu_L07_t) r)->properties;
143 /* action_get_state is inherited from the surf module */
145 static void action_use(surf_action_t action)
151 static int action_free(surf_action_t action)
155 if (!action->using) {
156 xbt_swag_remove(action, action->state_set);
157 if (((surf_action_workstation_L07_t) action)->variable)
158 lmm_variable_free(ptask_maxmin_system,
159 ((surf_action_workstation_L07_t) action)->
161 free(((surf_action_workstation_L07_t)action)->workstation_list);
162 free(((surf_action_workstation_L07_t)action)->communication_amount);
163 free(((surf_action_workstation_L07_t)action)->computation_amount);
170 static void action_cancel(surf_action_t action)
172 surf_action_change_state(action, SURF_ACTION_FAILED);
176 static void action_recycle(surf_action_t action)
182 /* action_change_state is inherited from the surf module */
183 /* action_set_data is inherited from the surf module */
185 static void action_suspend(surf_action_t action)
187 XBT_IN1("(%p))", action);
188 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
189 ((surf_action_workstation_L07_t) action)->suspended = 1;
190 lmm_update_variable_weight(ptask_maxmin_system,
191 ((surf_action_workstation_L07_t)
192 action)->variable, 0.0);
197 static void action_resume(surf_action_t action)
199 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
201 XBT_IN1("(%p)", act);
202 if (act->suspended != 2) {
203 lmm_update_variable_weight(ptask_maxmin_system,act->variable, 1.0);
209 static int action_is_suspended(surf_action_t action)
211 return (((surf_action_workstation_L07_t) action)->suspended == 1);
214 static void action_set_max_duration(surf_action_t action, double duration)
215 { /* FIXME: should inherit */
216 XBT_IN2("(%p,%g)", action, duration);
217 action->max_duration = duration;
222 static void action_set_priority(surf_action_t action, double priority)
223 { /* FIXME: should inherit */
224 XBT_IN2("(%p,%g)", action, priority);
225 action->priority = priority;
229 /**************************************/
230 /******* Resource Private **********/
231 /**************************************/
233 static int resource_used(void *resource_id)
235 /* We can freely cast as a link_L07_t because it has
236 the same prefix as cpu_L07_t */
237 return lmm_constraint_used(ptask_maxmin_system,
238 ((link_L07_t) resource_id)->
243 static double share_resources(double now)
245 s_surf_action_workstation_L07_t s_action;
246 surf_action_workstation_L07_t action = NULL;
248 xbt_swag_t running_actions =
249 surf_workstation_model->common_public->states.running_action_set;
250 double min = generic_maxmin_share_resources(running_actions,
251 xbt_swag_offset(s_action,
256 xbt_swag_foreach(action, running_actions) {
257 if (action->latency > 0) {
259 min = action->latency;
260 DEBUG3("Updating min (value) with %p (start %f): %f", action,
261 action->generic_action.start, min);
262 } else if (action->latency < min) {
263 min = action->latency;
264 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
265 action->generic_action.start, min);
270 DEBUG1("min value : %f", min);
275 static void update_actions_state(double now, double delta)
278 surf_action_workstation_L07_t action = NULL;
279 surf_action_workstation_L07_t next_action = NULL;
280 xbt_swag_t running_actions =
281 surf_workstation_model->common_public->states.running_action_set;
283 xbt_swag_foreach_safe(action, next_action, running_actions) {
285 if (action->latency > 0) {
286 if (action->latency > deltap) {
287 double_update(&(action->latency), deltap);
290 double_update(&(deltap), action->latency);
291 action->latency = 0.0;
293 if ((action->latency == 0.0) && (action->suspended == 0)) {
294 update_action_bound(action);
295 lmm_update_variable_weight(ptask_maxmin_system,action->variable, 1.0);
298 DEBUG3("Action (%p) : remains (%g) updated by %g.",
299 action, action->generic_action.remains,
300 lmm_variable_getvalue(action->variable) * delta);
301 double_update(&(action->generic_action.remains),
302 lmm_variable_getvalue(action->variable) * delta);
304 if (action->generic_action.max_duration != NO_MAX_DURATION)
305 double_update(&(action->generic_action.max_duration), delta);
307 DEBUG2("Action (%p) : remains (%g).",
308 action, action->generic_action.remains);
309 if ((action->generic_action.remains <= 0) &&
310 (lmm_get_variable_weight(action->variable) > 0)) {
311 action->generic_action.finish = surf_get_clock();
312 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
313 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
314 (action->generic_action.max_duration <= 0)) {
315 action->generic_action.finish = surf_get_clock();
316 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
318 /* Need to check that none of the model has failed */
319 lmm_constraint_t cnst = NULL;
321 void *constraint_id = NULL;
324 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
326 constraint_id = lmm_constraint_id(cnst);
328 /* if(((link_L07_t)constraint_id)->type== */
329 /* SURF_WORKSTATION_RESOURCE_LINK) { */
330 /* DEBUG2("Checking for link %s (%p)", */
331 /* ((link_L07_t)constraint_id)->name, */
332 /* ((link_L07_t)constraint_id)); */
334 /* if(((cpu_L07_t)constraint_id)->type== */
335 /* SURF_WORKSTATION_RESOURCE_CPU) { */
336 /* DEBUG3("Checking for cpu %s (%p) : %s", */
337 /* ((cpu_L07_t)constraint_id)->name, */
338 /* ((cpu_L07_t)constraint_id), */
339 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
342 if (((((link_L07_t) constraint_id)->type ==
343 SURF_WORKSTATION_RESOURCE_LINK) &&
344 (((link_L07_t) constraint_id)->state_current ==
346 ((((cpu_L07_t) constraint_id)->type ==
347 SURF_WORKSTATION_RESOURCE_CPU) &&
348 (((cpu_L07_t) constraint_id)->state_current ==
350 DEBUG1("Action (%p) Failed!!", action);
351 action->generic_action.finish = surf_get_clock();
352 surf_action_change_state((surf_action_t) action,
362 static void update_resource_state(void *id,
363 tmgr_trace_event_t event_type,
364 double value, double date)
367 link_L07_t nw_link = id;
369 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
370 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
371 if (event_type == nw_link->bw_event) {
372 nw_link->bw_current = value;
373 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
374 nw_link->bw_current);
375 } else if (event_type == nw_link->lat_event) {
376 lmm_variable_t var = NULL;
377 surf_action_workstation_L07_t action = NULL;
378 lmm_element_t elem = NULL;
380 nw_link->lat_current = value;
381 while ((var = lmm_get_var_from_cnst
382 (ptask_maxmin_system, nw_link->constraint, &elem))) {
385 action = lmm_variable_id(var);
386 update_action_bound(action);
389 } else if (event_type == nw_link->state_event) {
391 nw_link->state_current = SURF_LINK_ON;
393 nw_link->state_current = SURF_LINK_OFF;
395 CRITICAL0("Unknown event ! \n");
399 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
400 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
401 if (event_type == cpu->power_event) {
402 cpu->power_current = value;
403 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
404 cpu->power_current * cpu->power_scale);
405 } else if (event_type == cpu->state_event) {
407 cpu->state_current = SURF_CPU_ON;
409 cpu->state_current = SURF_CPU_OFF;
411 CRITICAL0("Unknown event ! \n");
421 static void finalize(void)
425 xbt_dict_free(&link_set);
426 xbt_dict_free(&workstation_set);
427 if (parallel_task_link_set != NULL) {
428 xbt_dict_free(¶llel_task_link_set);
430 xbt_swag_free(surf_workstation_model->common_public->states.
432 xbt_swag_free(surf_workstation_model->common_public->states.
434 xbt_swag_free(surf_workstation_model->common_public->states.
436 xbt_swag_free(surf_workstation_model->common_public->states.
439 free(surf_workstation_model->common_public);
440 free(surf_workstation_model->common_private);
441 free(surf_workstation_model->extension_public);
443 free(surf_workstation_model);
444 surf_workstation_model = NULL;
446 for (i = 0; i < nb_workstation; i++)
447 for (j = 0; j < nb_workstation; j++)
448 free(ROUTE(i, j).links);
450 routing_table = NULL;
453 if (ptask_maxmin_system) {
454 lmm_system_free(ptask_maxmin_system);
455 ptask_maxmin_system = NULL;
459 /**************************************/
460 /******* Resource Private **********/
461 /**************************************/
463 static e_surf_cpu_state_t resource_get_state(void *cpu)
465 return ((cpu_L07_t) cpu)->state_current;
468 static double get_speed(void *cpu, double load)
470 return load * (((cpu_L07_t) cpu)->power_scale);
473 static double get_available_speed(void *cpu)
475 return ((cpu_L07_t) cpu)->power_current;
478 static surf_action_t execute_parallel_task(int workstation_nb,
479 void **workstation_list,
480 double *computation_amount,
481 double *communication_amount,
482 double amount, double rate)
484 surf_action_workstation_L07_t action = NULL;
488 double latency = 0.0;
490 if (parallel_task_link_set == NULL)
491 parallel_task_link_set = xbt_dict_new();
493 xbt_dict_reset(parallel_task_link_set);
495 /* Compute the number of affected resources... */
496 for (i = 0; i < workstation_nb; i++) {
497 for (j = 0; j < workstation_nb; j++) {
498 cpu_L07_t card_src = workstation_list[i];
499 cpu_L07_t card_dst = workstation_list[j];
500 int route_size = ROUTE(card_src->id, card_dst->id).size;
501 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
504 if (communication_amount[i * workstation_nb + j] > 0)
505 for (k = 0; k < route_size; k++) {
506 lat += route[k]->lat_current;
507 xbt_dict_set(parallel_task_link_set, route[k]->name,
510 latency=MAX(latency,lat);
514 nb_link = xbt_dict_length(parallel_task_link_set);
515 xbt_dict_reset(parallel_task_link_set);
517 for (i = 0; i < workstation_nb; i++)
518 if (computation_amount[i] > 0)
521 action = xbt_new0(s_surf_action_workstation_L07_t, 1);
522 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
523 action, workstation_nb, nb_link);
524 action->generic_action.using = 1;
525 action->generic_action.cost = amount;
526 action->generic_action.remains = amount;
527 action->generic_action.max_duration = NO_MAX_DURATION;
528 action->generic_action.start = surf_get_clock();
529 action->generic_action.finish = -1.0;
530 action->generic_action.model_type =
531 (surf_model_t) surf_workstation_model;
532 action->suspended = 0; /* Should be useless because of the
533 calloc but it seems to help valgrind... */
534 action->workstation_nb = workstation_nb;
535 action->workstation_list = (cpu_L07_t *)workstation_list;
536 action->computation_amount = computation_amount;
537 action->communication_amount = communication_amount;
538 action->latency = latency;
539 action->generic_action.state_set =
540 surf_workstation_model->common_public->states.running_action_set;
542 xbt_swag_insert(action, action->generic_action.state_set);
545 if (action->rate > 0)
547 lmm_variable_new(ptask_maxmin_system, action, 1.0, -1.0,
548 workstation_nb + nb_link);
551 lmm_variable_new(ptask_maxmin_system, action, 1.0, action->rate,
552 workstation_nb + nb_link);
554 if (action->latency > 0)
555 lmm_update_variable_weight(ptask_maxmin_system,action->variable,0.0);
557 for (i = 0; i < workstation_nb; i++)
558 lmm_expand(ptask_maxmin_system,
559 ((cpu_L07_t) workstation_list[i])->constraint,
560 action->variable, computation_amount[i]);
562 for (i = 0; i < workstation_nb; i++) {
563 for (j = 0; j < workstation_nb; j++) {
564 cpu_L07_t card_src = workstation_list[i];
565 cpu_L07_t card_dst = workstation_list[j];
566 int route_size = ROUTE(card_src->id, card_dst->id).size;
567 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
569 if (communication_amount[i * workstation_nb + j] == 0.0)
571 for (k = 0; k < route_size; k++) {
572 lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
574 communication_amount[i * workstation_nb + j]);
579 if (nb_link + nb_host == 0) {
580 action->generic_action.cost = 1.0;
581 action->generic_action.remains = 0.0;
584 return (surf_action_t) action;
587 static surf_action_t execute(void *cpu, double size)
589 void **workstation_list = xbt_new0(void *, 1);
590 double *computation_amount = xbt_new0(double, 1);
591 double *communication_amount = xbt_new0(double, 1);
593 workstation_list[0] = cpu;
594 communication_amount[0] = 0.0;
595 computation_amount[0] = size;
597 return execute_parallel_task(1, workstation_list, computation_amount,
598 communication_amount, 1, -1);
601 static surf_action_t communicate(void *src, void *dst, double size,
604 void **workstation_list = xbt_new0(void *, 2);
605 double *computation_amount = xbt_new0(double, 2);
606 double *communication_amount = xbt_new0(double, 4);
607 surf_action_t res = NULL;
609 workstation_list[0] = src;
610 workstation_list[1] = dst;
611 communication_amount[1] = size;
613 res = execute_parallel_task(2, workstation_list,
614 computation_amount, communication_amount,
620 static surf_action_t action_sleep(void *cpu, double duration)
622 surf_action_workstation_L07_t action = NULL;
624 XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->name, duration);
626 action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
627 action->generic_action.max_duration = duration;
628 action->suspended = 2;
629 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
632 return (surf_action_t) action;
635 /* returns an array of link_L07_t */
636 static const void **get_route(void *src, void *dst)
638 cpu_L07_t card_src = src;
639 cpu_L07_t card_dst = dst;
640 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
642 return (const void **) route->links;
645 static int get_route_size(void *src, void *dst)
647 cpu_L07_t card_src = src;
648 cpu_L07_t card_dst = dst;
649 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
653 static const char *get_link_name(const void *link)
655 return ((link_L07_t) link)->name;
658 static double get_link_bandwidth(const void *link)
660 return ((link_L07_t) link)->bw_current;
663 static double get_link_latency(const void *link)
665 return ((link_L07_t) link)->lat_current;
668 static int link_shared(const void *link)
670 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
673 /**************************************/
674 /*** Resource Creation & Destruction **/
675 /**************************************/
677 static void cpu_free(void *cpu)
679 free(((cpu_L07_t) cpu)->name);
680 xbt_dict_free(&(((cpu_L07_t)cpu)->properties));
684 static cpu_L07_t cpu_new(const char *name, double power_scale,
685 double power_initial,
686 tmgr_trace_t power_trace,
687 e_surf_cpu_state_t state_initial,
688 tmgr_trace_t state_trace,
689 xbt_dict_t cpu_properties)
691 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
692 xbt_assert1(! xbt_dict_get_or_null(workstation_set, name),
693 "Host '%s' declared several times in the platform file.",name);
695 cpu->model = (surf_model_t) surf_workstation_model;
696 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
697 cpu->name = xbt_strdup(name);
698 cpu->id = nb_workstation++;
700 cpu->power_scale = power_scale;
701 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
703 cpu->power_current = power_initial;
706 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
708 cpu->state_current = state_initial;
711 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
714 lmm_constraint_new(ptask_maxmin_system, cpu,
715 cpu->power_current * cpu->power_scale);
717 /*add the property set*/
718 cpu->properties = current_property_set;
720 xbt_dict_set(workstation_set, name, cpu, cpu_free);
725 static void create_routing_table(void)
727 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
730 static void parse_cpu_init(void)
732 double power_scale = 0.0;
733 double power_initial = 0.0;
734 tmgr_trace_t power_trace = NULL;
735 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
736 tmgr_trace_t state_trace = NULL;
738 power_scale = get_cpu_power(A_surfxml_host_power);
739 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
740 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
742 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
743 (A_surfxml_host_state == A_surfxml_host_state_OFF),
745 if (A_surfxml_host_state == A_surfxml_host_state_ON)
746 state_initial = SURF_CPU_ON;
747 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
748 state_initial = SURF_CPU_OFF;
749 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
751 current_property_set = xbt_dict_new();
752 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
753 state_initial, state_trace,current_property_set);
756 static void link_free(void *nw_link)
758 free(((link_L07_t) nw_link)->name);
759 xbt_dict_free(&(((link_L07_t)nw_link)->properties));
763 static link_L07_t link_new(char *name,
765 tmgr_trace_t bw_trace,
767 tmgr_trace_t lat_trace,
770 tmgr_trace_t state_trace,
771 e_surf_link_sharing_policy_t
772 policy, xbt_dict_t properties)
774 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
775 xbt_assert1(! xbt_dict_get_or_null(link_set, name),
776 "Link '%s' declared several times in the platform file.",name);
778 nw_link->model = (surf_model_t) surf_workstation_model;
779 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
780 nw_link->name = name;
781 nw_link->bw_current = bw_initial;
784 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
785 nw_link->state_current = state_initial;
786 nw_link->lat_current = lat_initial;
789 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
791 nw_link->state_event =
792 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
794 nw_link->constraint =
795 lmm_constraint_new(ptask_maxmin_system, nw_link,
796 nw_link->bw_current);
798 if (policy == SURF_LINK_FATPIPE)
799 lmm_constraint_shared(nw_link->constraint);
801 nw_link->properties = properties;
803 xbt_dict_set(link_set, name, nw_link, link_free);
808 static void parse_link_init(void)
812 tmgr_trace_t bw_trace;
814 tmgr_trace_t lat_trace;
815 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
816 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
817 tmgr_trace_t state_trace;
819 name_link = xbt_strdup(A_surfxml_link_id);
820 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
821 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
822 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
823 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
825 xbt_assert0((A_surfxml_link_state ==
826 A_surfxml_link_state_ON)
827 || (A_surfxml_link_state ==
828 A_surfxml_link_state_OFF), "Invalid state");
829 if (A_surfxml_link_state == A_surfxml_link_state_ON)
830 state_initial_link = SURF_LINK_ON;
831 else if (A_surfxml_link_state ==
832 A_surfxml_link_state_OFF)
833 state_initial_link = SURF_LINK_OFF;
835 if (A_surfxml_link_sharing_policy ==
836 A_surfxml_link_sharing_policy_SHARED)
837 policy_initial_link = SURF_LINK_SHARED;
838 else if (A_surfxml_link_sharing_policy ==
839 A_surfxml_link_sharing_policy_FATPIPE)
840 policy_initial_link = SURF_LINK_FATPIPE;
842 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
844 current_property_set = xbt_dict_new();
845 link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
846 state_initial_link, state_trace, policy_initial_link, current_property_set);
849 static void route_new(int src_id, int dst_id,
850 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 = xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
859 static int src_id = -1;
860 static int dst_id = -1;
862 static void parse_route_set_endpoints(void)
864 cpu_L07_t cpu_tmp = NULL;
866 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
867 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
869 src_id = cpu_tmp->id;
871 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
872 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
874 dst_id = cpu_tmp->id;
876 route_action = A_surfxml_route_action;
879 static void parse_route_set_route(void)
882 if (src_id != -1 && dst_id != -1) {
883 name = bprintf("%x#%x",src_id, dst_id);
884 manage_route(route_table, name, route_action, 0);
889 static void add_loopback(void)
893 /* Adding loopback if needed */
894 for (i = 0; i < nb_workstation; i++)
895 if (!ROUTE(i, i).size) {
897 loopback = link_new(xbt_strdup("__MSG_loopback__"),
898 498000000, NULL, 0.000015, NULL,
900 SURF_LINK_FATPIPE,NULL);
902 ROUTE(i, i).size = 1;
903 ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
904 ROUTE(i, i).links[0] = loopback;
908 static void add_route(void)
912 unsigned int cpt = 0;
913 int link_list_capacity = 0;
914 link_L07_t *link_list = NULL;
915 xbt_dict_cursor_t cursor = NULL;
916 char *key,*data, *end;
917 const char *sep = "#";
918 xbt_dynar_t links, keys;
921 if (routing_table == NULL) create_routing_table();
923 xbt_dict_foreach(route_table, cursor, key, data) {
925 links = (xbt_dynar_t)data;
926 keys = xbt_str_split_str(key, sep);
928 src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
929 dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
931 link_list_capacity = xbt_dynar_length(links);
932 link_list = xbt_new(link_L07_t, link_list_capacity);
935 xbt_dynar_foreach (links, cpt, link) {
937 link_list[nb_link++] = xbt_dict_get(link_set, link);
940 RETHROW1("Link %s not found (dict raised this exception: %s)", link);
943 route_new(src_id, dst_id, link_list, nb_link);
947 static void add_traces(void) {
948 xbt_dict_cursor_t cursor=NULL;
949 char *trace_name,*elm;
951 if (!trace_connect_list_host_avail) return;
953 /* Connect traces relative to cpu */
954 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
955 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
956 cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
958 xbt_assert1(host, "Host %s undefined", elm);
959 xbt_assert1(trace, "Trace %s undefined", trace_name);
961 host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
964 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
965 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
966 cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
968 xbt_assert1(host, "Host %s undefined", elm);
969 xbt_assert1(trace, "Trace %s undefined", trace_name);
971 host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
974 /* Connect traces relative to network */
975 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
976 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
977 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
979 xbt_assert1(link, "Link %s undefined", elm);
980 xbt_assert1(trace, "Trace %s undefined", trace_name);
982 link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
985 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
986 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
987 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
989 xbt_assert1(link, "Link %s undefined", elm);
990 xbt_assert1(trace, "Trace %s undefined", trace_name);
992 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
995 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
996 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
997 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
999 xbt_assert1(link, "Link %s undefined", elm);
1000 xbt_assert1(trace, "Trace %s undefined", trace_name);
1002 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
1006 xbt_dynar_foreach (traces_connect_list, cpt, value) {
1007 trace_connect = xbt_str_split_str(value, "#");
1008 trace_id = xbt_dynar_get_as(trace_connect, 0, char*);
1009 connect_element = atoi(xbt_dynar_get_as(trace_connect, 1, char*));
1010 connect_kind = atoi(xbt_dynar_get_as(trace_connect, 2, char*));
1011 connector_id = xbt_dynar_get_as(trace_connect, 3, char*);
1013 xbt_assert1((trace = xbt_dict_get_or_null(traces_set_list, trace_id)), "Trace %s undefined", trace_id);
1015 if (connect_element == A_surfxml_trace_c_connect_element_HOST) {
1016 xbt_assert1((host = xbt_dict_get_or_null(workstation_set, connector_id)), "Host %s undefined", connector_id);
1017 switch (connect_kind) {
1018 case A_surfxml_trace_c_connect_kind_AVAILABILITY: host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
1019 case A_surfxml_trace_c_connect_kind_POWER: host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
1023 xbt_assert1((link = xbt_dict_get_or_null(link_set, connector_id)), "Link %s undefined", connector_id);
1024 switch (connect_kind) {
1025 case A_surfxml_trace_c_connect_kind_AVAILABILITY: link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1026 case A_surfxml_trace_c_connect_kind_BANDWIDTH: link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1027 case A_surfxml_trace_c_connect_kind_LATENCY: link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1034 static void define_callbacks(const char *file)
1036 /* Adding callback functions */
1037 surf_parse_reset_parser();
1038 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
1039 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
1040 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
1041 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
1042 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
1043 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
1044 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
1048 /**************************************/
1049 /********* Module creation ***********/
1050 /**************************************/
1052 static void model_init_internal(void)
1054 s_surf_action_t action;
1056 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1058 surf_workstation_model->common_private =
1059 xbt_new0(s_surf_model_private_t, 1);
1060 surf_workstation_model->common_public =
1061 xbt_new0(s_surf_model_public_t, 1);
1062 surf_workstation_model->extension_public =
1063 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1065 surf_workstation_model->common_public->states.ready_action_set =
1066 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1067 surf_workstation_model->common_public->states.running_action_set =
1068 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1069 surf_workstation_model->common_public->states.failed_action_set =
1070 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1071 surf_workstation_model->common_public->states.done_action_set =
1072 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1074 surf_workstation_model->common_public->name_service = name_service;
1075 surf_workstation_model->common_public->get_resource_name =
1077 surf_workstation_model->common_public->action_get_state =
1078 surf_action_get_state;
1079 surf_workstation_model->common_public->action_get_start_time =
1080 surf_action_get_start_time;
1081 surf_workstation_model->common_public->action_get_finish_time =
1082 surf_action_get_finish_time;
1083 surf_workstation_model->common_public->action_use = action_use;
1084 surf_workstation_model->common_public->action_free = action_free;
1085 surf_workstation_model->common_public->action_cancel = action_cancel;
1086 surf_workstation_model->common_public->action_recycle =
1088 surf_workstation_model->common_public->action_change_state =
1089 surf_action_change_state;
1090 surf_workstation_model->common_public->action_set_data =
1091 surf_action_set_data;
1092 surf_workstation_model->common_public->suspend = action_suspend;
1093 surf_workstation_model->common_public->resume = action_resume;
1094 surf_workstation_model->common_public->is_suspended =
1095 action_is_suspended;
1096 surf_workstation_model->common_public->set_max_duration =
1097 action_set_max_duration;
1098 surf_workstation_model->common_public->set_priority =
1099 action_set_priority;
1100 surf_workstation_model->common_public->name = "Workstation ptask_L07";
1102 surf_workstation_model->common_private->resource_used = resource_used;
1103 surf_workstation_model->common_private->share_resources =
1105 surf_workstation_model->common_private->update_actions_state =
1106 update_actions_state;
1107 surf_workstation_model->common_private->update_resource_state =
1108 update_resource_state;
1109 surf_workstation_model->common_private->finalize = finalize;
1111 surf_workstation_model->extension_public->execute = execute;
1112 surf_workstation_model->extension_public->sleep = action_sleep;
1113 surf_workstation_model->extension_public->get_state =
1115 surf_workstation_model->extension_public->get_speed = get_speed;
1116 surf_workstation_model->extension_public->get_available_speed =
1117 get_available_speed;
1118 surf_workstation_model->extension_public->communicate = communicate;
1119 surf_workstation_model->extension_public->execute_parallel_task =
1120 execute_parallel_task;
1121 surf_workstation_model->extension_public->get_route = get_route;
1122 surf_workstation_model->extension_public->get_route_size =
1124 surf_workstation_model->extension_public->get_link_name =
1126 surf_workstation_model->extension_public->get_link_bandwidth =
1128 surf_workstation_model->extension_public->get_link_latency =
1130 surf_workstation_model->extension_public->link_shared =
1133 surf_workstation_model->common_public->get_properties = get_properties;
1135 workstation_set = xbt_dict_new();
1136 link_set = xbt_dict_new();
1138 if (!ptask_maxmin_system)
1139 ptask_maxmin_system = lmm_system_new();
1142 /**************************************/
1143 /*************** Generic **************/
1144 /**************************************/
1145 void surf_workstation_model_init_ptask_L07(const char *filename)
1147 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1148 xbt_assert0(!surf_network_model,
1149 "network model type already defined");
1150 model_init_internal();
1151 define_callbacks(filename);
1153 update_model_description(surf_workstation_model_description,
1155 (surf_model_t) surf_workstation_model);
1156 xbt_dynar_push(model_list, &surf_workstation_model);