1 /* Copyright (c) 2004-2015. 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"
11 #include "src/surf/PropertyHolder.hpp"
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE Host;
27 class XBT_PRIVATE HostAction;
36 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
37 XBT_PUBLIC(void) host_add_traces();
46 /** @ingroup SURF_host_interface
47 * @brief SURF Host model interface class
48 * @details A model is an object which handle the interactions between its Resources and its Actions
50 class HostModel : public Model{
52 HostModel() : Model() {}
55 virtual Host *createHost(const char *name, RoutingEdge *net, Cpu *cpu, xbt_dict_t props)=0;
56 void addTraces() override {DIE_IMPOSSIBLE;}
58 virtual void adjustWeightOfDummyCpuActions();
59 virtual Action *executeParallelTask(int host_nb,
65 bool shareResourcesIsIdempotent() override {return true;}
71 /** @ingroup SURF_host_interface
72 * @brief SURF Host interface class
73 * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
75 class Host : public simgrid::surf::Resource,
76 public simgrid::surf::PropertyHolder {
78 static simgrid::xbt::Extension<simgrid::Host, Host> EXTENSION_ID;
81 static simgrid::surf::signal<void(Host*)> onCreation; /** Called on each newly created object */
82 static simgrid::surf::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
83 static simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
86 static void classInit();
88 * @brief Host constructor
90 * @param model HostModel associated to this Host
91 * @param name The name of the Host
92 * @param props Dictionary of properties associated to this Host
93 * @param storage The Storage associated to this Host
94 * @param netElm The RoutingEdge associated to this Host
95 * @param cpu The Cpu associated to this Host
97 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
98 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
101 * @brief Host constructor
103 * @param model HostModel associated to this Host
104 * @param name The name of the Host
105 * @param props Dictionary of properties associated to this Host
106 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
107 * @param storage The Storage associated to this Host
108 * @param netElm The RoutingEdge associated to this Host
109 * @param cpu The Cpu associated to this Host
111 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
112 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
115 /* Host destruction logic */
116 /**************************/
120 void destroy(); // Must be called instead of the destructor
122 bool currentlyDestroying_ = false;
126 void attach(simgrid::Host* host);
128 e_surf_resource_state_t getState();
129 void setState(e_surf_resource_state_t state);
132 * @brief Execute some quantity of computation
134 * @param flops_amount The value of the processing amount (in flop) needed to process
135 * @return The CpuAction corresponding to the processing
138 virtual Action *execute(double flops_amount)=0;
141 * @brief Make a process sleep for duration seconds
143 * @param duration The number of seconds to sleep
144 * @return The CpuAction corresponding to the sleeping
147 virtual Action *sleep(double duration)=0;
149 /** @brief Return the storage of corresponding mount point */
150 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
152 /** @brief Get the xbt_dict_t of mount_point: Storage */
153 virtual xbt_dict_t getMountedStorageList();
155 /** @brief Get the xbt_dynar_t of storages attached to the Host */
156 virtual xbt_dynar_t getAttachedStorageList();
161 * @param fullpath The full path to the file
162 * @return The StorageAction corresponding to the opening
164 virtual Action *open(const char* fullpath);
167 * @brief Close a file
169 * @param fd The file descriptor to close
170 * @return The StorageAction corresponding to the closing
172 virtual Action *close(surf_file_t fd);
175 * @brief Unlink a file
176 * @details [long description]
178 * @param fd [description]
179 * @return [description]
181 virtual int unlink(surf_file_t fd);
184 * @brief Get the size in bytes of the file
186 * @param fd The file descriptor to read
187 * @return The size in bytes of the file
189 virtual sg_size_t getSize(surf_file_t fd);
194 * @param fd The file descriptor to read
195 * @param size The size in bytes to read
196 * @return The StorageAction corresponding to the reading
198 virtual Action *read(surf_file_t fd, sg_size_t size);
201 * @brief Write a file
203 * @param fd The file descriptor to write
204 * @param size The size in bytes to write
205 * @return The StorageAction corresponding to the writing
207 virtual Action *write(surf_file_t fd, sg_size_t size);
210 * @brief Get the informations of a file descriptor
211 * @details The returned xbt_dynar_t contains:
212 * - the size of the file,
214 * - the storage name,
215 * - the storage typeId,
216 * - the storage content type
218 * @param fd The file descriptor
219 * @return An xbt_dynar_t with the file informations
221 virtual xbt_dynar_t getInfo(surf_file_t fd);
224 * @brief Get the current position of the file descriptor
226 * @param fd The file descriptor
227 * @return The current position of the file descriptor
229 virtual sg_size_t fileTell(surf_file_t fd);
232 * @brief Set the position indicator associated with the file descriptor to a new position
233 * @details [long description]
235 * @param fd The file descriptor
236 * @param offset The offset from the origin
237 * @param origin Position used as a reference for the offset
238 * - SEEK_SET: beginning of the file
239 * - SEEK_CUR: current position indicator
240 * - SEEK_END: end of the file
241 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
243 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
246 * @brief Move a file to another location on the *same mount point*.
247 * @details [long description]
249 * @param fd The file descriptor
250 * @param fullpath The new full path
251 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
252 * full path is not on the same mount point
254 virtual int fileMove(surf_file_t fd, const char* fullpath);
257 xbt_dynar_t p_storage;
258 RoutingEdge *p_netElm;
260 simgrid::Host* p_host = nullptr;
262 /** @brief Get the list of virtual machines on the current Host */
263 xbt_dynar_t getVms();
266 /** @brief Retrieve a copy of the parameters of that VM/PM
267 * @details The ramsize and overcommit fields are used on the PM too */
268 void getParams(vm_params_t params);
269 /** @brief Sets the params of that VM/PM */
270 void setParams(vm_params_t params);
271 simgrid::Host* getHost() { return p_host; }
273 s_vm_params_t p_params;
280 /** @ingroup SURF_host_interface
281 * @brief SURF host action interface class
283 class HostAction : public Action {
285 static simgrid::surf::signal<void(simgrid::surf::HostAction*, e_surf_action_state_t, e_surf_action_state_t)> onStateChange;
288 * @brief HostAction constructor
290 * @param model The HostModel associated to this HostAction
291 * @param cost The cost of this HostAction in [TODO]
292 * @param failed [description]
294 HostAction(simgrid::surf::Model *model, double cost, bool failed)
295 : Action(model, cost, failed) {}
298 * @brief HostAction constructor
300 * @param model The HostModel associated to this HostAction
301 * @param cost The cost of this HostAction in [TODO]
302 * @param failed [description]
303 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
305 HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
306 : Action(model, cost, failed, var) {}
308 void setState(e_surf_action_state_t state);
314 #endif /* SURF_Host_INTERFACE_HPP_ */