OSystem for rtstella

This commit is contained in:
Christian Speckner 2023-09-20 21:16:37 +02:00
parent 405397d1fa
commit 341dbb2b6f
5 changed files with 73 additions and 3 deletions

View File

@ -31,6 +31,8 @@
#if defined(RETRON77) #if defined(RETRON77)
#include "SettingsR77.hxx" #include "SettingsR77.hxx"
#include "OSystemR77.hxx" #include "OSystemR77.hxx"
#elif defined(RTSTELLA)
#include "OSystemRTStella.hxx"
#else #else
#include "OSystemUNIX.hxx" #include "OSystemUNIX.hxx"
#endif #endif
@ -92,6 +94,8 @@ class MediaFactory
#if defined(BSPF_UNIX) #if defined(BSPF_UNIX)
#if defined(RETRON77) #if defined(RETRON77)
return make_unique<OSystemR77>(); return make_unique<OSystemR77>();
#elif defined(RTSTELLA)
return make_unique<OSystemRTStella>();
#else #else
return make_unique<OSystemUNIX>(); return make_unique<OSystemUNIX>();
#endif #endif

View File

@ -0,0 +1,36 @@
#include "OSystemRTStella.hxx"
#include <sstream>
#include <sched.h>
#include <sys/sysinfo.h>
#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);
}

View File

@ -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

View File

@ -34,7 +34,7 @@ namespace {
const int cores = get_nprocs(); const int cores = get_nprocs();
if (cores < 2) { 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; return;
} }
@ -44,7 +44,7 @@ namespace {
if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0){ if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0){
ostringstream ss; ostringstream ss;
ss << "failed to pin thread: " << errno; ss << "failed to pin worker thread: " << errno;
Logger::error(ss.str()); Logger::error(ss.str());
} }

View File

@ -1,7 +1,9 @@
MODULE := src/os/rtstella MODULE := src/os/rtstella
MODULE_OBJS := \ 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 += \ MODULE_DIRS += \
src/os/rtstella src/os/rtstella