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 /* action_get_state is inherited from the surf module */
132 static void action_use(surf_action_t action)
138 static int action_free(surf_action_t action)
142 if (!action->refcount) {
143 xbt_swag_remove(action, action->state_set);
144 if (((surf_action_workstation_L07_t) action)->variable)
145 lmm_variable_free(ptask_maxmin_system,
146 ((surf_action_workstation_L07_t) action)->variable);
147 free(((surf_action_workstation_L07_t) action)->workstation_list);
148 free(((surf_action_workstation_L07_t) action)->communication_amount);
149 free(((surf_action_workstation_L07_t) action)->computation_amount);
156 static void action_cancel(surf_action_t action)
158 surf_action_state_set(action, SURF_ACTION_FAILED);
162 /* action_change_state is inherited from the surf module */
163 /* action_set_data is inherited from the surf module */
165 static void action_suspend(surf_action_t action)
167 XBT_IN1("(%p))", action);
168 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
169 ((surf_action_workstation_L07_t) action)->suspended = 1;
170 lmm_update_variable_weight(ptask_maxmin_system,
171 ((surf_action_workstation_L07_t)
172 action)->variable, 0.0);
177 static void action_resume(surf_action_t action)
179 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
181 XBT_IN1("(%p)", act);
182 if (act->suspended != 2) {
183 lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
189 static int action_is_suspended(surf_action_t action)
191 return (((surf_action_workstation_L07_t) action)->suspended == 1);
194 static void action_set_max_duration(surf_action_t action, double duration)
195 { /* FIXME: should inherit */
196 XBT_IN2("(%p,%g)", action, duration);
197 action->max_duration = duration;
202 static void action_set_priority(surf_action_t action, double priority)
203 { /* FIXME: should inherit */
204 XBT_IN2("(%p,%g)", action, priority);
205 action->priority = priority;
209 /**************************************/
210 /******* Resource Private **********/
211 /**************************************/
213 static int resource_used(void *resource_id)
215 /* We can freely cast as a link_L07_t because it has
216 the same prefix as cpu_L07_t */
217 return lmm_constraint_used(ptask_maxmin_system,
218 ((link_L07_t) resource_id)->constraint);
222 static double share_resources(double now)
224 s_surf_action_workstation_L07_t s_action;
225 surf_action_workstation_L07_t action = NULL;
227 xbt_swag_t running_actions =
228 surf_workstation_model->states.running_action_set;
229 double min = generic_maxmin_share_resources(running_actions,
230 xbt_swag_offset(s_action,
235 xbt_swag_foreach(action, running_actions) {
236 if (action->latency > 0) {
238 min = action->latency;
239 DEBUG3("Updating min (value) with %p (start %f): %f", action,
240 action->generic_action.start, min);
241 } else if (action->latency < min) {
242 min = action->latency;
243 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
244 action->generic_action.start, min);
249 DEBUG1("min value : %f", min);
254 static void update_actions_state(double now, double delta)
257 surf_action_workstation_L07_t action = NULL;
258 surf_action_workstation_L07_t next_action = NULL;
259 xbt_swag_t running_actions =
260 surf_workstation_model->states.running_action_set;
262 xbt_swag_foreach_safe(action, next_action, running_actions) {
264 if (action->latency > 0) {
265 if (action->latency > deltap) {
266 double_update(&(action->latency), deltap);
269 double_update(&(deltap), action->latency);
270 action->latency = 0.0;
272 if ((action->latency == 0.0) && (action->suspended == 0)) {
273 update_action_bound(action);
274 lmm_update_variable_weight(ptask_maxmin_system, action->variable,
278 DEBUG3("Action (%p) : remains (%g) updated by %g.",
279 action, action->generic_action.remains,
280 lmm_variable_getvalue(action->variable) * delta);
281 double_update(&(action->generic_action.remains),
282 lmm_variable_getvalue(action->variable) * delta);
284 if (action->generic_action.max_duration != NO_MAX_DURATION)
285 double_update(&(action->generic_action.max_duration), delta);
287 DEBUG2("Action (%p) : remains (%g).",
288 action, action->generic_action.remains);
289 if ((action->generic_action.remains <= 0) &&
290 (lmm_get_variable_weight(action->variable) > 0)) {
291 action->generic_action.finish = surf_get_clock();
292 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
293 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
294 (action->generic_action.max_duration <= 0)) {
295 action->generic_action.finish = surf_get_clock();
296 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
298 /* Need to check that none of the model has failed */
299 lmm_constraint_t cnst = NULL;
301 void *constraint_id = NULL;
304 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
306 constraint_id = lmm_constraint_id(cnst);
308 /* if(((link_L07_t)constraint_id)->type== */
309 /* SURF_WORKSTATION_RESOURCE_LINK) { */
310 /* DEBUG2("Checking for link %s (%p)", */
311 /* ((link_L07_t)constraint_id)->name, */
312 /* ((link_L07_t)constraint_id)); */
314 /* if(((cpu_L07_t)constraint_id)->type== */
315 /* SURF_WORKSTATION_RESOURCE_CPU) { */
316 /* DEBUG3("Checking for cpu %s (%p) : %s", */
317 /* ((cpu_L07_t)constraint_id)->name, */
318 /* ((cpu_L07_t)constraint_id), */
319 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
322 if (((((link_L07_t) constraint_id)->type ==
323 SURF_WORKSTATION_RESOURCE_LINK) &&
324 (((link_L07_t) constraint_id)->state_current ==
326 ((((cpu_L07_t) constraint_id)->type ==
327 SURF_WORKSTATION_RESOURCE_CPU) &&
328 (((cpu_L07_t) constraint_id)->state_current == SURF_CPU_OFF))) {
329 DEBUG1("Action (%p) Failed!!", action);
330 action->generic_action.finish = surf_get_clock();
331 surf_action_state_set((surf_action_t) action,
341 static void update_resource_state(void *id,
342 tmgr_trace_event_t event_type,
343 double value, double date)
346 link_L07_t nw_link = id;
348 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
349 DEBUG2("Updating link %s (%p)", nw_link->generic_resource.name, nw_link);
350 if (event_type == nw_link->bw_event) {
351 nw_link->bw_current = value;
352 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
353 nw_link->bw_current);
354 } else if (event_type == nw_link->lat_event) {
355 lmm_variable_t var = NULL;
356 surf_action_workstation_L07_t action = NULL;
357 lmm_element_t elem = NULL;
359 nw_link->lat_current = value;
360 while ((var = lmm_get_var_from_cnst
361 (ptask_maxmin_system, nw_link->constraint, &elem))) {
364 action = lmm_variable_id(var);
365 update_action_bound(action);
368 } else if (event_type == nw_link->state_event) {
370 nw_link->state_current = SURF_LINK_ON;
372 nw_link->state_current = SURF_LINK_OFF;
374 CRITICAL0("Unknown event ! \n");
378 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
379 DEBUG3("Updating cpu %s (%p) with value %g", cpu->generic_resource.name, cpu, value);
380 if (event_type == cpu->power_event) {
381 cpu->power_current = value;
382 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
383 cpu->power_current * cpu->power_scale);
384 } else if (event_type == cpu->state_event) {
386 cpu->state_current = SURF_CPU_ON;
388 cpu->state_current = SURF_CPU_OFF;
390 CRITICAL0("Unknown event ! \n");
400 static void finalize(void)
404 xbt_dict_free(&link_set);
405 if (parallel_task_link_set != NULL) {
406 xbt_dict_free(¶llel_task_link_set);
409 surf_model_exit(surf_workstation_model);
410 surf_workstation_model = NULL;
412 for (i = 0; i < nb_workstation; i++)
413 for (j = 0; j < nb_workstation; j++)
414 free(ROUTE(i, j).links);
416 routing_table = NULL;
419 if (ptask_maxmin_system) {
420 lmm_system_free(ptask_maxmin_system);
421 ptask_maxmin_system = NULL;
425 /**************************************/
426 /******* Resource Private **********/
427 /**************************************/
429 static e_surf_cpu_state_t resource_get_state(void *cpu)
431 return ((cpu_L07_t) cpu)->state_current;
434 static double get_speed(void *cpu, double load)
436 return load * (((cpu_L07_t) cpu)->power_scale);
439 static double get_available_speed(void *cpu)
441 return ((cpu_L07_t) cpu)->power_current;
444 static surf_action_t execute_parallel_task(int workstation_nb,
445 void **workstation_list,
446 double *computation_amount,
447 double *communication_amount,
448 double amount, double rate)
450 surf_action_workstation_L07_t action = NULL;
454 double latency = 0.0;
456 if (parallel_task_link_set == NULL)
457 parallel_task_link_set = xbt_dict_new();
459 xbt_dict_reset(parallel_task_link_set);
461 /* Compute the number of affected resources... */
462 for (i = 0; i < workstation_nb; i++) {
463 for (j = 0; j < workstation_nb; j++) {
464 cpu_L07_t card_src = workstation_list[i];
465 cpu_L07_t card_dst = workstation_list[j];
466 int route_size = ROUTE(card_src->id, card_dst->id).size;
467 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
470 if (communication_amount[i * workstation_nb + j] > 0)
471 for (k = 0; k < route_size; k++) {
472 lat += route[k]->lat_current;
473 xbt_dict_set(parallel_task_link_set, route[k]->generic_resource.name,
476 latency = MAX(latency, lat);
480 nb_link = xbt_dict_length(parallel_task_link_set);
481 xbt_dict_reset(parallel_task_link_set);
483 for (i = 0; i < workstation_nb; i++)
484 if (computation_amount[i] > 0)
487 action = xbt_new0(s_surf_action_workstation_L07_t, 1);
488 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
489 action, workstation_nb, nb_link);
490 action->generic_action.refcount = 1;
491 action->generic_action.cost = amount;
492 action->generic_action.remains = amount;
493 action->generic_action.max_duration = NO_MAX_DURATION;
494 action->generic_action.start = surf_get_clock();
495 action->generic_action.finish = -1.0;
496 action->generic_action.model_type = surf_workstation_model;
497 action->suspended = 0; /* Should be useless because of the
498 calloc but it seems to help valgrind... */
499 action->workstation_nb = workstation_nb;
500 action->workstation_list = (cpu_L07_t *) workstation_list;
501 action->computation_amount = computation_amount;
502 action->communication_amount = communication_amount;
503 action->latency = latency;
504 action->generic_action.state_set =
505 surf_workstation_model->states.running_action_set;
507 xbt_swag_insert(action, action->generic_action.state_set);
511 lmm_variable_new(ptask_maxmin_system, action, 1.0,
512 (action->rate > 0) ? action->rate : -1.0,
513 workstation_nb + nb_link);
515 if (action->latency > 0)
516 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
518 for (i = 0; i < workstation_nb; i++)
519 lmm_expand(ptask_maxmin_system,
520 ((cpu_L07_t) workstation_list[i])->constraint,
521 action->variable, computation_amount[i]);
523 for (i = 0; i < workstation_nb; i++) {
524 for (j = 0; j < workstation_nb; j++) {
525 cpu_L07_t card_src = workstation_list[i];
526 cpu_L07_t card_dst = workstation_list[j];
527 int route_size = ROUTE(card_src->id, card_dst->id).size;
528 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
530 if (communication_amount[i * workstation_nb + j] == 0.0)
532 for (k = 0; k < route_size; k++) {
533 lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
535 communication_amount[i * workstation_nb + j]);
540 if (nb_link + nb_host == 0) {
541 action->generic_action.cost = 1.0;
542 action->generic_action.remains = 0.0;
545 return (surf_action_t) action;
548 static surf_action_t execute(void *cpu, double size)
550 void **workstation_list = xbt_new0(void *, 1);
551 double *computation_amount = xbt_new0(double, 1);
552 double *communication_amount = xbt_new0(double, 1);
554 workstation_list[0] = cpu;
555 communication_amount[0] = 0.0;
556 computation_amount[0] = size;
558 return execute_parallel_task(1, workstation_list, computation_amount,
559 communication_amount, 1, -1);
562 static surf_action_t communicate(void *src, void *dst, double size,
565 void **workstation_list = xbt_new0(void *, 2);
566 double *computation_amount = xbt_new0(double, 2);
567 double *communication_amount = xbt_new0(double, 4);
568 surf_action_t res = NULL;
570 workstation_list[0] = src;
571 workstation_list[1] = dst;
572 communication_amount[1] = size;
574 res = execute_parallel_task(2, workstation_list,
575 computation_amount, communication_amount,
581 static surf_action_t action_sleep(void *cpu, double duration)
583 surf_action_workstation_L07_t action = NULL;
585 XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->generic_resource.name, duration);
587 action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
588 action->generic_action.max_duration = duration;
589 action->suspended = 2;
590 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
593 return (surf_action_t) action;
596 /* returns an array of link_L07_t */
597 static const void **get_route(void *src, void *dst)
599 cpu_L07_t card_src = src;
600 cpu_L07_t card_dst = dst;
601 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
603 return (const void **) route->links;
606 static int get_route_size(void *src, void *dst)
608 cpu_L07_t card_src = src;
609 cpu_L07_t card_dst = dst;
610 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
614 static double get_link_bandwidth(const void *link)
616 return ((link_L07_t) link)->bw_current;
619 static double get_link_latency(const void *link)
621 return ((link_L07_t) link)->lat_current;
624 static int link_shared(const void *link)
626 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
629 /**************************************/
630 /*** Resource Creation & Destruction **/
631 /**************************************/
633 static void cpu_free(void *cpu)
635 xbt_dict_free(&(((cpu_L07_t) cpu)->properties));
636 surf_resource_free(cpu);
639 static cpu_L07_t cpu_new(const char *name, double power_scale,
640 double power_initial,
641 tmgr_trace_t power_trace,
642 e_surf_cpu_state_t state_initial,
643 tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
645 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
646 xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
647 "Host '%s' declared several times in the platform file.", name);
649 cpu->generic_resource.model = surf_workstation_model;
650 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
651 cpu->generic_resource.name = xbt_strdup(name);
652 cpu->id = nb_workstation++;
654 cpu->power_scale = power_scale;
655 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
657 cpu->power_current = power_initial;
660 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
662 cpu->state_current = state_initial;
665 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
668 lmm_constraint_new(ptask_maxmin_system, cpu,
669 cpu->power_current * cpu->power_scale);
671 /*add the property set */
672 cpu->properties = current_property_set;
674 xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu,
680 static void create_routing_table(void)
682 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
685 static void parse_cpu_init(void)
687 double power_scale = 0.0;
688 double power_initial = 0.0;
689 tmgr_trace_t power_trace = NULL;
690 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
691 tmgr_trace_t state_trace = NULL;
693 power_scale = get_cpu_power(A_surfxml_host_power);
694 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
695 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
697 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
698 (A_surfxml_host_state == A_surfxml_host_state_OFF),
700 if (A_surfxml_host_state == A_surfxml_host_state_ON)
701 state_initial = SURF_CPU_ON;
702 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
703 state_initial = SURF_CPU_OFF;
704 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
706 current_property_set = xbt_dict_new();
707 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
708 state_initial, state_trace, current_property_set);
711 static void link_free(void *nw_link)
713 xbt_dict_free(&(((link_L07_t) nw_link)->properties));
714 surf_resource_free(nw_link);
717 static link_L07_t link_new(char *name,
719 tmgr_trace_t bw_trace,
721 tmgr_trace_t lat_trace,
724 tmgr_trace_t state_trace,
725 e_surf_link_sharing_policy_t
726 policy, xbt_dict_t properties)
728 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
729 xbt_assert1(!xbt_dict_get_or_null(link_set, name),
730 "Link '%s' declared several times in the platform file.", name);
732 nw_link->generic_resource.model = surf_workstation_model;
733 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
734 nw_link->generic_resource.name = name;
735 nw_link->bw_current = bw_initial;
738 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
739 nw_link->state_current = state_initial;
740 nw_link->lat_current = lat_initial;
743 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
745 nw_link->state_event =
746 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
748 nw_link->constraint =
749 lmm_constraint_new(ptask_maxmin_system, nw_link, nw_link->bw_current);
751 if (policy == SURF_LINK_FATPIPE)
752 lmm_constraint_shared(nw_link->constraint);
754 nw_link->properties = properties;
756 xbt_dict_set(link_set, name, nw_link, link_free);
761 static void parse_link_init(void)
765 tmgr_trace_t bw_trace;
767 tmgr_trace_t lat_trace;
768 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
769 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
770 tmgr_trace_t state_trace;
772 name_link = xbt_strdup(A_surfxml_link_id);
773 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
774 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
775 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
776 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
778 xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON)
779 || (A_surfxml_link_state ==
780 A_surfxml_link_state_OFF), "Invalid state");
781 if (A_surfxml_link_state == A_surfxml_link_state_ON)
782 state_initial_link = SURF_LINK_ON;
783 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
784 state_initial_link = SURF_LINK_OFF;
786 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
787 policy_initial_link = SURF_LINK_SHARED;
788 else if (A_surfxml_link_sharing_policy ==
789 A_surfxml_link_sharing_policy_FATPIPE)
790 policy_initial_link = SURF_LINK_FATPIPE;
792 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
794 current_property_set = xbt_dict_new();
795 link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
796 state_initial_link, state_trace, policy_initial_link,
797 current_property_set);
800 static void route_new(int src_id, int dst_id,
801 link_L07_t * link_list, int nb_link)
803 route_L07_t route = &(ROUTE(src_id, dst_id));
805 route->size = nb_link;
806 route->links = link_list =
807 xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
811 static int src_id = -1;
812 static int dst_id = -1;
814 static void parse_route_set_endpoints(void)
816 cpu_L07_t cpu_tmp = NULL;
819 (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
820 A_surfxml_route_src);
821 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
823 src_id = cpu_tmp->id;
826 (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
827 A_surfxml_route_dst);
828 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
830 dst_id = cpu_tmp->id;
832 route_action = A_surfxml_route_action;
835 static void parse_route_set_route(void)
838 if (src_id != -1 && dst_id != -1) {
839 name = bprintf("%x#%x", src_id, dst_id);
840 manage_route(route_table, name, route_action, 0);
845 static void add_loopback(void)
849 /* Adding loopback if needed */
850 for (i = 0; i < nb_workstation; i++)
851 if (!ROUTE(i, i).size) {
853 loopback = link_new(xbt_strdup("__MSG_loopback__"),
854 498000000, NULL, 0.000015, NULL,
855 SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
857 ROUTE(i, i).size = 1;
858 ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
859 ROUTE(i, i).links[0] = loopback;
863 static void add_route(void)
867 unsigned int cpt = 0;
868 int link_list_capacity = 0;
869 link_L07_t *link_list = NULL;
870 xbt_dict_cursor_t cursor = NULL;
871 char *key, *data, *end;
872 const char *sep = "#";
873 xbt_dynar_t links, keys;
876 if (routing_table == NULL)
877 create_routing_table();
879 xbt_dict_foreach(route_table, cursor, key, data) {
881 links = (xbt_dynar_t) data;
882 keys = xbt_str_split_str(key, sep);
884 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
885 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
886 xbt_dynar_free(&keys);
888 link_list_capacity = xbt_dynar_length(links);
889 link_list = xbt_new(link_L07_t, link_list_capacity);
892 xbt_dynar_foreach(links, cpt, link) {
894 link_list[nb_link++] = xbt_dict_get(link_set, link);
897 RETHROW1("Link %s not found (dict raised this exception: %s)", link);
900 route_new(src_id, dst_id, link_list, nb_link);
904 static void add_traces(void)
906 xbt_dict_cursor_t cursor = NULL;
907 char *trace_name, *elm;
909 if (!trace_connect_list_host_avail)
912 /* Connect traces relative to cpu */
913 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
914 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
915 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
917 xbt_assert1(host, "Host %s undefined", elm);
918 xbt_assert1(trace, "Trace %s undefined", trace_name);
920 host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
923 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
924 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
925 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
927 xbt_assert1(host, "Host %s undefined", elm);
928 xbt_assert1(trace, "Trace %s undefined", trace_name);
930 host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
933 /* Connect traces relative to network */
934 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
935 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
936 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
938 xbt_assert1(link, "Link %s undefined", elm);
939 xbt_assert1(trace, "Trace %s undefined", trace_name);
941 link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
944 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
945 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
946 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
948 xbt_assert1(link, "Link %s undefined", elm);
949 xbt_assert1(trace, "Trace %s undefined", trace_name);
951 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
954 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
955 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
956 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
958 xbt_assert1(link, "Link %s undefined", elm);
959 xbt_assert1(trace, "Trace %s undefined", trace_name);
961 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
965 static void define_callbacks(const char *file)
967 /* Adding callback functions */
968 surf_parse_reset_parser();
969 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
970 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
971 surfxml_add_callback(STag_surfxml_route_cb_list,
972 &parse_route_set_endpoints);
973 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
974 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
975 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
976 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
980 /**************************************/
981 /********* Module creation ***********/
982 /**************************************/
984 static void model_init_internal(void)
986 surf_workstation_model = surf_model_init();
988 surf_workstation_model->action_use = action_use;
989 surf_workstation_model->action_free = action_free;
990 surf_workstation_model->action_cancel = action_cancel;
991 surf_workstation_model->action_state_set = surf_action_state_set;
992 surf_workstation_model->suspend = action_suspend;
993 surf_workstation_model->resume = action_resume;
994 surf_workstation_model->is_suspended = action_is_suspended;
995 surf_workstation_model->set_max_duration = action_set_max_duration;
996 surf_workstation_model->set_priority = action_set_priority;
997 surf_workstation_model->name = "Workstation ptask_L07";
999 surf_workstation_model->model_private->resource_used = resource_used;
1000 surf_workstation_model->model_private->share_resources = share_resources;
1001 surf_workstation_model->model_private->update_actions_state =
1002 update_actions_state;
1003 surf_workstation_model->model_private->update_resource_state =
1004 update_resource_state;
1005 surf_workstation_model->model_private->finalize = finalize;
1007 surf_workstation_model->extension.workstation.execute = execute;
1008 surf_workstation_model->extension.workstation.sleep = action_sleep;
1009 surf_workstation_model->extension.workstation.get_state =
1011 surf_workstation_model->extension.workstation.get_speed = get_speed;
1012 surf_workstation_model->extension.workstation.get_available_speed =
1013 get_available_speed;
1014 surf_workstation_model->extension.workstation.communicate = communicate;
1015 surf_workstation_model->extension.workstation.execute_parallel_task =
1016 execute_parallel_task;
1017 surf_workstation_model->extension.workstation.get_route = get_route;
1018 surf_workstation_model->extension.workstation.get_route_size =
1020 surf_workstation_model->extension.workstation.get_link_bandwidth =
1022 surf_workstation_model->extension.workstation.get_link_latency =
1024 surf_workstation_model->extension.workstation.link_shared = link_shared;
1026 surf_workstation_model->get_properties = get_properties;
1028 link_set = xbt_dict_new();
1030 if (!ptask_maxmin_system)
1031 ptask_maxmin_system = lmm_system_new();
1034 /**************************************/
1035 /*************** Generic **************/
1036 /**************************************/
1037 void surf_workstation_model_init_ptask_L07(const char *filename)
1039 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1040 xbt_assert0(!surf_network_model, "network model type already defined");
1041 model_init_internal();
1042 define_callbacks(filename);
1044 update_model_description(surf_workstation_model_description,
1045 "ptask_L07", surf_workstation_model);
1046 xbt_dynar_push(model_list, &surf_workstation_model);