1 /* Copyright (c) 2007, 2008, 2009, 2010. 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. */
8 #include "xbt/sysdep.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
13 "Logging specific to SIMIX (hosts)");
15 /********************************* Host **************************************/
16 smx_host_t __SIMIX_host_create(const char *name,
17 void *workstation, void *data)
19 smx_host_t smx_host = xbt_new0(s_smx_host_t, 1);
23 smx_host->name = xbt_strdup(name);
24 smx_host->data = data;
25 smx_host->host = workstation;
26 smx_host->process_list =
27 xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
29 /* Update global variables */
30 xbt_dict_set(simix_global->host, smx_host->name, smx_host,
31 &__SIMIX_host_destroy);
37 * \brief Set the user data of a #smx_host_t.
39 * This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
40 * \param host SIMIX host
41 * \param data User data
44 XBT_INLINE void SIMIX_host_set_data(smx_host_t host, void *data)
46 xbt_assert0((host != NULL), "Invalid parameters");
47 xbt_assert0((host->data == NULL), "Data already set");
56 * \brief Return the user data of a #smx_host_t.
58 * This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
59 * \param host SIMIX host
61 XBT_INLINE void *SIMIX_host_get_data(smx_host_t host)
63 xbt_assert0((host != NULL), "Invalid parameters");
70 * \brief Return the name of the #smx_host_t.
72 * This functions checks whether \a host is a valid pointer or not and return its name.
73 * \param host SIMIX host
75 XBT_INLINE const char *SIMIX_host_get_name(smx_host_t host)
78 xbt_assert0((host != NULL), "Invalid parameters");
85 * \brief Return the location on which the current process is executed.
87 * Return the host, more details in #SIMIX_process_get_host
90 XBT_INLINE smx_host_t SIMIX_host_self(void)
92 return SIMIX_process_get_host(SIMIX_process_self());
96 * Real function for destroy a host.
97 * MSG_host_destroy is just a front_end that also removes it from
100 void __SIMIX_host_destroy(void *h)
102 smx_host_t host = (smx_host_t) h;
104 xbt_assert0((host != NULL), "Invalid parameters");
106 /* Clean Simulator data */
107 if (xbt_swag_size(host->process_list) != 0) {
109 bprintf("Shutting down host %s, but it's not empty:", host->name);
111 smx_process_t process = NULL;
113 xbt_swag_foreach(process, host->process_list) {
114 tmp = bprintf("%s\n\t%s", msg, process->name);
118 THROW1(arg_error, 0, "%s", msg);
121 xbt_swag_free(host->process_list);
123 /* Clean host structure */
131 * \brief Return the current number of #smx_host_t.
133 * \return Number of hosts
135 XBT_INLINE int SIMIX_host_get_number(void)
137 return (xbt_dict_size(simix_global->host));
142 * \brief Return an array of all the #smx_host_t.
144 * \return List of all hosts (in a newly allocated table)
146 smx_host_t *SIMIX_host_get_table(void)
148 smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host));
154 xbt_dict_foreach(simix_global->host, c, name, h)
161 * \brief Return a dict of all the #smx_host_t.
163 * \return List of all hosts (as a #xbt_dict_t)
165 XBT_INLINE xbt_dict_t SIMIX_host_get_dict(void)
167 return simix_global->host;
171 * \brief Return the speed of the processor.
173 * Return the speed (in Mflop/s), regardless of the current load on the machine.
174 * \param host SIMIX host
177 XBT_INLINE double SIMIX_host_get_speed(smx_host_t host)
179 xbt_assert0((host != NULL), "Invalid parameters");
181 return (surf_workstation_model->extension.workstation.
182 get_speed(host->host, 1.0));
186 * \brief Return the available speed of the processor.
188 * Return the available speed (in Mflop/s).
191 XBT_INLINE double SIMIX_host_get_available_speed(smx_host_t host)
193 xbt_assert0((host != NULL), "Invalid parameters");
195 return (surf_workstation_model->extension.workstation.
196 get_available_speed(host->host));
200 * \brief Return the host by its name
202 * Finds a smx_host_t using its name.
203 * \param name The name of an host.
204 * \return The corresponding host
206 XBT_INLINE smx_host_t SIMIX_host_get_by_name(const char *name)
208 xbt_assert0(((simix_global != NULL)
209 && (simix_global->host != NULL)),
210 "Environment not set yet");
212 return xbt_dict_get_or_null(simix_global->host, name);
216 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
219 * \return the dynamic array consisting of property names
221 XBT_INLINE xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
223 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
225 return surf_workstation_model->extension.
226 workstation.get_properties(host->host);
231 * \brief Return the state of a workstation
233 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
234 * \param host The SIMIX host
235 * \return 1 if host is available or 0 if not.
237 XBT_INLINE int SIMIX_host_get_state(smx_host_t host)
239 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
241 return (surf_workstation_model->extension.workstation.
242 get_state(host->host));