Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unnecessry files
[simgrid.git] / src / surf / workstation.cpp
1 #include "workstation.hpp"
2 #include "simgrid/sg_config.h"
3
4 extern "C" {
5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
6                                 "Logging specific to the SURF workstation module");
7 }
8
9 WorkstationModelPtr surf_workstation_model = NULL;
10
11 //FIXME:Faire hériter ou composer de cup et network
12
13 /*************
14  * CallBacks *
15  *************/
16
17 static void workstation_new(sg_platf_host_cbarg_t host){
18   surf_workstation_model->createResource(host->id);
19 }
20
21 /*********
22  * Model *
23  *********/
24
25 void surf_workstation_model_init_current_default(void)
26 {
27   surf_workstation_model = new WorkstationModel();
28   xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
29   surf_cpu_model_init_Cas01();
30   surf_network_model_init_LegrandVelho();
31
32   ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
33   xbt_dynar_push(model_list, &model);
34   sg_platf_host_add_cb(workstation_new);
35 }
36
37 void surf_workstation_model_init_compound()
38 {
39
40   xbt_assert(surf_cpu_model, "No CPU model defined yet!");
41   xbt_assert(surf_network_model, "No network model defined yet!");
42   surf_workstation_model = new WorkstationModel();
43
44   ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
45   xbt_dynar_push(model_list, &model);
46   sg_platf_host_add_cb(workstation_new);
47 }
48
49 WorkstationModel::WorkstationModel() : Model("Workstation") {
50 }
51
52 WorkstationModel::~WorkstationModel() {
53 }
54
55 void WorkstationModel::parseInit(sg_platf_host_cbarg_t host){
56   createResource(host->id);
57 }
58
59 WorkstationCLM03Ptr WorkstationModel::createResource(string name){
60
61   WorkstationCLM03Ptr workstation = new WorkstationCLM03(surf_workstation_model, name.c_str(), NULL,
62                   (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name.c_str(), ROUTING_STORAGE_HOST_LEVEL),
63                   (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name.c_str(), ROUTING_HOST_LEVEL),
64                   dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(host_lib, name.c_str(), SURF_CPU_LEVEL))));
65   XBT_DEBUG("Create workstation %s with %ld mounted disks", name.c_str(), xbt_dynar_length(workstation->p_storage));
66   xbt_lib_set(host_lib, name.c_str(), SURF_WKS_LEVEL, static_cast<ResourcePtr>(workstation));
67   return workstation;
68 }
69
70 double WorkstationModel::shareResources(double now){
71   return -1.0;
72 }
73
74 void WorkstationModel::updateActionsState(double now, double delta){
75   return;
76 }
77
78 ActionPtr WorkstationModel::executeParallelTask(int workstation_nb,
79                                         void **workstation_list,
80                                         double *computation_amount,
81                                         double *communication_amount,
82                                         double rate){
83 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
84   if ((workstation_nb == 1)
85       && (cost_or_zero(communication_amount, 0) == 0.0))
86     return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]);
87   else if ((workstation_nb == 1)
88            && (cost_or_zero(computation_amount, 0) == 0.0))
89     return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate);
90   else if ((workstation_nb == 2)
91              && (cost_or_zero(computation_amount, 0) == 0.0)
92              && (cost_or_zero(computation_amount, 1) == 0.0)) {
93     int i,nb = 0;
94     double value = 0.0;
95
96     for (i = 0; i < workstation_nb * workstation_nb; i++) {
97       if (cost_or_zero(communication_amount, i) > 0.0) {
98         nb++;
99         value = cost_or_zero(communication_amount, i);
100       }
101     }
102     if (nb == 1)
103       return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
104   }
105 #undef cost_or_zero
106
107   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
108   return NULL;
109 }
110
111 /* returns an array of network_link_CM02_t */
112 xbt_dynar_t WorkstationModel::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst)
113 {
114   XBT_DEBUG("ws_get_route");
115   return surf_network_model->getRoute(src->p_netElm, dst->p_netElm);
116 }
117
118 ActionPtr WorkstationModel::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate){
119   return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
120 }
121
122
123
124 /************
125  * Resource *
126  ************/
127 WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
128   : Resource(model, name, properties), p_storage(storage), p_netElm(netElm), p_cpu(cpu) {}
129
130 bool WorkstationCLM03::isUsed(){
131   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
132   return -1;
133 }
134
135 void WorkstationCLM03::updateState(tmgr_trace_event_t event_type, double value, double date){
136   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
137 }
138
139 ActionPtr WorkstationCLM03::execute(double size) {
140   return p_cpu->execute(size);
141 }
142
143 ActionPtr WorkstationCLM03::sleep(double duration) {
144   return p_cpu->sleep(duration);
145 }
146
147 e_surf_resource_state_t WorkstationCLM03::getState() {
148   return p_cpu->getState();
149 }
150
151 int WorkstationCLM03::getCore(){
152   return p_cpu->getCore();
153 }
154
155 double WorkstationCLM03::getSpeed(double load){
156   return p_cpu->getSpeed(load);
157 }
158
159 double WorkstationCLM03::getAvailableSpeed(){
160   return p_cpu->getAvailableSpeed();
161 }
162
163 double WorkstationCLM03::getCurrentPowerPeak()
164 {
165   return p_cpu->getCurrentPowerPeak();
166 }
167
168 double WorkstationCLM03::getPowerPeakAt(int pstate_index)
169 {
170   return p_cpu->getPowerPeakAt(pstate_index);
171 }
172
173 int WorkstationCLM03::getNbPstates()
174 {
175   return p_cpu->getNbPstates();
176 }
177
178 void WorkstationCLM03::setPowerPeakAt(int pstate_index)
179 {
180         p_cpu->setPowerPeakAt(pstate_index);
181 }
182
183 double WorkstationCLM03::getConsumedEnergy()
184 {
185   return p_cpu->getConsumedEnergy();
186 }
187
188
189 xbt_dict_t WorkstationCLM03::getProperties()
190 {
191   return p_cpu->m_properties;
192 }
193
194
195 StoragePtr WorkstationCLM03::findStorageOnMountList(const char* mount)
196 {
197   StoragePtr st = NULL;
198   s_mount_t mnt;
199   unsigned int cursor;
200
201   XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name);
202   xbt_dynar_foreach(p_storage,cursor,mnt)
203   {
204     XBT_DEBUG("See '%s'",mnt.name);
205     if(!strcmp(mount,mnt.name)){
206       st = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage));
207       break;
208     }
209   }
210   if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name);
211   return st;
212 }
213
214 xbt_dict_t WorkstationCLM03::getStorageList()
215 {
216   s_mount_t mnt;
217   unsigned int i;
218   xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
219   char *storage_name = NULL;
220
221   xbt_dynar_foreach(p_storage,i,mnt){
222     storage_name = (char *)dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage))->m_name;
223     xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
224   }
225   return storage_list;
226 }
227
228 ActionPtr WorkstationCLM03::open(const char* mount, const char* path) {
229   StoragePtr st = findStorageOnMountList(mount);
230   XBT_DEBUG("OPEN on disk '%s'", st->m_name);
231   return st->open(mount, path);
232 }
233
234 ActionPtr WorkstationCLM03::close(surf_file_t fd) {
235   StoragePtr st = findStorageOnMountList(fd->mount);
236   XBT_DEBUG("CLOSE on disk '%s'",st->m_name);
237   return st->close(fd);
238 }
239
240 ActionPtr WorkstationCLM03::read(surf_file_t fd, sg_storage_size_t size) {
241   StoragePtr st = findStorageOnMountList(fd->mount);
242   XBT_DEBUG("READ on disk '%s'",st->m_name);
243   return st->read(fd, size);
244 }
245
246 ActionPtr WorkstationCLM03::write(surf_file_t fd, sg_storage_size_t size) {
247   StoragePtr st = findStorageOnMountList(fd->mount);
248   XBT_DEBUG("WRITE on disk '%s'",st->m_name);
249   return st->write(fd, size);
250 }
251
252 int WorkstationCLM03::unlink(surf_file_t fd) {
253   if (!fd){
254     XBT_WARN("No such file descriptor. Impossible to unlink");
255     return 0;
256   } else {
257 //    XBT_INFO("%s %zu", fd->storage, fd->size);
258     StoragePtr st = findStorageOnMountList(fd->mount);
259     /* Check if the file is on this storage */
260     if (!xbt_dict_get_or_null(st->p_content, fd->name)){
261       XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
262           st->m_name);
263       return 0;
264     } else {
265       XBT_DEBUG("UNLINK on disk '%s'",st->m_name);
266       st->m_usedSize -= fd->size;
267
268       // Remove the file from storage
269       xbt_dict_remove(st->p_content, fd->name);
270
271       free(fd->name);
272       free(fd->mount);
273       xbt_free(fd);
274       return 1;
275     }
276   }
277 }
278
279 ActionPtr WorkstationCLM03::ls(const char* mount, const char *path){
280   XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
281   StoragePtr st = findStorageOnMountList(mount);
282   return st->ls(path);
283 }
284
285 sg_storage_size_t WorkstationCLM03::getSize(surf_file_t fd){
286   return fd->size;
287 }
288
289 xbt_dynar_t WorkstationCLM03::getInfo( surf_file_t fd)
290 {
291   StoragePtr st = findStorageOnMountList(fd->mount);
292   sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
293   *psize = fd->size;
294   xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
295   xbt_dynar_push_as(info, sg_storage_size_t *, psize);
296   xbt_dynar_push_as(info, void *, fd->mount);
297   xbt_dynar_push_as(info, void *, (void *)st->m_name);
298   xbt_dynar_push_as(info, void *, st->p_typeId);
299   xbt_dynar_push_as(info, void *, st->p_contentType);
300
301   return info;
302 }
303
304 sg_storage_size_t WorkstationCLM03::getFreeSize(const char* name)
305 {
306   StoragePtr st = findStorageOnMountList(name);
307   return st->m_size - st->m_usedSize;
308 }
309
310 sg_storage_size_t WorkstationCLM03::getUsedSize(const char* name)
311 {
312   StoragePtr st = findStorageOnMountList(name);
313   return st->m_usedSize;
314 }
315
316 e_surf_resource_state_t WorkstationCLM03Lmm::getState() {
317   return WorkstationCLM03::getState();
318 }
319 /**********
320  * Action *
321  **********/