Merge pull request #12620 from mitaclaw/jit-interface-cpu-thread-guard

JitInterface::ClearCache: Modernize With CPUThreadGuard
This commit is contained in:
Admiral H. Curtiss 2024-03-22 04:17:33 +01:00 committed by GitHub
commit f814dc58b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 52 additions and 53 deletions

View File

@ -408,12 +408,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling
jboolean enable) jboolean enable)
{ {
HostThreadLock guard; HostThreadLock guard;
Core::SetState(Core::State::Paused); auto& system = Core::System::GetInstance();
auto& jit_interface = Core::System::GetInstance().GetJitInterface(); auto& jit_interface = system.GetJitInterface();
jit_interface.ClearCache(); const Core::CPUThreadGuard cpu_guard(system);
jit_interface.ClearCache(cpu_guard);
jit_interface.SetProfilingState(enable ? JitInterface::ProfilingState::Enabled : jit_interface.SetProfilingState(enable ? JitInterface::ProfilingState::Enabled :
JitInterface::ProfilingState::Disabled); JitInterface::ProfilingState::Disabled);
Core::SetState(Core::State::Running);
} }
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv*, JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv*,

View File

@ -1006,18 +1006,17 @@ void UpdateWantDeterminism(Core::System& system, bool initial)
{ {
NOTICE_LOG_FMT(COMMON, "Want determinism <- {}", new_want_determinism ? "true" : "false"); NOTICE_LOG_FMT(COMMON, "Want determinism <- {}", new_want_determinism ? "true" : "false");
RunAsCPUThread([&] { const Core::CPUThreadGuard guard(system);
s_wants_determinism = new_want_determinism; s_wants_determinism = new_want_determinism;
const auto ios = system.GetIOS(); const auto ios = system.GetIOS();
if (ios) if (ios)
ios->UpdateWantDeterminism(new_want_determinism); ios->UpdateWantDeterminism(new_want_determinism);
system.GetFifo().UpdateWantDeterminism(new_want_determinism); system.GetFifo().UpdateWantDeterminism(new_want_determinism);
// We need to clear the cache because some parts of the JIT depend on want_determinism, // We need to clear the cache because some parts of the JIT depend on want_determinism,
// e.g. use of FMA. // e.g. use of FMA.
system.GetJitInterface().ClearCache(); system.GetJitInterface().ClearCache(guard);
});
} }
} }

View File

@ -271,30 +271,30 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mc_strings)
void MemChecks::Add(TMemCheck memory_check) void MemChecks::Add(TMemCheck memory_check)
{ {
bool had_any = HasAny(); bool had_any = HasAny();
Core::RunAsCPUThread([&] {
// Check for existing breakpoint, and overwrite with new info. const Core::CPUThreadGuard guard(m_system);
// This is assuming we usually want the new breakpoint over an old one. // Check for existing breakpoint, and overwrite with new info.
const u32 address = memory_check.start_address; // This is assuming we usually want the new breakpoint over an old one.
auto old_mem_check = const u32 address = memory_check.start_address;
std::find_if(m_mem_checks.begin(), m_mem_checks.end(), auto old_mem_check =
[address](const auto& check) { return check.start_address == address; }); std::find_if(m_mem_checks.begin(), m_mem_checks.end(),
if (old_mem_check != m_mem_checks.end()) [address](const auto& check) { return check.start_address == address; });
{ if (old_mem_check != m_mem_checks.end())
const bool is_enabled = old_mem_check->is_enabled; // Preserve enabled status {
*old_mem_check = std::move(memory_check); const bool is_enabled = old_mem_check->is_enabled; // Preserve enabled status
old_mem_check->is_enabled = is_enabled; *old_mem_check = std::move(memory_check);
old_mem_check->num_hits = 0; old_mem_check->is_enabled = is_enabled;
} old_mem_check->num_hits = 0;
else }
{ else
m_mem_checks.emplace_back(std::move(memory_check)); {
} m_mem_checks.emplace_back(std::move(memory_check));
// If this is the first one, clear the JIT cache so it can switch to }
// watchpoint-compatible code. // If this is the first one, clear the JIT cache so it can switch to
if (!had_any) // watchpoint-compatible code.
m_system.GetJitInterface().ClearCache(); if (!had_any)
m_system.GetMMU().DBATUpdated(); m_system.GetJitInterface().ClearCache(guard);
}); m_system.GetMMU().DBATUpdated();
} }
bool MemChecks::ToggleBreakPoint(u32 address) bool MemChecks::ToggleBreakPoint(u32 address)
@ -318,21 +318,19 @@ void MemChecks::Remove(u32 address)
if (iter == m_mem_checks.cend()) if (iter == m_mem_checks.cend())
return; return;
Core::RunAsCPUThread([&] { const Core::CPUThreadGuard guard(m_system);
m_mem_checks.erase(iter); m_mem_checks.erase(iter);
if (!HasAny()) if (!HasAny())
m_system.GetJitInterface().ClearCache(); m_system.GetJitInterface().ClearCache(guard);
m_system.GetMMU().DBATUpdated(); m_system.GetMMU().DBATUpdated();
});
} }
void MemChecks::Clear() void MemChecks::Clear()
{ {
Core::RunAsCPUThread([&] { const Core::CPUThreadGuard guard(m_system);
m_mem_checks.clear(); m_mem_checks.clear();
m_system.GetJitInterface().ClearCache(); m_system.GetJitInterface().ClearCache(guard);
m_system.GetMMU().DBATUpdated(); m_system.GetMMU().DBATUpdated();
});
} }
TMemCheck* MemChecks::GetMemCheck(u32 address, size_t size) TMemCheck* MemChecks::GetMemCheck(u32 address, size_t size)

View File

@ -241,7 +241,7 @@ bool JitInterface::HandleStackFault()
return m_jit->HandleStackFault(); return m_jit->HandleStackFault();
} }
void JitInterface::ClearCache() void JitInterface::ClearCache(const Core::CPUThreadGuard&)
{ {
if (m_jit) if (m_jit)
m_jit->ClearCache(); m_jit->ClearCache();

View File

@ -16,8 +16,9 @@ class JitBase;
namespace Core namespace Core
{ {
class CPUThreadGuard;
class System; class System;
} } // namespace Core
namespace PowerPC namespace PowerPC
{ {
enum class CPUCore; enum class CPUCore;
@ -72,7 +73,7 @@ public:
bool HandleStackFault(); bool HandleStackFault();
// Clearing CodeCache // Clearing CodeCache
void ClearCache(); void ClearCache(const Core::CPUThreadGuard& guard);
// This clear is "safe" in the sense that it's okay to run from // This clear is "safe" in the sense that it's okay to run from
// inside a JIT'ed block: it clears the instruction cache, but not // inside a JIT'ed block: it clears the instruction cache, but not

View File

@ -1752,7 +1752,8 @@ void MenuBar::PatchHLEFunctions()
void MenuBar::ClearCache() void MenuBar::ClearCache()
{ {
Core::RunAsCPUThread([] { Core::System::GetInstance().GetJitInterface().ClearCache(); }); auto& system = Core::System::GetInstance();
system.GetJitInterface().ClearCache(Core::CPUThreadGuard{system});
} }
void MenuBar::LogInstructions() void MenuBar::LogInstructions()