From dc7e143de597d3a256a12e25553e2c37547ed368 Mon Sep 17 00:00:00 2001 From: O1L Date: Sun, 14 Sep 2014 00:40:12 +0400 Subject: [PATCH 1/2] More information in KernelExplorer. --- rpcs3/Emu/SysCalls/SyncPrimitivesManager.h | 114 +++++++++++++++++++++ rpcs3/Emu/SysCalls/lv2/sys_cond.cpp | 2 + rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp | 3 + rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp | 3 + rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp | 2 + rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp | 3 + rpcs3/Emu/System.cpp | 3 + rpcs3/Emu/System.h | 5 + rpcs3/Gui/KernelExplorer.cpp | 27 +++-- rpcs3/emucore.vcxproj | 1 + rpcs3/emucore.vcxproj.filters | 3 + 11 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 rpcs3/Emu/SysCalls/SyncPrimitivesManager.h diff --git a/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h b/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h new file mode 100644 index 0000000000..a07395ca5e --- /dev/null +++ b/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h @@ -0,0 +1,114 @@ +#pragma once + +#include +#include "Emu/System.h" +#include "Emu/IdManager.h" +#include "Utilities/Log.h" + +struct SemaphoreAttribites +{ + std::string name; + u32 count; + u32 max_count; + + SemaphoreAttribites() {} + SemaphoreAttribites(const std::string& _name, u32 _count, u32 _max_count) : name(_name), count(_count), max_count(_max_count) {} +}; + +struct LwMutexAttributes +{ + std::string name; + u32 owner_id; + std::string status; // TODO: check status? + + LwMutexAttributes() {} + LwMutexAttributes(const std::string& _name, u32 _owner_id, std::string _status = "INITIALIZED") + : name(_name), owner_id(_owner_id), status(_status) {} +}; + +class SyncPrimManager +{ +private: + std::map m_cond_name; + std::map m_mutex_name; + std::map m_lw_cond_name; + std::map m_lw_mutex_attr; + std::map m_semaph_attr; + +public: + + // semaphores + void AddSemaphoreData(const u32 id, const std::string& name, const u32 count, const u32 max_count) + { + m_semaph_attr[id] = *(new SemaphoreAttribites(name, count, max_count)); + } + + void EraseSemaphoreData(const u32 id) + { + m_semaph_attr.erase(id); + } + + SemaphoreAttribites& GetSemaphoreData(const u32 id) + { + return m_semaph_attr[id]; + } + + // lw_mutexes + void AddLwMutexData(const u32 id, const std::string& name, const u32 owner_id) + { + m_lw_mutex_attr[id] = *(new LwMutexAttributes(name, owner_id)); + } + + void EraseLwMutexData(const u32 id) + { + m_lw_mutex_attr.erase(id); + } + + LwMutexAttributes& GetLwMutexData(const u32 id) + { + return m_lw_mutex_attr[id]; + } + + // lw_conditions, mutexes, conditions + void AddSyncPrimData(const IDType type, const u32 id, const std::string& name) + { + switch (type) + { + case TYPE_LWCOND: m_lw_cond_name[id] = name; break; + case TYPE_MUTEX: m_mutex_name[id] = name; break; + case TYPE_COND: m_cond_name[id] = name; break; + + } + } + + void EraseSyncPrimData(const IDType type, const u32 id) + { + switch (type) + { + case TYPE_LWCOND: m_lw_cond_name.erase(id); break; + case TYPE_MUTEX: m_mutex_name.erase(id); break; + case TYPE_COND: m_cond_name.erase(id); break; + + default: LOG_ERROR(GENERAL, "Unknown IDType = %d", type); + } + } + + std::string& GetSyncPrimName(const IDType type, const u32 id) + { + switch (type) + { + case TYPE_LWCOND: return m_lw_cond_name[id]; + case TYPE_MUTEX: return m_mutex_name[id]; + case TYPE_COND: return m_cond_name[id]; + } + } + + void Close() + { + m_cond_name.clear(); + m_mutex_name.clear(); + m_lw_cond_name.clear(); + m_lw_mutex_attr.clear(); + m_semaph_attr.clear(); + } +}; \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp index 8fdc6b6766..0ab41ee220 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp @@ -36,6 +36,7 @@ s32 sys_cond_create(vm::ptr> cond_id, u32 mutex_id, vm::ptrcond_count++; sys_cond.Warning("*** condition created [%s] (mutex_id=%d): id = %d", std::string(attr->name, 8).c_str(), mutex_id, id); + Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_COND, id, std::string(attr->name, 8)); return CELL_OK; } @@ -57,6 +58,7 @@ s32 sys_cond_destroy(u32 cond_id) cond->mutex->cond_count--; Emu.GetIdManager().RemoveID(cond_id); + Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_COND, cond_id); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp index 56d1dbd4c9..e7c1527d38 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp @@ -21,6 +21,8 @@ s32 sys_lwcond_create(vm::ptr lwcond, vm::ptr lwmut sys_lwcond.Warning("*** lwcond created [%s] (lwmutex_addr=0x%x): id = %d", std::string(attr->name, 8).c_str(), lwmutex.addr(), (u32) lwcond->lwcond_queue); + Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_LWCOND, id, std::string(attr->name, 8)); + return CELL_OK; } @@ -42,6 +44,7 @@ s32 sys_lwcond_destroy(vm::ptr lwcond) } Emu.GetIdManager().RemoveID(id); + Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_LWCOND, id); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index 330a56ee0d..df9829a02d 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -45,6 +45,8 @@ s32 sys_lwmutex_create(vm::ptr lwmutex, vm::ptrname, 8).c_str(), (u32) lwmutex->attribute, sq_id); + Emu.GetSyncPrimManager().AddLwMutexData(sq_id, std::string(attr->name, 8), GetCurrentPPUThread().GetId()); + return CELL_OK; } @@ -63,6 +65,7 @@ s32 sys_lwmutex_destroy(vm::ptr lwmutex) lwmutex->attribute = 0xDEADBEEF; lwmutex->sleep_queue = 0; Emu.GetIdManager().RemoveID(sq_id); + Emu.GetSyncPrimManager().EraseLwMutexData(sq_id); default: return res; } } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index 534496bbd4..63d4263552 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -63,6 +63,7 @@ s32 sys_mutex_create(vm::ptr> mutex_id, vm::ptr a sys_mutex.Warning("*** mutex created [%s] (protocol=0x%x, recursive=%s): id = %d", std::string(attr->name, 8).c_str(), (u32) attr->protocol, (is_recursive ? "true" : "false"), id); + Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_MUTEX, id, std::string(attr->name, 8)); // TODO: unlock mutex when owner thread does exit return CELL_OK; @@ -98,6 +99,7 @@ s32 sys_mutex_destroy(u32 mutex_id) mutex->m_mutex.unlock(tid, ~0); Emu.GetIdManager().RemoveID(mutex_id); + Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_MUTEX, mutex_id); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index e3e7574821..a7ddb0468e 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -42,6 +42,8 @@ s32 sys_semaphore_create(vm::ptr> sem, vm::ptrname, 8).c_str(), (u32)attr->protocol, id); + Emu.GetSyncPrimManager().AddSemaphoreData(id, std::string(attr->name, 8), initial_count, max_count); + return CELL_OK; } @@ -61,6 +63,7 @@ s32 sys_semaphore_destroy(u32 sem_id) } Emu.GetIdManager().RemoveID(sem_id); + Emu.GetSyncPrimManager().EraseSemaphoreData(sem_id); return CELL_OK; } diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index f5277cfa21..d67f1d3125 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -54,6 +54,7 @@ Emulator::Emulator() , m_event_manager(new EventManager()) , m_sfunc_manager(new StaticFuncManager()) , m_module_manager(new ModuleManager()) + , m_sync_prim_manager(new SyncPrimManager()) , m_vfs(new VFS()) { } @@ -71,6 +72,7 @@ Emulator::~Emulator() delete m_event_manager; delete m_sfunc_manager; delete m_module_manager; + delete m_sync_prim_manager; delete m_vfs; } @@ -480,6 +482,7 @@ void Emulator::Stop() GetCallbackManager().Clear(); GetModuleManager().UnloadModules(); GetSFuncManager().StaticFinalize(); + GetSyncPrimManager().Close(); CurGameInfo.Reset(); Memory.Close(); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 034d058002..05c8927eee 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -1,5 +1,7 @@ #pragma once + #include "Loader/Loader.h" +#include "Emu/SysCalls/SyncPrimitivesManager.h" enum Status { @@ -21,6 +23,7 @@ class CPUThread; class EventManager; class ModuleManager; class StaticFuncManager; +class SyncPrimManager; struct VFS; struct EmuInfo @@ -99,6 +102,7 @@ class Emulator EventManager* m_event_manager; StaticFuncManager* m_sfunc_manager; ModuleManager* m_module_manager; + SyncPrimManager* m_sync_prim_manager; VFS* m_vfs; EmuInfo m_info; @@ -133,6 +137,7 @@ public: EventManager& GetEventManager() { return *m_event_manager; } StaticFuncManager& GetSFuncManager() { return *m_sfunc_manager; } ModuleManager& GetModuleManager() { return *m_module_manager; } + SyncPrimManager& GetSyncPrimManager() { return *m_sync_prim_manager; } void AddModuleInit(std::unique_ptr m) { diff --git a/rpcs3/Gui/KernelExplorer.cpp b/rpcs3/Gui/KernelExplorer.cpp index 8db3a4a7b8..64e84e36df 100644 --- a/rpcs3/Gui/KernelExplorer.cpp +++ b/rpcs3/Gui/KernelExplorer.cpp @@ -46,7 +46,9 @@ void KernelExplorer::Update() char name[4096]; m_tree->DeleteAllItems(); - const auto& root = m_tree->AddRoot("Process, ID = 0x00000001, Total Memory Usage = 0x???????? (???.? MB)"); + const u32 total_memory_usage = Memory.GetUserMemTotalSize() - Memory.GetUserMemAvailSize(); + + const auto& root = m_tree->AddRoot(fmt::Format("Process, ID = 0x00000001, Total Memory Usage = 0x%x (%0.2f MB)", total_memory_usage, (float)total_memory_usage / (1024 * 1024))); // TODO: FileSystem @@ -59,7 +61,8 @@ void KernelExplorer::Update() const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_SEMAPHORE); for (const auto& id : objects) { - sprintf(name, "Semaphore: ID = 0x%08x", id); + sprintf(name, "Semaphore: ID = 0x%08x '%s', Count = %d, Max Count = %d", id, Emu.GetSyncPrimManager().GetSemaphoreData(id).name.c_str(), + Emu.GetSyncPrimManager().GetSemaphoreData(id).count, Emu.GetSyncPrimManager().GetSemaphoreData(id).max_count); m_tree->AppendItem(node, name); } } @@ -73,7 +76,7 @@ void KernelExplorer::Update() const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MUTEX); for (const auto& id : objects) { - sprintf(name, "Mutex: ID = 0x%08x", id); + sprintf(name, "Mutex: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_MUTEX, id).c_str()); m_tree->AppendItem(node, name); } } @@ -87,7 +90,8 @@ void KernelExplorer::Update() const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWMUTEX); for (const auto& id : objects) { - sprintf(name, "LW Mutex: ID = 0x%08x", id); + sprintf(name, "LW Mutex: ID = 0x%08x '%s', Owner Thread ID = 0x%08x - %s", id, Emu.GetSyncPrimManager().GetLwMutexData(id).name.c_str(), + Emu.GetSyncPrimManager().GetLwMutexData(id).owner_id, Emu.GetSyncPrimManager().GetLwMutexData(id).status.c_str()); m_tree->AppendItem(node, name); } } @@ -101,7 +105,7 @@ void KernelExplorer::Update() const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_COND); for (const auto& id : objects) { - sprintf(name, "Condition Variable: ID = 0x%08x", id); + sprintf(name, "Condition Variable: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_COND, id).c_str()); m_tree->AppendItem(node, name); } } @@ -113,9 +117,11 @@ void KernelExplorer::Update() sprintf(name, "Light Weight Condition Variables (%d)", count); const auto& node = m_tree->AppendItem(root, name); const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWCOND); + + u32 index = 0; for (const auto& id : objects) { - sprintf(name, "LW Condition Variable: ID = 0x%08x", id); + sprintf(name, "LW Condition Variable: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_LWCOND, id).c_str()); m_tree->AppendItem(node, name); } } @@ -163,6 +169,7 @@ void KernelExplorer::Update() m_tree->AppendItem(node, name); } } + // Event Flags count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_FLAG); if (count) @@ -180,7 +187,7 @@ void KernelExplorer::Update() // PPU / SPU / RawSPU threads { // TODO: add mutexes owners - + const auto& objects = Emu.GetCPU().GetThreads(); u32 ppu_threads_count = 0; u32 spu_threads_count = 0; @@ -206,7 +213,7 @@ void KernelExplorer::Update() { if (thread->GetType() == CPU_THREAD_PPU) { - sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); + sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); m_tree->AppendItem(node, name); } } @@ -221,7 +228,7 @@ void KernelExplorer::Update() { if (thread->GetType() == CPU_THREAD_SPU) { - sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); + sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); m_tree->AppendItem(node, name); } } @@ -236,7 +243,7 @@ void KernelExplorer::Update() { if (thread->GetType() == CPU_THREAD_RAW_SPU) { - sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); + sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); m_tree->AppendItem(node, name); } } diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index bc3b302f56..f09d6a99d5 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -408,6 +408,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 8ab503da45..038502f880 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1216,5 +1216,8 @@ Emu\SysCalls + + Emu\SysCalls + \ No newline at end of file From 2b7a00d42d5d6276c10053f537d06e3f72aa3757 Mon Sep 17 00:00:00 2001 From: O1L Date: Sun, 14 Sep 2014 00:50:38 +0400 Subject: [PATCH 2/2] Fixed typo --- rpcs3/Emu/SysCalls/SyncPrimitivesManager.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h b/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h index a07395ca5e..07293bbd96 100644 --- a/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h +++ b/rpcs3/Emu/SysCalls/SyncPrimitivesManager.h @@ -5,14 +5,14 @@ #include "Emu/IdManager.h" #include "Utilities/Log.h" -struct SemaphoreAttribites +struct SemaphoreAttributes { std::string name; u32 count; u32 max_count; - SemaphoreAttribites() {} - SemaphoreAttribites(const std::string& _name, u32 _count, u32 _max_count) : name(_name), count(_count), max_count(_max_count) {} + SemaphoreAttributes() {} + SemaphoreAttributes(const std::string& _name, u32 _count, u32 _max_count) : name(_name), count(_count), max_count(_max_count) {} }; struct LwMutexAttributes @@ -33,14 +33,14 @@ private: std::map m_mutex_name; std::map m_lw_cond_name; std::map m_lw_mutex_attr; - std::map m_semaph_attr; + std::map m_semaph_attr; public: // semaphores void AddSemaphoreData(const u32 id, const std::string& name, const u32 count, const u32 max_count) { - m_semaph_attr[id] = *(new SemaphoreAttribites(name, count, max_count)); + m_semaph_attr[id] = *(new SemaphoreAttributes(name, count, max_count)); } void EraseSemaphoreData(const u32 id) @@ -48,7 +48,7 @@ public: m_semaph_attr.erase(id); } - SemaphoreAttribites& GetSemaphoreData(const u32 id) + SemaphoreAttributes& GetSemaphoreData(const u32 id) { return m_semaph_attr[id]; }