x64 Interface: Allow for asynchronous invalidation (#647)

* x64 Interface: Make Invalidation asynchronous.

* Apply suggestions from code review
This commit is contained in:
Fernando S 2021-10-05 16:06:41 +02:00 committed by GitHub
parent 5e7d2afe0f
commit e4146ec3a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <mutex>
#include <boost/icl/interval_set.hpp> #include <boost/icl/interval_set.hpp>
@ -57,6 +58,8 @@ public:
void Run() { void Run() {
ASSERT(!is_executing); ASSERT(!is_executing);
PerformRequestedCacheInvalidation();
is_executing = true; is_executing = true;
SCOPE_EXIT { this->is_executing = false; }; SCOPE_EXIT { this->is_executing = false; };
jit_state.halt_requested = false; jit_state.halt_requested = false;
@ -80,6 +83,8 @@ public:
void Step() { void Step() {
ASSERT(!is_executing); ASSERT(!is_executing);
PerformRequestedCacheInvalidation();
is_executing = true; is_executing = true;
SCOPE_EXIT { this->is_executing = false; }; SCOPE_EXIT { this->is_executing = false; };
jit_state.halt_requested = true; jit_state.halt_requested = true;
@ -90,15 +95,21 @@ public:
} }
void ClearCache() { void ClearCache() {
std::unique_lock lock{invalidation_mutex};
invalidate_entire_cache = true; invalidate_entire_cache = true;
RequestCacheInvalidation(); if (is_executing) {
jit_state.halt_requested = true;
}
} }
void InvalidateCacheRange(u64 start_address, size_t length) { void InvalidateCacheRange(u64 start_address, size_t length) {
std::unique_lock lock{invalidation_mutex};
const auto end_address = static_cast<u64>(start_address + length - 1); const auto end_address = static_cast<u64>(start_address + length - 1);
const auto range = boost::icl::discrete_interval<u64>::closed(start_address, end_address); const auto range = boost::icl::discrete_interval<u64>::closed(start_address, end_address);
invalid_cache_ranges.add(range); invalid_cache_ranges.add(range);
RequestCacheInvalidation(); if (is_executing) {
jit_state.halt_requested = true;
}
} }
void Reset() { void Reset() {
@ -268,6 +279,7 @@ private:
} }
void PerformRequestedCacheInvalidation() { void PerformRequestedCacheInvalidation() {
std::unique_lock lock{invalidation_mutex};
if (!invalidate_entire_cache && invalid_cache_ranges.empty()) { if (!invalidate_entire_cache && invalid_cache_ranges.empty()) {
return; return;
} }
@ -292,6 +304,7 @@ private:
bool invalidate_entire_cache = false; bool invalidate_entire_cache = false;
boost::icl::interval_set<u64> invalid_cache_ranges; boost::icl::interval_set<u64> invalid_cache_ranges;
std::mutex invalidation_mutex;
}; };
Jit::Jit(UserConfig conf) Jit::Jit(UserConfig conf)