diff --git a/src/common/MediaFactory.hxx b/src/common/MediaFactory.hxx index b2b5678f1..06237ce54 100644 --- a/src/common/MediaFactory.hxx +++ b/src/common/MediaFactory.hxx @@ -31,6 +31,8 @@ #if defined(RETRON77) #include "SettingsR77.hxx" #include "OSystemR77.hxx" + #elif defined(RTSTELLA) + #include "OSystemRTStella.hxx" #else #include "OSystemUNIX.hxx" #endif @@ -92,6 +94,8 @@ class MediaFactory #if defined(BSPF_UNIX) #if defined(RETRON77) return make_unique(); + #elif defined(RTSTELLA) + return make_unique(); #else return make_unique(); #endif diff --git a/src/os/rtstella/OSystemRTStella.cxx b/src/os/rtstella/OSystemRTStella.cxx new file mode 100644 index 000000000..0b95f3339 --- /dev/null +++ b/src/os/rtstella/OSystemRTStella.cxx @@ -0,0 +1,36 @@ +#include "OSystemRTStella.hxx" + +#include +#include +#include + +#include "Logger.hxx" + +namespace { + void configureScheduler() { + const int cores = get_nprocs(); + if (cores < 2) { + Logger::error("failed to set scheduling affinity on main thread - not enough cores"); + return; + } + + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + for (int i = 0; i < cores - 1; i++) CPU_SET(i, &cpuset); + + if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0){ + ostringstream ss; + ss << "failed to pin main and auxiliary thread: " << errno; + + Logger::error(ss.str()); + } + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool OSystemRTStella::initialize(const Settings::Options& options) +{ + configureScheduler(); + + return OSystemStandalone::initialize(options); +} diff --git a/src/os/rtstella/OSystemRTStella.hxx b/src/os/rtstella/OSystemRTStella.hxx new file mode 100644 index 000000000..72e1abe80 --- /dev/null +++ b/src/os/rtstella/OSystemRTStella.hxx @@ -0,0 +1,28 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2023 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef OSYSTEM_RTSTELLA_HXX +#define OSYSTEM_RTSTELLA_HXX + +#include "OSystemStandalone.hxx" + +class OSystemRTStella: public OSystemStandalone { + public: + bool initialize(const Settings::Options& options) override; +}; + +#endif // OSYSTEM_RTSTELLA_HXX diff --git a/src/os/rtstella/RTEmulationWorker.cxx b/src/os/rtstella/RTEmulationWorker.cxx index 2c7c3c137..3a6cd22f8 100644 --- a/src/os/rtstella/RTEmulationWorker.cxx +++ b/src/os/rtstella/RTEmulationWorker.cxx @@ -34,7 +34,7 @@ namespace { const int cores = get_nprocs(); if (cores < 2) { - Logger::error("failed to set scheduling affinity - not enough cores"); + Logger::error("failed to set scheduling affinity on emulation worker - not enough cores"); return; } @@ -44,7 +44,7 @@ namespace { if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0){ ostringstream ss; - ss << "failed to pin thread: " << errno; + ss << "failed to pin worker thread: " << errno; Logger::error(ss.str()); } diff --git a/src/os/rtstella/module.mk b/src/os/rtstella/module.mk index e3a48e334..56384ae90 100644 --- a/src/os/rtstella/module.mk +++ b/src/os/rtstella/module.mk @@ -1,7 +1,9 @@ MODULE := src/os/rtstella MODULE_OBJS := \ - src/os/rtstella/Spinlock.o src/os/rtstella/RTEmulationWorker.o + src/os/rtstella/Spinlock.o \ + src/os/rtstella/RTEmulationWorker.o \ + src/os/rtstella/OSystemRTStella.o MODULE_DIRS += \ src/os/rtstella