[igt-dev] [PATCH i-g-t v3 3/3] test/xe_pm: Add vram_d3cold_threshold subtest

Gupta, Anshuman anshuman.gupta at intel.com
Fri Jul 21 07:17:09 UTC 2023



> -----Original Message-----
> From: Nilawar, Badal <badal.nilawar at intel.com>
> Sent: Friday, July 21, 2023 9:35 AM
> To: Gupta, Anshuman <anshuman.gupta at intel.com>; igt-
> dev at lists.freedesktop.org
> Cc: Dixit, Ashutosh <ashutosh.dixit at intel.com>; Vivi, Rodrigo
> <rodrigo.vivi at intel.com>; Tauro, Riana <riana.tauro at intel.com>
> Subject: Re: [PATCH i-g-t v3 3/3] test/xe_pm: Add vram_d3cold_threshold
> subtest
> 
> Hi Anshuman,
> 
> On 18-07-2023 16:38, Anshuman Gupta wrote:
> > Adding a vram_d3cold_threshold subtest, which creates a Xe bo and set
> > the vram_d3cold_threshold according to vram used and bo size.
> > Test setups the d3cold and expect card to be limited to d3hot.
> >
> > v2:
> > - Add subtest doc.
> > v3:
> > - skip the test on igfx. [Riana]
> > - Test doc enhancement. [Riana]
> > - Create the bo before vram query. [Riana]
> > - Use xe_bo_map insead of xe_bo_mmap_offset and mmap. [Riana]
> > - Close the bo handle. [Riana]
> >
> > Signed-off-by: Anshuman Gupta <anshuman.gupta at intel.com>
> > ---
> >   tests/xe/xe_pm.c | 82
> ++++++++++++++++++++++++++++++++++++++++++++++++
> >   1 file changed, 82 insertions(+)
> >
> > diff --git a/tests/xe/xe_pm.c b/tests/xe/xe_pm.c index
> > 11a4c3705..a8257b13c 100644
> > --- a/tests/xe/xe_pm.c
> > +++ b/tests/xe/xe_pm.c
> > @@ -20,6 +20,7 @@
> >   #include "lib/igt_device.h"
> >   #include "lib/igt_kms.h"
> >   #include "lib/igt_pm.h"
> > +#include "lib/igt_sysfs.h"
> >   #include "lib/igt_syncobj.h"
> >   #include "lib/intel_reg.h"
> >
> > @@ -31,6 +32,8 @@
> >   #define NO_SUSPEND -1
> >   #define NO_RPM -1
> >
> > +#define SIZE (4096 * 1024)
> > +
> >   typedef struct {
> >   	int fd_xe;
> >   	struct pci_device *pci_xe;
> > @@ -77,6 +80,22 @@ static void set_d3cold_allowed(struct pci_device
> *pci,
> >   	close(fd);
> >   }
> >
> > +static void set_vram_d3cold_threshold(int sysfs, uint64_t threshold)
> > +{
> > +	char path[64];
> > +	int ret;
> > +
> > +	sprintf(path, "device/vram_d3cold_threshold");
> > +
> > +	if (!faccessat(sysfs, path, R_OK | W_OK, 0))
> > +		ret = igt_sysfs_printf(sysfs, path, "%lu", threshold);
> > +	else
> > +		igt_warn("vram_d3cold_threshold is not present\n");
> > +
> > +	igt_info("ret value %d", ret);
> > +	igt_assert(ret > 0);
> > +}
> > +
> >   static bool setup_d3(device_t device, enum igt_acpi_d_state state)
> >   {
> >   	igt_dpms_turn_off_display(device.fd_xe);
> > @@ -349,6 +368,64 @@ NULL));
> >   		igt_assert(in_d3(device, d_state));
> >   }
> >
> > +/**
> > + * SUBTEST: vram-d3cold-threshold
> > + * Description:
> > + *	Validate whether card is limited to d3hot while vram used
> > + *	is greater than vram_d3cold_threshold.
> > + * Run type: FULL
> > + */
> > +static void test_vram_d3cold_threshold(device_t device) {
> > +	struct drm_xe_query_mem_usage *mem_usage;
> > +	struct drm_xe_device_query query = {
> > +		.extensions = 0,
> > +		.query = DRM_XE_DEVICE_QUERY_MEM_USAGE,
> > +		.size = 0,
> > +		.data = 0,
> > +	};
> > +	uint64_t vram_used_mb = 0, vram_total_mb = 0, threshold;
> > +	uint32_t bo, flags;
> > +	void *map;
> > +	int i, sysfs_fd;
> > +
> > +	flags = vram_memory(device.fd_xe, 0);
> > +	igt_require_f(flags, "Device doesn't support vram memory
> region\n");
> > +
> > +	igt_assert_eq(igt_ioctl(device.fd_xe,
> DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
> > +	igt_assert_neq(query.size, 0);
> > +
> > +	mem_usage = malloc(query.size);
> > +	igt_assert(mem_usage);
> > +
> > +	query.data = to_user_pointer(mem_usage);
> > +	igt_assert_eq(igt_ioctl(device.fd_xe,
> DRM_IOCTL_XE_DEVICE_QUERY,
> > +&query), 0);
> > +
> > +	for (i = 0; i < mem_usage->num_regions; i++) {
> > +		if (mem_usage->regions[i].mem_class ==
> XE_MEM_REGION_CLASS_VRAM) {
> > +			vram_used_mb +=  (mem_usage->regions[i].used /
> (1024 * 1024));
> > +			vram_total_mb += (mem_usage-
> >regions[i].total_size / (1024 * 1024));
> > +		}
> > +	}
> > +
> > +	threshold = vram_used_mb;
> > +	igt_require(threshold < vram_total_mb);
> > +
> > +	bo = xe_bo_create_flags(device.fd_xe, 0, SIZE, flags);
> > +	map = xe_bo_map(device.fd_xe, bo, SIZE);
> > +	memset(map, 0, SIZE);
> > +	munmap(map, SIZE);
> > +	sysfs_fd = igt_sysfs_open(device.fd_xe);
> > +	set_vram_d3cold_threshold(sysfs_fd, threshold);
> > +	close(sysfs_fd);
> > +
> > +	/* Setup D3Cold but card should be in D3hot */
> > +	igt_assert(setup_d3(device, IGT_ACPI_D3Cold));
> > +	igt_assert(in_d3(device, IGT_ACPI_D3Hot));
> > +	igt_assert(out_of_d3(device, IGT_ACPI_D3Cold));
> > +	gem_close(device.fd_xe, bo);
> Should original threshold be restored here to allow D3 cold?
thanks for review, I will fix this.
> 
> Regards,
> Badal
> > +}
> > +
> >   igt_main
> >   {
> >   	struct drm_xe_engine_class_instance *hwe; @@ -449,6 +526,11 @@
> > igt_main
> >   		}
> >   	}
> >
> > +	igt_describe("Validate whether card is limited to d3hot, if vram used
> > vram threshold");
> > +	igt_subtest("vram-d3cold-threshold") {
> > +		test_vram_d3cold_threshold(device);
> > +	}
> > +
> >   	igt_fixture {
> >   		set_d3cold_allowed(device.pci_xe, d3cold_allowed);
> >   		igt_restore_runtime_pm();


More information about the igt-dev mailing list