summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCamilleLaVey <camillelavey@citron-emu.org>2025-03-05 00:25:31 -0400
committerCamilleLaVey <camillelavey@citron-emu.org>2025-03-05 00:25:31 -0400
commit6565055865688ba316801d99a3c3a5a0300cad5d (patch)
treedc5221234a3bdecb1bf7cc6841ecdd2bbfd0c44c /src
parentee3d858935600e23a7914620b21f45082cccf8bd (diff)
Fix: Core_Memory logging and ARM_NCE Mutex logging
Diffstat (limited to 'src')
-rw-r--r--src/common/logging/types.h1
-rw-r--r--src/core/arm/nce/arm_nce.cpp8
-rw-r--r--src/core/arm/nce/arm_nce.h10
-rw-r--r--src/core/memory.cpp17
4 files changed, 23 insertions, 13 deletions
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index 9e2f42c5d..b6960afa3 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -36,6 +36,7 @@ enum class Class : u8 {
Core, ///< LLE emulation core
Core_ARM, ///< ARM CPU core
Core_Timing, ///< CoreTiming functions
+ Core_Memory, ///< Core memory functions
Config, ///< Emulator configuration (including commandline)
Debug, ///< Debugging tools
Debug_Emulated, ///< Debug messages from the emulated programs
diff --git a/src/core/arm/nce/arm_nce.cpp b/src/core/arm/nce/arm_nce.cpp
index f08c5c352..6220e3031 100644
--- a/src/core/arm/nce/arm_nce.cpp
+++ b/src/core/arm/nce/arm_nce.cpp
@@ -199,7 +199,7 @@ bool ArmNce::HandleGuestAccessFault(GuestContext* guest_ctx, void* raw_info, voi
}
// Trigger an immediate remap if lookup fails
- if (!memory.Remap(fault_addr, Memory::CITRON_PAGESIZE)) {
+ if (!memory.Remap(fault_addr, Memory::CITRON_PAGESIZE, *nce)) {
LOG_ERROR(Core_ARM, "Immediate remap failed for address {:X}", fault_addr);
return HandleFailedGuestFault(guest_ctx, raw_info, raw_context);
}
@@ -430,7 +430,7 @@ void ArmNce::InvalidateCacheRange(u64 addr, std::size_t size) {
}
TlbEntry* ArmNce::FindTlbEntry(u64 guest_addr) {
- std::lock_guard lock(m_tlb_mutex);
+ std::lock_guard<std::mutex> lock(m_tlb_mutex); // Correct usage of lock_guard
// Simple linear search - more reliable than complex indexing
for (size_t i = 0; i < TLB_SIZE; i++) {
@@ -456,7 +456,7 @@ void ArmNce::AddTlbEntry(u64 guest_addr, u64 host_addr, u32 size, bool writable)
return;
}
- std::lock_guard lock(m_tlb_mutex);
+ std::lock_guard<std::mutex> lock(m_tlb_mutex); // Correct usage of lock_guard
size_t replace_idx = TLB_SIZE;
auto now = std::chrono::steady_clock::now();
@@ -506,7 +506,7 @@ void ArmNce::AddTlbEntry(u64 guest_addr, u64 host_addr, u32 size, bool writable)
}
void ArmNce::InvalidateTlb() {
- std::lock_guard lock(m_tlb_mutex);
+ std::lock_guard<std::mutex> lock(m_tlb_mutex); // Correct usage of lock_guard
auto now = std::chrono::steady_clock::now();
auto expiration_time = std::chrono::minutes(5); // Example: 5 minutes expiration
diff --git a/src/core/arm/nce/arm_nce.h b/src/core/arm/nce/arm_nce.h
index 13da2c8b4..416703557 100644
--- a/src/core/arm/nce/arm_nce.h
+++ b/src/core/arm/nce/arm_nce.h
@@ -62,6 +62,11 @@ public:
void LockThread(Kernel::KThread* thread) override;
void UnlockThread(Kernel::KThread* thread) override;
+ // Method to provide access to TLB entries
+ const std::array<TlbEntry, TLB_SIZE>& GetTlbEntries() const {
+ return m_tlb;
+ }
+
protected:
const Kernel::DebugWatchpoint* HaltedWatchpoint() const override {
return nullptr;
@@ -109,8 +114,8 @@ public:
std::unique_ptr<u8[]> m_stack{};
// Enhanced TLB implementation
- std::array<TlbEntry, TLB_SIZE> m_tlb{};
- std::mutex m_tlb_mutex;
+ std::array<TlbEntry, TLB_SIZE> m_tlb{}; // Declare m_tlb
+ std::mutex m_tlb_mutex; // Declare m_tlb_mutex
u64 m_tlb_access_counter{0};
// TLB helper functions
@@ -120,6 +125,7 @@ public:
size_t GetTlbSetIndex(u64 guest_addr) const;
size_t FindReplacementEntry(size_t set_start);
void UpdateTlbEntryStats(TlbEntry& entry);
+ void StartTlbInvalidationTimer();
// Thread context caching
std::mutex m_context_mutex;
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index dd6ffaf6c..b32071899 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -27,6 +27,7 @@
#include "video_core/host1x/gpu_device_memory_manager.h"
#include "video_core/host1x/host1x.h"
#include "video_core/rasterizer_download_area.h"
+#include "core/arm/nce/arm_nce.h"
namespace Core::Memory {
@@ -1151,7 +1152,7 @@ bool Memory::InvalidateSeparateHeap(void* fault_address) {
#endif
}
-bool Memory::Remap(u64 guest_addr, u32 size) {
+bool Memory::Remap(u64 guest_addr, u32 size, ArmNce& arm_nce) {
// Unmap the old address
UnmapRegion(*impl->current_page_table, guest_addr, size, false);
@@ -1161,7 +1162,7 @@ bool Memory::Remap(u64 guest_addr, u32 size) {
// Allocate new memory
void* new_memory = std::malloc(size);
if (!new_memory) {
- LOG_ERROR(Core_Memory, "Failed to allocate new memory for remapping address {:X}", guest_addr);
+ LOG_ERROR(Core_ARM, "Failed to allocate new memory for remapping address {:X}", guest_addr);
return false;
}
@@ -1170,7 +1171,7 @@ bool Memory::Remap(u64 guest_addr, u32 size) {
// Verify the mapping
if (GetPointer(guest_addr) != nullptr) {
- LOG_INFO(Core_Memory, "Successfully remapped address {:X}", guest_addr);
+ LOG_INFO(Core_ARM, "Successfully remapped address {:X}", guest_addr);
return true;
} else {
LOG_ERROR(Core_Memory, "Failed to remap address {:X}", guest_addr);
@@ -1179,10 +1180,12 @@ bool Memory::Remap(u64 guest_addr, u32 size) {
}
}
-void Memory::ReclaimUnusedMemory() {
- std::lock_guard lock(m_tlb_mutex);
+void Memory::ReclaimUnusedMemory(ArmNce& arm_nce) {
+ std::lock_guard<std::mutex> lock(arm_nce.m_tlb_mutex); // Correct usage of lock_guard
- for (auto& entry : m_tlb) {
+ const auto& tlb_entries = arm_nce.GetTlbEntries();
+
+ for (const auto& entry : tlb_entries) {
if (entry.valid && entry.ref_count == 0) {
// Unmap the memory region
UnmapRegion(*impl->current_page_table, entry.guest_addr, entry.size, false);
@@ -1191,7 +1194,7 @@ void Memory::ReclaimUnusedMemory() {
std::free(reinterpret_cast<void*>(entry.host_addr));
// Invalidate the TLB entry
- entry.valid = false;
+ const_cast<TlbEntry&>(entry).valid = false;
LOG_INFO(Core_Memory, "Reclaimed memory for address {:X}", entry.guest_addr);
}