Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Renamed host to cpu. That was really confusing.
[simgrid.git] / src / surf / cpu.c
1 /* Authors: Arnaud Legrand                                                  */
2
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. */
5
6 #include "cpu_private.h"
7 #include "xbt/dict.h"
8
9 surf_cpu_resource_t surf_cpu_resource = NULL;
10 static xbt_dict_t cpu_set = NULL;
11 static lmm_system_t sys = NULL;
12
13 typedef struct cpu {
14   const char *name;
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;
21 } s_cpu_t, *cpu_t;
22
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
27    otherwise.
28 */
29
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)
33 {
34   cpu_t cpu = xbt_new0(s_cpu_t,1);
35
36   cpu->name = name;
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);
43
44   xbt_dict_set(cpu_set, name, cpu, NULL);
45
46   return cpu;
47 }
48
49 static void parse_file(const char *file)
50 {
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);
53 }
54
55 static void *name_service(const char *name)
56 {
57   void *cpu=NULL;
58   
59   xbt_dict_get(cpu_set, name, &cpu);
60
61   return cpu;
62 }
63
64 static const char *get_resource_name(void *resource_id)
65 {
66   return ((cpu_t) resource_id)->name;
67 }
68
69 static surf_action_t action_new(void *callback)
70 {
71   return NULL;
72 }
73
74 static e_surf_action_state_t action_get_state(surf_action_t action)
75 {
76   return SURF_ACTION_NOT_IN_THE_SYSTEM;
77 }
78
79 static void action_free(surf_action_t * action)
80 {
81   return;
82 }
83
84 static void action_cancel(surf_action_t action)
85 {
86   return;
87 }
88
89 static void action_recycle(surf_action_t action)
90 {
91   return;
92 }
93
94 static void action_change_state(surf_action_t action, e_surf_action_state_t state)
95 {
96   surf_action_change_state(action, state);
97   return;
98 }
99
100 static xbt_heap_float_t share_resources(void)
101 {
102   return -1.0;
103 }
104
105 static void solve(xbt_heap_float_t date)
106 {
107   return;
108 }
109
110 static surf_action_t execute(void *cpu, xbt_maxmin_float_t size)
111 {
112   return NULL;
113 }
114
115 static e_surf_cpu_state_t get_state(void *cpu)
116 {
117   return SURF_CPU_OFF;
118 }
119
120
121 surf_cpu_resource_t surf_cpu_resource_init(void)
122 {
123   surf_cpu_resource = xbt_new0(s_surf_cpu_resource_t,1);
124
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;
135
136   surf_cpu_resource->execute = execute;
137   surf_cpu_resource->get_state = get_state;
138
139   cpu_set = xbt_dict_new();
140
141   sys = lmm_system_new();
142
143   return surf_cpu_resource;
144 }