diff --git a/Core/Config.cpp b/Core/Config.cpp index 128ab7179f..31cbb554df 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -337,6 +337,7 @@ static ConfigSetting cpuSettings[] = { ConfigSetting("AtomicAudioLocks", &g_Config.bAtomicAudioLocks, false, true, true), ReportedConfigSetting("SeparateIOThread", &g_Config.bSeparateIOThread, true, true, true), + ReportedConfigSetting("IOTimingMethod", &g_Config.iIOTimingMethod, IOTIMING_FAST, true, true), ConfigSetting("FastMemoryAccess", &g_Config.bFastMemory, true, true, true), ReportedConfigSetting("FuncReplacements", &g_Config.bFuncReplacements, true, true, true), ReportedConfigSetting("CPUSpeed", &g_Config.iLockedCPUSpeed, 0, true, true), diff --git a/Core/Config.h b/Core/Config.h index 7aebc374d3..46779cef23 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -50,6 +50,13 @@ enum { GPU_BACKEND_DIRECT3D9 = 1, }; +// For iIOTimingMethod. +enum IOTimingMethods { + IOTIMING_FAST = 0, + IOTIMING_HOST = 1, + IOTIMING_REALISTIC = 2, +}; + namespace http { class Download; class Downloader; @@ -109,6 +116,7 @@ public: // Definitely cannot be changed while game is running. bool bSeparateCPUThread; + int iIOTimingMethod; bool bSeparateIOThread; bool bAtomicAudioLocks; int iLockedCPUSpeed; diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 6b2d4cee80..7dc150342b 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -240,7 +240,7 @@ public: /******************************************************************************/ -void __IoCompleteAsyncIO(int fd); +void __IoCompleteAsyncIO(FileNode *f); static void TellFsThreadEnded (SceUID threadID) { pspFileSystem.ThreadEnded(threadID); @@ -305,7 +305,6 @@ static void __IoFreeFd(int fd, u32 &error) { // For now, let's at least delay the callback mnotification. static void __IoAsyncNotify(u64 userdata, int cyclesLate) { int fd = (int) userdata; - __IoCompleteAsyncIO(fd); u32 error; FileNode *f = __IoGetFd(fd, error); @@ -314,6 +313,16 @@ static void __IoAsyncNotify(u64 userdata, int cyclesLate) { return; } + if (g_Config.iIOTimingMethod == IOTIMING_HOST) { + if (!ioManager.HasResult(f->handle)) { + // Try again in another 0.5ms until the IO completes on the host. + CoreTiming::ScheduleEvent(usToCycles(500) - cyclesLate, asyncNotifyEvent, userdata); + return; + } + } + + __IoCompleteAsyncIO(f); + if (f->waitingThreads.empty()) { return; } @@ -350,6 +359,14 @@ static void __IoSyncNotify(u64 userdata, int cyclesLate) { return; } + if (g_Config.iIOTimingMethod == IOTIMING_HOST) { + if (!ioManager.HasResult(f->handle)) { + // Try again in another 0.5ms until the IO completes on the host. + CoreTiming::ScheduleEvent(usToCycles(500) - cyclesLate, syncNotifyEvent, userdata); + return; + } + } + f->pendingAsyncResult = false; f->hasAsyncResult = false; @@ -567,22 +584,18 @@ static u32 sceKernelStderr() { return PSP_STDERR; } -void __IoCompleteAsyncIO(int fd) { - u32 error; - FileNode *f = __IoGetFd(fd, error); - if (f) { - AsyncIOResult managerResult; - if (ioManager.WaitResult(f->handle, managerResult)) { - f->asyncResult = managerResult; - } else { - // It's okay, not all operations are deferred. - } - if (f->callbackID) { - __KernelNotifyCallback(f->callbackID, f->callbackArg); - } - f->pendingAsyncResult = false; - f->hasAsyncResult = true; +void __IoCompleteAsyncIO(FileNode *f) { + AsyncIOResult managerResult; + if (ioManager.WaitResult(f->handle, managerResult)) { + f->asyncResult = managerResult; + } else { + // It's okay, not all operations are deferred. } + if (f->callbackID) { + __KernelNotifyCallback(f->callbackID, f->callbackArg); + } + f->pendingAsyncResult = false; + f->hasAsyncResult = true; } void __IoCopyDate(ScePspDateTime& date_out, const tm& date_in) diff --git a/Core/HW/AsyncIOManager.cpp b/Core/HW/AsyncIOManager.cpp index c022f16404..d3ff681ba5 100644 --- a/Core/HW/AsyncIOManager.cpp +++ b/Core/HW/AsyncIOManager.cpp @@ -47,6 +47,11 @@ void AsyncIOManager::Shutdown() { results_.clear(); } +bool AsyncIOManager::HasResult(u32 handle) { + lock_guard guard(resultsLock_); + return results_.find(handle) != results_.end(); +} + bool AsyncIOManager::PopResult(u32 handle, AsyncIOResult &result) { lock_guard guard(resultsLock_); if (results_.find(handle) != results_.end()) { diff --git a/Core/HW/AsyncIOManager.h b/Core/HW/AsyncIOManager.h index 76d6f5e7f9..643814236a 100644 --- a/Core/HW/AsyncIOManager.h +++ b/Core/HW/AsyncIOManager.h @@ -55,6 +55,7 @@ public: void ScheduleOperation(AsyncIOEvent ev); void Shutdown(); + bool HasResult(u32 handle); bool PopResult(u32 handle, AsyncIOResult &result); bool WaitResult(u32 handle, AsyncIOResult &result); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index b134433370..b26ba3a0ae 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -392,6 +392,9 @@ void GameSettingsScreen::CreateViews() { systemSettings->Add(new CheckBox(&g_Config.bSeparateCPUThread, s->T("Multithreaded (experimental)"))); systemSettings->Add(new CheckBox(&g_Config.bSeparateIOThread, s->T("I/O on thread (experimental)")))->SetEnabled(!PSP_IsInited()); + static const char *ioTimingMethods[] = { "Fast (lag on slow storage)", "Host (bugs, less lag)" }; + View *ioTimingMethod = systemSettings->Add(new PopupMultiChoice(&g_Config.iIOTimingMethod, s->T("IO timing method"), ioTimingMethods, 0, ARRAY_SIZE(ioTimingMethods), s, screenManager())); + ioTimingMethod->SetEnabledPtr(&g_Config.bSeparateIOThread); systemSettings->Add(new CheckBox(&g_Config.bForceLagSync, s->T("Force real clock sync (slower, less lag)"))); systemSettings->Add(new PopupSliderChoice(&g_Config.iLockedCPUSpeed, 0, 1000, s->T("Change CPU Clock", "Change CPU Clock (0 = default) (unstable)"), screenManager())); #ifndef MOBILE_DEVICE