1 /* Authors: Arnaud Legrand */
3 /* This program is free software; you can redistribute it and/or modify it
4 under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "cpu_private.h"
9 surf_cpu_resource_t surf_cpu_resource = NULL;
10 static xbt_dict_t cpu_set = NULL;
11 static lmm_system_t sys = NULL;
15 xbt_maxmin_float_t power_scale;
16 xbt_maxmin_float_t current_power;
17 tmgr_trace_t power_trace;
18 e_surf_action_state_t current_state;
19 tmgr_trace_t state_trace;
20 lmm_constraint_t constraint;
23 /* power_scale is the basic power of the cpu when the cpu is
24 completely available. initial_power is therefore expected to be
25 comprised between 0.0 and 1.0, just as the values of power_trace.
26 state_trace values mean SURF_CPU_ON if >0 and SURF_CPU_OFF
30 static void *new_cpu(const char *name, xbt_maxmin_float_t power_scale,
31 xbt_maxmin_float_t initial_power, tmgr_trace_t power_trace,
32 e_surf_cpu_state_t initial_state, tmgr_trace_t state_trace)
34 cpu_t cpu = xbt_new0(s_cpu_t,1);
37 cpu->power_scale = power_scale;
38 cpu->current_power = initial_power;
39 cpu->power_trace = power_trace;
40 cpu->current_state = initial_state;
41 cpu->state_trace = state_trace;
42 cpu->constraint = lmm_constraint_new(sys, cpu, cpu->current_power);
44 xbt_dict_set(cpu_set, name, cpu, NULL);
49 static void parse_file(const char *file)
51 new_cpu("Cpu A", 200.0, 1.0, NULL, SURF_CPU_ON, NULL);
52 new_cpu("Cpu B", 100.0, 1.0, NULL, SURF_CPU_ON, NULL);
55 static void *name_service(const char *name)
59 xbt_dict_get(cpu_set, name, &cpu);
64 static const char *get_resource_name(void *resource_id)
66 return ((cpu_t) resource_id)->name;
69 static surf_action_t action_new(void *callback)
74 static e_surf_action_state_t action_get_state(surf_action_t action)
76 return SURF_ACTION_NOT_IN_THE_SYSTEM;
79 static void action_free(surf_action_t * action)
84 static void action_cancel(surf_action_t action)
89 static void action_recycle(surf_action_t action)
94 static void action_change_state(surf_action_t action, e_surf_action_state_t state)
96 surf_action_change_state(action, state);
100 static xbt_heap_float_t share_resources(void)
105 static void solve(xbt_heap_float_t date)
110 static surf_action_t execute(void *cpu, xbt_maxmin_float_t size)
115 static e_surf_cpu_state_t get_state(void *cpu)
121 surf_cpu_resource_t surf_cpu_resource_init(void)
123 surf_cpu_resource = xbt_new0(s_surf_cpu_resource_t,1);
125 surf_cpu_resource->resource.parse_file = parse_file;
126 surf_cpu_resource->resource.name_service = name_service;
127 surf_cpu_resource->resource.get_resource_name = get_resource_name;
128 surf_cpu_resource->resource.action_get_state=surf_action_get_state;
129 surf_cpu_resource->resource.action_free = action_free;
130 surf_cpu_resource->resource.action_cancel = action_cancel;
131 surf_cpu_resource->resource.action_recycle = action_recycle;
132 surf_cpu_resource->resource.action_change_state = action_change_state;
133 surf_cpu_resource->resource.share_resources = share_resources;
134 surf_cpu_resource->resource.solve = solve;
136 surf_cpu_resource->execute = execute;
137 surf_cpu_resource->get_state = get_state;
139 cpu_set = xbt_dict_new();
141 sys = lmm_system_new();
143 return surf_cpu_resource;