From 30f97a7242680b34b230eef60e9a9b24e94714a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 10 May 2024 10:23:04 -0700 Subject: [PATCH] intel/perf: Move i915 specific code from common code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More code will be moved to i915 specific files in the next patches. Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/perf/i915/intel_perf.c | 96 ++++++++++++++++++++++++++++++++ src/intel/perf/i915/intel_perf.h | 5 ++ src/intel/perf/intel_perf.c | 90 ++++-------------------------- 3 files changed, 112 insertions(+), 79 deletions(-) diff --git a/src/intel/perf/i915/intel_perf.c b/src/intel/perf/i915/intel_perf.c index 7e41c76c811..127352c4250 100644 --- a/src/intel/perf/i915/intel_perf.c +++ b/src/intel/perf/i915/intel_perf.c @@ -5,11 +5,19 @@ #include "perf/i915/intel_perf.h" +#include + #include "common/intel_gem.h" +#include "common/i915/intel_gem.h" +#include "dev/intel_debug.h" +#include "dev/intel_device_info.h" +#include "intel_perf_common.h" #include "perf/intel_perf.h" #include "drm-uapi/i915_drm.h" +#define FILE_DEBUG_FLAG DEBUG_PERFMON + uint64_t i915_perf_get_oa_format(struct intel_perf_config *perf) { if (perf->devinfo->verx10 <= 75) @@ -79,3 +87,91 @@ i915_perf_stream_open(struct intel_perf_config *perf_config, int drm_fd, int fd = intel_ioctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m); return fd > -1 ? fd : 0; } + +static bool +i915_query_perf_config_supported(struct intel_perf_config *perf, int fd) +{ + int32_t length = 0; + return !intel_i915_query_flags(fd, DRM_I915_QUERY_PERF_CONFIG, + DRM_I915_QUERY_PERF_CONFIG_LIST, + NULL, &length); +} + +bool +i915_query_perf_config_data(struct intel_perf_config *perf, + int fd, const char *guid, + struct drm_i915_perf_oa_config *config) +{ + char data[sizeof(struct drm_i915_query_perf_config) + + sizeof(struct drm_i915_perf_oa_config)] = {}; + struct drm_i915_query_perf_config *i915_query = (void *)data; + struct drm_i915_perf_oa_config *i915_config = (void *)data + sizeof(*i915_query); + + memcpy(i915_query->uuid, guid, sizeof(i915_query->uuid)); + memcpy(i915_config, config, sizeof(*config)); + + int32_t item_length = sizeof(data); + if (intel_i915_query_flags(fd, DRM_I915_QUERY_PERF_CONFIG, + DRM_I915_QUERY_PERF_CONFIG_DATA_FOR_UUID, + i915_query, &item_length)) + return false; + + memcpy(config, i915_config, sizeof(*config)); + + return true; +} + +static int +i915_perf_version(int drm_fd) +{ + int tmp = 0; + intel_gem_get_param(drm_fd, I915_PARAM_PERF_REVISION, &tmp); + return tmp; +} + +static void +i915_get_sseu(int drm_fd, struct drm_i915_gem_context_param_sseu *sseu) +{ + struct drm_i915_gem_context_param arg = { + .param = I915_CONTEXT_PARAM_SSEU, + .size = sizeof(*sseu), + .value = (uintptr_t) sseu + }; + + intel_ioctl(drm_fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &arg); +} + +bool +i915_oa_metrics_available(struct intel_perf_config *perf, int fd, bool use_register_snapshots) +{ + bool i915_perf_oa_available = false; + struct stat sb; + + perf->i915_query_supported = i915_query_perf_config_supported(perf, fd); + perf->i915_perf_version = i915_perf_version(fd); + + /* Record the default SSEU configuration. */ + i915_get_sseu(fd, &perf->sseu); + + /* The existence of this sysctl parameter implies the kernel supports + * the i915 perf interface. + */ + if (stat("/proc/sys/dev/i915/perf_stream_paranoid", &sb) == 0) { + + /* If _paranoid == 1 then on Gfx8+ we won't be able to access OA + * metrics unless running as root. + */ + if (perf->devinfo->platform == INTEL_PLATFORM_HSW) + i915_perf_oa_available = true; + else { + uint64_t paranoid = 1; + + read_file_uint64("/proc/sys/dev/i915/perf_stream_paranoid", ¶noid); + + if (paranoid == 0 || geteuid() == 0) + i915_perf_oa_available = true; + } + } + + return i915_perf_oa_available; +} diff --git a/src/intel/perf/i915/intel_perf.h b/src/intel/perf/i915/intel_perf.h index ac338a61663..d10dddda727 100644 --- a/src/intel/perf/i915/intel_perf.h +++ b/src/intel/perf/i915/intel_perf.h @@ -9,6 +9,7 @@ #include struct intel_perf_config; +struct drm_i915_perf_oa_config; uint64_t i915_perf_get_oa_format(struct intel_perf_config *perf); @@ -16,3 +17,7 @@ int i915_perf_stream_open(struct intel_perf_config *perf_config, int drm_fd, uint32_t ctx_id, uint64_t metrics_set_id, uint64_t report_format, uint64_t period_exponent, bool hold_preemption, bool enable); + +bool i915_query_perf_config_data(struct intel_perf_config *perf, int fd, const char *guid, struct drm_i915_perf_oa_config *config); + +bool i915_oa_metrics_available(struct intel_perf_config *perf, int fd, bool use_register_snapshots); diff --git a/src/intel/perf/intel_perf.c b/src/intel/perf/intel_perf.c index 72038b2c36e..1f5415c4a0f 100644 --- a/src/intel/perf/intel_perf.c +++ b/src/intel/perf/intel_perf.c @@ -245,39 +245,6 @@ kernel_has_dynamic_config_support(struct intel_perf_config *perf, int fd) &invalid_config_id) < 0 && errno == ENOENT; } -static bool -i915_query_perf_config_supported(struct intel_perf_config *perf, int fd) -{ - int32_t length = 0; - return !intel_i915_query_flags(fd, DRM_I915_QUERY_PERF_CONFIG, - DRM_I915_QUERY_PERF_CONFIG_LIST, - NULL, &length); -} - -static bool -i915_query_perf_config_data(struct intel_perf_config *perf, - int fd, const char *guid, - struct drm_i915_perf_oa_config *config) -{ - char data[sizeof(struct drm_i915_query_perf_config) + - sizeof(struct drm_i915_perf_oa_config)] = {}; - struct drm_i915_query_perf_config *i915_query = (void *)data; - struct drm_i915_perf_oa_config *i915_config = (void *)data + sizeof(*i915_query); - - memcpy(i915_query->uuid, guid, sizeof(i915_query->uuid)); - memcpy(i915_config, config, sizeof(*config)); - - int32_t item_length = sizeof(data); - if (intel_i915_query_flags(fd, DRM_I915_QUERY_PERF_CONFIG, - DRM_I915_QUERY_PERF_CONFIG_DATA_FOR_UUID, - i915_query, &item_length)) - return false; - - memcpy(config, i915_config, sizeof(*config)); - - return true; -} - bool intel_perf_load_metric_id(struct intel_perf_config *perf_cfg, const char *guid, @@ -587,26 +554,6 @@ load_pipeline_statistic_metrics(struct intel_perf_config *perf_cfg, sort_query(query); } -static int -i915_perf_version(int drm_fd) -{ - int tmp = 0; - intel_gem_get_param(drm_fd, I915_PARAM_PERF_REVISION, &tmp); - return tmp; -} - -static void -i915_get_sseu(int drm_fd, struct drm_i915_gem_context_param_sseu *sseu) -{ - struct drm_i915_gem_context_param arg = { - .param = I915_CONTEXT_PARAM_SSEU, - .size = sizeof(*sseu), - .value = to_user_pointer(sseu) - }; - - intel_ioctl(drm_fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &arg); -} - static inline int compare_str_or_null(const char *s1, const char *s2) { @@ -699,8 +646,7 @@ oa_metrics_available(struct intel_perf_config *perf, int fd, bool use_register_snapshots) { perf_register_oa_queries_t oa_register = get_register_queries_function(devinfo); - bool i915_perf_oa_available = false; - struct stat sb; + bool oa_metrics_available = false; /* TODO: Xe still don't have support for performance metrics */ if (devinfo->kmd_type != INTEL_KMD_TYPE_I915) @@ -714,9 +660,7 @@ oa_metrics_available(struct intel_perf_config *perf, int fd, return true; } - perf->i915_query_supported = i915_query_perf_config_supported(perf, fd); perf->enable_all_metrics = debug_get_bool_option("INTEL_EXTENDED_METRICS", false); - perf->i915_perf_version = i915_perf_version(fd); /* TODO: We should query this from i915 */ if (devinfo->verx10 >= 125) @@ -725,30 +669,18 @@ oa_metrics_available(struct intel_perf_config *perf, int fd, perf->oa_timestamp_mask = 0xffffffffffffffffull >> (32 + perf->oa_timestamp_shift); - /* Record the default SSEU configuration. */ - i915_get_sseu(fd, &perf->sseu); - - /* The existence of this sysctl parameter implies the kernel supports - * the i915 perf interface. - */ - if (stat("/proc/sys/dev/i915/perf_stream_paranoid", &sb) == 0) { - - /* If _paranoid == 1 then on Gfx8+ we won't be able to access OA - * metrics unless running as root. - */ - if (devinfo->platform == INTEL_PLATFORM_HSW) - i915_perf_oa_available = true; - else { - uint64_t paranoid = 1; - - read_file_uint64("/proc/sys/dev/i915/perf_stream_paranoid", ¶noid); - - if (paranoid == 0 || geteuid() == 0) - i915_perf_oa_available = true; - } + switch (devinfo->kmd_type) { + case INTEL_KMD_TYPE_I915: + oa_metrics_available = i915_oa_metrics_available(perf, fd, use_register_snapshots); + break; + case INTEL_KMD_TYPE_XE: + break; + default: + unreachable("missing"); + break; } - return i915_perf_oa_available && + return oa_metrics_available && oa_register && get_sysfs_dev_dir(perf, fd) && init_oa_sys_vars(perf, use_register_snapshots);