Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
To: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>,
	igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH 2/2] i915/perf: Sanity check reports in mapped OA buffer
Date: Tue, 21 Jul 2020 09:21:44 +0300	[thread overview]
Message-ID: <1b566afd-4806-cad9-1a55-e54bf3fdb1d9@intel.com> (raw)
In-Reply-To: <20200721015717.46279-2-umesh.nerlige.ramappa@intel.com>

Looks good, just one nit and a test suggestion.

On 21/07/2020 04:57, Umesh Nerlige Ramappa wrote:
> For applications that need a faster way to access reports in the OA
> buffer, i915 now provides a way to map the OA buffer to privileged user
> space. Add a test to sanity check reports in the mapped OA buffer.
>
> Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
> ---
>   include/drm-uapi/i915_drm.h |  32 +++++
>   tests/i915/perf.c           | 241 ++++++++++++++++++++++++++++++++++++
>   2 files changed, 273 insertions(+)
>
> diff --git a/include/drm-uapi/i915_drm.h b/include/drm-uapi/i915_drm.h
> index 2b55af13..f7523d55 100644
> --- a/include/drm-uapi/i915_drm.h
> +++ b/include/drm-uapi/i915_drm.h
> @@ -2048,6 +2048,38 @@ struct drm_i915_perf_open_param {
>    */
>   #define I915_PERF_IOCTL_CONFIG	_IO('i', 0x2)
>   
> +/**
> + * Returns OA buffer properties to be used with mmap.
> + *
> + * This ioctl is available in perf revision 6.
> + */
> +#define I915_PERF_IOCTL_GET_OA_BUFFER_INFO _IO('i', 0x3)
> +
> +/**
> + * OA buffer size and offset.
> + */
> +struct drm_i915_perf_oa_buffer_info {
> +	__u32 size;
> +	__u32 offset;
> +	__u64 reserved[4];
> +};
> +
> +/**
> + * Returns current position of OA buffer head and tail.
> + *
> + * This ioctl is available in perf revision 6.
> + */
> +#define I915_PERF_IOCTL_GET_OA_BUFFER_HEAD_TAIL _IO('i', 0x4)
> +
> +/**
> + * OA buffer head and tail.
> + */
> +struct drm_i915_perf_oa_buffer_head_tail {
> +	__u32 head;
> +	__u32 tail;
> +	__u64 reserved[4];
> +};

We should probably test head/tail values.

Open the stream with a fast enough exponent and verify they loop correctly?

> +
>   /**
>    * Common to all i915 perf records
>    */
> diff --git a/tests/i915/perf.c b/tests/i915/perf.c
> index eb38ea12..b7aa1596 100644
> --- a/tests/i915/perf.c
> +++ b/tests/i915/perf.c
> @@ -206,6 +206,7 @@ static struct intel_perf *intel_perf = NULL;
>   static struct intel_perf_metric_set *test_set = NULL;
>   static bool *undefined_a_counters;
>   static uint64_t oa_exp_1_millisec;
> +struct intel_mmio_data mmio_data;
>   
>   static igt_render_copyfunc_t render_copy = NULL;
>   static uint32_t (*read_report_ticks)(uint32_t *report,
> @@ -5011,6 +5012,220 @@ test_whitelisted_registers_userspace_config(void)
>   	i915_perf_remove_config(drm_fd, config_id);
>   }
>   
> +#define OA_BUFFER_DATA(tail, head, oa_buffer_size) \
> +	(((tail) - (head)) & ((oa_buffer_size) - 1))
> +
> +#ifndef MAP_FAILED
> +#define MAP_FAILED ((void *)-1)
> +#endif
> +
> +static uint32_t oa_status_reg(void)
> +{
> +	if (IS_HASWELL(devid))
> +		return intel_register_read(&mmio_data, 0x2346) & 0x7;
> +	else if (IS_GEN12(devid))
> +		return intel_register_read(&mmio_data, 0xdafc) & 0x7;
> +	else
> +		return intel_register_read(&mmio_data, 0x2b08) & 0xf;
> +}
> +
> +static void invalid_map_oa_buffer(void)
> +{
> +	struct drm_i915_perf_oa_buffer_info oa_buffer;
> +	void *oa_vaddr = NULL;
> +
> +	do_ioctl(stream_fd, I915_PERF_IOCTL_GET_OA_BUFFER_INFO, &oa_buffer);
> +
> +	igt_debug("size        = %d\n", oa_buffer.size);
> +	igt_debug("offset      = %x\n", oa_buffer.offset);
> +
> +	igt_assert_eq(oa_buffer.size & (oa_buffer.size - 1), 0);
> +
> +	/* try a couple invalid mmaps */
> +	/* bad offsets */
> +	oa_vaddr = mmap(0, oa_buffer.size, PROT_READ, MAP_PRIVATE, stream_fd, 0);
> +	igt_assert(oa_vaddr == MAP_FAILED);
> +
> +	oa_vaddr = mmap(0, oa_buffer.size, PROT_READ, MAP_PRIVATE, stream_fd, 8192);
> +	igt_assert(oa_vaddr == MAP_FAILED);
> +
> +	oa_vaddr = mmap(0, oa_buffer.size, PROT_READ, MAP_PRIVATE, stream_fd, 11);
> +	igt_assert(oa_vaddr == MAP_FAILED);
> +
> +	/* bad size */
> +	oa_vaddr = mmap(0, oa_buffer.size + 1, PROT_READ, MAP_PRIVATE, stream_fd, oa_buffer.offset);
> +	igt_assert(oa_vaddr == MAP_FAILED);
> +
> +	/* do the right thing */
> +	oa_vaddr = mmap(0, oa_buffer.size, PROT_READ, MAP_PRIVATE, stream_fd, oa_buffer.offset);
> +	igt_assert(oa_vaddr != NULL);

oa_vaddr != NULL && oa_vaddr != MAP_FAILED ;)


> +
> +	munmap(oa_vaddr, oa_buffer.size);
> +}
> +
> +static void *map_oa_buffer(uint32_t *size)
> +{

> ...

> +
>   static unsigned
>   read_i915_module_ref(void)
>   {
> @@ -5179,6 +5394,9 @@ igt_main
>   
>   		render_copy = igt_get_render_copyfunc(devid);
>   		igt_require_f(render_copy, "no render-copy function\n");
> +
> +		intel_register_access_init(&mmio_data, intel_get_pci_device(),
> +					   0, drm_fd);
>   	}
>   
>   	igt_subtest("non-system-wide-paranoid")
> @@ -5346,6 +5564,28 @@ igt_main
>   		test_triggered_oa_reports();
>   	}
>   
> +	igt_subtest_group {
> +		igt_fixture {
> +			igt_require(i915_perf_revision(drm_fd) >= 8);
> +		}
> +
> +		igt_describe("Verify mapping of oa buffer");
> +		igt_subtest("map-oa-buffer")
> +			test_mapped_oa_buffer(check_reports_from_mapped_buffer);
> +
> +		igt_describe("Verify invalid mappings of oa buffer");
> +		igt_subtest("invalid-map-oa-buffer")
> +			test_mapped_oa_buffer(invalid_map_oa_buffer);
> +
> +		igt_describe("Verify if non-privileged user can map oa buffer");
> +		igt_subtest("non-privileged-map-oa-buffer")
> +			test_mapped_oa_buffer(test_unprivileged_map_oa_buffer);
> +
> +		igt_describe("Close FD and access oa buffer");
> +		igt_subtest("close-fd-and-access-oa-buffer")
> +			close_fd_and_access_oa_buffer();

I think one additional test that would be helpful is to do the following :


for (i = 0; i < 256; i++) {

   int fd = perf_open();

   void *ptr = mmap(fd);

   close(fd);

}

16Mb * 256 = 4Gb

That way you verify that we're not leaking GGTT space when closing the 
perf fd.

You might want to tweak the noa_wait sysfs value before/after the loop.

This might also only work on !32bits machines with enough memory...


-Lionel


> +	}
> +
>   	igt_fixture {
>   		/* leave sysctl options in their default state... */
>   		write_u64_file("/proc/sys/dev/i915/oa_max_sample_rate", 100000);
> @@ -5354,6 +5594,7 @@ igt_main
>   		if (intel_perf)
>   			intel_perf_free(intel_perf);
>   
> +		intel_register_access_fini(&mmio_data);
>   		close(drm_fd);
>   	}
>   }


_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2020-07-21  6:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21  1:57 [igt-dev] [PATCH 1/2] i915/perf: add tests for triggered OA reports Umesh Nerlige Ramappa
2020-07-21  1:57 ` [igt-dev] [PATCH 2/2] i915/perf: Sanity check reports in mapped OA buffer Umesh Nerlige Ramappa
2020-07-21  6:21   ` Lionel Landwerlin [this message]
2020-07-24 23:33     ` Umesh Nerlige Ramappa
2020-07-27  7:31       ` Lionel Landwerlin
2020-07-21  2:23 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [1/2] i915/perf: add tests for triggered OA reports Patchwork
2020-07-21  3:37 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2020-07-17 23:58 [igt-dev] [PATCH 1/2] " Umesh Nerlige Ramappa
2020-07-17 23:58 ` [igt-dev] [PATCH 2/2] i915/perf: Sanity check reports in mapped OA buffer Umesh Nerlige Ramappa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b566afd-4806-cad9-1a55-e54bf3fdb1d9@intel.com \
    --to=lionel.g.landwerlin@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=umesh.nerlige.ramappa@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox