From 0c4f427c0a32f68092bd4599436252865c122aca Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sat, 27 Dec 2025 14:15:17 -0400 Subject: [PATCH] Spinscale: PuppetComponent takes PuppetApplication& --- libspinscale/include/spinscale/component.h | 8 ++++--- .../include/spinscale/puppetApplication.h | 3 +++ libspinscale/src/component.cpp | 3 ++- libspinscale/src/puppetApplication.cpp | 17 +++++++++++++++ smocore/CMakeLists.txt | 3 +++ smocore/body/body.cpp | 16 +++++++++----- smocore/director/director.cpp | 6 ++++++ smocore/include/body/body.h | 1 + smocore/include/director/director.h | 6 ++---- smocore/include/mind.h | 5 +---- smocore/include/simulator/simulator.h | 6 ++---- smocore/mind.cpp | 21 ------------------- smocore/simulator/simulator.cpp | 13 ++++++++++++ 13 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 smocore/simulator/simulator.cpp diff --git a/libspinscale/include/spinscale/component.h b/libspinscale/include/spinscale/component.h index c288821..21e97cb 100644 --- a/libspinscale/include/spinscale/component.h +++ b/libspinscale/include/spinscale/component.h @@ -5,10 +5,10 @@ #include #include #include +#include namespace smo { -class Mind; class ComponentThread; class Component @@ -27,11 +27,13 @@ class PuppetComponent : public Component { public: - PuppetComponent(Mind &parent, const std::shared_ptr &thread); + PuppetComponent( + PuppetApplication &parent, + const std::shared_ptr &thread); ~PuppetComponent() = default; public: - Mind &parent; + PuppetApplication &parent; }; } // namespace smo diff --git a/libspinscale/include/spinscale/puppetApplication.h b/libspinscale/include/spinscale/puppetApplication.h index c13152e..40d796e 100644 --- a/libspinscale/include/spinscale/puppetApplication.h +++ b/libspinscale/include/spinscale/puppetApplication.h @@ -31,6 +31,9 @@ public: void exitAllPuppetThreadsReq( Callback callback); + // CPU distribution method + void distributeAndPinThreadsAcrossCpus(); + protected: // Collection of PuppetThread instances std::vector> componentThreads; diff --git a/libspinscale/src/component.cpp b/libspinscale/src/component.cpp index 3b86470..020952f 100644 --- a/libspinscale/src/component.cpp +++ b/libspinscale/src/component.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace smo { @@ -9,7 +10,7 @@ Component::Component(const std::shared_ptr &thread) } PuppetComponent::PuppetComponent( - Mind &parent, const std::shared_ptr &thread) + PuppetApplication &parent, const std::shared_ptr &thread) : Component(thread), parent(parent) { diff --git a/libspinscale/src/puppetApplication.cpp b/libspinscale/src/puppetApplication.cpp index c5e7cad..222b8be 100644 --- a/libspinscale/src/puppetApplication.cpp +++ b/libspinscale/src/puppetApplication.cpp @@ -201,4 +201,21 @@ void PuppetApplication::exitAllPuppetThreadsReq( } } +void PuppetApplication::distributeAndPinThreadsAcrossCpus() +{ + int cpuCount = ComponentThread::getAvailableCpuCount(); + + // Distribute and pin threads across CPUs + int threadIndex = 0; + for (auto& thread : componentThreads) + { + int targetCpu = threadIndex % cpuCount; + thread->pinToCpu(targetCpu); + ++threadIndex; + } + + std::cout << __func__ << ": Distributed " << threadIndex << " threads " + << "across " << cpuCount << " CPUs\n"; +} + } // namespace smo diff --git a/smocore/CMakeLists.txt b/smocore/CMakeLists.txt index 3344450..8579cc5 100644 --- a/smocore/CMakeLists.txt +++ b/smocore/CMakeLists.txt @@ -15,6 +15,9 @@ add_library(smocore STATIC # Director director/director.cpp + # Simulator + simulator/simulator.cpp + # Marionette marionette/main.cpp marionette/salmanoff.cpp diff --git a/smocore/body/body.cpp b/smocore/body/body.cpp index 62657ab..0aafe11 100644 --- a/smocore/body/body.cpp +++ b/smocore/body/body.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -23,14 +24,15 @@ class Body::InitializeReq { public: InitializeReq( - Mind &parent, const std::shared_ptr &caller, + PuppetApplication &parent, + const std::shared_ptr &caller, Callback callback) : PostedAsynchronousContinuation(caller, callback), parent(parent) {} private: - Mind &parent; + PuppetApplication &parent; public: void initializeReq1_posted( @@ -54,15 +56,17 @@ public: * We used to use Marionette, but there's a strong argument for using * Body instead since it's meant to handle device-management operations. */ + // Upcast to Mind to access Mind-specific members + Mind &mind = static_cast(context->parent); stim_buff::StimBuffApiManager::getInstance() - .loadAllStimBuffApiLibsFromOptions(parent.body.thread); + .loadAllStimBuffApiLibsFromOptions(mind.body.thread); /** EXPLANATION: * Consider body::initializeReq to have been called if even one of its * operations was executed at all, whether successfully or * unsuccessfully. */ - context->parent.bodyComponentInitialized = true; + mind.bodyComponentInitialized = true; std::cout << stim_buff::StimBuffApiManager::getInstance().stringifyLibs() << std::endl; @@ -176,7 +180,9 @@ void Body::finalizeReq(Callback callback) return; } - if (!parent.bodyComponentInitialized) + // Upcast to Mind to access Mind-specific members + Mind &mind = static_cast(parent); + if (!mind.bodyComponentInitialized) { std::cout << "Mrntt: Body component not initialized. " << "Skipping finalization." << "\n"; diff --git a/smocore/director/director.cpp b/smocore/director/director.cpp index a1fda4a..23d51dd 100644 --- a/smocore/director/director.cpp +++ b/smocore/director/director.cpp @@ -1,10 +1,16 @@ #include #include +#include #include namespace smo { namespace director { +Director::Director(Mind &parent, const std::shared_ptr &thread) +: PuppetComponent(static_cast(parent), thread) +{ +} + void Director::negtrinEventInd(void) { /** EXPLANATION: diff --git a/smocore/include/body/body.h b/smocore/include/body/body.h index 853df4d..eee8a26 100644 --- a/smocore/include/body/body.h +++ b/smocore/include/body/body.h @@ -1,6 +1,7 @@ #ifndef _BODY_COMPONENT_H #define _BODY_COMPONENT_H +#include #include #include #include diff --git a/smocore/include/director/director.h b/smocore/include/director/director.h index 01da807..488f406 100644 --- a/smocore/include/director/director.h +++ b/smocore/include/director/director.h @@ -2,6 +2,7 @@ #define DIRECTOR_H #include +#include #include #include #include @@ -17,10 +18,7 @@ class Director : public PuppetComponent { public: - Director(Mind &parent, const std::shared_ptr &thread) - : PuppetComponent(parent, thread) - {} - + Director(Mind &parent, const std::shared_ptr &thread); ~Director() = default; void negtrinEventInd(void); diff --git a/smocore/include/mind.h b/smocore/include/mind.h index 2838c66..1812fc8 100644 --- a/smocore/include/mind.h +++ b/smocore/include/mind.h @@ -7,8 +7,8 @@ #include #include -#include #include +#include #include #include #include @@ -35,9 +35,6 @@ public: // Get all this Mind's component threads. std::vector> getMindThreads() const; - // CPU distribution method - void distributeAndPinThreadsAcrossCpus(); - public: director::Director director; simulator::Simulator canvas; diff --git a/smocore/include/simulator/simulator.h b/smocore/include/simulator/simulator.h index 7989d8e..23657c4 100644 --- a/smocore/include/simulator/simulator.h +++ b/smocore/include/simulator/simulator.h @@ -2,6 +2,7 @@ #define SIMULATOR_H #include +#include #include #include @@ -16,10 +17,7 @@ class Simulator : public PuppetComponent { public: - Simulator(Mind &parent, const std::shared_ptr &thread) - : PuppetComponent(parent, thread) - {} - + Simulator(Mind &parent, const std::shared_ptr &thread); ~Simulator() = default; void initialize(); diff --git a/smocore/mind.cpp b/smocore/mind.cpp index 700e2a6..69c1bbb 100644 --- a/smocore/mind.cpp +++ b/smocore/mind.cpp @@ -245,25 +245,4 @@ void Mind::finalizeReq(Callback callback) request.get(), request))); } -void Mind::distributeAndPinThreadsAcrossCpus() -{ - int cpuCount = ComponentThread::getAvailableCpuCount(); - - if (OptionParser::getOptions().verbose) { - std::cout << __func__ << ": Available CPUs: " << cpuCount << "\n"; - } - - // Distribute and pin threads across CPUs - int threadIndex = 0; - for (auto& thread : componentThreads) - { - int targetCpu = threadIndex % cpuCount; - thread->pinToCpu(targetCpu); - ++threadIndex; - } - - std::cout << __func__ << ": Distributed " << threadIndex << " threads " - << "across " << cpuCount << " CPUs\n"; -} - } // namespace smo diff --git a/smocore/simulator/simulator.cpp b/smocore/simulator/simulator.cpp new file mode 100644 index 0000000..0911192 --- /dev/null +++ b/smocore/simulator/simulator.cpp @@ -0,0 +1,13 @@ +#include +#include + +namespace smo { +namespace simulator { + +Simulator::Simulator(Mind &parent, const std::shared_ptr &thread) +: PuppetComponent(static_cast(parent), thread) +{ +} + +} // namespace simulator +} // namespace smo