1 /* Copyright (c) 2004-2014. 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. */
7 #include "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
12 #ifndef SURF_WORKSTATION_INTERFACE_HPP_
13 #define SURF_WORKSTATION_INTERFACE_HPP_
19 class WorkstationModel;
20 typedef WorkstationModel *WorkstationModelPtr;
23 typedef Workstation *WorkstationPtr;
25 class WorkstationAction;
26 typedef WorkstationAction *WorkstationActionPtr;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Workstation creation *
34 * @details Callback functions have the following signature: `void(WorkstationPtr)`
36 extern surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Workstation destruction *
40 * @details Callback functions have the following signature: `void(WorkstationPtr)`
42 extern surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after Workstation State changed *
46 * @details Callback functions have the following signature: `void(WorkstationActionPtr)`
48 extern surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
50 /** @ingroup SURF_callbacks
51 * @brief Callbacks handler which emit the callbacks after WorkstationAction State changed *
52 * @details Callback functions have the following signature: `void(WorkstationActionPtr)`
54 extern surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
59 extern WorkstationModelPtr surf_workstation_model;
64 /** @ingroup SURF_workstation_interface
65 * @brief SURF Workstation model interface class
66 * @details A model is an object which handle the interactions between its Resources and its Actions
68 class WorkstationModel : public Model {
71 * @brief WorkstationModel constructor
73 * @param name the name of the model
75 WorkstationModel(const char *name);
78 * @brief WorkstationModel constructor
83 * @brief WorkstationModel destructor
88 * @brief [brief description]
89 * @details [long description]
91 virtual void adjustWeightOfDummyCpuActions();
94 * @brief [brief description]
95 * @details [long description]
97 * @param workstation_nb [description]
98 * @param workstation_list [description]
99 * @param computation_amount [description]
100 * @param communication_amount [description]
101 * @param rate [description]
102 * @return [description]
104 virtual ActionPtr executeParallelTask(int workstation_nb,
105 void **workstation_list,
106 double *computation_amount,
107 double *communication_amount,
111 * @brief [brief description]
112 * @details [long description]
114 * @param src [description]
115 * @param dst [description]
116 * @param size [description]
117 * @param rate [description]
118 * @return [description]
120 virtual ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate)=0;
122 CpuModelPtr p_cpuModel;
128 /** @ingroup SURF_workstation_interface
129 * @brief SURF Workstation interface class
130 * @details A workstation VM represent an virtual machine with a aggregation of a Cpu, a NetworkLink and a Storage
132 class Workstation : public Resource {
135 * @brief Workstation consrtuctor
140 * @brief Workstation constructor
142 * @param model WorkstationModel associated to this Workstation
143 * @param name The name of the Workstation
144 * @param props Dictionary of properties associated to this Workstation
145 * @param storage The Storage associated to this Workstation
146 * @param netElm The RoutingEdge associated to this Workstation
147 * @param cpu The Cpu associated to this Workstation
149 Workstation(ModelPtr model, const char *name, xbt_dict_t props,
150 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
153 * @brief Workstation constructor
155 * @param model WorkstationModel associated to this Workstation
156 * @param name The name of the Workstation
157 * @param props Dictionary of properties associated to this Workstation
158 * @param constraint The lmm constraint associated to this Workstation if it is part of a LMM component
159 * @param storage The Storage associated to this Workstation
160 * @param netElm The RoutingEdge associated to this Workstation
161 * @param cpu The Cpu associated to this Workstation
163 Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
164 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
167 * @brief Workstation destructor
171 void setState(e_surf_resource_state_t state);
174 * @brief Get the properties of the currenrt Workstation
176 * @return The properties of the current Workstation
178 xbt_dict_t getProperties();
181 * @brief Execute some quantity of computation
183 * @param size The value of the processing amount (in flop) needed to process
184 * @return The CpuAction corresponding to the processing
187 virtual ActionPtr execute(double size)=0;
190 * @brief Make a process sleep for duration seconds
192 * @param duration The number of seconds to sleep
193 * @return The CpuAction corresponding to the sleeping
196 virtual ActionPtr sleep(double duration)=0;
199 * @brief Get the number of cores of the associated Cpu
201 * @return The number of cores of the associated Cpu
204 virtual int getCore();
207 * @brief Get the speed of the associated Cpu
210 * @return The speed of the associated Cpu
213 virtual double getSpeed(double load);
216 * @brief Get the available speed of the associated Cpu
219 * @return The available speed of the associated Cpu
222 virtual double getAvailableSpeed();
225 * @brief Get the associated Cpu power peak
227 * @return The associated Cpu power peak
230 virtual double getCurrentPowerPeak();
232 virtual double getPowerPeakAt(int pstate_index);
233 virtual int getNbPstates();
234 virtual void setPowerPeakAt(int pstate_index);
237 * @brief Return the storage of corresponding mount point
239 * @param storage The mount point
240 * @return The corresponding Storage
242 virtual StoragePtr findStorageOnMountList(const char* storage);
245 * @brief Get the xbt_dict_t of mount_point: Storage
247 * @return The xbt_dict_t of mount_point: Storage
249 virtual xbt_dict_t getMountedStorageList();
252 * @brief Get the xbt_dynar_t of storages attached to the workstation
254 * @return The xbt_dynar_t of Storage names
256 virtual xbt_dynar_t getAttachedStorageList();
261 * @param mount The mount point
262 * @param path The path to the file
264 * @return The StorageAction corresponding to the opening
266 virtual ActionPtr open(const char* mount, const char* path);
269 * @brief Close a file
271 * @param fd The file descriptor to close
272 * @return The StorageAction corresponding to the closing
274 virtual ActionPtr close(surf_file_t fd);
277 * @brief Unlink a file
278 * @details [long description]
280 * @param fd [description]
281 * @return [description]
283 virtual int unlink(surf_file_t fd);
286 * @brief List directory contents of a path
287 * @details [long description]
289 * @param mount [description]
290 * @param path The path to the directory
291 * @return The StorageAction corresponding to the ls action
293 virtual ActionPtr ls(const char* mount, const char *path);
296 * @brief Get the size in bytes of the file
298 * @param fd The file descriptor to read
299 * @return The size in bytes of the file
301 virtual sg_size_t getSize(surf_file_t fd);
306 * @param fd The file descriptor to read
307 * @param size The size in bytes to read
308 * @return The StorageAction corresponding to the reading
310 virtual ActionPtr read(surf_file_t fd, sg_size_t size);
313 * @brief Write a file
315 * @param fd The file descriptor to write
316 * @param size The size in bytes to write
317 * @return The StorageAction corresponding to the writing
319 virtual ActionPtr write(surf_file_t fd, sg_size_t size);
322 * @brief Get the informations of a file descriptor
323 * @details The returned xbt_dynar_t contains:
324 * - the size of the file,
326 * - the storage name,
327 * - the storage typeId,
328 * - the storage content type
330 * @param fd The file descriptor
331 * @return An xbt_dynar_t with the file informations
333 virtual xbt_dynar_t getInfo(surf_file_t fd);
336 * @brief Get the current position of the file descriptor
338 * @param fd The file descriptor
339 * @return The current position of the file descriptor
341 virtual sg_size_t fileTell(surf_file_t fd);
344 * @brief Get the available space of the storage at the mount point
346 * @param name The mount point
347 * @return The amount of availble space in bytes
349 virtual sg_size_t getFreeSize(const char* name);
352 * @brief Get the used space of the storage at the mount point
354 * @param name The mount point
355 * @return The amount of used space in bytes
357 virtual sg_size_t getUsedSize(const char* name);
360 * @brief Set the position indictator assiociated with the file descriptor to a new position
361 * @details [long description]
363 * @param fd The file descriptor
364 * @param offset The offset from the origin
365 * @param origin Position used as a reference for the offset
366 * - SEEK_SET: beginning of the file
367 * - SEEK_CUR: current position indicator
368 * - SEEK_END: end of the file
369 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
371 virtual int fileSeek(surf_file_t fd, sg_size_t offset, int origin);
373 xbt_dynar_t p_storage;
374 RoutingEdgePtr p_netElm;
376 NetworkLinkPtr p_network;
379 * @brief Get the list of virtual machines on the current Workstation
381 * @return The list of VMs
383 xbt_dynar_t getVms();
387 * @brief [brief description]
388 * @details [long description]
390 * @param params [description]
392 void getParams(ws_params_t params);
395 * @brief [brief description]
396 * @details [long description]
398 * @param params [description]
400 void setParams(ws_params_t params);
401 s_ws_params_t p_params;
408 /** @ingroup SURF_workstation_interface
409 * @brief SURF workstation action interface class
411 class WorkstationAction : public Action {
414 * @brief WorkstationAction constructor
416 * @param model The WorkstationModel associated to this WorkstationAction
417 * @param cost The cost of this WorkstationAction in [TODO]
418 * @param failed [description]
420 WorkstationAction(ModelPtr model, double cost, bool failed)
421 : Action(model, cost, failed) {}
424 * @brief WorkstationAction constructor
426 * @param model The WorkstationModel associated to this WorkstationAction
427 * @param cost The cost of this WorkstationAction in [TODO]
428 * @param failed [description]
429 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
431 WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
432 : Action(model, cost, failed, var) {}
434 void setState(e_surf_action_state_t state);
438 #endif /* SURF_WORKSTATION_INTERFACE_HPP_ */