Mind: Distribute and pin Mind threads to CPUs

At startup, Marionette will distribute and pin the Mind
threads across the available CPUs, warning if it couldn't
do so.
This commit is contained in:
2025-08-03 09:18:45 -04:00
parent 1deb92a416
commit 285b63b618
4 changed files with 97 additions and 0 deletions
+10
View File
@@ -8,6 +8,9 @@
#include <stdexcept>
#include <queue>
#include <functional>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
namespace smo {
@@ -29,6 +32,7 @@ public:
ComponentThread(ThreadId id)
: id(id), name(getThreadName(id)),
work(io_service), pause_work(pause_io_service),
pinnedCpuId(-1),
thread(
((id == MRNTT) ? marionetteMain : main),
std::ref(*this))
@@ -87,6 +91,11 @@ public:
static void exitAllMindThreadsReq(std::function<void()> callback = nullptr);
static void joltAllMindThreadsReq(std::function<void()> callback = nullptr);
// CPU management methods
static int getAvailableCpuCount();
void pinToCpu(int cpuId);
static void distributeAndPinThreadsAcrossCpus();
enum class ThreadOp
{
START,
@@ -110,6 +119,7 @@ public:
boost::asio::io_service pause_io_service;
boost::asio::io_service::work pause_work;
std::atomic<bool> keepLooping;
int pinnedCpuId;
/* Always ensure that this is last so that the thread is spawned after
* everything else is constructed.