When debugging unstable tests on new platforms we currently we don't cleanup everything well in between different tests. Since only a single OA stream fd can be opened at a time, having the stream_fd as a global variable helps us cleanup the state between tests. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@xxxxxxxxx> --- tests/perf.c | 121 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/tests/perf.c b/tests/perf.c index dd2263ee..ca5bfdc5 100644 --- a/tests/perf.c +++ b/tests/perf.c @@ -285,6 +285,7 @@ static bool hsw_undefined_a_counters[45] = { static bool gen8_undefined_a_counters[45]; static int drm_fd = -1; +static int stream_fd = -1; static uint32_t devid; static int card = -1; static int n_eus; @@ -306,10 +307,22 @@ static uint32_t (*read_report_ticks)(uint32_t *report, static void (*sanity_check_reports)(uint32_t *oa_report0, uint32_t *oa_report1, enum drm_i915_oa_format format); +static void +__perf_close(int fd) +{ + close(fd); + stream_fd = -1; +} + static int __perf_open(int fd, struct drm_i915_perf_open_param *param) { - int ret = igt_ioctl(fd, DRM_IOCTL_I915_PERF_OPEN, param); + int ret; + + if (stream_fd >= 0) + __perf_close(stream_fd); + + ret = igt_ioctl(fd, DRM_IOCTL_I915_PERF_OPEN, param); igt_assert(ret >= 0); errno = 0; @@ -960,14 +973,12 @@ test_system_wide_paranoid(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd; - write_u64_file("/proc/sys/dev/i915/perf_stream_paranoid", 0); igt_drop_root(); stream_fd = __perf_open(drm_fd, ¶m); - close(stream_fd); + __perf_close(stream_fd); } igt_waitchildren(); @@ -1015,7 +1026,6 @@ test_invalid_oa_metric_set_id(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd; do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m, EINVAL); @@ -1025,7 +1035,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); - close(stream_fd); + __perf_close(stream_fd); /* There's no valid default OA metric set ID... */ param.num_properties--; @@ -1050,7 +1060,6 @@ test_invalid_oa_format_id(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd; do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m, EINVAL); @@ -1060,7 +1069,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); - close(stream_fd); + __perf_close(stream_fd); /* There's no valid default OA format... */ param.num_properties--; @@ -1088,8 +1097,7 @@ test_missing_sample_flags(void) } static void -read_2_oa_reports(int stream_fd, - int format_id, +read_2_oa_reports(int format_id, int exponent, uint32_t *oa_report0, uint32_t *oa_report1, @@ -1223,12 +1231,13 @@ open_and_read_2_oa_reports(int format_id, .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); - read_2_oa_reports(stream_fd, format_id, exponent, + stream_fd = __perf_open(drm_fd, ¶m); + + read_2_oa_reports(format_id, exponent, oa_report0, oa_report1, timer_only); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -1528,9 +1537,10 @@ test_invalid_oa_exponent(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); - close(stream_fd); + stream_fd = __perf_open(drm_fd, ¶m); + + __perf_close(stream_fd); for (int i = 32; i < 65; i++) { properties[7] = i; @@ -1580,12 +1590,10 @@ test_low_oa_exponent_permissions(void) properties[7] = ok_exponent; igt_fork(child, 1) { - int stream_fd; - igt_drop_root(); stream_fd = __perf_open(drm_fd, ¶m); - close(stream_fd); + __perf_close(stream_fd); } igt_waitchildren(); @@ -1634,7 +1642,6 @@ test_per_context_mode_unprivileged(void) igt_fork(child, 1) { drm_intel_context *context; drm_intel_bufmgr *bufmgr; - int stream_fd; uint32_t ctx_id = 0xffffffff; /* invalid id */ int ret; @@ -1652,7 +1659,7 @@ test_per_context_mode_unprivileged(void) properties[1] = ctx_id; stream_fd = __perf_open(drm_fd, ¶m); - close(stream_fd); + __perf_close(stream_fd); drm_intel_gem_context_destroy(context); drm_intel_bufmgr_destroy(bufmgr); @@ -1715,7 +1722,6 @@ test_blocking(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); uint8_t buf[1024 * 1024]; struct tms start_times; struct tms end_times; @@ -1740,6 +1746,8 @@ test_blocking(void) int64_t start; int n = 0; + stream_fd = __perf_open(drm_fd, ¶m); + times(&start_times); igt_debug("tick length = %dns, test duration = %"PRIu64"ns, min iter. = %d, max iter. = %d\n", @@ -1837,7 +1845,7 @@ test_blocking(void) igt_assert(kernel_ns <= (test_duration_ns / 100ull)); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -1866,7 +1874,6 @@ test_polling(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); uint8_t buf[1024 * 1024]; struct tms start_times; struct tms end_times; @@ -1890,6 +1897,8 @@ test_polling(void) int64_t start; int n = 0; + stream_fd = __perf_open(drm_fd, ¶m); + times(&start_times); igt_debug("tick length = %dns, test duration = %"PRIu64"ns, min iter. = %d, max iter. = %d\n", @@ -2018,7 +2027,7 @@ test_polling(void) igt_assert(kernel_ns <= (test_duration_ns / 100ull)); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -2041,7 +2050,6 @@ test_buffer_fill(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); int buf_size = 65536 * (256 + sizeof(struct drm_i915_perf_record_header)); uint8_t *buf = malloc(buf_size); size_t oa_buf_size = 16 * 1024 * 1024; @@ -2051,6 +2059,8 @@ test_buffer_fill(void) igt_assert(fill_duration < 1000000000); + stream_fd = __perf_open(drm_fd, ¶m); + for (int i = 0; i < 5; i++) { struct drm_i915_perf_record_header *header; bool overflow_seen; @@ -2101,7 +2111,7 @@ test_buffer_fill(void) free(buf); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -2125,7 +2135,6 @@ test_enable_disable(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); int buf_size = 65536 * (256 + sizeof(struct drm_i915_perf_record_header)); uint8_t *buf = malloc(buf_size); size_t oa_buf_size = 16 * 1024 * 1024; @@ -2133,6 +2142,7 @@ test_enable_disable(void) int n_full_oa_reports = oa_buf_size / report_size; uint64_t fill_duration = n_full_oa_reports * oa_period; + stream_fd = __perf_open(drm_fd, ¶m); for (int i = 0; i < 5; i++) { int len; @@ -2178,7 +2188,7 @@ test_enable_disable(void) free(buf); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -2205,7 +2215,6 @@ test_short_reads(void) uint8_t *pages = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, MAP_PRIVATE, zero_fd, 0); struct drm_i915_perf_record_header *header; - int stream_fd; int ret; igt_assert_neq(zero_fd, -1); @@ -2262,7 +2271,7 @@ test_short_reads(void) igt_assert_eq(ret, -1); igt_assert_eq(errno, ENOSPC); - close(stream_fd); + __perf_close(stream_fd); munmap(pages, page_size * 2); } @@ -2287,14 +2296,16 @@ test_non_sampling_read_error(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); + int ret; uint8_t buf[1024]; - int ret = read(stream_fd, buf, sizeof(buf)); + stream_fd = __perf_open(drm_fd, ¶m); + + ret = read(stream_fd, buf, sizeof(buf)); igt_assert_eq(ret, -1); igt_assert_eq(errno, EIO); - close(stream_fd); + __perf_close(stream_fd); } /* Check that attempts to read from a stream while it is disable will return @@ -2321,25 +2332,24 @@ test_disabled_read_error(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); uint32_t oa_report0[64]; uint32_t oa_report1[64]; uint32_t buf[128] = { 0 }; int ret; + stream_fd = __perf_open(drm_fd, ¶m); ret = read(stream_fd, buf, sizeof(buf)); igt_assert_eq(ret, -1); igt_assert_eq(errno, EIO); - close(stream_fd); + __perf_close(stream_fd); param.flags &= ~I915_PERF_FLAG_DISABLED; stream_fd = __perf_open(drm_fd, ¶m); - read_2_oa_reports(stream_fd, - test_oa_format, + read_2_oa_reports(test_oa_format, oa_exponent, oa_report0, oa_report1, @@ -2353,14 +2363,13 @@ test_disabled_read_error(void) do_ioctl(stream_fd, I915_PERF_IOCTL_ENABLE, 0); - read_2_oa_reports(stream_fd, - test_oa_format, + read_2_oa_reports(test_oa_format, oa_exponent, oa_report0, oa_report1, false); /* not just timer reports */ - close(stream_fd); + __perf_close(stream_fd); } static void @@ -2409,7 +2418,6 @@ test_mi_rpc(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); drm_intel_bufmgr *bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096); drm_intel_context *context; struct intel_batchbuffer *batch; @@ -2417,6 +2425,8 @@ test_mi_rpc(void) uint32_t *report32; int ret; + stream_fd = __perf_open(drm_fd, ¶m); + drm_intel_bufmgr_gem_enable_reuse(bufmgr); context = drm_intel_gem_context_create(bufmgr); @@ -2454,7 +2464,7 @@ test_mi_rpc(void) intel_batchbuffer_free(batch); drm_intel_gem_context_destroy(context); drm_intel_bufmgr_destroy(bufmgr); - close(stream_fd); + __perf_close(stream_fd); } static void @@ -2545,7 +2555,6 @@ hsw_test_single_ctx_counters(void) igt_fork(child, 1) { drm_intel_bufmgr *bufmgr; drm_intel_context *context0, *context1; - int stream_fd; struct intel_batchbuffer *batch; struct igt_buf src, dst; drm_intel_bo *bo; @@ -2724,7 +2733,7 @@ hsw_test_single_ctx_counters(void) drm_intel_gem_context_destroy(context0); drm_intel_gem_context_destroy(context1); drm_intel_bufmgr_destroy(bufmgr); - close(stream_fd); + __perf_close(stream_fd); } igt_waitchildren(); @@ -2747,10 +2756,12 @@ test_rc6_disable(void) .num_properties = sizeof(properties) / 16, .properties_ptr = to_user_pointer(properties), }; - int stream_fd = __perf_open(drm_fd, ¶m); - uint64_t n_events_start = read_debugfs_u64_record(drm_fd, "i915_drpc_info", - "RC6 residency since boot"); - uint64_t n_events_end; + uint64_t n_events_start, n_events_end; + + stream_fd = __perf_open(drm_fd, ¶m); + + n_events_start = read_debugfs_u64_record(drm_fd, "i915_drpc_info", + "RC6 residency since boot"); nanosleep(&(struct timespec){ .tv_sec = 0, .tv_nsec = 500000000 }, NULL); @@ -2759,12 +2770,12 @@ test_rc6_disable(void) igt_assert_eq(n_events_end - n_events_start, 0); - close(stream_fd); + __perf_close(stream_fd); n_events_start = read_debugfs_u64_record(drm_fd, "i915_drpc_info", "RC6 residency since boot"); - nanosleep(&(struct timespec){ .tv_sec = 0, .tv_nsec = 500000000 }, NULL); + nanosleep(&(struct timespec){ .tv_sec = 1, .tv_nsec = 0 }, NULL); n_events_end = read_debugfs_u64_record(drm_fd, "i915_drpc_info", "RC6 residency since boot"); @@ -2902,7 +2913,7 @@ test_create_destroy_userspace_config(void) const char *uuid = "01234567-0123-0123-0123-0123456789ab"; uint32_t mux_regs[] = { 0x9888 /* NOA_WRITE */, 0x0 }; uint32_t flex_regs[100]; - int i, stream_fd; + int i; uint64_t config_id; uint64_t properties[] = { DRM_I915_PERF_PROP_OA_METRICS_SET, 0, /* Filled later */ @@ -2970,7 +2981,7 @@ test_create_destroy_userspace_config(void) /* Read the config to verify shouldn't raise any issue. */ config_id = i915_perf_add_config(drm_fd, &config); - close(stream_fd); + __perf_close(stream_fd); i915_perf_remove_config(drm_fd, config_id); } @@ -3142,7 +3153,6 @@ test_i915_ref_count(void) .properties_ptr = to_user_pointer(properties), }; unsigned baseline, ref_count0, ref_count1; - int stream_fd; uint32_t oa_report0[64]; uint32_t oa_report1[64]; @@ -3182,14 +3192,13 @@ test_i915_ref_count(void) igt_assert(ref_count0 > baseline); - read_2_oa_reports(stream_fd, - test_oa_format, + read_2_oa_reports(test_oa_format, oa_exp_1_millisec, oa_report0, oa_report1, false); /* not just timer reports */ - close(stream_fd); + __perf_close(stream_fd); ref_count0 = read_i915_module_ref(); igt_debug("ref count after closing i915 perf stream fd = %u\n", ref_count0); igt_assert_eq(ref_count0, baseline); -- 2.14.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx