1 #include "msg_simix_private.h"
2 #include "xbt/sysdep.h"
5 /** \defgroup m_host_management Management functions of Hosts
6 * \brief This section describes the host structure of MSG
8 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
9 * (#m_host_t) and the functions for managing it.
11 * A <em>location</em> (or <em>host</em>) is any possible place where
12 * a process may run. Thus it may be represented as a
13 * <em>physical resource with computing capabilities</em>, some
14 * <em>mailboxes</em> to enable running process to communicate with
15 * remote ones, and some <em>private data</em> that can be only
16 * accessed by local process.
20 /********************************* Host **************************************/
21 m_host_t __MSG_host_create(smx_host_t workstation, void *data)
24 simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
25 m_host_t host = xbt_new0(s_m_host_t,1);
28 name = SIMIX_host_get_name(workstation);
30 host->name = xbt_strdup(name);
31 host->simdata = simdata;
34 simdata->host = workstation;
36 simdata->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
37 for (i = 0; i < msg_global->max_channel; i++)
38 simdata->mbox[i] = xbt_fifo_new();
40 simdata->sleeping = xbt_new0(smx_cond_t, msg_global->max_channel);
41 simdata->mutex = SIMIX_mutex_init();
42 SIMIX_host_set_data(workstation, host);
44 /* Update global variables */
45 xbt_fifo_unshift(msg_global->host, host);
50 /** \ingroup m_host_management
52 * \brief Set the user data of a #m_host_t.
54 * This functions checks whether some data has already been associated to \a host
55 or not and attach \a data to \a host if it is possible.
57 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
59 xbt_assert0((host!=NULL), "Invalid parameters");
60 xbt_assert0((host->data == NULL), "Data already set");
68 /** \ingroup m_host_management
70 * \brief Return the user data of a #m_host_t.
72 * This functions checks whether \a host is a valid pointer or not and return
73 the user data associated to \a host if it is possible.
75 void *MSG_host_get_data(m_host_t host)
78 xbt_assert0((host != NULL), "Invalid parameters");
84 /** \ingroup m_host_management
86 * \brief Return the name of the #m_host_t.
88 * This functions checks whether \a host is a valid pointer or not and return
91 const char *MSG_host_get_name(m_host_t host)
94 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
100 /** \ingroup m_host_management
102 * \brief Return the location on which the current process is executed.
104 m_host_t MSG_host_self(void)
106 return MSG_process_get_host(MSG_process_self());
110 * Real function for destroy a host.
111 * MSG_host_destroy is just a front_end that also removes it from
114 void __MSG_host_destroy(m_host_t host)
116 simdata_host_t simdata = NULL;
119 xbt_assert0((host != NULL), "Invalid parameters");
121 /* Clean Simulator data */
122 /* SIMIX host will be cleaned when MSG_clean calls SIMIX_clean */
123 simdata = (host)->simdata;
125 for (i = 0; i < msg_global->max_channel; i++)
126 xbt_fifo_free(simdata->mbox[i]);
128 free(simdata->sleeping);
129 SIMIX_mutex_destroy(simdata->mutex);
132 /* Clean host structure */
139 /** \ingroup m_host_management
140 * \brief Return the current number of #m_host_t.
142 int MSG_get_host_number(void)
144 return (xbt_fifo_size(msg_global->host));
147 /** \ingroup m_host_management
148 * \brief Return a array of all the #m_host_t.
150 m_host_t *MSG_get_host_table(void)
152 return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
155 /** \ingroup m_host_management
156 * \brief Return the number of MSG tasks currently running on a
157 * #m_host_t. The external load is not taken in account.
159 int MSG_get_host_msgload(m_host_t h)
161 xbt_assert0((h!= NULL), "Invalid parameters");
162 xbt_assert0(0, "Not implemented yet");
167 /** \ingroup m_host_management
168 * \brief Return the speed of the processor (in flop/s), regardless of
169 the current load on the machine.
171 double MSG_get_host_speed(m_host_t h)
173 xbt_assert0((h!= NULL), "Invalid parameters");
175 return(SIMIX_host_get_speed(h->simdata->host));
178 /** \ingroup msg_gos_functions
179 * \brief Determine if a host is available.
181 * \param h host to test
183 int MSG_host_is_avail (m_host_t h)
185 xbt_assert0((h!= NULL), "Invalid parameters");
186 return (SIMIX_host_get_state(h->simdata->host));