From edecb41b9723d680f8e6ed87a8f709b8db6ca32f Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Tue, 1 Aug 2023 02:37:58 -0700 Subject: [PATCH] accel/tcg: Support jit profiling with VTune --- accel/tcg/meson.build | 2 ++ accel/tcg/translate-all.c | 19 +++++++++++++++++++ meson.build | 13 +++++++++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 2 ++ 5 files changed, 38 insertions(+) diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build index 75e1dffb4d..03c0cd34b8 100644 --- a/accel/tcg/meson.build +++ b/accel/tcg/meson.build @@ -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( diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 058dafca0a..d2a138dbfc 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -63,6 +63,10 @@ #include "tb-context.h" #include "internal.h" +#if defined(CONFIG_VTUNE_JITPROFILING) +#include +#endif + /* make various TB consistency checks */ /** @@ -1035,6 +1039,21 @@ recycle_tb: 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; } diff --git a/meson.build b/meson.build index 0ae9c6f8a1..38127c9809 100644 --- a/meson.build +++ b/meson.build @@ -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') \ @@ -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) diff --git a/meson_options.txt b/meson_options.txt index 9e16d9fde1..84427cc95b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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 diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 5272bc0277..54195eb5b3 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -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]' @@ -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 ;;