Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'energy-pstate' of https://github.com/Takishipp/simgrid into Takishipp...
[simgrid.git] / src / msg / msg_host.cpp
1 /* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Host.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "src/simix/ActorImpl.hpp"
10 #include "src/simix/smx_host_private.hpp"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
13
14 extern "C" {
15
16 /** @addtogroup m_host_management
17  * (#msg_host_t) and the functions for managing it.
18  *
19  *  A <em>location</em> (or <em>host</em>) is any possible place where  a process may run. Thus it may be represented
20  *  as a <em>physical resource with computing capabilities</em>, some <em>mailboxes</em> to enable running process to
21  *  communicate with remote ones, and some <em>private data</em> that can be only accessed by local process.
22  *  \see msg_host_t
23  */
24
25 /********************************* Host **************************************/
26 /** \ingroup m_host_management
27  * \brief Finds a msg_host_t using its name.
28  *
29  * This is a name directory service
30  * \param name the name of an host.
31  * \return the corresponding host
32  */
33 msg_host_t MSG_host_by_name(const char *name)
34 {
35   return simgrid::s4u::Host::by_name_or_null(name);
36 }
37
38 /** \ingroup m_host_management
39  *
40  * \brief Set the user data of a #msg_host_t.
41  *
42  * This functions attach \a data to \a host if it is possible.
43  */
44 msg_error_t MSG_host_set_data(msg_host_t host, void *data) {
45   sg_host_user_set(host, data);
46   return MSG_OK;
47 }
48
49 /** \ingroup m_host_management
50  *
51  * \brief Return the user data of a #msg_host_t.
52  *
53  * This functions returns the user data associated to \a host if it is possible.
54  */
55 void *MSG_host_get_data(msg_host_t host) {
56   return sg_host_user(host);
57 }
58
59 /** \ingroup m_host_management
60  *
61  * \brief Return the location on which the current process is executed.
62  */
63 msg_host_t MSG_host_self()
64 {
65   return MSG_process_get_host(nullptr);
66 }
67
68 /** \ingroup m_host_management
69  *
70  * \brief Start the host if it is off
71  *
72  * See also #MSG_host_is_on() and #MSG_host_is_off() to test the current state of the host and @ref plugin_energy
73  * for more info on DVFS.
74  */
75 void MSG_host_on(msg_host_t host)
76 {
77   host->turnOn();
78 }
79
80 /** \ingroup m_host_management
81  *
82  * \brief Stop the host if it is on
83  *
84  * See also #MSG_host_is_on() and #MSG_host_is_off() to test the current state of the host and @ref plugin_energy
85  * for more info on DVFS.
86  */
87 void MSG_host_off(msg_host_t host)
88 {
89   host->turnOff();
90 }
91
92 /** \ingroup m_host_management
93  * \brief Return the current number MSG hosts.
94  */
95 int MSG_get_host_number()
96 {
97   return sg_host_count();
98 }
99
100 /** \ingroup m_host_management
101  * \brief Return a dynar containing all the hosts declared at a given point of time (including VMs)
102  * \remark The host order in the returned array is generally different from the host creation/declaration order in the
103  *         XML platform (we use a hash table internally)
104  */
105 xbt_dynar_t MSG_hosts_as_dynar() {
106   return sg_hosts_as_dynar();
107 }
108
109 /** \ingroup m_host_management
110  * \brief Return the speed of the processor (in flop/s), regardless of the current load on the machine.
111  */
112 double MSG_host_get_speed(msg_host_t host) {
113   return host->getSpeed();
114 }
115
116 /** \ingroup m_host_management
117  * \brief Return the number of cores.
118  *
119  * \param host a host
120  * \return the number of cores
121  */
122 int MSG_host_get_core_number(msg_host_t host) {
123   return host->getCoreCount();
124 }
125
126 /** \ingroup m_host_management
127  * \brief Return the list of processes attached to an host.
128  *
129  * \param host a host
130  * \param whereto a dynar in which we should push processes living on that host
131  */
132 void MSG_host_get_process_list(msg_host_t host, xbt_dynar_t whereto)
133 {
134   xbt_assert((host != nullptr), "Invalid parameters");
135   smx_actor_t actor = NULL;
136   xbt_swag_foreach(actor, host->extension<simgrid::simix::Host>()->process_list) {
137     msg_process_t p = actor->ciface();
138     xbt_dynar_push(whereto, &p);
139   }
140 }
141
142 /** \ingroup m_host_management
143  * \brief Returns the value of a given host property
144  *
145  * \param host a host
146  * \param name a property name
147  * \return value of a property (or nullptr if property not set)
148  */
149 const char *MSG_host_get_property_value(msg_host_t host, const char *name)
150 {
151   return host->getProperty(name);
152 }
153
154 /** \ingroup m_host_management
155  * \brief Returns a xbt_dict_t consisting of the list of properties assigned to this host
156  *
157  * \param host a host
158  * \return a dict containing the properties
159  */
160 xbt_dict_t MSG_host_get_properties(msg_host_t host)
161 {
162   xbt_assert((host != nullptr), "Invalid parameters (host is nullptr)");
163   xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
164   std::map<std::string, std::string>* props = host->getProperties();
165   if (props == nullptr)
166     return nullptr;
167   for (auto const& elm : *props) {
168     xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
169   }
170   return as_dict;
171 }
172
173 /** \ingroup m_host_management
174  * \brief Change the value of a given host property
175  *
176  * \param host a host
177  * \param name a property name
178  * \param value what to change the property to
179  */
180 void MSG_host_set_property_value(msg_host_t host, const char* name, char* value)
181 {
182   host->setProperty(name, value);
183 }
184
185 /** @ingroup m_host_management
186  * @brief Determine if a host is up and running.
187  *
188  * See also #MSG_host_on() and #MSG_host_off() to switch the host ON and OFF and @ref plugin_energy for more info on
189  * DVFS.
190  *
191  * @param host host to test
192  * @return Returns true if the host is up and running, and false if it's currently down
193  */
194 int MSG_host_is_on(msg_host_t host)
195 {
196   return host->isOn();
197 }
198
199 /** @ingroup m_host_management
200  * @brief Determine if a host is currently off.
201  *
202  * See also #MSG_host_on() and #MSG_host_off() to switch the host ON and OFF and @ref plugin_energy for more info on
203  * DVFS.
204  */
205 int MSG_host_is_off(msg_host_t host)
206 {
207   return host->isOff();
208 }
209
210 /** \ingroup m_host_management
211  * \brief Return the speed of the processor (in flop/s) at a given pstate. See also @ref plugin_energy.
212  *
213  * \param  host host to test
214  * \param pstate_index pstate to test
215  * \return Returns the processor speed associated with pstate_index
216  */
217 double MSG_host_get_power_peak_at(msg_host_t host, int pstate_index) {
218   xbt_assert((host != nullptr), "Invalid parameters (host is nullptr)");
219   return host->getPstateSpeed(pstate_index);
220 }
221
222 /** \ingroup m_host_management
223  * \brief Return the total count of pstates defined for a host. See also @ref plugin_energy.
224  *
225  * \param  host host to test
226  */
227 int MSG_host_get_nb_pstates(msg_host_t host) {
228   return sg_host_get_nb_pstates(host);
229 }
230
231 /** \ingroup m_host_management
232  * \brief Return the list of mount point names on an host.
233  * \param host a host
234  * \return a dict containing all mount point on the host (mount_name => msg_storage_t)
235  */
236 xbt_dict_t MSG_host_get_mounted_storage_list(msg_host_t host)
237 {
238   return sg_host_get_mounted_storage_list(host);
239 }
240
241 /** \ingroup m_host_management
242  * \brief Return the list of storages attached to an host.
243  * \param host a host
244  * \return a dynar containing all storages (name) attached to the host
245  */
246 xbt_dynar_t MSG_host_get_attached_storage_list(msg_host_t host)
247 {
248   return sg_host_get_attached_storage_list(host);
249 }
250
251 }