3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "workstation_KCCFLN05_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
13 "Logging specific to the SURF workstation module (KCCFLN05)");
15 static int nb_workstation = 0;
16 static s_route_KCCFLN05_t *routing_table = NULL;
17 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
18 static network_link_KCCFLN05_t loopback = NULL;
19 static xbt_dict_t parallel_task_network_link_set = NULL;
20 //added to work with GTNETS
21 static xbt_dict_t router_set = NULL;
23 /*xbt_dict_t network_link_set = NULL;*/
26 /* convenient function */
27 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
30 surf_action_workstation_KCCFLN05_t action = NULL;
31 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
32 (!xbt_dynar_length(cpu->outgoing_communications))) {
33 /* No communications */
34 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
35 cpu->power_current * cpu->power_scale);
36 } else if ((!xbt_dynar_length(cpu->incomming_communications))
37 && (xbt_dynar_length(cpu->outgoing_communications))) {
39 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
40 cpu->power_current * cpu->power_scale *
41 cpu->interference_send);
42 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
43 lmm_elem_set_value(maxmin_system, cpu->constraint,
45 cpu->power_current * cpu->power_scale *
46 ROUTE(action->src->id,
47 action->dst->id).impact_on_src);
48 } else if ((xbt_dynar_length(cpu->incomming_communications))
49 && (!xbt_dynar_length(cpu->outgoing_communications))) {
51 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
52 cpu->power_current * cpu->power_scale *
53 cpu->interference_recv);
54 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
55 lmm_elem_set_value(maxmin_system, cpu->constraint,
57 cpu->power_current * cpu->power_scale *
58 ROUTE(action->src->id,
59 action->dst->id).impact_on_dst);
61 /* Emission & Reception */
62 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
63 cpu->power_current * cpu->power_scale *
64 cpu->interference_send_recv);
65 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
66 lmm_elem_set_value(maxmin_system, cpu->constraint,
68 cpu->power_current * cpu->power_scale *
69 ROUTE(action->src->id,
71 impact_on_src_with_other_recv);
72 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
73 lmm_elem_set_value(maxmin_system, cpu->constraint,
75 cpu->power_current * cpu->power_scale *
76 ROUTE(action->src->id,
78 impact_on_dst_with_other_send);
82 /**************************************/
83 /******* Resource Public **********/
84 /**************************************/
86 static void *name_service(const char *name)
92 res = xbt_dict_get(workstation_set, name);
94 if (e.category != not_found_error)
96 WARN1("Host '%s' not found, verifing if it is a router", name);
104 static const char *get_model_name(void *model_id)
106 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
107 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
108 will theoretically be given as an argument here. */
109 return ((cpu_KCCFLN05_t) model_id)->name;
112 /* action_get_state is inherited from the surf module */
114 static void action_use(surf_action_t action)
120 static int action_free(surf_action_t action)
123 surf_action_t act = NULL;
124 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
125 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
128 if (!action->using) {
129 xbt_swag_remove(action, action->state_set);
130 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
131 lmm_variable_free(maxmin_system,
132 ((surf_action_workstation_KCCFLN05_t) action)->
135 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
137 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
142 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
144 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
148 if (src && (!xbt_dynar_length(src->outgoing_communications)))
149 __update_cpu_usage(src);
150 if (dst && (!xbt_dynar_length(dst->incomming_communications)))
151 __update_cpu_usage(dst);
159 static void action_cancel(surf_action_t action)
161 surf_action_change_state(action, SURF_ACTION_FAILED);
165 static void action_recycle(surf_action_t action)
171 /* action_change_state is inherited from the surf module */
172 /* action_set_data is inherited from the surf module */
174 static void action_suspend(surf_action_t action)
176 XBT_IN1("(%p))", action);
177 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
178 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
179 lmm_update_variable_weight(maxmin_system,
180 ((surf_action_workstation_KCCFLN05_t)
181 action)->variable, 0.0);
186 static void action_resume(surf_action_t action)
188 XBT_IN1("(%p)", action);
189 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
190 if (((surf_action_workstation_KCCFLN05_t) action)->lat_current == 0.0)
191 lmm_update_variable_weight(maxmin_system,
192 ((surf_action_workstation_KCCFLN05_t)
193 action)->variable, action->priority);
195 lmm_update_variable_weight(maxmin_system,
196 ((surf_action_workstation_KCCFLN05_t)
198 ((surf_action_workstation_KCCFLN05_t)
199 action)->lat_current);
201 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
206 static int action_is_suspended(surf_action_t action)
208 return (((surf_action_workstation_KCCFLN05_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)
221 XBT_IN2("(%p,%g)", action, priority);
222 action->priority = priority;
223 lmm_update_variable_weight(maxmin_system, ((surf_action_workstation_KCCFLN05_t) action)->variable, priority);
228 /**************************************/
229 /******* Resource Private **********/
230 /**************************************/
232 static int model_used(void *model_id)
234 /* We can freely cast as a network_link_KCCFLN05_t because it has
235 the same prefix as cpu_KCCFLN05_t */
236 if (((cpu_KCCFLN05_t) model_id)->type ==
237 SURF_WORKSTATION_RESOURCE_CPU)
238 return (lmm_constraint_used
239 (maxmin_system, ((cpu_KCCFLN05_t) model_id)->constraint)
240 || ((((cpu_KCCFLN05_t) model_id)->bus) ?
241 lmm_constraint_used(maxmin_system,
242 ((cpu_KCCFLN05_t) model_id)->
245 return lmm_constraint_used(maxmin_system,
246 ((network_link_KCCFLN05_t) model_id)->
251 static double share_models(double now)
253 s_surf_action_workstation_KCCFLN05_t s_action;
254 surf_action_workstation_KCCFLN05_t action = NULL;
256 xbt_swag_t running_actions =
257 surf_workstation_model->common_public->states.running_action_set;
258 double min = generic_maxmin_share_models(running_actions,
259 xbt_swag_offset(s_action,
262 xbt_swag_foreach(action, running_actions) {
263 if (action->latency > 0) {
265 min = action->latency;
266 DEBUG3("Updating min (value) with %p (start %f): %f", action,
267 action->generic_action.start, min);
268 } else if (action->latency < min) {
269 min = action->latency;
270 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
271 action->generic_action.start, min);
276 DEBUG1("min value : %f", min);
281 static void update_actions_state(double now, double delta)
284 surf_action_workstation_KCCFLN05_t action = NULL;
285 surf_action_workstation_KCCFLN05_t next_action = NULL;
286 xbt_swag_t running_actions =
287 surf_workstation_model->common_public->states.running_action_set;
289 xbt_swag_foreach_safe(action, next_action, running_actions) {
291 if (action->latency > 0) {
292 if (action->latency > deltap) {
293 double_update(&(action->latency), deltap);
296 double_update(&(deltap), action->latency);
297 action->latency = 0.0;
299 if ((action->latency == 0.0) && (action->suspended == 0)) {
300 if ((action)->lat_current == 0.0)
301 lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
303 lmm_update_variable_weight(maxmin_system, action->variable,
304 action->lat_current);
307 DEBUG3("Action (%p) : remains (%g) updated by %g.",
308 action, action->generic_action.remains,
309 lmm_variable_getvalue(action->variable) * deltap);
310 double_update(&(action->generic_action.remains),
311 lmm_variable_getvalue(action->variable) * deltap);
313 if (action->generic_action.max_duration != NO_MAX_DURATION)
314 double_update(&(action->generic_action.max_duration), delta);
316 if ((action->generic_action.remains <= 0) &&
317 (lmm_get_variable_weight(action->variable) > 0)) {
318 action->generic_action.finish = surf_get_clock();
319 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
320 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
321 (action->generic_action.max_duration <= 0)) {
322 action->generic_action.finish = surf_get_clock();
323 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
325 /* Need to check that none of the model has failed */
326 lmm_constraint_t cnst = NULL;
328 void *constraint_id = NULL;
331 lmm_get_cnst_from_var(maxmin_system, action->variable,
333 constraint_id = lmm_constraint_id(cnst);
335 /* if(((network_link_KCCFLN05_t)constraint_id)->type== */
336 /* SURF_WORKSTATION_RESOURCE_LINK) { */
337 /* DEBUG2("Checking for link %s (%p)", */
338 /* ((network_link_KCCFLN05_t)constraint_id)->name, */
339 /* ((network_link_KCCFLN05_t)constraint_id)); */
341 /* if(((cpu_KCCFLN05_t)constraint_id)->type== */
342 /* SURF_WORKSTATION_RESOURCE_CPU) { */
343 /* DEBUG3("Checking for cpu %s (%p) : %s", */
344 /* ((cpu_KCCFLN05_t)constraint_id)->name, */
345 /* ((cpu_KCCFLN05_t)constraint_id), */
346 /* ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
349 if (((((network_link_KCCFLN05_t) constraint_id)->type ==
350 SURF_WORKSTATION_RESOURCE_LINK) &&
351 (((network_link_KCCFLN05_t) constraint_id)->state_current ==
352 SURF_NETWORK_LINK_OFF)) ||
353 ((((cpu_KCCFLN05_t) constraint_id)->type ==
354 SURF_WORKSTATION_RESOURCE_CPU) &&
355 (((cpu_KCCFLN05_t) constraint_id)->state_current ==
357 DEBUG1("Action (%p) Failed!!", action);
358 action->generic_action.finish = surf_get_clock();
359 surf_action_change_state((surf_action_t) action,
369 static void update_model_state(void *id,
370 tmgr_trace_event_t event_type,
373 cpu_KCCFLN05_t cpu = id;
374 network_link_KCCFLN05_t nw_link = id;
376 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
377 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
378 if (event_type == nw_link->bw_event) {
379 nw_link->bw_current = value;
380 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
381 nw_link->bw_current);
382 } else if (event_type == nw_link->lat_event) {
383 double delta = value - nw_link->lat_current;
384 lmm_variable_t var = NULL;
385 surf_action_workstation_KCCFLN05_t action = NULL;
387 nw_link->lat_current = value;
388 while (lmm_get_var_from_cnst
389 (maxmin_system, nw_link->constraint, &var)) {
390 action = lmm_variable_id(var);
391 action->lat_current += delta;
392 if (action->rate < 0)
393 lmm_update_variable_bound(maxmin_system, action->variable,
394 SG_TCP_CTE_GAMMA / (2.0 *
398 lmm_update_variable_bound(maxmin_system, action->variable,
400 SG_TCP_CTE_GAMMA / (2.0 *
403 if (action->suspended == 0)
404 lmm_update_variable_weight(maxmin_system, action->variable,
405 action->lat_current);
406 lmm_update_variable_latency(maxmin_system, action->variable,
411 } else if (event_type == nw_link->state_event) {
413 nw_link->state_current = SURF_NETWORK_LINK_ON;
415 nw_link->state_current = SURF_NETWORK_LINK_OFF;
417 CRITICAL0("Unknown event ! \n");
421 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
422 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
423 if (event_type == cpu->power_event) {
424 cpu->power_current = value;
425 __update_cpu_usage(cpu);
426 } else if (event_type == cpu->state_event) {
428 cpu->state_current = SURF_CPU_ON;
430 cpu->state_current = SURF_CPU_OFF;
432 CRITICAL0("Unknown event ! \n");
442 static void finalize(void)
446 xbt_dict_free(&network_link_set);
447 xbt_dict_free(&workstation_set);
448 xbt_dict_free(&router_set);
449 if (parallel_task_network_link_set != NULL) {
450 xbt_dict_free(¶llel_task_network_link_set);
452 xbt_swag_free(surf_workstation_model->common_public->states.
454 xbt_swag_free(surf_workstation_model->common_public->states.
456 xbt_swag_free(surf_workstation_model->common_public->states.
458 xbt_swag_free(surf_workstation_model->common_public->states.
461 free(surf_workstation_model->common_public);
462 free(surf_workstation_model->common_private);
463 free(surf_workstation_model->extension_public);
465 free(surf_workstation_model);
466 surf_workstation_model = NULL;
468 for (i = 0; i < nb_workstation; i++)
469 for (j = 0; j < nb_workstation; j++)
470 free(ROUTE(i, j).links);
472 routing_table = NULL;
476 lmm_system_free(maxmin_system);
477 maxmin_system = NULL;
481 /**************************************/
482 /******* Resource Private **********/
483 /**************************************/
485 static surf_action_t execute(void *cpu, double size)
487 surf_action_workstation_KCCFLN05_t action = NULL;
488 cpu_KCCFLN05_t CPU = cpu;
490 XBT_IN2("(%s,%g)", CPU->name, size);
491 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
493 action->generic_action.using = 1;
494 action->generic_action.cost = size;
495 action->generic_action.remains = size;
496 action->generic_action.priority = 1.0;
497 action->generic_action.max_duration = NO_MAX_DURATION;
498 action->generic_action.start = surf_get_clock();
499 action->generic_action.finish = -1.0;
500 action->generic_action.model_type =
501 (surf_model_t) surf_workstation_model;
502 action->suspended = 0;
504 if (CPU->state_current == SURF_CPU_ON)
505 action->generic_action.state_set =
506 surf_workstation_model->common_public->states.
509 action->generic_action.state_set =
510 surf_workstation_model->common_public->states.failed_action_set;
511 xbt_swag_insert(action, action->generic_action.state_set);
513 action->variable = lmm_variable_new(maxmin_system, action,
514 action->generic_action.priority,
516 lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
518 return (surf_action_t) action;
521 static surf_action_t action_sleep(void *cpu, double duration)
523 surf_action_workstation_KCCFLN05_t action = NULL;
525 XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
527 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
528 action->generic_action.max_duration = duration;
529 action->suspended = 2;
530 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
533 return (surf_action_t) action;
536 static e_surf_cpu_state_t model_get_state(void *cpu)
538 return ((cpu_KCCFLN05_t) cpu)->state_current;
541 static double get_speed(void *cpu, double load)
543 return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
546 static double get_available_speed(void *cpu)
548 return ((cpu_KCCFLN05_t) cpu)->power_current;
552 static surf_action_t communicate(void *src, void *dst, double size,
555 surf_action_workstation_KCCFLN05_t action = NULL;
556 cpu_KCCFLN05_t card_src = src;
557 cpu_KCCFLN05_t card_dst = dst;
558 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
559 int route_size = route->size;
562 XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
563 xbt_assert2(route_size,
564 "You're trying to send data from %s to %s but there is no connexion between these two cards.",
565 card_src->name, card_dst->name);
567 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
569 action->generic_action.using = 1;
570 action->generic_action.cost = size;
571 action->generic_action.remains = size;
572 action->generic_action.max_duration = NO_MAX_DURATION;
573 action->generic_action.start = surf_get_clock();
574 action->generic_action.finish = -1.0;
577 action->generic_action.model_type =
578 (surf_model_t) surf_workstation_model;
579 action->suspended = 0; /* Should be useless because of the
580 calloc but it seems to help valgrind... */
581 action->generic_action.state_set =
582 surf_workstation_model->common_public->states.running_action_set;
584 xbt_dynar_push(card_src->outgoing_communications, &action);
585 xbt_dynar_push(card_dst->incomming_communications, &action);
587 xbt_swag_insert(action, action->generic_action.state_set);
590 action->latency = 0.0;
591 for (i = 0; i < route_size; i++)
592 action->latency += route->links[i]->lat_current;
593 action->lat_current = action->latency;
595 if (action->latency > 0)
596 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4); /* +1 for the src bus
599 +1 for the dst cpu */
601 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
604 if (action->rate < 0) {
605 if (action->lat_current > 0)
606 lmm_update_variable_bound(maxmin_system, action->variable,
607 SG_TCP_CTE_GAMMA / (2.0 *
608 action->lat_current));
610 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
612 if (action->lat_current > 0)
613 lmm_update_variable_bound(maxmin_system, action->variable,
615 SG_TCP_CTE_GAMMA / (2.0 *
619 lmm_update_variable_bound(maxmin_system, action->variable,
623 lmm_update_variable_latency(maxmin_system, action->variable,
626 for (i = 0; i < route_size; i++)
627 lmm_expand(maxmin_system, route->links[i]->constraint,
628 action->variable, 1.0);
630 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
632 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
633 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
634 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
637 return (surf_action_t) action;
640 static surf_action_t execute_parallel_task(int workstation_nb,
641 void **workstation_list,
642 double *computation_amount,
643 double *communication_amount,
644 double amount, double rate)
646 surf_action_workstation_KCCFLN05_t action = NULL;
651 if (parallel_task_network_link_set == NULL) {
652 parallel_task_network_link_set =
653 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
656 /* Compute the number of affected models... */
657 for (i = 0; i < workstation_nb; i++) {
658 for (j = 0; j < workstation_nb; j++) {
659 cpu_KCCFLN05_t card_src = workstation_list[i];
660 cpu_KCCFLN05_t card_dst = workstation_list[j];
661 int route_size = ROUTE(card_src->id, card_dst->id).size;
662 network_link_KCCFLN05_t *route =
663 ROUTE(card_src->id, card_dst->id).links;
665 if (communication_amount[i * workstation_nb + j] > 0)
666 for (k = 0; k < route_size; k++) {
667 xbt_dict_set(parallel_task_network_link_set, route[k]->name,
672 nb_link = xbt_dict_length(parallel_task_network_link_set);
673 xbt_dict_reset(parallel_task_network_link_set);
676 for (i = 0; i < workstation_nb; i++)
677 if (computation_amount[i] > 0)
680 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
681 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
682 action, nb_host, nb_link);
683 action->generic_action.using = 1;
684 action->generic_action.cost = amount;
685 action->generic_action.remains = amount;
686 action->generic_action.max_duration = NO_MAX_DURATION;
687 action->generic_action.start = -1.0;
688 action->generic_action.finish = -1.0;
689 action->generic_action.model_type =
690 (surf_model_t) surf_workstation_model;
691 action->suspended = 0; /* Should be useless because of the
692 calloc but it seems to help valgrind... */
693 action->generic_action.state_set =
694 surf_workstation_model->common_public->states.running_action_set;
696 xbt_swag_insert(action, action->generic_action.state_set);
699 if (action->rate > 0)
700 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
704 lmm_variable_new(maxmin_system, action, 1.0, action->rate,
707 for (i = 0; i < workstation_nb; i++)
708 if (computation_amount[i] > 0)
709 lmm_expand(maxmin_system,
710 ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
711 action->variable, computation_amount[i]);
713 for (i = 0; i < workstation_nb; i++) {
714 for (j = 0; j < workstation_nb; j++) {
715 cpu_KCCFLN05_t card_src = workstation_list[i];
716 cpu_KCCFLN05_t card_dst = workstation_list[j];
717 int route_size = ROUTE(card_src->id, card_dst->id).size;
718 network_link_KCCFLN05_t *route =
719 ROUTE(card_src->id, card_dst->id).links;
721 for (k = 0; k < route_size; k++) {
722 if (communication_amount[i * workstation_nb + j] > 0) {
723 lmm_expand_add(maxmin_system, route[k]->constraint,
725 communication_amount[i * workstation_nb + j]);
731 if (nb_link + nb_host == 0) {
732 action->generic_action.cost = 1.0;
733 action->generic_action.remains = 0.0;
736 return (surf_action_t) action;
739 /* returns an array of network_link_KCCFLN05_t */
740 static const void **get_route(void *src, void *dst)
742 cpu_KCCFLN05_t card_src = src;
743 cpu_KCCFLN05_t card_dst = dst;
744 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
746 return (const void **) route->links;
749 static int get_route_size(void *src, void *dst)
751 cpu_KCCFLN05_t card_src = src;
752 cpu_KCCFLN05_t card_dst = dst;
753 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
757 static const char *get_link_name(const void *link)
759 return ((network_link_KCCFLN05_t) link)->name;
762 static double get_link_bandwidth(const void *link)
764 return ((network_link_KCCFLN05_t) link)->bw_current;
767 static double get_link_latency(const void *link)
769 return ((network_link_KCCFLN05_t) link)->lat_current;
772 /**************************************/
773 /*** Resource Creation & Destruction **/
774 /**************************************/
777 static void router_free(void *router)
779 free(((router_KCCFLN05_t) router)->name);
782 static void router_new(const char *name)
784 static unsigned int nb_routers = 0;
786 INFO1("Creating a router %s", name);
788 router_KCCFLN05_t router;
789 router = xbt_new0(s_router_KCCFLN05_t, 1);
791 router->name = xbt_strdup(name);
792 router->id = nb_routers++;
793 xbt_dict_set(router_set, name, router, router_free);
796 static void parse_routers(void)
798 //add a dumb router just to be GTNETS compatible
799 router_new(A_surfxml_router_name);
802 static void cpu_free(void *cpu)
804 free(((cpu_KCCFLN05_t) cpu)->name);
805 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
806 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
810 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
811 double power_initial,
812 tmgr_trace_t power_trace,
813 e_surf_cpu_state_t state_initial,
814 tmgr_trace_t state_trace,
815 double interference_send,
816 double interference_recv,
817 double interference_send_recv,
818 double max_outgoing_rate)
820 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
822 cpu->model = (surf_model_t) surf_workstation_model;
823 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
824 cpu->name = xbt_strdup(name);
825 cpu->id = nb_workstation++;
827 cpu->power_scale = power_scale;
828 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
830 cpu->power_current = power_initial;
833 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
835 cpu->state_current = state_initial;
838 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
840 cpu->interference_send = interference_send;
841 cpu->interference_recv = interference_recv;
842 cpu->interference_send_recv = interference_send_recv;
845 lmm_constraint_new(maxmin_system, cpu,
846 cpu->power_current * cpu->power_scale);
847 if (max_outgoing_rate > 0)
848 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
850 cpu->incomming_communications =
851 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
852 cpu->outgoing_communications =
853 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
855 xbt_dict_set(workstation_set, name, cpu, cpu_free);
860 static void parse_cpu(void)
862 double power_scale = 0.0;
863 double power_initial = 0.0;
864 tmgr_trace_t power_trace = NULL;
865 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
866 tmgr_trace_t state_trace = NULL;
867 double interference_send = 0.0;
868 double interference_recv = 0.0;
869 double interference_send_recv = 0.0;
870 double max_outgoing_rate = -1.0;
872 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
873 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
874 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
876 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
877 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
879 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
880 state_initial = SURF_CPU_ON;
881 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
882 state_initial = SURF_CPU_OFF;
883 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
885 surf_parse_get_double(&interference_send,
886 A_surfxml_cpu_interference_send);
887 surf_parse_get_double(&interference_recv,
888 A_surfxml_cpu_interference_recv);
889 surf_parse_get_double(&interference_send_recv,
890 A_surfxml_cpu_interference_send_recv);
891 surf_parse_get_double(&max_outgoing_rate,
892 A_surfxml_cpu_max_outgoing_rate);
894 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
895 state_initial, state_trace, interference_send, interference_recv,
896 interference_send_recv, max_outgoing_rate);
899 static void create_routing_table(void)
902 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
905 static void network_link_free(void *nw_link)
907 free(((network_link_KCCFLN05_t) nw_link)->name);
911 static network_link_KCCFLN05_t network_link_new(char *name,
913 tmgr_trace_t bw_trace,
915 tmgr_trace_t lat_trace,
916 e_surf_network_link_state_t
918 tmgr_trace_t state_trace,
919 e_surf_network_link_sharing_policy_t
922 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
925 nw_link->model = (surf_model_t) surf_workstation_model;
926 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
927 nw_link->name = name;
928 nw_link->bw_current = bw_initial;
931 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
932 nw_link->state_current = state_initial;
933 nw_link->lat_current = lat_initial;
936 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
938 nw_link->state_event =
939 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
941 nw_link->constraint =
942 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
944 if (policy == SURF_NETWORK_LINK_FATPIPE)
945 lmm_constraint_shared(nw_link->constraint);
947 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
952 static void parse_network_link(void)
956 tmgr_trace_t bw_trace;
958 tmgr_trace_t lat_trace;
959 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
960 e_surf_network_link_sharing_policy_t policy_initial =
961 SURF_NETWORK_LINK_SHARED;
962 tmgr_trace_t state_trace;
964 name = xbt_strdup(A_surfxml_network_link_name);
965 surf_parse_get_double(&bw_initial, A_surfxml_network_link_bandwidth);
966 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
967 surf_parse_get_double(&lat_initial, A_surfxml_network_link_latency);
968 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
970 xbt_assert0((A_surfxml_network_link_state ==
971 A_surfxml_network_link_state_ON)
972 || (A_surfxml_network_link_state ==
973 A_surfxml_network_link_state_OFF), "Invalid state");
974 if (A_surfxml_network_link_state == A_surfxml_network_link_state_ON)
975 state_initial = SURF_NETWORK_LINK_ON;
976 else if (A_surfxml_network_link_state ==
977 A_surfxml_network_link_state_OFF)
978 state_initial = SURF_NETWORK_LINK_OFF;
980 if (A_surfxml_network_link_sharing_policy ==
981 A_surfxml_network_link_sharing_policy_SHARED)
982 policy_initial = SURF_NETWORK_LINK_SHARED;
983 else if (A_surfxml_network_link_sharing_policy ==
984 A_surfxml_network_link_sharing_policy_FATPIPE)
985 policy_initial = SURF_NETWORK_LINK_FATPIPE;
987 surf_parse_get_trace(&state_trace, A_surfxml_network_link_state_file);
989 network_link_new(name, bw_initial, bw_trace,
990 lat_initial, lat_trace, state_initial, state_trace,
994 static void route_new(int src_id, int dst_id,
995 network_link_KCCFLN05_t * link_list, int nb_link,
996 double impact_on_src, double impact_on_dst,
997 double impact_on_src_with_other_recv,
998 double impact_on_dst_with_other_send)
1000 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1002 route->size = nb_link;
1003 route->links = link_list =
1004 xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
1005 route->impact_on_src = impact_on_src;
1006 route->impact_on_dst = impact_on_src;
1007 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1008 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1012 static int link_list_capacity;
1013 static network_link_KCCFLN05_t *link_list = NULL;
1014 static int src_id = -1;
1015 static int dst_id = -1;
1016 static double impact_on_src;
1017 static double impact_on_dst;
1018 static double impact_on_src_with_other_recv;
1019 static double impact_on_dst_with_other_send;
1021 static void parse_route_set_endpoints(void)
1023 cpu_KCCFLN05_t cpu_tmp = NULL;
1025 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1026 if (cpu_tmp != NULL) {
1027 src_id = cpu_tmp->id;
1029 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1030 "Invalid name '%s': neither a cpu nor a router!",
1031 A_surfxml_route_src);
1036 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1037 if (cpu_tmp != NULL) {
1038 dst_id = cpu_tmp->id;
1040 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1041 "Invalid name '%s': neither a cpu nor a router!",
1042 A_surfxml_route_dst);
1047 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1048 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1049 surf_parse_get_double(&impact_on_src_with_other_recv,
1050 A_surfxml_route_impact_on_src_with_other_recv);
1051 surf_parse_get_double(&impact_on_dst_with_other_send,
1052 A_surfxml_route_impact_on_dst_with_other_send);
1055 link_list_capacity = 1;
1056 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1060 static void parse_route_elem(void)
1063 if (nb_link == link_list_capacity) {
1064 link_list_capacity *= 2;
1066 xbt_realloc(link_list,
1067 (link_list_capacity) *
1068 sizeof(network_link_KCCFLN05_t));
1071 link_list[nb_link++] =
1072 xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1075 RETHROW1("Link %s not found (dict raised this exception: %s)",
1076 A_surfxml_route_element_name);
1080 static void parse_route_set_route(void)
1082 if (src_id != -1 && dst_id != -1)
1083 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1084 impact_on_dst, impact_on_src_with_other_recv,
1085 impact_on_dst_with_other_send);
1088 static void parse_file(const char *file)
1092 /* Figuring out the cpus */
1093 surf_parse_reset_parser();
1094 ETag_surfxml_cpu_fun = parse_cpu;
1095 surf_parse_open(file);
1096 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1099 create_routing_table();
1101 /* Figuring out the router (added after GTNETS) */
1102 surf_parse_reset_parser();
1103 STag_surfxml_router_fun = parse_routers;
1104 surf_parse_open(file);
1105 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1108 /* Figuring out the network links */
1109 surf_parse_reset_parser();
1110 ETag_surfxml_network_link_fun = parse_network_link;
1111 surf_parse_open(file);
1112 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1115 /* Building the routes */
1116 surf_parse_reset_parser();
1117 STag_surfxml_route_fun = parse_route_set_endpoints;
1118 ETag_surfxml_route_element_fun = parse_route_elem;
1119 ETag_surfxml_route_fun = parse_route_set_route;
1120 surf_parse_open(file);
1121 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1124 /* Adding loopback if needed */
1125 for (i = 0; i < nb_workstation; i++)
1126 if (!ROUTE(i, i).size) {
1128 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1129 498000000, NULL, 0.000015, NULL,
1130 SURF_NETWORK_LINK_ON, NULL,
1131 SURF_NETWORK_LINK_FATPIPE);
1132 ROUTE(i, i).size = 1;
1133 ROUTE(i, i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1134 ROUTE(i, i).links[0] = loopback;
1139 /**************************************/
1140 /********* Module creation ***********/
1141 /**************************************/
1143 static void model_init_internal(void)
1145 s_surf_action_t action;
1147 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1149 surf_workstation_model->common_private =
1150 xbt_new0(s_surf_model_private_t, 1);
1151 surf_workstation_model->common_public =
1152 xbt_new0(s_surf_model_public_t, 1);
1153 surf_workstation_model->extension_public =
1154 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1156 surf_workstation_model->common_public->states.ready_action_set =
1157 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1158 surf_workstation_model->common_public->states.running_action_set =
1159 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1160 surf_workstation_model->common_public->states.failed_action_set =
1161 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1162 surf_workstation_model->common_public->states.done_action_set =
1163 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1165 surf_workstation_model->common_public->name_service = name_service;
1166 surf_workstation_model->common_public->get_model_name =
1168 surf_workstation_model->common_public->action_get_state =
1169 surf_action_get_state;
1170 surf_workstation_model->common_public->action_get_start_time =
1171 surf_action_get_start_time;
1172 surf_workstation_model->common_public->action_get_finish_time =
1173 surf_action_get_finish_time;
1174 surf_workstation_model->common_public->action_use = action_use;
1175 surf_workstation_model->common_public->action_free = action_free;
1176 surf_workstation_model->common_public->action_cancel = action_cancel;
1177 surf_workstation_model->common_public->action_recycle =
1179 surf_workstation_model->common_public->action_change_state =
1180 surf_action_change_state;
1181 surf_workstation_model->common_public->action_set_data =
1182 surf_action_set_data;
1183 surf_workstation_model->common_public->suspend = action_suspend;
1184 surf_workstation_model->common_public->resume = action_resume;
1185 surf_workstation_model->common_public->is_suspended =
1186 action_is_suspended;
1187 surf_workstation_model->common_public->set_max_duration =
1188 action_set_max_duration;
1189 surf_workstation_model->common_public->set_priority =
1190 action_set_priority;
1191 surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1193 surf_workstation_model->common_private->model_used = model_used;
1194 surf_workstation_model->common_private->share_models =
1196 surf_workstation_model->common_private->update_actions_state =
1197 update_actions_state;
1198 surf_workstation_model->common_private->update_model_state =
1200 surf_workstation_model->common_private->finalize = finalize;
1202 surf_workstation_model->extension_public->execute = execute;
1203 surf_workstation_model->extension_public->sleep = action_sleep;
1204 surf_workstation_model->extension_public->get_state =
1206 surf_workstation_model->extension_public->get_speed = get_speed;
1207 surf_workstation_model->extension_public->get_available_speed =
1208 get_available_speed;
1209 surf_workstation_model->extension_public->communicate = communicate;
1210 surf_workstation_model->extension_public->execute_parallel_task =
1211 execute_parallel_task;
1212 surf_workstation_model->extension_public->get_route = get_route;
1213 surf_workstation_model->extension_public->get_route_size =
1215 surf_workstation_model->extension_public->get_link_name =
1217 surf_workstation_model->extension_public->get_link_bandwidth =
1219 surf_workstation_model->extension_public->get_link_latency =
1222 workstation_set = xbt_dict_new();
1223 router_set = xbt_dict_new();
1224 network_link_set = xbt_dict_new();
1226 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1229 /**************************************/
1230 /*************** Generic **************/
1231 /**************************************/
1232 void surf_workstation_model_init_KCCFLN05(const char *filename)
1234 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1235 xbt_assert0(!surf_network_model,
1236 "network model type already defined");
1237 model_init_internal();
1238 parse_file(filename);
1240 xbt_dynar_push(model_list, &surf_workstation_model);