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: must match model_obj_t */
23 xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
24 e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
25 char *name; /* Do not move this field: must match link_L07_t */
26 lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
29 tmgr_trace_event_t power_event;
30 e_surf_cpu_state_t state_current;
31 tmgr_trace_event_t state_event;
32 int id; /* cpu and network card are a single object... */
33 } s_cpu_L07_t, *cpu_L07_t;
35 /**************************************/
36 /*********** network object ***********/
37 /**************************************/
39 typedef struct link_L07 {
40 surf_model_t model; /* Do not move this field: must match model_obj_t */
41 xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
42 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
43 char *name; /* Do not move this field: must match cpu_L07_t */
44 lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
46 tmgr_trace_event_t lat_event;
48 tmgr_trace_event_t bw_event;
49 e_surf_link_state_t state_current;
50 tmgr_trace_event_t state_event;
51 } s_link_L07_t, *link_L07_t;
54 typedef struct s_route_L07 {
57 } s_route_L07_t, *route_L07_t;
59 /**************************************/
60 /*************** actions **************/
61 /**************************************/
62 typedef struct surf_action_workstation_L07 {
63 s_surf_action_t generic_action;
64 lmm_variable_t variable;
66 cpu_L07_t *workstation_list;
67 double *computation_amount;
68 double *communication_amount;
72 } s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
75 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
77 static int nb_workstation = 0;
78 static s_route_L07_t *routing_table = NULL;
79 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
80 static link_L07_t loopback = NULL;
81 static xbt_dict_t parallel_task_link_set = NULL;
82 lmm_system_t ptask_maxmin_system = NULL;
85 static void update_action_bound(surf_action_workstation_L07_t action)
87 int workstation_nb = action->workstation_nb;
88 double lat_current = 0.0;
89 double lat_bound = -1.0;
92 for (i = 0; i < workstation_nb; i++) {
93 for (j = 0; j < workstation_nb; j++) {
94 cpu_L07_t card_src = action->workstation_list[i];
95 cpu_L07_t card_dst = action->workstation_list[j];
96 int route_size = ROUTE(card_src->id, card_dst->id).size;
97 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
100 if (action->communication_amount[i * workstation_nb + j] > 0) {
101 for (k = 0; k < route_size; k++) {
102 lat += route[k]->lat_current;
104 lat_current=MAX(lat_current,lat*action->communication_amount[i * workstation_nb + j]);
108 lat_bound = SG_TCP_CTE_GAMMA / (2.0 * lat_current);
109 DEBUG2("action (%p) : lat_bound = %g", action, lat_bound);
110 if ((action->latency == 0.0) && (action->suspended == 0)) {
111 if (action->rate < 0)
112 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
115 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
116 min(action->rate,lat_bound));
120 /**************************************/
121 /******* Resource Public **********/
122 /**************************************/
124 static void *name_service(const char *name)
126 return xbt_dict_get_or_null(workstation_set, name);
129 static const char *get_resource_name(void *resource_id)
131 /* We can freely cast as a cpu_L07_t because it has the same
132 prefix as link_L07_t. However, only cpu_L07_t
133 will theoretically be given as an argument here. */
135 return ((cpu_L07_t) resource_id)->name;
137 static xbt_dict_t get_properties(void *r) {
138 /* We can freely cast as a cpu_L07_t since it has the same prefix than link_L07_t */
139 return ((cpu_L07_t) r)->properties;
142 /* action_get_state is inherited from the surf module */
144 static void action_use(surf_action_t action)
150 static int action_free(surf_action_t action)
154 if (!action->using) {
155 xbt_swag_remove(action, action->state_set);
156 if (((surf_action_workstation_L07_t) action)->variable)
157 lmm_variable_free(ptask_maxmin_system,
158 ((surf_action_workstation_L07_t) action)->
160 free(((surf_action_workstation_L07_t)action)->workstation_list);
161 free(((surf_action_workstation_L07_t)action)->communication_amount);
162 free(((surf_action_workstation_L07_t)action)->computation_amount);
169 static void action_cancel(surf_action_t action)
171 surf_action_change_state(action, SURF_ACTION_FAILED);
175 static void action_recycle(surf_action_t action)
181 /* action_change_state is inherited from the surf module */
182 /* action_set_data is inherited from the surf module */
184 static void action_suspend(surf_action_t action)
186 XBT_IN1("(%p))", action);
187 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
188 ((surf_action_workstation_L07_t) action)->suspended = 1;
189 lmm_update_variable_weight(ptask_maxmin_system,
190 ((surf_action_workstation_L07_t)
191 action)->variable, 0.0);
196 static void action_resume(surf_action_t action)
198 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
200 XBT_IN1("(%p)", act);
201 if (act->suspended != 2) {
202 lmm_update_variable_weight(ptask_maxmin_system,act->variable, 1.0);
208 static int action_is_suspended(surf_action_t action)
210 return (((surf_action_workstation_L07_t) action)->suspended == 1);
213 static void action_set_max_duration(surf_action_t action, double duration)
214 { /* FIXME: should inherit */
215 XBT_IN2("(%p,%g)", action, duration);
216 action->max_duration = duration;
221 static void action_set_priority(surf_action_t action, double priority)
222 { /* FIXME: should inherit */
223 XBT_IN2("(%p,%g)", action, priority);
224 action->priority = priority;
228 /**************************************/
229 /******* Resource Private **********/
230 /**************************************/
232 static int resource_used(void *resource_id)
234 /* We can freely cast as a link_L07_t because it has
235 the same prefix as cpu_L07_t */
236 return lmm_constraint_used(ptask_maxmin_system,
237 ((link_L07_t) resource_id)->
242 static double share_resources(double now)
244 s_surf_action_workstation_L07_t s_action;
245 surf_action_workstation_L07_t action = NULL;
247 xbt_swag_t running_actions =
248 surf_workstation_model->common_public->states.running_action_set;
249 double min = generic_maxmin_share_resources(running_actions,
250 xbt_swag_offset(s_action,
255 xbt_swag_foreach(action, running_actions) {
256 if (action->latency > 0) {
258 min = action->latency;
259 DEBUG3("Updating min (value) with %p (start %f): %f", action,
260 action->generic_action.start, min);
261 } else if (action->latency < min) {
262 min = action->latency;
263 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
264 action->generic_action.start, min);
269 DEBUG1("min value : %f", min);
274 static void update_actions_state(double now, double delta)
277 surf_action_workstation_L07_t action = NULL;
278 surf_action_workstation_L07_t next_action = NULL;
279 xbt_swag_t running_actions =
280 surf_workstation_model->common_public->states.running_action_set;
282 xbt_swag_foreach_safe(action, next_action, running_actions) {
284 if (action->latency > 0) {
285 if (action->latency > deltap) {
286 double_update(&(action->latency), deltap);
289 double_update(&(deltap), action->latency);
290 action->latency = 0.0;
292 if ((action->latency == 0.0) && (action->suspended == 0)) {
293 update_action_bound(action);
294 lmm_update_variable_weight(ptask_maxmin_system,action->variable, 1.0);
297 DEBUG3("Action (%p) : remains (%g) updated by %g.",
298 action, action->generic_action.remains,
299 lmm_variable_getvalue(action->variable) * delta);
300 double_update(&(action->generic_action.remains),
301 lmm_variable_getvalue(action->variable) * delta);
303 if (action->generic_action.max_duration != NO_MAX_DURATION)
304 double_update(&(action->generic_action.max_duration), delta);
306 DEBUG2("Action (%p) : remains (%g).",
307 action, action->generic_action.remains);
308 if ((action->generic_action.remains <= 0) &&
309 (lmm_get_variable_weight(action->variable) > 0)) {
310 action->generic_action.finish = surf_get_clock();
311 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
312 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
313 (action->generic_action.max_duration <= 0)) {
314 action->generic_action.finish = surf_get_clock();
315 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
317 /* Need to check that none of the model has failed */
318 lmm_constraint_t cnst = NULL;
320 void *constraint_id = NULL;
323 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
325 constraint_id = lmm_constraint_id(cnst);
327 /* if(((link_L07_t)constraint_id)->type== */
328 /* SURF_WORKSTATION_RESOURCE_LINK) { */
329 /* DEBUG2("Checking for link %s (%p)", */
330 /* ((link_L07_t)constraint_id)->name, */
331 /* ((link_L07_t)constraint_id)); */
333 /* if(((cpu_L07_t)constraint_id)->type== */
334 /* SURF_WORKSTATION_RESOURCE_CPU) { */
335 /* DEBUG3("Checking for cpu %s (%p) : %s", */
336 /* ((cpu_L07_t)constraint_id)->name, */
337 /* ((cpu_L07_t)constraint_id), */
338 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
341 if (((((link_L07_t) constraint_id)->type ==
342 SURF_WORKSTATION_RESOURCE_LINK) &&
343 (((link_L07_t) constraint_id)->state_current ==
345 ((((cpu_L07_t) constraint_id)->type ==
346 SURF_WORKSTATION_RESOURCE_CPU) &&
347 (((cpu_L07_t) constraint_id)->state_current ==
349 DEBUG1("Action (%p) Failed!!", action);
350 action->generic_action.finish = surf_get_clock();
351 surf_action_change_state((surf_action_t) action,
361 static void update_resource_state(void *id,
362 tmgr_trace_event_t event_type,
366 link_L07_t nw_link = id;
368 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
369 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
370 if (event_type == nw_link->bw_event) {
371 nw_link->bw_current = value;
372 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
373 nw_link->bw_current);
374 } else if (event_type == nw_link->lat_event) {
375 lmm_variable_t var = NULL;
376 surf_action_workstation_L07_t action = NULL;
378 nw_link->lat_current = value;
379 while (lmm_get_var_from_cnst
380 (ptask_maxmin_system, nw_link->constraint, &var)) {
383 action = lmm_variable_id(var);
384 update_action_bound(action);
387 } else if (event_type == nw_link->state_event) {
389 nw_link->state_current = SURF_LINK_ON;
391 nw_link->state_current = SURF_LINK_OFF;
393 CRITICAL0("Unknown event ! \n");
397 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
398 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
399 if (event_type == cpu->power_event) {
400 cpu->power_current = value;
401 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
403 } else if (event_type == cpu->state_event) {
405 cpu->state_current = SURF_CPU_ON;
407 cpu->state_current = SURF_CPU_OFF;
409 CRITICAL0("Unknown event ! \n");
419 static void finalize(void)
423 xbt_dict_free(&link_set);
424 xbt_dict_free(&workstation_set);
425 if (parallel_task_link_set != NULL) {
426 xbt_dict_free(¶llel_task_link_set);
428 xbt_swag_free(surf_workstation_model->common_public->states.
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.
437 free(surf_workstation_model->common_public);
438 free(surf_workstation_model->common_private);
439 free(surf_workstation_model->extension_public);
441 free(surf_workstation_model);
442 surf_workstation_model = NULL;
444 for (i = 0; i < nb_workstation; i++)
445 for (j = 0; j < nb_workstation; j++)
446 free(ROUTE(i, j).links);
448 routing_table = NULL;
451 if (ptask_maxmin_system) {
452 lmm_system_free(ptask_maxmin_system);
453 ptask_maxmin_system = NULL;
457 /**************************************/
458 /******* Resource Private **********/
459 /**************************************/
461 static e_surf_cpu_state_t resource_get_state(void *cpu)
463 return ((cpu_L07_t) cpu)->state_current;
466 static double get_speed(void *cpu, double load)
468 return load * (((cpu_L07_t) cpu)->power_scale);
471 static double get_available_speed(void *cpu)
473 return ((cpu_L07_t) cpu)->power_current;
476 static surf_action_t execute_parallel_task(int workstation_nb,
477 void **workstation_list,
478 double *computation_amount,
479 double *communication_amount,
480 double amount, double rate)
482 surf_action_workstation_L07_t action = NULL;
486 double latency = 0.0;
488 if (parallel_task_link_set == NULL) {
489 parallel_task_link_set =
490 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
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;
669 /**************************************/
670 /*** Resource Creation & Destruction **/
671 /**************************************/
673 static void cpu_free(void *cpu)
675 free(((cpu_L07_t) cpu)->name);
679 static cpu_L07_t cpu_new(const char *name, double power_scale,
680 double power_initial,
681 tmgr_trace_t power_trace,
682 e_surf_cpu_state_t state_initial,
683 tmgr_trace_t state_trace,
684 xbt_dict_t cpu_properties)
686 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
688 cpu->model = (surf_model_t) surf_workstation_model;
689 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
690 cpu->name = xbt_strdup(name);
691 cpu->id = nb_workstation++;
693 cpu->power_scale = power_scale;
694 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
696 cpu->power_current = power_initial;
699 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
701 cpu->state_current = state_initial;
704 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
707 lmm_constraint_new(ptask_maxmin_system, cpu,
708 cpu->power_current * cpu->power_scale);
710 /*add the property set*/
711 cpu->properties = current_property_set;
713 xbt_dict_set(workstation_set, name, cpu, cpu_free);
717 static void create_routing_table(void)
719 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
722 static void parse_cpu_init(void)
724 double power_scale = 0.0;
725 double power_initial = 0.0;
726 tmgr_trace_t power_trace = NULL;
727 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
728 tmgr_trace_t state_trace = NULL;
730 surf_parse_get_double(&power_scale, A_surfxml_host_power);
731 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
732 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
734 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
735 (A_surfxml_host_state == A_surfxml_host_state_OFF),
737 if (A_surfxml_host_state == A_surfxml_host_state_ON)
738 state_initial = SURF_CPU_ON;
739 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
740 state_initial = SURF_CPU_OFF;
741 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
743 current_property_set = xbt_dict_new();
744 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
745 state_initial, state_trace,current_property_set);
748 static void link_free(void *nw_link)
750 free(((link_L07_t) nw_link)->name);
754 static link_L07_t link_new(char *name,
756 tmgr_trace_t bw_trace,
758 tmgr_trace_t lat_trace,
761 tmgr_trace_t state_trace,
762 e_surf_link_sharing_policy_t
763 policy, xbt_dict_t properties)
765 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
768 nw_link->model = (surf_model_t) surf_workstation_model;
769 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
770 nw_link->name = name;
771 nw_link->bw_current = bw_initial;
774 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
775 nw_link->state_current = state_initial;
776 nw_link->lat_current = lat_initial;
779 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
781 nw_link->state_event =
782 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
784 nw_link->constraint =
785 lmm_constraint_new(ptask_maxmin_system, nw_link,
786 nw_link->bw_current);
788 if (policy == SURF_LINK_FATPIPE)
789 lmm_constraint_shared(nw_link->constraint);
791 nw_link->properties = properties;
793 xbt_dict_set(link_set, name, nw_link, link_free);
798 static void parse_link_init(void)
802 tmgr_trace_t bw_trace;
804 tmgr_trace_t lat_trace;
805 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
806 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
807 tmgr_trace_t state_trace;
809 name_link = xbt_strdup(A_surfxml_link_id);
810 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
811 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
812 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
813 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
815 xbt_assert0((A_surfxml_link_state ==
816 A_surfxml_link_state_ON)
817 || (A_surfxml_link_state ==
818 A_surfxml_link_state_OFF), "Invalid state");
819 if (A_surfxml_link_state == A_surfxml_link_state_ON)
820 state_initial_link = SURF_LINK_ON;
821 else if (A_surfxml_link_state ==
822 A_surfxml_link_state_OFF)
823 state_initial_link = SURF_LINK_OFF;
825 if (A_surfxml_link_sharing_policy ==
826 A_surfxml_link_sharing_policy_SHARED)
827 policy_initial_link = SURF_LINK_SHARED;
828 else if (A_surfxml_link_sharing_policy ==
829 A_surfxml_link_sharing_policy_FATPIPE)
830 policy_initial_link = SURF_LINK_FATPIPE;
832 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
834 current_property_set = xbt_dict_new();
835 link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
836 state_initial_link, state_trace, policy_initial_link, current_property_set);
840 static void route_new(int src_id, int dst_id,
841 link_L07_t * link_list, int nb_link)
843 route_L07_t route = &(ROUTE(src_id, dst_id));
845 route->size = nb_link;
846 route->links = link_list =
847 xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
851 static int link_list_capacity;
852 static link_L07_t *link_list = NULL;
853 static int src_id = -1;
854 static int dst_id = -1;
855 static int is_first =1;
857 static void parse_route_set_endpoints(void)
859 cpu_L07_t cpu_tmp = NULL;
861 if (is_first) create_routing_table();
864 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
865 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
867 src_id = cpu_tmp->id;
869 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
870 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
872 dst_id = cpu_tmp->id;
875 link_list_capacity = 1;
876 link_list = xbt_new(link_L07_t, link_list_capacity);
879 static void parse_route_elem(void)
882 if (nb_link == link_list_capacity) {
883 link_list_capacity *= 2;
885 xbt_realloc(link_list,
886 (link_list_capacity) * sizeof(link_L07_t));
889 link_list[nb_link++] =
890 xbt_dict_get(link_set, A_surfxml_link_c_ctn_id);
893 RETHROW1("Link %s not found (dict raised this exception: %s)",
894 A_surfxml_link_c_ctn_id);
898 static void parse_route_set_route(void)
900 if (src_id != -1 && dst_id != -1)
901 route_new(src_id, dst_id, link_list, nb_link);
904 static void parse_file(const char *file)
908 /* Adding callback functions */
909 surf_parse_reset_parser();
910 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
911 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
912 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
913 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
914 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
915 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
918 surf_parse_open(file);
919 xbt_assert1((!surf_parse()), "Parse error in %s", file);
922 /* Adding loopback if needed */
923 for (i = 0; i < nb_workstation; i++)
924 if (!ROUTE(i, i).size) {
926 loopback = link_new(xbt_strdup("__MSG_loopback__"),
927 498000000, NULL, 0.000015, NULL,
929 SURF_LINK_FATPIPE,NULL);
931 ROUTE(i, i).size = 1;
932 ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
933 ROUTE(i, i).links[0] = loopback;
937 /**************************************/
938 /********* Module creation ***********/
939 /**************************************/
941 static void model_init_internal(void)
943 s_surf_action_t action;
945 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
947 surf_workstation_model->common_private =
948 xbt_new0(s_surf_model_private_t, 1);
949 surf_workstation_model->common_public =
950 xbt_new0(s_surf_model_public_t, 1);
951 surf_workstation_model->extension_public =
952 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
954 surf_workstation_model->common_public->states.ready_action_set =
955 xbt_swag_new(xbt_swag_offset(action, state_hookup));
956 surf_workstation_model->common_public->states.running_action_set =
957 xbt_swag_new(xbt_swag_offset(action, state_hookup));
958 surf_workstation_model->common_public->states.failed_action_set =
959 xbt_swag_new(xbt_swag_offset(action, state_hookup));
960 surf_workstation_model->common_public->states.done_action_set =
961 xbt_swag_new(xbt_swag_offset(action, state_hookup));
963 surf_workstation_model->common_public->name_service = name_service;
964 surf_workstation_model->common_public->get_resource_name =
966 surf_workstation_model->common_public->action_get_state =
967 surf_action_get_state;
968 surf_workstation_model->common_public->action_get_start_time =
969 surf_action_get_start_time;
970 surf_workstation_model->common_public->action_get_finish_time =
971 surf_action_get_finish_time;
972 surf_workstation_model->common_public->action_use = action_use;
973 surf_workstation_model->common_public->action_free = action_free;
974 surf_workstation_model->common_public->action_cancel = action_cancel;
975 surf_workstation_model->common_public->action_recycle =
977 surf_workstation_model->common_public->action_change_state =
978 surf_action_change_state;
979 surf_workstation_model->common_public->action_set_data =
980 surf_action_set_data;
981 surf_workstation_model->common_public->suspend = action_suspend;
982 surf_workstation_model->common_public->resume = action_resume;
983 surf_workstation_model->common_public->is_suspended =
985 surf_workstation_model->common_public->set_max_duration =
986 action_set_max_duration;
987 surf_workstation_model->common_public->set_priority =
989 surf_workstation_model->common_public->name = "Workstation ptask_L07";
991 surf_workstation_model->common_private->resource_used = resource_used;
992 surf_workstation_model->common_private->share_resources =
994 surf_workstation_model->common_private->update_actions_state =
995 update_actions_state;
996 surf_workstation_model->common_private->update_resource_state =
997 update_resource_state;
998 surf_workstation_model->common_private->finalize = finalize;
1000 surf_workstation_model->extension_public->execute = execute;
1001 surf_workstation_model->extension_public->sleep = action_sleep;
1002 surf_workstation_model->extension_public->get_state =
1004 surf_workstation_model->extension_public->get_speed = get_speed;
1005 surf_workstation_model->extension_public->get_available_speed =
1006 get_available_speed;
1007 surf_workstation_model->extension_public->communicate = communicate;
1008 surf_workstation_model->extension_public->execute_parallel_task =
1009 execute_parallel_task;
1010 surf_workstation_model->extension_public->get_route = get_route;
1011 surf_workstation_model->extension_public->get_route_size =
1013 surf_workstation_model->extension_public->get_link_name =
1015 surf_workstation_model->extension_public->get_link_bandwidth =
1017 surf_workstation_model->extension_public->get_link_latency =
1020 surf_workstation_model->common_public->get_properties = get_properties;
1022 workstation_set = xbt_dict_new();
1023 link_set = xbt_dict_new();
1025 if (!ptask_maxmin_system)
1026 ptask_maxmin_system = lmm_system_new();
1029 /**************************************/
1030 /*************** Generic **************/
1031 /**************************************/
1032 void surf_workstation_model_init_ptask_L07(const char *filename)
1034 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1035 xbt_assert0(!surf_network_model,
1036 "network model type already defined");
1037 model_init_internal();
1038 parse_file(filename);
1040 update_model_description(surf_workstation_model_description,
1041 surf_workstation_model_description_size,
1043 (surf_model_t) surf_workstation_model);
1044 xbt_dynar_push(model_list, &surf_workstation_model);