X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d8922a8d878de620b312b601417e286113135ae2..da6335359a88e448e4a706353f33e542a2fb00e5:/src/surf/surf_interface.cpp diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 3a37bcc055..9010a9490e 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -16,6 +16,7 @@ #include "src/simix/smx_host_private.h" #include "src/surf/HostImpl.hpp" #include "surf_private.h" +#include #include XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); @@ -25,13 +26,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (ke * Utils * *********/ -/* model_list_invoke contains only surf_host and surf_vm. - * The callback functions of cpu_model and network_model will be called from those of these host models. */ std::vector * all_existing_models = nullptr; /* to destroy models correctly */ -xbt_dynar_t model_list_invoke = nullptr; /* to invoke callbacks */ simgrid::trace_mgr::future_evt_set *future_evt_set = nullptr; -xbt_dynar_t surf_path = nullptr; +std::vector surf_path; std::vector host_that_restart; xbt_dict_t watched_hosts_lib; @@ -44,10 +42,12 @@ simgrid::xbt::signal surfExitCallbacks; } #include // FIXME: this plugin should not be linked to the core +#include // FIXME: this plugin should not be linked to the core s_surf_model_description_t surf_plugin_description[] = { - {"Energy", "Cpu energy consumption.", &sg_energy_plugin_init}, - {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */ + {"Energy", "Cpu energy consumption.", &sg_host_energy_plugin_init}, + {"Load", "Cpu load.", &sg_host_load_plugin_init}, + {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */ }; /* Don't forget to update the option description in smx_config when you change this */ @@ -128,10 +128,29 @@ double surf_get_clock() # define FILE_DELIM "/" /* FIXME: move to better location */ #endif +std::ifstream* surf_ifsopen(const char* name) +{ + std::ifstream* fs = new std::ifstream(); + xbt_assert(name); + if (__surf_is_absolute_file_path(name)) { /* don't mess with absolute file names */ + fs->open(name, std::ifstream::in); + } + + /* search relative files in the path */ + for (auto path_elm : surf_path) { + std::string buff = path_elm + FILE_DELIM + name; + fs->open(buff.c_str(), std::ifstream::in); + + if (!fs->fail()) { + XBT_DEBUG("Found file at %s", buff.c_str()); + return fs; + } + } + + return fs; +} FILE *surf_fopen(const char *name, const char *mode) { - unsigned int cpt; - char *path_elm = nullptr; char *buff; FILE *file = nullptr; @@ -141,8 +160,8 @@ FILE *surf_fopen(const char *name, const char *mode) return fopen(name, mode); /* search relative files in the path */ - xbt_dynar_foreach(surf_path, cpt, path_elm) { - buff = bprintf("%s" FILE_DELIM "%s", path_elm, name); + for (auto path_elm : surf_path) { + buff = bprintf("%s" FILE_DELIM "%s", path_elm.c_str(), name); file = fopen(buff, mode); free(buff); @@ -343,8 +362,6 @@ void surf_init(int *argc, char **argv) xbt_init(argc, argv); if (!all_existing_models) all_existing_models = new std::vector(); - if (!model_list_invoke) - model_list_invoke = xbt_dynar_new(sizeof(simgrid::surf::Model*), nullptr); if (!future_evt_set) future_evt_set = new simgrid::trace_mgr::future_evt_set(); @@ -361,8 +378,6 @@ void surf_exit() { TRACE_end(); /* Just in case it was not called by the upper layer (or there is no upper layer) */ - xbt_dynar_free(&surf_path); - sg_host_exit(); xbt_lib_free(&storage_lib); sg_link_exit(); @@ -373,7 +388,6 @@ void surf_exit() for (auto model : *all_existing_models) delete model; delete all_existing_models; - xbt_dynar_free(&model_list_invoke); simgrid::surf::surfExitCallbacks(); @@ -465,12 +479,10 @@ double Model::nextOccuringEventLazy(double now) min = now + time_to_completion; // when the task will complete if nothing changes } - if ((action->getMaxDuration() != NO_MAX_DURATION) - && (min == -1 - || action->getStartTime() + - action->getMaxDuration() < min)) { - min = action->getStartTime() + - action->getMaxDuration(); // when the task will complete anyway because of the deadline if any + if ((action->getMaxDuration() != NO_MAX_DURATION) && + (min == -1 || action->getStartTime() + action->getMaxDuration() < min)) { + // when the task will complete anyway because of the deadline if any + min = action->getStartTime() + action->getMaxDuration(); max_dur_flag = 1; }