From c5a571ebc7739bf52eb0a0ef3b15dc8702aa20d3 Mon Sep 17 00:00:00 2001 From: Adrien Cassagne Date: Tue, 30 Jul 2024 09:57:09 +0200 Subject: [PATCH] Add 'tools::Thread_pinning::is_init()' method. --- .../Tools/Thread_pinning/Thread_pinning.hpp | 1 + src/Scheduler/Scheduler.cpp | 3 ++- src/Tools/Thread_pinning/Thread_pinning.cpp | 20 ++++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/Tools/Thread_pinning/Thread_pinning.hpp b/include/Tools/Thread_pinning/Thread_pinning.hpp index f3ba22a..2b93851 100644 --- a/include/Tools/Thread_pinning/Thread_pinning.hpp +++ b/include/Tools/Thread_pinning/Thread_pinning.hpp @@ -10,6 +10,7 @@ namespace tools class Thread_pinning { public: + static bool is_init(); static void init(); static void destroy(); static void pin(const size_t puid); diff --git a/src/Scheduler/Scheduler.cpp b/src/Scheduler/Scheduler.cpp index 896dec3..073c451 100644 --- a/src/Scheduler/Scheduler.cpp +++ b/src/Scheduler/Scheduler.cpp @@ -1,5 +1,6 @@ #include "Scheduler/Scheduler.hpp" #include "Tools/Exception/exception.hpp" +#include "Tools/Thread_pinning/Thread_pinning.hpp" #include #include @@ -201,5 +202,5 @@ Scheduler::generate_pipeline() if (solution.empty()) this->schedule(); - return this->instantiate_pipeline(1, false, true, this->perform_threads_mapping()); + return this->instantiate_pipeline(1, false, tools::Thread_pinning::is_init(), this->perform_threads_mapping()); } diff --git a/src/Tools/Thread_pinning/Thread_pinning.cpp b/src/Tools/Thread_pinning/Thread_pinning.cpp index c528afe..9574d43 100644 --- a/src/Tools/Thread_pinning/Thread_pinning.cpp +++ b/src/Tools/Thread_pinning/Thread_pinning.cpp @@ -25,13 +25,19 @@ static bool g_is_init = false; static std::mutex g_mtx; static bool g_enable_logs = false; +bool +Thread_pinning::is_init() +{ + return g_is_init; +} + void Thread_pinning::init() { - if (!g_is_init) + if (!Thread_pinning::is_init()) { g_mtx.lock(); - if (!g_is_init) + if (!Thread_pinning::is_init()) { g_is_init = true; @@ -60,10 +66,10 @@ Thread_pinning::init() void Thread_pinning::destroy() { - if (g_is_init) + if (Thread_pinning::is_init()) { g_mtx.lock(); - if (g_is_init) + if (Thread_pinning::is_init()) { #ifdef SPU_HWLOC /* Destroy topology object. */ @@ -95,7 +101,7 @@ Thread_pinning::pin(const size_t puid) { g_mtx.lock(); #ifdef SPU_HWLOC - if (g_is_init) + if (Thread_pinning::is_init()) { int pu_depth = hwloc_get_type_or_below_depth(g_topology, HWLOC_OBJ_PU); hwloc_obj_t pu_obj = hwloc_get_obj_by_depth(g_topology, pu_depth, puid); @@ -162,7 +168,7 @@ Thread_pinning::pin(const std::string hwloc_objects) g_mtx.lock(); #ifdef SPU_HWLOC - if (g_is_init) + if (Thread_pinning::is_init()) { // Objects parsing std::vector hwloc_objects_vector = Thread_pinning_utils::thread_parser(hwloc_objects); @@ -242,7 +248,7 @@ Thread_pinning::unpin() { g_mtx.lock(); #ifdef SPU_HWLOC - if (!g_is_init) + if (!Thread_pinning::is_init()) { if (g_enable_logs) {