diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp index da225e40..f9e97c2d 100644 --- a/src/base/kernel/Entry.cpp +++ b/src/base/kernel/Entry.cpp @@ -41,6 +41,9 @@ #include "version.h" +namespace xmrig { + + static int showVersion() { printf(APP_NAME " " APP_VERSION "\n built on " __DATE__ @@ -92,6 +95,36 @@ static int showVersion() } +#ifdef XMRIG_FEATURE_HWLOC +static int exportTopology(const Process &process) +{ + const String path = process.location(Process::ExeLocation, "topology.xml"); + + hwloc_topology_t topology; + hwloc_topology_init(&topology); + hwloc_topology_load(topology); + +# if HWLOC_API_VERSION >= 0x20000 + if (hwloc_topology_export_xml(topology, path, 0) == -1) { +# else + if (hwloc_topology_export_xml(topology, path) == -1) { +# endif + printf("failed to export hwloc topology.\n"); + } + else { + printf("hwloc topology successfully exported to \"%s\"\n", path.data()); + } + + hwloc_topology_destroy(topology); + + return 0; +} +#endif + + +} // namespace xmrig + + xmrig::Entry::Id xmrig::Entry::get(const Process &process) { const Arguments &args = process.arguments(); @@ -103,11 +136,17 @@ xmrig::Entry::Id xmrig::Entry::get(const Process &process) return Version; } +# ifdef XMRIG_FEATURE_HWLOC + if (args.hasArg("--export-topology")) { + return Topo; + } +# endif + return Default; } -int xmrig::Entry::exec(const Process &, Id id) +int xmrig::Entry::exec(const Process &process, Id id) { switch (id) { case Usage: @@ -117,6 +156,11 @@ int xmrig::Entry::exec(const Process &, Id id) case Version: return showVersion(); +# ifdef XMRIG_FEATURE_HWLOC + case Topo: + return exportTopology(process); +# endif + default: break; } diff --git a/src/base/kernel/Entry.h b/src/base/kernel/Entry.h index 0208ecdb..c0bde080 100644 --- a/src/base/kernel/Entry.h +++ b/src/base/kernel/Entry.h @@ -38,7 +38,8 @@ public: enum Id { Default, Usage, - Version + Version, + Topo }; static Id get(const Process &process); diff --git a/src/core/config/usage.h b/src/core/config/usage.h index 275a58f9..b41ec6db 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -113,6 +113,10 @@ Options:\n\ --randomx-init=N threads count to initialize RandomX dataset\n\ --randomx-no-numa disable NUMA support for RandomX\n" #endif +#ifdef XMRIG_FEATURE_HWLOC +"\ + --export-topology export hwloc topology to a XML file and exit\n" +#endif "\ --dry-run test configuration and exit\n\ -h, --help display this help and exit\n\