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_
27 /** @ingroup SURF_callbacks
28 * @brief Callbacks handler which emit the callbacks after Host creation *
29 * @details Callback functions have the following signature: `void(HostPtr)`
31 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
33 /** @ingroup SURF_callbacks
34 * @brief Callbacks handler which emit the callbacks after Host destruction *
35 * @details Callback functions have the following signature: `void(HostPtr)`
37 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
39 /** @ingroup SURF_callbacks
40 * @brief Callbacks handler which emit the callbacks after Host State changed *
41 * @details Callback functions have the following signature: `void(HostAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
43 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
45 /** @ingroup SURF_callbacks
46 * @brief Callbacks handler which emit the callbacks after HostAction State changed *
47 * @details Callback functions have the following signature: `void(HostAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
49 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
54 XBT_PUBLIC_DATA(HostModel*) surf_host_model;
55 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
56 XBT_PUBLIC(void) host_add_traces();
61 /** @ingroup SURF_host_interface
62 * @brief SURF Host model interface class
63 * @details A model is an object which handle the interactions between its Resources and its Actions
65 class HostModel : public Model {
68 * @brief HostModel constructor
70 * @param name the name of the model
72 HostModel(const char *name);
74 /** @brief HostModel constructor */
77 /** @brief HostModel destructor */
80 virtual Host *createHost(const char *name)=0;
81 void addTraces(){DIE_IMPOSSIBLE;}
84 * @brief [brief description]
85 * @details [long description]
87 virtual void adjustWeightOfDummyCpuActions();
90 * @brief [brief description]
91 * @details [long description]
93 * @param host_nb [description]
94 * @param host_list [description]
95 * @param flops_amount [description]
96 * @param bytes_amount [description]
97 * @param rate [description]
98 * @return [description]
100 virtual Action *executeParallelTask(int host_nb,
102 double *flops_amount,
103 double *bytes_amount,
107 * @brief [brief description]
108 * @details [long description]
110 * @param src [description]
111 * @param dst [description]
112 * @param size [description]
113 * @param rate [description]
114 * @return [description]
116 virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0;
118 CpuModel *p_cpuModel;
124 /** @ingroup SURF_host_interface
125 * @brief SURF Host interface class
126 * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
128 class Host : public Resource {
131 * @brief Host constructor
133 * @param model HostModel associated to this Host
134 * @param name The name of the Host
135 * @param props Dictionary of properties associated to this Host
136 * @param storage The Storage associated to this Host
137 * @param netElm The RoutingEdge associated to this Host
138 * @param cpu The Cpu associated to this Host
140 Host(Model *model, const char *name, xbt_dict_t props,
141 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
144 * @brief Host constructor
146 * @param model HostModel associated to this Host
147 * @param name The name of the Host
148 * @param props Dictionary of properties associated to this Host
149 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
150 * @param storage The Storage associated to this Host
151 * @param netElm The RoutingEdge associated to this Host
152 * @param cpu The Cpu associated to this Host
154 Host(Model *model, const char *name, xbt_dict_t props,
155 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
158 /** @brief Host destructor */
161 void setState(e_surf_resource_state_t state);
164 * @brief Get the properties of the current Host
166 * @return The properties of the current Host
168 xbt_dict_t getProperties();
171 * @brief Execute some quantity of computation
173 * @param flops_amount The value of the processing amount (in flop) needed to process
174 * @return The CpuAction corresponding to the processing
177 virtual Action *execute(double flops_amount)=0;
180 * @brief Make a process sleep for duration seconds
182 * @param duration The number of seconds to sleep
183 * @return The CpuAction corresponding to the sleeping
186 virtual Action *sleep(double duration)=0;
189 * @brief Get the number of cores of the associated Cpu
191 * @return The number of cores of the associated Cpu
194 virtual int getCore();
197 * @brief Get the speed of the associated Cpu
200 * @return The speed of the associated Cpu
203 virtual double getSpeed(double load);
206 * @brief Get the available speed of the associated Cpu
209 * @return The available speed of the associated Cpu
212 virtual double getAvailableSpeed();
215 * @brief Get the associated Cpu power peak
217 * @return The associated Cpu power peak
220 virtual double getCurrentPowerPeak();
222 virtual double getPowerPeakAt(int pstate_index);
223 virtual int getNbPstates();
224 virtual void setPstate(int pstate_index);
225 virtual int getPstate();
228 * @brief Return the storage of corresponding mount point
230 * @param storage The mount point
231 * @return The corresponding Storage
233 virtual Storage *findStorageOnMountList(const char* storage);
236 * @brief Get the xbt_dict_t of mount_point: Storage
238 * @return The xbt_dict_t of mount_point: Storage
240 virtual xbt_dict_t getMountedStorageList();
243 * @brief Get the xbt_dynar_t of storages attached to the Host
245 * @return The xbt_dynar_t of Storage names
247 virtual xbt_dynar_t getAttachedStorageList();
252 * @param fullpath The full path to the file
254 * @return The StorageAction corresponding to the opening
256 virtual Action *open(const char* fullpath);
259 * @brief Close a file
261 * @param fd The file descriptor to close
262 * @return The StorageAction corresponding to the closing
264 virtual Action *close(surf_file_t fd);
267 * @brief Unlink a file
268 * @details [long description]
270 * @param fd [description]
271 * @return [description]
273 virtual int unlink(surf_file_t fd);
276 * @brief Get the size in bytes of the file
278 * @param fd The file descriptor to read
279 * @return The size in bytes of the file
281 virtual sg_size_t getSize(surf_file_t fd);
286 * @param fd The file descriptor to read
287 * @param size The size in bytes to read
288 * @return The StorageAction corresponding to the reading
290 virtual Action *read(surf_file_t fd, sg_size_t size);
293 * @brief Write a file
295 * @param fd The file descriptor to write
296 * @param size The size in bytes to write
297 * @return The StorageAction corresponding to the writing
299 virtual Action *write(surf_file_t fd, sg_size_t size);
302 * @brief Get the informations of a file descriptor
303 * @details The returned xbt_dynar_t contains:
304 * - the size of the file,
306 * - the storage name,
307 * - the storage typeId,
308 * - the storage content type
310 * @param fd The file descriptor
311 * @return An xbt_dynar_t with the file informations
313 virtual xbt_dynar_t getInfo(surf_file_t fd);
316 * @brief Get the current position of the file descriptor
318 * @param fd The file descriptor
319 * @return The current position of the file descriptor
321 virtual sg_size_t fileTell(surf_file_t fd);
324 * @brief Set the position indicator associated with the file descriptor to a new position
325 * @details [long description]
327 * @param fd The file descriptor
328 * @param offset The offset from the origin
329 * @param origin Position used as a reference for the offset
330 * - SEEK_SET: beginning of the file
331 * - SEEK_CUR: current position indicator
332 * - SEEK_END: end of the file
333 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
335 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
338 * @brief Move a file to another location on the *same mount point*.
339 * @details [long description]
341 * @param fd The file descriptor
342 * @param fullpath The new full path
343 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
344 * full path is not on the same mount point
346 virtual int fileMove(surf_file_t fd, const char* fullpath);
348 xbt_dynar_t p_storage;
349 RoutingEdge *p_netElm;
353 * @brief Get the list of virtual machines on the current Host
355 * @return The list of VMs
357 xbt_dynar_t getVms();
361 * @brief [brief description]
362 * @details [long description]
364 * @param params [description]
366 void getParams(ws_params_t params);
369 * @brief [brief description]
370 * @details [long description]
372 * @param params [description]
374 void setParams(ws_params_t params);
375 s_ws_params_t p_params;
382 /** @ingroup SURF_host_interface
383 * @brief SURF host action interface class
385 class HostAction : public Action {
388 * @brief HostAction constructor
390 * @param model The HostModel associated to this HostAction
391 * @param cost The cost of this HostAction in [TODO]
392 * @param failed [description]
394 HostAction(Model *model, double cost, bool failed)
395 : Action(model, cost, failed) {}
398 * @brief HostAction constructor
400 * @param model The HostModel associated to this HostAction
401 * @param cost The cost of this HostAction in [TODO]
402 * @param failed [description]
403 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
405 HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
406 : Action(model, cost, failed, var) {}
408 void setState(e_surf_action_state_t state);
412 #endif /* SURF_Host_INTERFACE_HPP_ */