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_HOST_INTERFACE_HPP_
13 #define SURF_HOST_INTERFACE_HPP_
20 typedef HostModel *HostModelPtr;
23 typedef Host *HostPtr;
26 typedef HostAction *HostActionPtr;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Host creation *
34 * @details Callback functions have the following signature: `void(HostPtr)`
36 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Host destruction *
40 * @details Callback functions have the following signature: `void(HostPtr)`
42 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after Host State changed *
46 * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
48 XBT_PUBLIC_DATA(surf_callback(void, HostPtr, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
50 /** @ingroup SURF_callbacks
51 * @brief Callbacks handler which emit the callbacks after HostAction State changed *
52 * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
54 XBT_PUBLIC_DATA(surf_callback(void, HostActionPtr, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
59 XBT_PUBLIC_DATA(HostModelPtr) surf_host_model;
60 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
61 XBT_PUBLIC(void) host_add_traces();
66 /** @ingroup SURF_host_interface
67 * @brief SURF Host model interface class
68 * @details A model is an object which handle the interactions between its Resources and its Actions
70 class HostModel : public Model {
73 * @brief HostModel constructor
75 * @param name the name of the model
77 HostModel(const char *name);
79 /** @brief HostModel constructor */
82 /** @brief HostModel destructor */
85 virtual HostPtr createHost(const char *name)=0;
86 void addTraces(){DIE_IMPOSSIBLE;}
89 * @brief [brief description]
90 * @details [long description]
92 virtual void adjustWeightOfDummyCpuActions();
95 * @brief [brief description]
96 * @details [long description]
98 * @param host_nb [description]
99 * @param host_list [description]
100 * @param flops_amount [description]
101 * @param bytes_amount [description]
102 * @param rate [description]
103 * @return [description]
105 virtual ActionPtr executeParallelTask(int host_nb,
107 double *flops_amount,
108 double *bytes_amount,
112 * @brief [brief description]
113 * @details [long description]
115 * @param src [description]
116 * @param dst [description]
117 * @param size [description]
118 * @param rate [description]
119 * @return [description]
121 virtual ActionPtr communicate(HostPtr src, HostPtr dst, double size, double rate)=0;
123 CpuModelPtr p_cpuModel;
129 /** @ingroup SURF_host_interface
130 * @brief SURF Host interface class
131 * @details An host represents a machine with a aggregation of a Cpu, a NetworkLink and a Storage
133 class Host : public Resource {
136 * @brief Host constructor
141 * @brief Host constructor
143 * @param model HostModel associated to this Host
144 * @param name The name of the Host
145 * @param props Dictionary of properties associated to this Host
146 * @param storage The Storage associated to this Host
147 * @param netElm The RoutingEdge associated to this Host
148 * @param cpu The Cpu associated to this Host
150 Host(ModelPtr model, const char *name, xbt_dict_t props,
151 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
154 * @brief Host constructor
156 * @param model HostModel associated to this Host
157 * @param name The name of the Host
158 * @param props Dictionary of properties associated to this Host
159 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
160 * @param storage The Storage associated to this Host
161 * @param netElm The RoutingEdge associated to this Host
162 * @param cpu The Cpu associated to this Host
164 Host(ModelPtr model, const char *name, xbt_dict_t props,
165 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdgePtr netElm,
168 /** @brief Host destructor */
171 void setState(e_surf_resource_state_t state);
174 * @brief Get the properties of the current Host
176 * @return The properties of the current Host
178 xbt_dict_t getProperties();
181 * @brief Execute some quantity of computation
183 * @param flops_amount The value of the processing amount (in flop) needed to process
184 * @return The CpuAction corresponding to the processing
187 virtual ActionPtr execute(double flops_amount)=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 setPstate(int pstate_index);
235 virtual int getPstate();
238 * @brief Return the storage of corresponding mount point
240 * @param storage The mount point
241 * @return The corresponding Storage
243 virtual StoragePtr findStorageOnMountList(const char* storage);
246 * @brief Get the xbt_dict_t of mount_point: Storage
248 * @return The xbt_dict_t of mount_point: Storage
250 virtual xbt_dict_t getMountedStorageList();
253 * @brief Get the xbt_dynar_t of storages attached to the Host
255 * @return The xbt_dynar_t of Storage names
257 virtual xbt_dynar_t getAttachedStorageList();
262 * @param fullpath The full path to the file
264 * @return The StorageAction corresponding to the opening
266 virtual ActionPtr open(const char* fullpath);
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 Get the size in bytes of the file
288 * @param fd The file descriptor to read
289 * @return The size in bytes of the file
291 virtual sg_size_t getSize(surf_file_t fd);
296 * @param fd The file descriptor to read
297 * @param size The size in bytes to read
298 * @return The StorageAction corresponding to the reading
300 virtual ActionPtr read(surf_file_t fd, sg_size_t size);
303 * @brief Write a file
305 * @param fd The file descriptor to write
306 * @param size The size in bytes to write
307 * @return The StorageAction corresponding to the writing
309 virtual ActionPtr write(surf_file_t fd, sg_size_t size);
312 * @brief Get the informations of a file descriptor
313 * @details The returned xbt_dynar_t contains:
314 * - the size of the file,
316 * - the storage name,
317 * - the storage typeId,
318 * - the storage content type
320 * @param fd The file descriptor
321 * @return An xbt_dynar_t with the file informations
323 virtual xbt_dynar_t getInfo(surf_file_t fd);
326 * @brief Get the current position of the file descriptor
328 * @param fd The file descriptor
329 * @return The current position of the file descriptor
331 virtual sg_size_t fileTell(surf_file_t fd);
334 * @brief Set the position indicator associated with the file descriptor to a new position
335 * @details [long description]
337 * @param fd The file descriptor
338 * @param offset The offset from the origin
339 * @param origin Position used as a reference for the offset
340 * - SEEK_SET: beginning of the file
341 * - SEEK_CUR: current position indicator
342 * - SEEK_END: end of the file
343 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
345 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
348 * @brief Move a file to another location on the *same mount point*.
349 * @details [long description]
351 * @param fd The file descriptor
352 * @param fullpath The new full path
353 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
354 * full path is not on the same mount point
356 virtual int fileMove(surf_file_t fd, const char* fullpath);
358 xbt_dynar_t p_storage;
359 RoutingEdgePtr p_netElm;
361 NetworkLinkPtr p_network;
364 * @brief Get the list of virtual machines on the current Host
366 * @return The list of VMs
368 xbt_dynar_t getVms();
372 * @brief [brief description]
373 * @details [long description]
375 * @param params [description]
377 void getParams(ws_params_t params);
380 * @brief [brief description]
381 * @details [long description]
383 * @param params [description]
385 void setParams(ws_params_t params);
386 s_ws_params_t p_params;
393 /** @ingroup SURF_host_interface
394 * @brief SURF host action interface class
396 class HostAction : public Action {
399 * @brief HostAction constructor
401 * @param model The HostModel associated to this HostAction
402 * @param cost The cost of this HostAction in [TODO]
403 * @param failed [description]
405 HostAction(ModelPtr model, double cost, bool failed)
406 : Action(model, cost, failed) {}
409 * @brief HostAction constructor
411 * @param model The HostModel associated to this HostAction
412 * @param cost The cost of this HostAction in [TODO]
413 * @param failed [description]
414 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
416 HostAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
417 : Action(model, cost, failed, var) {}
419 void setState(e_surf_action_state_t state);
423 #endif /* SURF_Host_INTERFACE_HPP_ */