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 XBT_PUBLIC_DATA(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 XBT_PUBLIC_DATA(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 action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
48 XBT_PUBLIC_DATA(surf_callback(void, WorkstationPtr, e_surf_resource_state_t, e_surf_resource_state_t)) 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 action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
54 XBT_PUBLIC_DATA(surf_callback(void, WorkstationActionPtr, e_surf_action_state_t, e_surf_action_state_t)) workstationActionStateChangedCallbacks;
59 XBT_PUBLIC_DATA(WorkstationModelPtr) surf_workstation_model;
60 XBT_PUBLIC(void) workstation_parse_init(sg_platf_host_cbarg_t host);
61 XBT_PUBLIC(void) workstation_add_traces();
66 /** @ingroup SURF_workstation_interface
67 * @brief SURF Workstation model interface class
68 * @details A model is an object which handle the interactions between its Resources and its Actions
70 class WorkstationModel : public Model {
73 * @brief WorkstationModel constructor
75 * @param name the name of the model
77 WorkstationModel(const char *name);
80 * @brief WorkstationModel constructor
85 * @brief WorkstationModel destructor
89 virtual WorkstationPtr createWorkstation(const char *name)=0;
90 void addTraces(){DIE_IMPOSSIBLE;}
93 * @brief [brief description]
94 * @details [long description]
96 virtual void adjustWeightOfDummyCpuActions();
99 * @brief [brief description]
100 * @details [long description]
102 * @param workstation_nb [description]
103 * @param workstation_list [description]
104 * @param computation_amount [description]
105 * @param communication_amount [description]
106 * @param rate [description]
107 * @return [description]
109 virtual ActionPtr executeParallelTask(int workstation_nb,
110 void **workstation_list,
111 double *computation_amount,
112 double *communication_amount,
116 * @brief [brief description]
117 * @details [long description]
119 * @param src [description]
120 * @param dst [description]
121 * @param size [description]
122 * @param rate [description]
123 * @return [description]
125 virtual ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate)=0;
127 CpuModelPtr p_cpuModel;
133 /** @ingroup SURF_workstation_interface
134 * @brief SURF Workstation interface class
135 * @details A workstation VM represent an virtual machine with a aggregation of a Cpu, a NetworkLink and a Storage
137 class Workstation : public Resource {
140 * @brief Workstation consrtuctor
145 * @brief Workstation constructor
147 * @param model WorkstationModel associated to this Workstation
148 * @param name The name of the Workstation
149 * @param props Dictionary of properties associated to this Workstation
150 * @param storage The Storage associated to this Workstation
151 * @param netElm The RoutingEdge associated to this Workstation
152 * @param cpu The Cpu associated to this Workstation
154 Workstation(ModelPtr model, const char *name, xbt_dict_t props,
155 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
158 * @brief Workstation constructor
160 * @param model WorkstationModel associated to this Workstation
161 * @param name The name of the Workstation
162 * @param props Dictionary of properties associated to this Workstation
163 * @param constraint The lmm constraint associated to this Workstation if it is part of a LMM component
164 * @param storage The Storage associated to this Workstation
165 * @param netElm The RoutingEdge associated to this Workstation
166 * @param cpu The Cpu associated to this Workstation
168 Workstation(ModelPtr model, const char *name, xbt_dict_t props,
169 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdgePtr netElm,
173 * @brief Workstation destructor
177 void setState(e_surf_resource_state_t state);
180 * @brief Get the properties of the currenrt Workstation
182 * @return The properties of the current Workstation
184 xbt_dict_t getProperties();
187 * @brief Execute some quantity of computation
189 * @param size The value of the processing amount (in flop) needed to process
190 * @return The CpuAction corresponding to the processing
193 virtual ActionPtr execute(double size)=0;
196 * @brief Make a process sleep for duration seconds
198 * @param duration The number of seconds to sleep
199 * @return The CpuAction corresponding to the sleeping
202 virtual ActionPtr sleep(double duration)=0;
205 * @brief Get the number of cores of the associated Cpu
207 * @return The number of cores of the associated Cpu
210 virtual int getCore();
213 * @brief Get the speed of the associated Cpu
216 * @return The speed of the associated Cpu
219 virtual double getSpeed(double load);
222 * @brief Get the available speed of the associated Cpu
225 * @return The available speed of the associated Cpu
228 virtual double getAvailableSpeed();
231 * @brief Get the associated Cpu power peak
233 * @return The associated Cpu power peak
236 virtual double getCurrentPowerPeak();
238 virtual double getPowerPeakAt(int pstate_index);
239 virtual int getNbPstates();
240 virtual void setPowerPeakAt(int pstate_index);
243 * @brief Return the storage of corresponding mount point
245 * @param storage The mount point
246 * @return The corresponding Storage
248 virtual StoragePtr findStorageOnMountList(const char* storage);
251 * @brief Get the xbt_dict_t of mount_point: Storage
253 * @return The xbt_dict_t of mount_point: Storage
255 virtual xbt_dict_t getMountedStorageList();
258 * @brief Get the xbt_dynar_t of storages attached to the workstation
260 * @return The xbt_dynar_t of Storage names
262 virtual xbt_dynar_t getAttachedStorageList();
267 * @param fullpath The full path to the file
269 * @return The StorageAction corresponding to the opening
271 virtual ActionPtr open(const char* fullpath);
274 * @brief Close a file
276 * @param fd The file descriptor to close
277 * @return The StorageAction corresponding to the closing
279 virtual ActionPtr close(surf_file_t fd);
282 * @brief Unlink a file
283 * @details [long description]
285 * @param fd [description]
286 * @return [description]
288 virtual int unlink(surf_file_t fd);
291 * @brief Get the size in bytes of the file
293 * @param fd The file descriptor to read
294 * @return The size in bytes of the file
296 virtual sg_size_t getSize(surf_file_t fd);
301 * @param fd The file descriptor to read
302 * @param size The size in bytes to read
303 * @return The StorageAction corresponding to the reading
305 virtual ActionPtr read(surf_file_t fd, sg_size_t size);
308 * @brief Write a file
310 * @param fd The file descriptor to write
311 * @param size The size in bytes to write
312 * @return The StorageAction corresponding to the writing
314 virtual ActionPtr write(surf_file_t fd, sg_size_t size);
317 * @brief Get the informations of a file descriptor
318 * @details The returned xbt_dynar_t contains:
319 * - the size of the file,
321 * - the storage name,
322 * - the storage typeId,
323 * - the storage content type
325 * @param fd The file descriptor
326 * @return An xbt_dynar_t with the file informations
328 virtual xbt_dynar_t getInfo(surf_file_t fd);
331 * @brief Get the current position of the file descriptor
333 * @param fd The file descriptor
334 * @return The current position of the file descriptor
336 virtual sg_size_t fileTell(surf_file_t fd);
339 * @brief Set the position indicator associated with the file descriptor to a new position
340 * @details [long description]
342 * @param fd The file descriptor
343 * @param offset The offset from the origin
344 * @param origin Position used as a reference for the offset
345 * - SEEK_SET: beginning of the file
346 * - SEEK_CUR: current position indicator
347 * - SEEK_END: end of the file
348 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
350 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
353 * @brief Move a file to another location on the *same mount point*.
354 * @details [long description]
356 * @param fd The file descriptor
357 * @param fullpath The new full path
358 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
359 * full path is not on the same mount point
361 virtual int fileMove(surf_file_t fd, const char* fullpath);
363 xbt_dynar_t p_storage;
364 RoutingEdgePtr p_netElm;
366 NetworkLinkPtr p_network;
369 * @brief Get the list of virtual machines on the current Workstation
371 * @return The list of VMs
373 xbt_dynar_t getVms();
377 * @brief [brief description]
378 * @details [long description]
380 * @param params [description]
382 void getParams(ws_params_t params);
385 * @brief [brief description]
386 * @details [long description]
388 * @param params [description]
390 void setParams(ws_params_t params);
391 s_ws_params_t p_params;
398 /** @ingroup SURF_workstation_interface
399 * @brief SURF workstation action interface class
401 class WorkstationAction : public Action {
404 * @brief WorkstationAction constructor
406 * @param model The WorkstationModel associated to this WorkstationAction
407 * @param cost The cost of this WorkstationAction in [TODO]
408 * @param failed [description]
410 WorkstationAction(ModelPtr model, double cost, bool failed)
411 : Action(model, cost, failed) {}
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]
419 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
421 WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
422 : Action(model, cost, failed, var) {}
424 void setState(e_surf_action_state_t state);
428 #endif /* SURF_WORKSTATION_INTERFACE_HPP_ */