X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c2bf63103e5914cb2245c77d45adc47e9a302889..16edf70b872e2d607cbb9122f6168a85e27f3721:/src/simix/smx_host.c diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index d700fef4b2..699c67e2df 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -9,125 +9,115 @@ #include "private.h" #include "xbt/sysdep.h" #include "xbt/log.h" +#include "xbt/dict.h" -/** \defgroup m_host_management Management functions of Hosts - * \brief This section describes the host structure of MSG - * - * \htmlonly \endhtmlonly - * (#m_host_t) and the functions for managing it. - * - * A location (or host) is any possible place where - * a process may run. Thus it may be represented as a - * physical resource with computing capabilities, some - * mailboxes to enable running process to communicate with - * remote ones, and some private data 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_host_t smx_host = xbt_new0(s_smx_host_t, 1); s_smx_process_t proc; /* Host structure */ - host->name = xbt_strdup(name); - host->simdata = simdata; - host->data = data; - - simdata->host = workstation; + smx_host->name = xbt_strdup(name); + smx_host->data = data; + smx_host->host = workstation; + smx_host->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_dict_set(simix_global->host, smx_host->name, smx_host, &__SIMIX_host_destroy); - xbt_fifo_unshift(simix_global->host, host); - - return host; + return smx_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. */ -void SIMIX_host_set_data(smx_host_t host, void *data) +XBT_INLINE 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 ; + 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_INLINE void *SIMIX_host_get_data(smx_host_t host) { - xbt_assert0((host != NULL), "Invalid parameters"); /* Return data */ - return (host->data); + return host->data; } -/** \ingroup m_host_management - * - * \brief Return the name of the #m_host_t. +/** + * \brief Return the name of the #smx_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_INLINE const char *SIMIX_host_get_name(smx_host_t host) { - xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters"); + xbt_assert0((host != NULL), "Invalid parameters"); /* Return data */ - return (host->name); + 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) +XBT_INLINE smx_host_t SIMIX_host_self(void) { return SIMIX_process_get_host(SIMIX_process_self()); } /* * Real function for destroy a host. - * MSG_host_destroy is just a front_end that also removes it from + * MSG_host_destroy is just a front_end that also removes it from * msg_global->host */ -void __SIMIX_host_destroy(smx_host_t host) +void __SIMIX_host_destroy(void *h) { - simdata_host_t simdata = NULL; + smx_host_t host = (smx_host_t) h; xbt_assert0((host != NULL), "Invalid parameters"); - /* Clean Simulator data */ - simdata = host->simdata; + if (xbt_swag_size(host->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_assert0((xbt_swag_size(simdata->process_list)==0), - "Some process are still running on this host"); - xbt_swag_free(simdata->process_list); + xbt_swag_foreach(process, host->process_list) { + tmp = bprintf("%s\n\t%s", msg, process->name); + free(msg); + msg = tmp; + } + THROW1(arg_error, 0, "%s", msg); + } - free(simdata); + xbt_swag_free(host->process_list); /* Clean host structure */ free(host->name); @@ -136,50 +126,115 @@ 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) +XBT_INLINE int SIMIX_host_get_number(void) { - return (xbt_fifo_size(simix_global->host)); + return (xbt_dict_size(simix_global->host)); } -/** \ingroup m_host_management - * \brief Return a array of all the #m_host_t. + +/** + * \brief Return an array of all the #smx_host_t. + * + * \return List of all hosts (in a newly allocated table) */ -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)); + smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host)); + smx_host_t h; + xbt_dict_cursor_t c; + char *name; + int i = 0; + + xbt_dict_foreach(simix_global->host, c, name, h) + res[i++] = h; + + return res; } +/** + * \brief Return a dict of all the #smx_host_t. + * + * \return List of all hosts (as a #xbt_dict_t) + */ +XBT_INLINE xbt_dict_t SIMIX_host_get_dict(void) +{ + return 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 + */ +XBT_INLINE double SIMIX_host_get_speed(smx_host_t host) +{ + xbt_assert0((host != NULL), "Invalid parameters"); + + return (surf_workstation_model->extension.workstation. + get_speed(host->host, 1.0)); +} + +/** + * \brief Return the available speed of the processor. + * + * Return the available speed (in Mflop/s). + * \return Speed + */ +XBT_INLINE double SIMIX_host_get_available_speed(smx_host_t host) +{ + xbt_assert0((host != NULL), "Invalid parameters"); + + return (surf_workstation_model->extension.workstation. + get_available_speed(host->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 */ -double SIMIX_get_host_speed(smx_host_t h) +XBT_INLINE smx_host_t SIMIX_host_get_by_name(const char *name) { - xbt_assert0((h!= NULL), "Invalid parameters"); + xbt_assert0(((simix_global != NULL) + && (simix_global->host != NULL)), "Environment not set yet"); - return(surf_workstation_resource-> - extension_public->get_speed(h->simdata->host,1.0)); + return xbt_dict_get_or_null(simix_global->host, name); } -/** \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_INLINE 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 (simix host is NULL)"); + + return surf_workstation_model->extension.workstation.get_properties(host->host); +} - cpustate = - surf_workstation_resource->extension_public->get_state(h->simdata->host); - xbt_assert0((cpustate == SURF_CPU_ON || cpustate == SURF_CPU_OFF), - "Invalid cpu state"); +/** + * \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. + */ +XBT_INLINE int SIMIX_host_get_state(smx_host_t host) +{ + xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)"); - return (cpustate==SURF_CPU_ON); + return (surf_workstation_model->extension.workstation. + get_state(host->host)); }