Logo AND Algorithmique Numérique Distribuée

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