From 4775ee0f232bccc4978dfbfb8153b7593be7dd77 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 1 Aug 2017 15:42:36 +0200 Subject: [PATCH] properties are now stored in maps and managed by ProperyHolder everywhere! --- .../trace-masterworker.tesh | 8 ++-- include/simgrid/msg.h | 32 +++++-------- include/simgrid/s4u/Host.hpp | 5 ++- include/simgrid/s4u/Storage.hpp | 2 +- include/simgrid/simix.h | 14 +++--- include/simgrid/simix.hpp | 25 ++++++----- src/include/surf/surf.h | 4 -- src/kernel/routing/NetZoneImpl.cpp | 4 +- src/kernel/routing/NetZoneImpl.hpp | 2 +- src/msg/msg_host.cpp | 2 +- src/msg/msg_io.cpp | 2 +- src/msg/msg_private.h | 2 +- src/msg/msg_process.cpp | 36 ++++++++++++--- src/s4u/s4u_actor.cpp | 6 +-- src/s4u/s4u_host.cpp | 8 ++-- src/s4u/s4u_storage.cpp | 2 +- src/simgrid/host.cpp | 4 +- src/simix/ActorImpl.cpp | 30 +++++++------ src/simix/ActorImpl.hpp | 17 +++---- src/simix/libsmx.cpp | 10 ----- src/simix/smx_host.cpp | 6 +-- src/simix/smx_host_private.h | 13 +++--- src/surf/PropertyHolder.cpp | 11 +++-- src/surf/PropertyHolder.hpp | 10 ++--- src/surf/StorageImpl.hpp | 4 +- src/surf/sg_platf.cpp | 45 +++++++------------ src/surf/surf_interface.cpp | 2 +- src/surf/xml/platf_private.hpp | 14 +++--- src/surf/xml/surfxml_sax_cb.cpp | 22 ++++----- .../storage_client_server.cpp | 2 +- .../basic-parsing-test.tesh | 4 +- 31 files changed, 159 insertions(+), 189 deletions(-) diff --git a/examples/msg/trace-masterworker/trace-masterworker.tesh b/examples/msg/trace-masterworker/trace-masterworker.tesh index 5e639c62c7..7690bfe874 100644 --- a/examples/msg/trace-masterworker/trace-masterworker.tesh +++ b/examples/msg/trace-masterworker/trace-masterworker.tesh @@ -19,13 +19,13 @@ $ $SG_TEST_EXENV ${bindir:=.}/trace-masterworker$EXEEXT --cfg=tracing:yes --cfg= p Tracing master/worker application with xml config $ $SG_TEST_EXENV ${bindir:=.}/trace-masterworker$EXEEXT ${srcdir:=.}/config_tracing.xml ${srcdir:=.}/../msg/app-masterworker/app-masterworker_d.xml -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to 'yes' -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/buffer' to 'yes' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to 'yes' -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'viva/categorized' to 'trace-masterworker.cat.plist' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/buffer' to 'yes' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to 'yes' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/filename' to 'trace-masterworker.trace' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to 'yes' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'viva/categorized' to 'trace-masterworker.cat.plist' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'viva/uncategorized' to 'trace-masterworker.uncat.plist' -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to 'yes' > [4.214821] [msg_trace_masterworker/INFO] Declared tracing categories: > [4.214821] [msg_trace_masterworker/INFO] request > [4.214821] [msg_trace_masterworker/INFO] finalize diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index e13be7ce3b..1f9c363a7e 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -17,6 +17,7 @@ #ifdef __cplusplus #include "simgrid/simix.h" +#include namespace simgrid { namespace msg { class Comm; @@ -377,36 +378,26 @@ XBT_PUBLIC(void) MSG_task_set_bound(msg_task_t task, double bound); XBT_PUBLIC(msg_error_t) MSG_process_join(msg_process_t process, double timeout); XBT_PUBLIC(msg_error_t) MSG_process_sleep(double nb_sec); -XBT_PUBLIC(void) MSG_task_set_flops_amount(msg_task_t task, - double flops_amount); +XBT_PUBLIC(void) MSG_task_set_flops_amount(msg_task_t task, double flops_amount); XBT_PUBLIC(double) MSG_task_get_flops_amount(msg_task_t task); -XBT_PUBLIC(void) MSG_task_set_bytes_amount(msg_task_t task, - double bytes_amount); +XBT_PUBLIC(void) MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount); XBT_PUBLIC(double) MSG_task_get_remaining_communication(msg_task_t task); XBT_PUBLIC(int) MSG_task_is_latency_bounded(msg_task_t task); XBT_PUBLIC(double) MSG_task_get_bytes_amount(msg_task_t task); +XBT_PUBLIC(msg_error_t) MSG_task_receive_ext(msg_task_t* task, const char* alias, double timeout, msg_host_t host); -XBT_PUBLIC(msg_error_t) - MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout, - msg_host_t host); - -XBT_PUBLIC(msg_error_t) - MSG_task_receive_with_timeout(msg_task_t * task, const char *alias, - double timeout); +XBT_PUBLIC(msg_error_t) MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout); -XBT_PUBLIC(msg_error_t) - MSG_task_receive(msg_task_t * task, const char *alias); +XBT_PUBLIC(msg_error_t) MSG_task_receive(msg_task_t* task, const char* alias); #define MSG_task_recv(t,a) MSG_task_receive(t,a) - - XBT_PUBLIC(msg_error_t) - MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout, - msg_host_t host, double rate); +MSG_task_receive_ext_bounded(msg_task_t* task, const char* alias, double timeout, msg_host_t host, double rate); -XBT_PUBLIC(msg_error_t) MSG_task_receive_with_timeout_bounded(msg_task_t * task, const char *alias, double timeout, double rate); +XBT_PUBLIC(msg_error_t) +MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* alias, double timeout, double rate); XBT_PUBLIC(msg_error_t) MSG_task_receive_bounded(msg_task_t * task, const char *alias,double rate); #define MSG_task_recv_bounded(t,a,r) MSG_task_receive_bounded(t,a,r) @@ -517,24 +508,21 @@ XBT_PUBLIC(void) MSG_vm_resume(msg_vm_t vm); XBT_PUBLIC(msg_host_t) MSG_vm_get_pm(msg_vm_t vm); XBT_PUBLIC(void) MSG_vm_set_bound(msg_vm_t vm, double bound); - #include "simgrid/instr.h" /* ****************************************************************************************** */ /* Used only by the bindings -- unclean pimple, please ignore if you're not writing a binding */ XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(msg_process_t process); - /* Functions renamed in 3.14 */ #define MSG_mailbox_get_head(m) MSG_mailbox_front(m) - SG_END_DECL() #ifdef __cplusplus XBT_PUBLIC(msg_process_t) MSG_process_create_from_stdfunc(const char* name, std::function code, void* data, msg_host_t host, - xbt_dict_t properties); + std::map* properties); #endif #endif diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 33f9710ca2..3c8691e4eb 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_S4U_HOST_HPP #define SIMGRID_S4U_HOST_HPP +#include #include #include @@ -86,9 +87,9 @@ public: double getSpeed(); int getCoreCount(); - std::unordered_map* getProperties(); + std::map* getProperties(); const char* getProperty(const char* key); - void setProperty(const char* key, const char* value); + void setProperty(std::string key, std::string value); void getProcesses(std::vector * list); double getPstateSpeed(int pstate_index); int getPstatesCount() const; diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index e3b1d90354..38e30b7e49 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -36,7 +36,7 @@ public: sg_size_t getSizeFree(); sg_size_t getSizeUsed(); - std::unordered_map* getProperties(); + std::map* getProperties(); const char* getProperty(const char* key); void setProperty(const char* key, const char* value); std::map* getContent(); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index e5886a3907..44e263529b 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -11,7 +11,7 @@ #include "simgrid/host.h" #include "xbt/ex.h" #include "xbt/parmap.h" - +#include /* ******************************** Host ************************************ */ /** @brief Host datatype @ingroup simix_host_management @@ -140,12 +140,9 @@ XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host, */ XBT_PUBLIC(void) SIMIX_maestro_create(void (*code)(void*), void* data); -XBT_PUBLIC(smx_actor_t) SIMIX_process_attach( - const char* name, - void *data, - const char* hostname, - xbt_dict_t properties, - smx_actor_t parent_process); +XBT_PUBLIC(smx_actor_t) +SIMIX_process_attach(const char* name, void* data, const char* hostname, std::map* properties, + smx_actor_t parent_process); XBT_PUBLIC(void) SIMIX_process_detach(); /*********************************** Host *************************************/ @@ -202,7 +199,7 @@ SG_BEGIN_DECL() /* Constructor and Destructor */ XBT_PUBLIC(smx_actor_t) simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc, char** argv, - xbt_dict_t properties); + std::map* properties); XBT_PUBLIC(void) simcall_process_kill(smx_actor_t process); XBT_PUBLIC(void) simcall_process_killall(int reset_pid); @@ -216,7 +213,6 @@ XBT_PUBLIC(void) simcall_process_suspend(smx_actor_t process); /* Getters and Setters */ XBT_PUBLIC(int) simcall_process_count(); XBT_PUBLIC(void) simcall_process_set_data(smx_actor_t process, void *data); -XBT_PUBLIC(xbt_dict_t) simcall_process_get_properties(smx_actor_t host); XBT_PUBLIC(void) simcall_process_set_kill_time(smx_actor_t process, double kill_time); XBT_PUBLIC(void) simcall_process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void *data); XBT_PUBLIC(void) simcall_process_join(smx_actor_t process, double timeout); diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 7e0e9e3cd5..eb7e26b88a 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -7,12 +7,13 @@ #ifndef SIMGRID_SIMIX_HPP #define SIMGRID_SIMIX_HPP -//#include -#include +#include #include +#include #include -#include +#include +#include XBT_PUBLIC(void) simcall_run_kernel(std::function const& code); @@ -97,21 +98,21 @@ extern simgrid::xbt::signal onDeadlock; * void *data: data a pointer to any data one may want to attach to the new object. * sg_host_t host: the location where the new process is executed * int argc, char **argv: parameters passed to code - * xbt_dict_t pros: properties + * std::map* props: properties */ -typedef smx_actor_t (*smx_creation_func_t) ( - /* name */ const char*, - std::function code, - /* userdata */ void*, - /* hostname */ sg_host_t, - /* props */ xbt_dict_t, - /* parent_process */ smx_actor_t); +typedef smx_actor_t (*smx_creation_func_t)( + /* name */ const char*, std::function code, + /* userdata */ void*, + /* hostname */ sg_host_t, + /* props */ std::map*, + /* parent_process */ smx_actor_t); extern "C" XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function); XBT_PUBLIC(smx_actor_t) -simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, xbt_dict_t properties); +simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, + std::map* properties); XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, simgrid::xbt::Task callback); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 173dcf4759..f1f3ce2eb2 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -17,7 +17,6 @@ #include "simgrid/datatypes.h" #include "simgrid/forward.h" - #ifdef __cplusplus namespace simgrid { @@ -423,9 +422,6 @@ XBT_PUBLIC(double) surf_get_clock(); */ XBT_PUBLIC(void) surf_exit(); -/* Prototypes of the functions that handle the properties */ -XBT_PUBLIC_DATA(xbt_dict_t) current_property_set;// the prop set for the currently parsed element (also used in SIMIX) - /* surf parse file related (public because called from a test suite) */ XBT_PUBLIC(void) parse_platform_file(const char *file); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 30b275062c..5f846b1017 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -43,7 +43,7 @@ NetZoneImpl::~NetZoneImpl() } simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vector* speedPerPstate, int coreAmount, - std::unordered_map* props) + std::map* props) { simgrid::s4u::Host* res = new simgrid::s4u::Host(name); @@ -56,7 +56,7 @@ simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vectorsetProperty(kv.first.c_str(), kv.second.c_str()); + res->setProperty(kv.first, kv.second); simgrid::s4u::Host::onCreation(*res); // notify the signal diff --git a/src/kernel/routing/NetZoneImpl.hpp b/src/kernel/routing/NetZoneImpl.hpp index fe97e732e2..e4a297caf7 100644 --- a/src/kernel/routing/NetZoneImpl.hpp +++ b/src/kernel/routing/NetZoneImpl.hpp @@ -59,7 +59,7 @@ protected: public: /** @brief Make an host within that NetZone */ simgrid::s4u::Host* createHost(const char* name, std::vector* speedPerPstate, int coreAmount, - std::unordered_map* props); + std::map* props); /** @brief Creates a new route in this NetZone */ void addBypassRoute(sg_platf_route_cbarg_t e_route) override; diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index 82a9ad772f..cea2d8af1f 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -166,7 +166,7 @@ xbt_dict_t MSG_host_get_properties(msg_host_t host) { xbt_assert((host != nullptr), "Invalid parameters (host is nullptr)"); xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); - std::unordered_map* props = host->getProperties(); + std::map* props = host->getProperties(); if (props == nullptr) return nullptr; for (auto elm : *props) { diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 648db4dc00..776adfe90b 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -389,7 +389,7 @@ xbt_dict_t MSG_storage_get_properties(msg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)"); xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); - std::unordered_map* props = storage->getProperties(); + std::map* props = storage->getProperties(); if (props == nullptr) return nullptr; for (auto elm : *props) { diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 6d20389928..33d241fb35 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -103,7 +103,7 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; /*************************************************************/ XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc); XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, - sg_host_t host, xbt_dict_t properties, + sg_host_t host, std::map* properties, smx_actor_t parent_process); XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size); diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index b3ea3c98c1..18878b0407 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -51,7 +51,7 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor) /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */ smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function code, void* data, sg_host_t host, - xbt_dict_t properties, smx_actor_t parent_process) + std::map* properties, smx_actor_t parent_process) { msg_process_t p = MSG_process_create_from_stdfunc(name, std::move(code), data, host, properties); return p == nullptr ? nullptr : p->getImpl(); @@ -123,7 +123,15 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun if (code) function = simgrid::xbt::wrapMain(code, argc, static_cast(argv)); - msg_process_t res = MSG_process_create_from_stdfunc(name, std::move(function), data, host, properties); + std::map props; + xbt_dict_cursor_t cursor = nullptr; + char* key; + char* value; + xbt_dict_foreach (properties, cursor, key, value) + props[key] = value; + xbt_dict_free(&properties); + + msg_process_t res = MSG_process_create_from_stdfunc(name, std::move(function), data, host, &props); for (int i = 0; i != argc; ++i) xbt_free(argv[i]); xbt_free(argv); @@ -133,7 +141,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun SG_END_DECL() msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function code, void* data, msg_host_t host, - xbt_dict_t properties) + std::map* properties) { xbt_assert(code != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr"); simgrid::msg::ActorExt* msgExt = new simgrid::msg::ActorExt(data); @@ -161,10 +169,16 @@ SG_BEGIN_DECL() msg_process_t MSG_process_attach(const char *name, void *data, msg_host_t host, xbt_dict_t properties) { xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr"); + std::map props; + xbt_dict_cursor_t cursor = nullptr; + char* key; + char* value; + xbt_dict_foreach (properties, cursor, key, value) + props[key] = value; + xbt_dict_free(&properties); /* Let's create the process: SIMIX may decide to start it right now, even before returning the flow control to us */ - smx_actor_t process = - SIMIX_process_attach(name, new simgrid::msg::ActorExt(data), host->getCname(), properties, nullptr); + smx_actor_t process = SIMIX_process_attach(name, new simgrid::msg::ActorExt(data), host->getCname(), &props, nullptr); if (not process) xbt_die("Could not attach"); simcall_process_on_exit(process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,process); @@ -355,7 +369,7 @@ const char *MSG_process_get_name(msg_process_t process) */ const char *MSG_process_get_property_value(msg_process_t process, const char *name) { - return (char*) xbt_dict_get_or_null(MSG_process_get_properties(process), name); + return process->getProperty(name); } /** \ingroup m_process_management @@ -366,7 +380,15 @@ const char *MSG_process_get_property_value(msg_process_t process, const char *na xbt_dict_t MSG_process_get_properties(msg_process_t process) { xbt_assert(process != nullptr, "Invalid parameter: First argument must not be nullptr"); - return simcall_process_get_properties(process->getImpl()); + xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); + std::map* props = + simgrid::simix::kernelImmediate([process] { return process->getImpl()->getProperties(); }); + if (props == nullptr) + return nullptr; + for (auto elm : *props) { + xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr); + } + return as_dict; } /** \ingroup m_process_management diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 6b6f2ef5d8..7dcef8fee5 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -174,14 +174,12 @@ void Actor::killAll(int resetPid) /** Retrieve the property value (or nullptr if not set) */ const char* Actor::getProperty(const char* key) { - return (char*)xbt_dict_get_or_null(simcall_process_get_properties(pimpl_), key); + return simgrid::simix::kernelImmediate([this, key] { return pimpl_->getProperty(key); }); } void Actor::setProperty(const char* key, const char* value) { - simgrid::simix::kernelImmediate([this, key, value] { - xbt_dict_set(simcall_process_get_properties(pimpl_), key, (char*)value, (void_f_pvoid_t) nullptr); - }); + simgrid::simix::kernelImmediate([this, key, value] { pimpl_->setProperty(key, value); }); } Actor* Actor::restart() diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 9dafa33ce0..cd083646d2 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -177,11 +177,9 @@ void Host::routeTo(Host* dest, std::vector* links, double* late } /** Get the properties assigned to a host */ -std::unordered_map* Host::getProperties() +std::map* Host::getProperties() { - return simgrid::simix::kernelImmediate([this] { - return this->pimpl_->getProperties(); - }); + return simgrid::simix::kernelImmediate([this] { return this->pimpl_->getProperties(); }); } /** Retrieve the property value (or nullptr if not set) */ @@ -190,7 +188,7 @@ const char* Host::getProperty(const char* key) return this->pimpl_->getProperty(key); } -void Host::setProperty(const char* key, const char* value) +void Host::setProperty(std::string key, std::string value) { simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); } diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 58ad8f4c28..38be6654ba 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -60,7 +60,7 @@ sg_size_t Storage::getSize() return pimpl_->getSize(); } -std::unordered_map* Storage::getProperties() +std::map* Storage::getProperties() { return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 07f801756d..b86e0689a8 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -181,7 +181,7 @@ void sg_host_set_pstate(sg_host_t host,int pstate) { /** @brief Get the properties of an host */ xbt_dict_t sg_host_get_properties(sg_host_t host) { xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f); - std::unordered_map* props = host->getProperties(); + std::map* props = host->getProperties(); if (props == nullptr) return nullptr; for (auto elm : *props) { @@ -260,7 +260,7 @@ void sg_host_dump(sg_host_t host) XBT_INFO("Displaying host %s", host->getCname()); XBT_INFO(" - speed: %.0f", host->getSpeed()); XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host)); - std::unordered_map* props = host->getProperties(); + std::map* props = host->getProperties(); if (not props->empty()) { XBT_INFO(" - properties:"); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 3209e85a3a..318e5ed228 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -5,12 +5,12 @@ #include #include +#include #include #include #include -#include "xbt/dict.h" #include "xbt/ex.hpp" #include "xbt/functional.hpp" #include "xbt/log.h" @@ -141,7 +141,6 @@ namespace simix { ActorImpl::~ActorImpl() { delete this->context; - xbt_dict_free(&this->properties); } static int dying_daemon(void* exit_status, void* data) @@ -291,7 +290,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data) * \return the process created */ smx_actor_t SIMIX_process_create(const char* name, std::function code, void* data, simgrid::s4u::Host* host, - xbt_dict_t properties, smx_actor_t parent_process) + std::map* properties, smx_actor_t parent_process) { XBT_DEBUG("Start process %s on host '%s'", name, host->getCname()); @@ -331,7 +330,9 @@ smx_actor_t SIMIX_process_create(const char* name, std::function code, v process->context = SIMIX_context_new(std::move(code), simix_global->cleanup_process_function, process); /* Add properties */ - process->properties = properties; + if (properties != nullptr) + for (auto kv : *properties) + process->setProperty(kv.first, kv.second); /* Make sure that the process is initialized for simix, in case we are called from the Host::onCreation signal */ if (host->extension() == nullptr) @@ -354,8 +355,8 @@ smx_actor_t SIMIX_process_create(const char* name, std::function code, v return process; } -smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname, xbt_dict_t properties, - smx_actor_t parent_process) +smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname, + std::map* properties, smx_actor_t parent_process) { // This is mostly a copy/paste from SIMIX_process_new(), // it'd be nice to share some code between those two functions. @@ -364,8 +365,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn XBT_DEBUG("Attach process %s on host '%s'", name, hostname); if (host->isOff()) { - XBT_WARN("Cannot launch process '%s' on failed host '%s'", - name, hostname); + XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, hostname); return nullptr; } @@ -400,7 +400,9 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn process->context = simix_global->context_factory->attach(simix_global->cleanup_process_function, process); /* Add properties */ - process->properties = properties; + if (properties != nullptr) + for (auto kv : *properties) + process->setProperty(kv.first, kv.second); /* Add the process to it's host process list */ xbt_swag_insert(process, host->extension()->process_list); @@ -780,7 +782,8 @@ void SIMIX_process_yield(smx_actor_t self) /* Add the process to the list of process to restart, only if the host is down */ if (self->auto_restart && self->host->isOff()) { SIMIX_host_add_auto_restart_process(self->host, self->cname(), self->code, self->userdata, - SIMIX_timer_get_date(self->kill_timer), self->properties, self->auto_restart); + SIMIX_timer_get_date(self->kill_timer), self->getProperties(), + self->auto_restart); } XBT_DEBUG("Process %s@%s is dead", self->cname(), self->host->getCname()); self->context->stop(); @@ -882,9 +885,8 @@ void SIMIX_process_auto_restart_set(smx_actor_t process, int auto_restart) { * \param properties the properties of the process * \param auto_restart either it is autorestarting or not. */ -extern "C" -smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc, - char** argv, xbt_dict_t properties) +extern "C" smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, + int argc, char** argv, std::map* properties) { if (name == nullptr) name = ""; @@ -897,7 +899,7 @@ smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* } smx_actor_t simcall_process_create(const char* name, std::function code, void* data, sg_host_t host, - xbt_dict_t properties) + std::map* properties) { if (name == nullptr) name = ""; diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 952546bae0..3d7285f148 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -8,8 +8,10 @@ #include "simgrid/s4u/Actor.hpp" #include "src/simix/popping_private.h" +#include "src/surf/PropertyHolder.hpp" #include "xbt/swag.h" #include +#include typedef struct s_smx_process_exit_fun { int_f_pvoid_pvoid_t fun; @@ -27,11 +29,11 @@ public: void *data = nullptr; sg_host_t host = nullptr; double kill_time = 0.0; - xbt_dict_t properties = nullptr; + std::map* properties = nullptr; bool auto_restart = false; }; -class ActorImpl { +class ActorImpl : public simgrid::surf::PropertyHolder { public: ActorImpl() : piface_(this) {} ~ActorImpl(); @@ -59,7 +61,6 @@ public: sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */ smx_activity_t waiting_synchro = nullptr; /* the current blocking synchro if any */ std::list comms; /* the current non-blocking communication synchros */ - xbt_dict_t properties = nullptr; s_smx_simcall_t simcall; void* userdata = nullptr; /* kept for compatibility, it should be replaced with moddata */ std::vector on_exit; /* list of functions executed when the process dies */ @@ -123,13 +124,9 @@ typedef simgrid::simix::ActorImpl* smx_actor_t; SG_BEGIN_DECL() -XBT_PRIVATE smx_actor_t SIMIX_process_create( - const char *name, - std::function code, - void *data, - sg_host_t host, - xbt_dict_t properties, - smx_actor_t parent_process); +XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, std::function code, void* data, sg_host_t host, + std::map* properties, + smx_actor_t parent_process); XBT_PRIVATE void SIMIX_process_runall(); XBT_PRIVATE void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 15aeec6e93..045f8519e5 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -245,16 +245,6 @@ void simcall_process_set_kill_time(smx_actor_t process, double kill_time) }); } -/** - * \ingroup simix_process_management - * \brief Return the properties - * - * This function returns the properties associated with this process - */ -xbt_dict_t simcall_process_get_properties(smx_actor_t process) -{ - return process->properties; -} /** * \ingroup simix_process_management * \brief Add an on_exit function diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index fda196e0f5..ed75d52815 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -112,9 +112,9 @@ const char* sg_host_self_get_name() * The processes will only be restarted once, meaning that you will have to register the process * again to restart the process again. */ -void SIMIX_host_add_auto_restart_process( - sg_host_t host, const char *name, std::function code, - void* data, double kill_time, xbt_dict_t properties, int auto_restart) +void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function code, void* data, + double kill_time, std::map* properties, + int auto_restart) { smx_process_arg_t arg = new simgrid::simix::ProcessArg(); arg->name = name; diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index ffdcd20074..b7028b9db0 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -6,8 +6,9 @@ #ifndef SIMIX_HOST_PRIVATE_H #define SIMIX_HOST_PRIVATE_H -#include #include +#include +#include #include #include @@ -39,13 +40,9 @@ namespace simgrid { } SG_BEGIN_DECL() -XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, - const char *name, - std::function code, - void *data, - double kill_time, - xbt_dict_t properties, - int auto_restart); +XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function code, + void* data, double kill_time, + std::map* properties, int auto_restart); XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host); XBT_PRIVATE void SIMIX_execution_cancel(smx_activity_t synchro); diff --git a/src/surf/PropertyHolder.cpp b/src/surf/PropertyHolder.cpp index 03210a7ce2..a6696aee1e 100644 --- a/src/surf/PropertyHolder.cpp +++ b/src/surf/PropertyHolder.cpp @@ -8,8 +8,6 @@ namespace simgrid { namespace surf { -PropertyHolder::PropertyHolder() = default; - PropertyHolder::~PropertyHolder() { delete properties_; } @@ -26,17 +24,18 @@ const char *PropertyHolder::getProperty(const char*key) { } /** @brief Change the value of a given key in the property set */ -void PropertyHolder::setProperty(const char*key, const char*value) { +void PropertyHolder::setProperty(std::string key, std::string value) +{ if (not properties_) - properties_ = new std::unordered_map; + properties_ = new std::map; (*properties_)[key] = value; } /** @brief Return the whole set of properties. Don't mess with it, dude! */ -std::unordered_map* PropertyHolder::getProperties() +std::map* PropertyHolder::getProperties() { if (not properties_) - properties_ = new std::unordered_map; + properties_ = new std::map; return properties_; } diff --git a/src/surf/PropertyHolder.hpp b/src/surf/PropertyHolder.hpp index afbdbc2491..7c07fcd946 100644 --- a/src/surf/PropertyHolder.hpp +++ b/src/surf/PropertyHolder.hpp @@ -5,7 +5,7 @@ #ifndef SRC_SURF_PROPERTYHOLDER_HPP_ #define SRC_SURF_PROPERTYHOLDER_HPP_ -#include +#include namespace simgrid { namespace surf { @@ -17,19 +17,19 @@ namespace surf { class PropertyHolder { // DO NOT DERIVE THIS CLASS, or the diamond inheritance mayhem will get you public: - explicit PropertyHolder(); + PropertyHolder() = default; ~PropertyHolder(); const char *getProperty(const char*id); - void setProperty(const char*id, const char*value); + void setProperty(std::string id, std::string value); /* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy). * But some user API expose this call so removing it is not so easy. */ - std::unordered_map* getProperties(); + std::map* getProperties(); private: - std::unordered_map* properties_ = nullptr; + std::map* properties_ = nullptr; }; } /* namespace surf */ diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 6f1f2b95b3..18835f3696 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -213,10 +213,10 @@ public: std::string id; std::string model; std::string content; - xbt_dict_t properties; + std::map* properties; std::map* model_properties; sg_size_t size; - StorageType(std::string id, std::string model, std::string content, xbt_dict_t properties, + StorageType(std::string id, std::string model, std::string content, std::map* properties, std::map* model_properties, sg_size_t size) : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size) { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index ec195988b1..d0ef69e9f9 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -75,14 +75,11 @@ void sg_platf_exit() { /** @brief Add an host to the current AS */ void sg_platf_new_host(sg_platf_host_cbarg_t args) { - std::unordered_map props; + std::map props; if (args->properties) { - xbt_dict_cursor_t cursor=nullptr; - char *key; - char* data; - xbt_dict_foreach (args->properties, cursor, key, data) - props[key] = data; - xbt_dict_free(&args->properties); + for (auto elm : *args->properties) + props.insert({elm.first, elm.second}); + delete args->properties; } simgrid::s4u::Host* host = @@ -138,12 +135,9 @@ void sg_platf_new_link(LinkCreationArgs* link) surf_network_model->createLink(link_name.c_str(), link->bandwidth, link->latency, link->policy); if (link->properties) { - xbt_dict_cursor_t cursor = nullptr; - char* key; - char* data; - xbt_dict_foreach (link->properties, cursor, key, data) - l->setProperty(key, data); - xbt_dict_free(&link->properties); + for (auto elm : *link->properties) + l->setProperty(elm.first, elm.second); + delete link->properties; } if (link->latency_trace) @@ -204,15 +198,11 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) s_sg_platf_host_cbarg_t host; memset(&host, 0, sizeof(host)); host.id = host_id; - if ((cluster->properties != nullptr) && (not xbt_dict_is_empty(cluster->properties))) { - xbt_dict_cursor_t cursor=nullptr; - char *key; - char* data; - host.properties = xbt_dict_new_homogeneous(free); - - xbt_dict_foreach(cluster->properties,cursor,key,data) { - xbt_dict_set(host.properties, key, xbt_strdup(data), nullptr); - } + if ((cluster->properties != nullptr) && (not cluster->properties->empty())) { + host.properties = new std::map; + + for (auto elm : *cluster->properties) + host.properties->insert({elm.first, elm.second}); } host.speed_per_pstate = cluster->speeds; @@ -280,7 +270,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) xbt_free(host_id); rankId++; } - xbt_dict_free(&cluster->properties); + delete cluster->properties; // Add a router. XBT_DEBUG(" "); @@ -391,12 +381,9 @@ void sg_platf_new_storage(StorageCreationArgs* storage) auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach); if (storage->properties) { - xbt_dict_cursor_t cursor = nullptr; - char *key; - char* data; - xbt_dict_foreach (storage->properties, cursor, key, data) - s->setProperty(key, data); - xbt_dict_free(&storage->properties); + for (auto elm : *storage->properties) + s->setProperty(elm.first, elm.second); + delete storage->properties; } } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index b13c5ab98c..7973e5ec1f 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -369,7 +369,7 @@ void surf_exit() sg_link_exit(); for (auto e : storage_types) { simgrid::surf::StorageType* stype = e.second; - xbt_dict_free(&(stype->properties)); + delete stype->properties; delete stype->model_properties; delete stype; } diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index cdfe6efb5e..b5ae88cec5 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -49,7 +49,7 @@ typedef struct { tmgr_trace_t speed_trace; tmgr_trace_t state_trace; const char* coord; - xbt_dict_t properties; + std::map* properties; } s_sg_platf_host_cbarg_t; typedef s_sg_platf_host_cbarg_t* sg_platf_host_cbarg_t; @@ -69,7 +69,7 @@ public: tmgr_trace_t latency_trace = nullptr; tmgr_trace_t state_trace = nullptr; e_surf_link_sharing_policy_t policy = SURF_LINK_FATPIPE; - xbt_dict_t properties = nullptr; + std::map* properties = nullptr; }; class PeerCreationArgs { @@ -110,7 +110,7 @@ typedef struct s_sg_platf_cluster_cbarg { double limiter_link; e_surf_cluster_topology_t topology; const char* topo_parameters; - xbt_dict_t properties; + std::map* properties; const char* router_id; e_surf_link_sharing_policy_t sharing_policy; e_surf_link_sharing_policy_t bb_sharing_policy; @@ -132,7 +132,7 @@ public: std::string id; std::string type_id; std::string content; - xbt_dict_t properties; + std::map* properties; std::string attach; }; @@ -141,7 +141,7 @@ public: std::string id; std::string model; std::string content; - xbt_dict_t properties; + std::map* properties; std::map* model_properties; sg_size_t size; }; @@ -177,7 +177,7 @@ typedef struct s_sg_platf_process_cbarg *sg_platf_process_cbarg_t; typedef struct s_sg_platf_process_cbarg { const char **argv; int argc; - xbt_dict_t properties; + std::map* properties; const char *host; const char *function; double start_time; @@ -192,6 +192,8 @@ typedef struct s_sg_platf_AS_cbarg { } s_sg_platf_AS_cbarg_t; #define SG_PLATF_AS_INITIALIZER {nullptr,0} +/* The default current property receiver. Setup in the corresponding opening callbacks. */ +extern std::map* current_property_set; /********** Routing **********/ void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 0d09857753..8d77fca7da 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -319,7 +319,7 @@ static std::vector surf_parse_get_all_speeds(char* speeds, const char* e /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */ /* The default current property receiver. Setup in the corresponding opening callbacks. */ -xbt_dict_t current_property_set = nullptr; +std::map* current_property_set = nullptr; std::map* current_model_property_set = nullptr; int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties) @@ -520,11 +520,10 @@ void STag_surfxml_prop() simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id); netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value); - } - else{ + } else { if (not current_property_set) - current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error - xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr); + current_property_set = new std::map; // Maybe, it should raise an error + current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value}); XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value, current_property_set); } @@ -996,19 +995,16 @@ void STag_surfxml_config() void ETag_surfxml_config() { - xbt_dict_cursor_t cursor = nullptr; - char *key; - char *elem; - xbt_dict_foreach(current_property_set, cursor, key, elem) { - if (xbt_cfg_is_default_value(key)) { - std::string cfg = std::string(key) + ":" + elem; + for (auto elm : *current_property_set) { + if (xbt_cfg_is_default_value(elm.first.c_str())) { + std::string cfg = elm.first + ":" + elm.second; xbt_cfg_set_parse(cfg.c_str()); } else - XBT_INFO("The custom configuration '%s' is already defined by user!",key); + XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str()); } XBT_DEBUG("End configuration name = %s",A_surfxml_config_id); - xbt_dict_free(¤t_property_set); + delete current_property_set; current_property_set = nullptr; } diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 7d71f9365d..4e443200ce 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation"); static void display_storage_properties(simgrid::s4u::Storage* storage) { - std::unordered_map* props = storage->getProperties(); + std::map* props = storage->getProperties(); if (not props->empty()) { XBT_INFO("\tProperties of mounted storage: %s", storage->getName()); diff --git a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.tesh b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.tesh index ee27b68deb..099c46b3f6 100644 --- a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.tesh +++ b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.tesh @@ -40,16 +40,16 @@ $ ${bindir:=.}/basic-parsing-test ../platforms/four_hosts_floyd.xml > Workstation number: 4, link number: 5 $ ${bindir:=.}/basic-parsing-test ../platforms/properties.xml -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'host/model' to 'compound' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'cpu/optim' to 'TI' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'host/model' to 'compound' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'maxmin/precision' to '0.000010' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'Vegas' > Workstation number: 1, link number: 1 $ ${bindir:=.}/basic-parsing-test ../platforms/properties.xml --cfg=cpu/optim:TI > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'cpu/optim' to 'TI' -> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'host/model' to 'compound' > [0.000000] [surf_parse/INFO] The custom configuration 'cpu/optim' is already defined by user! +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'host/model' to 'compound' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'maxmin/precision' to '0.000010' > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'Vegas' > Workstation number: 1, link number: 1 -- 2.20.1