1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "surf_private.h"
13 SURF_WORKSTATION_RESOURCE_CPU,
14 SURF_WORKSTATION_RESOURCE_LINK,
15 } e_surf_workstation_model_type_t;
17 /**************************************/
18 /********* cpu object *****************/
19 /**************************************/
20 typedef struct cpu_L07 {
21 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
22 e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
23 lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
26 tmgr_trace_event_t power_event;
27 e_surf_resource_state_t state_current;
28 tmgr_trace_event_t state_event;
29 int id; /* cpu and network card are a single object... */
30 } s_cpu_L07_t, *cpu_L07_t;
32 /**************************************/
33 /*********** network object ***********/
34 /**************************************/
36 typedef struct link_L07 {
37 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
38 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
39 lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
41 tmgr_trace_event_t lat_event;
43 tmgr_trace_event_t bw_event;
44 e_surf_resource_state_t state_current;
45 tmgr_trace_event_t state_event;
46 } s_link_L07_t, *link_L07_t;
48 /**************************************/
49 /*************** actions **************/
50 /**************************************/
51 typedef struct surf_action_workstation_L07 {
52 s_surf_action_t generic_action;
53 lmm_variable_t variable;
55 cpu_L07_t *workstation_list;
56 double *computation_amount;
57 double *communication_amount;
61 } s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
64 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
66 static int ptask_host_count = 0;
67 static xbt_dict_t ptask_parallel_task_link_set = NULL;
68 lmm_system_t ptask_maxmin_system = NULL;
71 static void ptask_update_action_bound(surf_action_workstation_L07_t action)
73 int workstation_nb = action->workstation_nb;
74 double lat_current = 0.0;
75 double lat_bound = -1.0;
80 for (i = 0; i < workstation_nb; i++) {
81 for (j = 0; j < workstation_nb; j++) {
82 cpu_L07_t card_src = action->workstation_list[i];
83 cpu_L07_t card_dst = action->workstation_list[j];
84 xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
87 if (action->communication_amount[i * workstation_nb + j] > 0) {
88 xbt_dynar_foreach(route, cpt, link) {
89 lat += link->lat_current;
93 lat * action->communication_amount[i * workstation_nb + j]);
97 lat_bound = sg_tcp_gamma / (2.0 * lat_current);
98 DEBUG2("action (%p) : lat_bound = %g", action, lat_bound);
99 if ((action->latency == 0.0) && (action->suspended == 0)) {
100 if (action->rate < 0)
101 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
104 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
105 min(action->rate, lat_bound));
109 /**************************************/
110 /******* Resource Public **********/
111 /**************************************/
113 static int ptask_action_unref(surf_action_t action)
117 if (!action->refcount) {
118 xbt_swag_remove(action, action->state_set);
119 if (((surf_action_workstation_L07_t) action)->variable)
120 lmm_variable_free(ptask_maxmin_system,
121 ((surf_action_workstation_L07_t) action)->variable);
122 free(((surf_action_workstation_L07_t) action)->workstation_list);
123 free(((surf_action_workstation_L07_t) action)->communication_amount);
124 free(((surf_action_workstation_L07_t) action)->computation_amount);
131 static void ptask_action_cancel(surf_action_t action)
133 surf_action_state_set(action, SURF_ACTION_FAILED);
137 /* action_change_state is inherited from the surf module */
138 /* action_set_data is inherited from the surf module */
140 static void ptask_action_suspend(surf_action_t action)
142 XBT_IN1("(%p))", action);
143 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
144 ((surf_action_workstation_L07_t) action)->suspended = 1;
145 lmm_update_variable_weight(ptask_maxmin_system,
146 ((surf_action_workstation_L07_t)
147 action)->variable, 0.0);
152 static void ptask_action_resume(surf_action_t action)
154 surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action;
156 XBT_IN1("(%p)", act);
157 if (act->suspended != 2) {
158 lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
164 static int ptask_action_is_suspended(surf_action_t action)
166 return (((surf_action_workstation_L07_t) action)->suspended == 1);
169 static void ptask_action_set_max_duration(surf_action_t action, double duration)
170 { /* FIXME: should inherit */
171 XBT_IN2("(%p,%g)", action, duration);
172 action->max_duration = duration;
177 static void ptask_action_set_priority(surf_action_t action, double priority)
178 { /* FIXME: should inherit */
179 XBT_IN2("(%p,%g)", action, priority);
180 action->priority = priority;
184 static double ptask_action_get_remains(surf_action_t action)
186 XBT_IN1("(%p)", action);
187 return action->remains;
191 /**************************************/
192 /******* Resource Private **********/
193 /**************************************/
195 static int ptask_resource_used(void *resource_id)
197 /* We can freely cast as a link_L07_t because it has
198 the same prefix as cpu_L07_t */
199 return lmm_constraint_used(ptask_maxmin_system,
200 ((link_L07_t) resource_id)->constraint);
204 static double ptask_share_resources(double now)
206 s_surf_action_workstation_L07_t s_action;
207 surf_action_workstation_L07_t action = NULL;
209 xbt_swag_t running_actions =
210 surf_workstation_model->states.running_action_set;
211 double min = generic_maxmin_share_resources(running_actions,
212 xbt_swag_offset(s_action,
217 xbt_swag_foreach(action, running_actions) {
218 if (action->latency > 0) {
220 min = action->latency;
221 DEBUG3("Updating min (value) with %p (start %f): %f", action,
222 action->generic_action.start, min);
223 } else if (action->latency < min) {
224 min = action->latency;
225 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
226 action->generic_action.start, min);
231 DEBUG1("min value : %f", min);
236 static void ptask_update_actions_state(double now, double delta)
239 surf_action_workstation_L07_t action = NULL;
240 surf_action_workstation_L07_t next_action = NULL;
241 xbt_swag_t running_actions =
242 surf_workstation_model->states.running_action_set;
244 xbt_swag_foreach_safe(action, next_action, running_actions) {
246 if (action->latency > 0) {
247 if (action->latency > deltap) {
248 double_update(&(action->latency), deltap);
251 double_update(&(deltap), action->latency);
252 action->latency = 0.0;
254 if ((action->latency == 0.0) && (action->suspended == 0)) {
255 ptask_update_action_bound(action);
256 lmm_update_variable_weight(ptask_maxmin_system, action->variable,
260 DEBUG3("Action (%p) : remains (%g) updated by %g.",
261 action, action->generic_action.remains,
262 lmm_variable_getvalue(action->variable) * delta);
263 double_update(&(action->generic_action.remains),
264 lmm_variable_getvalue(action->variable) * delta);
266 if (action->generic_action.max_duration != NO_MAX_DURATION)
267 double_update(&(action->generic_action.max_duration), delta);
269 DEBUG2("Action (%p) : remains (%g).",
270 action, action->generic_action.remains);
271 if ((action->generic_action.remains <= 0) &&
272 (lmm_get_variable_weight(action->variable) > 0)) {
273 action->generic_action.finish = surf_get_clock();
274 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
275 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
276 (action->generic_action.max_duration <= 0)) {
277 action->generic_action.finish = surf_get_clock();
278 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
280 /* Need to check that none of the model has failed */
281 lmm_constraint_t cnst = NULL;
283 void *constraint_id = NULL;
286 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
288 constraint_id = lmm_constraint_id(cnst);
290 /* if(((link_L07_t)constraint_id)->type== */
291 /* SURF_WORKSTATION_RESOURCE_LINK) { */
292 /* DEBUG2("Checking for link %s (%p)", */
293 /* ((link_L07_t)constraint_id)->name, */
294 /* ((link_L07_t)constraint_id)); */
296 /* if(((cpu_L07_t)constraint_id)->type== */
297 /* SURF_WORKSTATION_RESOURCE_CPU) { */
298 /* DEBUG3("Checking for cpu %s (%p) : %s", */
299 /* ((cpu_L07_t)constraint_id)->name, */
300 /* ((cpu_L07_t)constraint_id), */
301 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
304 if (((((link_L07_t) constraint_id)->type ==
305 SURF_WORKSTATION_RESOURCE_LINK) &&
306 (((link_L07_t) constraint_id)->state_current ==
307 SURF_RESOURCE_OFF)) ||
308 ((((cpu_L07_t) constraint_id)->type ==
309 SURF_WORKSTATION_RESOURCE_CPU) &&
310 (((cpu_L07_t) constraint_id)->state_current ==
311 SURF_RESOURCE_OFF))) {
312 DEBUG1("Action (%p) Failed!!", action);
313 action->generic_action.finish = surf_get_clock();
314 surf_action_state_set((surf_action_t) action, SURF_ACTION_FAILED);
323 static void ptask_update_resource_state(void *id,
324 tmgr_trace_event_t event_type,
325 double value, double date)
328 link_L07_t nw_link = id;
330 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
331 DEBUG2("Updating link %s (%p)", surf_resource_name(nw_link), nw_link);
332 if (event_type == nw_link->bw_event) {
333 nw_link->bw_current = value;
334 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
335 nw_link->bw_current);
336 if (tmgr_trace_event_free(event_type))
337 nw_link->bw_event = NULL;
338 } else if (event_type == nw_link->lat_event) {
339 lmm_variable_t var = NULL;
340 surf_action_workstation_L07_t action = NULL;
341 lmm_element_t elem = NULL;
343 nw_link->lat_current = value;
344 while ((var = lmm_get_var_from_cnst
345 (ptask_maxmin_system, nw_link->constraint, &elem))) {
348 action = lmm_variable_id(var);
349 ptask_update_action_bound(action);
351 if (tmgr_trace_event_free(event_type))
352 nw_link->lat_event = NULL;
354 } else if (event_type == nw_link->state_event) {
356 nw_link->state_current = SURF_RESOURCE_ON;
358 nw_link->state_current = SURF_RESOURCE_OFF;
359 if (tmgr_trace_event_free(event_type))
360 nw_link->state_event = NULL;
362 CRITICAL0("Unknown event ! \n");
366 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
367 DEBUG3("Updating cpu %s (%p) with value %g", surf_resource_name(cpu), cpu,
369 if (event_type == cpu->power_event) {
370 cpu->power_current = value;
371 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
372 cpu->power_current * cpu->power_scale);
373 if (tmgr_trace_event_free(event_type))
374 cpu->power_event = NULL;
375 } else if (event_type == cpu->state_event) {
377 cpu->state_current = SURF_RESOURCE_ON;
379 cpu->state_current = SURF_RESOURCE_OFF;
380 if (tmgr_trace_event_free(event_type))
381 cpu->state_event = NULL;
383 CRITICAL0("Unknown event ! \n");
393 static void ptask_finalize(void)
395 if (ptask_parallel_task_link_set != NULL)
396 xbt_dict_free(&ptask_parallel_task_link_set);
398 surf_model_exit(surf_workstation_model);
399 surf_workstation_model = NULL;
400 surf_model_exit(surf_network_model);
401 surf_network_model = NULL;
402 used_routing->finalize();
404 ptask_host_count = 0;
406 if (ptask_maxmin_system) {
407 lmm_system_free(ptask_maxmin_system);
408 ptask_maxmin_system = NULL;
412 /**************************************/
413 /******* Resource Private **********/
414 /**************************************/
416 static e_surf_resource_state_t ptask_resource_get_state(void *cpu)
418 return ((cpu_L07_t) cpu)->state_current;
421 static double ptask_get_speed(void *cpu, double load)
423 return load * (((cpu_L07_t) cpu)->power_scale);
426 static double ptask_get_available_speed(void *cpu)
428 return ((cpu_L07_t) cpu)->power_current;
431 static surf_action_t ptask_execute_parallel_task(int workstation_nb,
432 void **workstation_list,
433 double *computation_amount,
434 double *communication_amount,
435 double amount, double rate)
437 surf_action_workstation_L07_t action = NULL;
442 double latency = 0.0;
444 if (ptask_parallel_task_link_set == NULL)
445 ptask_parallel_task_link_set = xbt_dict_new();
447 xbt_dict_reset(ptask_parallel_task_link_set);
449 /* Compute the number of affected resources... */
450 for (i = 0; i < workstation_nb; i++) {
451 for (j = 0; j < workstation_nb; j++) {
452 cpu_L07_t card_src = workstation_list[i];
453 cpu_L07_t card_dst = workstation_list[j];
455 xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
458 if (communication_amount[i * workstation_nb + j] > 0)
459 xbt_dynar_foreach(route, cpt, link) {
460 lat += link->lat_current;
461 xbt_dict_set(ptask_parallel_task_link_set, link->generic_resource.name,
464 latency = MAX(latency, lat);
468 nb_link = xbt_dict_length(ptask_parallel_task_link_set);
469 xbt_dict_reset(ptask_parallel_task_link_set);
471 for (i = 0; i < workstation_nb; i++)
472 if (computation_amount[i] > 0)
476 surf_action_new(sizeof(s_surf_action_workstation_L07_t), amount,
477 surf_workstation_model, 0);
478 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", action,
479 workstation_nb, nb_link);
480 action->suspended = 0; /* Should be useless because of the
481 calloc but it seems to help valgrind... */
482 action->workstation_nb = workstation_nb;
483 action->workstation_list = (cpu_L07_t *) workstation_list;
484 action->computation_amount = computation_amount;
485 action->communication_amount = communication_amount;
486 action->latency = latency;
490 lmm_variable_new(ptask_maxmin_system, action, 1.0,
491 (action->rate > 0) ? action->rate : -1.0,
492 workstation_nb + nb_link);
494 if (action->latency > 0)
495 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
497 for (i = 0; i < workstation_nb; i++)
498 lmm_expand(ptask_maxmin_system,
499 ((cpu_L07_t) workstation_list[i])->constraint,
500 action->variable, computation_amount[i]);
502 for (i = 0; i < workstation_nb; i++) {
503 for (j = 0; j < workstation_nb; j++) {
504 cpu_L07_t card_src = workstation_list[i];
505 cpu_L07_t card_dst = workstation_list[j];
507 xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
509 if (communication_amount[i * workstation_nb + j] == 0.0)
511 xbt_dynar_foreach(route, cpt, link) {
512 lmm_expand_add(ptask_maxmin_system, link->constraint,
514 communication_amount[i * workstation_nb + j]);
519 if (nb_link + nb_host == 0) {
520 action->generic_action.cost = 1.0;
521 action->generic_action.remains = 0.0;
524 return (surf_action_t) action;
527 static surf_action_t ptask_execute(void *cpu, double size)
529 void **workstation_list = xbt_new0(void *, 1);
530 double *computation_amount = xbt_new0(double, 1);
531 double *communication_amount = xbt_new0(double, 1);
533 workstation_list[0] = cpu;
534 communication_amount[0] = 0.0;
535 computation_amount[0] = size;
537 return ptask_execute_parallel_task(1, workstation_list, computation_amount,
538 communication_amount, 1, -1);
541 static surf_action_t ptask_communicate(void *src, void *dst, double size,
544 void **workstation_list = xbt_new0(void *, 2);
545 double *computation_amount = xbt_new0(double, 2);
546 double *communication_amount = xbt_new0(double, 4);
547 surf_action_t res = NULL;
549 workstation_list[0] = src;
550 workstation_list[1] = dst;
551 communication_amount[1] = size;
553 res = ptask_execute_parallel_task(2, workstation_list,
554 computation_amount, communication_amount,
560 static surf_action_t ptask_action_sleep(void *cpu, double duration)
562 surf_action_workstation_L07_t action = NULL;
564 XBT_IN2("(%s,%g)", surf_resource_name(cpu), duration);
566 action = (surf_action_workstation_L07_t) ptask_execute(cpu, 1.0);
567 action->generic_action.max_duration = duration;
568 action->suspended = 2;
569 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
572 return (surf_action_t) action;
575 static xbt_dynar_t ptask_get_route(void *src, void *dst)
577 cpu_L07_t host_src = src;
578 cpu_L07_t host_dst = dst;
580 return used_routing->get_route(host_src->id, host_dst->id);
583 static double ptask_get_link_bandwidth(const void *link)
585 return ((link_L07_t) link)->bw_current;
588 static double ptask_get_link_latency(const void *link)
590 return ((link_L07_t) link)->lat_current;
593 static int ptask_link_shared(const void *link)
595 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
598 /**************************************/
599 /*** Resource Creation & Destruction **/
600 /**************************************/
602 static cpu_L07_t ptask_cpu_new(const char *name, double power_scale,
603 double power_initial,
604 tmgr_trace_t power_trace,
605 e_surf_resource_state_t state_initial,
606 tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
608 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
609 xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
610 "Host '%s' declared several times in the platform file.", name);
612 cpu->generic_resource.model = surf_workstation_model;
613 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
614 cpu->generic_resource.name = xbt_strdup(name);
615 cpu->generic_resource.properties = current_property_set;
616 cpu->id = ptask_host_count++;
618 cpu->power_scale = power_scale;
619 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
621 cpu->power_current = power_initial;
624 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
626 cpu->state_current = state_initial;
629 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
632 lmm_constraint_new(ptask_maxmin_system, cpu,
633 cpu->power_current * cpu->power_scale);
635 xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu,
641 static void ptask_parse_cpu_init(void)
643 double power_scale = 0.0;
644 double power_initial = 0.0;
645 tmgr_trace_t power_trace = NULL;
646 e_surf_resource_state_t state_initial = SURF_RESOURCE_OFF;
647 tmgr_trace_t state_trace = NULL;
649 power_scale = get_cpu_power(A_surfxml_host_power);
650 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
651 power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
653 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
654 (A_surfxml_host_state == A_surfxml_host_state_OFF),
656 if (A_surfxml_host_state == A_surfxml_host_state_ON)
657 state_initial = SURF_RESOURCE_ON;
658 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
659 state_initial = SURF_RESOURCE_OFF;
660 state_trace = tmgr_trace_new(A_surfxml_host_state_file);
662 current_property_set = xbt_dict_new();
663 ptask_cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
664 state_initial, state_trace, current_property_set);
667 static link_L07_t ptask_link_new(char *name,
669 tmgr_trace_t bw_trace,
671 tmgr_trace_t lat_trace,
672 e_surf_resource_state_t
674 tmgr_trace_t state_trace,
675 e_surf_link_sharing_policy_t
676 policy, xbt_dict_t properties)
678 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
679 xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_set, name),
680 "Link '%s' declared several times in the platform file.", name);
682 nw_link->generic_resource.model = surf_workstation_model;
683 nw_link->generic_resource.properties = properties;
684 nw_link->generic_resource.name = name;
685 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
686 nw_link->bw_current = bw_initial;
689 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
690 nw_link->state_current = state_initial;
691 nw_link->lat_current = lat_initial;
694 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
696 nw_link->state_event =
697 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
699 nw_link->constraint =
700 lmm_constraint_new(ptask_maxmin_system, nw_link, nw_link->bw_current);
702 if (policy == SURF_LINK_FATPIPE)
703 lmm_constraint_shared(nw_link->constraint);
706 xbt_dict_set(surf_network_model->resource_set, name, nw_link,
712 static void ptask_parse_link_init(void)
716 tmgr_trace_t bw_trace;
718 tmgr_trace_t lat_trace;
719 e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
720 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
721 tmgr_trace_t state_trace;
723 name_link = xbt_strdup(A_surfxml_link_id);
724 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
725 bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
726 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
727 lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
729 xbt_assert0((A_surfxml_link_state == A_surfxml_link_state_ON)
730 || (A_surfxml_link_state ==
731 A_surfxml_link_state_OFF), "Invalid state");
732 if (A_surfxml_link_state == A_surfxml_link_state_ON)
733 state_initial_link = SURF_RESOURCE_ON;
734 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
735 state_initial_link = SURF_RESOURCE_OFF;
737 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
738 policy_initial_link = SURF_LINK_SHARED;
739 else if (A_surfxml_link_sharing_policy ==
740 A_surfxml_link_sharing_policy_FATPIPE)
741 policy_initial_link = SURF_LINK_FATPIPE;
743 state_trace = tmgr_trace_new(A_surfxml_link_state_file);
745 current_property_set = xbt_dict_new();
746 ptask_link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
747 state_initial_link, state_trace, policy_initial_link,
748 current_property_set);
751 static void ptask_add_traces(void)
753 xbt_dict_cursor_t cursor = NULL;
754 char *trace_name, *elm;
756 if (!trace_connect_list_host_avail)
759 /* Connect traces relative to cpu */
760 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
761 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
762 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
764 xbt_assert1(host, "Host %s undefined", elm);
765 xbt_assert1(trace, "Trace %s undefined", trace_name);
767 host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
770 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
771 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
772 cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
774 xbt_assert1(host, "Host %s undefined", elm);
775 xbt_assert1(trace, "Trace %s undefined", trace_name);
777 host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host);
780 /* Connect traces relative to network */
781 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
782 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
784 xbt_dict_get_or_null(surf_network_model->resource_set, elm);
786 xbt_assert1(link, "Link %s undefined", elm);
787 xbt_assert1(trace, "Trace %s undefined", trace_name);
789 link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
792 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
793 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
795 xbt_dict_get_or_null(surf_network_model->resource_set, elm);
797 xbt_assert1(link, "Link %s undefined", elm);
798 xbt_assert1(trace, "Trace %s undefined", trace_name);
800 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
803 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
804 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
806 xbt_dict_get_or_null(surf_network_model->resource_set, elm);
808 xbt_assert1(link, "Link %s undefined", elm);
809 xbt_assert1(trace, "Trace %s undefined", trace_name);
811 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
815 static void ptask_define_callbacks(const char *file)
817 /* Adding callback functions */
818 surf_parse_reset_parser();
819 surfxml_add_callback(STag_surfxml_host_cb_list, &ptask_parse_cpu_init);
820 surfxml_add_callback(STag_surfxml_link_cb_list, &ptask_parse_link_init);
821 surfxml_add_callback(ETag_surfxml_platform_cb_list, &ptask_add_traces);
825 /**************************************/
826 /********* Module creation ***********/
827 /**************************************/
829 static void ptask_model_init_internal(void)
831 surf_workstation_model = surf_model_init();
833 surf_workstation_model->action_unref = ptask_action_unref;
834 surf_workstation_model->action_cancel = ptask_action_cancel;
835 surf_workstation_model->action_state_set = surf_action_state_set;
836 surf_workstation_model->suspend = ptask_action_suspend;
837 surf_workstation_model->resume = ptask_action_resume;
838 surf_workstation_model->is_suspended = ptask_action_is_suspended;
839 surf_workstation_model->set_max_duration = ptask_action_set_max_duration;
840 surf_workstation_model->set_priority = ptask_action_set_priority;
841 surf_workstation_model->get_remains = ptask_action_get_remains;
842 surf_workstation_model->name = "Workstation ptask_L07";
844 surf_workstation_model->model_private->resource_used = ptask_resource_used;
845 surf_workstation_model->model_private->share_resources = ptask_share_resources;
846 surf_workstation_model->model_private->update_actions_state =
847 ptask_update_actions_state;
848 surf_workstation_model->model_private->update_resource_state =
849 ptask_update_resource_state;
850 surf_workstation_model->model_private->finalize = ptask_finalize;
852 surf_workstation_model->extension.workstation.execute = ptask_execute;
853 surf_workstation_model->extension.workstation.sleep = ptask_action_sleep;
854 surf_workstation_model->extension.workstation.get_state =
855 ptask_resource_get_state;
856 surf_workstation_model->extension.workstation.get_speed = ptask_get_speed;
857 surf_workstation_model->extension.workstation.get_available_speed =
858 ptask_get_available_speed;
859 surf_workstation_model->extension.workstation.communicate = ptask_communicate;
860 surf_workstation_model->extension.workstation.get_route = ptask_get_route;
861 surf_workstation_model->extension.workstation.execute_parallel_task =
862 ptask_execute_parallel_task;
863 surf_workstation_model->extension.workstation.get_link_bandwidth =
864 ptask_get_link_bandwidth;
865 surf_workstation_model->extension.workstation.get_link_latency =
866 ptask_get_link_latency;
867 surf_workstation_model->extension.workstation.link_shared = ptask_link_shared;
868 surf_workstation_model->extension.workstation.get_properties =
869 surf_resource_properties;
872 if (!ptask_maxmin_system)
873 ptask_maxmin_system = lmm_system_new();
875 routing_model_create(sizeof(link_L07_t),
876 ptask_link_new(xbt_strdup("__loopback__"),
877 498000000, NULL, 0.000015, NULL,
878 SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE,
883 /**************************************/
884 /*************** Generic **************/
885 /**************************************/
886 void surf_workstation_model_init_ptask_L07(const char *filename)
888 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
889 xbt_assert0(!surf_network_model, "network model type already defined");
890 surf_network_model = surf_model_init();
891 ptask_define_callbacks(filename);
892 ptask_model_init_internal();
894 update_model_description(surf_workstation_model_description,
895 "ptask_L07", surf_workstation_model);
896 xbt_dynar_push(model_list, &surf_workstation_model);