[Intel-gfx] [PATCH i-g-t v5 10/11] tests/perf: prevent power management to kick in when necessary

2017-08-31 Thread Lionel Landwerlin
Some of our tests measure that the OA unit produces reports at
expected time intervals (as configured through the PERF_OPEN
ioctl). It turns out the power management plays a role in the decision
of the OA unit to write reports to memory. Under normal circumstances
we don't really mind if the unit misses one report here or there, but
for our tests it makes pretty difficult to verify whether we've made a
mistake in the configuration.

To work around this, let's prevent power management to kick in by
holding /dev/cpu_dma_latency opened for the following tests :

  - blocking
  - polling
  - buffer-fill
  - oa-exponents

Many thanks to Chris Wilson for suggesting this!

Signed-off-by: Lionel Landwerlin 
---
 tests/perf.c | 64 ++--
 1 file changed, 41 insertions(+), 23 deletions(-)

diff --git a/tests/perf.c b/tests/perf.c
index 6c062d20..070dee97 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -288,6 +288,7 @@ static bool hsw_undefined_a_counters[45] = {
 static bool gen8_undefined_a_counters[45];
 
 static int drm_fd = -1;
+static int pm_fd = -1;
 static int stream_fd = -1;
 static uint32_t devid;
 static int card = -1;
@@ -331,21 +332,38 @@ __perf_close(int fd)
 {
close(fd);
stream_fd = -1;
+
+   if (pm_fd >= 0) {
+   close(pm_fd);
+   pm_fd = -1;
+   }
 }
 
 static int
-__perf_open(int fd, struct drm_i915_perf_open_param *param)
+__perf_open(int fd, struct drm_i915_perf_open_param *param, bool prevent_pm)
 {
int ret;
+   int32_t pm_value = 0;
 
if (stream_fd >= 0)
__perf_close(stream_fd);
+   if (pm_fd >= 0) {
+   close(pm_fd);
+   pm_fd = -1;
+   }
 
ret = igt_ioctl(fd, DRM_IOCTL_I915_PERF_OPEN, param);
 
igt_assert(ret >= 0);
errno = 0;
 
+   if (prevent_pm) {
+   pm_fd = open("/dev/cpu_dma_latency", O_RDWR);
+   igt_assert(pm_fd >= 0);
+
+   igt_assert_eq(write(pm_fd, &pm_value, sizeof(pm_value)), 
sizeof(pm_value));
+   }
+
return ret;
 }
 
@@ -1257,7 +1275,7 @@ test_system_wide_paranoid(void)
 
igt_drop_root();
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
__perf_close(stream_fd);
}
 
@@ -1314,7 +1332,7 @@ test_invalid_oa_metric_set_id(void)
 
/* Check that we aren't just seeing false positives... */
properties[ARRAY_SIZE(properties) - 1] = test_metric_set_id;
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
__perf_close(stream_fd);
 
/* There's no valid default OA metric set ID... */
@@ -1348,7 +1366,7 @@ test_invalid_oa_format_id(void)
 
/* Check that we aren't just seeing false positives... */
properties[ARRAY_SIZE(properties) - 1] = test_oa_format;
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
__perf_close(stream_fd);
 
/* There's no valid default OA format... */
@@ -1512,7 +1530,7 @@ open_and_read_2_oa_reports(int format_id,
.properties_ptr = to_user_pointer(properties),
};
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
 
read_2_oa_reports(format_id, exponent,
  oa_report0, oa_report1, timer_only);
@@ -1916,7 +1934,7 @@ test_oa_exponents(void)
  oa_exponent_to_ns(exponent) / 1000.0,
  oa_exponent_to_ns(exponent) / (1000.0 * 
1000.0));
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, true /* 
prevent_pm */);
 
/* Right after opening the OA stream, read a
 * first timestamp as way to filter previously
@@ -2192,7 +2210,7 @@ test_invalid_oa_exponent(void)
.properties_ptr = to_user_pointer(properties),
};
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
 
__perf_close(stream_fd);
 
@@ -2246,7 +2264,7 @@ test_low_oa_exponent_permissions(void)
igt_fork(child, 1) {
igt_drop_root();
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
__perf_close(stream_fd);
}
 
@@ -2312,7 +2330,7 @@ test_per_context_mode_unprivileged(void)
 
properties[1] = ctx_id;
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   stream_fd = __perf_open(drm_fd, ¶m, false);
__perf_close(stream_fd);
 
drm_intel_gem_context_destroy(context);
@@ -2401,7 +2419,7 @@ test_blocking(void)
int64_t start, end;
int n = 0;
 
-   stream_fd = __perf_open(drm_fd, ¶m);
+   st

Re: [Intel-gfx] [PATCH i-g-t v5 10/11] tests/perf: prevent power management to kick in when necessary

2017-09-18 Thread Matthew Auld
On 08/31, Lionel Landwerlin wrote:
> Some of our tests measure that the OA unit produces reports at
> expected time intervals (as configured through the PERF_OPEN
> ioctl). It turns out the power management plays a role in the decision
> of the OA unit to write reports to memory. Under normal circumstances
> we don't really mind if the unit misses one report here or there, but
> for our tests it makes pretty difficult to verify whether we've made a
> mistake in the configuration.
> 
> To work around this, let's prevent power management to kick in by
> holding /dev/cpu_dma_latency opened for the following tests :
> 
>   - blocking
>   - polling
>   - buffer-fill
>   - oa-exponents
+- enable-disable

> 
> Many thanks to Chris Wilson for suggesting this!
> 
> Signed-off-by: Lionel Landwerlin 

Seems to cure the oa-exponents test for me, so:
Reviewed-by: Matthew Auld 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx