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->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) && (host->simdata != NULL), "Invalid parameters");
110 /** \ingroup m_host_management
112 * \brief Return the location on which the current process is executed.
114 m_host_t MSG_host_self(void)
116 return MSG_process_get_host(MSG_process_self());
120 * Real function for destroy a host.
121 * MSG_host_destroy is just a front_end that also removes it from
124 void __MSG_host_destroy(m_host_t host)
126 simdata_host_t simdata = NULL;
129 xbt_assert0((host != NULL), "Invalid parameters");
131 /* Clean Simulator data */
132 /* SIMIX host will be cleaned when MSG_clean calls SIMIX_clean */
133 simdata = (host)->simdata;
135 for (i = 0; i < msg_global->max_channel; i++)
136 xbt_fifo_free(simdata->mbox[i]);
138 free(simdata->sleeping);
139 SIMIX_mutex_destroy(simdata->mutex);
142 /* Clean host structure */
149 /** \ingroup m_host_management
150 * \brief Return the current number of #m_host_t.
152 int MSG_get_host_number(void)
154 return (xbt_fifo_size(msg_global->host));
157 /** \ingroup m_host_management
158 * \brief Return a array of all the #m_host_t.
160 m_host_t *MSG_get_host_table(void)
162 return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
165 /** \ingroup m_host_management
166 * \brief Return the number of MSG tasks currently running on a
167 * #m_host_t. The external load is not taken in account.
169 int MSG_get_host_msgload(m_host_t h)
171 xbt_assert0((h!= NULL), "Invalid parameters");
172 xbt_assert0(0, "Not implemented yet");
177 /** \ingroup m_host_management
178 * \brief Return the speed of the processor (in flop/s), regardless of
179 the current load on the machine.
181 double MSG_get_host_speed(m_host_t h)
183 xbt_assert0((h!= NULL), "Invalid parameters");
185 return(SIMIX_host_get_speed(h->simdata->host));
188 /** \ingroup msg_gos_functions
189 * \brief Determine if a host is available.
191 * \param h host to test
193 int MSG_host_is_avail (m_host_t h)
195 xbt_assert0((h!= NULL), "Invalid parameters");
196 return (SIMIX_host_get_state(h->simdata->host));