Skip to content

Commit

Permalink
accel/tcg: Support jit profiling with VTune
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Aug 2, 2023
1 parent 1d3c7c0 commit edecb41
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions accel/tcg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ tcg_ss.add(files(
tcg_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c'))
tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c'))
tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c')])
tcg_ss.add(when: 'CONFIG_VTUNE_JITPROFILING', if_true: [vtune_jitprofiling])

specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)

specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
Expand Down
19 changes: 19 additions & 0 deletions accel/tcg/translate-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
#include "tb-context.h"
#include "internal.h"

#if defined(CONFIG_VTUNE_JITPROFILING)
#include <jitprofiling.h>
#endif

/* make various TB consistency checks */

/**
Expand Down Expand Up @@ -1035,6 +1039,21 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_tb_remove(tb);
return existing_tb;
}

#if defined(CONFIG_VTUNE_JITPROFILING)
if (iJIT_IsProfilingActive() == iJIT_SAMPLING_ON && !recycled) {
iJIT_Method_Load *jmethod = g_malloc0(sizeof(iJIT_Method_Load));
jmethod->method_id = iJIT_GetNewMethodID();
jmethod->method_name = g_strdup_printf("G@0x%x", pc);
jmethod->class_file_name = NULL;
jmethod->source_file_name = NULL;
jmethod->method_load_address = (void*)tb->tc.ptr;
jmethod->method_size = tb->tc.size;

iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)jmethod);
}
#endif

return tb;
}

Expand Down
13 changes: 13 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,18 @@ if have_system and get_option('renderdoc').enabled()
have_renderdoc = true
endif

have_vtune = false
vtune_path = get_option('vtune')
if vtune_path != ''
have_vtune = true
vtune_jitprofiling = declare_dependency(
dependencies: cc.find_library('jitprofiling', dirs: [vtune_path + '/lib64']),
include_directories: include_directories(vtune_path + '/include'))
config_host += { 'CONFIG_VTUNE_JITPROFILING': 'y' }
else
vtune_jitprofiling = not_found
endif

dbus_display = get_option('dbus_display') \
.require(gio.version().version_compare('>=2.64'),
error_message: '-display dbus requires glib>=2.64') \
Expand Down Expand Up @@ -4060,6 +4072,7 @@ summary_info += {'libudev': libudev}
# Dummy dependency, keep .found()
summary_info += {'FUSE lseek': fuse_lseek.found()}
summary_info += {'selinux': selinux}
summary_info += {'vtune': have_vtune ? vtune_path : false}
summary(summary_info, bool_yn: true, section: 'Dependencies')

if not supported_cpus.contains(cpu)
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ option('fuzzing_engine', type : 'string', value : '',
description: 'fuzzing engine library for OSS-Fuzz')
option('trace_file', type: 'string', value: 'trace',
description: 'Trace file prefix for simple backend')
option('vtune', type : 'string', value : '',
description: 'Path to VTune directory for profiling')

# Everything else can be set via --enable/--disable-* option
# on the configure script command line. After adding an option
Expand Down
2 changes: 2 additions & 0 deletions scripts/meson-buildoptions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ meson_options_help() {
printf "%s\n" ' --sysconfdir=VALUE Sysconf data directory [etc]'
printf "%s\n" ' --tls-priority=VALUE Default TLS protocol/cipher priority string'
printf "%s\n" ' [NORMAL]'
printf "%s\n" ' --vtune=VALUE Path to VTune directory for profiling'
printf "%s\n" ' --with-pkgversion=VALUE use specified string as sub-version of the'
printf "%s\n" ' package'
printf "%s\n" ' --with-trace-file=VALUE Trace file prefix for simple backend [trace]'
Expand Down Expand Up @@ -462,6 +463,7 @@ _meson_option_parse() {
--disable-vnc-sasl) printf "%s" -Dvnc_sasl=disabled ;;
--enable-vte) printf "%s" -Dvte=enabled ;;
--disable-vte) printf "%s" -Dvte=disabled ;;
--vtune=*) quote_sh "-Dvtune=$2" ;;
--enable-vvfat) printf "%s" -Dvvfat=enabled ;;
--disable-vvfat) printf "%s" -Dvvfat=disabled ;;
--enable-whpx) printf "%s" -Dwhpx=enabled ;;
Expand Down

0 comments on commit edecb41

Please sign in to comment.