Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Integrate Bruno's work on SIMIX onto main stream. Tests are broken, but it looks...
[simgrid.git] / src / msg_simix / msg_simix_host.c
1 #include "msg_simix_private.h"
2 #include "xbt/sysdep.h"
3 #include "xbt/log.h"
4
5 /** \defgroup m_host_management Management functions of Hosts
6  *  \brief This section describes the host structure of MSG
7  * 
8  *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
9  * (#m_host_t) and the functions for managing it.
10  *  
11  *  A <em>location</em> (or <em>host</em>) is any possible place where
12  *  a process may run. Thus it may be represented as a
13  *  <em>physical resource with computing capabilities</em>, some
14  *  <em>mailboxes</em> to enable running process to communicate with
15  *  remote ones, and some <em>private data</em> that can be only
16  *  accessed by local process.
17  *  \see m_host_t
18  */
19
20 /********************************* Host **************************************/
21 m_host_t __MSG_host_create(smx_host_t workstation, void *data)
22 {
23         const char * name;
24   simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
25   m_host_t host = xbt_new0(s_m_host_t,1);
26   int i;
27
28         name = SIMIX_host_get_name(workstation);
29   /* Host structure */
30   host->name = xbt_strdup(name);
31   host->simdata = simdata;
32   host->data = data;
33
34   simdata->host = workstation;
35
36   simdata->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
37   for (i = 0; i < msg_global->max_channel; i++)
38     simdata->mbox[i] = xbt_fifo_new();
39   
40         simdata->sleeping = xbt_new0(smx_cond_t, msg_global->max_channel);
41         simdata->mutex = SIMIX_mutex_init();
42         SIMIX_host_set_data(workstation, host);
43
44   /* Update global variables */
45         xbt_fifo_unshift(msg_global->host, host);
46  
47   return host;
48 }
49
50 /** \ingroup m_host_management
51  *
52  * \brief Set the user data of a #m_host_t.
53  *
54  * This functions checks whether some data has already been associated to \a host 
55    or not and attach \a data to \a host if it is possible.
56  */
57 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
58 {       
59   xbt_assert0((host!=NULL), "Invalid parameters");
60   xbt_assert0((host->data == NULL), "Data already set");
61
62   /* Assign data */
63   host->data = data;
64
65   return MSG_OK;
66 }
67
68 /** \ingroup m_host_management
69  *
70  * \brief Return the user data of a #m_host_t.
71  *
72  * This functions checks whether \a host is a valid pointer or not and return
73    the user data associated to \a host if it is possible.
74  */
75 void *MSG_host_get_data(m_host_t host)
76 {
77
78   xbt_assert0((host != NULL), "Invalid parameters");
79
80   /* Return data */
81   return (host->data);
82 }
83
84 /** \ingroup m_host_management
85  *
86  * \brief Return the name of the #m_host_t.
87  *
88  * This functions checks whether \a host is a valid pointer or not and return
89    its name.
90  */
91 const char *MSG_host_get_name(m_host_t host)
92 {
93
94   xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
95
96   /* Return data */
97   return (host->name);
98 }
99
100 /** \ingroup m_host_management
101  *
102  * \brief Return the location on which the current process is executed.
103  */
104 m_host_t MSG_host_self(void)
105 {
106   return MSG_process_get_host(MSG_process_self());
107 }
108
109 /*
110  * Real function for destroy a host.
111  * MSG_host_destroy is just  a front_end that also removes it from 
112  * msg_global->host
113  */
114 void __MSG_host_destroy(m_host_t host)
115 {
116   simdata_host_t simdata = NULL;
117   int i = 0;
118
119   xbt_assert0((host != NULL), "Invalid parameters");
120
121   /* Clean Simulator data */
122         /* SIMIX host will be cleaned when MSG_clean calls SIMIX_clean */
123   simdata = (host)->simdata;
124
125   for (i = 0; i < msg_global->max_channel; i++)
126     xbt_fifo_free(simdata->mbox[i]);
127   free(simdata->mbox);
128   free(simdata->sleeping);
129         SIMIX_mutex_destroy(simdata->mutex);
130   free(simdata);
131
132   /* Clean host structure */
133   free(host->name);
134   free(host);
135
136   return;
137 }
138
139 /** \ingroup m_host_management
140  * \brief Return the current number of #m_host_t.
141  */
142 int MSG_get_host_number(void)
143 {
144   return (xbt_fifo_size(msg_global->host));
145 }
146
147 /** \ingroup m_host_management
148  * \brief Return a array of all the #m_host_t.
149  */
150 m_host_t *MSG_get_host_table(void)
151 {
152   return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
153 }
154
155 /** \ingroup m_host_management
156  * \brief Return the number of MSG tasks currently running on a
157  * #m_host_t. The external load is not taken in account.
158  */
159 int MSG_get_host_msgload(m_host_t h)
160 {
161   xbt_assert0((h!= NULL), "Invalid parameters");
162   xbt_assert0(0, "Not implemented yet");
163
164   return(0);
165 }
166
167 /** \ingroup m_host_management
168  * \brief Return the speed of the processor (in flop/s), regardless of 
169     the current load on the machine.
170  */
171 double MSG_get_host_speed(m_host_t h)
172 {
173   xbt_assert0((h!= NULL), "Invalid parameters");
174
175   return(SIMIX_host_get_speed(h->simdata->host));
176 }
177
178 /** \ingroup msg_gos_functions
179  * \brief Determine if a host is available.
180  *
181  * \param h host to test
182  */
183 int MSG_host_is_avail (m_host_t h)
184 {
185   xbt_assert0((h!= NULL), "Invalid parameters");
186         return (SIMIX_host_get_state(h->simdata->host));
187 }