Work toward making EngineImpl::initialize() the only entry point of
the library initialization. It's now impossible to initialize xbt
separately of EngineImpl.
It should help reducing the mess in that code, which results from the
many ways of initializing the library. simgrid-mc, unit-tests, smpi
and others each have their own way of initializing everything,
resulting in a spagetthi and fragile code. It's a bit of a waste to
initialize an EngineImpl even when you don't want to actually run a
simulation, but easier code is always better.
This commit also includes another one because I git amended locally by
error, sorry for the mess. The other commit was about the deprecation
of xbt_procname and xbt_getpid that were xbt functions relying on S4U.
23 files changed:
include src/xbt/xbt_replay.cpp
include src/xbt/xbt_str.cpp
include src/xbt/xbt_str_test.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
include teshsuite/kernel/CMakeLists.txt
include teshsuite/mc/CMakeLists.txt
include teshsuite/models/CMakeLists.txt
/** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */
#define XBT_THROW_POINT \
/** 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:
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();
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);
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 */
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.
*
/** Creates a new platform, including hosts, links, and the routing table.
*
#include <xbt/asserts.h>
#include <xbt/log.h>
#include <xbt/asserts.h>
#include <xbt/log.h>
-#include <xbt/module.h>
-
#include <xbt/dynar.h>
#include <xbt/dict.h>
#include <xbt/dynar.h>
#include <xbt/dict.h>
#ifndef XBT_MODULE_H
#define XBT_MODULE_H
#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>
-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);
+}
#ifndef XBT_VIRTU_H
#define XBT_VIRTU_H
#ifndef XBT_VIRTU_H
#define XBT_VIRTU_H
+#include <simgrid/actor.h>
#include <xbt/base.h>
#ifdef __cplusplus
#include <xbt/base.h>
#ifdef __cplusplus
-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() ?: "maestro";
+}
-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();
+};
#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 "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/log.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <dlfcn.h>
#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};
+static void xbt_postexit()
+{
+ if (not cfg_dbg_clean_atexit)
+ return;
+ xbt_log_postexit();
+}
+
namespace simgrid::kernel {
EngineImpl::~EngineImpl()
namespace simgrid::kernel {
EngineImpl::~EngineImpl()
simgrid::mc::AppSide::initialize();
#endif
simgrid::mc::AppSide::initialize();
#endif
- if (xbt_initialized == 0) {
- xbt_init(argc, argv);
+ static bool inited = false;
+ if (not inited) {
+ inited = true;
+ atexit(xbt_postexit);
+ xbt_log_init(argc, argv);
+
+ 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]);
sg_config_init(argc, argv);
}
sg_config_init(argc, argv);
}
/* register a function to be called after the environment creation */
s4u::Engine::on_platform_created_cb([this]() { this->presolve(); });
/* 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)
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/kernel/resource/profile/StochasticDatedValue.hpp"
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/kernel/resource/profile/StochasticDatedValue.hpp"
+
+#include "xbt/asserts.h"
#include "xbt/random.hpp"
#include "xbt/random.hpp"
#include <math.h>
namespace simgrid::kernel::profile {
#include <math.h>
namespace simgrid::kernel::profile {
- return simgrid::kernel::actor::ActorImpl::self()->get_pid();
+ auto* self = simgrid::kernel::actor::ActorImpl::self();
+ return self ? self->get_pid() : 0;
const char* get_cname()
{
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;
const char* sg_actor_self_get_name()
{
const char* sg_actor_self_get_name()
{
+ if (simgrid::s4u::Actor::is_maestro())
+ return "maestro";
return simgrid::s4u::this_actor::get_cname();
}
return simgrid::s4u::this_actor::get_cname();
}
/* **************************** Public C interface *************************** */
void simgrid_init(int* argc, char** argv)
{
/* **************************** 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)
{
}
void simgrid_load_platform(const char* file)
{
XBT_WARN("Call to sg_config_init() after initialization ignored");
return;
}
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);
/* 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};
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());
sg_config_cmd_line(argc, argv);
xbt_mallocator_initialization_is_done(simgrid::kernel::context::Context::is_parallel());
#include "src/internal_config.h"
#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/backtrace.hpp>
#include <xbt/string.hpp>
#include <xbt/sysdep.h>
#include <cstdio>
#include <cstdlib>
#include <cstdio>
#include <cstdlib>
void Backtrace::display() const
{
std::string backtrace = resolve();
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());
}
(xbt_log_no_loc ? " -- short trace because of --log=no_loc" : ""),
backtrace.empty() ? "(backtrace not set -- did you install Boost.Stacktrace?)" : backtrace.c_str());
}
void _xbt_throw(char* message, const char* file, int line, const char* func)
{
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;
}
xbt_free(message);
throw e;
}
#include "simgrid/host.h"
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
#include "simgrid/host.h"
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
+#include <simgrid/actor.h>
+#include <simgrid/s4u/Actor.hpp>
+
#include <algorithm>
#include <cstdio>
#include <algorithm>
#include <cstdio>
} else \
(void)0
#define show_int(data) show_it((data), "d")
} 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)
#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 */
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 */
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);
break;
case 'F': /* file name; LOG4J compliant */
show_string(ev->fileName);
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.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 */
#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 */
check_overflow(1);
/* Display the proc info if available */
- procname = xbt_procname();
+ procname = sg_actor_self_get_name();
if (procname && strcmp(procname,"maestro")) {
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) {
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());
#include "xbt/log.h"
#include "xbt/log.hpp"
#include "xbt/misc.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 "xbt/sysdep.h"
#include <cmath>
std::vector<std::string> cmdline; /* all we got in argv */
} // namespace simgrid::xbt
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));
const int xbt_pagesize = static_cast<int>(sysconf(_SC_PAGESIZE));
const int xbt_pagebits = static_cast<int>(log2(xbt_pagesize));
-static void xbt_postexit()
-{
- if (not cfg_dbg_clean_atexit)
- return;
- xbt_initialized--;
- 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;
- }
- atexit(xbt_postexit);
-
- 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))
/* 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))
void xbt_log_postexit(void);
void xbt_log_postexit(void);
-extern int xbt_initialized;
-
+++ /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 "simgrid/s4u/Engine.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "xbt/log.h"
#include "xbt/sysdep.h"
#include <algorithm>
#include <array>
#include "xbt/sysdep.h"
#include <algorithm>
#include <array>
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "xbt/random.hpp"
#include "xbt/sysdep.h" /* time manipulation for benchmarking */
#include "xbt/xbt_os_time.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"
* 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"
#include "src/xbt/mmalloc/mmalloc.h"
#include "xbt.h"
{
xbt_mheap_t heapA = nullptr;
std::array<void*, TESTSIZE> pointers;
{
xbt_mheap_t heapA = nullptr;
std::array<void*, TESTSIZE> pointers;
+ simgrid_init(&argc, argv);
XBT_INFO("Allocating a new heap");
unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
XBT_INFO("Allocating a new heap");
unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
src/xbt/xbt_parse_units.cpp
src/xbt/xbt_replay.cpp
src/xbt/xbt_str.cpp
src/xbt/xbt_parse_units.cpp
src/xbt/xbt_replay.cpp
src/xbt/xbt_str.cpp