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"
15 /** \defgroup m_host_management Management functions of Hosts
16 * \brief This section describes the host structure of MSG
18 /** @addtogroup m_host_management
19 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
20 * (#m_host_t) and the functions for managing it.
22 * A <em>location</em> (or <em>host</em>) is any possible place where
23 * a process may run. Thus it may be represented as a
24 * <em>physical resource with computing capabilities</em>, some
25 * <em>mailboxes</em> to enable running process to communicate with
26 * remote ones, and some <em>private data</em> that can be only
27 * accessed by local process.
31 /********************************* Host **************************************/
32 m_host_t __MSG_host_create(smx_host_t workstation, void *data)
35 simdata_host_t simdata = xbt_new0(s_simdata_host_t, 1);
36 m_host_t host = xbt_new0(s_m_host_t, 1);
39 char alias[MAX_ALIAS_NAME +1] = {0}; /* buffer used to build the key of the mailbox */
41 name = SIMIX_host_get_name(workstation);
43 host->name = xbt_strdup(name);
44 host->simdata = simdata;
47 simdata->smx_host = workstation;
49 if (msg_global->max_channel>0)
50 simdata->mailboxes = xbt_new0(msg_mailbox_t, msg_global->max_channel);
52 for (i = 0; i < msg_global->max_channel; i++)
54 sprintf(alias,"%s:%d",name,i);
56 /* the key of the mailbox (in this case) is build from the name of the host and the channel number */
57 simdata->mailboxes[i] = MSG_mailbox_create(alias);
58 MSG_mailbox_set_hostname(simdata->mailboxes[i],name);
59 memset(alias,0,MAX_ALIAS_NAME +1);
62 simdata->mutex = SIMIX_mutex_init();
63 SIMIX_host_set_data(workstation, host);
65 /* Update global variables */
66 xbt_fifo_unshift(msg_global->host, host);
71 /** \ingroup m_host_management
73 * \brief Set the user data of a #m_host_t.
75 * This functions checks whether some data has already been associated to \a host
76 or not and attach \a data to \a host if it is possible.
78 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
80 xbt_assert0((host != NULL), "Invalid parameters");
81 xbt_assert0((host->data == NULL), "Data already set");
89 /** \ingroup m_host_management
91 * \brief Return the user data of a #m_host_t.
93 * This functions checks whether \a host is a valid pointer or not and return
94 the user data associated to \a host if it is possible.
96 void *MSG_host_get_data(m_host_t host)
99 xbt_assert0((host != NULL), "Invalid parameters");
105 /** \ingroup m_host_management
107 * \brief Return the name of the #m_host_t.
109 * This functions checks whether \a host is a valid pointer or not and return
112 const char *MSG_host_get_name(m_host_t host)
115 xbt_assert0((host != NULL)
116 && (host->simdata != NULL), "Invalid parameters");
122 /** \ingroup m_host_management
124 * \brief Return the location on which the current process is executed.
126 m_host_t MSG_host_self(void)
128 return MSG_process_get_host(MSG_process_self());
132 * Real function to destroy a host.
133 * MSG_host_destroy is just a front_end that also removes it from
136 void __MSG_host_destroy(m_host_t host)
138 simdata_host_t simdata = NULL;
140 char alias[MAX_ALIAS_NAME +1] = {0}; /* buffer used to build the key of the mailbox */
142 xbt_assert0((host != NULL), "Invalid parameters");
144 /* Clean Simulator data */
145 /* SIMIX host will be cleaned when MSG_clean calls SIMIX_clean */
146 simdata = (host)->simdata;
148 for (i = 0; i < msg_global->max_channel; i++)
150 sprintf(alias,"%s:%d",host->name,i);
151 MSG_mailbox_free((void*)(simdata->mailboxes[i]));
152 memset(alias,0,MAX_ALIAS_NAME +1);
155 if (msg_global->max_channel>0)
156 free(simdata->mailboxes);
157 SIMIX_mutex_destroy(simdata->mutex);
160 /* Clean host structure */
167 /** \ingroup m_host_management
168 * \brief Return the current number of #m_host_t.
170 int MSG_get_host_number(void)
172 return (xbt_fifo_size(msg_global->host));
175 /** \ingroup m_host_management
176 * \brief Return a array of all the #m_host_t.
178 m_host_t *MSG_get_host_table(void)
180 return ((m_host_t *) xbt_fifo_to_array(msg_global->host));
183 /** \ingroup m_host_management
184 * \brief Return the number of MSG tasks currently running on a
185 * #m_host_t. The external load is not taken in account.
187 int MSG_get_host_msgload(m_host_t h)
189 xbt_assert0((h != NULL), "Invalid parameters");
190 xbt_assert0(0, "Not implemented yet");
195 /** \ingroup m_host_management
196 * \brief Return the speed of the processor (in flop/s), regardless of
197 the current load on the machine.
199 double MSG_get_host_speed(m_host_t h)
201 xbt_assert0((h != NULL), "Invalid parameters");
203 return (SIMIX_host_get_speed(h->simdata->smx_host));
206 /** \ingroup m_host_management
207 * \brief Returns the value of a given host property
210 * \param name a property name
211 * \return value of a property (or NULL if property not set)
213 const char* MSG_host_get_property_value(m_host_t host, const char* name)
215 return xbt_dict_get_or_null(MSG_host_get_properties(host), name);
218 /** \ingroup m_host_management
219 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
222 * \return a dict containing the properties
224 xbt_dict_t MSG_host_get_properties(m_host_t host)
226 xbt_assert0((host != NULL), "Invalid parameters");
228 return (SIMIX_host_get_properties(host->simdata->smx_host));
232 /** \ingroup msg_gos_functions
233 * \brief Determine if a host is available.
235 * \param h host to test
237 int MSG_host_is_avail(m_host_t h)
239 xbt_assert0((h != NULL), "Invalid parameters");
240 return (SIMIX_host_get_state(h->simdata->smx_host));