Spinscale: PuppetComponent takes PuppetApplication&
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,9 @@ add_library(smocore STATIC
|
||||
# Director
|
||||
director/director.cpp
|
||||
|
||||
# Simulator
|
||||
simulator/simulator.cpp
|
||||
|
||||
# Marionette
|
||||
marionette/main.cpp
|
||||
marionette/salmanoff.cpp
|
||||
|
||||
+11
-5
@@ -4,6 +4,7 @@
|
||||
#include <spinscale/asynchronousLoop.h>
|
||||
#include <spinscale/callback.h>
|
||||
#include <spinscale/callableTracer.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <body/body.h>
|
||||
#include <componentThread.h>
|
||||
#include <mind.h>
|
||||
@@ -23,14 +24,15 @@ class Body::InitializeReq
|
||||
{
|
||||
public:
|
||||
InitializeReq(
|
||||
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
|
||||
PuppetApplication &parent,
|
||||
const std::shared_ptr<ComponentThread> &caller,
|
||||
Callback<bodyLifetimeMgmtOpCbFn> callback)
|
||||
: PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(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<Mind&>(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<bodyLifetimeMgmtOpCbFn> callback)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parent.bodyComponentInitialized)
|
||||
// Upcast to Mind to access Mind-specific members
|
||||
Mind &mind = static_cast<Mind&>(parent);
|
||||
if (!mind.bodyComponentInitialized)
|
||||
{
|
||||
std::cout << "Mrntt: Body component not initialized. "
|
||||
<< "Skipping finalization." << "\n";
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
#include <iostream>
|
||||
#include <director/director.h>
|
||||
#include <mind.h>
|
||||
#include <goal.h>
|
||||
|
||||
namespace smo {
|
||||
namespace director {
|
||||
|
||||
Director::Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
|
||||
{
|
||||
}
|
||||
|
||||
void Director::negtrinEventInd(void)
|
||||
{
|
||||
/** EXPLANATION:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef _BODY_COMPONENT_H
|
||||
#define _BODY_COMPONENT_H
|
||||
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <spinscale/component.h>
|
||||
#include <functional>
|
||||
#include <spinscale/callback.h>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define DIRECTOR_H
|
||||
|
||||
#include <config.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <spinscale/component.h>
|
||||
#include <goal.h>
|
||||
#include <lruLifo.h>
|
||||
@@ -17,10 +18,7 @@ class Director
|
||||
: public PuppetComponent
|
||||
{
|
||||
public:
|
||||
Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
: PuppetComponent(parent, thread)
|
||||
{}
|
||||
|
||||
Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
||||
~Director() = default;
|
||||
|
||||
void negtrinEventInd(void);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <string>
|
||||
#include <spinscale/callback.h>
|
||||
|
||||
#include <spinscale/component.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <spinscale/component.h>
|
||||
#include <componentThread.h>
|
||||
#include <mindThread.h>
|
||||
#include <director/director.h>
|
||||
@@ -35,9 +35,6 @@ public:
|
||||
// Get all this Mind's component threads.
|
||||
std::vector<std::shared_ptr<MindThread>> getMindThreads() const;
|
||||
|
||||
// CPU distribution method
|
||||
void distributeAndPinThreadsAcrossCpus();
|
||||
|
||||
public:
|
||||
director::Director director;
|
||||
simulator::Simulator canvas;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SIMULATOR_H
|
||||
|
||||
#include <config.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <spinscale/component.h>
|
||||
#include <simulator/scene.h>
|
||||
|
||||
@@ -16,10 +17,7 @@ class Simulator
|
||||
: public PuppetComponent
|
||||
{
|
||||
public:
|
||||
Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
: PuppetComponent(parent, thread)
|
||||
{}
|
||||
|
||||
Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
||||
~Simulator() = default;
|
||||
|
||||
void initialize();
|
||||
|
||||
@@ -245,25 +245,4 @@ void Mind::finalizeReq(Callback<mindLifetimeMgmtOpCbFn> 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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <simulator/simulator.h>
|
||||
#include <mind.h>
|
||||
|
||||
namespace smo {
|
||||
namespace simulator {
|
||||
|
||||
Simulator::Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace simulator
|
||||
} // namespace smo
|
||||
Reference in New Issue
Block a user