3 /* Copyright (c) 2002-2007 Arnaud Legrand. */
4 /* Copyright (c) 2007 Bruno Donassolo. */
5 /* All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "msg/private.h"
11 #include "xbt/sysdep.h"
14 /** \defgroup m_host_management Management functions of Hosts
15 * \brief This section describes the host structure of MSG
17 /** @addtogroup m_host_management
18 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
19 * (#m_host_t) and the functions for managing it.
21 * A <em>location</em> (or <em>host</em>) is any possible place where
22 * a process may run. Thus it may be represented as a
23 * <em>physical resource with computing capabilities</em>, some
24 * <em>mailboxes</em> to enable running process to communicate with
25 * remote ones, and some <em>private data</em> that can be only
26 * accessed by local process.
30 /********************************* Host **************************************/
31 m_host_t __MSG_host_create(smx_host_t workstation, void *data)
34 simdata_host_t simdata = xbt_new0(s_simdata_host_t, 1);
35 m_host_t host = xbt_new0(s_m_host_t, 1);
38 name = SIMIX_host_get_name(workstation);
40 host->name = xbt_strdup(name);
41 host->simdata = simdata;
44 simdata->smx_host = workstation;
46 simdata->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
47 for (i = 0; i < msg_global->max_channel; i++)
48 simdata->mbox[i] = xbt_fifo_new();
50 simdata->sleeping = xbt_new0(smx_cond_t, msg_global->max_channel);
51 simdata->mutex = SIMIX_mutex_init();
52 SIMIX_host_set_data(workstation, host);
54 /* Update global variables */
55 xbt_fifo_unshift(msg_global->host, host);
60 /** \ingroup m_host_management
62 * \brief Set the user data of a #m_host_t.
64 * This functions checks whether some data has already been associated to \a host
65 or not and attach \a data to \a host if it is possible.
67 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
69 xbt_assert0((host != NULL), "Invalid parameters");
70 xbt_assert0((host->data == NULL), "Data already set");
78 /** \ingroup m_host_management
80 * \brief Return the user data of a #m_host_t.
82 * This functions checks whether \a host is a valid pointer or not and return
83 the user data associated to \a host if it is possible.
85 void *MSG_host_get_data(m_host_t host)
88 xbt_assert0((host != NULL), "Invalid parameters");
94 /** \ingroup m_host_management
96 * \brief Return the name of the #m_host_t.
98 * This functions checks whether \a host is a valid pointer or not and return
101 const char *MSG_host_get_name(m_host_t host)
104 xbt_assert0((host != NULL)
105 && (host->simdata != NULL), "Invalid parameters");
111 /** \ingroup m_host_management
113 * \brief Return the location on which the current process is executed.
115 m_host_t MSG_host_self(void)
117 return MSG_process_get_host(MSG_process_self());
121 * Real function to destroy a host.
122 * MSG_host_destroy is just a front_end that also removes it from
125 void __MSG_host_destroy(m_host_t host)
127 simdata_host_t simdata = NULL;
130 xbt_assert0((host != NULL), "Invalid parameters");
132 /* Clean Simulator data */
133 /* SIMIX host will be cleaned when MSG_clean calls SIMIX_clean */
134 simdata = (host)->simdata;
136 for (i = 0; i < msg_global->max_channel; i++)
137 xbt_fifo_free(simdata->mbox[i]);
139 free(simdata->sleeping);
140 SIMIX_mutex_destroy(simdata->mutex);
143 /* Clean host structure */
150 /** \ingroup m_host_management
151 * \brief Return the current number of #m_host_t.
153 int MSG_get_host_number(void)
155 return (xbt_fifo_size(msg_global->host));
158 /** \ingroup m_host_management
159 * \brief Return a array of all the #m_host_t.
161 m_host_t *MSG_get_host_table(void)
163 return ((m_host_t *) xbt_fifo_to_array(msg_global->host));
166 /** \ingroup m_host_management
167 * \brief Return the number of MSG tasks currently running on a
168 * #m_host_t. The external load is not taken in account.
170 int MSG_get_host_msgload(m_host_t h)
172 xbt_assert0((h != NULL), "Invalid parameters");
173 xbt_assert0(0, "Not implemented yet");
178 /** \ingroup m_host_management
179 * \brief Return the speed of the processor (in flop/s), regardless of
180 the current load on the machine.
182 double MSG_get_host_speed(m_host_t h)
184 xbt_assert0((h != NULL), "Invalid parameters");
186 return (SIMIX_host_get_speed(h->simdata->smx_host));
189 /** \ingroup msg_gos_functions
190 * \brief Determine if a host is available.
192 * \param h host to test
194 int MSG_host_is_avail(m_host_t h)
196 xbt_assert0((h != NULL), "Invalid parameters");
197 return (SIMIX_host_get_state(h->simdata->smx_host));