Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* Cleanup the DTD by renaming:
[simgrid.git] / src / simix / smx_host.c
index b1f1b79..c00faa5 100644 (file)
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
 
-/** \defgroup m_host_management Management functions of Hosts
- *  \brief This section describes the host structure of MSG
- * 
- *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Hosts" --> \endhtmlonly
- * (#m_host_t) and the functions for managing it.
- *  
- *  A <em>location</em> (or <em>host</em>) is any possible place where
- *  a process may run. Thus it may be represented as a
- *  <em>physical resource with computing capabilities</em>, some
- *  <em>mailboxes</em> to enable running process to communicate with
- *  remote ones, and some <em>private data</em> that can be only
- *  accessed by local process.
- *  \see m_host_t
- */
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
+                               "Logging specific to SIMIX (hosts)");
 
 /********************************* Host **************************************/
 smx_host_t __SIMIX_host_create(const char *name,
-                        void *workstation,
-                        void *data)
+                              void *workstation, void *data)
 {
-  simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
-  smx_host_t host = xbt_new0(s_smx_host_t,1);
+  smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t, 1);
+  smx_host_t host = xbt_new0(s_smx_host_t, 1);
   s_smx_process_t proc;
 
   /* Host structure */
@@ -41,7 +28,8 @@ smx_host_t __SIMIX_host_create(const char *name,
 
   simdata->host = workstation;
 
-  simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
+  simdata->process_list =
+      xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
   /* Update global variables */
 
   xbt_fifo_unshift(simix_global->host, host);
@@ -49,59 +37,60 @@ smx_host_t __SIMIX_host_create(const char *name,
   return host;
 }
 
-/** \ingroup m_host_management
+/** 
+ * \brief Set the user data of a #smx_host_t.
  *
- * \brief Set the user data of a #m_host_t.
+ * This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
+ *     \param host SIMIX host
+ *     \param data User data
  *
- * This functions checks whether some data has already been associated to \a host 
-   or not and attach \a data to \a host if it is possible.
  */
-SIMIX_error_t SIMIX_host_set_data(smx_host_t host, void *data)
+void SIMIX_host_set_data(smx_host_t host, void *data)
 {
-  xbt_assert0((host!=NULL), "Invalid parameters");
+  xbt_assert0((host != NULL), "Invalid parameters");
   xbt_assert0((host->data == NULL), "Data already set");
 
   /* Assign data */
   host->data = data;
 
-  return SIMIX_OK;
+  return;
 }
 
-/** \ingroup m_host_management
+/**
+ * \brief Return the user data of a #smx_host_t.
  *
- * \brief Return the user data of a #m_host_t.
- *
- * This functions checks whether \a host is a valid pointer or not and return
-   the user data associated to \a host if it is possible.
+ * This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
+ * \param host SIMIX host
  */
 void *SIMIX_host_get_data(smx_host_t host)
 {
-
   xbt_assert0((host != NULL), "Invalid parameters");
 
   /* Return data */
   return (host->data);
 }
 
-/** \ingroup m_host_management
+/** 
+ * \brief Return the name of the #smx_host_t.
  *
- * \brief Return the name of the #m_host_t.
- *
- * This functions checks whether \a host is a valid pointer or not and return
-   its name.
+ * This functions checks whether \a host is a valid pointer or not and return its name.
+ * \param host SIMIX host
  */
 const char *SIMIX_host_get_name(smx_host_t host)
 {
 
-  xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
+  xbt_assert0((host != NULL)
+             && (host->simdata != NULL), "Invalid parameters");
 
   /* Return data */
   return (host->name);
 }
 
-/** \ingroup m_host_management
- *
+/** 
  * \brief Return the location on which the current process is executed.
+ *
+ * Return the host,  more details in #SIMIX_process_get_host
+ * \return SIMIX host
  */
 smx_host_t SIMIX_host_self(void)
 {
@@ -115,16 +104,28 @@ smx_host_t SIMIX_host_self(void)
  */
 void __SIMIX_host_destroy(smx_host_t host)
 {
-  simdata_host_t simdata = NULL;
+  smx_simdata_host_t simdata = NULL;
 
   xbt_assert0((host != NULL), "Invalid parameters");
 
+
   /* Clean Simulator data */
   simdata = host->simdata;
 
-  xbt_assert0((xbt_swag_size(simdata->process_list)==0),
-             "Some process are still running on this host");
+  if (xbt_swag_size(simdata->process_list) != 0) {
+    char *msg =
+       bprintf("Shutting down host %s, but it's not empty:", host->name);
+    char *tmp;
+    smx_process_t process = NULL;
+
+    xbt_swag_foreach(process, simdata->process_list) {
+      tmp = bprintf("%s\n\t%s", msg, process->name);
+      free(msg);
+      msg = tmp;
+    }
+    THROW1(arg_error, 0, "%s", msg);
+  }
+
   xbt_swag_free(simdata->process_list);
 
   free(simdata);
@@ -136,50 +137,107 @@ void __SIMIX_host_destroy(smx_host_t host)
   return;
 }
 
-/** \ingroup m_host_management
- * \brief Return the current number of #m_host_t.
+/**
+ * \brief Return the current number of #smx_host_t.
+ *
+ * \return Number of hosts
  */
-int SIMIX_get_host_number(void)
+int SIMIX_host_get_number(void)
 {
   return (xbt_fifo_size(simix_global->host));
 }
 
-/** \ingroup m_host_management
- * \brief Return a array of all the #m_host_t.
+/**
+ * \brief Return a array of all the #smx_host_t.
+ *
+ * \return List of all hosts
  */
-smx_host_t *SIMIX_get_host_table(void)
+smx_host_t *SIMIX_host_get_table(void)
 {
-  return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
+  return ((smx_host_t *) xbt_fifo_to_array(simix_global->host));
 }
 
 
-/** \ingroup m_host_management
- * \brief Return the speed of the processor (in Mflop/s), regardless of 
-    the current load on the machine.
+/**
+ * \brief Return the speed of the processor.
+ *
+ * Return the speed (in Mflop/s), regardless of the current load on the machine.
+ * \param host SIMIX host
+ * \return Speed
+ */
+double SIMIX_host_get_speed(smx_host_t host)
+{
+  xbt_assert0((host != NULL), "Invalid parameters");
+
+  return (surf_workstation_model->
+         extension_public->get_speed(host->simdata->host, 1.0));
+}
+
+/**
+ * \brief Return the available speed of the processor.
+ *
+ * Return the available speed (in Mflop/s).
+ * \return Speed
  */
-double SIMIX_get_host_speed(smx_host_t h)
+double SIMIX_host_get_available_speed(smx_host_t host)
 {
-  xbt_assert0((h!= NULL), "Invalid parameters");
+  xbt_assert0((host != NULL), "Invalid parameters");
 
-  return(surf_workstation_resource->
-        extension_public->get_speed(h->simdata->host,1.0));
+  return (surf_workstation_model->
+         extension_public->get_available_speed(host->simdata->host));
+}
+
+/**
+ * \brief Return the host by its name
+ *
+ * Finds a smx_host_t using its name.
+ * \param name The name of an host.
+ * \return The corresponding host
+ */
+smx_host_t SIMIX_host_get_by_name(const char *name)
+{
+  xbt_fifo_item_t i = NULL;
+  smx_host_t host = NULL;
+
+  xbt_assert0(((simix_global != NULL)
+              && (simix_global->host != NULL)),
+             "Environment not set yet");
+
+  xbt_fifo_foreach(simix_global->host, i, host, smx_host_t) {
+    if (strcmp(host->name, name) == 0)
+      return host;
+  }
+  return NULL;
 }
 
-/** \ingroup msg_gos_functions
- * \brief Determine if a host is available.
+/**
+ * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
  *
- * \param h host to test
+ * \param host a host
+ * \return the dynamic array consisting of property names
  */
-int SIMIX_host_is_avail (smx_host_t h)
+xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
 {
-  e_surf_cpu_state_t cpustate;
-  xbt_assert0((h!= NULL), "Invalid parameters");
+  xbt_assert0((host != NULL), "Invalid parameters");
+
+  return (surf_workstation_model->
+         common_public->get_cpu_properties(host->simdata->host));
+
+}
+
 
-  cpustate =
-    surf_workstation_resource->extension_public->get_state(h->simdata->host);
+/**
+ * \brief Return the state of a workstation
+ *
+ * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
+ * \param host The SIMIX host
+ * \return 1 if host is available or 0 if not.
+ */
+int SIMIX_host_get_state(smx_host_t host)
+{
+  xbt_assert0((host != NULL), "Invalid parameters");
 
-  xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF),
-             "Invalid cpu state");
+  return (surf_workstation_model->
+         extension_public->get_state(host->simdata->host));
 
-  return (cpustate==SURF_CPU_ON);
 }