sthread:
- Implement pthread_join in MC mode.
+XBT:
+ - simgrid::xbt::cmdline and simgrid::xbt::binary_name are gone.
+ Please use simgrid::s4u::Engine::get_cmdline() instead.
+
Documentation:
- New section in the user guide on the provided performance models.
- New section presenting some technical good practices for (potential) contributors.
include src/xbt/xbt_log_appender_file.cpp
include src/xbt/xbt_log_layout_format.cpp
include src/xbt/xbt_log_layout_simple.cpp
-include src/xbt/xbt_main.cpp
-include src/xbt/xbt_modinter.h
+include src/xbt/xbt_misc.cpp
include src/xbt/xbt_os_file.cpp
include src/xbt/xbt_os_time.c
include src/xbt/xbt_parse_units.cpp
include src/xbt/xbt_replay.cpp
include src/xbt/xbt_str.cpp
include src/xbt/xbt_str_test.cpp
-include src/xbt/xbt_virtu.cpp
include teshsuite/kernel/CMakeLists.txt
include teshsuite/mc/CMakeLists.txt
include teshsuite/models/CMakeLists.txt
/* 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. */
-/* This file defines all possible exception that could occur in a SimGrid library. */
+/* This file defines all possible exceptions that could occur in a SimGrid library. */
#ifndef SIMGRID_EXCEPTIONS_HPP
#define SIMGRID_EXCEPTIONS_HPP
+#include <simgrid/actor.h>
#include <xbt/backtrace.hpp>
#include <xbt/ex.h>
#include <xbt/string.hpp>
/** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */
#define XBT_THROW_POINT \
- ::simgrid::xbt::ThrowPoint(__FILE__, __LINE__, __func__, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid())
+ ::simgrid::xbt::ThrowPoint(__FILE__, __LINE__, __func__, simgrid::xbt::Backtrace(), sg_actor_self_get_name(), \
+ sg_actor_self_get_pid())
class XBT_PUBLIC ImpossibleError : public std::logic_error {
public:
XBT_PUBLIC sg_actor_t sg_actor_self();
XBT_PUBLIC aid_t sg_actor_self_get_pid();
XBT_PUBLIC aid_t sg_actor_self_get_ppid();
+/** Returns the name of the current actor (or "maestro" if maestro is running) */
XBT_PUBLIC const char* sg_actor_self_get_name();
XBT_PUBLIC void* sg_actor_self_get_data();
XBT_PUBLIC void sg_actor_self_set_data(void* data);
SG_BEGIN_DECL /* C interface */
- /** Initialize the SimGrid engine, taking the command line parameters of your main function. */
- XBT_PUBLIC void
- simgrid_init(int* argc, char** argv);
+/** Initialize the SimGrid engine, taking the command line parameters of your main function. */
+XBT_PUBLIC void
+simgrid_init(int* argc, char** argv);
/** Creates a new platform, including hosts, links, and the routing table.
*
static s4u::Engine* get_instance();
static s4u::Engine* get_instance(int* argc, char** argv);
static bool has_instance() { return instance_ != nullptr; }
+ const std::vector<std::string>& get_cmdline() const;
/**
* Creates a new platform, including hosts, links, and the routing table.
return res;
}
- kernel::EngineImpl* get_impl() const { return pimpl; }
+ kernel::EngineImpl* get_impl() const
+ {
+ return pimpl_;
+ }
/** Returns whether SimGrid was initialized yet -- mostly for internal use */
static bool is_initialized();
static xbt::signal<void(void)> on_deadlock;
static xbt::signal<void()> on_simulation_end;
- kernel::EngineImpl* const pimpl;
+ kernel::EngineImpl* const pimpl_;
static Engine* instance_;
void initialize(int* argc, char** argv);
};
#ifndef SIMGRID_VERSION_H
#define SIMGRID_VERSION_H
+#include "xbt/base.h"
+
#define SIMGRID_GIT_VERSION "@GIT_VERSION@"
/** Define the version numbers of the used header files.
#include <xbt/asserts.h>
#include <xbt/log.h>
-#include <xbt/module.h>
-
#include <xbt/dynar.h>
#include <xbt/dict.h>
#include <xbt/base.h>
#include <xbt/misc.h>
#include <xbt/sysdep.h>
-#include <xbt/virtu.h>
/** @addtogroup XBT_ex_c
* @brief Exceptions support (C)
#ifndef XBT_MODULE_H
#define XBT_MODULE_H
-#include <xbt/misc.h> /* XBT_PUBLIC */
+// avoid deprecation warning on include (remove entire file with XBT_ATTRIB_DEPRECATED_v337)
+#ifndef XBT_MODULE_H_NO_DEPRECATED_WARNING
+#warning xbt/module.h is deprecated and will be removed in v3.37.
+#endif
+
+#include <simgrid/engine.h>
+#include <xbt/base.h>
SG_BEGIN_DECL
-XBT_PUBLIC void xbt_init(int* argc, char** argv);
+XBT_ATTRIB_DEPRECATED_v337("Please use simgrid_init(&argc, argv) instead") static void xbt_init(int* argc, char** argv)
+{
+ simgrid_init(argc, argv);
+}
SG_END_DECL
return res;
}
-/** @brief like free
- @hideinitializer */
+/** @brief like free */
#define xbt_free(p) free(p) /*nothing specific to do here. A poor valgrind replacement? */
#ifdef __cplusplus
#ifndef XBT_VIRTU_H
#define XBT_VIRTU_H
+#include <simgrid/actor.h>
#include <xbt/base.h>
-#ifdef __cplusplus
-#include <string>
-#include <vector>
-
-namespace simgrid {
-namespace xbt {
-
-/* Get the name of the UNIX process englobing the world */
-XBT_PUBLIC_DATA std::string binary_name;
-/** Contains all the parameters we got from the command line (including argv[0]) */
-XBT_PUBLIC_DATA std::vector<std::string> cmdline;
-
-} // namespace xbt
-} // namespace simgrid
+// avoid deprecation warning on include (remove entire file with XBT_ATTRIB_DEPRECATED_v337)
+#ifndef XBT_VIRTU_H_NO_DEPRECATED_WARNING
+#warning xbt/virtu.h is deprecated and will be removed in v3.37.
#endif
SG_BEGIN_DECL
-XBT_PUBLIC const char* xbt_procname(void);
+XBT_ATTRIB_DEPRECATED_v337("Please use sg_actor_self_get_name()") static const char* xbt_procname(void)
+{
+ return sg_actor_self_get_name();
+}
-XBT_PUBLIC int xbt_getpid(void);
+XBT_ATTRIB_DEPRECATED_v337("Please use sg_actor_self_get_pid()") static int xbt_getpid(void)
+{
+ return sg_actor_self_get_pid();
+};
SG_END_DECL
-/* Copyright (c) 2010-2023. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2010-2023. 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. */
-#include "simgrid/Exception.hpp"
#include "simgrid/version.h"
#include "src/instr/instr_private.hpp"
#include "src/smpi/include/private.hpp"
-#include "xbt/virtu.h" /* xbt::cmdline */
+#include <simgrid/Exception.hpp>
+#include <simgrid/s4u/Engine.hpp>
extern std::ofstream tracing_file;
namespace simgrid::instr::paje {
tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR
<< "." << SIMGRID_VERSION_PATCH << '\n';
tracing_file << "#[";
- for (auto const& str : simgrid::xbt::cmdline) {
+ for (auto const& str : simgrid::s4u::Engine::get_instance()->get_cmdline()) {
tracing_file << str << " ";
}
tracing_file << "]\n";
#include "src/simgrid/math_utils.h"
#include "src/simgrid/sg_config.hpp"
#include "src/smpi/include/smpi_actor.hpp"
-#include "src/xbt/xbt_modinter.h" /* whether initialization was already done */
-#include "xbt/module.h"
+
+#include "xbt/log.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <dlfcn.h>
}
}
+static simgrid::config::Flag<bool> cfg_dbg_clean_atexit{
+ "debug/clean-atexit", "Whether to cleanup SimGrid at exit. Disable it if your code segfaults after its end.", true};
+
namespace simgrid::kernel {
EngineImpl::~EngineImpl()
simgrid::mc::AppSide::initialize();
#endif
- if (xbt_initialized == 0) {
- xbt_init(argc, argv);
+ static bool inited = false;
+ if (not inited) {
+ inited = true;
+ xbt_log_init(argc, argv);
+
+ simgrid::xbt::install_exception_handler();
+
+ for (int i = 0; i < *argc; i++)
+ cmdline_.emplace_back(argv[i]);
sg_config_init(argc, argv);
}
/* register a function to be called after the environment creation */
s4u::Engine::on_platform_created_cb([this]() { this->presolve(); });
- if (config::get_value<bool>("debug/clean-atexit"))
+ if (cfg_dbg_clean_atexit)
atexit(shutdown);
}
std::unique_ptr<void, std::function<int(void*)>> platf_handle_; //!< handle for platform library
friend s4u::Engine;
+ std::vector<std::string> cmdline_; // Copy of the argv we got (including argv[0])
public:
EngineImpl() = default;
#endif
void initialize(int* argc, char** argv);
+ const std::vector<std::string>& get_cmdline() const
+ {
+ return cmdline_;
+ }
void load_platform(const std::string& platf);
void load_deployment(const std::string& file) const;
void seal_platform() const;
const std::vector<resource::Model*>& get_all_models() const { return models_; }
static bool has_instance() { return s4u::Engine::has_instance(); }
- static EngineImpl* get_instance() { return s4u::Engine::get_instance()->pimpl; }
- static EngineImpl* get_instance(int* argc, char** argv) { return s4u::Engine::get_instance(argc, argv)->pimpl; }
+ static EngineImpl* get_instance()
+ {
+ return s4u::Engine::get_instance()->pimpl_;
+ }
+ static EngineImpl* get_instance(int* argc, char** argv)
+ {
+ return s4u::Engine::get_instance(argc, argv)->pimpl_;
+ }
actor::ActorCodeFactory get_function(const std::string& name)
{
#include "simgrid/Exception.hpp"
#include "src/internal_config.h" /* loads context system definitions */
#include "src/kernel/EngineImpl.hpp"
-#include "src/xbt/xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */
#include "xbt/function_types.h"
#include <boost/core/demangle.hpp>
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/kernel/resource/profile/StochasticDatedValue.hpp"
-#include "xbt.h"
+
+#include "xbt/asserts.h"
#include "xbt/random.hpp"
+
#include <math.h>
namespace simgrid::kernel::profile {
aid_t get_pid()
{
- return simgrid::kernel::actor::ActorImpl::self()->get_pid();
+ auto* self = simgrid::kernel::actor::ActorImpl::self();
+ return self ? self->get_pid() : 0;
}
aid_t get_ppid()
const char* get_cname()
{
- return simgrid::kernel::actor::ActorImpl::self()->get_cname();
+ auto* self = simgrid::kernel::actor::ActorImpl::self();
+ return self ? self->get_cname() : nullptr;
}
Host* get_host()
const char* sg_actor_self_get_name()
{
+ if (simgrid::s4u::Actor::is_maestro())
+ return "maestro";
return simgrid::s4u::this_actor::get_cname();
}
xbt_assert(Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine");
Engine::instance_ = this;
instr::init();
- pimpl->initialize(argc, argv);
+ pimpl_->initialize(argc, argv);
// Either create a new context with maestro or create
// a context object with the current context maestro):
kernel::actor::create_maestro(maestro_code);
}
-Engine::Engine(std::string name) : pimpl(new kernel::EngineImpl())
+Engine::Engine(std::string name) : pimpl_(new kernel::EngineImpl())
{
int argc = 1;
char* argv = &name[0];
initialize(&argc, &argv);
}
-Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl())
+Engine::Engine(int* argc, char** argv) : pimpl_(new kernel::EngineImpl())
{
initialize(argc, argv);
}
}
return Engine::instance_;
}
+const std::vector<std::string>& Engine::get_cmdline() const
+{
+ return pimpl_->get_cmdline();
+}
void Engine::shutdown() // XBT_ATTRIB_DEPRECATED_v335
{
void Engine::add_model(std::shared_ptr<kernel::resource::Model> model,
const std::vector<kernel::resource::Model*>& dependencies)
{
- kernel::actor::simcall_answered([this, &model, &dependencies] { pimpl->add_model(std::move(model), dependencies); });
+ kernel::actor::simcall_answered([this, &model, &dependencies] { pimpl_->add_model(std::move(model), dependencies); });
}
const std::vector<simgrid::kernel::resource::Model*>& Engine::get_all_models() const
{
- return pimpl->get_all_models();
+ return pimpl_->get_all_models();
}
void Engine::load_platform(const std::string& platf) const
{
- pimpl->load_platform(platf);
+ pimpl_->load_platform(platf);
}
void Engine::seal_platform() const
{
- pimpl->seal_platform();
+ pimpl_->seal_platform();
}
static void flatify_hosts(Engine const& engine, std::stringstream& ss)
}
void Engine::register_default(const kernel::actor::ActorCodeFactory& code)
{
- simgrid::kernel::actor::simcall_answered([this, &code]() { pimpl->register_default(code); });
+ simgrid::kernel::actor::simcall_answered([this, &code]() { pimpl_->register_default(code); });
}
void Engine::register_function(const std::string& name, const kernel::actor::ActorCodeFactory& code)
{
- simgrid::kernel::actor::simcall_answered([this, name, &code]() { pimpl->register_function(name, code); });
+ simgrid::kernel::actor::simcall_answered([this, name, &code]() { pimpl_->register_function(name, code); });
}
/** Load a deployment file and launch the actors that it contains
*/
void Engine::load_deployment(const std::string& deploy) const
{
- pimpl->load_deployment(deploy);
+ pimpl_->load_deployment(deploy);
}
/** Returns the amount of hosts in the platform */
std::vector<Host*> Engine::get_filtered_hosts(const std::function<bool(Host*)>& filter) const
{
std::vector<Host*> hosts;
- if (pimpl->netzone_root_) {
- hosts = pimpl->netzone_root_->get_filtered_hosts(filter);
+ if (pimpl_->netzone_root_) {
+ hosts = pimpl_->netzone_root_->get_filtered_hosts(filter);
}
/* Sort hosts in lexicographical order: keep same behavior when the hosts were saved on Engine
* Some tests do a get_all_hosts() and selects hosts in this order */
Host* Engine::host_by_name_or_null(const std::string& name) const
{
Host* host = nullptr;
- if (pimpl->netzone_root_) {
- auto* host_impl = pimpl->netzone_root_->get_host_by_name_or_null(name);
+ if (pimpl_->netzone_root_) {
+ auto* host_impl = pimpl_->netzone_root_->get_host_by_name_or_null(name);
if (host_impl)
host = host_impl->get_iface();
}
SplitDuplexLink* Engine::split_duplex_link_by_name(const std::string& name) const
{
- auto* link_impl = pimpl->netzone_root_ ? pimpl->netzone_root_->get_split_duplex_link_by_name_or_null(name) : nullptr;
+ auto* link_impl =
+ pimpl_->netzone_root_ ? pimpl_->netzone_root_->get_split_duplex_link_by_name_or_null(name) : nullptr;
if (not link_impl)
throw std::invalid_argument("Link not found: " + name);
return link_impl->get_iface();
Link* Engine::link_by_name_or_null(const std::string& name) const
{
Link* link = nullptr;
- if (pimpl->netzone_root_) {
+ if (pimpl_->netzone_root_) {
/* keep behavior where internal __loopback__ link from network model is given to user */
if (name == "__loopback__")
- return pimpl->netzone_root_->get_network_model()->loopback_->get_iface();
- auto* link_impl = pimpl->netzone_root_->get_link_by_name_or_null(name);
+ return pimpl_->netzone_root_->get_network_model()->loopback_->get_iface();
+ auto* link_impl = pimpl_->netzone_root_->get_link_by_name_or_null(name);
if (link_impl)
link = link_impl->get_iface();
}
{
/* two actors may have pushed the same mbox_create simcall at the same time */
kernel::activity::MailboxImpl* mbox = kernel::actor::simcall_answered([&name, this] {
- auto [m, inserted] = pimpl->mailboxes_.try_emplace(name, nullptr);
+ auto [m, inserted] = pimpl_->mailboxes_.try_emplace(name, nullptr);
if (inserted) {
m->second = new kernel::activity::MailboxImpl(name);
XBT_DEBUG("Creating a mailbox at %p with name %s", m->second, name.c_str());
size_t Engine::get_link_count() const
{
int count = 0;
- if (pimpl->netzone_root_) {
- count += pimpl->netzone_root_->get_link_count();
+ if (pimpl_->netzone_root_) {
+ count += pimpl_->netzone_root_->get_link_count();
/* keep behavior where internal __loopback__ link from network model is given to user */
- count += pimpl->netzone_root_->get_network_model()->loopback_ ? 1 : 0;
+ count += pimpl_->netzone_root_->get_network_model()->loopback_ ? 1 : 0;
}
return count;
}
std::vector<Link*> Engine::get_filtered_links(const std::function<bool(Link*)>& filter) const
{
std::vector<Link*> res;
- if (pimpl->netzone_root_) {
- res = pimpl->netzone_root_->get_filtered_links(filter);
+ if (pimpl_->netzone_root_) {
+ res = pimpl_->netzone_root_->get_filtered_links(filter);
/* keep behavior where internal __loopback__ link from network model is given to user */
- if (pimpl->netzone_root_->get_network_model()->loopback_ &&
- filter(pimpl->netzone_root_->get_network_model()->loopback_->get_iface()))
- res.push_back(pimpl->netzone_root_->get_network_model()->loopback_->get_iface());
+ if (pimpl_->netzone_root_->get_network_model()->loopback_ &&
+ filter(pimpl_->netzone_root_->get_network_model()->loopback_->get_iface()))
+ res.push_back(pimpl_->netzone_root_->get_network_model()->loopback_->get_iface());
}
return res;
}
size_t Engine::get_actor_count() const
{
- return pimpl->get_actor_count();
+ return pimpl_->get_actor_count();
}
std::vector<ActorPtr> Engine::get_all_actors() const
{
std::vector<ActorPtr> actor_list;
- for (auto const& [_, actor] : pimpl->get_actor_list()) {
+ for (auto const& [_, actor] : pimpl_->get_actor_list()) {
actor_list.push_back(actor->get_iface());
}
return actor_list;
std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(ActorPtr)>& filter) const
{
std::vector<ActorPtr> actor_list;
- for (auto const& [_, actor] : pimpl->get_actor_list()) {
+ for (auto const& [_, actor] : pimpl_->get_actor_list()) {
if (filter(actor->get_iface()))
actor_list.push_back(actor->get_iface());
}
fflush(stdout);
fflush(stderr);
- pimpl->run(max_date);
+ pimpl_->run(max_date);
}
void Engine::track_vetoed_activities(std::set<Activity*>* vetoed_activities) const
/** @brief Retrieve the root netzone, containing all others */
s4u::NetZone* Engine::get_netzone_root() const
{
- if (pimpl->netzone_root_)
- return pimpl->netzone_root_->get_iface();
+ if (pimpl_->netzone_root_)
+ return pimpl_->netzone_root_->get_iface();
return nullptr;
}
/** @brief Set the root netzone, containing all others. Once set, it cannot be changed. */
void Engine::set_netzone_root(const s4u::NetZone* netzone)
{
- xbt_assert(pimpl->netzone_root_ == nullptr, "The root NetZone cannot be changed once set");
- pimpl->netzone_root_ = netzone->get_impl();
+ xbt_assert(pimpl_->netzone_root_ == nullptr, "The root NetZone cannot be changed once set");
+ pimpl_->netzone_root_ = netzone->get_impl();
}
static NetZone* netzone_by_name_recursive(NetZone* current, const std::string& name)
/** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
kernel::routing::NetPoint* Engine::netpoint_by_name_or_null(const std::string& name) const
{
- auto netp = pimpl->netpoints_.find(name);
- return netp == pimpl->netpoints_.end() ? nullptr : netp->second;
+ auto netp = pimpl_->netpoints_.find(name);
+ return netp == pimpl_->netpoints_.end() ? nullptr : netp->second;
}
kernel::routing::NetPoint* Engine::netpoint_by_name(const std::string& name) const
std::vector<kernel::routing::NetPoint*> Engine::get_all_netpoints() const
{
std::vector<kernel::routing::NetPoint*> res;
- for (auto const& [_, netpoint] : pimpl->netpoints_)
+ for (auto const& [_, netpoint] : pimpl_->netpoints_)
res.push_back(netpoint);
return res;
}
/** @brief Register a new netpoint to the system */
void Engine::netpoint_register(kernel::routing::NetPoint* point)
{
- simgrid::kernel::actor::simcall_answered([this, point] { pimpl->netpoints_[point->get_name()] = point; });
+ simgrid::kernel::actor::simcall_answered([this, point] { pimpl_->netpoints_[point->get_name()] = point; });
}
/** @brief Unregister a given netpoint */
void Engine::netpoint_unregister(kernel::routing::NetPoint* point)
{
kernel::actor::simcall_answered([this, point] {
- pimpl->netpoints_.erase(point->get_name());
+ pimpl_->netpoints_.erase(point->get_name());
delete point;
});
}
/* **************************** Public C interface *************************** */
void simgrid_init(int* argc, char** argv)
{
- static simgrid::s4u::Engine e(argc, argv);
+ simgrid::s4u::Engine::get_instance(argc, argv);
}
void simgrid_load_platform(const char* file)
{
XBT_WARN("Call to sg_config_init() after initialization ignored");
return;
}
+ _sg_cfg_init_status = 1;
/* Plugins and models configuration */
simgrid_plugins().create_flag("plugin", "The plugins", "", true);
static simgrid::config::Flag<bool> cfg_execution_cutpath{
"exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false};
- _sg_cfg_init_status = 1;
-
sg_config_cmd_line(argc, argv);
xbt_mallocator_initialization_is_done(simgrid::kernel::context::Context::is_parallel());
#include "private.hpp"
#include "src/internal_config.h"
+#include "src/kernel/EngineImpl.hpp"
#include "src/smpi/include/smpi_actor.hpp"
#include "src/xbt/memory_map.hpp"
-#include "xbt/virtu.h"
#include <algorithm>
#include <cerrno>
static void smpi_get_executable_global_size()
{
- char* buffer = realpath(simgrid::xbt::binary_name.c_str(), nullptr);
- xbt_assert(buffer != nullptr, "Could not resolve real path of binary file '%s'", simgrid::xbt::binary_name.c_str());
+ auto* binary_name = simgrid::kernel::EngineImpl::get_instance()->get_cmdline().front().c_str();
+ char* buffer = realpath(binary_name, nullptr);
+ xbt_assert(buffer != nullptr, "Could not resolve real path of binary file '%s'", binary_name);
std::string full_name = buffer;
free(buffer);
#include "src/internal_config.h"
+#include <simgrid/actor.h>
+#include <simgrid/s4u/Actor.hpp>
#include <xbt/backtrace.hpp>
#include <xbt/string.hpp>
#include <xbt/sysdep.h>
-#include <xbt/virtu.h>
#include <cstdio>
#include <cstdlib>
void Backtrace::display() const
{
std::string backtrace = resolve();
- std::fprintf(stderr, "Backtrace (displayed in actor %s%s):\n%s\n", xbt_procname(),
+ std::fprintf(stderr, "Backtrace (displayed in actor %s%s):\n%s\n",
+ simgrid::s4u::Actor::is_maestro() ? "maestro" : sg_actor_self_get_name(),
(xbt_log_no_loc ? " -- short trace because of --log=no_loc" : ""),
backtrace.empty() ? "(backtrace not set -- did you install Boost.Stacktrace?)" : backtrace.c_str());
}
#include "xbt/dict.h"
#include "dict_private.h"
#include "simgrid/Exception.hpp"
-#include "src/xbt/xbt_modinter.h"
#include "xbt/ex.h"
#include "xbt/log.h"
#include "xbt/mallocator.h"
constexpr int MAX_FILL_PERCENT = 80;
+/** Handle the dict mallocators init/fini cycle. */
+static void xbt_dict_postexit()
+{
+ if (dict_elm_mallocator != nullptr) {
+ xbt_mallocator_free(dict_elm_mallocator);
+ dict_elm_mallocator = nullptr;
+ }
+}
+static void xbt_dict_preinit()
+{
+ if (dict_elm_mallocator == nullptr) {
+ dict_elm_mallocator =
+ xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f, dict_elm_mallocator_reset_f);
+ atexit(xbt_dict_postexit);
+ }
+}
+
/**
* @brief Constructor
* @param free_ctn function to call with (@a data as argument) when @a data is removed from the dictionary
*/
xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn)
{
- xbt_dict_preinit();
+ xbt_dict_preinit(); // Make sure that the module is intialized
xbt_dict_t dict;
{
return not dict || (xbt_dict_length(dict) == 0);
}
-
-/**
- * Create the dict mallocators.
- * This is an internal XBT function called during the lib initialization.
- * It can be used several times to recreate the mallocator, for example when you switch to MC mode
- */
-void xbt_dict_preinit()
-{
- if (dict_elm_mallocator == nullptr)
- dict_elm_mallocator = xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f,
- dict_elm_mallocator_reset_f);
-}
-
-/**
- * Destroy the dict mallocators.
- * This is an internal XBT function during the lib initialization
- */
-void xbt_dict_postexit()
-{
- if (dict_elm_mallocator != nullptr) {
- xbt_mallocator_free(dict_elm_mallocator);
- dict_elm_mallocator = nullptr;
- }
-}
void _xbt_throw(char* message, const char* file, int line, const char* func)
{
- simgrid::Exception e(
- simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()),
- message ? message : "");
+ simgrid::Exception e(simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), sg_actor_self_get_name(),
+ sg_actor_self_get_pid()),
+ message ? message : "");
xbt_free(message);
throw e;
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/xbt/log_private.hpp"
-#include "src/xbt/xbt_modinter.h"
#include "xbt/string.hpp"
#include "xbt/sysdep.h"
static void xbt_log_help();
static void xbt_log_help_categories();
+static void xbt_log_postexit();
void xbt_log_init(int *argc, char **argv)
{
int parse_args = 1; // Stop parsing the parameters once we found '--'
xbt_log_control_set("xbt_help.app:stdout xbt_help.threshold:VERBOSE xbt_help.fmt:%m%n");
+ atexit(xbt_log_postexit);
/* Set logs and init log submodule */
for (int i = 1; i < *argc; i++) {
}
}
-static void log_cat_exit(const s_xbt_log_category_t* cat)
+static void log_cat_exit(xbt_log_category_t cat)
{
if (cat->appender) {
if (cat->appender->free_)
cat->appender->free_(cat->appender);
xbt_free(cat->appender);
+ cat->appender = nullptr;
}
if (cat->layout) {
if (cat->layout->free_)
cat->layout->free_(cat->layout);
xbt_free(cat->layout);
+ cat->layout = nullptr;
}
- for (auto const* child = cat->firstChild; child != nullptr; child = child->nextSibling)
+ for (auto* child = cat->firstChild; child != nullptr; child = child->nextSibling)
log_cat_exit(child);
+ cat->firstChild = nullptr;
}
-void xbt_log_postexit(void)
+static void xbt_log_postexit(void)
{
XBT_VERB("Exiting log");
log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT));
#include "simgrid/host.h"
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
-#include "xbt/virtu.h"
+#include <simgrid/actor.h>
+#include <simgrid/s4u/Actor.hpp>
+
#include <algorithm>
#include <cstdio>
} else \
(void)0
#define show_int(data) show_it((data), "d")
+#define show_long(data) show_it((data), "ld")
#define show_double(data) show_it((data), "f")
static bool xbt_log_layout_format_doit(const s_xbt_log_layout_t* l, xbt_log_event_t ev, const char* msg_fmt)
case 't': /* thread/process name; LOG4J compliant */
case 'P': /* Used before SimGrid 3.26 and kept for compatiblity. Should not hurt. */
case 'a': /* actor name; SimGrid extension */
- show_string(xbt_procname());
+ show_string(sg_actor_self_get_name());
break;
case 'i': /* actor ID; SimGrid extension */
- show_int(xbt_getpid());
+ show_long(sg_actor_self_get_pid());
break;
case 'F': /* file name; LOG4J compliant */
show_string(ev->fileName);
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
-#include "xbt/virtu.h"
+#include <simgrid/actor.h>
+#include <simgrid/s4u/Actor.hpp>
#include "simgrid/engine.h" /* simgrid_get_clock */
#include "simgrid/host.h" /* sg_host_self_get_name */
check_overflow(1);
/* Display the proc info if available */
- procname = xbt_procname();
+ procname = sg_actor_self_get_name();
if (procname && strcmp(procname,"maestro")) {
- len = snprintf(p, rem_size, "%s:%s:(%d) ", sg_host_self_get_name(), procname, xbt_getpid());
+ len = snprintf(p, rem_size, "%s:%s:(%ld) ", sg_host_self_get_name(), procname, sg_actor_self_get_pid());
check_overflow(len);
} else if (not procname) {
- len = snprintf(p, rem_size, "%s::(%d) ", sg_host_self_get_name(), xbt_getpid());
+ len = snprintf(p, rem_size, "%s::(%ld) ", sg_host_self_get_name(), sg_actor_self_get_pid());
check_overflow(len);
}
+++ /dev/null
-/* module handling */
-
-/* Copyright (c) 2006-2023. 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. */
-
-#define XBT_LOG_LOCALLY_DEFINE_XBT_CHANNEL /* MSVC don't want it to be declared extern in headers and local here */
-
-#include "simgrid/config.h"
-#include "src/internal_config.h"
-#include "src/simgrid/sg_config.hpp"
-#include "src/sthread/sthread.h" // sthread_inside_simgrid
-#include "src/xbt/coverage.h"
-#include "src/xbt/xbt_modinter.h" /* prototype of other module's init/exit in XBT */
-#include "xbt/config.hpp"
-#include "xbt/dynar.h"
-#include "xbt/log.h"
-#include "xbt/log.hpp"
-#include "xbt/misc.h"
-#include "xbt/module.h" /* this module */
-#include "xbt/sysdep.h"
-
-#include <cmath>
-#include <cstdio>
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#include <string>
-#include <vector>
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module, xbt, "module handling");
-
-XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); /* lives here even if that's a bit odd to solve linking issues: this is used in xbt_log_file_appender to detect whether SMPI is used (and thus whether we should unbench the writing to disk) */
-
-namespace simgrid::xbt {
-std::string binary_name; /* Name of the system process containing us (mandatory to retrieve neat backtraces) */
-std::vector<std::string> cmdline; /* all we got in argv */
-} // namespace simgrid::xbt
-
-
-int xbt_initialized = 0;
-simgrid::config::Flag<bool> cfg_dbg_clean_atexit{
- "debug/clean-atexit",
- "Whether to cleanup SimGrid at exit. Disable it if your code segfaults after its end.",
- true};
-
-const int xbt_pagesize = static_cast<int>(sysconf(_SC_PAGESIZE));
-const int xbt_pagebits = static_cast<int>(log2(xbt_pagesize));
-
-/* Declare xbt_preinit and xbt_postexit as constructor/destructor of the library.
- * This is crude and rather compiler-specific, unfortunately.
- */
-static void xbt_preinit() XBT_ATTRIB_CONSTRUCTOR(200);
-static void xbt_postexit();
-XBT_ATTRIB_NOINLINE void sthread_enable()
-{ // These symbols are used from ContextSwapped in any case, but they are only useful
- asm("");
-}
-XBT_ATTRIB_NOINLINE void sthread_disable()
-{ // when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
- asm("");
-}
-
-static void xbt_preinit()
-{
- xbt_dict_preinit();
- atexit(xbt_postexit);
-}
-
-static void xbt_postexit()
-{
- if (not cfg_dbg_clean_atexit)
- return;
- xbt_initialized--;
- xbt_dict_postexit();
- xbt_log_postexit();
-}
-
-/** @brief Initialize the xbt mechanisms. */
-void xbt_init(int *argc, char **argv)
-{
- xbt_initialized++;
- if (xbt_initialized > 1) {
- XBT_DEBUG("XBT has been initialized %d times.", xbt_initialized);
- return;
- }
-
- simgrid::xbt::install_exception_handler();
-
- if (*argc > 0)
- simgrid::xbt::binary_name = argv[0];
- for (int i = 0; i < *argc; i++)
- simgrid::xbt::cmdline.emplace_back(argv[i]);
-
- xbt_log_init(argc, argv);
-}
-
-/* these two functions belong to xbt/sysdep.h, which have no corresponding .c file */
-/** @brief like xbt_free, but you can be sure that it is a function */
-void xbt_free_f(void* p) noexcept(noexcept(::free))
-{
- xbt_free(p);
-}
-
-/** @brief should be given a pointer to pointer, and frees the second one */
-void xbt_free_ref(void* d) noexcept(noexcept(::free))
-{
- xbt_free(*(void**)d);
-}
-
-/** @brief Kill the program in silence */
-void xbt_abort()
-{
- /* Call __gcov_flush on abort when compiling with coverage options. */
- coverage_checkpoint();
- abort();
-}
-
-#ifndef HAVE_SMPI
-int SMPI_is_inited()
-{
- return false;
-}
-#endif
--- /dev/null
+/* Various pieces of code which don't fit in any module */
+
+/* Copyright (c) 2006-2023. 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. */
+
+#define XBT_LOG_LOCALLY_DEFINE_XBT_CHANNEL /* MSVC don't want it to be declared extern in headers and local here */
+
+#include "src/internal_config.h"
+#include "src/sthread/sthread.h" // sthread_inside_simgrid
+#include "src/xbt/coverage.h"
+#include "xbt/log.h"
+#include "xbt/misc.h"
+#include "xbt/sysdep.h"
+
+#include <cmath>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); /* lives here even if that's a bit odd to solve linking issues: this
+ is used in xbt_log_file_appender to detect whether SMPI is used
+ (and thus whether we should unbench the writing to disk) */
+
+const int xbt_pagesize = static_cast<int>(sysconf(_SC_PAGESIZE));
+const int xbt_pagebits = static_cast<int>(log2(xbt_pagesize));
+
+XBT_ATTRIB_NOINLINE void sthread_enable()
+{ // These symbols are used from ContextSwapped in any case, but they are only useful
+ asm("");
+}
+XBT_ATTRIB_NOINLINE void sthread_disable()
+{ // when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
+ asm("");
+}
+
+/* these two functions belong to xbt/sysdep.h, which have no corresponding .c file */
+/** @brief like xbt_free, but you can be sure that it is a function */
+void xbt_free_f(void* p) noexcept(noexcept(::free))
+{
+ xbt_free(p);
+}
+
+/** @brief should be given a pointer to pointer, and frees the second one */
+void xbt_free_ref(void* d) noexcept(noexcept(::free))
+{
+ xbt_free(*(void**)d);
+}
+
+/** @brief Kill the program in silence */
+void xbt_abort()
+{
+ /* Call __gcov_flush on abort when compiling with coverage options. */
+ coverage_checkpoint();
+ abort();
+}
+
+#ifndef HAVE_SMPI
+int SMPI_is_inited()
+{
+ return false;
+}
+#endif
+++ /dev/null
-/* xbt_modinter - How to init/exit the XBT modules */
-
-/* Copyright (c) 2004-2023. 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 XBT_MODINTER_H
-#define XBT_MODINTER_H
-#include "xbt/misc.h"
-
-SG_BEGIN_DECL
-
-/* Modules definitions */
-
-void xbt_log_postexit(void);
-
-void xbt_dict_preinit(void);
-void xbt_dict_postexit(void);
-
-extern int xbt_initialized;
-
-SG_END_DECL
-
-#endif
+++ /dev/null
-/* virtualization layer for XBT */
-
-/* Copyright (c) 2007-2023. 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. */
-
-#include <simgrid/s4u/Actor.hpp>
-#include <xbt/virtu.h>
-
-#include "src/kernel/actor/ActorImpl.hpp"
-
-int xbt_getpid()
-{
- const auto* self = simgrid::kernel::actor::ActorImpl::self();
- return self == nullptr ? 0 : static_cast<int>(self->get_pid());
-}
-
-const char* xbt_procname(void)
-{
- return simgrid::s4u::Actor::is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname();
-}
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "xbt/log.h"
-#include "xbt/module.h"
#include "xbt/sysdep.h"
#include <algorithm>
#include <array>
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/lmm/maxmin.hpp"
-#include "xbt/module.h"
#include "xbt/random.hpp"
#include "xbt/sysdep.h" /* time manipulation for benchmarking */
#include "xbt/xbt_os_time.h"
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/Exception.hpp"
+#include "simgrid/engine.h"
#include "src/xbt/mmalloc/mmalloc.h"
#include "xbt.h"
{
xbt_mheap_t heapA = nullptr;
std::array<void*, TESTSIZE> pointers;
- xbt_init(&argc,argv);
+ simgrid_init(&argc, argv);
XBT_INFO("Allocating a new heap");
unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
src/xbt/log_private.hpp
src/xbt/mallocator_private.h
src/xbt/parmap.hpp
- src/xbt/xbt_modinter.h
src/xbt/mmalloc/mmalloc.h
src/xbt/mmalloc/mfree.c
src/xbt/xbt_log_appender_file.cpp
src/xbt/xbt_log_layout_format.cpp
src/xbt/xbt_log_layout_simple.cpp
- src/xbt/xbt_main.cpp
+ src/xbt/xbt_misc.cpp
src/xbt/xbt_os_file.cpp
src/xbt/xbt_os_time.c
src/xbt/xbt_parse_units.cpp
src/xbt/xbt_replay.cpp
src/xbt/xbt_str.cpp
- src/xbt/xbt_virtu.cpp
)
if(HAVE_MMALLOC)