Spinscale: PuppetComponent takes PuppetApplication&

This commit is contained in:
2025-12-27 14:15:17 -04:00
parent f862db922e
commit 0c4f427c0a
13 changed files with 66 additions and 42 deletions
+5 -3
View File
@@ -5,10 +5,10 @@
#include <memory>
#include <functional>
#include <spinscale/callback.h>
#include <spinscale/puppetApplication.h>
namespace smo {
class Mind;
class ComponentThread;
class Component
@@ -27,11 +27,13 @@ class PuppetComponent
: public Component
{
public:
PuppetComponent(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
PuppetComponent(
PuppetApplication &parent,
const std::shared_ptr<ComponentThread> &thread);
~PuppetComponent() = default;
public:
Mind &parent;
PuppetApplication &parent;
};
} // namespace smo
@@ -31,6 +31,9 @@ public:
void exitAllPuppetThreadsReq(
Callback<puppetThreadLifetimeMgmtOpCbFn> callback);
// CPU distribution method
void distributeAndPinThreadsAcrossCpus();
protected:
// Collection of PuppetThread instances
std::vector<std::shared_ptr<PuppetThread>> componentThreads;
+2 -1
View File
@@ -1,4 +1,5 @@
#include <spinscale/component.h>
#include <spinscale/puppetApplication.h>
#include <marionette/marionette.h>
namespace smo {
@@ -9,7 +10,7 @@ Component::Component(const std::shared_ptr<ComponentThread> &thread)
}
PuppetComponent::PuppetComponent(
Mind &parent, const std::shared_ptr<ComponentThread> &thread)
PuppetApplication &parent, const std::shared_ptr<ComponentThread> &thread)
: Component(thread),
parent(parent)
{
+17
View File
@@ -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