Skip to content

Commit

Permalink
add support for JIT profiling with VTune
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Jul 24, 2021
1 parent c9b918d commit 6944fdb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmake/FindVTune.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

find_path(VTUNE_PATH "")

include_directories("${VTUNE_PATH}/include")
link_directories("${VTUNE_PATH}/lib64")
43 changes: 43 additions & 0 deletions src/ARMJIT_x64/ARMJIT_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../Config.h"

#include <assert.h>
#include <stdarg.h>

#include "../dolphin/CommonFuncs.h"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/ARMJIT_x64/ARMJIT_Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -230,6 +234,10 @@ class Compiler : public Gen::XEmitter

u8* RewriteMemAccess(u8* pc);

#ifdef JIT_PROFILING_ENABLED
void CreateMethod(const char* namefmt, void* start, ...);
#endif

u8* FarCode;
u8* NearCode;
u32 FarSize;
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ else()
target_link_libraries(core rt)
endif()
endif()

if (ENABLE_JIT_PROFILING)
target_link_libraries(core jitprofiling)
endif()

0 comments on commit 6944fdb

Please sign in to comment.