3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/sysdep.h"
12 /** \defgroup m_host_management Management functions of Hosts
13 * \brief This section describes the host structure of MSG
15 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
16 * (#m_host_t) and the functions for managing it.
18 * A <em>location</em> (or <em>host</em>) is any possible place where
19 * a process may run. Thus it may be represented as a
20 * <em>physical resource with computing capabilities</em>, some
21 * <em>mailboxes</em> to enable running process to communicate with
22 * remote ones, and some <em>private data</em> that can be only
23 * accessed by local process.
27 /********************************* Host **************************************/
28 smx_host_t __SIMIX_host_create(const char *name,
32 simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
33 smx_host_t host = xbt_new0(s_smx_host_t,1);
37 host->name = xbt_strdup(name);
38 host->simdata = simdata;
41 simdata->host = workstation;
43 simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, process_hookup));
44 /* Update global variables */
46 xbt_fifo_unshift(simix_global->host, host);
51 /** \ingroup m_host_management
53 * \brief Set the user data of a #m_host_t.
55 * This functions checks whether some data has already been associated to \a host
56 or not and attach \a data to \a host if it is possible.
58 SIMIX_error_t SIMIX_host_set_data(smx_host_t host, void *data)
60 xbt_assert0((host!=NULL), "Invalid parameters");
61 xbt_assert0((host->data == NULL), "Data already set");
69 /** \ingroup m_host_management
71 * \brief Return the user data of a #m_host_t.
73 * This functions checks whether \a host is a valid pointer or not and return
74 the user data associated to \a host if it is possible.
76 void *SIMIX_host_get_data(smx_host_t host)
79 xbt_assert0((host != NULL), "Invalid parameters");
85 /** \ingroup m_host_management
87 * \brief Return the name of the #m_host_t.
89 * This functions checks whether \a host is a valid pointer or not and return
92 const char *SIMIX_host_get_name(smx_host_t host)
95 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
101 /** \ingroup m_host_management
103 * \brief Return the location on which the current process is executed.
105 smx_host_t SIMIX_host_self(void)
107 return SIMIX_process_get_host(SIMIX_process_self());
111 * Real function for destroy a host.
112 * MSG_host_destroy is just a front_end that also removes it from
115 void __SIMIX_host_destroy(smx_host_t host)
117 simdata_host_t simdata = NULL;
119 xbt_assert0((host != NULL), "Invalid parameters");
122 /* Clean Simulator data */
123 simdata = (host)->simdata;
125 xbt_assert0((xbt_swag_size(simdata->process_list)==0),
126 "Some process are still running on this host");
127 xbt_swag_free(simdata->process_list);
131 /* Clean host structure */
138 /** \ingroup m_host_management
139 * \brief Return the current number of #m_host_t.
141 int SIMIX_get_host_number(void)
143 return (xbt_fifo_size(simix_global->host));
146 /** \ingroup m_host_management
147 * \brief Return a array of all the #m_host_t.
149 smx_host_t *SIMIX_get_host_table(void)
151 return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
154 /** \ingroup m_host_management
155 * \brief Return the number of MSG tasks currently running on a
156 * #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");
165 // return(surf_workstation_resource->extension_public->get_load(h->simdata->host));
169 /** \ingroup m_host_management
170 * \brief Return the speed of the processor (in Mflop/s), regardless of
171 the current load on the machine.
173 double SIMIX_get_host_speed(smx_host_t h)
175 xbt_assert0((h!= NULL), "Invalid parameters");
177 return(surf_workstation_resource->
178 extension_public->get_speed(h->simdata->host,1.0));
181 /** \ingroup msg_gos_functions
182 * \brief Determine if a host is available.
184 * \param h host to test
186 int SIMIX_host_is_avail (smx_host_t h)
188 e_surf_cpu_state_t cpustate;
189 xbt_assert0((h!= NULL), "Invalid parameters");
192 surf_workstation_resource->extension_public->get_state(h->simdata->host);
194 xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF),
195 "Invalid cpu state");
197 return (cpustate==SURF_CPU_ON);