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;
107 lat * action->communication_amount[i * workstation_nb + j]);
111 lat_bound = sg_tcp_gamma / (2.0 * lat_current);
112 DEBUG2("action (%p) : lat_bound = %g", action, lat_bound);
113 if ((action->latency == 0.0) && (action->suspended == 0)) {
114 if (action->rate < 0)
115 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
118 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
119 min(action->rate, lat_bound));
123 /**************************************/
124 /******* Resource Public **********/
125 /**************************************/
127 static void *name_service(const char *name)
129 return xbt_dict_get_or_null(workstation_set, name);
132 static const char *get_resource_name(void *resource_id)
134 /* We can freely cast as a cpu_L07_t because it has the same
135 prefix as link_L07_t. However, only cpu_L07_t
136 will theoretically be given as an argument here. */
138 return ((cpu_L07_t) resource_id)->name;
141 static xbt_dict_t get_properties(void *r)
143 /* We can freely cast as a cpu_L07_t since it has the same prefix than link_L07_t */
144 return ((cpu_L07_t) r)->properties;
147 /* action_get_state is inherited from the surf module */
149 static void action_use(surf_action_t action)
155 static int action_free(surf_action_t action)
159 if (!action->refcount) {
160 xbt_swag_remove(action, action->state_set);
161 if (((surf_action_workstation_L07_t) action)->variable)
162 lmm_variable_free(ptask_maxmin_system,
163 ((surf_action_workstation_L07_t) action)->variable);
164 free(((surf_action_workstation_L07_t) action)->workstation_list);
165 free(((surf_action_workstation_L07_t) action)->communication_amount);
166 free(((surf_action_workstation_L07_t) action)->computation_amount);
173 static void action_cancel(surf_action_t action)
175 surf_action_change_state(action, SURF_ACTION_FAILED);
179 /* action_change_state is inherited from the surf module */
180 /* action_set_data is inherited from the surf module */
182 static void action_suspend(surf_action_t action)
184 XBT_IN1("(%p))", action);
185 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
186 ((surf_action_workstation_L07_t) action)->suspended = 1;
187 lmm_update_variable_weight(ptask_maxmin_system,
188 ((surf_action_workstation_L07_t)
189 action)->variable, 0.0);
194 static void action_resume(surf_action_t action)
196 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
198 XBT_IN1("(%p)", act);
199 if (act->suspended != 2) {
200 lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
206 static int action_is_suspended(surf_action_t action)
208 return (((surf_action_workstation_L07_t) action)->suspended == 1);
211 static void action_set_max_duration(surf_action_t action, double duration)
212 { /* FIXME: should inherit */
213 XBT_IN2("(%p,%g)", action, duration);
214 action->max_duration = duration;
219 static void action_set_priority(surf_action_t action, double priority)
220 { /* FIXME: should inherit */
221 XBT_IN2("(%p,%g)", action, priority);
222 action->priority = priority;
226 /**************************************/
227 /******* Resource Private **********/
228 /**************************************/
230 static int resource_used(void *resource_id)
232 /* We can freely cast as a link_L07_t because it has
233 the same prefix as cpu_L07_t */
234 return lmm_constraint_used(ptask_maxmin_system,
235 ((link_L07_t) resource_id)->constraint);
239 static double share_resources(double now)
241 s_surf_action_workstation_L07_t s_action;
242 surf_action_workstation_L07_t action = NULL;
244 xbt_swag_t running_actions =
245 surf_workstation_model->common_public.states.running_action_set;
246 double min = generic_maxmin_share_resources(running_actions,
247 xbt_swag_offset(s_action,
252 xbt_swag_foreach(action, running_actions) {
253 if (action->latency > 0) {
255 min = action->latency;
256 DEBUG3("Updating min (value) with %p (start %f): %f", action,
257 action->generic_action.start, min);
258 } else if (action->latency < min) {
259 min = action->latency;
260 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
261 action->generic_action.start, min);
266 DEBUG1("min value : %f", min);
271 static void update_actions_state(double now, double delta)
274 surf_action_workstation_L07_t action = NULL;
275 surf_action_workstation_L07_t next_action = NULL;
276 xbt_swag_t running_actions =
277 surf_workstation_model->common_public.states.running_action_set;
279 xbt_swag_foreach_safe(action, next_action, running_actions) {
281 if (action->latency > 0) {
282 if (action->latency > deltap) {
283 double_update(&(action->latency), deltap);
286 double_update(&(deltap), action->latency);
287 action->latency = 0.0;
289 if ((action->latency == 0.0) && (action->suspended == 0)) {
290 update_action_bound(action);
291 lmm_update_variable_weight(ptask_maxmin_system, action->variable,
295 DEBUG3("Action (%p) : remains (%g) updated by %g.",
296 action, action->generic_action.remains,
297 lmm_variable_getvalue(action->variable) * delta);
298 double_update(&(action->generic_action.remains),
299 lmm_variable_getvalue(action->variable) * delta);
301 if (action->generic_action.max_duration != NO_MAX_DURATION)
302 double_update(&(action->generic_action.max_duration), delta);
304 DEBUG2("Action (%p) : remains (%g).",
305 action, action->generic_action.remains);
306 if ((action->generic_action.remains <= 0) &&
307 (lmm_get_variable_weight(action->variable) > 0)) {
308 action->generic_action.finish = surf_get_clock();
309 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
310 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
311 (action->generic_action.max_duration <= 0)) {
312 action->generic_action.finish = surf_get_clock();
313 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
315 /* Need to check that none of the model has failed */
316 lmm_constraint_t cnst = NULL;
318 void *constraint_id = NULL;
321 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
323 constraint_id = lmm_constraint_id(cnst);
325 /* if(((link_L07_t)constraint_id)->type== */
326 /* SURF_WORKSTATION_RESOURCE_LINK) { */
327 /* DEBUG2("Checking for link %s (%p)", */
328 /* ((link_L07_t)constraint_id)->name, */
329 /* ((link_L07_t)constraint_id)); */
331 /* if(((cpu_L07_t)constraint_id)->type== */
332 /* SURF_WORKSTATION_RESOURCE_CPU) { */
333 /* DEBUG3("Checking for cpu %s (%p) : %s", */
334 /* ((cpu_L07_t)constraint_id)->name, */
335 /* ((cpu_L07_t)constraint_id), */
336 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
339 if (((((link_L07_t) constraint_id)->type ==
340 SURF_WORKSTATION_RESOURCE_LINK) &&
341 (((link_L07_t) constraint_id)->state_current ==
343 ((((cpu_L07_t) constraint_id)->type ==
344 SURF_WORKSTATION_RESOURCE_CPU) &&
345 (((cpu_L07_t) constraint_id)->state_current == SURF_CPU_OFF))) {
346 DEBUG1("Action (%p) Failed!!", action);
347 action->generic_action.finish = surf_get_clock();
348 surf_action_change_state((surf_action_t) action,
358 static void update_resource_state(void *id,
359 tmgr_trace_event_t event_type,
360 double value, double date)
363 link_L07_t nw_link = id;
365 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
366 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
367 if (event_type == nw_link->bw_event) {
368 nw_link->bw_current = value;
369 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
370 nw_link->bw_current);
371 } else if (event_type == nw_link->lat_event) {
372 lmm_variable_t var = NULL;
373 surf_action_workstation_L07_t action = NULL;
374 lmm_element_t elem = NULL;
376 nw_link->lat_current = value;
377 while ((var = lmm_get_var_from_cnst
378 (ptask_maxmin_system, nw_link->constraint, &elem))) {
381 action = lmm_variable_id(var);
382 update_action_bound(action);
385 } else if (event_type == nw_link->state_event) {
387 nw_link->state_current = SURF_LINK_ON;
389 nw_link->state_current = SURF_LINK_OFF;
391 CRITICAL0("Unknown event ! \n");
395 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
396 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
397 if (event_type == cpu->power_event) {
398 cpu->power_current = value;
399 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
400 cpu->power_current * cpu->power_scale);
401 } else if (event_type == cpu->state_event) {
403 cpu->state_current = SURF_CPU_ON;
405 cpu->state_current = SURF_CPU_OFF;
407 CRITICAL0("Unknown event ! \n");
417 static void finalize(void)
421 xbt_dict_free(&link_set);
422 xbt_dict_free(&workstation_set);
423 if (parallel_task_link_set != NULL) {
424 xbt_dict_free(¶llel_task_link_set);
427 surf_model_exit((surf_model_t)surf_workstation_model);
429 free(surf_workstation_model->extension_public);
431 free(surf_workstation_model);
432 surf_workstation_model = NULL;
434 for (i = 0; i < nb_workstation; i++)
435 for (j = 0; j < nb_workstation; j++)
436 free(ROUTE(i, j).links);
438 routing_table = NULL;
441 if (ptask_maxmin_system) {
442 lmm_system_free(ptask_maxmin_system);
443 ptask_maxmin_system = NULL;
447 /**************************************/
448 /******* Resource Private **********/
449 /**************************************/
451 static e_surf_cpu_state_t resource_get_state(void *cpu)
453 return ((cpu_L07_t) cpu)->state_current;
456 static double get_speed(void *cpu, double load)
458 return load * (((cpu_L07_t) cpu)->power_scale);
461 static double get_available_speed(void *cpu)
463 return ((cpu_L07_t) cpu)->power_current;
466 static surf_action_t execute_parallel_task(int workstation_nb,
467 void **workstation_list,
468 double *computation_amount,
469 double *communication_amount,
470 double amount, double rate)
472 surf_action_workstation_L07_t action = NULL;
476 double latency = 0.0;
478 if (parallel_task_link_set == NULL)
479 parallel_task_link_set = xbt_dict_new();
481 xbt_dict_reset(parallel_task_link_set);
483 /* Compute the number of affected resources... */
484 for (i = 0; i < workstation_nb; i++) {
485 for (j = 0; j < workstation_nb; j++) {
486 cpu_L07_t card_src = workstation_list[i];
487 cpu_L07_t card_dst = workstation_list[j];
488 int route_size = ROUTE(card_src->id, card_dst->id).size;
489 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
492 if (communication_amount[i * workstation_nb + j] > 0)
493 for (k = 0; k < route_size; k++) {
494 lat += route[k]->lat_current;
495 xbt_dict_set(parallel_task_link_set, route[k]->name,
498 latency = MAX(latency, lat);
502 nb_link = xbt_dict_length(parallel_task_link_set);
503 xbt_dict_reset(parallel_task_link_set);
505 for (i = 0; i < workstation_nb; i++)
506 if (computation_amount[i] > 0)
509 action = xbt_new0(s_surf_action_workstation_L07_t, 1);
510 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
511 action, workstation_nb, nb_link);
512 action->generic_action.refcount = 1;
513 action->generic_action.cost = amount;
514 action->generic_action.remains = amount;
515 action->generic_action.max_duration = NO_MAX_DURATION;
516 action->generic_action.start = surf_get_clock();
517 action->generic_action.finish = -1.0;
518 action->generic_action.model_type = (surf_model_t) surf_workstation_model;
519 action->suspended = 0; /* Should be useless because of the
520 calloc but it seems to help valgrind... */
521 action->workstation_nb = workstation_nb;
522 action->workstation_list = (cpu_L07_t *) workstation_list;
523 action->computation_amount = computation_amount;
524 action->communication_amount = communication_amount;
525 action->latency = latency;
526 action->generic_action.state_set =
527 surf_workstation_model->common_public.states.running_action_set;
529 xbt_swag_insert(action, action->generic_action.state_set);
533 lmm_variable_new(ptask_maxmin_system, action, 1.0,
534 (action->rate > 0) ? action->rate : -1.0,
535 workstation_nb + nb_link);
537 if (action->latency > 0)
538 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
540 for (i = 0; i < workstation_nb; i++)
541 lmm_expand(ptask_maxmin_system,
542 ((cpu_L07_t) workstation_list[i])->constraint,
543 action->variable, computation_amount[i]);
545 for (i = 0; i < workstation_nb; i++) {
546 for (j = 0; j < workstation_nb; j++) {
547 cpu_L07_t card_src = workstation_list[i];
548 cpu_L07_t card_dst = workstation_list[j];
549 int route_size = ROUTE(card_src->id, card_dst->id).size;
550 link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
552 if (communication_amount[i * workstation_nb + j] == 0.0)
554 for (k = 0; k < route_size; k++) {
555 lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
557 communication_amount[i * workstation_nb + j]);
562 if (nb_link + nb_host == 0) {
563 action->generic_action.cost = 1.0;
564 action->generic_action.remains = 0.0;
567 return (surf_action_t) action;
570 static surf_action_t execute(void *cpu, double size)
572 void **workstation_list = xbt_new0(void *, 1);
573 double *computation_amount = xbt_new0(double, 1);
574 double *communication_amount = xbt_new0(double, 1);
576 workstation_list[0] = cpu;
577 communication_amount[0] = 0.0;
578 computation_amount[0] = size;
580 return execute_parallel_task(1, workstation_list, computation_amount,
581 communication_amount, 1, -1);
584 static surf_action_t communicate(void *src, void *dst, double size,
587 void **workstation_list = xbt_new0(void *, 2);
588 double *computation_amount = xbt_new0(double, 2);
589 double *communication_amount = xbt_new0(double, 4);
590 surf_action_t res = NULL;
592 workstation_list[0] = src;
593 workstation_list[1] = dst;
594 communication_amount[1] = size;
596 res = execute_parallel_task(2, workstation_list,
597 computation_amount, communication_amount,
603 static surf_action_t action_sleep(void *cpu, double duration)
605 surf_action_workstation_L07_t action = NULL;
607 XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->name, duration);
609 action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
610 action->generic_action.max_duration = duration;
611 action->suspended = 2;
612 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
615 return (surf_action_t) action;
618 /* returns an array of link_L07_t */
619 static const void **get_route(void *src, void *dst)
621 cpu_L07_t card_src = src;
622 cpu_L07_t card_dst = dst;
623 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
625 return (const void **) route->links;
628 static int get_route_size(void *src, void *dst)
630 cpu_L07_t card_src = src;
631 cpu_L07_t card_dst = dst;
632 route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
636 static const char *get_link_name(const void *link)
638 return ((link_L07_t) link)->name;
641 static double get_link_bandwidth(const void *link)
643 return ((link_L07_t) link)->bw_current;
646 static double get_link_latency(const void *link)
648 return ((link_L07_t) link)->lat_current;
651 static int link_shared(const void *link)
653 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
656 /**************************************/
657 /*** Resource Creation & Destruction **/
658 /**************************************/
660 static void cpu_free(void *cpu)
662 free(((cpu_L07_t) cpu)->name);
663 xbt_dict_free(&(((cpu_L07_t) cpu)->properties));
667 static cpu_L07_t cpu_new(const char *name, double power_scale,
668 double power_initial,
669 tmgr_trace_t power_trace,
670 e_surf_cpu_state_t state_initial,
671 tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
673 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
674 xbt_assert1(!xbt_dict_get_or_null(workstation_set, name),
675 "Host '%s' declared several times in the platform file.", name);
677 cpu->model = (surf_model_t) surf_workstation_model;
678 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
679 cpu->name = xbt_strdup(name);
680 cpu->id = nb_workstation++;
682 cpu->power_scale = power_scale;
683 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
685 cpu->power_current = power_initial;
688 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
690 cpu->state_current = state_initial;
693 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
696 lmm_constraint_new(ptask_maxmin_system, cpu,
697 cpu->power_current * cpu->power_scale);
699 /*add the property set */
700 cpu->properties = current_property_set;
702 xbt_dict_set(workstation_set, name, cpu, cpu_free);
707 static void create_routing_table(void)
709 routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
712 static void parse_cpu_init(void)
714 double power_scale = 0.0;
715 double power_initial = 0.0;
716 tmgr_trace_t power_trace = NULL;
717 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
718 tmgr_trace_t state_trace = NULL;
720 power_scale = get_cpu_power(A_surfxml_host_power);
721 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
722 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
724 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
725 (A_surfxml_host_state == A_surfxml_host_state_OFF),
727 if (A_surfxml_host_state == A_surfxml_host_state_ON)
728 state_initial = SURF_CPU_ON;
729 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
730 state_initial = SURF_CPU_OFF;
731 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
733 current_property_set = xbt_dict_new();
734 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
735 state_initial, state_trace, current_property_set);
738 static void link_free(void *nw_link)
740 free(((link_L07_t) nw_link)->name);
741 xbt_dict_free(&(((link_L07_t) nw_link)->properties));
745 static link_L07_t link_new(char *name,
747 tmgr_trace_t bw_trace,
749 tmgr_trace_t lat_trace,
752 tmgr_trace_t state_trace,
753 e_surf_link_sharing_policy_t
754 policy, xbt_dict_t properties)
756 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
757 xbt_assert1(!xbt_dict_get_or_null(link_set, name),
758 "Link '%s' declared several times in the platform file.", name);
760 nw_link->model = (surf_model_t) surf_workstation_model;
761 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
762 nw_link->name = name;
763 nw_link->bw_current = bw_initial;
766 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
767 nw_link->state_current = state_initial;
768 nw_link->lat_current = lat_initial;
771 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
773 nw_link->state_event =
774 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
776 nw_link->constraint =
777 lmm_constraint_new(ptask_maxmin_system, nw_link, nw_link->bw_current);
779 if (policy == SURF_LINK_FATPIPE)
780 lmm_constraint_shared(nw_link->constraint);
782 nw_link->properties = properties;
784 xbt_dict_set(link_set, name, nw_link, link_free);
789 static void parse_link_init(void)
793 tmgr_trace_t bw_trace;
795 tmgr_trace_t lat_trace;
796 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
797 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
798 tmgr_trace_t state_trace;
800 name_link = xbt_strdup(A_surfxml_link_id);
801 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
802 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
803 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
804 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
806 xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON)
807 || (A_surfxml_link_state ==
808 A_surfxml_link_state_OFF), "Invalid state");
809 if (A_surfxml_link_state == A_surfxml_link_state_ON)
810 state_initial_link = SURF_LINK_ON;
811 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
812 state_initial_link = SURF_LINK_OFF;
814 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
815 policy_initial_link = SURF_LINK_SHARED;
816 else if (A_surfxml_link_sharing_policy ==
817 A_surfxml_link_sharing_policy_FATPIPE)
818 policy_initial_link = SURF_LINK_FATPIPE;
820 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
822 current_property_set = xbt_dict_new();
823 link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
824 state_initial_link, state_trace, policy_initial_link,
825 current_property_set);
828 static void route_new(int src_id, int dst_id,
829 link_L07_t * link_list, int nb_link)
831 route_L07_t route = &(ROUTE(src_id, dst_id));
833 route->size = nb_link;
834 route->links = link_list =
835 xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
839 static int src_id = -1;
840 static int dst_id = -1;
842 static void parse_route_set_endpoints(void)
844 cpu_L07_t cpu_tmp = NULL;
846 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
847 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
849 src_id = cpu_tmp->id;
851 cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_dst);
852 xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
854 dst_id = cpu_tmp->id;
856 route_action = A_surfxml_route_action;
859 static void parse_route_set_route(void)
862 if (src_id != -1 && dst_id != -1) {
863 name = bprintf("%x#%x", src_id, dst_id);
864 manage_route(route_table, name, route_action, 0);
869 static void add_loopback(void)
873 /* Adding loopback if needed */
874 for (i = 0; i < nb_workstation; i++)
875 if (!ROUTE(i, i).size) {
877 loopback = link_new(xbt_strdup("__MSG_loopback__"),
878 498000000, NULL, 0.000015, NULL,
879 SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
881 ROUTE(i, i).size = 1;
882 ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
883 ROUTE(i, i).links[0] = loopback;
887 static void add_route(void)
891 unsigned int cpt = 0;
892 int link_list_capacity = 0;
893 link_L07_t *link_list = NULL;
894 xbt_dict_cursor_t cursor = NULL;
895 char *key, *data, *end;
896 const char *sep = "#";
897 xbt_dynar_t links, keys;
900 if (routing_table == NULL)
901 create_routing_table();
903 xbt_dict_foreach(route_table, cursor, key, data) {
905 links = (xbt_dynar_t) data;
906 keys = xbt_str_split_str(key, sep);
908 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
909 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
910 xbt_dynar_free(&keys);
912 link_list_capacity = xbt_dynar_length(links);
913 link_list = xbt_new(link_L07_t, link_list_capacity);
916 xbt_dynar_foreach(links, cpt, link) {
918 link_list[nb_link++] = xbt_dict_get(link_set, link);
921 RETHROW1("Link %s not found (dict raised this exception: %s)", link);
924 route_new(src_id, dst_id, link_list, nb_link);
928 static void add_traces(void)
930 xbt_dict_cursor_t cursor = NULL;
931 char *trace_name, *elm;
933 if (!trace_connect_list_host_avail)
936 /* Connect traces relative to cpu */
937 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
938 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
939 cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
941 xbt_assert1(host, "Host %s undefined", elm);
942 xbt_assert1(trace, "Trace %s undefined", trace_name);
944 host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
947 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
948 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
949 cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
951 xbt_assert1(host, "Host %s undefined", elm);
952 xbt_assert1(trace, "Trace %s undefined", trace_name);
954 host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
957 /* Connect traces relative to network */
958 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
959 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
960 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
962 xbt_assert1(link, "Link %s undefined", elm);
963 xbt_assert1(trace, "Trace %s undefined", trace_name);
965 link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
968 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
969 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
970 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
972 xbt_assert1(link, "Link %s undefined", elm);
973 xbt_assert1(trace, "Trace %s undefined", trace_name);
975 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
978 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
979 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
980 link_L07_t link = xbt_dict_get_or_null(link_set, elm);
982 xbt_assert1(link, "Link %s undefined", elm);
983 xbt_assert1(trace, "Trace %s undefined", trace_name);
985 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
989 xbt_dynar_foreach (traces_connect_list, cpt, value) {
990 trace_connect = xbt_str_split_str(value, "#");
991 trace_id = xbt_dynar_get_as(trace_connect, 0, char*);
992 connect_element = atoi(xbt_dynar_get_as(trace_connect, 1, char*));
993 connect_kind = atoi(xbt_dynar_get_as(trace_connect, 2, char*));
994 connector_id = xbt_dynar_get_as(trace_connect, 3, char*);
996 xbt_assert1((trace = xbt_dict_get_or_null(traces_set_list, trace_id)), "Trace %s undefined", trace_id);
998 if (connect_element == A_surfxml_trace_c_connect_element_HOST) {
999 xbt_assert1((host = xbt_dict_get_or_null(workstation_set, connector_id)), "Host %s undefined", connector_id);
1000 switch (connect_kind) {
1001 case A_surfxml_trace_c_connect_kind_AVAILABILITY: host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
1002 case A_surfxml_trace_c_connect_kind_POWER: host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
1006 xbt_assert1((link = xbt_dict_get_or_null(link_set, connector_id)), "Link %s undefined", connector_id);
1007 switch (connect_kind) {
1008 case A_surfxml_trace_c_connect_kind_AVAILABILITY: link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1009 case A_surfxml_trace_c_connect_kind_BANDWIDTH: link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1010 case A_surfxml_trace_c_connect_kind_LATENCY: link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
1017 static void define_callbacks(const char *file)
1019 /* Adding callback functions */
1020 surf_parse_reset_parser();
1021 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
1022 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
1023 surfxml_add_callback(STag_surfxml_route_cb_list,
1024 &parse_route_set_endpoints);
1025 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
1026 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
1027 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
1028 surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
1032 /**************************************/
1033 /********* Module creation ***********/
1034 /**************************************/
1036 static void model_init_internal(void)
1038 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1040 surf_model_init((surf_model_t)surf_workstation_model);
1041 surf_workstation_model->extension_public =
1042 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1044 surf_workstation_model->common_public.name_service = name_service;
1045 surf_workstation_model->common_public.get_resource_name =
1047 surf_workstation_model->common_public.action_get_state =
1048 surf_action_get_state;
1049 surf_workstation_model->common_public.action_get_start_time =
1050 surf_action_get_start_time;
1051 surf_workstation_model->common_public.action_get_finish_time =
1052 surf_action_get_finish_time;
1053 surf_workstation_model->common_public.action_use = action_use;
1054 surf_workstation_model->common_public.action_free = action_free;
1055 surf_workstation_model->common_public.action_cancel = action_cancel;
1056 surf_workstation_model->common_public.action_change_state =
1057 surf_action_change_state;
1058 surf_workstation_model->common_public.action_set_data =
1059 surf_action_set_data;
1060 surf_workstation_model->common_public.suspend = action_suspend;
1061 surf_workstation_model->common_public.resume = action_resume;
1062 surf_workstation_model->common_public.is_suspended = action_is_suspended;
1063 surf_workstation_model->common_public.set_max_duration =
1064 action_set_max_duration;
1065 surf_workstation_model->common_public.set_priority = action_set_priority;
1066 surf_workstation_model->common_public.name = "Workstation ptask_L07";
1068 surf_workstation_model->common_private->resource_used = resource_used;
1069 surf_workstation_model->common_private->share_resources = share_resources;
1070 surf_workstation_model->common_private->update_actions_state =
1071 update_actions_state;
1072 surf_workstation_model->common_private->update_resource_state =
1073 update_resource_state;
1074 surf_workstation_model->common_private->finalize = finalize;
1076 surf_workstation_model->extension_public->execute = execute;
1077 surf_workstation_model->extension_public->sleep = action_sleep;
1078 surf_workstation_model->extension_public->get_state = resource_get_state;
1079 surf_workstation_model->extension_public->get_speed = get_speed;
1080 surf_workstation_model->extension_public->get_available_speed =
1081 get_available_speed;
1082 surf_workstation_model->extension_public->communicate = communicate;
1083 surf_workstation_model->extension_public->execute_parallel_task =
1084 execute_parallel_task;
1085 surf_workstation_model->extension_public->get_route = get_route;
1086 surf_workstation_model->extension_public->get_route_size = get_route_size;
1087 surf_workstation_model->extension_public->get_link_name = get_link_name;
1088 surf_workstation_model->extension_public->get_link_bandwidth =
1090 surf_workstation_model->extension_public->get_link_latency =
1092 surf_workstation_model->extension_public->link_shared = link_shared;
1094 surf_workstation_model->common_public.get_properties = get_properties;
1096 workstation_set = xbt_dict_new();
1097 link_set = xbt_dict_new();
1099 if (!ptask_maxmin_system)
1100 ptask_maxmin_system = lmm_system_new();
1103 /**************************************/
1104 /*************** Generic **************/
1105 /**************************************/
1106 void surf_workstation_model_init_ptask_L07(const char *filename)
1108 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1109 xbt_assert0(!surf_network_model, "network model type already defined");
1110 model_init_internal();
1111 define_callbacks(filename);
1113 update_model_description(surf_workstation_model_description,
1115 (surf_model_t) surf_workstation_model);
1116 xbt_dynar_push(model_list, &surf_workstation_model);