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 = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
28 /* Update global variables */
29 xbt_dict_set(simix_global->host, smx_host->name, smx_host, &__SIMIX_host_destroy);
35 * \brief Set the user data of a #smx_host_t.
37 * 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.
38 * \param host SIMIX host
39 * \param data User data
42 XBT_INLINE void SIMIX_host_set_data(smx_host_t host, void *data)
44 xbt_assert0((host != NULL), "Invalid parameters");
45 xbt_assert0((host->data == NULL), "Data already set");
54 * \brief Return the user data of a #smx_host_t.
56 * 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.
57 * \param host SIMIX host
59 XBT_INLINE void *SIMIX_host_get_data(smx_host_t host)
61 xbt_assert0((host != NULL), "Invalid parameters");
68 * \brief Return the name of the #smx_host_t.
70 * This functions checks whether \a host is a valid pointer or not and return its name.
71 * \param host SIMIX host
73 XBT_INLINE const char *SIMIX_host_get_name(smx_host_t host)
76 xbt_assert0((host != NULL), "Invalid parameters");
83 * \brief Return the location on which the current process is executed.
85 * Return the host, more details in #SIMIX_process_get_host
88 XBT_INLINE smx_host_t SIMIX_host_self(void)
90 return SIMIX_process_get_host(SIMIX_process_self());
94 * Real function for destroy a host.
95 * MSG_host_destroy is just a front_end that also removes it from
98 void __SIMIX_host_destroy(void *h)
100 smx_host_t host = (smx_host_t) h;
102 xbt_assert0((host != NULL), "Invalid parameters");
104 /* Clean Simulator data */
105 if (xbt_swag_size(host->process_list) != 0) {
106 char *msg = bprintf("Shutting down host %s, but it's not empty:", host->name);
108 smx_process_t process = NULL;
110 xbt_swag_foreach(process, host->process_list) {
111 tmp = bprintf("%s\n\t%s", msg, process->name);
115 THROW1(arg_error, 0, "%s", msg);
118 xbt_swag_free(host->process_list);
120 /* Clean host structure */
128 * \brief Return the current number of #smx_host_t.
130 * \return Number of hosts
132 XBT_INLINE int SIMIX_host_get_number(void)
134 return (xbt_dict_size(simix_global->host));
139 * \brief Return an array of all the #smx_host_t.
141 * \return List of all hosts (in a newly allocated table)
143 smx_host_t *SIMIX_host_get_table(void)
145 smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host));
151 xbt_dict_foreach(simix_global->host, c, name, h)
158 * \brief Return a dict of all the #smx_host_t.
160 * \return List of all hosts (as a #xbt_dict_t)
162 XBT_INLINE xbt_dict_t SIMIX_host_get_dict(void)
164 return simix_global->host;
168 * \brief Return the speed of the processor.
170 * Return the speed (in Mflop/s), regardless of the current load on the machine.
171 * \param host SIMIX host
174 XBT_INLINE double SIMIX_host_get_speed(smx_host_t host)
176 xbt_assert0((host != NULL), "Invalid parameters");
178 return (surf_workstation_model->extension.workstation.
179 get_speed(host->host, 1.0));
183 * \brief Return the available speed of the processor.
185 * Return the available speed (in Mflop/s).
188 XBT_INLINE double SIMIX_host_get_available_speed(smx_host_t host)
190 xbt_assert0((host != NULL), "Invalid parameters");
192 return (surf_workstation_model->extension.workstation.
193 get_available_speed(host->host));
197 * \brief Return the host by its name
199 * Finds a smx_host_t using its name.
200 * \param name The name of an host.
201 * \return The corresponding host
203 XBT_INLINE smx_host_t SIMIX_host_get_by_name(const char *name)
205 xbt_assert0(((simix_global != NULL)
206 && (simix_global->host != NULL)), "Environment not set yet");
208 return xbt_dict_get_or_null(simix_global->host, name);
212 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
215 * \return the dynamic array consisting of property names
217 XBT_INLINE xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
219 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
221 return surf_workstation_model->extension.workstation.get_properties(host->host);
226 * \brief Return the state of a workstation
228 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
229 * \param host The SIMIX host
230 * \return 1 if host is available or 0 if not.
232 XBT_INLINE int SIMIX_host_get_state(smx_host_t host)
234 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
236 return (surf_workstation_model->extension.workstation.
237 get_state(host->host));