<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 8, 2018 at 7:42 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We want to reuse it later on.<br>
<br>
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
---<br>
src/mesa/drivers/dri/i965/brw_<wbr>context.h | 3 +<br>
src/mesa/drivers/dri/i965/brw_<wbr>performance_query.c | 146 +++++++++++-----------<br>
2 files changed, 73 insertions(+), 76 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_context.h b/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
index d6e3c7807f7..d3e7c71207b 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
@@ -1189,6 +1189,9 @@ struct brw_context<br>
*/<br>
struct hash_table *oa_metrics_table;<br>
<br>
+ /* Location of the device's sysfs entry. */<br>
+ char sysfs_dev_dir[256];<br>
+<br>
struct brw_perf_query_info *queries;<br>
int n_queries;<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_performance_query.c b/src/mesa/drivers/dri/i965/<wbr>brw_performance_query.c<br>
index 622c2d2d950..a084b30fe7c 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_performance_query.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_performance_query.c<br>
@@ -318,6 +318,47 @@ brw_perf_query(struct gl_perf_query_object *o)<br>
<br>
/*****************************<wbr>******************************<wbr>*******************/<br>
<br>
+static bool<br>
+read_file_uint64(const char *file, uint64_t *val)<br>
+{<br>
+ char buf[32];<br>
+ int fd, n;<br>
+<br>
+ fd = open(file, 0);<br>
+ if (fd < 0)<br>
+ return false;<br>
+ while ((n = read(fd, buf, sizeof (buf) - 1)) < 0 &&<br>
+ errno == EINTR);<br>
+ close(fd);<br>
+ if (n < 0)<br>
+ return false;<br>
+<br>
+ buf[n] = '\0';<br>
+ *val = strtoull(buf, NULL, 0);<br>
+<br>
+ return true;<br>
+}<br>
+<br>
+static bool<br>
+read_sysfs_drm_device_file_<wbr>uint64(struct brw_context *brw,<br>
+ const char *file,<br>
+ uint64_t *value)<br>
+{<br>
+ char buf[512];<br>
+ int len;<br>
+<br>
+ len = snprintf(buf, sizeof(buf), "%s/%s",<br>
+ brw->perfquery.sysfs_dev_dir, file);<br>
+ if (len < 0 || len >= sizeof(buf)) {<br>
+ DBG("Failed to concatenate sys filename to read u64 from\n");<br>
+ return false;<br>
+ }<br>
+<br>
+ return read_file_uint64(buf, value);<br>
+}<br>
+<br>
+/****************************<wbr>******************************<wbr>********************/<br>
+<br>
static bool<br>
brw_is_perf_query_ready(struct gl_context *ctx,<br>
struct gl_perf_query_object *o);<br>
@@ -1746,27 +1787,6 @@ init_pipeline_statistic_query_<wbr>registers(struct brw_context *brw)<br>
query->data_size = sizeof(uint64_t) * query->n_counters;<br>
}<br>
<br>
-static bool<br>
-read_file_uint64(const char *file, uint64_t *val)<br>
-{<br>
- char buf[32];<br>
- int fd, n;<br>
-<br>
- fd = open(file, 0);<br>
- if (fd < 0)<br>
- return false;<br>
- while ((n = read(fd, buf, sizeof (buf) - 1)) < 0 &&<br>
- errno == EINTR);<br>
- close(fd);<br>
- if (n < 0)<br>
- return false;<br>
-<br>
- buf[n] = '\0';<br>
- *val = strtoull(buf, NULL, 0);<br>
-<br>
- return true;<br>
-}<br>
-<br>
static void<br>
register_oa_config(struct brw_context *brw,<br>
const struct brw_perf_query_info *query,<br>
@@ -1780,14 +1800,14 @@ register_oa_config(struct brw_context *brw,<br>
}<br>
<br>
static void<br>
-enumerate_sysfs_metrics(<wbr>struct brw_context *brw, const char *sysfs_dev_dir)<br>
+enumerate_sysfs_metrics(<wbr>struct brw_context *brw)<br>
{<br>
char buf[256];<br>
DIR *metricsdir = NULL;<br>
struct dirent *metric_entry;<br>
int len;<br>
<br>
- len = snprintf(buf, sizeof(buf), "%s/metrics", sysfs_dev_dir);<br>
+ len = snprintf(buf, sizeof(buf), "%s/metrics", brw->perfquery.sysfs_dev_dir);<br>
if (len < 0 || len >= sizeof(buf)) {<br>
DBG("Failed to concatenate path to sysfs metrics/ directory\n");<br>
return;<br>
@@ -1814,7 +1834,7 @@ enumerate_sysfs_metrics(struct brw_context *brw, const char *sysfs_dev_dir)<br>
uint64_t id;<br>
<br>
len = snprintf(buf, sizeof(buf), "%s/metrics/%s/id",<br>
- sysfs_dev_dir, metric_entry->d_name);<br>
+ brw->perfquery.sysfs_dev_dir, metric_entry->d_name);<br>
if (len < 0 || len >= sizeof(buf)) {<br>
DBG("Failed to concatenate path to sysfs metric id file\n");<br>
continue;<br>
@@ -1834,37 +1854,18 @@ enumerate_sysfs_metrics(struct brw_context *brw, const char *sysfs_dev_dir)<br>
}<br>
<br>
static bool<br>
-read_sysfs_drm_device_file_<wbr>uint64(struct brw_context *brw,<br>
- const char *sysfs_dev_dir,<br>
- const char *file,<br>
- uint64_t *value)<br>
-{<br>
- char buf[512];<br>
- int len;<br>
-<br>
- len = snprintf(buf, sizeof(buf), "%s/%s", sysfs_dev_dir, file);<br>
- if (len < 0 || len >= sizeof(buf)) {<br>
- DBG("Failed to concatenate sys filename to read u64 from\n");<br>
- return false;<br>
- }<br>
-<br>
- return read_file_uint64(buf, value);<br>
-}<br>
-<br>
-static bool<br>
-kernel_has_dynamic_config_<wbr>support(struct brw_context *brw,<br>
- const char *sysfs_dev_dir)<br>
+kernel_has_dynamic_config_<wbr>support(struct brw_context *brw)<br>
{<br>
__DRIscreen *screen = brw->screen->driScrnPriv;<br>
struct hash_entry *entry;<br>
<br>
hash_table_foreach(brw-><wbr>perfquery.oa_metrics_table, entry) {<br>
struct brw_perf_query_info *query = entry->data;<br>
- char config_path[256];<br>
+ char config_path[280];<br></blockquote><div><br></div><div>What's with the bump?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
uint64_t config_id;<br>
<br>
- snprintf(config_path, sizeof(config_path),<br>
- "%s/metrics/%s/id", sysfs_dev_dir, query->guid);<br>
+ snprintf(config_path, sizeof(config_path), "%s/metrics/%s/id",<br>
+ brw->perfquery.sysfs_dev_dir, query->guid);<br>
<br>
/* Look for the test config, which we know we can't replace. */<br>
if (read_file_uint64(config_path, &config_id) && config_id == 1) {<br>
@@ -1877,7 +1878,7 @@ kernel_has_dynamic_config_<wbr>support(struct brw_context *brw,<br>
}<br>
<br>
static void<br>
-init_oa_configs(struct brw_context *brw, const char *sysfs_dev_dir)<br>
+init_oa_configs(struct brw_context *brw)<br>
{<br>
__DRIscreen *screen = brw->screen->driScrnPriv;<br>
struct hash_entry *entry;<br>
@@ -1885,12 +1886,12 @@ init_oa_configs(struct brw_context *brw, const char *sysfs_dev_dir)<br>
hash_table_foreach(brw-><wbr>perfquery.oa_metrics_table, entry) {<br>
const struct brw_perf_query_info *query = entry->data;<br>
struct drm_i915_perf_oa_config config;<br>
- char config_path[256];<br>
+ char config_path[280];<br></blockquote><div><br></div><div>Here too<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
uint64_t config_id;<br>
int ret;<br>
<br>
- snprintf(config_path, sizeof(config_path),<br>
- "%s/metrics/%s/id", sysfs_dev_dir, query->guid);<br>
+ snprintf(config_path, sizeof(config_path), "%s/metrics/%s/id",<br>
+ brw->perfquery.sysfs_dev_dir, query->guid);<br>
<br>
/* Don't recreate already loaded configs. */<br>
if (read_file_uint64(config_path, &config_id)) {<br>
@@ -1925,20 +1926,16 @@ init_oa_configs(struct brw_context *brw, const char *sysfs_dev_dir)<br>
}<br>
<br>
static bool<br>
-init_oa_sys_vars(struct brw_context *brw, const char *sysfs_dev_dir)<br>
+init_oa_sys_vars(struct brw_context *brw)<br>
{<br>
const struct gen_device_info *devinfo = &brw->screen->devinfo;<br>
uint64_t min_freq_mhz = 0, max_freq_mhz = 0;<br>
__DRIscreen *screen = brw->screen->driScrnPriv;<br>
<br>
- if (!read_sysfs_drm_device_file_<wbr>uint64(brw, sysfs_dev_dir,<br>
- "gt_min_freq_mhz",<br>
- &min_freq_mhz))<br>
+ if (!read_sysfs_drm_device_file_<wbr>uint64(brw, "gt_min_freq_mhz", &min_freq_mhz))<br>
return false;<br>
<br>
- if (!read_sysfs_drm_device_file_<wbr>uint64(brw, sysfs_dev_dir,<br>
- "gt_max_freq_mhz",<br>
- &max_freq_mhz))<br>
+ if (!read_sysfs_drm_device_file_<wbr>uint64(brw, "gt_max_freq_mhz", &max_freq_mhz))<br>
return false;<br>
<br>
brw->perfquery.sys_vars.gt_<wbr>min_freq = min_freq_mhz * 1000000;<br>
@@ -2023,9 +2020,7 @@ init_oa_sys_vars(struct brw_context *brw, const char *sysfs_dev_dir)<br>
}<br>
<br>
static bool<br>
-get_sysfs_dev_dir(struct brw_context *brw,<br>
- char *path_buf,<br>
- int path_buf_len)<br>
+get_sysfs_dev_dir(struct brw_context *brw)<br>
{<br>
__DRIscreen *screen = brw->screen->driScrnPriv;<br>
struct stat sb;<br>
@@ -2034,9 +2029,7 @@ get_sysfs_dev_dir(struct brw_context *brw,<br>
struct dirent *drm_entry;<br>
int len;<br>
<br>
- assert(path_buf);<br>
- assert(path_buf_len);<br>
- path_buf[0] = '\0';<br>
+ brw->perfquery.sysfs_dev_dir[<wbr>0] = '\0';<br>
<br>
if (fstat(screen->fd, &sb)) {<br>
DBG("Failed to stat DRM fd\n");<br>
@@ -2051,16 +2044,17 @@ get_sysfs_dev_dir(struct brw_context *brw,<br>
return false;<br>
}<br>
<br>
- len = snprintf(path_buf, path_buf_len,<br>
+ len = snprintf(brw->perfquery.sysfs_<wbr>dev_dir,<br>
+ sizeof(brw->perfquery.sysfs_<wbr>dev_dir),<br>
"/sys/dev/char/%d:%d/device/<wbr>drm", maj, min);<br>
- if (len < 0 || len >= path_buf_len) {<br>
+ if (len < 0 || len >= sizeof(brw->perfquery.sysfs_<wbr>dev_dir)) {<br>
DBG("Failed to concatenate sysfs path to drm device\n");<br>
return false;<br>
}<br>
<br>
- drmdir = opendir(path_buf);<br>
+ drmdir = opendir(brw->perfquery.sysfs_<wbr>dev_dir);<br>
if (!drmdir) {<br>
- DBG("Failed to open %s: %m\n", path_buf);<br>
+ DBG("Failed to open %s: %m\n", brw->perfquery.sysfs_dev_dir);<br>
return false;<br>
}<br>
<br>
@@ -2069,11 +2063,12 @@ get_sysfs_dev_dir(struct brw_context *brw,<br>
drm_entry->d_type == DT_LNK) &&<br>
strncmp(drm_entry->d_name, "card", 4) == 0)<br>
{<br>
- len = snprintf(path_buf, path_buf_len,<br>
+ len = snprintf(brw->perfquery.sysfs_<wbr>dev_dir,<br>
+ sizeof(brw->perfquery.sysfs_<wbr>dev_dir),<br>
"/sys/dev/char/%d:%d/device/<wbr>drm/%s",<br>
maj, min, drm_entry->d_name);<br>
closedir(drmdir);<br>
- if (len < 0 || len >= path_buf_len)<br>
+ if (len < 0 || len >= sizeof(brw->perfquery.sysfs_<wbr>dev_dir))<br>
return false;<br>
else<br>
return true;<br>
@@ -2134,7 +2129,6 @@ brw_init_perf_query_info(<wbr>struct gl_context *ctx)<br>
const struct gen_device_info *devinfo = &brw->screen->devinfo;<br>
bool i915_perf_oa_available = false;<br>
struct stat sb;<br>
- char sysfs_dev_dir[128];<br>
perf_register_oa_queries_t oa_register;<br>
<br>
if (brw->perfquery.n_queries)<br>
@@ -2166,8 +2160,8 @@ brw_init_perf_query_info(<wbr>struct gl_context *ctx)<br>
<br>
if (i915_perf_oa_available &&<br>
oa_register &&<br>
- get_sysfs_dev_dir(brw, sysfs_dev_dir, sizeof(sysfs_dev_dir)) &&<br>
- init_oa_sys_vars(brw, sysfs_dev_dir))<br>
+ get_sysfs_dev_dir(brw) &&<br>
+ init_oa_sys_vars(brw))<br>
{<br>
brw->perfquery.oa_metrics_<wbr>table =<br>
_mesa_hash_table_create(NULL, _mesa_key_hash_string,<br>
@@ -2179,10 +2173,10 @@ brw_init_perf_query_info(<wbr>struct gl_context *ctx)<br>
oa_register(brw);<br>
<br>
if (likely((INTEL_DEBUG & DEBUG_NO_OACONFIG) == 0) &&<br>
- kernel_has_dynamic_config_<wbr>support(brw, sysfs_dev_dir))<br>
- init_oa_configs(brw, sysfs_dev_dir);<br>
+ kernel_has_dynamic_config_<wbr>support(brw))<br>
+ init_oa_configs(brw);<br>
else<br>
- enumerate_sysfs_metrics(brw, sysfs_dev_dir);<br>
+ enumerate_sysfs_metrics(brw);<br>
}<br>
<br>
brw->perfquery.unaccumulated =<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.16.2<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>