From 0bac7d0f735ac8ba47a46e1db4f6d7a7164fe0f2 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Fri, 11 Dec 2015 13:17:23 +0100 Subject: [PATCH] Use simgrid::Host instead of xbt_dictelt_t for root main object The MC is currently broken. --- doc/doxygen/module-surf.doc | 2 +- include/simgrid/Host.hpp | 32 +++++ include/simgrid/forward.h | 10 +- include/simgrid/host.h | 13 +- include/simgrid/simdag.h | 2 +- include/surf/surf_routing.h | 2 +- include/xbt/Lib.hpp | 68 ++++++++++ src/bindings/java/jmsg.cpp | 7 +- src/bindings/java/jmsg_as.cpp | 2 +- src/bindings/java/jmsg_host.cpp | 14 +- src/bindings/java/jmsg_task.cpp | 4 +- src/bindings/java/jmsg_vm.cpp | 6 +- src/include/surf/surf.h | 97 +++++++------- src/mc/ModelChecker.cpp | 1 + src/mc/mc_smx.cpp | 1 + src/msg/msg_host.cpp | 25 ++-- src/msg/msg_vm.cpp | 41 +++--- src/s4u/s4u_host.cpp | 3 +- src/simdag/sd_dotloader.c | 2 +- src/simdag/sd_global.c | 13 +- src/simdag/sd_workstation.c | 4 +- src/simgrid/host.cpp | 140 +++++++++++++------- src/simgrid/sg_config.c | 2 +- src/simix/smx_host.cpp | 4 +- src/simix/smx_vm.cpp | 5 +- src/surf/host_clm03.cpp | 2 +- src/surf/host_interface.hpp | 2 +- src/surf/host_ptask_L07.cpp | 2 +- src/surf/network_ns3.cpp | 39 ++---- src/surf/ns3/ns3_interface.cc | 5 +- src/surf/ns3/ns3_interface.h | 13 ++ src/surf/surf_c_bindings.cpp | 117 ++++++++-------- src/surf/surf_interface.cpp | 8 +- src/surf/surf_routing.cpp | 16 +-- src/surf/surf_routing_vivaldi.cpp | 12 +- src/surf/virtual_machine.cpp | 7 +- src/surf/virtual_machine.hpp | 6 +- src/surf/vm_hl13.cpp | 11 +- src/surf/vm_hl13.hpp | 14 +- teshsuite/simdag/platforms/flatifier.c | 10 +- teshsuite/simdag/platforms/is_router_test.c | 4 +- 41 files changed, 470 insertions(+), 298 deletions(-) create mode 100644 include/simgrid/Host.hpp create mode 100644 include/xbt/Lib.hpp diff --git a/doc/doxygen/module-surf.doc b/doc/doxygen/module-surf.doc index 1cfcdc4851..80e4652238 100644 --- a/doc/doxygen/module-surf.doc +++ b/doc/doxygen/module-surf.doc @@ -53,7 +53,7 @@ #surf_host_model_init_current_default() or #surf_host_model_init_ptask_L07() to create the platform. - Then you can access the hosts with the global variables \ref host_lib. + Then you can access the hosts with the global variables \ref host_list. Some functions of the \ref SURF_host_interface and similar can give you some information about: - a host: get_speed(), get_available_speed(); diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp new file mode 100644 index 0000000000..a4e8ec5ed0 --- /dev/null +++ b/include/simgrid/Host.hpp @@ -0,0 +1,32 @@ +/* Copyright (c) 2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_HOST_HPP +#define SIMGRID_HOST_HPP + +#include +#include +#include + +#include +#include + +namespace simgrid { + +XBT_PUBLIC_CLASS Host : public simgrid::xbt::Lib { +private: + std::string id_; +public: + Host(std::string id); + ~Host(); + std::string const& id() const { return id_; } + static Host* find_host(const char* name); + static Host* get_host(const char* name); +}; + +} + +#endif diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index a0b8ded37e..434abff5dd 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -11,6 +11,10 @@ #ifdef __cplusplus +namespace simgrid { +class Host; +} + namespace simgrid { namespace surf { @@ -22,6 +26,7 @@ class Link; } } +typedef simgrid::Host simgrid_Host; typedef simgrid::surf::Cpu surf_Cpu; typedef simgrid::surf::RoutingEdge surf_RoutingEdge; typedef simgrid::surf::As surf_As; @@ -29,6 +34,7 @@ typedef simgrid::surf::Link Link; #else +typedef struct simgrid_Host simgrid_Host; typedef struct surf_Cpu surf_Cpu; typedef struct surf_RoutingEdge surf_RoutingEdge; typedef struct surf_As surf_As; @@ -36,17 +42,15 @@ typedef struct Link Link; #endif +typedef simgrid_Host* sg_host_t; typedef surf_Cpu *surf_cpu_t; typedef surf_RoutingEdge *routing_edge_t; typedef surf_RoutingEdge *sg_routing_edge_t; typedef surf_As *AS_t; // Types which are in fact dictelmt: - -typedef xbt_dictelm_t sg_host_t; typedef xbt_dictelm_t sg_storage_t; - typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */ typedef void *sg_routing_link_t; /* FIXME:The actual type is model-dependent so use void* instead*/ diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 185d57f26f..e440ef9036 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -7,18 +7,25 @@ #ifndef SIMGRID_HOST_H_ #define SIMGRID_HOST_H_ +#include + #include #include #include +#ifdef __cplusplus +#include +#endif + SG_BEGIN_DECL() +XBT_PUBLIC(size_t) sg_host_count(); +XBT_PUBLIC(size_t) sg_host_add_level(void(*deleter)(void*)); XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name); XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name); -static XBT_INLINE char *sg_host_get_name(sg_host_t host){ - return host->key; -} +XBT_PUBLIC(void*) sg_host_get_facet(sg_host_t host, size_t facet); +XBT_PUBLIC(const char*) sg_host_get_name(sg_host_t host); XBT_PUBLIC(xbt_dynar_t) sg_hosts_as_dynar(void); // ========== User Data ============== diff --git a/include/simgrid/simdag.h b/include/simgrid/simdag.h index 6c58089f1b..07a18c2735 100644 --- a/include/simgrid/simdag.h +++ b/include/simgrid/simdag.h @@ -22,7 +22,7 @@ SG_BEGIN_DECL() resource with computing capabilities and has a name. @see SD_workstation_management */ -typedef xbt_dictelm_t SD_workstation_t; +typedef sg_host_t SD_workstation_t; /** @brief Workstation access mode @ingroup SD_datatypes_management diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index 655b2b4da1..da85c7281f 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -12,7 +12,7 @@ SG_BEGIN_DECL() -XBT_PUBLIC_DATA(xbt_lib_t) host_lib; +XBT_PUBLIC_DATA(xbt_dict_t) host_list; XBT_PUBLIC_DATA(int) SURF_HOST_LEVEL; //Surf workstation level XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level XBT_PUBLIC_DATA(int) SD_STORAGE_LEVEL; //Simdag storage level diff --git a/include/xbt/Lib.hpp b/include/xbt/Lib.hpp new file mode 100644 index 0000000000..36c10b7ab0 --- /dev/null +++ b/include/xbt/Lib.hpp @@ -0,0 +1,68 @@ +/* Copyright (c) 2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_XBT_LIB_HPP +#define SIMGRID_XBT_LIB_HPP + +#include + +#include + +namespace simgrid { +namespace xbt { + +template +class Lib { +private: + static std::vector deleters_; +protected: + std::vector facets_; +public: + static std::size_t add_level(void (*deleter)(void*)) + { + std::size_t res = deleters_.size(); + deleters_.push_back(deleter); + return res; + } + template static + std::size_t add_level() + { + return add_level([](void* p){ delete (U*)p; }); + } + Lib() : facets_(deleters_.size(), nullptr) {} + ~Lib() + { + for (std::size_t i = 0; i < facets_.size(); ++i) + if (facets_[i] != nullptr) + deleters_[i](facets_[i]); + } + + // TODO, make type-safe versions of this + void* facet(std::size_t level) + { + if (level >= facets_.size()) + return nullptr; + else + return facets_.at(level); + } + void set_facet(std::size_t level, void* value, bool use_dtor = true) + { + if (level >= facets_.size()) + facets_.resize(level + 1, nullptr); + void* old_value = this->facet(level); + facets_.at(level) = value; + if (use_dtor && old_value != nullptr && deleters_[level]) + deleters_[level](old_value); + } +}; + +template +std::vector Lib::deleters_ = {}; + +} +} + +#endif diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 863053c2ba..90461fb968 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -134,8 +134,8 @@ Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) MSG_init(&argc, argv); - JAVA_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __JAVA_host_priv_free); - JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, (void_f_pvoid_t) __JAVA_storage_priv_free); + JAVA_HOST_LEVEL = simgrid::Host::add_level(__JAVA_host_priv_free); + JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, __JAVA_storage_priv_free); for (index = 0; index < argc; index++) free(argv[index]); @@ -157,7 +157,8 @@ JNIEXPORT void JNICALL /* Cleanup java hosts */ xbt_dynar_t hosts = MSG_hosts_as_dynar(); for (unsigned long index = 0; index < xbt_dynar_length(hosts) - 1; index++) { - jobject jhost = (jobject) xbt_lib_get_level(xbt_dynar_get_as(hosts,index,msg_host_t), JAVA_HOST_LEVEL); + msg_host_t msg_host = xbt_dynar_get_as(hosts,index,msg_host_t); + jobject jhost = (jobject) msg_host->facet(JAVA_HOST_LEVEL); if (jhost) jhost_unref(env, jhost); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index 2ebbc0e7fa..b7d9cd8679 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -161,7 +161,7 @@ Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas) host = xbt_dynar_get_as(table,index,msg_host_t); - jhost = (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + jhost = (jobject) host->facet(JAVA_HOST_LEVEL); if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 8a710d5671..5e1019aa38 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -86,7 +86,7 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, } env->ReleaseStringUTFChars(jname, name); - if (!xbt_lib_get_level(host, JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ + if (!host->facet(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ /* Instantiate a new java host */ jhost = jhost_new_instance(env); @@ -111,11 +111,11 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, /* the native host data field is set with the global reference to the * java host returned by this function */ - xbt_lib_set(host_lib, host->key, JAVA_HOST_LEVEL, (void *) jhost); + host->set_facet(JAVA_HOST_LEVEL, (void *)jhost); } /* return the global reference to the java host instance */ - return (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + return (jobject) host->facet(JAVA_HOST_LEVEL); } JNIEXPORT jobject JNICALL @@ -124,7 +124,7 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { msg_host_t host = MSG_host_self(); - if (!xbt_lib_get_level(host, JAVA_HOST_LEVEL)) { + if (!host->facet(JAVA_HOST_LEVEL)) { /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ @@ -148,9 +148,9 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { env->SetObjectField(jhost, jhost_field_Host_name, jname); /* Bind & store it */ jhost_bind(jhost, host, env); - xbt_lib_set(host_lib, host->key, JAVA_HOST_LEVEL, (void *) jhost); + host->set_facet(JAVA_HOST_LEVEL, (void *) jhost); } else { - jhost = (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + jhost = (jobject) host->facet(JAVA_HOST_LEVEL); } return jhost; @@ -368,7 +368,7 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) for (index = 0; index < count; index++) { host = xbt_dynar_get_as(table,index,msg_host_t); - jhost = (jobject) (xbt_lib_get_level(host, JAVA_HOST_LEVEL)); + jhost = (jobject) host->facet(JAVA_HOST_LEVEL); if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); diff --git a/src/bindings/java/jmsg_task.cpp b/src/bindings/java/jmsg_task.cpp index 0977910ca3..cd22641e7f 100644 --- a/src/bindings/java/jmsg_task.cpp +++ b/src/bindings/java/jmsg_task.cpp @@ -282,12 +282,12 @@ Java_org_simgrid_msg_Task_getSource(JNIEnv * env, if (host == NULL) { return NULL; } - if (!xbt_lib_get_level(host, JAVA_HOST_LEVEL)) { + if (!host->facet(JAVA_HOST_LEVEL)) { jxbt_throw_jni(env, "MSG_task_get_source() failed"); return NULL; } - return (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + return (jobject) host->facet(JAVA_HOST_LEVEL); } JNIEXPORT jdouble JNICALL diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index a5be2cca98..0258585ae1 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -167,7 +167,7 @@ Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm) { msg_vm_t vm = jvm_get_native(env,jvm); msg_host_t host = MSG_vm_get_pm(vm); - if (!xbt_lib_get_level(host, JAVA_HOST_LEVEL)) { + if (!host->facet(JAVA_HOST_LEVEL)) { /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ @@ -193,9 +193,9 @@ Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm) { jname); /* Bind & store it */ jhost_bind(jhost, host, env); - xbt_lib_set(host_lib, host->key, JAVA_HOST_LEVEL, (void *) jhost); + host->set_facet(JAVA_HOST_LEVEL, (void *) jhost); } else { - jhost = (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + jhost = (jobject) host->facet(JAVA_HOST_LEVEL); } return jhost; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 706486ea22..1eee7b4e17 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -198,8 +198,9 @@ typedef enum { XBT_PUBLIC_DATA(routing_platf_t) routing_platf; -static inline surf_host_t surf_host_resource_priv(const void *host){ - return (surf_host_t) xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL); +static inline surf_host_t surf_host_resource_priv(sg_host_t host) +{ + return (surf_host_t) sg_host_get_facet(host, SURF_HOST_LEVEL); } static inline void *surf_storage_resource_priv(const void *storage){ return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL); @@ -271,10 +272,11 @@ XBT_PUBLIC(surf_action_t) surf_host_model_execute_parallel_task(surf_host_model_ double rate); /** @brief Get the route (dynar of sg_link_t) between two hosts */ -XBT_PUBLIC(xbt_dynar_t) surf_host_model_get_route(surf_host_model_t model, surf_resource_t src, surf_resource_t dst); +XBT_PUBLIC(xbt_dynar_t) surf_host_model_get_route( + surf_host_model_t model, sg_host_t src, sg_host_t dst); /** @brief Create a new VM on the specified host */ -XBT_PUBLIC(void) surf_vm_model_create(const char *name, surf_resource_t host_PM); +XBT_PUBLIC(void) surf_vm_model_create(const char *name, sg_host_t host_PM); /** @brief Create a communication between two hosts * @@ -320,31 +322,31 @@ static inline void surf_host_set_state(surf_host_t host, e_surf_resource_state_t } /** @brief Get the speed of the cpu associated to a host */ -XBT_PUBLIC(double) surf_host_get_speed(surf_resource_t resource, double load); +XBT_PUBLIC(double) surf_host_get_speed(sg_host_t resource, double load); /** @brief Get the available speed of cpu associated to a host */ -XBT_PUBLIC(double) surf_host_get_available_speed(surf_resource_t host); +XBT_PUBLIC(double) surf_host_get_available_speed(sg_host_t host); /** @brief Get the number of cores of the cpu associated to a host */ -XBT_PUBLIC(int) surf_host_get_core(surf_resource_t host); +XBT_PUBLIC(int) surf_host_get_core(sg_host_t host); /** @brief Create a computation action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_execute(surf_resource_t host, double size); +XBT_PUBLIC(surf_action_t) surf_host_execute(sg_host_t host, double size); /** @brief Create a sleep action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_sleep(surf_resource_t host, double duration); +XBT_PUBLIC(surf_action_t) surf_host_sleep(sg_host_t host, double duration); /** @brief Create a file opening action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_open(surf_resource_t host, const char* fullpath); +XBT_PUBLIC(surf_action_t) surf_host_open(sg_host_t host, const char* fullpath); /** @brief Create a file closing action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_close(surf_resource_t host, surf_file_t fd); +XBT_PUBLIC(surf_action_t) surf_host_close(sg_host_t host, surf_file_t fd); /** @brief Create a file reading action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_read(surf_resource_t host, surf_file_t fd, sg_size_t size); +XBT_PUBLIC(surf_action_t) surf_host_read(sg_host_t host, surf_file_t fd, sg_size_t size); /** @brief Create a file writing action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_write(surf_resource_t host, surf_file_t fd, sg_size_t size); +XBT_PUBLIC(surf_action_t) surf_host_write(sg_host_t host, surf_file_t fd, sg_size_t size); /** * @brief Get the informations of a file descriptor @@ -359,7 +361,7 @@ XBT_PUBLIC(surf_action_t) surf_host_write(surf_resource_t host, surf_file_t fd, * @param fd The file descriptor * @return An xbt_dynar_t with the file informations */ -XBT_PUBLIC(xbt_dynar_t) surf_host_get_info(surf_resource_t host, surf_file_t fd); +XBT_PUBLIC(xbt_dynar_t) surf_host_get_info(sg_host_t host, surf_file_t fd); /** * @brief Get the available space of the storage at the mount point @@ -368,7 +370,7 @@ XBT_PUBLIC(xbt_dynar_t) surf_host_get_info(surf_resource_t host, surf_file_t fd) * @param name The mount point * @return The amount of available space in bytes */ -XBT_PUBLIC(sg_size_t) surf_host_get_free_size(surf_resource_t resource, const char* name); +XBT_PUBLIC(sg_size_t) surf_host_get_free_size(sg_host_t resource, const char* name); /** * @brief Get the used space of the storage at the mount point @@ -377,47 +379,47 @@ XBT_PUBLIC(sg_size_t) surf_host_get_free_size(surf_resource_t resource, const ch * @param name The mount point * @return The amount of used space in bytes */ -XBT_PUBLIC(sg_size_t) surf_host_get_used_size(surf_resource_t resource, const char* name); +XBT_PUBLIC(sg_size_t) surf_host_get_used_size(sg_host_t resource, const char* name); /** @brief Get the list of VMs hosted on the host */ -XBT_PUBLIC(xbt_dynar_t) surf_host_get_vms(surf_resource_t resource); +XBT_PUBLIC(xbt_dynar_t) surf_host_get_vms(sg_host_t resource); /** @brief Retrieve the params of that VM * @details You can use fields ramsize and overcommit on a PM, too. */ -XBT_PUBLIC(void) surf_host_get_params(surf_resource_t resource, vm_params_t params); +XBT_PUBLIC(void) surf_host_get_params(sg_host_t resource, vm_params_t params); /** @brief Sets the params of that VM/PM * @details You can use fields ramsize and overcommit on a PM, too. */ -XBT_PUBLIC(void) surf_host_set_params(surf_resource_t resource, vm_params_t params); +XBT_PUBLIC(void) surf_host_set_params(sg_host_t resource, vm_params_t params); /** * @brief Destroy a VM * * @param resource The surf vm */ -XBT_PUBLIC(void) surf_vm_destroy(surf_resource_t resource); +XBT_PUBLIC(void) surf_vm_destroy(sg_host_t resource); /** @brief Suspend a VM */ -XBT_PUBLIC(void) surf_vm_suspend(surf_resource_t resource); +XBT_PUBLIC(void) surf_vm_suspend(sg_host_t resource); /** @brief Resume a VM */ -XBT_PUBLIC(void) surf_vm_resume(surf_resource_t resource); +XBT_PUBLIC(void) surf_vm_resume(sg_host_t resource); /** * @brief Save the VM (Not yet implemented) * * @param resource The surf vm */ -XBT_PUBLIC(void) surf_vm_save(surf_resource_t resource); +XBT_PUBLIC(void) surf_vm_save(sg_host_t resource); /** * @brief Restore the VM (Not yet implemented) * * @param resource The surf vm */ -XBT_PUBLIC(void) surf_vm_restore(surf_resource_t resource); +XBT_PUBLIC(void) surf_vm_restore(sg_host_t resource); /** * @brief Migrate the VM to the destination host @@ -425,7 +427,7 @@ XBT_PUBLIC(void) surf_vm_restore(surf_resource_t resource); * @param resource The surf vm * @param ind_vm_ws_dest The destination host */ -XBT_PUBLIC(void) surf_vm_migrate(surf_resource_t resource, surf_resource_t ind_vm_ws_dest); +XBT_PUBLIC(void) surf_vm_migrate(sg_host_t resource, sg_host_t ind_vm_ws_dest); /** * @brief Get the physical machine hosting the VM @@ -433,7 +435,7 @@ XBT_PUBLIC(void) surf_vm_migrate(surf_resource_t resource, surf_resource_t ind_v * @param resource The surf vm * @return The physical machine hosting the VM */ -XBT_PUBLIC(surf_resource_t) surf_vm_get_pm(surf_resource_t resource); +XBT_PUBLIC(sg_host_t) surf_vm_get_pm(sg_host_t resource); /** * @brief [brief description] @@ -442,7 +444,7 @@ XBT_PUBLIC(surf_resource_t) surf_vm_get_pm(surf_resource_t resource); * @param resource [description] * @param bound [description] */ -XBT_PUBLIC(void) surf_vm_set_bound(surf_resource_t resource, double bound); +XBT_PUBLIC(void) surf_vm_set_bound(sg_host_t resource, double bound); /** * @brief [brief description] @@ -452,7 +454,7 @@ XBT_PUBLIC(void) surf_vm_set_bound(surf_resource_t resource, double bound); * @param cpu [description] * @param mask [description] */ -XBT_PUBLIC(void) surf_vm_set_affinity(surf_resource_t resource, surf_resource_t cpu, unsigned long mask); +XBT_PUBLIC(void) surf_vm_set_affinity(sg_host_t resource, sg_host_t cpu, unsigned long mask); /** * @brief Execute some quantity of computation @@ -461,7 +463,7 @@ XBT_PUBLIC(void) surf_vm_set_affinity(surf_resource_t resource, surf_resource_t * @param size The value of the processing amount (in flop) needed to process * @return The surf action corresponding to the processing */ -XBT_PUBLIC(surf_action_t) surf_cpu_execute(surf_resource_t cpu, double size); +XBT_PUBLIC(surf_action_t) surf_cpu_execute(sg_host_t cpu, double size); /** * @brief Make the cpu sleep for duration (in seconds) @@ -471,7 +473,7 @@ XBT_PUBLIC(surf_action_t) surf_cpu_execute(surf_resource_t cpu, double size); * @param duration The number of seconds to sleep * @return The surf action corresponding to the sleeping */ -XBT_PUBLIC(surf_action_t) surf_cpu_sleep(surf_resource_t cpu, double duration); +XBT_PUBLIC(surf_action_t) surf_cpu_sleep(sg_host_t cpu, double duration); /** * @brief Get the host power peak @@ -480,7 +482,7 @@ XBT_PUBLIC(surf_action_t) surf_cpu_sleep(surf_resource_t cpu, double duration); * @param host The surf host * @return The power peak */ -XBT_PUBLIC(double) surf_host_get_current_power_peak(surf_resource_t host); +XBT_PUBLIC(double) surf_host_get_current_power_peak(sg_host_t host); /** * @brief [brief description] @@ -491,7 +493,7 @@ XBT_PUBLIC(double) surf_host_get_current_power_peak(surf_resource_t host); * * @return [description] */ -XBT_PUBLIC(double) surf_host_get_power_peak_at(surf_resource_t host, int pstate_index); +XBT_PUBLIC(double) surf_host_get_power_peak_at(sg_host_t host, int pstate_index); /** * @brief [brief description] @@ -500,12 +502,12 @@ XBT_PUBLIC(double) surf_host_get_power_peak_at(surf_resource_t host, int pstate_ * @param host [description] * @return [description] */ -XBT_PUBLIC(int) surf_host_get_nb_pstates(surf_resource_t host); +XBT_PUBLIC(int) surf_host_get_nb_pstates(sg_host_t host); -XBT_PUBLIC(void) surf_host_set_pstate(surf_resource_t host, int pstate_index); -XBT_PUBLIC(int) surf_host_get_pstate(surf_resource_t host); -XBT_PUBLIC(double) surf_host_get_wattmin_at(surf_resource_t resource, int pstate); -XBT_PUBLIC(double) surf_host_get_wattmax_at(surf_resource_t resource, int pstate); +XBT_PUBLIC(void) surf_host_set_pstate(sg_host_t host, int pstate_index); +XBT_PUBLIC(int) surf_host_get_pstate(sg_host_t host); +XBT_PUBLIC(double) surf_host_get_wattmin_at(sg_host_t resource, int pstate); +XBT_PUBLIC(double) surf_host_get_wattmax_at(sg_host_t resource, int pstate); /** * @brief Get the consumed energy (in joules) of an host @@ -513,7 +515,7 @@ XBT_PUBLIC(double) surf_host_get_wattmax_at(surf_resource_t resource, int pstate * @param host The surf host * @return The consumed energy */ -XBT_PUBLIC(double) surf_host_get_consumed_energy(surf_resource_t host); +XBT_PUBLIC(double) surf_host_get_consumed_energy(sg_host_t host); /** * @brief Get the list of storages mounted on an host @@ -521,7 +523,7 @@ XBT_PUBLIC(double) surf_host_get_consumed_energy(surf_resource_t host); * @param host The surf host * @return Dictionary of mount point, Storage */ -XBT_PUBLIC(xbt_dict_t) surf_host_get_mounted_storage_list(surf_resource_t host); +XBT_PUBLIC(xbt_dict_t) surf_host_get_mounted_storage_list(sg_host_t host); /** * @brief Get the list of storages attached to an host @@ -529,7 +531,7 @@ XBT_PUBLIC(xbt_dict_t) surf_host_get_mounted_storage_list(surf_resource_t host); * @param host The surf host * @return Dictionary of storage */ -XBT_PUBLIC(xbt_dynar_t) surf_host_get_attached_storage_list(surf_resource_t host); +XBT_PUBLIC(xbt_dynar_t) surf_host_get_attached_storage_list(sg_host_t host); /** * @brief Unlink a file descriptor @@ -539,7 +541,7 @@ XBT_PUBLIC(xbt_dynar_t) surf_host_get_attached_storage_list(surf_resource_t host * * @return 0 if failed to unlink, 1 otherwise */ -XBT_PUBLIC(int) surf_host_unlink(surf_resource_t host, surf_file_t fd); +XBT_PUBLIC(int) surf_host_unlink(sg_host_t host, surf_file_t fd); /** * @brief Get the size of a file on a host @@ -549,7 +551,7 @@ XBT_PUBLIC(int) surf_host_unlink(surf_resource_t host, surf_file_t fd); * * @return The size in bytes of the file */ -XBT_PUBLIC(size_t) surf_host_get_size(surf_resource_t host, surf_file_t fd); +XBT_PUBLIC(size_t) surf_host_get_size(sg_host_t host, surf_file_t fd); /** * @brief Get the current position of the file descriptor @@ -558,7 +560,7 @@ XBT_PUBLIC(size_t) surf_host_get_size(surf_resource_t host, surf_file_t fd); * @param fd The file descriptor * @return The current position of the file descriptor */ -XBT_PUBLIC(size_t) surf_host_file_tell(surf_resource_t host, surf_file_t fd); +XBT_PUBLIC(size_t) surf_host_file_tell(sg_host_t host, surf_file_t fd); /** * @brief Move a file to another location on the *same mount point*. @@ -570,7 +572,7 @@ XBT_PUBLIC(size_t) surf_host_file_tell(surf_resource_t host, surf_file_t fd); * * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED */ -XBT_PUBLIC(int) surf_host_file_move(surf_resource_t host, surf_file_t fd, const char* fullpath); +XBT_PUBLIC(int) surf_host_file_move(sg_host_t host, surf_file_t fd, const char* fullpath); /** * @brief Set the position indictator assiociated with the file descriptor to a new position @@ -585,7 +587,7 @@ XBT_PUBLIC(int) surf_host_file_move(surf_resource_t host, surf_file_t fd, const * - SEEK_END: end of the file * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED */ -XBT_PUBLIC(int) surf_host_file_seek(surf_resource_t host, +XBT_PUBLIC(int) surf_host_file_seek(sg_host_t host, surf_file_t fd, sg_offset_t offset, int origin); @@ -733,7 +735,7 @@ XBT_PUBLIC(double) surf_action_get_cost(surf_action_t action); * @param cpu [description] * @param mask [description] */ -XBT_PUBLIC(void) surf_cpu_action_set_affinity(surf_action_t action, surf_resource_t cpu, unsigned long mask); +XBT_PUBLIC(void) surf_cpu_action_set_affinity(surf_action_t action, sg_host_t cpu, unsigned long mask); /** * @brief [brief description] @@ -774,10 +776,11 @@ XBT_PUBLIC(xbt_dict_t) surf_storage_action_get_ls_dict(surf_action_t action); * * @param resource The surf storage * @return The host name + * may not exist. */ XBT_PUBLIC(const char * ) surf_storage_get_host(surf_resource_t resource); -XBT_PUBLIC(surf_model_t) surf_resource_model(const void *host, int level); +XBT_PUBLIC(surf_host_model_t) surf_host_get_model(sg_host_t host); /** @} */ diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 5c947d25a6..6e73a2de40 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -63,6 +63,7 @@ ModelChecker::~ModelChecker() const char* ModelChecker::get_host_name(const char* hostname) { + // FIXME, simgrid::Host // Lookup the host name in the dictionary (or create it): xbt_dictelm_t elt = xbt_dict_get_elm_or_null(this->hostnames_, hostname); if (!elt) { diff --git a/src/mc/mc_smx.cpp b/src/mc/mc_smx.cpp index 9e95602299..2b051ca43b 100644 --- a/src/mc/mc_smx.cpp +++ b/src/mc/mc_smx.cpp @@ -179,6 +179,7 @@ const char* MC_smx_process_get_host_name(smx_process_t p) simgrid::mc::Process* process = &mc_model_checker->process(); + // FIXME, simgrid::Host // Currently, smx_host_t = xbt_dictelm_t. // TODO, add an static_assert on this if switching to C++ // The host name is host->key and the host->key_len==strlen(host->key). diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index da8e2ffcb4..209e29620a 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -9,6 +9,7 @@ #include "xbt/sysdep.h" #include "xbt/log.h" #include "simgrid/simix.h" +#include "simgrid/Host.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg); @@ -72,7 +73,7 @@ msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our paramete */ msg_host_t MSG_host_by_name(const char *name) { - return (msg_host_t) xbt_lib_get_elm_or_null(host_lib,name); + return simgrid::Host::find_host(name); } /** \ingroup m_host_management @@ -179,27 +180,23 @@ void __MSG_host_destroy(msg_host_t host) //FIXME: killme? */ int MSG_get_host_number(void) { - return xbt_lib_length(host_lib); + return xbt_dict_length(host_list); } #ifdef MSG_USE_DEPRECATED msg_host_t *MSG_get_host_table(void) { - void **array; - int i = 0; - xbt_lib_cursor_t cursor; - char *key; - void **data; + if (xbt_dict_is_empty(host_list)) + return nullptr; - if (xbt_lib_length(host_lib) == 0) - return NULL; - else - array = xbt_new0(void *, xbt_lib_length(host_lib)); + void **array = xbt_new0(void *, xbt_dict_length(host_list)); - xbt_lib_foreach(host_lib, cursor, key, data) { + xbt_lib_cursor_t cursor; + const char *id; + simgrid::Host* host; + xbt_dict_foreach(host_list, cursor, id, host) if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) - array[i++] = data[MSG_HOST_LEVEL]; - } + array[i++] = host->facet(MSG_HOST_LEVEL); return (msg_host_t *)array; } diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 91c4796d5d..836b25dd5c 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -210,10 +210,11 @@ msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name) { /* make sure the VM of the same name does not exit */ { - xbt_dictelm_t ind_host_tmp = xbt_lib_get_elm_or_null(host_lib, name); - if (ind_host_tmp && sg_host_simix(ind_host_tmp) != NULL) { + simgrid::Host* ind_host_tmp = + (simgrid::Host*) xbt_dict_get_or_null(host_list, name); + if (ind_host_tmp != nullptr && sg_host_simix(ind_host_tmp) != nullptr) { XBT_ERROR("host %s already exits", name); - return NULL; + return nullptr; } } @@ -293,45 +294,45 @@ void MSG_vm_shutdown(msg_vm_t vm) * migration. The names of these mailboxes must not conflict with others. */ static inline char *get_mig_mbox_src_dst(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm) { - char *vm_name = sg_host_get_name(vm); - char *src_pm_name = sg_host_get_name(src_pm); - char *dst_pm_name = sg_host_get_name(dst_pm); + const char *vm_name = sg_host_get_name(vm); + const char *src_pm_name = sg_host_get_name(src_pm); + const char *dst_pm_name = sg_host_get_name(dst_pm); return bprintf("__mbox_mig_src_dst:%s(%s-%s)", vm_name, src_pm_name, dst_pm_name); } static inline char *get_mig_mbox_ctl(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm) { - char *vm_name = sg_host_get_name(vm); - char *src_pm_name = sg_host_get_name(src_pm); - char *dst_pm_name = sg_host_get_name(dst_pm); + const char *vm_name = sg_host_get_name(vm); + const char *src_pm_name = sg_host_get_name(src_pm); + const char *dst_pm_name = sg_host_get_name(dst_pm); return bprintf("__mbox_mig_ctl:%s(%s-%s)", vm_name, src_pm_name, dst_pm_name); } static inline char *get_mig_process_tx_name(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm) { - char *vm_name = sg_host_get_name(vm); - char *src_pm_name = sg_host_get_name(src_pm); - char *dst_pm_name = sg_host_get_name(dst_pm); + const char *vm_name = sg_host_get_name(vm); + const char *src_pm_name = sg_host_get_name(src_pm); + const char *dst_pm_name = sg_host_get_name(dst_pm); return bprintf("__pr_mig_tx:%s(%s-%s)", vm_name, src_pm_name, dst_pm_name); } static inline char *get_mig_process_rx_name(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm) { - char *vm_name = sg_host_get_name(vm); - char *src_pm_name = sg_host_get_name(src_pm); - char *dst_pm_name = sg_host_get_name(dst_pm); + const char *vm_name = sg_host_get_name(vm); + const char *src_pm_name = sg_host_get_name(src_pm); + const char *dst_pm_name = sg_host_get_name(dst_pm); return bprintf("__pr_mig_rx:%s(%s-%s)", vm_name, src_pm_name, dst_pm_name); } static inline char *get_mig_task_name(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm, int stage) { - char *vm_name = sg_host_get_name(vm); - char *src_pm_name = sg_host_get_name(src_pm); - char *dst_pm_name = sg_host_get_name(dst_pm); + const char *vm_name = sg_host_get_name(vm); + const char *src_pm_name = sg_host_get_name(src_pm); + const char *dst_pm_name = sg_host_get_name(dst_pm); return bprintf("__task_mig_stage%d:%s(%s-%s)", stage, vm_name, src_pm_name, dst_pm_name); } @@ -423,7 +424,9 @@ static int migration_rx_fun(int argc, char *argv[]) // Now the VM is running on the new host (the migration is completed) (even if the SRC crash) msg_host_priv_t priv = sg_host_msg(vm); priv->is_migrating = 0; - XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", ms->vm->key, ms->src_pm->key, ms->dst_pm->key); + XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", + sg_host_get_name(ms->vm), sg_host_get_name(ms->src_pm), + sg_host_get_name(ms->dst_pm)); TRACE_msg_vm_change_host(ms->vm, ms->src_pm, ms->dst_pm); } // Inform the SRC that the migration has been correctly performed diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index b9d83b4f52..6f35dfb5a4 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -17,7 +17,8 @@ namespace s4u { boost::unordered_map *Host::hosts = new boost::unordered_map(); -Host::Host(const char*name) { +Host::Host(const char*name) +{ p_inferior = sg_host_by_name(name); if (p_inferior==NULL) xbt_die("No such host: %s",name); //FIXME: raise an exception diff --git a/src/simdag/sd_dotloader.c b/src/simdag/sd_dotloader.c index fc32b2649d..4e0c4a1534 100644 --- a/src/simdag/sd_dotloader.c +++ b/src/simdag/sd_dotloader.c @@ -231,7 +231,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){ computer = xbt_dynar_new(sizeof(SD_task_t), NULL); xbt_dict_set(computers, char_performer, computer, NULL); } - if(performer < xbt_lib_length(host_lib)){ + if(performer < xbt_dict_length(host_list)){ /* the wanted computer is available */ SD_task_t *task_test = NULL; if(order < computer->used) diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index e5f97a0b36..dad96a3992 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -10,6 +10,7 @@ #include "xbt/dynar.h" #include "surf/surf.h" #include "simgrid/sg_config.h" +#include "simgrid/host.h" #include "xbt/ex.h" #include "xbt/log.h" #include "xbt/str.h" @@ -201,15 +202,19 @@ void SD_create_environment(const char *platform_file) { xbt_lib_cursor_t cursor = NULL; char *name = NULL; - void **surf_workstation = NULL; void **surf_storage = NULL; parse_platform_file(platform_file); /* now let's create the SD wrappers for workstations, storages and links */ - xbt_lib_foreach(host_lib, cursor, name, surf_workstation){ - if(surf_workstation[SURF_HOST_LEVEL]) - __SD_workstation_create(surf_workstation[SURF_HOST_LEVEL], NULL); + { + xbt_dict_cursor_t cursor = NULL; + simgrid_Host* host = NULL; + xbt_dict_foreach(host_list, cursor, name, host){ + surf_Host* surf_host = (surf_Host*) sg_host_get_facet(host, SURF_HOST_LEVEL); + if (surf_host != NULL) + __SD_workstation_create(surf_host, NULL); + } } xbt_lib_foreach(storage_lib, cursor, name, surf_storage) { diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 178c33a460..3b5c2ea7be 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -72,7 +72,7 @@ void __SD_storage_destroy(void *storage) */ SD_workstation_t SD_workstation_get_by_name(const char *name) { - return xbt_lib_get_elm_or_null(host_lib, name); + return sg_host_by_name(name); } /** @@ -101,7 +101,7 @@ const SD_workstation_t *SD_workstation_get_list(void) { */ int SD_workstation_get_number(void) { - return xbt_lib_length(host_lib); + return sg_host_count(); } /** diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 4f4ea787a7..376392a9c9 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -6,32 +6,49 @@ #include "xbt/dict.h" #include "simgrid/host.h" +#include "simgrid/Host.hpp" #include "surf/surf.h" // routing_get_network_element_type FIXME:killme -sg_host_t sg_host_by_name(const char *name){ - return xbt_lib_get_elm_or_null(host_lib, name); +size_t sg_host_count() +{ + return xbt_dict_length(host_list); } -sg_host_t sg_host_by_name_or_create(const char *name) { - sg_host_t res = xbt_lib_get_elm_or_null(host_lib, name); - if (!res) { - xbt_lib_set(host_lib,name,0,NULL); // Should only create the bucklet with no data added - res = xbt_lib_get_elm_or_null(host_lib, name); - } - return res; +void* sg_host_get_facet(sg_host_t host, size_t facet) +{ + return host->facet(facet); +} + +const char *sg_host_get_name(sg_host_t host) +{ + return host->id().c_str(); +} + +size_t sg_host_add_level(void(*deleter)(void*)) +{ + return simgrid::Host::add_level(deleter); } -xbt_dynar_t sg_hosts_as_dynar(void) { - xbt_lib_cursor_t cursor; - char *key; - void **data; + +sg_host_t sg_host_by_name(const char *name) +{ + return simgrid::Host::find_host(name); +} + +sg_host_t sg_host_by_name_or_create(const char *name) +{ + return simgrid::Host::get_host(name); +} + +xbt_dynar_t sg_hosts_as_dynar(void) +{ xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL); - xbt_lib_foreach(host_lib, cursor, key, data) { - if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) { - xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor); - xbt_dynar_push(res, &elm); - } - } + xbt_dict_cursor_t cursor = nullptr; + const char* name = nullptr; + simgrid::Host* host = nullptr; + xbt_dict_foreach(host_list, cursor, name, host) + if(routing_get_network_element_type(name) == SURF_NETWORK_ELEMENT_HOST) + xbt_dynar_push(res, &host); return res; } @@ -57,65 +74,67 @@ static XBT_INLINE void routing_asr_host_free(void *p) { delete static_cast(p); } -void sg_host_init() { - MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free); - SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy); - - SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); - SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free); - ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); - USER_HOST_LEVEL = xbt_lib_add_level(host_lib,NULL); +void sg_host_init() +{ + MSG_HOST_LEVEL = simgrid::Host::add_level([](void *p) { + __MSG_host_priv_free((msg_host_priv_t) p); + }); + SD_HOST_LEVEL = simgrid::Host::add_level(__SD_workstation_destroy); + SIMIX_HOST_LEVEL = simgrid::Host::add_level(SIMIX_host_destroy); + SURF_CPU_LEVEL = simgrid::Host::add_level(surf_cpu_free); + ROUTING_HOST_LEVEL = simgrid::Host::add_level(routing_asr_host_free); + USER_HOST_LEVEL = simgrid::Host::add_level(NULL); } + // ========== User data Layer ========== void *sg_host_user(sg_host_t host) { - return xbt_lib_get_level(host, USER_HOST_LEVEL); + return host->facet(USER_HOST_LEVEL); } void sg_host_user_set(sg_host_t host, void* userdata) { - xbt_lib_set(host_lib,host->key,USER_HOST_LEVEL,userdata); + host->set_facet(USER_HOST_LEVEL,userdata); } void sg_host_user_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,USER_HOST_LEVEL,1); + host->set_facet(USER_HOST_LEVEL, nullptr); } // ========== MSG Layer ============== msg_host_priv_t sg_host_msg(sg_host_t host) { - return (msg_host_priv_t) xbt_lib_get_level(host, MSG_HOST_LEVEL); + return (msg_host_priv_t) host->facet(MSG_HOST_LEVEL); } void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) { - xbt_lib_set(host_lib,host->key,MSG_HOST_LEVEL,smx_host); + host->set_facet(MSG_HOST_LEVEL, smx_host); } void sg_host_msg_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,MSG_HOST_LEVEL,1); + host->set_facet(MSG_HOST_LEVEL, nullptr); } // ========== SimDag Layer ============== SD_workstation_priv_t sg_host_sd(sg_host_t host) { - return (SD_workstation_priv_t) xbt_lib_get_level(host, SD_HOST_LEVEL); + return (SD_workstation_priv_t) host->facet(SD_HOST_LEVEL); } void sg_host_sd_set(sg_host_t host, SD_workstation_priv_t smx_host) { - xbt_lib_set(host_lib,host->key,SD_HOST_LEVEL,smx_host); + host->set_facet(SD_HOST_LEVEL, smx_host); } void sg_host_sd_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,SD_HOST_LEVEL,1); + host->set_facet(SD_HOST_LEVEL, nullptr); } // ========== Simix layer ============= smx_host_priv_t sg_host_simix(sg_host_t host){ - return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL); + return (smx_host_priv_t) host->facet(SIMIX_HOST_LEVEL); } void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) { - xbt_assert(xbt_lib_get_or_null(host_lib,host->key,SIMIX_HOST_LEVEL) == NULL); - xbt_lib_set(host_lib,host->key,SIMIX_HOST_LEVEL,smx_host); + host->set_facet(SIMIX_HOST_LEVEL, smx_host); } void sg_host_simix_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,SIMIX_HOST_LEVEL,1); + host->set_facet(SIMIX_HOST_LEVEL, nullptr); } // ========== SURF CPU ============ surf_cpu_t sg_host_surfcpu(sg_host_t host) { - return (surf_cpu_t) xbt_lib_get_level(host, SURF_CPU_LEVEL); + return (surf_cpu_t) host->facet(SURF_CPU_LEVEL); } void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { - xbt_lib_set(host_lib, host->key, SURF_CPU_LEVEL, cpu); + host->set_facet(SURF_CPU_LEVEL, cpu); } void sg_host_surfcpu_register(sg_host_t host, surf_cpu_t cpu) { @@ -124,20 +143,19 @@ void sg_host_surfcpu_register(sg_host_t host, surf_cpu_t cpu) sg_host_surfcpu_set(host, cpu); } void sg_host_surfcpu_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,SURF_CPU_LEVEL,1); + host->set_facet(SURF_CPU_LEVEL, nullptr); } // ========== RoutingEdge ============ surf_RoutingEdge *sg_host_edge(sg_host_t host) { - return (surf_RoutingEdge*) xbt_lib_get_level(host, ROUTING_HOST_LEVEL); + return (surf_RoutingEdge*) host->facet(ROUTING_HOST_LEVEL); } void sg_host_edge_set(sg_host_t host, surf_RoutingEdge *edge) { - xbt_lib_set(host_lib, host->key, ROUTING_HOST_LEVEL, edge); + host->set_facet(ROUTING_HOST_LEVEL, edge); } void sg_host_edge_destroy(sg_host_t host, int do_callback) { - xbt_lib_unset(host_lib,host->key,ROUTING_HOST_LEVEL,do_callback); + host->set_facet(ROUTING_HOST_LEVEL, nullptr, do_callback); } - // =========== user-level functions =============== // ================================================ double sg_host_get_speed(sg_host_t host){ @@ -181,3 +199,31 @@ int sg_host_get_nb_pstates(sg_host_t host) { int sg_host_get_pstate(sg_host_t host) { return surf_host_get_pstate(host); } + +namespace simgrid { + +Host::Host(std::string id) + : id_(std::move(id)) +{ +} + +Host::~Host() +{ +} + +Host* Host::find_host(const char* name) +{ + return (Host*) xbt_dict_get_or_null(host_list, name); +} + +Host* Host::get_host(const char* name) +{ + Host* host = find_host(name); + if (host == nullptr) { + host = new Host(name); + xbt_dict_set(host_list, name, host, NULL); + } + return host; +} + +} diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index 0182f32624..c20342408f 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -456,7 +456,7 @@ static void _sg_cfg_cb__surf_network_coordinates(const char *name, int val = xbt_cfg_get_boolean(_sg_cfg_set, name); if (val) { if (!already_set) { - COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp); + COORD_HOST_LEVEL = sg_host_add_level(xbt_dynar_free_voidp); COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp); } already_set = 1; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 363423b5f6..45f48f907c 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -367,9 +367,9 @@ smx_synchro_t SIMIX_process_parallel_execute(const char *name, /* FIXME: what happens if host_list contains VMs and PMs. If * execute_parallel_task() does not change the state of the model, we can mix * them. */ - surf_model_t ws_model = surf_resource_model(host_list[0], SURF_HOST_LEVEL); + surf_host_model_t ws_model = surf_host_get_model(host_list[0]); for (i = 1; i < host_nb; i++) { - surf_model_t ws_model_tmp = surf_resource_model(host_list[i], SURF_HOST_LEVEL); + surf_host_model_t ws_model_tmp = surf_host_get_model(host_list[0]); if (ws_model_tmp != ws_model) { XBT_CRITICAL("mixing VMs and PMs is not supported"); DIE_IMPOSSIBLE; diff --git a/src/simix/smx_vm.cpp b/src/simix/smx_vm.cpp index dae28e7b8f..6751a1b94d 100644 --- a/src/simix/smx_vm.cpp +++ b/src/simix/smx_vm.cpp @@ -61,7 +61,7 @@ static int __can_be_started(sg_host_t vm) } if (pm_overcommit) { - XBT_INFO("%s allows memory overcommit.", pm->key); + XBT_INFO("%s allows memory overcommit.", sg_host_get_name(pm)); return 1; } @@ -78,7 +78,8 @@ static int __can_be_started(sg_host_t vm) if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", - vm->key, pm->key, vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); + sg_host_get_name(vm), sg_host_get_name(pm), + vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); xbt_dynar_free(&dyn_vms); return 0; } diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 3850c8bc0c..955331aa57 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -53,7 +53,7 @@ Host *HostCLM03Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) netElm, cpu); surf_callback_emit(hostCreatedCallbacks, host); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); - xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host); + simgrid::Host::find_host(name)->set_facet(SURF_HOST_LEVEL, host); return host; } diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index e0ec337a7f..70b7c1ca84 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -125,7 +125,7 @@ public: Cpu *cpu); /** @brief Host destructor */ - ~ Host(); + ~Host(); void setState(e_surf_resource_state_t state); diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index d6d022a7d6..45148d9ccc 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -275,7 +275,7 @@ Host *HostL07Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) HostL07 *host = new HostL07(this, name, NULL, netElm, cpu); surf_callback_emit(hostCreatedCallbacks, host); - xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host); + simgrid::Host::get_host(name)->set_facet(SURF_HOST_LEVEL, host); return host; } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index fc3cb25fd9..40fbd0bef6 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -11,14 +11,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3); -extern xbt_lib_t host_lib; -extern xbt_lib_t as_router_lib; - -extern xbt_dict_t dict_socket; - xbt_dynar_t IPV4addr; static double time_to_next_flow_completion = -1; +extern xbt_dict_t dict_socket; + /************* * Callbacks * *************/ @@ -44,11 +41,7 @@ static void simgrid_ns3_add_host(simgrid::surf::Host* host) { const char* id = host->getName(); XBT_DEBUG("NS3_ADD_HOST '%s'", id); - xbt_lib_set(host_lib, - id, - NS3_HOST_LEVEL, - ns3_add_host(id) - ); + simgrid::Host::get_host(id)->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); } static void parse_ns3_add_link(sg_platf_link_cbarg_t link) @@ -115,11 +108,8 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); xbt_dynar_push_as(tab_elements_num, int, start); router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix); - xbt_lib_set(host_lib, - router_id, - NS3_HOST_LEVEL, - ns3_add_host_cluster(router_id) - ); + simgrid::Host::get_host(router_id) + ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); break; @@ -130,11 +120,8 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) for (i = start; i <= end; i++){ xbt_dynar_push_as(tab_elements_num, int, i); router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix); - xbt_lib_set(host_lib, - router_id, - NS3_HOST_LEVEL, - ns3_add_host_cluster(router_id) - ); + simgrid::Host::get_host(router_id) + ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); } @@ -159,8 +146,8 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) router_id = bprintf("ns3_%s%d%s", cluster_prefix, elmts, cluster_suffix); XBT_DEBUG("Create link from '%s' to '%s'",host_id,router_id); - ns3_nodes_t host_src = static_cast(xbt_lib_get_or_null(host_lib,host_id, NS3_HOST_LEVEL)); - ns3_nodes_t host_dst = static_cast(xbt_lib_get_or_null(host_lib,router_id,NS3_HOST_LEVEL)); + ns3_nodes_t host_src = ns3_find_host(host_id); + ns3_nodes_t host_dst = ns3_find_host(router_id); if(host_src && host_dst){} else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num); @@ -218,9 +205,9 @@ static void create_ns3_topology(void) XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->getName(), link_bdw, link_lat); //create link ns3 - ns3_nodes_t host_src = static_cast(xbt_lib_get_or_null(host_lib,src,NS3_HOST_LEVEL)); + ns3_nodes_t host_src = ns3_find_host(src); if(!host_src) host_src = static_cast(xbt_lib_get_or_null(as_router_lib,src,NS3_ASR_LEVEL)); - ns3_nodes_t host_dst = static_cast(xbt_lib_get_or_null(host_lib,dst,NS3_HOST_LEVEL)); + ns3_nodes_t host_dst = ns3_find_host(dst); if(!host_dst) host_dst = static_cast(xbt_lib_get_or_null(as_router_lib,dst,NS3_ASR_LEVEL)); if(host_src && host_dst){} @@ -284,8 +271,8 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel() { routing_model_create(NULL); define_callbacks_ns3(); - NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host); - NS3_ASR_LEVEL = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_host); + NS3_HOST_LEVEL = simgrid::Host::add_level(free_ns3_host); + NS3_ASR_LEVEL = xbt_lib_add_level(as_router_lib, free_ns3_host); } NetworkNS3Model::~NetworkNS3Model() { diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc index 0b9b1a3d10..bd9a5586f6 100644 --- a/src/surf/ns3/ns3_interface.cc +++ b/src/surf/ns3/ns3_interface.cc @@ -13,7 +13,6 @@ using namespace ns3; -extern xbt_lib_t host_lib; extern int NS3_HOST_LEVEL; //host node for ns3 extern xbt_dynar_t IPV4addr; @@ -59,8 +58,8 @@ double ns3_time(){ int ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,void * action) { - ns3_nodes_t node1 = (ns3_nodes_t) xbt_lib_get_or_null(host_lib,a,NS3_HOST_LEVEL); - ns3_nodes_t node2 = (ns3_nodes_t) xbt_lib_get_or_null(host_lib,b,NS3_HOST_LEVEL); + ns3_nodes_t node1 = ns3_find_host(a); + ns3_nodes_t node2 = ns3_find_host(b); Ptr src_node = nodes.Get(node1->node_num); Ptr dst_node = nodes.Get(node2->node_num); diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index 8aaf466df4..8043743bf2 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -12,6 +12,9 @@ #include "xbt/misc.h" #include "xbt/sysdep.h" +#include +#include + typedef enum { NS3_NETWORK_ELEMENT_NULL = 0, /* NULL */ NS3_NETWORK_ELEMENT_HOST, /* host type */ @@ -46,6 +49,16 @@ XBT_PUBLIC(void) ns3_add_link(int src, e_ns3_network_element_type_t type_src, XBT_PUBLIC(void) ns3_end_platform(void); XBT_PUBLIC(void) ns3_add_cluster(char * bw,char * lat,const char *id); +XBT_INLINE +ns3_nodes_t ns3_find_host(const char* id) +{ + sg_host_t host = sg_host_by_name(id); + if (host == nullptr) + return nullptr; + else + return (ns3_nodes_t) sg_host_get_facet(host, NS3_HOST_LEVEL); +} + SG_END_DECL() #endif diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index ac3baae876..9ee5be13f2 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -18,11 +18,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); * TOOLS * *********/ -static simgrid::surf::Host *get_casted_host(surf_resource_t resource){ +static simgrid::surf::Host *get_casted_host(sg_host_t resource){ return static_cast(surf_host_resource_priv(resource)); } -static simgrid::surf::VirtualMachine *get_casted_vm(surf_resource_t resource){ +static simgrid::surf::VirtualMachine *get_casted_vm(sg_host_t resource){ return static_cast(surf_host_resource_priv(resource)); } @@ -168,12 +168,11 @@ void routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst, * MODEL * *********/ -surf_model_t surf_resource_model(const void *host, int level) { - /* If level is SURF_WKS_LEVEL, ws is a host_CLM03 object. It has - * surf_resource at the generic_resource field. */ - simgrid::surf::Resource *ws = static_cast( - xbt_lib_get_level((xbt_dictelm_t) host, level)); - return ws->getModel(); +surf_host_model_t surf_host_get_model(sg_host_t host) +{ + simgrid::surf::Host* surf_host = + (simgrid::surf::Host*) host->facet(SURF_HOST_LEVEL); + return (surf_host_model_t) surf_host->getModel(); } surf_action_t surf_model_extract_done_action_set(surf_model_t model){ @@ -223,7 +222,7 @@ surf_action_t surf_host_model_execute_parallel_task(surf_host_model_t model, } xbt_dynar_t surf_host_model_get_route(surf_host_model_t /*model*/, - surf_resource_t src, surf_resource_t dst){ + sg_host_t src, sg_host_t dst){ xbt_dynar_t route = NULL; routing_platf->getRouteAndLatency( get_casted_host(src)->p_netElm, @@ -231,7 +230,7 @@ xbt_dynar_t surf_host_model_get_route(surf_host_model_t /*model*/, return route; } -void surf_vm_model_create(const char *name, surf_resource_t ind_phys_host){ +void surf_vm_model_create(const char *name, sg_host_t ind_phys_host){ surf_vm_model->createVM(name, ind_phys_host); } @@ -255,184 +254,184 @@ void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state resource->setState(state); } -surf_action_t surf_host_sleep(surf_resource_t host, double duration){ +surf_action_t surf_host_sleep(sg_host_t host, double duration){ return get_casted_host(host)->sleep(duration); } -double surf_host_get_speed(surf_resource_t host, double load){ +double surf_host_get_speed(sg_host_t host, double load){ return sg_host_surfcpu(host)->getSpeed(load); } -double surf_host_get_available_speed(surf_resource_t host){ +double surf_host_get_available_speed(sg_host_t host){ return sg_host_surfcpu(host)->getAvailableSpeed(); } -int surf_host_get_core(surf_resource_t host){ +int surf_host_get_core(sg_host_t host){ return sg_host_surfcpu(host)->getCore(); } -surf_action_t surf_host_execute(surf_resource_t host, double size){ +surf_action_t surf_host_execute(sg_host_t host, double size){ return get_casted_host(host)->execute(size); } -double surf_host_get_current_power_peak(surf_resource_t host){ +double surf_host_get_current_power_peak(sg_host_t host){ return sg_host_surfcpu(host)->getCurrentPowerPeak(); } -double surf_host_get_power_peak_at(surf_resource_t host, int pstate_index){ +double surf_host_get_power_peak_at(sg_host_t host, int pstate_index){ return sg_host_surfcpu(host)->getPowerPeakAt(pstate_index); } -int surf_host_get_nb_pstates(surf_resource_t host){ +int surf_host_get_nb_pstates(sg_host_t host){ return sg_host_surfcpu(host)->getNbPstates(); } -void surf_host_set_pstate(surf_resource_t host, int pstate_index){ +void surf_host_set_pstate(sg_host_t host, int pstate_index){ sg_host_surfcpu(host)->setPstate(pstate_index); } -int surf_host_get_pstate(surf_resource_t host){ +int surf_host_get_pstate(sg_host_t host){ return sg_host_surfcpu(host)->getPstate(); } using simgrid::energy::HostEnergy; using simgrid::energy::surf_energy; -double surf_host_get_wattmin_at(surf_resource_t resource, int pstate){ +double surf_host_get_wattmin_at(sg_host_t resource, int pstate){ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization."); std::map::iterator hostIt = surf_energy->find(get_casted_host(resource)); return hostIt->second->getWattMinAt(pstate); } -double surf_host_get_wattmax_at(surf_resource_t resource, int pstate){ +double surf_host_get_wattmax_at(sg_host_t resource, int pstate){ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization."); std::map::iterator hostIt = surf_energy->find(get_casted_host(resource)); return hostIt->second->getWattMaxAt(pstate); } -double surf_host_get_consumed_energy(surf_resource_t resource){ +double surf_host_get_consumed_energy(sg_host_t resource){ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization."); std::map::iterator hostIt = surf_energy->find(get_casted_host(resource)); return hostIt->second->getConsumedEnergy(); } -xbt_dict_t surf_host_get_mounted_storage_list(surf_resource_t host){ +xbt_dict_t surf_host_get_mounted_storage_list(sg_host_t host){ return get_casted_host(host)->getMountedStorageList(); } -xbt_dynar_t surf_host_get_attached_storage_list(surf_resource_t host){ +xbt_dynar_t surf_host_get_attached_storage_list(sg_host_t host){ return get_casted_host(host)->getAttachedStorageList(); } -surf_action_t surf_host_open(surf_resource_t host, const char* fullpath){ +surf_action_t surf_host_open(sg_host_t host, const char* fullpath){ return get_casted_host(host)->open(fullpath); } -surf_action_t surf_host_close(surf_resource_t host, surf_file_t fd){ +surf_action_t surf_host_close(sg_host_t host, surf_file_t fd){ return get_casted_host(host)->close(fd); } -int surf_host_unlink(surf_resource_t host, surf_file_t fd){ +int surf_host_unlink(sg_host_t host, surf_file_t fd){ return get_casted_host(host)->unlink(fd); } -size_t surf_host_get_size(surf_resource_t host, surf_file_t fd){ +size_t surf_host_get_size(sg_host_t host, surf_file_t fd){ return get_casted_host(host)->getSize(fd); } -surf_action_t surf_host_read(surf_resource_t host, surf_file_t fd, sg_size_t size){ +surf_action_t surf_host_read(sg_host_t host, surf_file_t fd, sg_size_t size){ return get_casted_host(host)->read(fd, size); } -surf_action_t surf_host_write(surf_resource_t host, surf_file_t fd, sg_size_t size){ +surf_action_t surf_host_write(sg_host_t host, surf_file_t fd, sg_size_t size){ return get_casted_host(host)->write(fd, size); } -xbt_dynar_t surf_host_get_info(surf_resource_t host, surf_file_t fd){ +xbt_dynar_t surf_host_get_info(sg_host_t host, surf_file_t fd){ return get_casted_host(host)->getInfo(fd); } -size_t surf_host_file_tell(surf_resource_t host, surf_file_t fd){ +size_t surf_host_file_tell(sg_host_t host, surf_file_t fd){ return get_casted_host(host)->fileTell(fd); } -int surf_host_file_seek(surf_resource_t host, surf_file_t fd, +int surf_host_file_seek(sg_host_t host, surf_file_t fd, sg_offset_t offset, int origin){ return get_casted_host(host)->fileSeek(fd, offset, origin); } -int surf_host_file_move(surf_resource_t host, surf_file_t fd, const char* fullpath){ +int surf_host_file_move(sg_host_t host, surf_file_t fd, const char* fullpath){ return get_casted_host(host)->fileMove(fd, fullpath); } -xbt_dynar_t surf_host_get_vms(surf_resource_t host){ +xbt_dynar_t surf_host_get_vms(sg_host_t host){ xbt_dynar_t vms = get_casted_host(host)->getVms(); xbt_dynar_t vms_ = xbt_dynar_new(sizeof(sg_host_t), NULL); unsigned int cpt; simgrid::surf::VirtualMachine *vm; xbt_dynar_foreach(vms, cpt, vm) { - sg_host_t vm_ = xbt_lib_get_elm_or_null(host_lib, vm->getName()); + // TODO, use a backlink from simgrid::surf::Host to simgrid::Host + sg_host_t vm_ = (sg_host_t) xbt_dict_get_elm_or_null(host_list, vm->getName()); xbt_dynar_push(vms_, &vm_); } xbt_dynar_free(&vms); return vms_; } -void surf_host_get_params(surf_resource_t host, vm_params_t params){ +void surf_host_get_params(sg_host_t host, vm_params_t params){ get_casted_host(host)->getParams(params); } -void surf_host_set_params(surf_resource_t host, vm_params_t params){ +void surf_host_set_params(sg_host_t host, vm_params_t params){ get_casted_host(host)->setParams(params); } -void surf_vm_destroy(surf_resource_t resource){ +void surf_vm_destroy(sg_host_t resource){ /* Before clearing the entries in host_lib, we have to pick up resources. */ - simgrid::surf::VirtualMachine *vm = get_casted_vm(resource); - char* name = xbt_dict_get_elm_key(resource); + const char* name = resource->id().c_str(); /* We deregister objects from host_lib, without invoking the freeing callback * of each level. * * Do not call xbt_lib_remove() here. It deletes all levels of the key, * including MSG_HOST_LEVEL and others. We should unregister only what we know. */ - sg_host_surfcpu_destroy((sg_host_t)resource); - sg_host_edge_destroy((sg_host_t)resource,1); - xbt_lib_unset(host_lib, name, SURF_HOST_LEVEL, 0); + sg_host_surfcpu_destroy(resource); + sg_host_edge_destroy(resource,1); + // TODO, use backlink from simgrid::surf::Host to simgrid::Host + simgrid::Host* host = (simgrid::Host*) xbt_dict_get_or_null(host_list, name); + host->set_facet(SURF_HOST_LEVEL, nullptr); /* TODO: comment out when VM storage is implemented. */ - // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); - - delete vm; + // host->set_facet(SURF_STORAGE_LEVEL, nullptr); } -void surf_vm_suspend(surf_resource_t vm){ +void surf_vm_suspend(sg_host_t vm){ get_casted_vm(vm)->suspend(); } -void surf_vm_resume(surf_resource_t vm){ +void surf_vm_resume(sg_host_t vm){ get_casted_vm(vm)->resume(); } -void surf_vm_save(surf_resource_t vm){ +void surf_vm_save(sg_host_t vm){ get_casted_vm(vm)->save(); } -void surf_vm_restore(surf_resource_t vm){ +void surf_vm_restore(sg_host_t vm){ get_casted_vm(vm)->restore(); } -void surf_vm_migrate(surf_resource_t vm, surf_resource_t ind_vm_ws_dest){ +void surf_vm_migrate(sg_host_t vm, sg_host_t ind_vm_ws_dest){ get_casted_vm(vm)->migrate(ind_vm_ws_dest); } -surf_resource_t surf_vm_get_pm(surf_resource_t vm){ +sg_host_t surf_vm_get_pm(sg_host_t vm){ return get_casted_vm(vm)->getPm(); } -void surf_vm_set_bound(surf_resource_t vm, double bound){ +void surf_vm_set_bound(sg_host_t vm, double bound){ return get_casted_vm(vm)->setBound(bound); } -void surf_vm_set_affinity(surf_resource_t vm, surf_resource_t cpu, unsigned long mask){ +void surf_vm_set_affinity(sg_host_t vm, sg_host_t cpu, unsigned long mask){ return get_casted_vm(vm)->setAffinity(sg_host_surfcpu(cpu), mask); } @@ -456,11 +455,11 @@ const char* surf_storage_get_host(surf_resource_t resource){ return static_cast(surf_storage_resource_priv(resource))->p_attach; } -surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){ +surf_action_t surf_cpu_execute(sg_host_t cpu, double size){ return sg_host_surfcpu(cpu)->execute(size); } -surf_action_t surf_cpu_sleep(surf_resource_t cpu, double duration){ +surf_action_t surf_cpu_sleep(sg_host_t cpu, double duration){ return sg_host_surfcpu(cpu)->sleep(duration); } @@ -516,7 +515,7 @@ double surf_action_get_cost(surf_action_t action){ return action->getCost(); } -void surf_cpu_action_set_affinity(surf_action_t action, surf_resource_t cpu, unsigned long mask) { +void surf_cpu_action_set_affinity(surf_action_t action, sg_host_t cpu, unsigned long mask) { static_cast(action)->setAffinity(sg_host_surfcpu(cpu), mask); } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index adf270b04d..e5cee4109a 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -306,7 +306,9 @@ void sg_version(int *ver_major,int *ver_minor,int *ver_patch) { void surf_init(int *argc, char **argv) { XBT_DEBUG("Create all Libs"); - host_lib = xbt_lib_new(); + host_list = xbt_dict_new_homogeneous([](void*p) { + delete (simgrid::Host*)p; + }); as_router_lib = xbt_lib_new(); storage_lib = xbt_lib_new(); storage_type_lib = xbt_lib_new(); @@ -319,7 +321,7 @@ void surf_init(int *argc, char **argv) ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free); XBT_DEBUG("Add SURF levels"); - SURF_HOST_LEVEL = xbt_lib_add_level(host_lib,surf_host_free); + SURF_HOST_LEVEL = simgrid::Host::add_level(surf_host_free); SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free); xbt_init(argc, argv); @@ -352,7 +354,7 @@ void surf_exit(void) xbt_dynar_free(&host_that_restart); xbt_dynar_free(&surf_path); - xbt_lib_free(&host_lib); + xbt_dict_free(&host_list); xbt_lib_free(&as_router_lib); xbt_lib_free(&storage_lib); sg_link_exit(); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index d71fe5db92..433de56176 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -33,7 +33,7 @@ surf_callback(void, simgrid::surf::As*) asCreatedCallbacks; * @ingroup SURF_build_api * @brief A library containing all known hosts */ -xbt_lib_t host_lib; +xbt_dict_t host_list; int SURF_HOST_LEVEL; //Surf host level int COORD_HOST_LEVEL=0; //Coordinates level @@ -196,7 +196,7 @@ simgrid::surf::RoutingEdge *routing_add_host( } xbt_dynar_shrink(ctn, 0); xbt_dynar_free(&ctn_str); - xbt_lib_set(host_lib, host->id, COORD_HOST_LEVEL, (void *) ctn); + simgrid::Host::get_host(host->id)->set_facet(COORD_HOST_LEVEL, (void *) ctn); XBT_DEBUG("Having set host coordinates for '%s'",host->id); } @@ -1334,14 +1334,12 @@ const char *surf_AS_get_model(simgrid::surf::As *as) xbt_dynar_t surf_AS_get_hosts(simgrid::surf::As *as) { xbt_dynar_t elms = as->p_indexNetworkElm; - sg_routing_edge_t relm; - xbt_dictelm_t delm; - int index; int count = xbt_dynar_length(elms); - xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_dictelm_t), NULL); - for (index = 0; index < count; index++) { - relm = xbt_dynar_get_as(elms, index, simgrid::surf::RoutingEdge*); - delm = xbt_lib_get_elm_or_null(host_lib, relm->getName()); + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), NULL); + for (int index = 0; index < count; index++) { + sg_routing_edge_t relm = + xbt_dynar_get_as(elms, index, simgrid::surf::RoutingEdge*); + sg_host_t delm = simgrid::Host::find_host(relm->getName()); if (delm!=NULL) { xbt_dynar_push(res, &delm); } diff --git a/src/surf/surf_routing_vivaldi.cpp b/src/surf/surf_routing_vivaldi.cpp index b0ae9c2ea6..315369c432 100644 --- a/src/surf/surf_routing_vivaldi.cpp +++ b/src/surf/surf_routing_vivaldi.cpp @@ -57,8 +57,9 @@ void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_ *lat += static_cast(info.link_up)->getLatency(); } } - src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, tmp_src_name, COORD_HOST_LEVEL); - if(!src_ctn ) src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, src->getName(), COORD_HOST_LEVEL); + src_ctn = (xbt_dynar_t) simgrid::Host::get_host(tmp_src_name)->facet(COORD_HOST_LEVEL); + if (src_ctn == nullptr) + src_ctn = (xbt_dynar_t) simgrid::Host::get_host(src->getName())->facet(COORD_HOST_LEVEL); } else if(src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_AS){ tmp_src_name = ROUTER_PEER(src->getName()); @@ -79,8 +80,11 @@ void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_ *lat += static_cast(info.link_down)->getLatency(); } } - dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, tmp_dst_name, COORD_HOST_LEVEL); - if(!dst_ctn ) dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, dst->getName(), COORD_HOST_LEVEL); + dst_ctn = (xbt_dynar_t) simgrid::Host::get_host(tmp_dst_name) + ->facet(COORD_HOST_LEVEL); + if (dst_ctn == nullptr) + dst_ctn = (xbt_dynar_t) simgrid::Host::get_host(dst->getName()) + ->facet(COORD_HOST_LEVEL); } else if(dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || dst->getRcType() == SURF_NETWORK_ELEMENT_AS){ tmp_dst_name = ROUTER_PEER(dst->getName()); diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 8b5946ecb6..eaac5bb22c 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -38,8 +38,7 @@ VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, : Host(model, name, props, NULL, netElm, cpu) { VMModel::ws_vms.push_back(*this); - - xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, this); + simgrid::Host::get_host(name)->set_facet(SURF_HOST_LEVEL, this); } /* @@ -61,9 +60,9 @@ void VirtualMachine::setState(e_surf_resource_state_t state){ * A surf level object will be useless in the upper layer. Returning the * dict_elm of the host. **/ -surf_resource_t VirtualMachine::getPm() +sg_host_t VirtualMachine::getPm() { - return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName()); + return simgrid::Host::find_host(p_subWs->getName()); } /********** diff --git a/src/surf/virtual_machine.hpp b/src/surf/virtual_machine.hpp index 795ae2ef8e..a7d99e458a 100644 --- a/src/surf/virtual_machine.hpp +++ b/src/surf/virtual_machine.hpp @@ -83,10 +83,10 @@ public: virtual void restore()=0; /** @brief Migrate the VM to the destination host */ - virtual void migrate(surf_resource_t dest_PM)=0; + virtual void migrate(sg_host_t dest_PM)=0; /** @brief Get the physical machine hosting the VM */ - virtual surf_resource_t getPm()=0; + virtual sg_host_t getPm()=0; virtual void setBound(double bound)=0; virtual void setAffinity(Cpu *cpu, unsigned long mask)=0; @@ -120,7 +120,7 @@ public: * @param host_PM The real machine hosting the VM * */ - virtual VirtualMachine *createVM(const char *name, surf_resource_t host_PM)=0; + virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0; void adjustWeightOfDummyCpuActions() {}; typedef boost::intrusive::member_hook< diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 295421bbdf..c2ff00aac2 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -33,7 +33,7 @@ void VMHL13Model::updateActionsState(double /*now*/, double /*delta*/) {} /* ind means ''indirect'' that this is a reference on the whole dict_elm * structure (i.e not on the surf_resource_private infos) */ -VirtualMachine *VMHL13Model::createVM(const char *name, surf_resource_t host_PM) +VirtualMachine *VMHL13Model::createVM(const char *name, sg_host_t host_PM) { VirtualMachine* vm = new VMHL13(this, name, NULL, host_PM); surf_callback_emit(VMCreatedCallbacks, vm); @@ -163,7 +163,7 @@ Action *VMHL13Model::executeParallelTask(int host_nb, ************/ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, - surf_resource_t host_PM) + sg_host_t host_PM) : VirtualMachine(model, name, props, NULL, NULL) { Host *sub_ws = surf_host_resource_priv(host_PM); @@ -269,7 +269,7 @@ void VMHL13::restore() /* * Update the physical host of the given VM */ -void VMHL13::migrate(surf_resource_t ind_dst_pm) +void VMHL13::migrate(sg_host_t ind_dst_pm) { /* ind_dst_pm equals to smx_host_t */ Host *ws_dst = static_cast(surf_host_resource_priv(ind_dst_pm)); @@ -335,9 +335,10 @@ void VMHL13::setAffinity(Cpu *cpu, unsigned long mask){ * A surf level object will be useless in the upper layer. Returning the * dict_elm of the host. **/ -surf_resource_t VMHL13::getPm() +sg_host_t VMHL13::getPm() { - return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName()); + // TODO, store pointer to the PM? + return simgrid::Host::find_host(p_subWs->getName()); } /* Adding a task to a VM updates the VCPU task on its physical machine. */ diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index 411620d99b..ca0f38026a 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -33,15 +33,15 @@ public: VMHL13Model(); ~VMHL13Model(){}; - VirtualMachine *createVM(const char *name, surf_resource_t host_PM); + VirtualMachine *createVM(const char *name, sg_host_t host_PM) override; double shareResources(double now); - void adjustWeightOfDummyCpuActions() {}; + void adjustWeightOfDummyCpuActions() override {}; Action *executeParallelTask(int host_nb, sg_host_t *host_list, double *flops_amount, double *bytes_amount, - double rate); - void updateActionsState(double /*now*/, double /*delta*/); + double rate) override; + void updateActionsState(double /*now*/, double /*delta*/) override; }; /************ @@ -50,7 +50,7 @@ public: class VMHL13 : public VirtualMachine { public: - VMHL13(VMModel *model, const char* name, xbt_dict_t props, surf_resource_t host_PM); + VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t host_PM); ~VMHL13(); void suspend(); @@ -59,12 +59,12 @@ public: void save(); void restore(); - void migrate(surf_resource_t ind_dst_pm); + void migrate(sg_host_t ind_dst_pm); e_surf_resource_state_t getState(); void setState(e_surf_resource_state_t state); - surf_resource_t getPm(); // will be vm_ws_get_pm() + sg_host_t getPm(); // will be vm_ws_get_pm() void setBound(double bound); void setAffinity(Cpu *cpu, unsigned long mask); diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index 3115c3f701..ad49f948b8 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -190,18 +190,18 @@ int main(int argc, char **argv) } } - - xbt_lib_foreach(host_lib, cursor_src, src, value1) // Routes from host + sg_host_t host1, host2; + xbt_dict_foreach(host_list, cursor_src, src, host1) // Routes from host { value1 = sg_host_edge(sg_host_by_name(src)); - xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host + xbt_dict_foreach(host_list, cursor_dst, dst, host2) //to host { printf(" \n " ,src ,dst); xbt_dynar_t route=NULL; value2 = sg_host_edge(sg_host_by_name(dst)); - routing_get_route_and_latency(value1,value2,&route,NULL); + routing_get_route_and_latency(value1, value2, &route,NULL); for(i=0;i\n"); } } - xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host + xbt_dict_foreach(host_list, cursor_dst, dst, value2) //to host { printf(" \n " ,src, dst); diff --git a/teshsuite/simdag/platforms/is_router_test.c b/teshsuite/simdag/platforms/is_router_test.c index 49d05ceeef..9d87429944 100644 --- a/teshsuite/simdag/platforms/is_router_test.c +++ b/teshsuite/simdag/platforms/is_router_test.c @@ -27,12 +27,12 @@ int main(int argc, char **argv) /* creation of the environment */ SD_create_environment(argv[1]); - size = xbt_lib_length(host_lib) + xbt_lib_length(as_router_lib); + size = xbt_dict_length(host_list) + xbt_lib_length(as_router_lib); printf("Workstation number: %d, link number: %d, elmts number: %d\n", SD_workstation_get_number(), SD_link_get_number(), size); - xbt_lib_foreach(host_lib, cursor, key, data) { + xbt_dict_foreach(host_list, cursor, key, data) { printf(" - Seen: \"%s\" is type : %d\n", key, (int) routing_get_network_element_type(key)); } -- 2.20.1