intel/perf: expose some utility functions

The Vulkan performance query extension is a bit lower level than the
GL one. Expose some of the functions to do the result accumulation
directly in the Anv driver.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
This commit is contained in:
Lionel Landwerlin
2019-08-28 15:45:00 +03:00
parent a0e0e75db1
commit a338b7d739
2 changed files with 55 additions and 31 deletions

View File

@@ -583,14 +583,15 @@ kernel_has_dynamic_config_support(struct gen_perf_config *perf, int fd)
&invalid_config_id) < 0 && errno == ENOENT; &invalid_config_id) < 0 && errno == ENOENT;
} }
static bool bool
load_metric_id(struct gen_perf_config *perf, const char *guid, gen_perf_load_metric_id(struct gen_perf_config *perf_cfg,
uint64_t *metric_id) const char *guid,
uint64_t *metric_id)
{ {
char config_path[280]; char config_path[280];
snprintf(config_path, sizeof(config_path), "%s/metrics/%s/id", snprintf(config_path, sizeof(config_path), "%s/metrics/%s/id",
perf->sysfs_dev_dir, guid); perf_cfg->sysfs_dev_dir, guid);
/* Don't recreate already loaded configs. */ /* Don't recreate already loaded configs. */
return read_file_uint64(config_path, metric_id); return read_file_uint64(config_path, metric_id);
@@ -605,7 +606,7 @@ init_oa_configs(struct gen_perf_config *perf, int fd)
uint64_t config_id; uint64_t config_id;
int ret; int ret;
if (load_metric_id(perf, query->guid, &config_id)) { if (gen_perf_load_metric_id(perf, query->guid, &config_id)) {
DBG("metric set: %s (already loaded)\n", query->guid); DBG("metric set: %s (already loaded)\n", query->guid);
register_oa_config(perf, query, config_id); register_oa_config(perf, query, config_id);
continue; continue;
@@ -964,11 +965,11 @@ gen8_read_report_clock_ratios(const uint32_t *report,
*unslice_freq_hz = unslice_freq * 16666667ULL; *unslice_freq_hz = unslice_freq * 16666667ULL;
} }
static void void
query_result_read_frequencies(struct gen_perf_query_result *result, gen_perf_query_result_read_frequencies(struct gen_perf_query_result *result,
const struct gen_device_info *devinfo, const struct gen_device_info *devinfo,
const uint32_t *start, const uint32_t *start,
const uint32_t *end) const uint32_t *end)
{ {
/* Slice/Unslice frequency is only available in the OA reports when the /* Slice/Unslice frequency is only available in the OA reports when the
* "Disable OA reports due to clock ratio change" field in * "Disable OA reports due to clock ratio change" field in
@@ -989,11 +990,11 @@ query_result_read_frequencies(struct gen_perf_query_result *result,
&result->unslice_frequency[1]); &result->unslice_frequency[1]);
} }
static void void
query_result_accumulate(struct gen_perf_query_result *result, gen_perf_query_result_accumulate(struct gen_perf_query_result *result,
const struct gen_perf_query_info *query, const struct gen_perf_query_info *query,
const uint32_t *start, const uint32_t *start,
const uint32_t *end) const uint32_t *end)
{ {
int i, idx = 0; int i, idx = 0;
@@ -1031,8 +1032,8 @@ query_result_accumulate(struct gen_perf_query_result *result,
} }
static void void
query_result_clear(struct gen_perf_query_result *result) gen_perf_query_result_clear(struct gen_perf_query_result *result)
{ {
memset(result, 0, sizeof(*result)); memset(result, 0, sizeof(*result));
result->hw_id = 0xffffffff; /* invalid */ result->hw_id = 0xffffffff; /* invalid */
@@ -1292,8 +1293,8 @@ get_metric_id(struct gen_perf_config *perf,
} }
struct gen_perf_query_info *raw_query = (struct gen_perf_query_info *)query; struct gen_perf_query_info *raw_query = (struct gen_perf_query_info *)query;
if (!load_metric_id(perf, query->guid, if (!gen_perf_load_metric_id(perf, query->guid,
&raw_query->oa_metrics_set_id)) { &raw_query->oa_metrics_set_id)) {
DBG("Unable to read query guid=%s ID, falling back to test config\n", query->guid); DBG("Unable to read query guid=%s ID, falling back to test config\n", query->guid);
raw_query->oa_metrics_set_id = 1ULL; raw_query->oa_metrics_set_id = 1ULL;
} else { } else {
@@ -1735,7 +1736,7 @@ gen_perf_begin_query(struct gen_perf_context *perf_ctx,
*/ */
buf->refcount++; buf->refcount++;
query_result_clear(&query->oa.result); gen_perf_query_result_clear(&query->oa.result);
query->oa.results_accumulated = false; query->oa.results_accumulated = false;
add_to_unaccumulated_query_list(perf_ctx, query); add_to_unaccumulated_query_list(perf_ctx, query);
@@ -2203,8 +2204,9 @@ accumulate_oa_reports(struct gen_perf_context *perf_ctx,
} }
if (add) { if (add) {
query_result_accumulate(&query->oa.result, query->queryinfo, gen_perf_query_result_accumulate(&query->oa.result,
last, report); query->queryinfo,
last, report);
} }
last = report; last = report;
@@ -2224,8 +2226,8 @@ accumulate_oa_reports(struct gen_perf_context *perf_ctx,
end: end:
query_result_accumulate(&query->oa.result, query->queryinfo, gen_perf_query_result_accumulate(&query->oa.result, query->queryinfo,
last, end); last, end);
query->oa.results_accumulated = true; query->oa.results_accumulated = true;
drop_from_unaccumulated_query_list(perf_ctx, query); drop_from_unaccumulated_query_list(perf_ctx, query);
@@ -2412,10 +2414,10 @@ gen_perf_get_query_data(struct gen_perf_context *perf_ctx,
read_gt_frequency(perf_ctx, query); read_gt_frequency(perf_ctx, query);
uint32_t *begin_report = query->oa.map; uint32_t *begin_report = query->oa.map;
uint32_t *end_report = query->oa.map + MI_RPC_BO_END_OFFSET_BYTES; uint32_t *end_report = query->oa.map + MI_RPC_BO_END_OFFSET_BYTES;
query_result_read_frequencies(&query->oa.result, gen_perf_query_result_read_frequencies(&query->oa.result,
perf_ctx->devinfo, perf_ctx->devinfo,
begin_report, begin_report,
end_report); end_report);
accumulate_oa_reports(perf_ctx, query); accumulate_oa_reports(perf_ctx, query);
assert(query->oa.results_accumulated); assert(query->oa.results_accumulated);

View File

@@ -255,12 +255,34 @@ struct gen_perf_config {
struct gen_perf_query_object; struct gen_perf_query_object;
const struct gen_perf_query_info* gen_perf_query_info(const struct gen_perf_query_object *); const struct gen_perf_query_info* gen_perf_query_info(const struct gen_perf_query_object *);
struct gen_perf_context;
struct gen_perf_context *gen_perf_new_context(void *parent);
void gen_perf_init_metrics(struct gen_perf_config *perf_cfg, void gen_perf_init_metrics(struct gen_perf_config *perf_cfg,
const struct gen_device_info *devinfo, const struct gen_device_info *devinfo,
int drm_fd); int drm_fd);
/** Query i915 for a metric id using guid.
*/
bool gen_perf_load_metric_id(struct gen_perf_config *perf_cfg,
const char *guid,
uint64_t *metric_id);
/** Read the slice/unslice frequency from 2 OA reports and store then into
* result.
*/
void gen_perf_query_result_read_frequencies(struct gen_perf_query_result *result,
const struct gen_device_info *devinfo,
const uint32_t *start,
const uint32_t *end);
/** Accumulate the delta between 2 OA reports into result for a given query.
*/
void gen_perf_query_result_accumulate(struct gen_perf_query_result *result,
const struct gen_perf_query_info *query,
const uint32_t *start,
const uint32_t *end);
void gen_perf_query_result_clear(struct gen_perf_query_result *result);
struct gen_perf_context;
struct gen_perf_context *gen_perf_new_context(void *parent);
void gen_perf_init_context(struct gen_perf_context *perf_ctx, void gen_perf_init_context(struct gen_perf_context *perf_ctx,
struct gen_perf_config *perf_cfg, struct gen_perf_config *perf_cfg,
void * ctx, /* driver context (eg, brw_context) */ void * ctx, /* driver context (eg, brw_context) */