3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
15 "Logging specific to SIMIX (hosts)");
17 /********************************* Host **************************************/
18 smx_host_t __SIMIX_host_create(const char *name,
19 void *workstation, void *data)
21 smx_host_t smx_host = xbt_new0(s_smx_host_t, 1);
25 smx_host->name = xbt_strdup(name);
26 smx_host->data = data;
27 smx_host->host = workstation;
28 smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
30 /* Update global variables */
31 xbt_dict_set(simix_global->host, smx_host->name, smx_host, &__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) {
108 char *msg = bprintf("Shutting down host %s, but it's not empty:", host->name);
110 smx_process_t process = NULL;
112 xbt_swag_foreach(process, host->process_list) {
113 tmp = bprintf("%s\n\t%s", msg, process->name);
117 THROW1(arg_error, 0, "%s", msg);
120 xbt_swag_free(host->process_list);
122 /* Clean host structure */
130 * \brief Return the current number of #smx_host_t.
132 * \return Number of hosts
134 XBT_INLINE int SIMIX_host_get_number(void)
136 return (xbt_dict_size(simix_global->host));
141 * \brief Return an array of all the #smx_host_t.
143 * \return List of all hosts (in a newly allocated table)
145 smx_host_t *SIMIX_host_get_table(void)
147 smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host));
153 xbt_dict_foreach(simix_global->host, c, name, h)
160 * \brief Return a dict of all the #smx_host_t.
162 * \return List of all hosts (as a #xbt_dict_t)
164 XBT_INLINE xbt_dict_t SIMIX_host_get_dict(void)
166 return simix_global->host;
170 * \brief Return the speed of the processor.
172 * Return the speed (in Mflop/s), regardless of the current load on the machine.
173 * \param host SIMIX host
176 XBT_INLINE double SIMIX_host_get_speed(smx_host_t host)
178 xbt_assert0((host != NULL), "Invalid parameters");
180 return (surf_workstation_model->extension.workstation.
181 get_speed(host->host, 1.0));
185 * \brief Return the available speed of the processor.
187 * Return the available speed (in Mflop/s).
190 XBT_INLINE double SIMIX_host_get_available_speed(smx_host_t host)
192 xbt_assert0((host != NULL), "Invalid parameters");
194 return (surf_workstation_model->extension.workstation.
195 get_available_speed(host->host));
199 * \brief Return the host by its name
201 * Finds a smx_host_t using its name.
202 * \param name The name of an host.
203 * \return The corresponding host
205 XBT_INLINE smx_host_t SIMIX_host_get_by_name(const char *name)
207 xbt_assert0(((simix_global != NULL)
208 && (simix_global->host != NULL)), "Environment not set yet");
210 return xbt_dict_get_or_null(simix_global->host, name);
214 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
217 * \return the dynamic array consisting of property names
219 XBT_INLINE xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
221 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
223 return surf_workstation_model->extension.workstation.get_properties(host->host);
228 * \brief Return the state of a workstation
230 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
231 * \param host The SIMIX host
232 * \return 1 if host is available or 0 if not.
234 XBT_INLINE int SIMIX_host_get_state(smx_host_t host)
236 xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
238 return (surf_workstation_model->extension.workstation.
239 get_state(host->host));