From b7630a950a6b865fcc195c58e39e6c3cfa550ccb Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 7 Jan 2016 14:52:21 +0100 Subject: [PATCH] give simgrid::Host a getState() method, and use it --- include/simgrid/Host.hpp | 1 + src/include/surf/surf.h | 5 ----- src/simgrid/host.cpp | 7 ++++++- src/simix/smx_host.cpp | 8 ++++---- src/simix/smx_io.cpp | 12 ++++++------ src/simix/smx_network.cpp | 5 ++--- src/simix/smx_process.cpp | 4 ++-- src/simix/smx_vm.cpp | 3 ++- src/surf/virtual_machine.hpp | 2 +- src/surf/vm_hl13.hpp | 4 ++-- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp index 0460df64c1..fb2a5090f7 100644 --- a/include/simgrid/Host.hpp +++ b/include/simgrid/Host.hpp @@ -40,6 +40,7 @@ public: simgrid::xbt::string const& getName() const { return name_; } void on(); void off(); + e_surf_resource_state_t getState(); xbt_dict_t getProperties(); xbt_swag_t getProcessList(); double getCurrentPowerPeak(); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index cf58fce33a..6d3265fec3 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -305,11 +305,6 @@ XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host); /** @brief Get the state of a surf resource (cpu, host, network, …) */ XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t resource); -static XBT_INLINE e_surf_resource_state_t surf_host_get_state(surf_host_t host) { - return surf_resource_get_state((surf_cpp_resource_t)host); -} - - /** @brief Set the state of a surf resource (cpu, host, network, …) */ XBT_PUBLIC(void) surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state); static inline void surf_host_set_state(surf_host_t host, e_surf_resource_state_t state) { diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index df6a15bf29..7f8881b646 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -138,7 +138,7 @@ double sg_host_get_available_speed(sg_host_t host){ * @return 1 if the host is active or 0 if it has crashed. */ int sg_host_get_state(sg_host_t host) { - return surf_host_get_state(surf_host_resource_priv(host)); + return host->p_cpu->getState(); } /** @brief Returns the total energy consumed by the host (in Joules). @@ -190,6 +190,11 @@ void Host::off() simgrid::simix::simcall(SIMCALL_HOST_OFF, this); } +e_surf_resource_state_t Host::getState() { + return p_cpu->getState(); +} + + /** Get the properties assigned to a host */ xbt_dict_t Host::getProperties() { diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 5139c62b61..71bf7a5c57 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -43,7 +43,7 @@ void SIMIX_host_on(sg_host_t h) xbt_assert((host != NULL), "Invalid parameters"); - if (surf_host_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_OFF) { + if (h->getState()==SURF_RESOURCE_OFF) { surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON); unsigned int cpt; @@ -96,7 +96,7 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer) xbt_assert((host != NULL), "Invalid parameters"); - if (surf_host_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_ON) { + if (h->getState()==SURF_RESOURCE_ON) { surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF); /* Clean Simulator data */ @@ -499,7 +499,7 @@ void SIMIX_execution_finish(smx_synchro_t synchro) (int)synchro->state); } /* check if the host is down */ - if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->host)) != SURF_RESOURCE_ON) { + if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } @@ -517,7 +517,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro) { if (synchro->type == SIMIX_SYNC_EXECUTE && /* FIMXE: handle resource failure * for parallel tasks too */ - surf_host_get_state(surf_host_resource_priv(synchro->execution.host)) == SURF_RESOURCE_OFF) { + synchro->execution.host->getState() == SURF_RESOURCE_OFF) { /* If the host running the synchro failed, notice it so that the asking * process can be killed if it runs on that host itself */ synchro->state = SIMIX_FAILED; diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index 146a80acc2..9bac80e889 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -61,7 +61,7 @@ smx_synchro_t SIMIX_file_read(smx_file_t fd, sg_size_t size, sg_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -93,7 +93,7 @@ smx_synchro_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -125,7 +125,7 @@ smx_synchro_t SIMIX_file_open(const char* fullpath, sg_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -157,7 +157,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, sg_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -181,7 +181,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, sg_host_t host) int SIMIX_file_unlink(smx_file_t fd, sg_host_t host) { /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -373,7 +373,7 @@ void SIMIX_io_finish(smx_synchro_t synchro) (int)synchro->state); } - if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->host)) != SURF_RESOURCE_ON) { + if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index d808503b73..21d58901a5 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -792,8 +792,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro) /* Check out for errors */ - if (surf_host_get_state(surf_host_resource_priv( - simcall->issuer->host)) != SURF_RESOURCE_ON) { + if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); } else @@ -871,7 +870,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro) } } - if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->host)) != SURF_RESOURCE_ON) { + if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 3f74714d1c..891f989c76 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -770,7 +770,7 @@ smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration) sg_host_t host = process->host; /* check if the host is active */ - if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (host->getState() != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host)); } @@ -812,7 +812,7 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro) THROW_IMPOSSIBLE; break; } - if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->host)) != SURF_RESOURCE_ON) { + if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } simcall_process_sleep__set__result(simcall, state); diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index 6751a1b94d..ae7493490a 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -9,6 +9,7 @@ #include "xbt/log.h" #include "xbt/dict.h" #include "mc/mc.h" +#include "src/surf/host_interface.hpp" //If you need to log some stuffs, just uncomment these two lines and uses XBT_DEBUG for instance XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX (vms)"); @@ -100,7 +101,7 @@ void SIMIX_vm_start(sg_host_t ind_vm) int SIMIX_vm_get_state(sg_host_t ind_vm) { - return surf_host_get_state(surf_host_resource_priv(ind_vm)); + return surf_host_resource_priv(ind_vm)->getState(); } /** diff --git a/src/surf/virtual_machine.hpp b/src/surf/virtual_machine.hpp index fff482a981..c943946ff9 100644 --- a/src/surf/virtual_machine.hpp +++ b/src/surf/virtual_machine.hpp @@ -68,7 +68,7 @@ public: /** @brief Destructor */ ~VirtualMachine(); - void setState(e_surf_resource_state_t state); + void setState(e_surf_resource_state_t state) override; /** @brief Suspend the VM */ virtual void suspend()=0; diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index aba2143324..df67e4f544 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -61,8 +61,8 @@ public: void migrate(sg_host_t ind_dst_pm) override; - e_surf_resource_state_t getState(); - void setState(e_surf_resource_state_t state); + e_surf_resource_state_t getState() override; + void setState(e_surf_resource_state_t state) override; void setBound(double bound); void setAffinity(Cpu *cpu, unsigned long mask); -- 2.20.1