From 08d2586a862237f9b37da2326acd25757968f84d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 17 Jan 2025 18:57:10 +1000 Subject: [PATCH] System: Allow host to set async worker count For regtest. --- src/core/system.cpp | 6 ++---- src/core/system_private.h | 2 +- src/duckstation-qt/qthost.cpp | 5 ++++- src/duckstation-regtest/regtest_host.cpp | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index b92e9a0d2..bcead5cb1 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -115,8 +115,6 @@ SystemBootParameters::~SystemBootParameters() = default; namespace System { -static constexpr u32 NUM_ASYNC_WORKER_THREADS = 2; - static constexpr float PRE_FRAME_SLEEP_UPDATE_INTERVAL = 1.0f; static constexpr const char FALLBACK_EXE_NAME[] = "PSX.EXE"; static constexpr u32 MAX_SKIPPED_DUPLICATE_FRAME_COUNT = 2; // 20fps minimum @@ -497,7 +495,7 @@ void System::ProcessShutdown() CPU::CodeCache::ProcessShutdown(); } -bool System::CPUThreadInitialize(Error* error) +bool System::CPUThreadInitialize(Error* error, u32 async_worker_thread_count) { #ifdef _WIN32 // On Win32, we have a bunch of things which use COM (e.g. SDL, Cubeb, etc). @@ -516,7 +514,7 @@ bool System::CPUThreadInitialize(Error* error) LogStartupInformation(); - s_state.async_task_queue.SetWorkerCount(NUM_ASYNC_WORKER_THREADS); + s_state.async_task_queue.SetWorkerCount(async_worker_thread_count); GPUThread::Internal::ProcessStartup(); diff --git a/src/core/system_private.h b/src/core/system_private.h index e6fc714c3..964f38a43 100644 --- a/src/core/system_private.h +++ b/src/core/system_private.h @@ -60,7 +60,7 @@ bool ProcessStartup(Error* error); void ProcessShutdown(); /// Called on CPU thread initialization. -bool CPUThreadInitialize(Error* error); +bool CPUThreadInitialize(Error* error, u32 async_worker_thread_count); /// Called on CPU thread shutdown. void CPUThreadShutdown(); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 2ead351cd..95dcc7679 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -77,6 +77,9 @@ LOG_CHANNEL(Host); static constexpr u32 SETTINGS_VERSION = 3; static constexpr u32 SETTINGS_SAVE_DELAY = 1000; +/// Use two async worker threads, should be enough for most tasks. +static constexpr u32 NUM_ASYNC_WORKER_THREADS = 2; + /// Interval at which the controllers are polled when the system is not active. static constexpr u32 BACKGROUND_CONTROLLER_POLLING_INTERVAL = 100; @@ -1844,7 +1847,7 @@ void EmuThread::run() // input source setup must happen on emu thread { Error startup_error; - if (!System::CPUThreadInitialize(&startup_error)) + if (!System::CPUThreadInitialize(&startup_error, NUM_ASYNC_WORKER_THREADS)) { moveToThread(m_ui_thread); Host::ReportFatalError("Fatal Startup Error", startup_error.GetDescription()); diff --git a/src/duckstation-regtest/regtest_host.cpp b/src/duckstation-regtest/regtest_host.cpp index bcb3aee90..6c6cefb81 100644 --- a/src/duckstation-regtest/regtest_host.cpp +++ b/src/duckstation-regtest/regtest_host.cpp @@ -813,7 +813,8 @@ int main(int argc, char* argv[]) if (!RegTestHost::SetNewDataRoot(autoboot->filename)) return EXIT_FAILURE; - if (!System::CPUThreadInitialize(&startup_error)) + // Only one async worker. + if (!System::CPUThreadInitialize(&startup_error, 1)) { ERROR_LOG("CPUThreadInitialize() failed: {}", startup_error.GetDescription()); return EXIT_FAILURE;