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, 1.0);
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)
220 { /* FIXME: should inherit */
221 XBT_IN2("(%p,%g)", action, priority);
222 action->priority = priority;
226 /**************************************/
227 /******* Resource Private **********/
228 /**************************************/
230 static int model_used(void *model_id)
232 /* We can freely cast as a network_link_KCCFLN05_t because it has
233 the same prefix as cpu_KCCFLN05_t */
234 if (((cpu_KCCFLN05_t) model_id)->type ==
235 SURF_WORKSTATION_RESOURCE_CPU)
236 return (lmm_constraint_used
237 (maxmin_system, ((cpu_KCCFLN05_t) model_id)->constraint)
238 || ((((cpu_KCCFLN05_t) model_id)->bus) ?
239 lmm_constraint_used(maxmin_system,
240 ((cpu_KCCFLN05_t) model_id)->
243 return lmm_constraint_used(maxmin_system,
244 ((network_link_KCCFLN05_t) model_id)->
249 static double share_models(double now)
251 s_surf_action_workstation_KCCFLN05_t s_action;
252 surf_action_workstation_KCCFLN05_t action = NULL;
254 xbt_swag_t running_actions =
255 surf_workstation_model->common_public->states.running_action_set;
256 double min = generic_maxmin_share_models(running_actions,
257 xbt_swag_offset(s_action,
260 xbt_swag_foreach(action, running_actions) {
261 if (action->latency > 0) {
263 min = action->latency;
264 DEBUG3("Updating min (value) with %p (start %f): %f", action,
265 action->generic_action.start, min);
266 } else if (action->latency < min) {
267 min = action->latency;
268 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
269 action->generic_action.start, min);
274 DEBUG1("min value : %f", min);
279 static void update_actions_state(double now, double delta)
282 surf_action_workstation_KCCFLN05_t action = NULL;
283 surf_action_workstation_KCCFLN05_t next_action = NULL;
284 xbt_swag_t running_actions =
285 surf_workstation_model->common_public->states.running_action_set;
287 xbt_swag_foreach_safe(action, next_action, running_actions) {
289 if (action->latency > 0) {
290 if (action->latency > deltap) {
291 double_update(&(action->latency), deltap);
294 double_update(&(deltap), action->latency);
295 action->latency = 0.0;
297 if ((action->latency == 0.0) && (action->suspended == 0)) {
298 if ((action)->lat_current == 0.0)
299 lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
301 lmm_update_variable_weight(maxmin_system, action->variable,
302 action->lat_current);
305 DEBUG3("Action (%p) : remains (%g) updated by %g.",
306 action, action->generic_action.remains,
307 lmm_variable_getvalue(action->variable) * deltap);
308 double_update(&(action->generic_action.remains),
309 lmm_variable_getvalue(action->variable) * deltap);
311 if (action->generic_action.max_duration != NO_MAX_DURATION)
312 double_update(&(action->generic_action.max_duration), delta);
314 if ((action->generic_action.remains <= 0) &&
315 (lmm_get_variable_weight(action->variable) > 0)) {
316 action->generic_action.finish = surf_get_clock();
317 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
318 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
319 (action->generic_action.max_duration <= 0)) {
320 action->generic_action.finish = surf_get_clock();
321 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
323 /* Need to check that none of the model has failed */
324 lmm_constraint_t cnst = NULL;
326 void *constraint_id = NULL;
329 lmm_get_cnst_from_var(maxmin_system, action->variable,
331 constraint_id = lmm_constraint_id(cnst);
333 /* if(((network_link_KCCFLN05_t)constraint_id)->type== */
334 /* SURF_WORKSTATION_RESOURCE_LINK) { */
335 /* DEBUG2("Checking for link %s (%p)", */
336 /* ((network_link_KCCFLN05_t)constraint_id)->name, */
337 /* ((network_link_KCCFLN05_t)constraint_id)); */
339 /* if(((cpu_KCCFLN05_t)constraint_id)->type== */
340 /* SURF_WORKSTATION_RESOURCE_CPU) { */
341 /* DEBUG3("Checking for cpu %s (%p) : %s", */
342 /* ((cpu_KCCFLN05_t)constraint_id)->name, */
343 /* ((cpu_KCCFLN05_t)constraint_id), */
344 /* ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
347 if (((((network_link_KCCFLN05_t) constraint_id)->type ==
348 SURF_WORKSTATION_RESOURCE_LINK) &&
349 (((network_link_KCCFLN05_t) constraint_id)->state_current ==
350 SURF_NETWORK_LINK_OFF)) ||
351 ((((cpu_KCCFLN05_t) constraint_id)->type ==
352 SURF_WORKSTATION_RESOURCE_CPU) &&
353 (((cpu_KCCFLN05_t) constraint_id)->state_current ==
355 DEBUG1("Action (%p) Failed!!", action);
356 action->generic_action.finish = surf_get_clock();
357 surf_action_change_state((surf_action_t) action,
367 static void update_model_state(void *id,
368 tmgr_trace_event_t event_type,
371 cpu_KCCFLN05_t cpu = id;
372 network_link_KCCFLN05_t nw_link = id;
374 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
375 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
376 if (event_type == nw_link->bw_event) {
377 nw_link->bw_current = value;
378 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
379 nw_link->bw_current);
380 } else if (event_type == nw_link->lat_event) {
381 double delta = value - nw_link->lat_current;
382 lmm_variable_t var = NULL;
383 surf_action_workstation_KCCFLN05_t action = NULL;
385 nw_link->lat_current = value;
386 while (lmm_get_var_from_cnst
387 (maxmin_system, nw_link->constraint, &var)) {
388 action = lmm_variable_id(var);
389 action->lat_current += delta;
390 if (action->rate < 0)
391 lmm_update_variable_bound(maxmin_system, action->variable,
392 SG_TCP_CTE_GAMMA / (2.0 *
396 lmm_update_variable_bound(maxmin_system, action->variable,
398 SG_TCP_CTE_GAMMA / (2.0 *
401 if (action->suspended == 0)
402 lmm_update_variable_weight(maxmin_system, action->variable,
403 action->lat_current);
404 lmm_update_variable_latency(maxmin_system, action->variable,
409 } else if (event_type == nw_link->state_event) {
411 nw_link->state_current = SURF_NETWORK_LINK_ON;
413 nw_link->state_current = SURF_NETWORK_LINK_OFF;
415 CRITICAL0("Unknown event ! \n");
419 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
420 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
421 if (event_type == cpu->power_event) {
422 cpu->power_current = value;
423 __update_cpu_usage(cpu);
424 } else if (event_type == cpu->state_event) {
426 cpu->state_current = SURF_CPU_ON;
428 cpu->state_current = SURF_CPU_OFF;
430 CRITICAL0("Unknown event ! \n");
440 static void finalize(void)
444 xbt_dict_free(&network_link_set);
445 xbt_dict_free(&workstation_set);
446 xbt_dict_free(&router_set);
447 if (parallel_task_network_link_set != NULL) {
448 xbt_dict_free(¶llel_task_network_link_set);
450 xbt_swag_free(surf_workstation_model->common_public->states.
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.
459 free(surf_workstation_model->common_public);
460 free(surf_workstation_model->common_private);
461 free(surf_workstation_model->extension_public);
463 free(surf_workstation_model);
464 surf_workstation_model = NULL;
466 for (i = 0; i < nb_workstation; i++)
467 for (j = 0; j < nb_workstation; j++)
468 free(ROUTE(i, j).links);
470 routing_table = NULL;
474 lmm_system_free(maxmin_system);
475 maxmin_system = NULL;
479 /**************************************/
480 /******* Resource Private **********/
481 /**************************************/
483 static surf_action_t execute(void *cpu, double size)
485 surf_action_workstation_KCCFLN05_t action = NULL;
486 cpu_KCCFLN05_t CPU = cpu;
488 XBT_IN2("(%s,%g)", CPU->name, size);
489 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
491 action->generic_action.using = 1;
492 action->generic_action.cost = size;
493 action->generic_action.remains = size;
494 action->generic_action.priority = 1.0;
495 action->generic_action.max_duration = NO_MAX_DURATION;
496 action->generic_action.start = surf_get_clock();
497 action->generic_action.finish = -1.0;
498 action->generic_action.model_type =
499 (surf_model_t) surf_workstation_model;
500 action->suspended = 0;
502 if (CPU->state_current == SURF_CPU_ON)
503 action->generic_action.state_set =
504 surf_workstation_model->common_public->states.
507 action->generic_action.state_set =
508 surf_workstation_model->common_public->states.failed_action_set;
509 xbt_swag_insert(action, action->generic_action.state_set);
511 action->variable = lmm_variable_new(maxmin_system, action,
512 action->generic_action.priority,
514 lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
516 return (surf_action_t) action;
519 static surf_action_t action_sleep(void *cpu, double duration)
521 surf_action_workstation_KCCFLN05_t action = NULL;
523 XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
525 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
526 action->generic_action.max_duration = duration;
527 action->suspended = 2;
528 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
531 return (surf_action_t) action;
534 static e_surf_cpu_state_t model_get_state(void *cpu)
536 return ((cpu_KCCFLN05_t) cpu)->state_current;
539 static double get_speed(void *cpu, double load)
541 return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
544 static double get_available_speed(void *cpu)
546 return ((cpu_KCCFLN05_t) cpu)->power_current;
550 static surf_action_t communicate(void *src, void *dst, double size,
553 surf_action_workstation_KCCFLN05_t action = NULL;
554 cpu_KCCFLN05_t card_src = src;
555 cpu_KCCFLN05_t card_dst = dst;
556 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
557 int route_size = route->size;
560 XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
561 xbt_assert2(route_size,
562 "You're trying to send data from %s to %s but there is no connexion between these two cards.",
563 card_src->name, card_dst->name);
565 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
567 action->generic_action.using = 1;
568 action->generic_action.cost = size;
569 action->generic_action.remains = size;
570 action->generic_action.max_duration = NO_MAX_DURATION;
571 action->generic_action.start = surf_get_clock();
572 action->generic_action.finish = -1.0;
575 action->generic_action.model_type =
576 (surf_model_t) surf_workstation_model;
577 action->suspended = 0; /* Should be useless because of the
578 calloc but it seems to help valgrind... */
579 action->generic_action.state_set =
580 surf_workstation_model->common_public->states.running_action_set;
582 xbt_dynar_push(card_src->outgoing_communications, &action);
583 xbt_dynar_push(card_dst->incomming_communications, &action);
585 xbt_swag_insert(action, action->generic_action.state_set);
588 action->latency = 0.0;
589 for (i = 0; i < route_size; i++)
590 action->latency += route->links[i]->lat_current;
591 action->lat_current = action->latency;
593 if (action->latency > 0)
594 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4); /* +1 for the src bus
597 +1 for the dst cpu */
599 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
602 if (action->rate < 0) {
603 if (action->lat_current > 0)
604 lmm_update_variable_bound(maxmin_system, action->variable,
605 SG_TCP_CTE_GAMMA / (2.0 *
606 action->lat_current));
608 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
610 if (action->lat_current > 0)
611 lmm_update_variable_bound(maxmin_system, action->variable,
613 SG_TCP_CTE_GAMMA / (2.0 *
617 lmm_update_variable_bound(maxmin_system, action->variable,
621 lmm_update_variable_latency(maxmin_system, action->variable,
624 for (i = 0; i < route_size; i++)
625 lmm_expand(maxmin_system, route->links[i]->constraint,
626 action->variable, 1.0);
628 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
630 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
631 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
632 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
635 return (surf_action_t) action;
638 static surf_action_t execute_parallel_task(int workstation_nb,
639 void **workstation_list,
640 double *computation_amount,
641 double *communication_amount,
642 double amount, double rate)
644 surf_action_workstation_KCCFLN05_t action = NULL;
649 if (parallel_task_network_link_set == NULL) {
650 parallel_task_network_link_set =
651 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
654 /* Compute the number of affected models... */
655 for (i = 0; i < workstation_nb; i++) {
656 for (j = 0; j < workstation_nb; j++) {
657 cpu_KCCFLN05_t card_src = workstation_list[i];
658 cpu_KCCFLN05_t card_dst = workstation_list[j];
659 int route_size = ROUTE(card_src->id, card_dst->id).size;
660 network_link_KCCFLN05_t *route =
661 ROUTE(card_src->id, card_dst->id).links;
663 if (communication_amount[i * workstation_nb + j] > 0)
664 for (k = 0; k < route_size; k++) {
665 xbt_dict_set(parallel_task_network_link_set, route[k]->name,
670 nb_link = xbt_dict_length(parallel_task_network_link_set);
671 xbt_dict_reset(parallel_task_network_link_set);
674 for (i = 0; i < workstation_nb; i++)
675 if (computation_amount[i] > 0)
678 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
679 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
680 action, nb_host, nb_link);
681 action->generic_action.using = 1;
682 action->generic_action.cost = amount;
683 action->generic_action.remains = amount;
684 action->generic_action.max_duration = NO_MAX_DURATION;
685 action->generic_action.start = -1.0;
686 action->generic_action.finish = -1.0;
687 action->generic_action.model_type =
688 (surf_model_t) surf_workstation_model;
689 action->suspended = 0; /* Should be useless because of the
690 calloc but it seems to help valgrind... */
691 action->generic_action.state_set =
692 surf_workstation_model->common_public->states.running_action_set;
694 xbt_swag_insert(action, action->generic_action.state_set);
697 if (action->rate > 0)
698 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
702 lmm_variable_new(maxmin_system, action, 1.0, action->rate,
705 for (i = 0; i < workstation_nb; i++)
706 if (computation_amount[i] > 0)
707 lmm_expand(maxmin_system,
708 ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
709 action->variable, computation_amount[i]);
711 for (i = 0; i < workstation_nb; i++) {
712 for (j = 0; j < workstation_nb; j++) {
713 cpu_KCCFLN05_t card_src = workstation_list[i];
714 cpu_KCCFLN05_t card_dst = workstation_list[j];
715 int route_size = ROUTE(card_src->id, card_dst->id).size;
716 network_link_KCCFLN05_t *route =
717 ROUTE(card_src->id, card_dst->id).links;
719 for (k = 0; k < route_size; k++) {
720 if (communication_amount[i * workstation_nb + j] > 0) {
721 lmm_expand_add(maxmin_system, route[k]->constraint,
723 communication_amount[i * workstation_nb + j]);
729 if (nb_link + nb_host == 0) {
730 action->generic_action.cost = 1.0;
731 action->generic_action.remains = 0.0;
734 return (surf_action_t) action;
737 /* returns an array of network_link_KCCFLN05_t */
738 static const void **get_route(void *src, void *dst)
740 cpu_KCCFLN05_t card_src = src;
741 cpu_KCCFLN05_t card_dst = dst;
742 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
744 return (const void **) route->links;
747 static int get_route_size(void *src, void *dst)
749 cpu_KCCFLN05_t card_src = src;
750 cpu_KCCFLN05_t card_dst = dst;
751 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
755 static const char *get_link_name(const void *link)
757 return ((network_link_KCCFLN05_t) link)->name;
760 static double get_link_bandwidth(const void *link)
762 return ((network_link_KCCFLN05_t) link)->bw_current;
765 static double get_link_latency(const void *link)
767 return ((network_link_KCCFLN05_t) link)->lat_current;
770 /**************************************/
771 /*** Resource Creation & Destruction **/
772 /**************************************/
775 static void router_free(void *router)
777 free(((router_KCCFLN05_t) router)->name);
780 static void router_new(const char *name)
782 static unsigned int nb_routers = 0;
784 INFO1("Creating a router %s", name);
786 router_KCCFLN05_t router;
787 router = xbt_new0(s_router_KCCFLN05_t, 1);
789 router->name = xbt_strdup(name);
790 router->id = nb_routers++;
791 xbt_dict_set(router_set, name, router, router_free);
794 static void parse_routers(void)
796 //add a dumb router just to be GTNETS compatible
797 router_new(A_surfxml_router_name);
800 static void cpu_free(void *cpu)
802 free(((cpu_KCCFLN05_t) cpu)->name);
803 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
804 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
808 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
809 double power_initial,
810 tmgr_trace_t power_trace,
811 e_surf_cpu_state_t state_initial,
812 tmgr_trace_t state_trace,
813 double interference_send,
814 double interference_recv,
815 double interference_send_recv,
816 double max_outgoing_rate)
818 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
820 cpu->model = (surf_model_t) surf_workstation_model;
821 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
822 cpu->name = xbt_strdup(name);
823 cpu->id = nb_workstation++;
825 cpu->power_scale = power_scale;
826 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
828 cpu->power_current = power_initial;
831 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
833 cpu->state_current = state_initial;
836 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
838 cpu->interference_send = interference_send;
839 cpu->interference_recv = interference_recv;
840 cpu->interference_send_recv = interference_send_recv;
843 lmm_constraint_new(maxmin_system, cpu,
844 cpu->power_current * cpu->power_scale);
845 if (max_outgoing_rate > 0)
846 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
848 cpu->incomming_communications =
849 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
850 cpu->outgoing_communications =
851 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
853 xbt_dict_set(workstation_set, name, cpu, cpu_free);
858 static void parse_cpu(void)
860 double power_scale = 0.0;
861 double power_initial = 0.0;
862 tmgr_trace_t power_trace = NULL;
863 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
864 tmgr_trace_t state_trace = NULL;
865 double interference_send = 0.0;
866 double interference_recv = 0.0;
867 double interference_send_recv = 0.0;
868 double max_outgoing_rate = -1.0;
870 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
871 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
872 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
874 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
875 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
877 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
878 state_initial = SURF_CPU_ON;
879 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
880 state_initial = SURF_CPU_OFF;
881 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
883 surf_parse_get_double(&interference_send,
884 A_surfxml_cpu_interference_send);
885 surf_parse_get_double(&interference_recv,
886 A_surfxml_cpu_interference_recv);
887 surf_parse_get_double(&interference_send_recv,
888 A_surfxml_cpu_interference_send_recv);
889 surf_parse_get_double(&max_outgoing_rate,
890 A_surfxml_cpu_max_outgoing_rate);
892 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
893 state_initial, state_trace, interference_send, interference_recv,
894 interference_send_recv, max_outgoing_rate);
897 static void create_routing_table(void)
900 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
903 static void network_link_free(void *nw_link)
905 free(((network_link_KCCFLN05_t) nw_link)->name);
909 static network_link_KCCFLN05_t network_link_new(char *name,
911 tmgr_trace_t bw_trace,
913 tmgr_trace_t lat_trace,
914 e_surf_network_link_state_t
916 tmgr_trace_t state_trace,
917 e_surf_network_link_sharing_policy_t
920 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
923 nw_link->model = (surf_model_t) surf_workstation_model;
924 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
925 nw_link->name = name;
926 nw_link->bw_current = bw_initial;
929 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
930 nw_link->state_current = state_initial;
931 nw_link->lat_current = lat_initial;
934 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
936 nw_link->state_event =
937 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
939 nw_link->constraint =
940 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
942 if (policy == SURF_NETWORK_LINK_FATPIPE)
943 lmm_constraint_shared(nw_link->constraint);
945 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
950 static void parse_network_link(void)
954 tmgr_trace_t bw_trace;
956 tmgr_trace_t lat_trace;
957 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
958 e_surf_network_link_sharing_policy_t policy_initial =
959 SURF_NETWORK_LINK_SHARED;
960 tmgr_trace_t state_trace;
962 name = xbt_strdup(A_surfxml_network_link_name);
963 surf_parse_get_double(&bw_initial, A_surfxml_network_link_bandwidth);
964 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
965 surf_parse_get_double(&lat_initial, A_surfxml_network_link_latency);
966 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
968 xbt_assert0((A_surfxml_network_link_state ==
969 A_surfxml_network_link_state_ON)
970 || (A_surfxml_network_link_state ==
971 A_surfxml_network_link_state_OFF), "Invalid state");
972 if (A_surfxml_network_link_state == A_surfxml_network_link_state_ON)
973 state_initial = SURF_NETWORK_LINK_ON;
974 else if (A_surfxml_network_link_state ==
975 A_surfxml_network_link_state_OFF)
976 state_initial = SURF_NETWORK_LINK_OFF;
978 if (A_surfxml_network_link_sharing_policy ==
979 A_surfxml_network_link_sharing_policy_SHARED)
980 policy_initial = SURF_NETWORK_LINK_SHARED;
981 else if (A_surfxml_network_link_sharing_policy ==
982 A_surfxml_network_link_sharing_policy_FATPIPE)
983 policy_initial = SURF_NETWORK_LINK_FATPIPE;
985 surf_parse_get_trace(&state_trace, A_surfxml_network_link_state_file);
987 network_link_new(name, bw_initial, bw_trace,
988 lat_initial, lat_trace, state_initial, state_trace,
992 static void route_new(int src_id, int dst_id,
993 network_link_KCCFLN05_t * link_list, int nb_link,
994 double impact_on_src, double impact_on_dst,
995 double impact_on_src_with_other_recv,
996 double impact_on_dst_with_other_send)
998 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1000 route->size = nb_link;
1001 route->links = link_list =
1002 xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
1003 route->impact_on_src = impact_on_src;
1004 route->impact_on_dst = impact_on_src;
1005 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1006 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1010 static int link_list_capacity;
1011 static network_link_KCCFLN05_t *link_list = NULL;
1012 static int src_id = -1;
1013 static int dst_id = -1;
1014 static double impact_on_src;
1015 static double impact_on_dst;
1016 static double impact_on_src_with_other_recv;
1017 static double impact_on_dst_with_other_send;
1019 static void parse_route_set_endpoints(void)
1021 cpu_KCCFLN05_t cpu_tmp = NULL;
1023 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1024 if (cpu_tmp != NULL) {
1025 src_id = cpu_tmp->id;
1027 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1028 "Invalid name '%s': neither a cpu nor a router!",
1029 A_surfxml_route_src);
1034 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1035 if (cpu_tmp != NULL) {
1036 dst_id = cpu_tmp->id;
1038 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1039 "Invalid name '%s': neither a cpu nor a router!",
1040 A_surfxml_route_dst);
1045 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1046 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1047 surf_parse_get_double(&impact_on_src_with_other_recv,
1048 A_surfxml_route_impact_on_src_with_other_recv);
1049 surf_parse_get_double(&impact_on_dst_with_other_send,
1050 A_surfxml_route_impact_on_dst_with_other_send);
1053 link_list_capacity = 1;
1054 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1058 static void parse_route_elem(void)
1061 if (nb_link == link_list_capacity) {
1062 link_list_capacity *= 2;
1064 xbt_realloc(link_list,
1065 (link_list_capacity) *
1066 sizeof(network_link_KCCFLN05_t));
1069 link_list[nb_link++] =
1070 xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1073 RETHROW1("Link %s not found (dict raised this exception: %s)",
1074 A_surfxml_route_element_name);
1078 static void parse_route_set_route(void)
1080 if (src_id != -1 && dst_id != -1)
1081 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1082 impact_on_dst, impact_on_src_with_other_recv,
1083 impact_on_dst_with_other_send);
1086 static void parse_file(const char *file)
1090 /* Figuring out the cpus */
1091 surf_parse_reset_parser();
1092 ETag_surfxml_cpu_fun = parse_cpu;
1093 surf_parse_open(file);
1094 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1097 create_routing_table();
1099 /* Figuring out the router (added after GTNETS) */
1100 surf_parse_reset_parser();
1101 STag_surfxml_router_fun = parse_routers;
1102 surf_parse_open(file);
1103 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1106 /* Figuring out the network links */
1107 surf_parse_reset_parser();
1108 ETag_surfxml_network_link_fun = parse_network_link;
1109 surf_parse_open(file);
1110 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1113 /* Building the routes */
1114 surf_parse_reset_parser();
1115 STag_surfxml_route_fun = parse_route_set_endpoints;
1116 ETag_surfxml_route_element_fun = parse_route_elem;
1117 ETag_surfxml_route_fun = parse_route_set_route;
1118 surf_parse_open(file);
1119 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1122 /* Adding loopback if needed */
1123 for (i = 0; i < nb_workstation; i++)
1124 if (!ROUTE(i, i).size) {
1126 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1127 498000000, NULL, 0.000015, NULL,
1128 SURF_NETWORK_LINK_ON, NULL,
1129 SURF_NETWORK_LINK_FATPIPE);
1130 ROUTE(i, i).size = 1;
1131 ROUTE(i, i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1132 ROUTE(i, i).links[0] = loopback;
1137 /**************************************/
1138 /********* Module creation ***********/
1139 /**************************************/
1141 static void model_init_internal(void)
1143 s_surf_action_t action;
1145 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1147 surf_workstation_model->common_private =
1148 xbt_new0(s_surf_model_private_t, 1);
1149 surf_workstation_model->common_public =
1150 xbt_new0(s_surf_model_public_t, 1);
1151 surf_workstation_model->extension_public =
1152 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1154 surf_workstation_model->common_public->states.ready_action_set =
1155 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1156 surf_workstation_model->common_public->states.running_action_set =
1157 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1158 surf_workstation_model->common_public->states.failed_action_set =
1159 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1160 surf_workstation_model->common_public->states.done_action_set =
1161 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1163 surf_workstation_model->common_public->name_service = name_service;
1164 surf_workstation_model->common_public->get_model_name =
1166 surf_workstation_model->common_public->action_get_state =
1167 surf_action_get_state;
1168 surf_workstation_model->common_public->action_get_start_time =
1169 surf_action_get_start_time;
1170 surf_workstation_model->common_public->action_get_finish_time =
1171 surf_action_get_finish_time;
1172 surf_workstation_model->common_public->action_use = action_use;
1173 surf_workstation_model->common_public->action_free = action_free;
1174 surf_workstation_model->common_public->action_cancel = action_cancel;
1175 surf_workstation_model->common_public->action_recycle =
1177 surf_workstation_model->common_public->action_change_state =
1178 surf_action_change_state;
1179 surf_workstation_model->common_public->action_set_data =
1180 surf_action_set_data;
1181 surf_workstation_model->common_public->suspend = action_suspend;
1182 surf_workstation_model->common_public->resume = action_resume;
1183 surf_workstation_model->common_public->is_suspended =
1184 action_is_suspended;
1185 surf_workstation_model->common_public->set_max_duration =
1186 action_set_max_duration;
1187 surf_workstation_model->common_public->set_priority =
1188 action_set_priority;
1189 surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1191 surf_workstation_model->common_private->model_used = model_used;
1192 surf_workstation_model->common_private->share_models =
1194 surf_workstation_model->common_private->update_actions_state =
1195 update_actions_state;
1196 surf_workstation_model->common_private->update_model_state =
1198 surf_workstation_model->common_private->finalize = finalize;
1200 surf_workstation_model->extension_public->execute = execute;
1201 surf_workstation_model->extension_public->sleep = action_sleep;
1202 surf_workstation_model->extension_public->get_state =
1204 surf_workstation_model->extension_public->get_speed = get_speed;
1205 surf_workstation_model->extension_public->get_available_speed =
1206 get_available_speed;
1207 surf_workstation_model->extension_public->communicate = communicate;
1208 surf_workstation_model->extension_public->execute_parallel_task =
1209 execute_parallel_task;
1210 surf_workstation_model->extension_public->get_route = get_route;
1211 surf_workstation_model->extension_public->get_route_size =
1213 surf_workstation_model->extension_public->get_link_name =
1215 surf_workstation_model->extension_public->get_link_bandwidth =
1217 surf_workstation_model->extension_public->get_link_latency =
1220 workstation_set = xbt_dict_new();
1221 router_set = xbt_dict_new();
1222 network_link_set = xbt_dict_new();
1224 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1227 /**************************************/
1228 /*************** Generic **************/
1229 /**************************************/
1230 void surf_workstation_model_init_KCCFLN05(const char *filename)
1232 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1233 xbt_assert0(!surf_network_model,
1234 "network model type already defined");
1235 model_init_internal();
1236 parse_file(filename);
1238 xbt_dynar_push(model_list, &surf_workstation_model);