aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRSDuck <RSDuck@users.noreply.github.com>2021-07-24 16:20:03 +0200
committerRSDuck <RSDuck@users.noreply.github.com>2021-07-24 16:20:03 +0200
commit6944fdbe781cd30da109eb47dea86158ec1f8ebf (patch)
treeee0427b2570c94dbe2aa8fe54218347f5483f11f
parentc9b918d3051891b2a50c022a8c1666f5dc49b727 (diff)
add support for JIT profiling with VTune
-rw-r--r--CMakeLists.txt7
-rw-r--r--cmake/FindVTune.cmake5
-rw-r--r--src/ARMJIT_x64/ARMJIT_Compiler.cpp43
-rw-r--r--src/ARMJIT_x64/ARMJIT_Compiler.h8
-rw-r--r--src/CMakeLists.txt4
5 files changed, 67 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f89c31..18f7967 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,13 @@ endif()
if (ENABLE_JIT)
add_definitions(-DJIT_ENABLED)
+
+ option(ENABLE_JIT_PROFILING "Enable JIT profiling with VTune" OFF)
+
+ if (ENABLE_JIT_PROFILING)
+ include(cmake/FindVTune.cmake)
+ add_definitions(-DJIT_PROFILING_ENABLED)
+ endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL Release)
diff --git a/cmake/FindVTune.cmake b/cmake/FindVTune.cmake
new file mode 100644
index 0000000..3c16dba
--- /dev/null
+++ b/cmake/FindVTune.cmake
@@ -0,0 +1,5 @@
+
+find_path(VTUNE_PATH "")
+
+include_directories("${VTUNE_PATH}/include")
+link_directories("${VTUNE_PATH}/lib64")
diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp
index aef8b91..5e01077 100644
--- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp
+++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp
@@ -22,6 +22,7 @@
#include "../Config.h"
#include <assert.h>
+#include <stdarg.h>
#include "../dolphin/CommonFuncs.h"
@@ -298,6 +299,10 @@ Compiler::Compiler()
SetJumpTarget(und);
MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND)));
RET();
+
+#ifdef JIT_PROFILING_ENABLED
+ CreateMethod("ReadBanked", ReadBanked);
+#endif
}
{
// RSCRATCH mode
@@ -341,6 +346,10 @@ Compiler::Compiler()
MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND)), R(RSCRATCH3));
CLC();
RET();
+
+#ifdef JIT_PROFILING_ENABLED
+ CreateMethod("WriteBanked", WriteBanked);
+#endif
}
for (int consoleType = 0; consoleType < 2; consoleType++)
@@ -401,6 +410,10 @@ Compiler::Compiler()
ABI_PopRegistersAndAdjustStack(CallerSavedPushRegs, 8);
RET();
+#ifdef JIT_PROFILING_ENABLED
+ CreateMethod("FastMemStorePatch%d_%d_%d", PatchedStoreFuncs[consoleType][num][size][reg], num, size, reg);
+#endif
+
for (int signextend = 0; signextend < 2; signextend++)
{
PatchedLoadFuncs[consoleType][num][size][signextend][reg] = GetWritableCodePtr();
@@ -439,6 +452,10 @@ Compiler::Compiler()
else
MOVZX(32, 8 << size, rdMapped, R(RSCRATCH));
RET();
+
+#ifdef JIT_PROFILING_ENABLED
+ CreateMethod("FastMemLoadPatch%d_%d_%d_%d", PatchedLoadFuncs[consoleType][num][size][signextend][reg], num, size, reg, signextend);
+#endif
}
}
}
@@ -668,6 +685,28 @@ void Compiler::Comp_SpecialBranchBehaviour(bool taken)
}
}
+#ifdef JIT_PROFILING_ENABLED
+void Compiler::CreateMethod(const char* namefmt, void* start, ...)
+{
+ if (iJIT_IsProfilingActive())
+ {
+ va_list args;
+ va_start(args, start);
+ char name[64];
+ vsprintf(name, namefmt, args);
+ va_end(args);
+
+ iJIT_Method_Load method = {0};
+ method.method_id = iJIT_GetNewMethodID();
+ method.method_name = name;
+ method.method_load_address = start;
+ method.method_size = GetWritableCodePtr() - (u8*)start;
+
+ iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&method);
+ }
+}
+#endif
+
JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount, bool hasMemoryInstr)
{
if (NearSize - (GetCodePtr() - NearStart) < 1024 * 32) // guess...
@@ -805,6 +844,10 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[]
ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles));
JMP((u8*)ARM_Ret, true);
+#ifdef JIT_PROFILING_ENABLED
+ CreateMethod("JIT_Block_%d_%d_%08X", (void*)res, Num, Thumb, instrs[0].Addr);
+#endif
+
/*FILE* codeout = fopen("codeout", "a");
fprintf(codeout, "beginning block argargarg__ %x!!!", instrs[0].Addr);
fwrite((u8*)res, GetWritableCodePtr() - (u8*)res, 1, codeout);
diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h
index 9836282..5046c88 100644
--- a/src/ARMJIT_x64/ARMJIT_Compiler.h
+++ b/src/ARMJIT_x64/ARMJIT_Compiler.h
@@ -25,6 +25,10 @@
#include "../ARMJIT_Internal.h"
#include "../ARMJIT_RegisterCache.h"
+#ifdef JIT_PROFILING_ENABLED
+#include <jitprofiling.h>
+#endif
+
#include <unordered_map>
namespace ARMJIT
@@ -230,6 +234,10 @@ public:
u8* RewriteMemAccess(u8* pc);
+#ifdef JIT_PROFILING_ENABLED
+ void CreateMethod(const char* namefmt, void* start, ...);
+#endif
+
u8* FarCode;
u8* NearCode;
u32 FarSize;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5603943..f604a39 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -124,3 +124,7 @@ else()
target_link_libraries(core rt)
endif()
endif()
+
+if (ENABLE_JIT_PROFILING)
+ target_link_libraries(core jitprofiling)
+endif() \ No newline at end of file