Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Commit the autogenerated files
[simgrid.git] / src / simix / smx_host.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4    All rights reserved.                                          */
5
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. */
8
9 #include "private.h"
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12
13 /** \defgroup m_host_management Management functions of Hosts
14  *  \brief This section describes the host structure of MSG
15  * 
16  *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
17  * (#m_host_t) and the functions for managing it.
18  *  
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.
25  *  \see m_host_t
26  */
27
28 /********************************* Host **************************************/
29 smx_host_t __SIMIX_host_create(const char *name,
30                          void *workstation,
31                          void *data)
32 {
33   simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
34   smx_host_t host = xbt_new0(s_smx_host_t,1);
35   s_smx_process_t proc;
36
37   /* Host structure */
38   host->name = xbt_strdup(name);
39   host->simdata = simdata;
40   host->data = data;
41
42   simdata->host = workstation;
43
44   simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
45   /* Update global variables */
46
47   xbt_fifo_unshift(simix_global->host, host);
48
49   return host;
50 }
51
52 /** \ingroup m_host_management
53  *
54  * \brief Set the user data of a #m_host_t.
55  *
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.
58  */
59 void SIMIX_host_set_data(smx_host_t host, void *data)
60 {
61   xbt_assert0((host!=NULL), "Invalid parameters");
62   xbt_assert0((host->data == NULL), "Data already set");
63
64   /* Assign data */
65   host->data = data;
66
67   return ;
68 }
69
70 /** \ingroup m_host_management
71  *
72  * \brief Return the user data of a #m_host_t.
73  *
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.
76  */
77 void *SIMIX_host_get_data(smx_host_t host)
78 {
79
80   xbt_assert0((host != NULL), "Invalid parameters");
81
82   /* Return data */
83   return (host->data);
84 }
85
86 /** \ingroup m_host_management
87  *
88  * \brief Return the name of the #m_host_t.
89  *
90  * This functions checks whether \a host is a valid pointer or not and return
91    its name.
92  */
93 const char *SIMIX_host_get_name(smx_host_t host)
94 {
95
96   xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
97
98   /* Return data */
99   return (host->name);
100 }
101
102 /** \ingroup m_host_management
103  *
104  * \brief Return the location on which the current process is executed.
105  */
106 smx_host_t SIMIX_host_self(void)
107 {
108   return SIMIX_process_get_host(SIMIX_process_self());
109 }
110
111 /*
112  * Real function for destroy a host.
113  * MSG_host_destroy is just  a front_end that also removes it from 
114  * msg_global->host
115  */
116 void __SIMIX_host_destroy(smx_host_t host)
117 {
118   simdata_host_t simdata = NULL;
119
120   xbt_assert0((host != NULL), "Invalid parameters");
121
122  
123   /* Clean Simulator data */
124   simdata = host->simdata;
125
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);
129
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 SIMIX_get_host_number(void)
143 {
144   return (xbt_fifo_size(simix_global->host));
145 }
146
147 /** \ingroup m_host_management
148  * \brief Return a array of all the #m_host_t.
149  */
150 smx_host_t *SIMIX_get_host_table(void)
151 {
152   return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
153 }
154
155
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.
159  */
160 double SIMIX_get_host_speed(smx_host_t h)
161 {
162   xbt_assert0((h!= NULL), "Invalid parameters");
163
164   return(surf_workstation_resource->
165          extension_public->get_speed(h->simdata->host,1.0));
166 }
167
168 /** \ingroup msg_gos_functions
169  * \brief Determine if a host is available.
170  *
171  * \param h host to test
172  */
173 int SIMIX_host_is_avail (smx_host_t h)
174 {
175   e_surf_cpu_state_t cpustate;
176   xbt_assert0((h!= NULL), "Invalid parameters");
177
178   cpustate =
179     surf_workstation_resource->extension_public->get_state(h->simdata->host);
180
181   xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF),
182               "Invalid cpu state");
183
184   return (cpustate==SURF_CPU_ON);
185 }