[igt-dev] [PATCH i-g-t 3/6] lib/i915: Add support for loading perf configurations
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Mon Feb 17 14:21:52 UTC 2020
---
lib/i915/perf.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/i915/perf.h | 2 ++
2 files changed, 77 insertions(+)
diff --git a/lib/i915/perf.c b/lib/i915/perf.c
index 8aaf8e61..f23a9b12 100644
--- a/lib/i915/perf.c
+++ b/lib/i915/perf.c
@@ -433,3 +433,78 @@ intel_perf_add_metric_set(struct intel_perf *perf,
{
igt_list_add_tail(&metric_set->link, &perf->metric_sets);
}
+
+static void
+load_metric_set_config(struct intel_perf_metric_set *metric_set, int drm_fd)
+{
+ struct drm_i915_perf_oa_config config;
+ uint64_t config_id = 0;
+
+ memset(&config, 0, sizeof(config));
+
+ memcpy(config.uuid, metric_set->hw_config_guid, sizeof(config.uuid));
+
+ config.n_mux_regs = metric_set->n_mux_regs;
+ config.mux_regs_ptr = (uintptr_t) metric_set->mux_regs;
+
+ config.n_boolean_regs = metric_set->n_b_counter_regs;
+ config.boolean_regs_ptr = (uintptr_t) metric_set->b_counter_regs;
+
+ config.n_flex_regs = metric_set->n_flex_regs;
+ config.flex_regs_ptr = (uintptr_t) metric_set->flex_regs;
+
+ while (ioctl(drm_fd, DRM_IOCTL_I915_PERF_ADD_CONFIG, &config) < 0 &&
+ (errno == EAGAIN || errno == EINTR));
+
+ metric_set->perf_oa_metrics_set = config_id;
+}
+
+void
+intel_perf_load_perf_configs(struct intel_perf *perf, int drm_fd)
+{
+ int drm_card = get_card_for_fd(drm_fd);
+ struct dirent *entry;
+ char metrics_path[128];
+ DIR *metrics_dir;
+ struct intel_perf_metric_set *metric_set;
+
+ snprintf(metrics_path, sizeof(metrics_path),
+ "/sys/class/drm/card%d/metrics", drm_card);
+ metrics_dir = opendir(metrics_path);
+ if (!metrics_dir)
+ return;
+
+ while ((entry = readdir(metrics_dir))) {
+ char *metric_id_path;
+ uint64_t metric_id;
+
+ if (entry->d_type != DT_DIR)
+ continue;
+
+ asprintf(&metric_id_path, "%s/%s/id",
+ metrics_path, entry->d_name);
+
+ if (!read_file_uint64(metric_id_path, &metric_id)) {
+ free(metric_id_path);
+ continue;
+ }
+
+ free(metric_id_path);
+
+ igt_list_for_each_entry(metric_set, &perf->metric_sets, link) {
+ if (!strcmp(metric_set->hw_config_guid, entry->d_name)) {
+ metric_set->perf_oa_metrics_set = metric_id;
+ break;
+ }
+ }
+ }
+
+ closedir(metrics_dir);
+
+ igt_list_for_each_entry(metric_set, &perf->metric_sets, link) {
+ if (metric_set->perf_oa_metrics_set)
+ continue;
+
+ load_metric_set_config(metric_set, drm_fd);
+ }
+}
diff --git a/lib/i915/perf.h b/lib/i915/perf.h
index 7dfa0472..246d06cf 100644
--- a/lib/i915/perf.h
+++ b/lib/i915/perf.h
@@ -220,6 +220,8 @@ void intel_perf_add_logical_counter(struct intel_perf *perf,
void intel_perf_add_metric_set(struct intel_perf *perf,
struct intel_perf_metric_set *metric_set);
+void intel_perf_load_perf_configs(struct intel_perf *perf, int drm_fd);
+
#ifdef __cplusplus
};
#endif
--
2.25.0
More information about the igt-dev
mailing list