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"
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 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_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 lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
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 } s_cpu_L07_t, *cpu_L07_t;
34 /**************************************/
35 /*********** network object ***********/
36 /**************************************/
38 typedef struct link_L07 {
39 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
40 xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
41 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
42 lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
44 tmgr_trace_event_t lat_event;
46 tmgr_trace_event_t bw_event;
47 e_surf_link_state_t state_current;
48 tmgr_trace_event_t state_event;
49 } s_link_L07_t, *link_L07_t;
52 typedef struct s_route_L07 {
55 } s_route_L07_t, *route_L07_t;
57 /**************************************/
58 /*************** actions **************/
59 /**************************************/
60 typedef struct surf_action_workstation_L07 {
61 s_surf_action_t generic_action;
62 lmm_variable_t variable;
64 cpu_L07_t *workstation_list;
65 double *computation_amount;
66 double *communication_amount;
70 } s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
73 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
75 static int nb_workstation = 0;
76 static s_route_L07_t *routing_table = NULL;
77 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
78 static link_L07_t loopback = NULL;
79 static xbt_dict_t parallel_task_link_set = NULL;
80 lmm_system_t ptask_maxmin_system = NULL;
83 static void update_action_bound(surf_action_workstation_L07_t action)
85 int workstation_nb = action->workstation_nb;
86 double lat_current = 0.0;
87 double lat_bound = -1.0;
90 for (i = 0; i < workstation_nb; i++) {
91 for (j = 0; j < workstation_nb; j++) {
92 cpu_L07_t card_src = action->workstation_list[i];
93 cpu_L07_t card_dst = action->workstation_list[j];
94 int route_size = ROUTE(card_src->id, card_dst->id).size;
95 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
98 if (action->communication_amount[i * workstation_nb + j] > 0) {
99 for (k = 0; k < route_size; k++) {
100 lat += route[k]->lat_current;
104 lat * action->communication_amount[i * workstation_nb + j]);
108 lat_bound = sg_tcp_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 xbt_dict_t get_properties(void *r)
126 /* We can freely cast as a cpu_L07_t since it has the same prefix than link_L07_t */
127 return ((cpu_L07_t) r)->properties;
130 static int action_unref(surf_action_t action)
134 if (!action->refcount) {
135 xbt_swag_remove(action, action->state_set);
136 if (((surf_action_workstation_L07_t) action)->variable)
137 lmm_variable_free(ptask_maxmin_system,
138 ((surf_action_workstation_L07_t) action)->variable);
139 free(((surf_action_workstation_L07_t) action)->workstation_list);
140 free(((surf_action_workstation_L07_t) action)->communication_amount);
141 free(((surf_action_workstation_L07_t) action)->computation_amount);
148 static void action_cancel(surf_action_t action)
150 surf_action_state_set(action, SURF_ACTION_FAILED);
154 /* action_change_state is inherited from the surf module */
155 /* action_set_data is inherited from the surf module */
157 static void action_suspend(surf_action_t action)
159 XBT_IN1("(%p))", action);
160 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
161 ((surf_action_workstation_L07_t) action)->suspended = 1;
162 lmm_update_variable_weight(ptask_maxmin_system,
163 ((surf_action_workstation_L07_t)
164 action)->variable, 0.0);
169 static void action_resume(surf_action_t action)
171 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
173 XBT_IN1("(%p)", act);
174 if (act->suspended != 2) {
175 lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
181 static int action_is_suspended(surf_action_t action)
183 return (((surf_action_workstation_L07_t) action)->suspended == 1);
186 static void action_set_max_duration(surf_action_t action, double duration)
187 { /* FIXME: should inherit */
188 XBT_IN2("(%p,%g)", action, duration);
189 action->max_duration = duration;
194 static void action_set_priority(surf_action_t action, double priority)
195 { /* FIXME: should inherit */
196 XBT_IN2("(%p,%g)", action, priority);
197 action->priority = priority;
201 /**************************************/
202 /******* Resource Private **********/
203 /**************************************/
205 static int resource_used(void *resource_id)
207 /* We can freely cast as a link_L07_t because it has
208 the same prefix as cpu_L07_t */
209 return lmm_constraint_used(ptask_maxmin_system,
210 ((link_L07_t) resource_id)->constraint);
214 static double share_resources(double now)
216 s_surf_action_workstation_L07_t s_action;
217 surf_action_workstation_L07_t action = NULL;
219 xbt_swag_t running_actions =
220 surf_workstation_model->states.running_action_set;
221 double min = generic_maxmin_share_resources(running_actions,
222 xbt_swag_offset(s_action,
227 xbt_swag_foreach(action, running_actions) {
228 if (action->latency > 0) {
230 min = action->latency;
231 DEBUG3("Updating min (value) with %p (start %f): %f", action,
232 action->generic_action.start, min);
233 } else if (action->latency < min) {
234 min = action->latency;
235 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
236 action->generic_action.start, min);
241 DEBUG1("min value : %f", min);
246 static void update_actions_state(double now, double delta)
249 surf_action_workstation_L07_t action = NULL;
250 surf_action_workstation_L07_t next_action = NULL;
251 xbt_swag_t running_actions =
252 surf_workstation_model->states.running_action_set;
254 xbt_swag_foreach_safe(action, next_action, running_actions) {
256 if (action->latency > 0) {
257 if (action->latency > deltap) {
258 double_update(&(action->latency), deltap);
261 double_update(&(deltap), action->latency);
262 action->latency = 0.0;
264 if ((action->latency == 0.0) && (action->suspended == 0)) {
265 update_action_bound(action);
266 lmm_update_variable_weight(ptask_maxmin_system, action->variable,
270 DEBUG3("Action (%p) : remains (%g) updated by %g.",
271 action, action->generic_action.remains,
272 lmm_variable_getvalue(action->variable) * delta);
273 double_update(&(action->generic_action.remains),
274 lmm_variable_getvalue(action->variable) * delta);
276 if (action->generic_action.max_duration != NO_MAX_DURATION)
277 double_update(&(action->generic_action.max_duration), delta);
279 DEBUG2("Action (%p) : remains (%g).",
280 action, action->generic_action.remains);
281 if ((action->generic_action.remains <= 0) &&
282 (lmm_get_variable_weight(action->variable) > 0)) {
283 action->generic_action.finish = surf_get_clock();
284 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
285 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
286 (action->generic_action.max_duration <= 0)) {
287 action->generic_action.finish = surf_get_clock();
288 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
290 /* Need to check that none of the model has failed */
291 lmm_constraint_t cnst = NULL;
293 void *constraint_id = NULL;
296 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
298 constraint_id = lmm_constraint_id(cnst);
300 /* if(((link_L07_t)constraint_id)->type== */
301 /* SURF_WORKSTATION_RESOURCE_LINK) { */
302 /* DEBUG2("Checking for link %s (%p)", */
303 /* ((link_L07_t)constraint_id)->name, */
304 /* ((link_L07_t)constraint_id)); */
306 /* if(((cpu_L07_t)constraint_id)->type== */
307 /* SURF_WORKSTATION_RESOURCE_CPU) { */
308 /* DEBUG3("Checking for cpu %s (%p) : %s", */
309 /* ((cpu_L07_t)constraint_id)->name, */
310 /* ((cpu_L07_t)constraint_id), */
311 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
314 if (((((link_L07_t) constraint_id)->type ==
315 SURF_WORKSTATION_RESOURCE_LINK) &&
316 (((link_L07_t) constraint_id)->state_current ==
318 ((((cpu_L07_t) constraint_id)->type ==
319 SURF_WORKSTATION_RESOURCE_CPU) &&
320 (((cpu_L07_t) constraint_id)->state_current == SURF_CPU_OFF))) {
321 DEBUG1("Action (%p) Failed!!", action);
322 action->generic_action.finish = surf_get_clock();
323 surf_action_state_set((surf_action_t) action,
333 static void update_resource_state(void *id,
334 tmgr_trace_event_t event_type,
335 double value, double date)
338 link_L07_t nw_link = id;
340 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
341 DEBUG2("Updating link %s (%p)", nw_link->generic_resource.name, nw_link);
342 if (event_type == nw_link->bw_event) {
343 nw_link->bw_current = value;
344 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
345 nw_link->bw_current);
346 } else if (event_type == nw_link->lat_event) {
347 lmm_variable_t var = NULL;
348 surf_action_workstation_L07_t action = NULL;
349 lmm_element_t elem = NULL;
351 nw_link->lat_current = value;
352 while ((var = lmm_get_var_from_cnst
353 (ptask_maxmin_system, nw_link->constraint, &elem))) {
356 action = lmm_variable_id(var);
357 update_action_bound(action);
360 } else if (event_type == nw_link->state_event) {
362 nw_link->state_current = SURF_LINK_ON;
364 nw_link->state_current = SURF_LINK_OFF;
366 CRITICAL0("Unknown event ! \n");
370 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
371 DEBUG3("Updating cpu %s (%p) with value %g", cpu->generic_resource.name, cpu, value);
372 if (event_type == cpu->power_event) {
373 cpu->power_current = value;
374 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
375 cpu->power_current * cpu->power_scale);
376 } else if (event_type == cpu->state_event) {
378 cpu->state_current = SURF_CPU_ON;
380 cpu->state_current = SURF_CPU_OFF;
382 CRITICAL0("Unknown event ! \n");
392 static void finalize(void)
396 xbt_dict_free(&link_set);
397 if (parallel_task_link_set != NULL) {
398 xbt_dict_free(¶llel_task_link_set);
401 surf_model_exit(surf_workstation_model);
402 surf_workstation_model = NULL;
404 for (i = 0; i < nb_workstation; i++)
405 for (j = 0; j < nb_workstation; j++)
406 free(ROUTE(i, j).links);
408 routing_table = NULL;
411 if (ptask_maxmin_system) {
412 lmm_system_free(ptask_maxmin_system);
413 ptask_maxmin_system = NULL;
417 /**************************************/
418 /******* Resource Private **********/
419 /**************************************/
421 static e_surf_cpu_state_t resource_get_state(void *cpu)
423 return ((cpu_L07_t) cpu)->state_current;
426 static double get_speed(void *cpu, double load)
428 return load * (((cpu_L07_t) cpu)->power_scale);
431 static double get_available_speed(void *cpu)
433 return ((cpu_L07_t) cpu)->power_current;
436 static surf_action_t execute_parallel_task(int workstation_nb,
437 void **workstation_list,
438 double *computation_amount,
439 double *communication_amount,
440 double amount, double rate)
442 surf_action_workstation_L07_t action = NULL;
446 double latency = 0.0;
448 if (parallel_task_link_set == NULL)
449 parallel_task_link_set = xbt_dict_new();
451 xbt_dict_reset(parallel_task_link_set);
453 /* Compute the number of affected resources... */
454 for (i = 0; i < workstation_nb; i++) {
455 for (j = 0; j < workstation_nb; j++) {
456 cpu_L07_t card_src = workstation_list[i];
457 cpu_L07_t card_dst = workstation_list[j];
458 int route_size = ROUTE(card_src->id, card_dst->id).size;
459 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
462 if (communication_amount[i * workstation_nb + j] > 0)
463 for (k = 0; k < route_size; k++) {
464 lat += route[k]->lat_current;
465 xbt_dict_set(parallel_task_link_set, route[k]->generic_resource.name,
468 latency = MAX(latency, lat);
472 nb_link = xbt_dict_length(parallel_task_link_set);
473 xbt_dict_reset(parallel_task_link_set);
475 for (i = 0; i < workstation_nb; i++)
476 if (computation_amount[i] > 0)
479 action = xbt_new0(s_surf_action_workstation_L07_t, 1);
480 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
481 action, workstation_nb, nb_link);
482 action->generic_action.refcount = 1;
483 action->generic_action.cost = amount;
484 action->generic_action.remains = amount;
485 action->generic_action.max_duration = NO_MAX_DURATION;
486 action->generic_action.start = surf_get_clock();
487 action->generic_action.finish = -1.0;
488 action->generic_action.model_type = surf_workstation_model;
489 action->suspended = 0; /* Should be useless because of the
490 calloc but it seems to help valgrind... */
491 action->workstation_nb = workstation_nb;
492 action->workstation_list = (cpu_L07_t *) workstation_list;
493 action->computation_amount = computation_amount;
494 action->communication_amount = communication_amount;
495 action->latency = latency;
496 action->generic_action.state_set =
497 surf_workstation_model->states.running_action_set;
499 xbt_swag_insert(action, action->generic_action.state_set);
503 lmm_variable_new(ptask_maxmin_system, action, 1.0,
504 (action->rate > 0) ? action->rate : -1.0,
505 workstation_nb + nb_link);
507 if (action->latency > 0)
508 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
510 for (i = 0; i < workstation_nb; i++)
511 lmm_expand(ptask_maxmin_system,
512 ((cpu_L07_t) workstation_list[i])->constraint,
513 action->variable, computation_amount[i]);
515 for (i = 0; i < workstation_nb; i++) {
516 for (j = 0; j < workstation_nb; j++) {
517 cpu_L07_t card_src = workstation_list[i];
518 cpu_L07_t card_dst = workstation_list[j];
519 int route_size = ROUTE(card_src->id, card_dst->id).size;
520 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
522 if (communication_amount[i * workstation_nb + j] == 0.0)
524 for (k = 0; k < route_size; k++) {
525 lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
527 communication_amount[i * workstation_nb + j]);
532 if (nb_link + nb_host == 0) {
533 action->generic_action.cost = 1.0;
534 action->generic_action.remains = 0.0;
537 return (surf_action_t) action;
540 static surf_action_t execute(void *cpu, double size)
542 void **workstation_list = xbt_new0(void *, 1);
543 double *computation_amount = xbt_new0(double, 1);
544 double *communication_amount = xbt_new0(double, 1);
546 workstation_list[0] = cpu;
547 communication_amount[0] = 0.0;
548 computation_amount[0] = size;
550 return execute_parallel_task(1, workstation_list, computation_amount,
551 communication_amount, 1, -1);
554 static surf_action_t communicate(void *src, void *dst, double size,
557 void **workstation_list = xbt_new0(void *, 2);
558 double *computation_amount = xbt_new0(double, 2);
559 double *communication_amount = xbt_new0(double, 4);
560 surf_action_t res = NULL;
562 workstation_list[0] = src;
563 workstation_list[1] = dst;
564 communication_amount[1] = size;
566 res = execute_parallel_task(2, workstation_list,
567 computation_amount, communication_amount,
573 static surf_action_t action_sleep(void *cpu, double duration)
575 surf_action_workstation_L07_t action = NULL;
577 XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->generic_resource.name, duration);
579 action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
580 action->generic_action.max_duration = duration;
581 action->suspended = 2;
582 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
585 return (surf_action_t) action;
588 /* returns an array of link_L07_t */
589 static const void **get_route(void *src, void *dst)
591 cpu_L07_t card_src = src;
592 cpu_L07_t card_dst = dst;
593 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
595 return (const void **) route->links;
598 static int get_route_size(void *src, void *dst)
600 cpu_L07_t card_src = src;
601 cpu_L07_t card_dst = dst;
602 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
606 static double get_link_bandwidth(const void *link)
608 return ((link_L07_t) link)->bw_current;
611 static double get_link_latency(const void *link)
613 return ((link_L07_t) link)->lat_current;
616 static int link_shared(const void *link)
618 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
621 /**************************************/
622 /*** Resource Creation & Destruction **/
623 /**************************************/
625 static void cpu_free(void *cpu)
627 xbt_dict_free(&(((cpu_L07_t) cpu)->properties));
628 surf_resource_free(cpu);
631 static cpu_L07_t cpu_new(const char *name, double power_scale,
632 double power_initial,
633 tmgr_trace_t power_trace,
634 e_surf_cpu_state_t state_initial,
635 tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
637 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
638 xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
639 "Host '%s' declared several times in the platform file.", name);
641 cpu->generic_resource.model = surf_workstation_model;
642 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
643 cpu->generic_resource.name = xbt_strdup(name);
644 cpu->id = nb_workstation++;
646 cpu->power_scale = power_scale;
647 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
649 cpu->power_current = power_initial;
652 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
654 cpu->state_current = state_initial;
657 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
660 lmm_constraint_new(ptask_maxmin_system, cpu,
661 cpu->power_current * cpu->power_scale);
663 /*add the property set */
664 cpu->properties = current_property_set;
666 xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu,
672 static void create_routing_table(void)
674 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
677 static void parse_cpu_init(void)
679 double power_scale = 0.0;
680 double power_initial = 0.0;
681 tmgr_trace_t power_trace = NULL;
682 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
683 tmgr_trace_t state_trace = NULL;
685 power_scale = get_cpu_power(A_surfxml_host_power);
686 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
687 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
689 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
690 (A_surfxml_host_state == A_surfxml_host_state_OFF),
692 if (A_surfxml_host_state == A_surfxml_host_state_ON)
693 state_initial = SURF_CPU_ON;
694 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
695 state_initial = SURF_CPU_OFF;
696 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
698 current_property_set = xbt_dict_new();
699 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
700 state_initial, state_trace, current_property_set);
703 static void link_free(void *nw_link)
705 xbt_dict_free(&(((link_L07_t) nw_link)->properties));
706 surf_resource_free(nw_link);
709 static link_L07_t link_new(char *name,
711 tmgr_trace_t bw_trace,
713 tmgr_trace_t lat_trace,
716 tmgr_trace_t state_trace,
717 e_surf_link_sharing_policy_t
718 policy, xbt_dict_t properties)
720 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
721 xbt_assert1(!xbt_dict_get_or_null(link_set, name),
722 "Link '%s' declared several times in the platform file.", name);
724 nw_link->generic_resource.model = surf_workstation_model;
725 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
726 nw_link->generic_resource.name = name;
727 nw_link->bw_current = bw_initial;
730 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
731 nw_link->state_current = state_initial;
732 nw_link->lat_current = lat_initial;
735 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
737 nw_link->state_event =
738 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
740 nw_link->constraint =
741 lmm_constraint_new(ptask_maxmin_system, nw_link, nw_link->bw_current);
743 if (policy == SURF_LINK_FATPIPE)
744 lmm_constraint_shared(nw_link->constraint);
746 nw_link->properties = properties;
748 xbt_dict_set(link_set, name, nw_link, link_free);
753 static void parse_link_init(void)
757 tmgr_trace_t bw_trace;
759 tmgr_trace_t lat_trace;
760 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
761 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
762 tmgr_trace_t state_trace;
764 name_link = xbt_strdup(A_surfxml_link_id);
765 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
766 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
767 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
768 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
770 xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON)
771 || (A_surfxml_link_state ==
772 A_surfxml_link_state_OFF), "Invalid state");
773 if (A_surfxml_link_state == A_surfxml_link_state_ON)
774 state_initial_link = SURF_LINK_ON;
775 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
776 state_initial_link = SURF_LINK_OFF;
778 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
779 policy_initial_link = SURF_LINK_SHARED;
780 else if (A_surfxml_link_sharing_policy ==
781 A_surfxml_link_sharing_policy_FATPIPE)
782 policy_initial_link = SURF_LINK_FATPIPE;
784 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
786 current_property_set = xbt_dict_new();
787 link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
788 state_initial_link, state_trace, policy_initial_link,
789 current_property_set);
792 static void route_new(int src_id, int dst_id,
793 link_L07_t * link_list, int nb_link)
795 route_L07_t route = &(ROUTE(src_id, dst_id));
797 route->size = nb_link;
798 route->links = link_list =
799 xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
803 static int src_id = -1;
804 static int dst_id = -1;
806 static void parse_route_set_endpoints(void)
808 cpu_L07_t cpu_tmp = NULL;
811 (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
812 A_surfxml_route_src);
813 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
815 src_id = cpu_tmp->id;
818 (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
819 A_surfxml_route_dst);
820 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
822 dst_id = cpu_tmp->id;
824 route_action = A_surfxml_route_action;
827 static void parse_route_set_route(void)
830 if (src_id != -1 && dst_id != -1) {
831 name = bprintf("%x#%x", src_id, dst_id);
832 manage_route(route_table, name, route_action, 0);
837 static void add_loopback(void)
841 /* Adding loopback if needed */
842 for (i = 0; i < nb_workstation; i++)
843 if (!ROUTE(i, i).size) {
845 loopback = link_new(xbt_strdup("__MSG_loopback__"),
846 498000000, NULL, 0.000015, NULL,
847 SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
849 ROUTE(i, i).size = 1;
850 ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
851 ROUTE(i, i).links[0] = loopback;
855 static void add_route(void)
859 unsigned int cpt = 0;
860 int link_list_capacity = 0;
861 link_L07_t *link_list = NULL;
862 xbt_dict_cursor_t cursor = NULL;
863 char *key, *data, *end;
864 const char *sep = "#";
865 xbt_dynar_t links, keys;
868 if (routing_table == NULL)
869 create_routing_table();
871 xbt_dict_foreach(route_table, cursor, key, data) {
873 links = (xbt_dynar_t) data;
874 keys = xbt_str_split_str(key, sep);
876 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
877 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
878 xbt_dynar_free(&keys);
880 link_list_capacity = xbt_dynar_length(links);
881 link_list = xbt_new(link_L07_t, link_list_capacity);
884 xbt_dynar_foreach(links, cpt, link) {
886 link_list[nb_link++] = xbt_dict_get(link_set, link);
889 RETHROW1("Link %s not found (dict raised this exception: %s)", link);
892 route_new(src_id, dst_id, link_list, nb_link);
896 static void add_traces(void)
898 xbt_dict_cursor_t cursor = NULL;
899 char *trace_name, *elm;
901 if (!trace_connect_list_host_avail)
904 /* Connect traces relative to cpu */
905 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
906 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
907 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
909 xbt_assert1(host, "Host %s undefined", elm);
910 xbt_assert1(trace, "Trace %s undefined", trace_name);
912 host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
915 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
916 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
917 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
919 xbt_assert1(host, "Host %s undefined", elm);
920 xbt_assert1(trace, "Trace %s undefined", trace_name);
922 host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
925 /* Connect traces relative to network */
926 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
927 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
928 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
930 xbt_assert1(link, "Link %s undefined", elm);
931 xbt_assert1(trace, "Trace %s undefined", trace_name);
933 link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
936 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
937 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
938 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
940 xbt_assert1(link, "Link %s undefined", elm);
941 xbt_assert1(trace, "Trace %s undefined", trace_name);
943 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
946 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
947 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
948 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
950 xbt_assert1(link, "Link %s undefined", elm);
951 xbt_assert1(trace, "Trace %s undefined", trace_name);
953 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
957 static void define_callbacks(const char *file)
959 /* Adding callback functions */
960 surf_parse_reset_parser();
961 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
962 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
963 surfxml_add_callback(STag_surfxml_route_cb_list,
964 &parse_route_set_endpoints);
965 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
966 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
967 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
968 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
972 /**************************************/
973 /********* Module creation ***********/
974 /**************************************/
976 static void model_init_internal(void)
978 surf_workstation_model = surf_model_init();
980 surf_workstation_model->action_unref = action_unref;
981 surf_workstation_model->action_cancel = action_cancel;
982 surf_workstation_model->action_state_set = surf_action_state_set;
983 surf_workstation_model->suspend = action_suspend;
984 surf_workstation_model->resume = action_resume;
985 surf_workstation_model->is_suspended = action_is_suspended;
986 surf_workstation_model->set_max_duration = action_set_max_duration;
987 surf_workstation_model->set_priority = action_set_priority;
988 surf_workstation_model->name = "Workstation ptask_L07";
990 surf_workstation_model->model_private->resource_used = resource_used;
991 surf_workstation_model->model_private->share_resources = share_resources;
992 surf_workstation_model->model_private->update_actions_state =
993 update_actions_state;
994 surf_workstation_model->model_private->update_resource_state =
995 update_resource_state;
996 surf_workstation_model->model_private->finalize = finalize;
998 surf_workstation_model->extension.workstation.execute = execute;
999 surf_workstation_model->extension.workstation.sleep = action_sleep;
1000 surf_workstation_model->extension.workstation.get_state =
1002 surf_workstation_model->extension.workstation.get_speed = get_speed;
1003 surf_workstation_model->extension.workstation.get_available_speed =
1004 get_available_speed;
1005 surf_workstation_model->extension.workstation.communicate = communicate;
1006 surf_workstation_model->extension.workstation.execute_parallel_task =
1007 execute_parallel_task;
1008 surf_workstation_model->extension.workstation.get_route = get_route;
1009 surf_workstation_model->extension.workstation.get_route_size =
1011 surf_workstation_model->extension.workstation.get_link_bandwidth =
1013 surf_workstation_model->extension.workstation.get_link_latency =
1015 surf_workstation_model->extension.workstation.link_shared = link_shared;
1017 surf_workstation_model->get_properties = get_properties;
1019 link_set = xbt_dict_new();
1021 if (!ptask_maxmin_system)
1022 ptask_maxmin_system = lmm_system_new();
1025 /**************************************/
1026 /*************** Generic **************/
1027 /**************************************/
1028 void surf_workstation_model_init_ptask_L07(const char *filename)
1030 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1031 xbt_assert0(!surf_network_model, "network model type already defined");
1032 model_init_internal();
1033 define_callbacks(filename);
1035 update_model_description(surf_workstation_model_description,
1036 "ptask_L07", surf_workstation_model);
1037 xbt_dynar_push(model_list, &surf_workstation_model);