3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
13 /** \defgroup m_host_management Management functions of Hosts
14 * \brief This section describes the host structure of MSG
16 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
17 * (#m_host_t) and the functions for managing it.
19 * A <em>location</em> (or <em>host</em>) is any possible place where
20 * a process may run. Thus it may be represented as a
21 * <em>physical resource with computing capabilities</em>, some
22 * <em>mailboxes</em> to enable running process to communicate with
23 * remote ones, and some <em>private data</em> that can be only
24 * accessed by local process.
28 /********************************* Host **************************************/
29 smx_host_t __SIMIX_host_create(const char *name,
33 simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
34 smx_host_t host = xbt_new0(s_smx_host_t,1);
38 host->name = xbt_strdup(name);
39 host->simdata = simdata;
42 simdata->host = workstation;
44 simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
45 /* Update global variables */
47 xbt_fifo_unshift(simix_global->host, host);
52 /** \ingroup m_host_management
54 * \brief Set the user data of a #m_host_t.
56 * This functions checks whether some data has already been associated to \a host
57 or not and attach \a data to \a host if it is possible.
59 void SIMIX_host_set_data(smx_host_t host, void *data)
61 xbt_assert0((host!=NULL), "Invalid parameters");
62 xbt_assert0((host->data == NULL), "Data already set");
70 /** \ingroup m_host_management
72 * \brief Return the user data of a #m_host_t.
74 * This functions checks whether \a host is a valid pointer or not and return
75 the user data associated to \a host if it is possible.
77 void *SIMIX_host_get_data(smx_host_t host)
80 xbt_assert0((host != NULL), "Invalid parameters");
86 /** \ingroup m_host_management
88 * \brief Return the name of the #m_host_t.
90 * This functions checks whether \a host is a valid pointer or not and return
93 const char *SIMIX_host_get_name(smx_host_t host)
96 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
102 /** \ingroup m_host_management
104 * \brief Return the location on which the current process is executed.
106 smx_host_t SIMIX_host_self(void)
108 return SIMIX_process_get_host(SIMIX_process_self());
112 * Real function for destroy a host.
113 * MSG_host_destroy is just a front_end that also removes it from
116 void __SIMIX_host_destroy(smx_host_t host)
118 simdata_host_t simdata = NULL;
120 xbt_assert0((host != NULL), "Invalid parameters");
123 /* Clean Simulator data */
124 simdata = host->simdata;
126 xbt_assert0((xbt_swag_size(simdata->process_list)==0),
127 "Some process are still running on this host");
128 xbt_swag_free(simdata->process_list);
132 /* Clean host structure */
139 /** \ingroup m_host_management
140 * \brief Return the current number of #m_host_t.
142 int SIMIX_get_host_number(void)
144 return (xbt_fifo_size(simix_global->host));
147 /** \ingroup m_host_management
148 * \brief Return a array of all the #m_host_t.
150 smx_host_t *SIMIX_get_host_table(void)
152 return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
156 /** \ingroup m_host_management
157 * \brief Return the speed of the processor (in Mflop/s), regardless of
158 the current load on the machine.
160 double SIMIX_get_host_speed(smx_host_t h)
162 xbt_assert0((h!= NULL), "Invalid parameters");
164 return(surf_workstation_resource->
165 extension_public->get_speed(h->simdata->host,1.0));
168 /** \ingroup msg_gos_functions
169 * \brief Determine if a host is available.
171 * \param h host to test
173 int SIMIX_host_is_avail (smx_host_t h)
175 e_surf_cpu_state_t cpustate;
176 xbt_assert0((h!= NULL), "Invalid parameters");
179 surf_workstation_resource->extension_public->get_state(h->simdata->host);
181 xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF),
182 "Invalid cpu state");
184 return (cpustate==SURF_CPU_ON);