Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure the navbar tricks we use in the post-processor don't land in the short...
[simgrid.git] / src / msg / host.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
8 #include "private.h"
9 #include "xbt/sysdep.h"
10 #include "xbt/log.h"
11
12 /** \defgroup m_host_management Management functions of Hosts
13  *  \brief This section describes the host structure of MSG
14  */
15
16 /** \addtogroup m_host_management
17  *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
18  * (#m_host_t) and the functions for managing it.
19  *  
20  *  A <em>location</em> (or <em>host</em>) is any possible place where
21  *  a process may run. Thus it may be represented as a
22  *  <em>physical resource with computing capabilities</em>, some
23  *  <em>mailboxes</em> to enable running process to communicate with
24  *  remote ones, and some <em>private data</em> that can be only
25  *  accessed by local process.
26  *  \see m_host_t
27  */
28
29 /********************************* Host **************************************/
30 m_host_t __MSG_host_create(const char *name,
31                          void *workstation,
32                          void *data)
33 {
34   simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
35   m_host_t host = xbt_new0(s_m_host_t,1);
36   int i;
37
38   /* Host structure */
39   host->name = xbt_strdup(name);
40   host->simdata = simdata;
41   host->data = data;
42
43   simdata->host = workstation;
44
45   simdata->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
46   for (i = 0; i < msg_global->max_channel; i++)
47     simdata->mbox[i] = xbt_fifo_new();
48   simdata->sleeping = xbt_new0(m_process_t, msg_global->max_channel);
49   simdata->process_list = xbt_fifo_new();
50   /* Update global variables */
51
52   xbt_fifo_unshift(msg_global->host, host);
53
54   PAJE_HOST_NEW(host);
55
56   return host;
57 }
58
59 /** \ingroup m_host_management
60  *
61  * \brief Set the user data of a #m_host_t.
62  *
63  * This functions checks whether some data has already been associated to \a host 
64    or not and attach \a data to \a host if it is possible.
65  */
66 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
67 {
68   xbt_assert0((host!=NULL), "Invalid parameters");
69   xbt_assert0((host->data == NULL), "Data already set");
70
71   /* Assign data */
72   host->data = data;
73
74   return MSG_OK;
75 }
76
77 /** \ingroup m_host_management
78  *
79  * \brief Return the user data of a #m_host_t.
80  *
81  * This functions checks whether \a host is a valid pointer or not and return
82    the user data associated to \a host if it is possible.
83  */
84 void *MSG_host_get_data(m_host_t host)
85 {
86
87   xbt_assert0((host != NULL), "Invalid parameters");
88
89   /* Return data */
90   return (host->data);
91 }
92
93 /** \ingroup m_host_management
94  *
95  * \brief Return the name of the #m_host_t.
96  *
97  * This functions checks whether \a host is a valid pointer or not and return
98    its name.
99  */
100 const char *MSG_host_get_name(m_host_t host)
101 {
102
103   xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
104
105   /* Return data */
106   return (host->name);
107 }
108
109 /** \ingroup m_host_management
110  *
111  * \brief Return the location on which the current process is executed.
112  */
113 m_host_t MSG_host_self(void)
114 {
115   return MSG_process_get_host(MSG_process_self());
116 }
117
118 /*
119  * Real function for destroy a host.
120  * MSG_host_destroy is just  a front_end that also removes it from 
121  * msg_global->host
122  */
123 void __MSG_host_destroy(m_host_t host)
124 {
125   simdata_host_t simdata = NULL;
126   int i = 0;
127
128   xbt_assert0((host != NULL), "Invalid parameters");
129
130   PAJE_HOST_FREE(host);
131  
132   /* Clean Simulator data */
133   simdata = (host)->simdata;
134
135   for (i = 0; i < msg_global->max_channel; i++)
136     xbt_fifo_free(simdata->mbox[i]);
137   free(simdata->mbox);
138   free(simdata->sleeping);
139   xbt_assert0((xbt_fifo_size(simdata->process_list)==0),
140               "Some process are still running on this host");
141   xbt_fifo_free(simdata->process_list);
142
143   free(simdata);
144
145   /* Clean host structure */
146   free(host->name);
147   free(host);
148
149   return;
150 }
151
152 /** \ingroup m_host_management
153  * \brief Return the current number of #m_host_t.
154  */
155 int MSG_get_host_number(void)
156 {
157   return (xbt_fifo_size(msg_global->host));
158 }
159
160 /** \ingroup m_host_management
161  * \brief Return a array of all the #m_host_t.
162  */
163 m_host_t *MSG_get_host_table(void)
164 {
165   return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
166 }
167
168 /** \ingroup m_host_management
169  * \brief Return the number of MSG tasks currently running on a
170  * #m_host_t. The external load is not taken in account.
171  */
172 int MSG_get_host_msgload(m_host_t h)
173 {
174   xbt_assert0((h!= NULL), "Invalid parameters");
175   xbt_assert0(0, "Not implemented yet");
176
177   return(0);
178 /*   return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */
179 }
180
181 /** \ingroup m_host_management
182  * \brief Return the speed of the processor (in flop/s), regardless of 
183     the current load on the machine.
184  */
185 double MSG_get_host_speed(m_host_t h)
186 {
187   xbt_assert0((h!= NULL), "Invalid parameters");
188
189   return(surf_workstation_resource->
190          extension_public->get_speed(h->simdata->host,1.0));
191 }
192
193 /** \ingroup msg_gos_functions
194  * \brief Determine if a host is available.
195  *
196  * \param h host to test
197  */
198 int MSG_host_is_avail (m_host_t h)
199 {
200   e_surf_cpu_state_t cpustate;
201   xbt_assert0((h!= NULL), "Invalid parameters");
202
203   cpustate =
204     surf_workstation_resource->extension_public->get_state(h->simdata->host);
205
206   xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF),
207               "Invalid cpu state");
208
209   return (cpustate==SURF_CPU_ON);
210 }