Initial Xe test suite
Subsystems (2)
v8 cover Initial Xe test suite
This is continuation of https://patchwork.freedesktop.org/series/112191/
Series doesn't contain KUnit changes as they are not upstream IGT ready yet. Functional changes (library, tests, etc.) were squashed to dedicated patch to make review easier.
v3: address review comments (Kamil, Mauro)
v4: address review comments (Michał)
- add documentation for most of public functions
- use function generator instead of RETV() macro
- fix gt usage on memory regioning (it might lead to same region)
v5: - fix _Static_assert() error produced on older compilers
- temporary drop igt_doc.py, we'll provide new version for older pythons
v6: - alter xe_vm to use long long (Zbigniew)
v7: - fixed missed one subtest which should use long long (Zbigniew)
v8: - fixed two subtests which didn't compile on mips/armhf (Zbigniew)
Rodrigo Vivi (1):
lib/igt_pm: Add a helper to query the runtime_usage.
Zbigniew Kempczyński (6):
drm-uapi/xe_drm: Add Xe uAPI
lib/xe: Introduce Xe library
tests/xe: Add Xe IGT tests
tools/xe_reg: Add Xe register read/write tool intel-ci/xe-fast-feedback: Introduce xe-fast-feedback list runner/job_list: return error on crashes while running --list-subtests
include/drm-uapi/xe_drm.h | 807 +++++++++++ lib/drmtest.c | 3 + lib/drmtest.h | 1 + lib/igt_pm.c | 18 + lib/igt_pm.h | 1 + lib/meson.build | 4 + lib/xe/xe_compute.c | 406 ++++++ lib/xe/xe_compute.h | 29 + lib/xe/xe_ioctl.c | 436 ++++++ lib/xe/xe_ioctl.h | 87 ++ lib/xe/xe_query.c | 471 +++++++ lib/xe/xe_query.h | 94 ++ lib/xe/xe_spin.c | 157 +++ lib/xe/xe_spin.h | 48 + meson.build | 8 + runner/job_list.c | 1 + tests/intel-ci/meson.build | 1 + tests/intel-ci/xe-fast-feedback.testlist | 140 ++ tests/meson.build | 1 + tests/xe/meson.build | 33 + tests/xe/xe_compute.c | 148 ++ tests/xe/xe_debugfs.c | 257 ++++ tests/xe/xe_dma_buf_sync.c | 262 ++++ tests/xe/xe_evict.c | 623 +++++++++ tests/xe/xe_exec_balancer.c | 714 ++++++++++ tests/xe/xe_exec_basic.c | 350 +++++ tests/xe/xe_exec_compute_mode.c | 364 +++++ tests/xe/xe_exec_fault_mode.c | 575 ++++++++ tests/xe/xe_exec_reset.c | 817 +++++++++++ tests/xe/xe_exec_threads.c | 1166 ++++++++++++++++ tests/xe/xe_guc_pc.c | 425 ++++++ tests/xe/xe_huc_copy.c | 205 +++ tests/xe/xe_mmap.c | 79 ++ tests/xe/xe_mmio.c | 94 ++ tests/xe/xe_pm.c | 385 ++++++ tests/xe/xe_prime_self_import.c | 489 +++++++ tests/xe/xe_query.c | 475 +++++++ tests/xe/xe_test_config.json | 133 ++ tests/xe/xe_vm.c | 1612 ++++++++++++++++++++++ tests/xe/xe_waitfence.c | 103 ++ tools/meson.build | 1 + tools/xe_reg.c | 366 +++++ 42 files changed, 12389 insertions(+) create mode 100644 include/drm-uapi/xe_drm.h create mode 100644 lib/xe/xe_compute.c create mode 100644 lib/xe/xe_compute.h create mode 100644 lib/xe/xe_ioctl.c create mode 100644 lib/xe/xe_ioctl.h create mode 100644 lib/xe/xe_query.c create mode 100644 lib/xe/xe_query.h create mode 100644 lib/xe/xe_spin.c create mode 100644 lib/xe/xe_spin.h create mode 100644 tests/intel-ci/xe-fast-feedback.testlist create mode 100644 tests/xe/meson.build create mode 100644 tests/xe/xe_compute.c create mode 100644 tests/xe/xe_debugfs.c create mode 100644 tests/xe/xe_dma_buf_sync.c create mode 100644 tests/xe/xe_evict.c create mode 100644 tests/xe/xe_exec_balancer.c create mode 100644 tests/xe/xe_exec_basic.c create mode 100644 tests/xe/xe_exec_compute_mode.c create mode 100644 tests/xe/xe_exec_fault_mode.c create mode 100644 tests/xe/xe_exec_reset.c create mode 100644 tests/xe/xe_exec_threads.c create mode 100644 tests/xe/xe_guc_pc.c create mode 100644 tests/xe/xe_huc_copy.c create mode 100644 tests/xe/xe_mmap.c create mode 100644 tests/xe/xe_mmio.c create mode 100644 tests/xe/xe_pm.c create mode 100644 tests/xe/xe_prime_self_import.c create mode 100644 tests/xe/xe_query.c create mode 100644 tests/xe/xe_test_config.json create mode 100644 tests/xe/xe_vm.c create mode 100644 tests/xe/xe_waitfence.c create mode 100644 tools/xe_reg.c
Signature · 1 line
2.34.1
PATCH v8 1/7 drm-uapi/xe_drm: Add Xe uAPI
Introduce uAPI contract for Xe IGT.
--- include/drm-uapi/xe_drm.h | 807 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 807 insertions(+) create mode 100644 include/drm-uapi/xe_drm.h
include/drm-uapi/xe_drm.h new file +807 -0
@@ -0,0 +1,807 @@ +/* +* Copyright 2021 Intel Corporation. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR +* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef _UAPI_XE_DRM_H_ +#define _UAPI_XE_DRM_H_ + +#include "drm.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/* Please note that modifications to all structs defined here are +* subject to backwards-compatibility constraints. +*/ + +/** +* struct i915_user_extension - Base class for defining a chain of extensions +* +* Many interfaces need to grow over time. In most cases we can simply +* extend the struct and have userspace pass in more data. Another option, +* as demonstrated by Vulkan's approach to providing extensions for forward +* and backward compatibility, is to use a list of optional structs to +* provide those extra details. +* +* The key advantage to using an extension chain is that it allows us to +* redefine the interface more easily than an ever growing struct of +* increasing complexity, and for large parts of that interface to be +* entirely optional. The downside is more pointer chasing; chasing across +* the __user boundary with pointers encapsulated inside u64. +* +* Example chaining: +* +* .. code-block:: C +* +* struct i915_user_extension ext3 { +* .next_extension = 0, // end +* .name = ..., +* }; +* struct i915_user_extension ext2 { +* .next_extension = (uintptr_t)&ext3, +* .name = ..., +* }; +* struct i915_user_extension ext1 { +* .next_extension = (uintptr_t)&ext2, +* .name = ..., +* }; +* +* Typically the struct i915_user_extension would be embedded in some uAPI +* struct, and in this case we would feed it the head of the chain(i.e ext1), +* which would then apply all of the above extensions. +* +*/ +struct xe_user_extension { +/** +* @next_extension: +* +* Pointer to the next struct i915_user_extension, or zero if the end. +*/ +__u64 next_extension; +/** +* @name: Name of the extension. +* +* Note that the name here is just some integer. +* +* Also note that the name space for this is not global for the whole +* driver, but rather its scope/meaning is limited to the specific piece +* of uAPI which has embedded the struct i915_user_extension. +*/ +__u32 name; +/** +* @flags: MBZ +* +* All undefined bits must be zero. +*/ +__u32 pad; +}; + +/* +* i915 specific ioctls. +* +* The device specific ioctl range is [DRM_COMMAND_BASE, DRM_COMMAND_END) ie +* [0x40, 0xa0) (a0 is excluded). The numbers below are defined as offset +* against DRM_COMMAND_BASE and should be between [0x0, 0x60). +*/ +#define DRM_XE_DEVICE_QUERY 0x00 +#define DRM_XE_GEM_CREATE 0x01 +#define DRM_XE_GEM_MMAP_OFFSET 0x02 +#define DRM_XE_VM_CREATE 0x03 +#define DRM_XE_VM_DESTROY 0x04 +#define DRM_XE_VM_BIND 0x05 +#define DRM_XE_ENGINE_CREATE 0x06 +#define DRM_XE_ENGINE_DESTROY 0x07 +#define DRM_XE_EXEC 0x08 +#define DRM_XE_MMIO 0x09 +#define DRM_XE_ENGINE_SET_PROPERTY 0x0a +#define DRM_XE_WAIT_USER_FENCE 0x0b +#define DRM_XE_VM_MADVISE 0x0c +#define DRM_XE_ENGINE_GET_PROPERTY 0x0d + +/* Must be kept compact -- no holes */ +#define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query) +#define DRM_IOCTL_XE_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_CREATE, struct drm_xe_gem_create) +#define DRM_IOCTL_XE_GEM_MMAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_MMAP_OFFSET, struct drm_xe_gem_mmap_offset) +#define DRM_IOCTL_XE_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_CREATE, struct drm_xe_vm_create) +#define DRM_IOCTL_XE_VM_DESTROY DRM_IOW( DRM_COMMAND_BASE + DRM_XE_VM_DESTROY, struct drm_xe_vm_destroy) +#define DRM_IOCTL_XE_VM_BIND DRM_IOW( DRM_COMMAND_BASE + DRM_XE_VM_BIND, struct drm_xe_vm_bind) +#define DRM_IOCTL_XE_ENGINE_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_ENGINE_CREATE, struct drm_xe_engine_create) +#define DRM_IOCTL_XE_ENGINE_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_ENGINE_GET_PROPERTY, struct drm_xe_engine_get_property) +#define DRM_IOCTL_XE_ENGINE_DESTROY DRM_IOW( DRM_COMMAND_BASE + DRM_XE_ENGINE_DESTROY, struct drm_xe_engine_destroy) +#define DRM_IOCTL_XE_EXEC DRM_IOW( DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec) +#define DRM_IOCTL_XE_MMIO DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_MMIO, struct drm_xe_mmio) +#define DRM_IOCTL_XE_ENGINE_SET_PROPERTY DRM_IOW( DRM_COMMAND_BASE + DRM_XE_ENGINE_SET_PROPERTY, struct drm_xe_engine_set_property) +#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence) +#define DRM_IOCTL_XE_VM_MADVISE DRM_IOW( DRM_COMMAND_BASE + DRM_XE_VM_MADVISE, struct drm_xe_vm_madvise) + +struct drm_xe_engine_class_instance { +__u16 engine_class; + +#define DRM_XE_ENGINE_CLASS_RENDER 0 +#define DRM_XE_ENGINE_CLASS_COPY 1 +#define DRM_XE_ENGINE_CLASS_VIDEO_DECODE 2 +#define DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 3 +#define DRM_XE_ENGINE_CLASS_COMPUTE 4 +/* +* Kernel only class (not actual hardware engine class). Used for +* creating ordered queues of VM bind operations. +*/ +#define DRM_XE_ENGINE_CLASS_VM_BIND 5 + +__u16 engine_instance; +__u16 gt_id; +}; + +#define XE_MEM_REGION_CLASS_SYSMEM 0 +#define XE_MEM_REGION_CLASS_VRAM 1 + +struct drm_xe_query_mem_usage { +__u32 num_regions; +__u32 pad; + +struct drm_xe_query_mem_region { +__u16 mem_class; +__u16 instance;/* unique ID even among different classes */ +__u32 pad; +__u32 min_page_size; +__u32 max_page_size; +__u64 total_size; +__u64 used; +__u64 reserved[8 ]; + } regions[]; +}; + +struct drm_xe_query_config { +__u32 num_params; +__u32 pad; +#define XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0 +#define XE_QUERY_CONFIG_FLAGS 1 +#define XE_QUERY_CONFIG_FLAGS_HAS_VRAM (0x1 << 0) +#define XE_QUERY_CONFIG_FLAGS_USE_GUC (0x1 << 1) +#define XE_QUERY_CONFIG_MIN_ALIGNEMENT 2 +#define XE_QUERY_CONFIG_VA_BITS 3 +#define XE_QUERY_CONFIG_GT_COUNT 4 +#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5 +#define XE_QUERY_CONFIG_NUM_PARAM XE_QUERY_CONFIG_MEM_REGION_COUNT + 1 +__u64 info[]; +}; + +struct drm_xe_query_gts { +__u32 num_gt; +__u32 pad; + +/* +* TODO: Perhaps info about every mem region relative to this GT? e.g. +* bandwidth between this GT and remote region? +*/ + +struct drm_xe_query_gt { +#define XE_QUERY_GT_TYPE_MAIN 0 +#define XE_QUERY_GT_TYPE_REMOTE 1 +#define XE_QUERY_GT_TYPE_MEDIA 2 +__u16 type; +__u16 instance; +__u32 clock_freq; +__u64 features; +__u64 native_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ +__u64 slow_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ +__u64 inaccessible_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ +__u64 reserved[8 ]; + } gts[]; +}; + +struct drm_xe_query_topology_mask { +/** @gt_id: GT ID the mask is associated with */ +__u16 gt_id; + +/** @type: type of mask */ +__u16 type; +#define XE_TOPO_DSS_GEOMETRY (1 << 0) +#define XE_TOPO_DSS_COMPUTE (1 << 1) +#define XE_TOPO_EU_PER_DSS (1 << 2) + +/** @num_bytes: number of bytes in requested mask */ +__u32 num_bytes; + +/** @mask: little-endian mask of @num_bytes */ +__u8 mask[]; +}; + +struct drm_xe_device_query { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @query: The type of data to query */ +__u32 query; + +#define DRM_XE_DEVICE_QUERY_ENGINES 0 +#define DRM_XE_DEVICE_QUERY_MEM_USAGE 1 +#define DRM_XE_DEVICE_QUERY_CONFIG 2 +#define DRM_XE_DEVICE_QUERY_GTS 3 +#define DRM_XE_DEVICE_QUERY_HWCONFIG 4 +#define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5 + +/** @size: Size of the queried data */ +__u32 size; + +/** @data: Queried data is placed here */ +__u64 data; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_gem_create { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** +* @size: Requested size for the object +* +* The (page-aligned) allocated size for the object will be returned. +*/ +__u64 size; + +/** +* @flags: Flags, currently a mask of memory instances of where BO can +* be placed +*/ +#define XE_GEM_CREATE_FLAG_DEFER_BACKING (0x1 << 24) +#define XE_GEM_CREATE_FLAG_SCANOUT (0x1 << 25) +__u32 flags; + +/** +* @vm_id: Attached VM, if any +* +* If a VM is specified, this BO must: +* +* 1. Only ever be bound to that VM. +* +* 2. Cannot be exported as a PRIME fd. +*/ +__u32 vm_id; + +/** +* @handle: Returned handle for the object. +* +* Object handles are nonzero. +*/ +__u32 handle; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_gem_mmap_offset { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @handle: Handle for the object being mapped. */ +__u32 handle; + +/** @flags: Must be zero */ +__u32 flags; + +/** @offset: The fake offset to use for subsequent mmap call */ +__u64 offset; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +/** +* struct drm_xe_vm_bind_op_error_capture - format of VM bind op error capture +*/ +struct drm_xe_vm_bind_op_error_capture { +/** @error: errno that occured */ +__s32 error; +/** @op: operation that encounter an error */ +__u32 op; +/** @addr: address of bind op */ +__u64 addr; +/** @size: size of bind */ +__u64 size; +}; + +/** struct drm_xe_ext_vm_set_property - VM set property extension */ +struct drm_xe_ext_vm_set_property { +/** @base: base user extension */ +struct xe_user_extension base; + +/** @property: property to set */ +#define XE_VM_PROPERTY_BIND_OP_ERROR_CAPTURE_ADDRESS 0 +__u32 property; + +/** @value: property value */ +__u64 value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_vm_create { +/** @extensions: Pointer to the first extension struct, if any */ +#define XE_VM_EXTENSION_SET_PROPERTY 0 +__u64 extensions; + +/** @flags: Flags */ +__u32 flags; + +#define DRM_XE_VM_CREATE_SCRATCH_PAGE (0x1 << 0) +#define DRM_XE_VM_CREATE_COMPUTE_MODE (0x1 << 1) +#define DRM_XE_VM_CREATE_ASYNC_BIND_OPS (0x1 << 2) +#define DRM_XE_VM_CREATE_FAULT_MODE (0x1 << 3) + +/** @vm_id: Returned VM ID */ +__u32 vm_id; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_vm_destroy { +/** @vm_id: VM ID */ +__u32 vm_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_vm_bind_op { +/** +* @obj: GEM object to operate on, MBZ for MAP_USERPTR, MBZ for UNMAP +*/ +__u32 obj; + +union { +/** +* @obj_offset: Offset into the object, MBZ for CLEAR_RANGE, +* ignored for unbind +*/ +__u64 obj_offset; +/** @userptr: user pointer to bind on */ +__u64 userptr; + }; + +/** +* @range: Number of bytes from the object to bind to addr, MBZ for UNMAP_ALL +*/ +__u64 range; + +/** @addr: Address to operate on, MBZ for UNMAP_ALL */ +__u64 addr; + +/** +* @gt_mask: Mask for which GTs to create binds for, 0 == All GTs, +* only applies to creating new VMAs +*/ +__u64 gt_mask; + +/** @op: Operation to perform (lower 16 bits) and flags (upper 16 bits) */ +__u32 op; + +/** @mem_region: Memory region to prefetch VMA to, instance not a mask */ +__u32 region; + +#define XE_VM_BIND_OP_MAP 0x0 +#define XE_VM_BIND_OP_UNMAP 0x1 +#define XE_VM_BIND_OP_MAP_USERPTR 0x2 +#define XE_VM_BIND_OP_RESTART 0x3 +#define XE_VM_BIND_OP_UNMAP_ALL 0x4 +#define XE_VM_BIND_OP_PREFETCH 0x5 + +#define XE_VM_BIND_FLAG_READONLY (0x1 << 16) +/* +* A bind ops completions are always async, hence the support for out +* sync. This flag indicates the allocation of the memory for new page +* tables and the job to program the pages tables is asynchronous +* relative to the IOCTL. That part of a bind operation can fail under +* memory pressure, the job in practice can't fail unless the system is +* totally shot. +* +* If this flag is clear and the IOCTL doesn't return an error, in +* practice the bind op is good and will complete. +* +* If this flag is set and doesn't return return an error, the bind op +* can still fail and recovery is needed. If configured, the bind op that +* caused the error will be captured in drm_xe_vm_bind_op_error_capture. +* Once the user sees the error (via a ufence + +* XE_VM_PROPERTY_BIND_OP_ERROR_CAPTURE_ADDRESS), it should free memory +* via non-async unbinds, and then restart all queue'd async binds op via +* XE_VM_BIND_OP_RESTART. Or alternatively the user should destroy the +* VM. +* +* This flag is only allowed when DRM_XE_VM_CREATE_ASYNC_BIND_OPS is +* configured in the VM and must be set if the VM is configured with +* DRM_XE_VM_CREATE_ASYNC_BIND_OPS and not in an error state. +*/ +#define XE_VM_BIND_FLAG_ASYNC (0x1 << 17) +/* +* Valid on a faulting VM only, do the MAP operation immediately rather +* than differing the MAP to the page fault handler. +*/ +#define XE_VM_BIND_FLAG_IMMEDIATE (0x1 << 18) + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_vm_bind { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @vm_id: The ID of the VM to bind to */ +__u32 vm_id; + +/** +* @engine_id: engine_id, must be of class DRM_XE_ENGINE_CLASS_VM_BIND +* and engine must have same vm_id. If zero, the default VM bind engine +* is used. +*/ +__u32 engine_id; + +/** @num_binds: number of binds in this IOCTL */ +__u32 num_binds; + +union { +/** @bind: used if num_binds == 1 */ +struct drm_xe_vm_bind_op bind; +/** +* @vector_of_binds: userptr to array of struct +* drm_xe_vm_bind_op if num_binds > 1 +*/ +__u64 vector_of_binds; + }; + +/** @num_syncs: amount of syncs to wait on */ +__u32 num_syncs; + +/** @syncs: pointer to struct drm_xe_sync array */ +__u64 syncs; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +/** struct drm_xe_ext_engine_set_property - engine set property extension */ +struct drm_xe_ext_engine_set_property { +/** @base: base user extension */ +struct xe_user_extension base; + +/** @property: property to set */ +__u32 property; + +/** @value: property value */ +__u64 value; +}; + +/** +* struct drm_xe_engine_set_property - engine set property +* +* Same namespace for extensions as drm_xe_engine_create +*/ +struct drm_xe_engine_set_property { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @engine_id: Engine ID */ +__u32 engine_id; + +/** @property: property to set */ +#define XE_ENGINE_SET_PROPERTY_PRIORITY 0 +#define XE_ENGINE_SET_PROPERTY_TIMESLICE 1 +#define XE_ENGINE_SET_PROPERTY_PREEMPTION_TIMEOUT 2 +/* +* Long running or ULLS engine mode. DMA fences not allowed in this +* mode. Must match the value of DRM_XE_VM_CREATE_COMPUTE_MODE, serves +* as a sanity check the UMD knows what it is doing. Can only be set at +* engine create time. +*/ +#define XE_ENGINE_SET_PROPERTY_COMPUTE_MODE 3 +#define XE_ENGINE_SET_PROPERTY_PERSISTENCE 4 +#define XE_ENGINE_SET_PROPERTY_JOB_TIMEOUT 5 +#define XE_ENGINE_SET_PROPERTY_ACC_TRIGGER 6 +#define XE_ENGINE_SET_PROPERTY_ACC_NOTIFY 7 +#define XE_ENGINE_SET_PROPERTY_ACC_GRANULARITY 8 +__u32 property; + +/** @value: property value */ +__u64 value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_engine_create { +/** @extensions: Pointer to the first extension struct, if any */ +#define XE_ENGINE_EXTENSION_SET_PROPERTY 0 +__u64 extensions; + +/** @width: submission width (number BB per exec) for this engine */ +__u16 width; + +/** @num_placements: number of valid placements for this engine */ +__u16 num_placements; + +/** @vm_id: VM to use for this engine */ +__u32 vm_id; + +/** @flags: MBZ */ +__u32 flags; + +/** @engine_id: Returned engine ID */ +__u32 engine_id; + +/** +* @instances: user pointer to a 2-d array of struct +* drm_xe_engine_class_instance +* +* length = width (i) * num_placements (j) +* index = j + i * width +*/ +__u64 instances; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_engine_get_property { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @engine_id: Engine ID */ +__u32 engine_id; + +/** @property: property to get */ +#define XE_ENGINE_GET_PROPERTY_BAN 0 +__u32 property; + +/** @value: property value */ +__u64 value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_engine_destroy { +/** @engine_id: Engine ID */ +__u32 engine_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_sync { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +__u32 flags; + +#define DRM_XE_SYNC_SYNCOBJ 0x0 +#define DRM_XE_SYNC_TIMELINE_SYNCOBJ 0x1 +#define DRM_XE_SYNC_DMA_BUF 0x2 +#define DRM_XE_SYNC_USER_FENCE 0x3 +#define DRM_XE_SYNC_SIGNAL 0x10 + +union { +__u32 handle; +/** +* @addr: Address of user fence. When sync passed in via exec +* IOCTL this a GPU address in the VM. When sync passed in via +* VM bind IOCTL this is a user pointer. In either case, it is +* the users responsibility that this address is present and +* mapped when the user fence is signalled. Must be qword +* aligned. +*/ +__u64 addr; + }; + +__u64 timeline_value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_exec { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @vm_id: VM ID to run batch buffer in */ +__u32 engine_id; + +/** @num_syncs: Amount of struct drm_xe_sync in array. */ +__u32 num_syncs; + +/** @syncs: Pointer to struct drm_xe_sync array. */ +__u64 syncs; + +/** +* @address: address of batch buffer if num_batch_buffer == 1 or an +* array of batch buffer addresses +*/ +__u64 address; + +/** +* @num_batch_buffer: number of batch buffer in this exec, must match +* the width of the engine +*/ +__u16 num_batch_buffer; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_mmio { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +__u32 addr; + +__u32 flags; + +#define DRM_XE_MMIO_8BIT 0x0 +#define DRM_XE_MMIO_16BIT 0x1 +#define DRM_XE_MMIO_32BIT 0x2 +#define DRM_XE_MMIO_64BIT 0x3 +#define DRM_XE_MMIO_BITS_MASK 0x3 +#define DRM_XE_MMIO_READ 0x4 +#define DRM_XE_MMIO_WRITE 0x8 + +__u64 value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +/** +* struct drm_xe_wait_user_fence - wait user fence +* +* Wait on user fence, XE will wakeup on every HW engine interrupt in the +* instances list and check if user fence is complete: +* (*addr & MASK) OP (VALUE & MASK) +* +* Returns to user on user fence completion or timeout. +*/ +struct drm_xe_wait_user_fence { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; +union { +/** +* @addr: user pointer address to wait on, must qword aligned +*/ +__u64 addr; +/** +* @vm_id: The ID of the VM which encounter an error used with +* DRM_XE_UFENCE_WAIT_VM_ERROR. Upper 32 bits must be clear. +*/ +__u64 vm_id; + }; +/** @op: wait operation (type of comparison) */ +#define DRM_XE_UFENCE_WAIT_EQ 0 +#define DRM_XE_UFENCE_WAIT_NEQ 1 +#define DRM_XE_UFENCE_WAIT_GT 2 +#define DRM_XE_UFENCE_WAIT_GTE 3 +#define DRM_XE_UFENCE_WAIT_LT 4 +#define DRM_XE_UFENCE_WAIT_LTE 5 +__u16 op; +/** @flags: wait flags */ +#define DRM_XE_UFENCE_WAIT_SOFT_OP (1 << 0)/* e.g. Wait on VM bind */ +#define DRM_XE_UFENCE_WAIT_ABSTIME (1 << 1) +#define DRM_XE_UFENCE_WAIT_VM_ERROR (1 << 2) +__u16 flags; +/** @value: compare value */ +__u64 value; +/** @mask: comparison mask */ +#define DRM_XE_UFENCE_WAIT_U8 0xffu +#define DRM_XE_UFENCE_WAIT_U16 0xffffu +#define DRM_XE_UFENCE_WAIT_U32 0xffffffffu +#define DRM_XE_UFENCE_WAIT_U64 0xffffffffffffffffu +__u64 mask; +/** @timeout: how long to wait before bailing, value in jiffies */ +__s64 timeout; +/** +* @num_engines: number of engine instances to wait on, must be zero +* when DRM_XE_UFENCE_WAIT_SOFT_OP set +*/ +__u64 num_engines; +/** +* @instances: user pointer to array of drm_xe_engine_class_instance to +* wait on, must be NULL when DRM_XE_UFENCE_WAIT_SOFT_OP set +*/ +__u64 instances; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +struct drm_xe_vm_madvise { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @vm_id: The ID VM in which the VMA exists */ +__u32 vm_id; + +/** @range: Number of bytes in the VMA */ +__u64 range; + +/** @addr: Address of the VMA to operation on */ +__u64 addr; + +/* +* Setting the preferred location will trigger a migrate of the VMA +* backing store to new location if the backing store is already +* allocated. +*/ +#define DRM_XE_VM_MADVISE_PREFERRED_MEM_CLASS 0 +#define DRM_XE_VM_MADVISE_PREFERRED_GT 1 +/* +* In this case lower 32 bits are mem class, upper 32 are GT. +* Combination provides a single IOCTL plus migrate VMA to preferred +* location. +*/ +#define DRM_XE_VM_MADVISE_PREFERRED_MEM_CLASS_GT 2 +/* +* The CPU will do atomic memory operations to this VMA. Must be set on +* some devices for atomics to behave correctly. +*/ +#define DRM_XE_VM_MADVISE_CPU_ATOMIC 3 +/* +* The device will do atomic memory operations to this VMA. Must be set +* on some devices for atomics to behave correctly. +*/ +#define DRM_XE_VM_MADVISE_DEVICE_ATOMIC 4 +/* +* Priority WRT to eviction (moving from preferred memory location due +* to memory pressure). The lower the priority, the more likely to be +* evicted. +*/ +#define DRM_XE_VM_MADVISE_PRIORITY 5 +#define DRM_XE_VMA_PRIORITY_LOW 0 +#define DRM_XE_VMA_PRIORITY_NORMAL 1/* Default */ +#define DRM_XE_VMA_PRIORITY_HIGH 2/* Must be elevated user */ +/* Pin the VMA in memory, must be elevated user */ +#define DRM_XE_VM_MADVISE_PIN 6 + +/** @property: property to set */ +__u32 property; + +/** @value: property value */ +__u64 value; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; + +#if defined(__cplusplus) +} +#endif + +#endif /* _UAPI_XE_DRM_H_ */
Signature · 1 line
2.34.1
PATCH v8 2/7 lib/xe: Introduce Xe library
In reply to Zbigniew KempczyńskiXe, is a new driver for Intel GPUs that supports both integrated and discrete platforms starting with Tiger Lake (first Intel Xe Architecture).
Series was split to allow easier review. Library, drm uapi, tests, tools and other were squashed according to code subject.
This patch introduces library used for Xe tests. As there's not too trivial to calculate credits for squashed subjects full series credits are:
--- lib/drmtest.c | 3 + lib/drmtest.h | 1 + lib/meson.build | 4 + lib/xe/xe_compute.c | 406 ++++++++++++++++++++++++++++++++++++++ lib/xe/xe_compute.h | 29 +++ lib/xe/xe_ioctl.c | 436 ++++++++++++++++++++++++++++++++++++++++ lib/xe/xe_ioctl.h | 87 ++++++++ lib/xe/xe_query.c | 471 ++++++++++++++++++++++++++++++++++++++++++++ lib/xe/xe_query.h | 94 +++++++++ lib/xe/xe_spin.c | 157 +++++++++++++++ lib/xe/xe_spin.h | 48 +++++ meson.build | 8 + 12 files changed, 1744 insertions(+) create mode 100644 lib/xe/xe_compute.c create mode 100644 lib/xe/xe_compute.h create mode 100644 lib/xe/xe_ioctl.c create mode 100644 lib/xe/xe_ioctl.h create mode 100644 lib/xe/xe_query.c create mode 100644 lib/xe/xe_query.h create mode 100644 lib/xe/xe_spin.c create mode 100644 lib/xe/xe_spin.h
lib/drmtest.c +3 -0
@@ -189,6 +189,7 @@ static const struct module { { DRIVER_V3D, "v3d" }, { DRIVER_VC4, "vc4" }, { DRIVER_VGEM, "vgem" }, + { DRIVER_XE, "xe" }, {} };
@@ -547,6 +548,8 @@ static const char *chipset_to_str(int chipset)return "panfrost" ;case DRIVER_MSM :return "msm" ; +case DRIVER_XE : +return "xe" ;case DRIVER_ANY :return "any" ;default :
lib/drmtest.h +1 -0
@@ -51,6 +51,7 @@#define DRIVER_V3D (1 << 4)#define DRIVER_PANFROST (1 << 5)#define DRIVER_MSM (1 << 6) +#define DRIVER_XE (1 << 7)/* * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
lib/meson.build +4 -0
@@ -98,6 +98,10 @@ lib_sources = [ 'veboxcopy_gen12.c', 'igt_msm.c', 'igt_dsc.c', + 'xe/xe_compute.c', + 'xe/xe_ioctl.c', + 'xe/xe_query.c', + 'xe/xe_spin.c' ] lib_deps = [
lib/xe/xe_compute.c new file +406 -0
406 lines not on this page · raw message
lib/xe/xe_compute.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +* +* Authors: +* Francois Dugast <[email protected]> +*/ + +#ifndef XE_COMPUTE_H +#define XE_COMPUTE_H + +#include <stdint.h> + +void tgllp_create_indirect_data (uint32_t *addr_bo_buffer_batch, +uint64_t addr_input,uint64_t addr_output); +void tgllp_create_surface_state (uint32_t *addr_bo_buffer_batch, +uint64_t addr_input,uint64_t addr_output); +void tgllp_create_dynamic_state (uint32_t *addr_bo_buffer_batch, +uint64_t offset_kernel); +void tgllp_create_batch_compute (uint32_t *addr_bo_buffer_batch, +uint64_t addr_surface_state_base, +uint64_t addr_dynamic_state_base, +uint64_t addr_indirect_object_base, +uint64_t offset_indirect_data_start); + +extern unsigned char tgllp_kernel_square_bin[]; +extern unsigned int tgllp_kernel_square_length; + +#endif /* XE_COMPUTE_H */
lib/xe/xe_ioctl.c new file +436 -0
436 lines not on this page · raw message
lib/xe/xe_ioctl.h new file +87 -0
87 lines not on this page · raw message
lib/xe/xe_query.c new file +471 -0
471 lines not on this page · raw message
lib/xe/xe_query.h new file +94 -0
94 lines not on this page · raw message
lib/xe/xe_spin.c new file +157 -0
157 lines not on this page · raw message
lib/xe/xe_spin.h new file +48 -0
48 lines not on this page · raw message
meson.build +8 -0
@@ -261,6 +261,7 @@ libexecdir = join_paths(get_option('libexecdir'), 'igt-gpu-tools') amdgpudir = join_paths(libexecdir, 'amdgpu') v3ddir = join_paths(libexecdir, 'v3d') vc4dir = join_paths(libexecdir, 'vc4') +xedir = join_paths(libexecdir, 'xe') mandir = get_option('mandir') pkgconfigdir = join_paths(libdir, 'pkgconfig') python3 = find_program('python3', required : true)
@@ -308,12 +309,19 @@ if get_option('use_rpath') vc4_rpathdir = join_paths(vc4_rpathdir, '..') endforeach vc4_rpathdir = join_paths(vc4_rpathdir, libdir) + + xedir_rpathdir = '$ORIGIN' + foreach p : xedir.split('/') + xedir_rpathdir = join_paths(xedir_rpathdir, '..') + endforeach + xedir_rpathdir = join_paths(xedir_rpathdir, libdir) else bindir_rpathdir = '' libexecdir_rpathdir = '' amdgpudir_rpathdir = '' v3d_rpathdir = '' vc4_rpathdir = '' + xedir_rpathdir = '' endif subdir('lib')
Signature · 1 line
2.34.1
PATCH v8 3/7 lib/igt_pm: Add a helper to query the runtime_usage.
In reply to Zbigniew KempczyńskiFrom: Rodrigo Vivi <[email protected]>
It will be useful so the tests can assert the expected usage counter movement depending on the operation.
--- lib/igt_pm.c | 18 ++++++++++++++++++ lib/igt_pm.h | 1 + 2 files changed, 19 insertions(+)
lib/igt_pm.c +18 -0
@@ -1363,3 +1363,21 @@ int igt_pm_get_runtime_suspended_time(struct pci_device *pci_dev)return -1 ; } + +/** +* igt_pm_get_runtime_usage: +* @pci_dev: pci device +* +* Reports the runtime PM usage count of a device. +*/ +int igt_pm_get_runtime_usage (struct pci_device *pci_dev) +{ +char usage_str[64 ]; +int usage, fd; + + fd =igt_pm_get_power_attr_fd_rdonly (pci_dev,"runtime_usage" ); +if (igt_pm_read_power_attr (fd, usage_str,64 , true)) +igt_assert (sscanf (usage_str,"%d" , &usage) >0 ); + +return usage; +}
lib/igt_pm.h +1 -0
@@ -86,5 +86,6 @@ void igt_pm_restore_pci_card_runtime_pm(void);void igt_pm_print_pci_card_runtime_status (void );bool i915_is_slpc_enabled (int fd);int igt_pm_get_runtime_suspended_time (struct pci_device *pci_dev); +int igt_pm_get_runtime_usage (struct pci_device *pci_dev);#endif /* IGT_PM_H */
Signature · 1 line
2.34.1
PATCH v8 4/7 tests/xe: Add Xe IGT tests
In reply to Zbigniew KempczyńskiCollaborative change of IGT Xe tests.
--- tests/meson.build | 1 + tests/xe/meson.build | 33 + tests/xe/xe_compute.c | 148 +++ tests/xe/xe_debugfs.c | 257 +++++ tests/xe/xe_dma_buf_sync.c | 262 +++++ tests/xe/xe_evict.c | 623 ++++++++++++ tests/xe/xe_exec_balancer.c | 714 ++++++++++++++ tests/xe/xe_exec_basic.c | 350 +++++++ tests/xe/xe_exec_compute_mode.c | 364 +++++++ tests/xe/xe_exec_fault_mode.c | 575 +++++++++++ tests/xe/xe_exec_reset.c | 817 ++++++++++++++++ tests/xe/xe_exec_threads.c | 1166 ++++++++++++++++++++++ tests/xe/xe_guc_pc.c | 425 ++++++++ tests/xe/xe_huc_copy.c | 205 ++++ tests/xe/xe_mmap.c | 79 ++ tests/xe/xe_mmio.c | 94 ++ tests/xe/xe_pm.c | 385 ++++++++ tests/xe/xe_prime_self_import.c | 489 ++++++++++ tests/xe/xe_query.c | 475 +++++++++ tests/xe/xe_test_config.json | 133 +++ tests/xe/xe_vm.c | 1612 +++++++++++++++++++++++++++++++ tests/xe/xe_waitfence.c | 103 ++ 22 files changed, 9310 insertions(+) create mode 100644 tests/xe/meson.build create mode 100644 tests/xe/xe_compute.c create mode 100644 tests/xe/xe_debugfs.c create mode 100644 tests/xe/xe_dma_buf_sync.c create mode 100644 tests/xe/xe_evict.c create mode 100644 tests/xe/xe_exec_balancer.c create mode 100644 tests/xe/xe_exec_basic.c create mode 100644 tests/xe/xe_exec_compute_mode.c create mode 100644 tests/xe/xe_exec_fault_mode.c create mode 100644 tests/xe/xe_exec_reset.c create mode 100644 tests/xe/xe_exec_threads.c create mode 100644 tests/xe/xe_guc_pc.c create mode 100644 tests/xe/xe_huc_copy.c create mode 100644 tests/xe/xe_mmap.c create mode 100644 tests/xe/xe_mmio.c create mode 100644 tests/xe/xe_pm.c create mode 100644 tests/xe/xe_prime_self_import.c create mode 100644 tests/xe/xe_query.c create mode 100644 tests/xe/xe_test_config.json create mode 100644 tests/xe/xe_vm.c create mode 100644 tests/xe/xe_waitfence.c
tests/meson.build +1 -0
@@ -470,6 +470,7 @@ test_executables += executable('sw_sync', 'sw_sync.c', test_list += 'sw_sync' subdir('amdgpu') +subdir('xe') subdir('v3d')
tests/xe/meson.build new file +33 -0
@@ -0,0 +1,33 @@ +xe_progs = [ + 'xe_compute', + 'xe_dma_buf_sync', + 'xe_debugfs', + 'xe_evict', + 'xe_exec_balancer', + 'xe_exec_basic', + 'xe_exec_compute_mode', + 'xe_exec_fault_mode', + 'xe_exec_reset', + 'xe_exec_threads', + 'xe_guc_pc', + 'xe_huc_copy', + 'xe_mmap', + 'xe_mmio', + 'xe_pm', + 'xe_prime_self_import', + 'xe_query', + 'xe_vm', + 'xe_waitfence', +] +xe_deps = test_deps + +xe_test_config = meson.current_source_dir() + '/xe_test_config.json' + +foreach prog : xe_progs + test_executables += executable(prog, prog + '.c', + dependencies : xe_deps, + install_dir : xedir, + install_rpath : xedir_rpathdir, + install : true) + test_list += join_paths('xe', prog) +endforeach
tests/xe/xe_compute.c new file +148 -0
148 lines not on this page · raw message
tests/xe/xe_debugfs.c new file +257 -0
257 lines not on this page · raw message
tests/xe/xe_dma_buf_sync.c new file +262 -0
262 lines not on this page · raw message
tests/xe/xe_evict.c new file +623 -0
623 lines not on this page · raw message
tests/xe/xe_exec_balancer.c new file +714 -0
714 lines not on this page · raw message
tests/xe/xe_exec_basic.c new file +350 -0
350 lines not on this page · raw message
tests/xe/xe_exec_compute_mode.c new file +364 -0
364 lines not on this page · raw message
tests/xe/xe_exec_fault_mode.c new file +575 -0
242 lines not on this page · raw message
tests/xe/xe_exec_reset.c new file +817 -0
817 lines not on this page · raw message
tests/xe/xe_exec_threads.c new file +1166 -0
1,166 lines not on this page · raw message
tests/xe/xe_guc_pc.c new file +425 -0
425 lines not on this page · raw message
tests/xe/xe_huc_copy.c new file +205 -0
205 lines not on this page · raw message
tests/xe/xe_mmap.c new file +79 -0
79 lines not on this page · raw message
tests/xe/xe_mmio.c new file +94 -0
94 lines not on this page · raw message
tests/xe/xe_pm.c new file +385 -0
385 lines not on this page · raw message
tests/xe/xe_prime_self_import.c new file +489 -0
489 lines not on this page · raw message
tests/xe/xe_query.c new file +475 -0
475 lines not on this page · raw message
tests/xe/xe_test_config.json new file +133 -0
133 lines not on this page · raw message
tests/xe/xe_vm.c new file +1612 -0
1,612 lines not on this page · raw message
tests/xe/xe_waitfence.c new file +103 -0
103 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Re: [igt-dev] [PATCH i-g-t v8 4/7] tests/xe: Add Xe IGT tests
On Wed, Mar 08, 2023 at 08:53:31AM +0100, Zbigniew Kempczyński wrote:
I should be the author of this patch I'm thinking as I wrote almost of these tests.
Matt
Quoted 9,508 lines
Collaborative change of IGT Xe tests.
Signed-off-by Matthew Brost <[email protected]>Signed-off-by Jason Ekstrand <[email protected]>Signed-off-by Maarten Lankhorst <[email protected]>Signed-off-by Philippe Lecluse <[email protected]>Signed-off-by Francois Dugast <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>Signed-off-by Matthew Auld <[email protected]>Signed-off-by Zbigniew Kempczyński <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>--- tests/meson.build | 1 + tests/xe/meson.build | 33 + tests/xe/xe_compute.c | 148 +++ tests/xe/xe_debugfs.c | 257 +++++ tests/xe/xe_dma_buf_sync.c | 262 +++++ tests/xe/xe_evict.c | 623 ++++++++++++ tests/xe/xe_exec_balancer.c | 714 ++++++++++++++ tests/xe/xe_exec_basic.c | 350 +++++++ tests/xe/xe_exec_compute_mode.c | 364 +++++++ tests/xe/xe_exec_fault_mode.c | 575 +++++++++++ tests/xe/xe_exec_reset.c | 817 ++++++++++++++++ tests/xe/xe_exec_threads.c | 1166 ++++++++++++++++++++++ tests/xe/xe_guc_pc.c | 425 ++++++++ tests/xe/xe_huc_copy.c | 205 ++++ tests/xe/xe_mmap.c | 79 ++ tests/xe/xe_mmio.c | 94 ++ tests/xe/xe_pm.c | 385 ++++++++ tests/xe/xe_prime_self_import.c | 489 ++++++++++ tests/xe/xe_query.c | 475 +++++++++ tests/xe/xe_test_config.json | 133 +++ tests/xe/xe_vm.c | 1612 +++++++++++++++++++++++++++++++ tests/xe/xe_waitfence.c | 103 ++ 22 files changed, 9310 insertions(+) create mode 100644 tests/xe/meson.build create mode 100644 tests/xe/xe_compute.c create mode 100644 tests/xe/xe_debugfs.c create mode 100644 tests/xe/xe_dma_buf_sync.c create mode 100644 tests/xe/xe_evict.c create mode 100644 tests/xe/xe_exec_balancer.c create mode 100644 tests/xe/xe_exec_basic.c create mode 100644 tests/xe/xe_exec_compute_mode.c create mode 100644 tests/xe/xe_exec_fault_mode.c create mode 100644 tests/xe/xe_exec_reset.c create mode 100644 tests/xe/xe_exec_threads.c create mode 100644 tests/xe/xe_guc_pc.c create mode 100644 tests/xe/xe_huc_copy.c create mode 100644 tests/xe/xe_mmap.c create mode 100644 tests/xe/xe_mmio.c create mode 100644 tests/xe/xe_pm.c create mode 100644 tests/xe/xe_prime_self_import.c create mode 100644 tests/xe/xe_query.c create mode 100644 tests/xe/xe_test_config.json create mode 100644 tests/xe/xe_vm.c create mode 100644 tests/xe/xe_waitfence.ctests/meson.build +1
-0@@ -470,6 +470,7 @@ test_executables += executable('sw_sync', 'sw_sync.c', test_list += 'sw_sync' subdir('amdgpu') +subdir('xe') subdir('v3d')tests/xe/meson.build new file +33
-0@@ -0,0 +1,33 @@ +xe_progs = [ + 'xe_compute', + 'xe_dma_buf_sync', + 'xe_debugfs', + 'xe_evict', + 'xe_exec_balancer', + 'xe_exec_basic', + 'xe_exec_compute_mode', + 'xe_exec_fault_mode', + 'xe_exec_reset', + 'xe_exec_threads', + 'xe_guc_pc', + 'xe_huc_copy', + 'xe_mmap', + 'xe_mmio', + 'xe_pm', + 'xe_prime_self_import', + 'xe_query', + 'xe_vm', + 'xe_waitfence', +] +xe_deps = test_deps + +xe_test_config = meson.current_source_dir() + '/xe_test_config.json' + +foreach prog : xe_progs + test_executables += executable(prog, prog + '.c', + dependencies : xe_deps, + install_dir : xedir, + install_rpath : xedir_rpathdir, + install : true) + test_list += join_paths('xe', prog) +endforeachtests/xe/xe_compute.c new file +148
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2022 Intel Corporation +*/ + +/** +* TEST: Check compute-related functionality +* Category: Hardware building block +* Sub-category: compute +* Test category: functionality test +* Run type: BAT +*/ + +#include <string.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "xe_drm.h" +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_compute.h" + +#define MAX (X ,Y ) (((X) > (Y)) ? (X) : (Y)) +#define SIZE_DATA 64 +#define SIZE_BATCH 0x1000 +#define SIZE_KERNEL 0x1000 +#define SIZE_BUFFER_INPUT MAX(sizeof(float)*SIZE_DATA, 0x1000) +#define SIZE_BUFFER_OUTPUT MAX(sizeof(float)*SIZE_DATA, 0x1000) +#define ADDR_BATCH 0x100000 +#define ADDR_INPUT (unsigned long)0x200000 +#define ADDR_OUTPUT (unsigned long)0x300000 +#define ADDR_SURFACE_STATE_BASE (unsigned long)0x400000 +#define ADDR_DYNAMIC_STATE_BASE (unsigned long)0x500000 +#define ADDR_INDIRECT_OBJECT_BASE 0x800100000000 +#define OFFSET_INDIRECT_DATA_START 0xFFFDF000 +#define OFFSET_KERNEL 0xFFFEF000 + +struct bo_dict_entry { +uint64_t addr; +uint32_t size; +void *data; +}; + +/** +* SUBTEST: compute-square +* GPU requirement: only works on TGL_GT2 with device ID: 0x9a49 +* Description: +* This test shows how to create a batch to execute a +* compute kernel. For now it supports tgllp only. +* TODO: extend test to cover other platforms +*/ +static void +test_compute_square (int fd) +{ +uint32_t vm, engine; +float *dinput; +struct drm_xe_sync sync = {0 }; + +#define BO_DICT_ENTRIES 7 +struct bo_dict_entry bo_dict[BO_DICT_ENTRIES ] = { + { .addr =ADDR_INDIRECT_OBJECT_BASE +OFFSET_KERNEL , .size =SIZE_KERNEL },// kernel + { .addr =ADDR_DYNAMIC_STATE_BASE , .size =0x1000 },// dynamic state + { .addr =ADDR_SURFACE_STATE_BASE , .size =0x1000 },// surface state + { .addr =ADDR_INDIRECT_OBJECT_BASE +OFFSET_INDIRECT_DATA_START , .size =0x10000 },// indirect data + { .addr =ADDR_INPUT , .size =SIZE_BUFFER_INPUT },// input + { .addr =ADDR_OUTPUT , .size =SIZE_BUFFER_OUTPUT },// output + { .addr =ADDR_BATCH , .size =SIZE_BATCH },// batch + }; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + engine =xe_engine_create_class (fd, vm,DRM_XE_ENGINE_CLASS_RENDER ); + sync.flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL ; + sync.handle =syncobj_create (fd,0 ); + +for (int i =0 ; i <BO_DICT_ENTRIES ; i++) { + bo_dict[i].data =aligned_alloc (xe_get_default_alignment (fd), bo_dict[i].size); +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (bo_dict[i].data), bo_dict[i].addr, bo_dict[i].size, &sync,1 ); +syncobj_wait (fd, &sync.handle,1 ,INT64_MAX ,0 ,NULL ); +memset (bo_dict[i].data,0 , bo_dict[i].size); + } +memcpy (bo_dict[0 ].data, tgllp_kernel_square_bin, tgllp_kernel_square_length); +tgllp_create_dynamic_state (bo_dict[1 ].data,OFFSET_KERNEL ); +tgllp_create_surface_state (bo_dict[2 ].data,ADDR_INPUT ,ADDR_OUTPUT ); +tgllp_create_indirect_data (bo_dict[3 ].data,ADDR_INPUT ,ADDR_OUTPUT ); + dinput = (float *)bo_dict[4 ].data; +srand (time (NULL )); +for (int i=0 ; i <SIZE_DATA ; i++) { + ((float *) dinput)[i] =rand ()/(float )RAND_MAX ; + } +tgllp_create_batch_compute (bo_dict[6 ].data,ADDR_SURFACE_STATE_BASE ,ADDR_DYNAMIC_STATE_BASE ,ADDR_INDIRECT_OBJECT_BASE ,OFFSET_INDIRECT_DATA_START ); + +xe_exec_wait (fd, engine,ADDR_BATCH ); +for (int i =0 ; i <SIZE_DATA ; i++) { +igt_assert (((float *) bo_dict[5 ].data)[i] == ((float *) bo_dict[4 ].data)[i] * ((float *) bo_dict[4 ].data)[i]); + } + +for (int i =0 ; i <BO_DICT_ENTRIES ; i++) { +xe_vm_unbind_async (fd, vm,0 ,0 , bo_dict[i].addr, bo_dict[i].size, &sync,1 ); +syncobj_wait (fd, &sync.handle,1 ,INT64_MAX ,0 ,NULL ); +free (bo_dict[i].data); + } + +syncobj_destroy (fd, sync.handle); +xe_engine_destroy (fd, engine); +xe_vm_destroy (fd, vm); +} + +static bool +is_device_supported (int fd) +{ +struct drm_xe_query_config *config; +struct drm_xe_device_query query = { + .extensions =0 , + .query =DRM_XE_DEVICE_QUERY_CONFIG , + .size =0 , + .data =0 , + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_DEVICE_QUERY , &query),0 ); + + config =malloc (query.size); +igt_assert (config); + + query.data =to_user_pointer (config); +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_DEVICE_QUERY , &query),0 ); + +return (config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] &0xffff ) ==0x9a49 ; +} + +igt_main +{ +int xe; + + igt_fixture { + xe =drm_open_driver (DRIVER_XE ); +xe_device_get (xe); + } + + igt_subtest("compute-square") { +igt_skip_on (!is_device_supported (xe)); +test_compute_square (xe); + } + + igt_fixture { +xe_device_put (xe); +close (xe); + } +}tests/xe/xe_debugfs.c new file +257
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +/** +* TEST: Check debugfs userspace API +* Category: Software building block +* Sub-category: debugfs +* Test category: functionality test +* Run type: BAT +* Description: Validate debugfs entries +*/ + +#include "igt.h" + +#include "xe_drm.h" +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" + +#include <fcntl.h> +#include <string.h> +#include <sys/types.h> +#include <dirent.h> + +static int validate_entries (int fd,const char *add_path,const char *const str_val[],int str_cnt) +{ +int i; +int hit; +int found =0 ; +int not_found =0 ; +DIR *dir; +struct dirent *de; +char path[PATH_MAX ]; + +if (!igt_debugfs_path (fd, path,sizeof (path))) +return -1 ; + +strcat (path, add_path); + dir =opendir (path); +if (!dir) +return -1 ; + +while ((de =readdir (dir))) { +if (de->d_name[0 ] =='.' ) +continue ; + hit =0 ; +for (i =0 ; i < str_cnt; i++) { +if (!strcmp (str_val[i], de->d_name)) { + hit =1 ; +break ; + } + } +if (hit) { + found++; + }else { + not_found++; +igt_warn ("no test for: %s/%s\n" , path, de->d_name); + } + } +closedir (dir); +return 0 ; +} + +/** +* SUBTEST: base +* Description: Check if various debugfs devnodes exist and test reading them. +*/ +static void +test_base (int fd) +{ +static const char *const expected_files[] = { +"gt0" , +"gt1" , +"stolen_mm" , +"gtt_mm" , +"vram0_mm" , +"forcewake_all" , +"info" , +"gem_names" , +"clients" , +"name" + }; + +char reference[4096 ]; +int val =0 ; +struct xe_device *xe_dev =xe_device_get (fd); +struct drm_xe_query_config *config = xe_dev->config; + +igt_assert (config); +sprintf (reference,"devid 0x%llx" , + config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] &0xffff ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"revid %lld" , + config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] >>16 ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"is_dgfx %s" , config->info[XE_QUERY_CONFIG_FLAGS ] & +XE_QUERY_CONFIG_FLAGS_HAS_VRAM ?"yes" :"no" ); + +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"enable_guc %s" , config->info[XE_QUERY_CONFIG_FLAGS ] & +XE_QUERY_CONFIG_FLAGS_USE_GUC ?"yes" :"no" ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"tile_count %lld" , config->info[XE_QUERY_CONFIG_GT_COUNT ]); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +switch (config->info[XE_QUERY_CONFIG_VA_BITS ]) { +case 48 : + val =3 ; +break ; +case 57 : + val =4 ; +break ; + } +sprintf (reference,"vm_max_level %d" , val); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +igt_assert (igt_debugfs_exists (fd,"gt0" ,O_RDONLY )); +if (config->info[XE_QUERY_CONFIG_GT_COUNT ] >1 ) +igt_assert (igt_debugfs_exists (fd,"gt1" ,O_RDONLY )); + +igt_assert (igt_debugfs_exists (fd,"gtt_mm" ,O_RDONLY )); +igt_debugfs_dump (fd,"gtt_mm" ); + +if (config->info[XE_QUERY_CONFIG_FLAGS ] &XE_QUERY_CONFIG_FLAGS_HAS_VRAM ) { +igt_assert (igt_debugfs_exists (fd,"vram0_mm" ,O_RDONLY )); +igt_debugfs_dump (fd,"vram0_mm" ); + } + +if (igt_debugfs_exists (fd,"stolen_mm" ,O_RDONLY )) +igt_debugfs_dump (fd,"stolen_mm" ); + +igt_assert (igt_debugfs_exists (fd,"clients" ,O_RDONLY )); +igt_debugfs_dump (fd,"clients" ); + +igt_assert (igt_debugfs_exists (fd,"gem_names" ,O_RDONLY )); +igt_debugfs_dump (fd,"gem_names" ); + +validate_entries (fd,"" , expected_files,ARRAY_SIZE (expected_files)); + +free (config); +} + +/** +* SUBTEST: %s +* Description: Check %arg[1] debugfs devnodes +* TODO: add support for ``force_reset`` entries +* +* arg[1]: +* +* @gt0: gt0 +* @gt1: gt1 +*/ +static void +test_gt (int fd,int gt_id) +{ +char name[256 ]; +static const char *const expected_files[] = { +"uc" , +"steering" , +"topology" , +"sa_info" , +"hw_engines" , +// "force_reset" + }; +static const char *const expected_files_uc[] = { +"huc_info" , +"guc_log" , +"guc_info" , +// "guc_ct_selftest" + }; + +sprintf (name,"gt%d/hw_engines" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/sa_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/steering" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/topology" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/guc_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/huc_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/guc_log" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"/gt%d" , gt_id); +validate_entries (fd, name, expected_files,ARRAY_SIZE (expected_files)); + +sprintf (name,"/gt%d/uc" , gt_id); +validate_entries (fd, name, expected_files_uc,ARRAY_SIZE (expected_files_uc)); +} + +/** +* SUBTEST: forcewake +* Description: check forcewake debugfs devnode +*/ +static void +test_forcewake (int fd) +{ +int handle =igt_debugfs_open (fd,"forcewake_all" ,O_WRONLY ); + +igt_assert (handle !=-1 ); +close (handle); +} + +igt_main +{ +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); +__igt_debugfs_dump (fd,"info" ,IGT_LOG_INFO ); + } + + igt_subtest("base") { +test_base (fd); + } + + igt_subtest("gt0") { +igt_require (igt_debugfs_exists (fd,"gt0" ,O_RDONLY )); +test_gt (fd,0 ); + } + + igt_subtest("gt1") { +igt_require (igt_debugfs_exists (fd,"gt1" ,O_RDONLY )); +test_gt (fd,1 ); + } + + igt_subtest("forcewake") { +test_forcewake (fd); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_dma_buf_sync.c new file +262
-0@@ -0,0 +1,262 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Check dmabuf functionality +* Category: Software building block +* Sub-category: dmabuf +* Test category: functionality test +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_spin.h" +#include <string.h> +#include <linux/dma-buf.h> +#include <sys/poll.h> + +#define MAX_N_BO 16 +#define N_FD 2 + +#define READ_SYNC (0x1 << 0) + +struct igt_dma_buf_sync_file { +__u32 flags; +__s32 fd; +}; + +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE \ + _IOWR(DMA_BUF_BASE, 2, struct igt_dma_buf_sync_file) + +static int dmabuf_export_sync_file (int dmabuf,uint32_t flags) +{ +struct igt_dma_buf_sync_file arg; + + arg.flags = flags; + arg.fd =-1 ; +do_ioctl (dmabuf,IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE , &arg); + +return arg.fd; +} + +static bool dmabuf_busy (int dmabuf,uint32_t flags) +{ +struct pollfd pfd = { .fd = dmabuf }; + +/* If DMA_BUF_SYNC_WRITE is set, we don't want to set POLLIN or +* else poll() may return a non-zero value if there are only read +* fences because POLLIN is ready even if POLLOUT isn't. +*/ +if (flags &DMA_BUF_SYNC_WRITE ) + pfd.events |=POLLOUT ; +else if (flags &DMA_BUF_SYNC_READ ) + pfd.events |=POLLIN ; + +return poll (&pfd,1 ,0 ) ==0 ; +} + +static bool sync_file_busy (int sync_file) +{ +struct pollfd pfd = { .fd = sync_file, .events =POLLIN }; +return poll (&pfd,1 ,0 ) ==0 ; +} + +/** +* SUBTEST: export-dma-buf-once +* Description: Test exporting a sync file from a dma-buf +* Run type: BAT +* +* SUBTEST: export-dma-buf-once-read-sync +* Description: Test export prime BO as sync file and verify business +* Run type: BAT +* +* SUBTEST: export-dma-buf-many +* Description: Test exporting many sync files from a dma-buf +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: export-dma-buf-many-read-sync +* Description: Test export many prime BO as sync file and verify business +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +*/ + +static void +test_export_dma_buf (struct drm_xe_engine_class_instance *hwe0, +struct drm_xe_engine_class_instance *hwe1, +int n_bo,int flags) +{ +uint64_t addr =0x1a0000 , base_addr =0x1a0000 ; +int fd[N_FD ]; +uint32_t bo[MAX_N_BO ]; +int dma_buf_fd[MAX_N_BO ]; +uint32_t import_bo[MAX_N_BO ]; +uint32_t vm[N_FD ]; +uint32_t engine[N_FD ]; +size_t bo_size; +struct { +struct xe_spin spin; +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data [MAX_N_BO ]; +int i; + +igt_assert (n_bo <=MAX_N_BO ); + +for (i =0 ; i <N_FD ; ++i) { + fd[i] =drm_open_driver (DRIVER_XE ); +xe_device_get (fd[0 ]); + vm[i] =xe_vm_create (fd[i],0 ,0 ); + engine[i] =xe_engine_create (fd[i], vm[i], !i ? hwe0 : hwe1,0 ); + } + + bo_size =sizeof (*data[0 ]) *N_FD ; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd[0 ]), +xe_get_default_alignment (fd[0 ])); +for (i =0 ; i < n_bo; ++i) { + bo[i] =xe_bo_create (fd[0 ], hwe0->gt_id,0 , bo_size); + dma_buf_fd[i] =prime_handle_to_fd (fd[0 ], bo[i]); + import_bo[i] =prime_fd_to_handle (fd[1 ], dma_buf_fd[i]); + +if (i &1 ) + data[i] =xe_bo_map (fd[1 ], import_bo[i], bo_size); +else + data[i] =xe_bo_map (fd[0 ], bo[i], bo_size); +memset (data[i],0 , bo_size); + +xe_vm_bind_sync (fd[0 ], vm[0 ], bo[i],0 , addr, bo_size); +xe_vm_bind_sync (fd[1 ], vm[1 ], import_bo[i],0 , addr, bo_size); + addr += bo_size; + } + addr = base_addr; + +for (i =0 ; i < n_bo; ++i) { +uint64_t batch_offset = (char *)&data[i]->batch - + (char *)data[i]; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i]->data - (char *)data[i]; +uint64_t sdi_addr = addr + sdi_offset; +uint64_t spin_offset = (char *)&data[i]->spin - (char *)data[i]; +uint64_t spin_addr = addr + spin_offset; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t syncobj; +int b =0 ; +int sync_fd; + +/* Write spinner on FD[0] */ +xe_spin_init (&data[i]->spin, spin_addr, true); + exec.engine_id = engine[0 ]; + exec.address = spin_addr; +xe_exec (fd[0 ], &exec); + +/* Export prime BO as sync file and veify business */ +if (flags &READ_SYNC ) + sync_fd =dmabuf_export_sync_file (dma_buf_fd[i], +DMA_BUF_SYNC_READ ); +else + sync_fd =dmabuf_export_sync_file (dma_buf_fd[i], +DMA_BUF_SYNC_WRITE ); +xe_spin_wait_started (&data[i]->spin); +igt_assert (sync_file_busy (sync_fd)); +igt_assert (dmabuf_busy (dma_buf_fd[i],DMA_BUF_SYNC_READ )); + +/* Convert sync file to syncobj */ + syncobj =syncobj_create (fd[1 ],0 ); +syncobj_import_sync_file (fd[1 ], syncobj, sync_fd); + +/* Do an exec with syncobj as in fence on FD[1] */ + data[i]->batch[b++] =MI_STORE_DWORD_IMM ; + data[i]->batch[b++] = sdi_addr; + data[i]->batch[b++] = sdi_addr >>32 ; + data[i]->batch[b++] =0xc0ffee ; + data[i]->batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i]->batch)); + sync[0 ].handle = syncobj; + sync[1 ].handle =syncobj_create (fd[1 ],0 ); + exec.engine_id = engine[1 ]; + exec.address = batch_addr; + exec.num_syncs =2 ; +xe_exec (fd[1 ], &exec); + +/* Verify exec blocked on spinner / prime BO */ +usleep (5000 ); +igt_assert (!syncobj_wait (fd[1 ], &sync[1 ].handle,1 ,1 ,0 , +NULL )); +igt_assert_eq (data[i]->data,0x0 ); + +/* End spinner and verify exec complete */ +xe_spin_end (&data[i]->spin); +igt_assert (syncobj_wait (fd[1 ], &sync[1 ].handle,1 ,INT64_MAX , +0 ,NULL )); +igt_assert_eq (data[i]->data,0xc0ffee ); + +/* Clean up */ +syncobj_destroy (fd[1 ], sync[0 ].handle); +syncobj_destroy (fd[1 ], sync[1 ].handle); +close (sync_fd); + addr += bo_size; + } + +for (i =0 ; i < n_bo; ++i) { +munmap (data[i], bo_size); +gem_close (fd[0 ], bo[i]); +close (dma_buf_fd[i]); + } + +for (i =0 ; i <N_FD ; ++i) { +xe_device_put (fd[i]); +close (fd[i]); + } + +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe, *hwe0 =NULL , *hwe1; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + +for_each_hw_engine (fd, hwe) +if (hwe0 ==NULL ) { + hwe0 = hwe; + }else { + hwe1 = hwe; +break ; + } + } + + igt_subtest("export-dma-buf-once") +test_export_dma_buf (hwe0, hwe1,1 ,0 ); + + igt_subtest("export-dma-buf-many") +test_export_dma_buf (hwe0, hwe1,16 ,0 ); + + igt_subtest("export-dma-buf-once-read-sync") +test_export_dma_buf (hwe0, hwe1,1 ,READ_SYNC ); + + igt_subtest("export-dma-buf-many-read-sync") +test_export_dma_buf (hwe0, hwe1,16 ,READ_SYNC ); + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_evict.c new file +623
-0@@ -0,0 +1,623 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define MULTI_VM (0x1 << 0) +#define THREADED (0x1 << 1) +#define MIXED_THREADS (0x1 << 2) +#define LEGACY_THREAD (0x1 << 3) +#define COMPUTE_THREAD (0x1 << 4) +#define EXTERNAL_OBJ (0x1 << 5) +#define BIND_ENGINE (0x1 << 6) + +static void +test_evict (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,size_t bo_size, +unsigned long flags,pthread_barrier_t *barrier) +{ +uint32_t vm, vm2, vm3; +uint32_t bind_engines[3 ] = {0 ,0 ,0 }; +uint64_t addr =0x100000000 , base_addr =0x100000000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +uint32_t *bo; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + bo =calloc (n_execs /2 ,sizeof (*bo)); +igt_assert (bo); + + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[0 ] =xe_bind_engine_create (fd, vm,0 ); +if (flags &MULTI_VM ) { + vm2 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + vm3 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); +if (flags &BIND_ENGINE ) { + bind_engines[1 ] =xe_bind_engine_create (fd, vm2,0 ); + bind_engines[2 ] =xe_bind_engine_create (fd, vm3,0 ); + } + } + +for (i =0 ; i < n_engines; i++) { +if (flags &MULTI_VM ) + engines[i] =xe_engine_create (fd, i &1 ? vm2 : vm , + eci,0 ); +else + engines[i] =xe_engine_create (fd, vm, eci,0 ); + syncobjs[i] =syncobj_create (fd,0 ); + }; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint32_t __bo; +int e = i % n_engines; + +if (i < n_execs /2 ) { +uint32_t _vm = (flags &EXTERNAL_OBJ ) && + i < n_execs /8 ?0 : vm; + +if (flags &MULTI_VM ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id,0 , + bo_size); + }else if (flags &THREADED ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, vm, + bo_size); + }else { + __bo = bo[i] =xe_bo_create_flags (fd, _vm, + bo_size, +vram_memory (fd, eci->gt_id) | +system_memory (fd)); + } + }else { + __bo = bo[i % (n_execs /2 )]; + } +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); + +if (i < n_execs /2 ) { + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[0 ].handle =syncobj_create (fd,0 ); +if (flags &MULTI_VM ) { +xe_vm_bind_async (fd, vm3, bind_engines[2 ], __bo, +0 , addr, + bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 , +INT64_MAX ,0 ,NULL )); +xe_vm_bind_async (fd, i &1 ? vm2 : vm, + i &1 ? bind_engines[1 ] : + bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + }else { +xe_vm_bind_async (fd, vm, bind_engines[0 ], + __bo,0 , addr, bo_size, + sync,1 ); + } + } + addr += bo_size; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +if (i >= n_engines) +syncobj_reset (fd, &syncobjs[e],1 ); + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_EXEC , &exec),0 ); + +if (i +1 == n_execs /2 ) { + addr = base_addr; + exec.num_syncs =1 ; + exec.syncs =to_user_pointer (sync +1 ); +if (barrier) +pthread_barrier_wait (barrier); + } + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_engines; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +for (i =0 ; i < n_execs; i++) { +uint32_t __bo; + + __bo = bo[i % (n_execs /2 )]; +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +igt_assert_eq (data[i].data,0xc0ffee ); + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +for (i =0 ; i <3 ; i++) +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + +for (i =0 ; i < n_execs /2 ; i++) +gem_close (fd, bo[i]); + +xe_vm_destroy (fd, vm); +if (flags &MULTI_VM ) { +xe_vm_destroy (fd, vm2); +xe_vm_destroy (fd, vm3); + } +xe_device_put (fd); +close (fd); +} + +static void +test_evict_cm (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,size_t bo_size,unsigned long flags, +pthread_barrier_t *barrier) +{ +uint32_t vm, vm2; +uint32_t bind_engines[2 ] = {0 ,0 }; +uint64_t addr =0x100000000 , base_addr =0x100000000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t *bo; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; +uint64_t vm_sync; +uint64_t exec_sync; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + bo =calloc (n_execs /2 ,sizeof (*bo)); +igt_assert (bo); + + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[0 ] =xe_bind_engine_create (fd, vm,0 ); +if (flags &MULTI_VM ) { + vm2 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[1 ] =xe_bind_engine_create (fd, vm2,0 ); + } + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + +if (flags &MULTI_VM ) + engines[i] =xe_engine_create (fd, i &1 ? vm2 : vm, eci, +to_user_pointer (&ext)); +else + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); + } + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint32_t __bo; +int e = i % n_engines; + +if (i < n_execs /2 ) { +uint32_t _vm = (flags &EXTERNAL_OBJ ) && + i < n_execs /8 ?0 : vm; + +if (flags &MULTI_VM ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, +0 , bo_size); + }else if (flags &THREADED ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, + vm, bo_size); + }else { + __bo = bo[i] =xe_bo_create_flags (fd, _vm, + bo_size, +vram_memory (fd, eci->gt_id) | +system_memory (fd)); + } + }else { + __bo = bo[i % (n_execs /2 )]; + } +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +if (i < n_execs /2 ) +memset (data,0 ,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +if (i < n_execs /2 ) { + sync[0 ].addr =to_user_pointer (&data[i].vm_sync); +if (flags &MULTI_VM ) { +xe_vm_bind_async (fd, i &1 ? vm2 : vm, + i &1 ? bind_engines[1 ] : + bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + }else { +xe_vm_bind_async (fd, vm, bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + } +#define TWENTY_SEC 20000 +xe_wait_ufence (fd, &data[i].vm_sync,USER_FENCE_VALUE , +NULL ,TWENTY_SEC ); + } + sync[0 ].addr = addr + (char *)&data[i].exec_sync - + (char *)data; + addr += bo_size; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + exec.engine_id = engines[e]; + exec.address = batch_addr; +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_EXEC , &exec),0 ); + +if (i +1 == n_execs /2 ) { + addr = base_addr; +if (barrier) +pthread_barrier_wait (barrier); + } + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_execs; i++) { +uint32_t __bo; + + __bo = bo[i % (n_execs /2 )]; +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,TWENTY_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_engines; i++) +xe_engine_destroy (fd, engines[i]); + +for (i =0 ; i <2 ; i++) +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + +for (i =0 ; i < n_execs /2 ; i++) +gem_close (fd, bo[i]); + +xe_vm_destroy (fd, vm); +if (flags &MULTI_VM ) +xe_vm_destroy (fd, vm2); +xe_device_put (fd); +close (fd); +} + +struct thread_data { +pthread_t thread; +pthread_mutex_t *mutex; +pthread_cond_t *cond; +pthread_barrier_t *barrier; +int fd; +struct drm_xe_engine_class_instance *eci; +int n_engines; +int n_execs; +uint64_t bo_size; +int flags; +bool *go; +}; + +static void *thread (void *data) +{ +struct thread_data *t = data; + +pthread_mutex_lock (t->mutex); +while (*t->go ==0 ) +pthread_cond_wait (t->cond, t->mutex); +pthread_mutex_unlock (t->mutex); + +if (t->flags &COMPUTE_THREAD ) +test_evict_cm (t->fd, t->eci, t->n_engines, t->n_execs, + t->bo_size, t->flags, t->barrier); +else +test_evict (t->fd, t->eci, t->n_engines, t->n_execs, + t->bo_size, t->flags, t->barrier); + +return NULL ; +} + +static void +threads (int fd,struct drm_xe_engine_class_instance *eci, +int n_threads,int n_engines,int n_execs,size_t bo_size, +unsigned long flags) +{ +pthread_barrier_t barrier; +bool go = false; +struct thread_data *threads_data; +pthread_mutex_t mutex; +pthread_cond_t cond; +int i; + + threads_data =calloc (n_threads,sizeof (*threads_data)); +igt_assert (threads_data); + +pthread_mutex_init (&mutex,0 ); +pthread_cond_init (&cond,0 ); +pthread_barrier_init (&barrier,NULL , n_threads); + +for (i =0 ; i < n_threads; ++i) { + threads_data[i].mutex = &mutex; + threads_data[i].cond = &cond; + threads_data[i].barrier = &barrier; + threads_data[i].fd = fd; + threads_data[i].eci = eci; + threads_data[i].n_engines = n_engines; + threads_data[i].n_execs = n_execs; + threads_data[i].bo_size = bo_size; + threads_data[i].flags = flags; +if ((i &1 && flags &MIXED_THREADS ) || flags &COMPUTE_THREAD ) + threads_data[i].flags |=COMPUTE_THREAD ; +else + threads_data[i].flags |=LEGACY_THREAD ; + threads_data[i].go = &go; + +pthread_create (&threads_data[i].thread,0 , thread, + &threads_data[i]); + } + +pthread_mutex_lock (&mutex); + go = true; +pthread_cond_broadcast (&cond); +pthread_mutex_unlock (&mutex); + +for (i =0 ; i < n_threads; ++i) +pthread_join (threads_data[i].thread,NULL ); +} + +static uint64_t calc_bo_size (uint64_t vram_size,int mul,int div) +{ +return (ALIGN (vram_size,0x40000000 ) * mul) / div; +} + +/* +* Table driven test that attempts to cover all possible scenarios of eviction +* (small / large objects, compute mode vs non-compute VMs, external BO or BOs +* tied to VM, multiple VMs using over 51% of the VRAM, evicting BOs from your +* own VM, and using a user bind or kernel VM engine to do the binds). All of +* these options are attempted to be mixed via different table entries. Single +* threaded sections exists for both compute and non-compute VMs, and thread +* sections exists which cover multiple compute VM, multiple non-compute VMs, +* and mixing of VMs. +*/ +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections[] = { + {"small" ,16 ,448 ,1 ,128 ,0 }, + {"small-external" ,16 ,448 ,1 ,128 ,EXTERNAL_OBJ }, + {"small-multi-vm" ,16 ,256 ,1 ,128 ,MULTI_VM }, + {"large" ,4 ,16 ,1 ,4 ,0 }, + {"large-external" ,4 ,16 ,1 ,4 ,EXTERNAL_OBJ }, + {"large-multi-vm" ,4 ,8 ,3 ,8 ,MULTI_VM }, + {"beng-small" ,16 ,448 ,1 ,128 ,BIND_ENGINE }, + {"beng-small-external" ,16 ,448 ,1 ,128 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-small-multi-vm" ,16 ,256 ,1 ,128 ,BIND_ENGINE | +MULTI_VM }, + {"beng-large" ,4 ,16 ,1 ,4 ,0 }, + {"beng-large-external" ,4 ,16 ,1 ,4 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-large-multi-vm" ,4 ,8 ,3 ,8 ,BIND_ENGINE |MULTI_VM }, + {NULL }, + }; +const struct section_cm { +const char *name; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections_cm[] = { + {"small-cm" ,16 ,448 ,1 ,128 ,0 }, + {"small-external-cm" ,16 ,448 ,1 ,128 ,EXTERNAL_OBJ }, + {"small-multi-vm-cm" ,16 ,256 ,1 ,128 ,MULTI_VM }, + {"large-cm" ,4 ,16 ,1 ,4 ,0 }, + {"large-external-cm" ,4 ,16 ,1 ,4 ,EXTERNAL_OBJ }, + {"large-multi-vm-cm" ,4 ,8 ,3 ,8 ,MULTI_VM }, + {"beng-small-cm" ,16 ,448 ,1 ,128 ,BIND_ENGINE }, + {"beng-small-external-cm" ,16 ,448 ,1 ,128 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-small-multi-vm-cm" ,16 ,256 ,1 ,128 ,BIND_ENGINE | +MULTI_VM }, + {"beng-large-cm" ,4 ,16 ,1 ,4 ,BIND_ENGINE }, + {"beng-large-external-cm" ,4 ,16 ,1 ,4 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-large-multi-vm-cm" ,4 ,8 ,3 ,8 ,BIND_ENGINE | +MULTI_VM }, + {NULL }, + }; +const struct section_threads { +const char *name; +int n_threads; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections_threads[] = { + {"threads-small" ,2 ,16 ,128 ,1 ,128 , +THREADED }, + {"cm-threads-small" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |THREADED }, + {"mixed-threads-small" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |THREADED }, + {"mixed-many-threads-small" ,3 ,16 ,128 ,1 ,128 , +THREADED }, + {"threads-large" ,2 ,2 ,4 ,3 ,8 , +THREADED }, + {"cm-threads-large" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |THREADED }, + {"mixed-threads-large" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |THREADED }, + {"mixed-many-threads-large" ,3 ,2 ,4 ,3 ,8 , +THREADED }, + {"threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MULTI_VM |THREADED }, + {"cm-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |MULTI_VM |THREADED }, + {"mixed-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |MULTI_VM |THREADED }, + {"threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MULTI_VM |THREADED }, + {"cm-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |MULTI_VM |THREADED }, + {"mixed-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |MULTI_VM |THREADED }, + {"beng-threads-small" ,2 ,16 ,128 ,1 ,128 , +THREADED |BIND_ENGINE }, + {"beng-cm-threads-small" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-small" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |THREADED |BIND_ENGINE }, + {"beng-mixed-many-threads-small" ,3 ,16 ,128 ,1 ,128 , +THREADED |BIND_ENGINE }, + {"beng-threads-large" ,2 ,2 ,4 ,3 ,8 , +THREADED |BIND_ENGINE }, + {"beng-cm-threads-large" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-large" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |THREADED |BIND_ENGINE }, + {"beng-mixed-many-threads-large" ,3 ,2 ,4 ,3 ,8 , +THREADED |BIND_ENGINE }, + {"beng-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-cm-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-cm-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |MULTI_VM |THREADED |BIND_ENGINE }, + {NULL }, + }; +uint64_t vram_size; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); +igt_require (xe_has_vram (fd)); + vram_size =xe_vram_size (fd,0 ); +igt_assert (vram_size); + +for_each_hw_engine (fd, hwe) +if (hwe->engine_class !=DRM_XE_ENGINE_CLASS_COPY ) +break ; + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +test_evict (-1 , hwe, s->n_engines, s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags,NULL ); + } + +for (const struct section_cm *s = sections_cm; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +test_evict_cm (-1 , hwe, s->n_engines, s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags,NULL ); + } + +for (const struct section_threads *s = sections_threads; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +threads (-1 , hwe, s->n_threads, s->n_engines, + s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags); + } + +igt_fixture +close (fd ); +}tests/xe/xe_exec_balancer.c new file +714
-0@@ -0,0 +1,714 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality for virtual and parallel engines +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: virtual and parallel engines +* Test category: functionality test +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_spin.h" +#include <string.h> + +#define MAX_INSTANCE 9 + +/** +* SUBTEST: virtual-all-active +* Description: +* Run a test to check if virtual engines can be running on all instances +* of a class simultaneously +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +*/ +static void test_all_active (int fd,int gt,int class) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_INSTANCE ]; +uint32_t syncobjs[MAX_INSTANCE ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +struct xe_spin spin; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, num_placements =0 ; + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * num_placements; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd),xe_get_default_alignment (fd)); + + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + +for (i =0 ; i < num_placements; i++) { +struct drm_xe_engine_create create = { + .vm_id = vm, + .width =1 , + .num_placements = num_placements, + .instances =to_user_pointer (eci), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + syncobjs[i] =syncobj_create (fd,0 ); + }; + + sync[0 ].handle =syncobj_create (fd,0 ); +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); + +for (i =0 ; i < num_placements; i++) { +uint64_t spin_offset = (char *)&data[i].spin - (char *)data; +uint64_t spin_addr = addr + spin_offset; + +xe_spin_init (&data[i].spin, spin_addr, false); + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[i]; + + exec.engine_id = engines[i]; + exec.address = spin_addr; +xe_exec (fd, &exec); +xe_spin_wait_started (&data[i].spin); + } + +for (i =0 ; i < num_placements; i++) { +xe_spin_end (&data[i].spin); +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); + } +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < num_placements; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +munmap (data, bo_size); +gem_close (fd, bo); +xe_vm_destroy (fd, vm); +} + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define VIRTUAL (0x1 << 4) +#define PARALLEL (0x1 << 5) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] test twice +* Run type: BAT +* +* SUBTEST: no-exec-%s +* Description: Run no-exec %arg[1] test +* Run type: BAT +* +* arg[1]: +* +* @virtual-basic: virtual basic +* @virtual-userptr: virtual userptr +* @virtual-rebind: virtual rebind +* @virtual-userptr-rebind: virtual userptr -rebind +* @virtual-userptr-invalidate: virtual userptr invalidate +* @virtual-userptr-invalidate-race: virtual userptr invalidate racy +* @parallel-basic: parallel basic +* @parallel-userptr: parallel userptr +* @parallel-rebind: parallel rebind +* @parallel-userptr-rebind: parallel userptr rebind +* @parallel-userptr-invalidate: parallel userptr invalidate +* @parallel-userptr-invalidate-race: parallel userptr invalidate racy +*/ +static void +test_exec (int fd,int gt,int class,int n_engines,int n_execs, +unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, j, b, num_placements =0 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd),xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), bo_size); +igt_assert (data); + } +memset (data,0 , bo_size); + }else { + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + } + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_engine_create create = { + .vm_id = vm, + .width = flags &PARALLEL ? num_placements :1 , + .num_placements = flags &PARALLEL ?1 : num_placements, + .instances =to_user_pointer (eci), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + syncobjs[i] =syncobj_create (fd,0 ); + }; + exec.num_batch_buffer = flags &PARALLEL ? num_placements :1 ; + + sync[0 ].handle =syncobj_create (fd,0 ); +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (data), addr, + bo_size, sync,1 ); + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint64_t batches[MAX_INSTANCE ]; +int e = i % n_engines; + +for (j =0 ; j < num_placements && flags &PARALLEL ; ++j) + batches[j] = batch_addr; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = flags &PARALLEL ? +to_user_pointer (batches) : batch_addr; +if (e != i) +syncobj_reset (fd, &syncobjs[e],1 ); +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { + sync[1 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, + sync +1 ,1 ); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 , +to_user_pointer (data), + addr, bo_size, sync, +1 ); + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +igt_assert (syncobj_wait (fd, &syncobjs[e],1 , +INT64_MAX ,0 ,NULL )); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + } + } + +for (i =0 ; i < n_engines && n_execs; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +} + +/** +* SUBTEST: once-cm-%s +* Description: Run compute mode virtual engine arg[1] test only once +* +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-cm-%s +* Description: Run compute mode virtual engine arg[1] test twice +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-cm-%s +* Description: Run compute mode virtual engine arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-cm-%s +* Description: Run compute mode virtual engine arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: no-exec-cm-%s +* Description: Run compute mode virtual engine arg[1] no-exec test +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @virtual-basic: virtual basic +* @virtual-userptr: virtual userptr +* @virtual-rebind: virtual rebind +* @virtual-userptr-rebind: virtual userptr rebind +* @virtual-userptr-invalidate: virtual userptr invalidate +* @virtual-userptr-invalidate-race: virtual userptr invalidate racy +*/ + +static void +test_cm (int fd,int gt,int class,int n_engines,int n_execs, +unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, j, b, num_placements =0 ; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; +struct drm_xe_engine_create create = { + .vm_id = vm, + .width =1 , + .num_placements = num_placements, + .instances =to_user_pointer (eci), + .extensions =to_user_pointer (&ext), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + } + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (data), addr, + bo_size, sync,1 ); + +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size,NULL , +0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 , +to_user_pointer (data), + addr, bo_size, sync, +1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +xe_wait_ufence (fd, &data[i].exec_sync, +USER_FENCE_VALUE ,NULL ,ONE_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + +if (flags &RACE ) { + map_fd =open ("/tmp" ,O_TMPFILE |O_RDWR , +0x666 ); +write (map_fd, data, bo_size); + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED , map_fd,0 ); + }else { + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED |MAP_ANONYMOUS ,-1 ,0 ); + } +igt_assert (data !=MAP_FAILED ); + } + } + + j = flags &INVALIDATE && n_execs ? n_execs -1 :0 ; +for (i = j; i < n_execs; i++) +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + +/* Wait for all execs to complete */ +if (flags &INVALIDATE ) +usleep (250000 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +for (i =0 ; i < n_engines; i++) +xe_engine_destroy (fd, engines[i]); + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +} + + +igt_main +{ +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"virtual-basic" ,VIRTUAL }, + {"virtual-userptr" ,VIRTUAL |USERPTR }, + {"virtual-rebind" ,VIRTUAL |REBIND }, + {"virtual-userptr-rebind" ,VIRTUAL |USERPTR |REBIND }, + {"virtual-userptr-invalidate" ,VIRTUAL |USERPTR | +INVALIDATE }, + {"virtual-userptr-invalidate-race" ,VIRTUAL |USERPTR | +INVALIDATE |RACE }, + {"parallel-basic" ,PARALLEL }, + {"parallel-userptr" ,PARALLEL |USERPTR }, + {"parallel-rebind" ,PARALLEL |REBIND }, + {"parallel-userptr-rebind" ,PARALLEL |USERPTR |REBIND }, + {"parallel-userptr-invalidate" ,PARALLEL |USERPTR | +INVALIDATE }, + {"parallel-userptr-invalidate-race" ,PARALLEL |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int gt; +int class; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + + igt_subtest("virtual-all-active") +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_all_active (fd, gt, class); + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,1 , + s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,2 , + s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("many-engines-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("no-exec-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,0 , + s->flags); + +if (s->flags &PARALLEL ) +continue ; + + igt_subtest_f("once-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,1 , s->flags); + + igt_subtest_f("twice-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,2 , s->flags); + + igt_subtest_f("many-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("many-engines-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("no-exec-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,0 , s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_basic.c new file +350
-0@@ -0,0 +1,350 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality +* Category: Hardware building block +* Sub-category: execbuf +* Test category: functionality test +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define DEFER_ALLOC (0x1 << 5) +#define DEFER_BIND (0x1 << 6) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-many-vm-%s +* Description: Run %arg[1] test on many engines and many VMs +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] test twice +* Run type: BAT +* +* SUBTEST: no-exec-%s +* Description: Run no-exec %arg[1] test +* Run type: BAT +* +* arg[1]: +* +* @basic: basic +* @basic-defer-mmap: basic defer mmap +* @basic-defer-bind: basic defer bind +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate racy +* @bindengine: bind engine +* @bindengine-userptr: bind engine userptr description +* @bindengine-rebind: bind engine rebind description +* @bindengine-userptr-rebind: bind engine userptr rebind +* @bindengine-userptr-invalidate: bind engine userptr invalidate +* @bindengine-userptr-invalidate-race: bind engine userptr invalidate racy +*/ + +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,int n_vm,unsigned int flags) +{ +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint64_t addr[MAX_N_ENGINES ]; +uint32_t vm[MAX_N_ENGINES ]; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); +igt_assert (n_vm <=MAX_N_ENGINES ); + +for (i =0 ; i < n_vm; ++i) + vm[i] =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + + addr[0 ] =0x1a0000 ; +for (i =1 ; i <MAX_N_ENGINES ; ++i) + addr[i] = addr[i -1 ] + (0x1ull <<32 ); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), bo_size); +igt_assert (data); + } +memset (data,0 , bo_size); + }else { +if (flags &DEFER_ALLOC ) { + bo =xe_bo_create_flags (fd, n_vm ==1 ? vm[0 ] :0 , + bo_size, +vram_if_possible (fd, eci->gt_id) | +XE_GEM_CREATE_FLAG_DEFER_BACKING ); + }else { + bo =xe_bo_create (fd, eci->gt_id, n_vm ==1 ? vm[0 ] :0 , + bo_size); + } +if (!(flags &DEFER_BIND )) + data =xe_bo_map (fd, bo, bo_size); + } + +for (i =0 ; i < n_engines; i++) { +uint32_t __vm = vm[i % n_vm]; + + engines[i] =xe_engine_create (fd, __vm, eci,0 ); +if (flags &BIND_ENGINE ) + bind_engines[i] =xe_bind_engine_create (fd, __vm,0 ); +else + bind_engines[i] =0 ; + syncobjs[i] =syncobj_create (fd,0 ); + }; + + sync[0 ].handle =syncobj_create (fd,0 ); +for (i =0 ; i < n_vm; ++i) { +if (bo) +xe_vm_bind_async (fd, vm[i], bind_engines[i], bo,0 , + addr[i], bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm[i], bind_engines[i], +to_user_pointer (data), addr[i], + bo_size, sync,1 ); + } + +if (flags &DEFER_BIND ) + data =xe_bo_map (fd, bo, bo_size); + +for (i =0 ; i < n_execs; i++) { +uint64_t __addr = addr[i % n_vm]; +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = __addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = __addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +if (e != i) +syncobj_reset (fd, &syncobjs[e],1 ); +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +uint32_t __vm = vm[i % n_vm]; + + sync[1 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, __vm, bind_engines[e],0 , + __addr, bo_size, sync +1 ,1 ); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + addr[i % n_vm] += bo_size; + __addr = addr[i % n_vm]; +if (bo) +xe_vm_bind_async (fd, __vm, bind_engines[e], bo, +0 , __addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, __vm, + bind_engines[e], +to_user_pointer (data), + __addr, bo_size, sync, +1 ); + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +igt_assert (syncobj_wait (fd, &syncobjs[e],1 , +INT64_MAX ,0 ,NULL )); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + } + } + +for (i =0 ; i < n_engines && n_execs; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +for (i =0 ; i < n_vm; ++i) { +syncobj_reset (fd, &sync[0 ].handle,1 ); +xe_vm_unbind_async (fd, vm[i], bind_engines[i],0 , addr[i], + bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 , +INT64_MAX ,0 ,NULL )); + } + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +for (i =0 ; i < n_vm; ++i) +xe_vm_destroy (fd, vm[i]); +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"basic" ,0 }, + {"basic-defer-mmap" ,DEFER_ALLOC }, + {"basic-defer-bind" ,DEFER_ALLOC |DEFER_BIND }, + {"userptr" ,USERPTR }, + {"rebind" ,REBIND }, + {"userptr-rebind" ,USERPTR |REBIND }, + {"userptr-invalidate" ,USERPTR |INVALIDATE }, + {"userptr-invalidate-race" ,USERPTR |INVALIDATE |RACE }, + {"bindengine" ,BIND_ENGINE }, + {"bindengine-userptr" ,BIND_ENGINE |USERPTR }, + {"bindengine-rebind" ,BIND_ENGINE |REBIND }, + {"bindengine-userptr-rebind" ,BIND_ENGINE |USERPTR |REBIND }, + {"bindengine-userptr-invalidate" ,BIND_ENGINE |USERPTR | +INVALIDATE }, + {"bindengine-userptr-invalidate-race" ,BIND_ENGINE |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,1 ,1 , s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,2 ,1 , s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,1 , + s->flags); + + igt_subtest_f("many-engines-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,1 , + s->flags); + + igt_subtest_f("many-engines-many-vm-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,16 , + s->flags); + + igt_subtest_f("no-exec-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,0 ,1 , s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_compute_mode.c new file +364
-0@@ -0,0 +1,364 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf compute machine functionality +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: compute machine +* Test category: functionality test +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define VM_FOR_BO (0x1 << 5) +#define ENGINE_EARLY (0x1 << 6) + +/** +* SUBTEST: twice-%s +* Description: Run %arg[1] compute machine test twice +* Run type: BAT +* +* SUBTEST: once-%s +* Description: Run %arg[1] compute machine test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] compute machine test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @basic: basic +* @preempt-fence-early: preempt fence early +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate race +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: bindengine userptr invalidate +* @bindengine-userptr-invalidate-race: bindengine-userptr invalidate race +*/ + +/** +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] compute machine test on many engines +* +* arg[1]: +* +* @basic: basic +* @preempt-fence-early: preempt fence early +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: bindengine userptr invalidate +*/ +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +int i, j, b; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +for (i =0 ; (flags &ENGINE_EARLY ) && i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { + bo =xe_bo_create (fd, eci->gt_id, flags &VM_FOR_BO ? vm :0 , + bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; !(flags &ENGINE_EARLY ) && i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[0 ], bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, bind_engines[0 ], +to_user_pointer (data), addr, + bo_size, sync,1 ); +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm, bind_engines[e],0 , + addr, bo_size,NULL ,0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[e], bo, +0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, + bind_engines[e], +to_user_pointer (data), + addr, bo_size, sync, +1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +xe_wait_ufence (fd, &data[i].exec_sync, +USER_FENCE_VALUE ,NULL ,ONE_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + +if (flags &RACE ) { + map_fd =open ("/tmp" ,O_TMPFILE |O_RDWR , +0x666 ); +write (map_fd, data, bo_size); + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED , map_fd,0 ); + }else { + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED |MAP_ANONYMOUS ,-1 ,0 ); + } +igt_assert (data !=MAP_FAILED ); + } + } + + j = flags &INVALIDATE ? n_execs -1 :0 ; +for (i = j; i < n_execs; i++) +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + +/* Wait for all execs to complete */ +if (flags &INVALIDATE ) +usleep (250000 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +xe_vm_unbind_async (fd, vm, bind_engines[0 ],0 , addr, bo_size, + sync,1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + +for (i = j; i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +for (i =0 ; i < n_engines; i++) { +xe_engine_destroy (fd, engines[i]); +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +if (map_fd !=-1 ) +close (map_fd); +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"basic" ,0 }, + {"preempt-fence-early" ,VM_FOR_BO |ENGINE_EARLY }, + {"userptr" ,USERPTR }, + {"rebind" ,REBIND }, + {"userptr-rebind" ,USERPTR |REBIND }, + {"userptr-invalidate" ,USERPTR |INVALIDATE }, + {"userptr-invalidate-race" ,USERPTR |INVALIDATE |RACE }, + {"bindengine" ,BIND_ENGINE }, + {"bindengine-userptr" ,BIND_ENGINE |USERPTR }, + {"bindengine-rebind" ,BIND_ENGINE |REBIND }, + {"bindengine-userptr-rebind" ,BIND_ENGINE |USERPTR | +REBIND }, + {"bindengine-userptr-invalidate" ,BIND_ENGINE |USERPTR | +INVALIDATE }, + {"bindengine-userptr-invalidate-race" ,BIND_ENGINE |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,1 , s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,2 , s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :128 , + s->flags); + +if (s->flags &RACE ) +continue ; + + igt_subtest_f("many-engines-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :128 , + s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_fault_mode.c new file +575
-0@@ -0,0 +1,575 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality for virtual and parallel engines +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: fault mode +* Test category: functionality test +* GPU requirements: GPU needs support for DRM_XE_VM_CREATE_FAULT_MODE +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define WAIT_ATOMIC (0x1 << 5) +#define IMMEDIATE (0x1 << 6) +#define PREFETCH (0x1 << 7) +#define INVALID_FAULT (0x1 << 8) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] fault mode test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] fault mode test twice +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] fault mode test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] fault mode test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @basic: basic +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate race +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: +* bindengine userptr invalidate +* @bindengine-userptr-invalidate-race: +* bindengine userptr invalidate race +* @basic-imm: basic imm +* @userptr-imm: userptr imm +* @rebind-imm: rebind imm +* @userptr-rebind-imm: userptr rebind imm +* @userptr-invalidate-imm: userptr invalidate imm +* @userptr-invalidate-race-imm: userptr invalidate race imm +* @bindengine-imm: bindengine imm +* @bindengine-userptr-imm: bindengine userptr imm +* @bindengine-rebind-imm: bindengine rebind imm +* @bindengine-userptr-rebind-imm: +* bindengine userptr rebind imm +* @bindengine-userptr-invalidate-imm: +* bindengine userptr invalidate imm +* @bindengine-userptr-invalidate-race-imm: +* bindengine userptr invalidate race imm +* @basic-prefetch: basic prefetch +* @userptr-prefetch: userptr prefetch +* @rebind-prefetch: rebind prefetch +* @userptr-rebind-prefetch: userptr rebind prefetch +* @userptr-invalidate-prefetch: userptr invalidate prefetch +* @userptr-invalidate-race-prefetch: userptr invalidate race prefetch +* @bindengine-prefetch: bindengine prefetch +* @bindengine-userptr-prefetch: bindengine userptr prefetch +* @bindengine-rebind-prefetch: bindengine rebind prefetch +* @bindengine-userptr-rebind-prefetch: bindengine userptr rebind prefetch +* @bindengine-userptr-invalidate-prefetch: +* bindengine userptr invalidate prefetch +* @bindengine-userptr-invalidate-race-prefetch: +* bindengine userptr invalidate race prefetch +* @invalid-fault: invalid fault +* @invalid-userptr-fault: invalid userptr fault +*/ + +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +int i, j, b; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_FAULT_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { +if (flags &PREFETCH ) + bo =xe_bo_create_flags (fd,0 , bo_size, +all_memory_regions (fd)); +else + bo =xe_bo_create (fd, eci->gt_id,0 , bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; i < n_engines; i++) { + engines[i] =xe_engine_create (fd, vm, eci,0 ); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (flags &IMMEDIATE ) { +if (bo) +xe_vm_bind_async_flags (fd, vm, bind_engines[0 ], bo,0 , + addr, bo_size, sync,1 , +XE_VM_BIND_FLAG_IMMEDIATE ); +else +xe_vm_bind_userptr_async_flags (fd, vm, bind_engines[0 ], +to_user_pointer (data), + addr, bo_size, sync,1 , +XE_VM_BIND_FLAG_IMMEDIATE ); + }else { +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[0 ], bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, bind_engines[0 ], +to_user_pointer (data), addr, + bo_size, sync,1 ); + } + +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +if (flags &PREFETCH ) { +/* Should move to system memory */ +xe_vm_prefetch_async (fd, vm, bind_engines[0 ],0 , addr, + bo_size, sync,1 ,0 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm, bind_engines[e],0 , + addr, bo_size,NULL ,0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[e], bo, +0 , addr, bo_size, sync,1 ); +else Lines of this file are not shown. View the raw message.
tests/xe/xe_prime_self_import.c new file +489
-0Lines of this file are not shown. View the raw message.
tests/xe/xe_test_config.json new file +133
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Re: [igt-dev] [PATCH i-g-t v8 4/7] tests/xe: Add Xe IGT tests
Quoted 3 lines · Matthew Brost
On Wed, Mar 08, 2023 at 08:53:31AM +0100, Zbigniew Kempczyński wrote:
I should be the author of this patch I'm thinking as I wrote almost of these tests.
I'm really sorry.
That wasn't intention to change it, I'm not sure on which step it was changed to me.
What's a way to change author after such commit is merged? Revert all and add again?
--
Zbigniew
Quoted 9,511 lines
Matt
Quoted 9,508 lines
Collaborative change of IGT Xe tests.
Signed-off-by Matthew Brost <[email protected]>Signed-off-by Jason Ekstrand <[email protected]>Signed-off-by Maarten Lankhorst <[email protected]>Signed-off-by Philippe Lecluse <[email protected]>Signed-off-by Francois Dugast <[email protected]>Signed-off-by Rodrigo Vivi <[email protected]>Signed-off-by Matthew Auld <[email protected]>Signed-off-by Zbigniew Kempczyński <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>--- tests/meson.build | 1 + tests/xe/meson.build | 33 + tests/xe/xe_compute.c | 148 +++ tests/xe/xe_debugfs.c | 257 +++++ tests/xe/xe_dma_buf_sync.c | 262 +++++ tests/xe/xe_evict.c | 623 ++++++++++++ tests/xe/xe_exec_balancer.c | 714 ++++++++++++++ tests/xe/xe_exec_basic.c | 350 +++++++ tests/xe/xe_exec_compute_mode.c | 364 +++++++ tests/xe/xe_exec_fault_mode.c | 575 +++++++++++ tests/xe/xe_exec_reset.c | 817 ++++++++++++++++ tests/xe/xe_exec_threads.c | 1166 ++++++++++++++++++++++ tests/xe/xe_guc_pc.c | 425 ++++++++ tests/xe/xe_huc_copy.c | 205 ++++ tests/xe/xe_mmap.c | 79 ++ tests/xe/xe_mmio.c | 94 ++ tests/xe/xe_pm.c | 385 ++++++++ tests/xe/xe_prime_self_import.c | 489 ++++++++++ tests/xe/xe_query.c | 475 +++++++++ tests/xe/xe_test_config.json | 133 +++ tests/xe/xe_vm.c | 1612 +++++++++++++++++++++++++++++++ tests/xe/xe_waitfence.c | 103 ++ 22 files changed, 9310 insertions(+) create mode 100644 tests/xe/meson.build create mode 100644 tests/xe/xe_compute.c create mode 100644 tests/xe/xe_debugfs.c create mode 100644 tests/xe/xe_dma_buf_sync.c create mode 100644 tests/xe/xe_evict.c create mode 100644 tests/xe/xe_exec_balancer.c create mode 100644 tests/xe/xe_exec_basic.c create mode 100644 tests/xe/xe_exec_compute_mode.c create mode 100644 tests/xe/xe_exec_fault_mode.c create mode 100644 tests/xe/xe_exec_reset.c create mode 100644 tests/xe/xe_exec_threads.c create mode 100644 tests/xe/xe_guc_pc.c create mode 100644 tests/xe/xe_huc_copy.c create mode 100644 tests/xe/xe_mmap.c create mode 100644 tests/xe/xe_mmio.c create mode 100644 tests/xe/xe_pm.c create mode 100644 tests/xe/xe_prime_self_import.c create mode 100644 tests/xe/xe_query.c create mode 100644 tests/xe/xe_test_config.json create mode 100644 tests/xe/xe_vm.c create mode 100644 tests/xe/xe_waitfence.ctests/meson.build +1
-0@@ -470,6 +470,7 @@ test_executables += executable('sw_sync', 'sw_sync.c', test_list += 'sw_sync' subdir('amdgpu') +subdir('xe') subdir('v3d')tests/xe/meson.build new file +33
-0@@ -0,0 +1,33 @@ +xe_progs = [ + 'xe_compute', + 'xe_dma_buf_sync', + 'xe_debugfs', + 'xe_evict', + 'xe_exec_balancer', + 'xe_exec_basic', + 'xe_exec_compute_mode', + 'xe_exec_fault_mode', + 'xe_exec_reset', + 'xe_exec_threads', + 'xe_guc_pc', + 'xe_huc_copy', + 'xe_mmap', + 'xe_mmio', + 'xe_pm', + 'xe_prime_self_import', + 'xe_query', + 'xe_vm', + 'xe_waitfence', +] +xe_deps = test_deps + +xe_test_config = meson.current_source_dir() + '/xe_test_config.json' + +foreach prog : xe_progs + test_executables += executable(prog, prog + '.c', + dependencies : xe_deps, + install_dir : xedir, + install_rpath : xedir_rpathdir, + install : true) + test_list += join_paths('xe', prog) +endforeachtests/xe/xe_compute.c new file +148
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2022 Intel Corporation +*/ + +/** +* TEST: Check compute-related functionality +* Category: Hardware building block +* Sub-category: compute +* Test category: functionality test +* Run type: BAT +*/ + +#include <string.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "xe_drm.h" +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_compute.h" + +#define MAX (X ,Y ) (((X) > (Y)) ? (X) : (Y)) +#define SIZE_DATA 64 +#define SIZE_BATCH 0x1000 +#define SIZE_KERNEL 0x1000 +#define SIZE_BUFFER_INPUT MAX(sizeof(float)*SIZE_DATA, 0x1000) +#define SIZE_BUFFER_OUTPUT MAX(sizeof(float)*SIZE_DATA, 0x1000) +#define ADDR_BATCH 0x100000 +#define ADDR_INPUT (unsigned long)0x200000 +#define ADDR_OUTPUT (unsigned long)0x300000 +#define ADDR_SURFACE_STATE_BASE (unsigned long)0x400000 +#define ADDR_DYNAMIC_STATE_BASE (unsigned long)0x500000 +#define ADDR_INDIRECT_OBJECT_BASE 0x800100000000 +#define OFFSET_INDIRECT_DATA_START 0xFFFDF000 +#define OFFSET_KERNEL 0xFFFEF000 + +struct bo_dict_entry { +uint64_t addr; +uint32_t size; +void *data; +}; + +/** +* SUBTEST: compute-square +* GPU requirement: only works on TGL_GT2 with device ID: 0x9a49 +* Description: +* This test shows how to create a batch to execute a +* compute kernel. For now it supports tgllp only. +* TODO: extend test to cover other platforms +*/ +static void +test_compute_square (int fd) +{ +uint32_t vm, engine; +float *dinput; +struct drm_xe_sync sync = {0 }; + +#define BO_DICT_ENTRIES 7 +struct bo_dict_entry bo_dict[BO_DICT_ENTRIES ] = { + { .addr =ADDR_INDIRECT_OBJECT_BASE +OFFSET_KERNEL , .size =SIZE_KERNEL },// kernel + { .addr =ADDR_DYNAMIC_STATE_BASE , .size =0x1000 },// dynamic state + { .addr =ADDR_SURFACE_STATE_BASE , .size =0x1000 },// surface state + { .addr =ADDR_INDIRECT_OBJECT_BASE +OFFSET_INDIRECT_DATA_START , .size =0x10000 },// indirect data + { .addr =ADDR_INPUT , .size =SIZE_BUFFER_INPUT },// input + { .addr =ADDR_OUTPUT , .size =SIZE_BUFFER_OUTPUT },// output + { .addr =ADDR_BATCH , .size =SIZE_BATCH },// batch + }; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + engine =xe_engine_create_class (fd, vm,DRM_XE_ENGINE_CLASS_RENDER ); + sync.flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL ; + sync.handle =syncobj_create (fd,0 ); + +for (int i =0 ; i <BO_DICT_ENTRIES ; i++) { + bo_dict[i].data =aligned_alloc (xe_get_default_alignment (fd), bo_dict[i].size); +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (bo_dict[i].data), bo_dict[i].addr, bo_dict[i].size, &sync,1 ); +syncobj_wait (fd, &sync.handle,1 ,INT64_MAX ,0 ,NULL ); +memset (bo_dict[i].data,0 , bo_dict[i].size); + } +memcpy (bo_dict[0 ].data, tgllp_kernel_square_bin, tgllp_kernel_square_length); +tgllp_create_dynamic_state (bo_dict[1 ].data,OFFSET_KERNEL ); +tgllp_create_surface_state (bo_dict[2 ].data,ADDR_INPUT ,ADDR_OUTPUT ); +tgllp_create_indirect_data (bo_dict[3 ].data,ADDR_INPUT ,ADDR_OUTPUT ); + dinput = (float *)bo_dict[4 ].data; +srand (time (NULL )); +for (int i=0 ; i <SIZE_DATA ; i++) { + ((float *) dinput)[i] =rand ()/(float )RAND_MAX ; + } +tgllp_create_batch_compute (bo_dict[6 ].data,ADDR_SURFACE_STATE_BASE ,ADDR_DYNAMIC_STATE_BASE ,ADDR_INDIRECT_OBJECT_BASE ,OFFSET_INDIRECT_DATA_START ); + +xe_exec_wait (fd, engine,ADDR_BATCH ); +for (int i =0 ; i <SIZE_DATA ; i++) { +igt_assert (((float *) bo_dict[5 ].data)[i] == ((float *) bo_dict[4 ].data)[i] * ((float *) bo_dict[4 ].data)[i]); + } + +for (int i =0 ; i <BO_DICT_ENTRIES ; i++) { +xe_vm_unbind_async (fd, vm,0 ,0 , bo_dict[i].addr, bo_dict[i].size, &sync,1 ); +syncobj_wait (fd, &sync.handle,1 ,INT64_MAX ,0 ,NULL ); +free (bo_dict[i].data); + } + +syncobj_destroy (fd, sync.handle); +xe_engine_destroy (fd, engine); +xe_vm_destroy (fd, vm); +} + +static bool +is_device_supported (int fd) +{ +struct drm_xe_query_config *config; +struct drm_xe_device_query query = { + .extensions =0 , + .query =DRM_XE_DEVICE_QUERY_CONFIG , + .size =0 , + .data =0 , + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_DEVICE_QUERY , &query),0 ); + + config =malloc (query.size); +igt_assert (config); + + query.data =to_user_pointer (config); +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_DEVICE_QUERY , &query),0 ); + +return (config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] &0xffff ) ==0x9a49 ; +} + +igt_main +{ +int xe; + + igt_fixture { + xe =drm_open_driver (DRIVER_XE ); +xe_device_get (xe); + } + + igt_subtest("compute-square") { +igt_skip_on (!is_device_supported (xe)); +test_compute_square (xe); + } + + igt_fixture { +xe_device_put (xe); +close (xe); + } +}tests/xe/xe_debugfs.c new file +257
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +/** +* TEST: Check debugfs userspace API +* Category: Software building block +* Sub-category: debugfs +* Test category: functionality test +* Run type: BAT +* Description: Validate debugfs entries +*/ + +#include "igt.h" + +#include "xe_drm.h" +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" + +#include <fcntl.h> +#include <string.h> +#include <sys/types.h> +#include <dirent.h> + +static int validate_entries (int fd,const char *add_path,const char *const str_val[],int str_cnt) +{ +int i; +int hit; +int found =0 ; +int not_found =0 ; +DIR *dir; +struct dirent *de; +char path[PATH_MAX ]; + +if (!igt_debugfs_path (fd, path,sizeof (path))) +return -1 ; + +strcat (path, add_path); + dir =opendir (path); +if (!dir) +return -1 ; + +while ((de =readdir (dir))) { +if (de->d_name[0 ] =='.' ) +continue ; + hit =0 ; +for (i =0 ; i < str_cnt; i++) { +if (!strcmp (str_val[i], de->d_name)) { + hit =1 ; +break ; + } + } +if (hit) { + found++; + }else { + not_found++; +igt_warn ("no test for: %s/%s\n" , path, de->d_name); + } + } +closedir (dir); +return 0 ; +} + +/** +* SUBTEST: base +* Description: Check if various debugfs devnodes exist and test reading them. +*/ +static void +test_base (int fd) +{ +static const char *const expected_files[] = { +"gt0" , +"gt1" , +"stolen_mm" , +"gtt_mm" , +"vram0_mm" , +"forcewake_all" , +"info" , +"gem_names" , +"clients" , +"name" + }; + +char reference[4096 ]; +int val =0 ; +struct xe_device *xe_dev =xe_device_get (fd); +struct drm_xe_query_config *config = xe_dev->config; + +igt_assert (config); +sprintf (reference,"devid 0x%llx" , + config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] &0xffff ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"revid %lld" , + config->info[XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] >>16 ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"is_dgfx %s" , config->info[XE_QUERY_CONFIG_FLAGS ] & +XE_QUERY_CONFIG_FLAGS_HAS_VRAM ?"yes" :"no" ); + +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"enable_guc %s" , config->info[XE_QUERY_CONFIG_FLAGS ] & +XE_QUERY_CONFIG_FLAGS_USE_GUC ?"yes" :"no" ); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +sprintf (reference,"tile_count %lld" , config->info[XE_QUERY_CONFIG_GT_COUNT ]); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +switch (config->info[XE_QUERY_CONFIG_VA_BITS ]) { +case 48 : + val =3 ; +break ; +case 57 : + val =4 ; +break ; + } +sprintf (reference,"vm_max_level %d" , val); +igt_assert (igt_debugfs_search (fd,"info" , reference)); + +igt_assert (igt_debugfs_exists (fd,"gt0" ,O_RDONLY )); +if (config->info[XE_QUERY_CONFIG_GT_COUNT ] >1 ) +igt_assert (igt_debugfs_exists (fd,"gt1" ,O_RDONLY )); + +igt_assert (igt_debugfs_exists (fd,"gtt_mm" ,O_RDONLY )); +igt_debugfs_dump (fd,"gtt_mm" ); + +if (config->info[XE_QUERY_CONFIG_FLAGS ] &XE_QUERY_CONFIG_FLAGS_HAS_VRAM ) { +igt_assert (igt_debugfs_exists (fd,"vram0_mm" ,O_RDONLY )); +igt_debugfs_dump (fd,"vram0_mm" ); + } + +if (igt_debugfs_exists (fd,"stolen_mm" ,O_RDONLY )) +igt_debugfs_dump (fd,"stolen_mm" ); + +igt_assert (igt_debugfs_exists (fd,"clients" ,O_RDONLY )); +igt_debugfs_dump (fd,"clients" ); + +igt_assert (igt_debugfs_exists (fd,"gem_names" ,O_RDONLY )); +igt_debugfs_dump (fd,"gem_names" ); + +validate_entries (fd,"" , expected_files,ARRAY_SIZE (expected_files)); + +free (config); +} + +/** +* SUBTEST: %s +* Description: Check %arg[1] debugfs devnodes +* TODO: add support for ``force_reset`` entries +* +* arg[1]: +* +* @gt0: gt0 +* @gt1: gt1 +*/ +static void +test_gt (int fd,int gt_id) +{ +char name[256 ]; +static const char *const expected_files[] = { +"uc" , +"steering" , +"topology" , +"sa_info" , +"hw_engines" , +// "force_reset" + }; +static const char *const expected_files_uc[] = { +"huc_info" , +"guc_log" , +"guc_info" , +// "guc_ct_selftest" + }; + +sprintf (name,"gt%d/hw_engines" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/sa_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/steering" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/topology" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/guc_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/huc_info" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"gt%d/uc/guc_log" , gt_id); +igt_assert (igt_debugfs_exists (fd, name,O_RDONLY )); +igt_debugfs_dump (fd, name); + +sprintf (name,"/gt%d" , gt_id); +validate_entries (fd, name, expected_files,ARRAY_SIZE (expected_files)); + +sprintf (name,"/gt%d/uc" , gt_id); +validate_entries (fd, name, expected_files_uc,ARRAY_SIZE (expected_files_uc)); +} + +/** +* SUBTEST: forcewake +* Description: check forcewake debugfs devnode +*/ +static void +test_forcewake (int fd) +{ +int handle =igt_debugfs_open (fd,"forcewake_all" ,O_WRONLY ); + +igt_assert (handle !=-1 ); +close (handle); +} + +igt_main +{ +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); +__igt_debugfs_dump (fd,"info" ,IGT_LOG_INFO ); + } + + igt_subtest("base") { +test_base (fd); + } + + igt_subtest("gt0") { +igt_require (igt_debugfs_exists (fd,"gt0" ,O_RDONLY )); +test_gt (fd,0 ); + } + + igt_subtest("gt1") { +igt_require (igt_debugfs_exists (fd,"gt1" ,O_RDONLY )); +test_gt (fd,1 ); + } + + igt_subtest("forcewake") { +test_forcewake (fd); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_dma_buf_sync.c new file +262
-0@@ -0,0 +1,262 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Check dmabuf functionality +* Category: Software building block +* Sub-category: dmabuf +* Test category: functionality test +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_spin.h" +#include <string.h> +#include <linux/dma-buf.h> +#include <sys/poll.h> + +#define MAX_N_BO 16 +#define N_FD 2 + +#define READ_SYNC (0x1 << 0) + +struct igt_dma_buf_sync_file { +__u32 flags; +__s32 fd; +}; + +#define IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE \ + _IOWR(DMA_BUF_BASE, 2, struct igt_dma_buf_sync_file) + +static int dmabuf_export_sync_file (int dmabuf,uint32_t flags) +{ +struct igt_dma_buf_sync_file arg; + + arg.flags = flags; + arg.fd =-1 ; +do_ioctl (dmabuf,IGT_DMA_BUF_IOCTL_EXPORT_SYNC_FILE , &arg); + +return arg.fd; +} + +static bool dmabuf_busy (int dmabuf,uint32_t flags) +{ +struct pollfd pfd = { .fd = dmabuf }; + +/* If DMA_BUF_SYNC_WRITE is set, we don't want to set POLLIN or +* else poll() may return a non-zero value if there are only read +* fences because POLLIN is ready even if POLLOUT isn't. +*/ +if (flags &DMA_BUF_SYNC_WRITE ) + pfd.events |=POLLOUT ; +else if (flags &DMA_BUF_SYNC_READ ) + pfd.events |=POLLIN ; + +return poll (&pfd,1 ,0 ) ==0 ; +} + +static bool sync_file_busy (int sync_file) +{ +struct pollfd pfd = { .fd = sync_file, .events =POLLIN }; +return poll (&pfd,1 ,0 ) ==0 ; +} + +/** +* SUBTEST: export-dma-buf-once +* Description: Test exporting a sync file from a dma-buf +* Run type: BAT +* +* SUBTEST: export-dma-buf-once-read-sync +* Description: Test export prime BO as sync file and verify business +* Run type: BAT +* +* SUBTEST: export-dma-buf-many +* Description: Test exporting many sync files from a dma-buf +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: export-dma-buf-many-read-sync +* Description: Test export many prime BO as sync file and verify business +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +*/ + +static void +test_export_dma_buf (struct drm_xe_engine_class_instance *hwe0, +struct drm_xe_engine_class_instance *hwe1, +int n_bo,int flags) +{ +uint64_t addr =0x1a0000 , base_addr =0x1a0000 ; +int fd[N_FD ]; +uint32_t bo[MAX_N_BO ]; +int dma_buf_fd[MAX_N_BO ]; +uint32_t import_bo[MAX_N_BO ]; +uint32_t vm[N_FD ]; +uint32_t engine[N_FD ]; +size_t bo_size; +struct { +struct xe_spin spin; +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data [MAX_N_BO ]; +int i; + +igt_assert (n_bo <=MAX_N_BO ); + +for (i =0 ; i <N_FD ; ++i) { + fd[i] =drm_open_driver (DRIVER_XE ); +xe_device_get (fd[0 ]); + vm[i] =xe_vm_create (fd[i],0 ,0 ); + engine[i] =xe_engine_create (fd[i], vm[i], !i ? hwe0 : hwe1,0 ); + } + + bo_size =sizeof (*data[0 ]) *N_FD ; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd[0 ]), +xe_get_default_alignment (fd[0 ])); +for (i =0 ; i < n_bo; ++i) { + bo[i] =xe_bo_create (fd[0 ], hwe0->gt_id,0 , bo_size); + dma_buf_fd[i] =prime_handle_to_fd (fd[0 ], bo[i]); + import_bo[i] =prime_fd_to_handle (fd[1 ], dma_buf_fd[i]); + +if (i &1 ) + data[i] =xe_bo_map (fd[1 ], import_bo[i], bo_size); +else + data[i] =xe_bo_map (fd[0 ], bo[i], bo_size); +memset (data[i],0 , bo_size); + +xe_vm_bind_sync (fd[0 ], vm[0 ], bo[i],0 , addr, bo_size); +xe_vm_bind_sync (fd[1 ], vm[1 ], import_bo[i],0 , addr, bo_size); + addr += bo_size; + } + addr = base_addr; + +for (i =0 ; i < n_bo; ++i) { +uint64_t batch_offset = (char *)&data[i]->batch - + (char *)data[i]; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i]->data - (char *)data[i]; +uint64_t sdi_addr = addr + sdi_offset; +uint64_t spin_offset = (char *)&data[i]->spin - (char *)data[i]; +uint64_t spin_addr = addr + spin_offset; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t syncobj; +int b =0 ; +int sync_fd; + +/* Write spinner on FD[0] */ +xe_spin_init (&data[i]->spin, spin_addr, true); + exec.engine_id = engine[0 ]; + exec.address = spin_addr; +xe_exec (fd[0 ], &exec); + +/* Export prime BO as sync file and veify business */ +if (flags &READ_SYNC ) + sync_fd =dmabuf_export_sync_file (dma_buf_fd[i], +DMA_BUF_SYNC_READ ); +else + sync_fd =dmabuf_export_sync_file (dma_buf_fd[i], +DMA_BUF_SYNC_WRITE ); +xe_spin_wait_started (&data[i]->spin); +igt_assert (sync_file_busy (sync_fd)); +igt_assert (dmabuf_busy (dma_buf_fd[i],DMA_BUF_SYNC_READ )); + +/* Convert sync file to syncobj */ + syncobj =syncobj_create (fd[1 ],0 ); +syncobj_import_sync_file (fd[1 ], syncobj, sync_fd); + +/* Do an exec with syncobj as in fence on FD[1] */ + data[i]->batch[b++] =MI_STORE_DWORD_IMM ; + data[i]->batch[b++] = sdi_addr; + data[i]->batch[b++] = sdi_addr >>32 ; + data[i]->batch[b++] =0xc0ffee ; + data[i]->batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i]->batch)); + sync[0 ].handle = syncobj; + sync[1 ].handle =syncobj_create (fd[1 ],0 ); + exec.engine_id = engine[1 ]; + exec.address = batch_addr; + exec.num_syncs =2 ; +xe_exec (fd[1 ], &exec); + +/* Verify exec blocked on spinner / prime BO */ +usleep (5000 ); +igt_assert (!syncobj_wait (fd[1 ], &sync[1 ].handle,1 ,1 ,0 , +NULL )); +igt_assert_eq (data[i]->data,0x0 ); + +/* End spinner and verify exec complete */ +xe_spin_end (&data[i]->spin); +igt_assert (syncobj_wait (fd[1 ], &sync[1 ].handle,1 ,INT64_MAX , +0 ,NULL )); +igt_assert_eq (data[i]->data,0xc0ffee ); + +/* Clean up */ +syncobj_destroy (fd[1 ], sync[0 ].handle); +syncobj_destroy (fd[1 ], sync[1 ].handle); +close (sync_fd); + addr += bo_size; + } + +for (i =0 ; i < n_bo; ++i) { +munmap (data[i], bo_size); +gem_close (fd[0 ], bo[i]); +close (dma_buf_fd[i]); + } + +for (i =0 ; i <N_FD ; ++i) { +xe_device_put (fd[i]); +close (fd[i]); + } + +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe, *hwe0 =NULL , *hwe1; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + +for_each_hw_engine (fd, hwe) +if (hwe0 ==NULL ) { + hwe0 = hwe; + }else { + hwe1 = hwe; +break ; + } + } + + igt_subtest("export-dma-buf-once") +test_export_dma_buf (hwe0, hwe1,1 ,0 ); + + igt_subtest("export-dma-buf-many") +test_export_dma_buf (hwe0, hwe1,16 ,0 ); + + igt_subtest("export-dma-buf-once-read-sync") +test_export_dma_buf (hwe0, hwe1,1 ,READ_SYNC ); + + igt_subtest("export-dma-buf-many-read-sync") +test_export_dma_buf (hwe0, hwe1,16 ,READ_SYNC ); + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_evict.c new file +623
-0@@ -0,0 +1,623 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define MULTI_VM (0x1 << 0) +#define THREADED (0x1 << 1) +#define MIXED_THREADS (0x1 << 2) +#define LEGACY_THREAD (0x1 << 3) +#define COMPUTE_THREAD (0x1 << 4) +#define EXTERNAL_OBJ (0x1 << 5) +#define BIND_ENGINE (0x1 << 6) + +static void +test_evict (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,size_t bo_size, +unsigned long flags,pthread_barrier_t *barrier) +{ +uint32_t vm, vm2, vm3; +uint32_t bind_engines[3 ] = {0 ,0 ,0 }; +uint64_t addr =0x100000000 , base_addr =0x100000000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +uint32_t *bo; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + bo =calloc (n_execs /2 ,sizeof (*bo)); +igt_assert (bo); + + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[0 ] =xe_bind_engine_create (fd, vm,0 ); +if (flags &MULTI_VM ) { + vm2 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + vm3 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); +if (flags &BIND_ENGINE ) { + bind_engines[1 ] =xe_bind_engine_create (fd, vm2,0 ); + bind_engines[2 ] =xe_bind_engine_create (fd, vm3,0 ); + } + } + +for (i =0 ; i < n_engines; i++) { +if (flags &MULTI_VM ) + engines[i] =xe_engine_create (fd, i &1 ? vm2 : vm , + eci,0 ); +else + engines[i] =xe_engine_create (fd, vm, eci,0 ); + syncobjs[i] =syncobj_create (fd,0 ); + }; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint32_t __bo; +int e = i % n_engines; + +if (i < n_execs /2 ) { +uint32_t _vm = (flags &EXTERNAL_OBJ ) && + i < n_execs /8 ?0 : vm; + +if (flags &MULTI_VM ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id,0 , + bo_size); + }else if (flags &THREADED ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, vm, + bo_size); + }else { + __bo = bo[i] =xe_bo_create_flags (fd, _vm, + bo_size, +vram_memory (fd, eci->gt_id) | +system_memory (fd)); + } + }else { + __bo = bo[i % (n_execs /2 )]; + } +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); + +if (i < n_execs /2 ) { + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[0 ].handle =syncobj_create (fd,0 ); +if (flags &MULTI_VM ) { +xe_vm_bind_async (fd, vm3, bind_engines[2 ], __bo, +0 , addr, + bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 , +INT64_MAX ,0 ,NULL )); +xe_vm_bind_async (fd, i &1 ? vm2 : vm, + i &1 ? bind_engines[1 ] : + bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + }else { +xe_vm_bind_async (fd, vm, bind_engines[0 ], + __bo,0 , addr, bo_size, + sync,1 ); + } + } + addr += bo_size; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +if (i >= n_engines) +syncobj_reset (fd, &syncobjs[e],1 ); + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_EXEC , &exec),0 ); + +if (i +1 == n_execs /2 ) { + addr = base_addr; + exec.num_syncs =1 ; + exec.syncs =to_user_pointer (sync +1 ); +if (barrier) +pthread_barrier_wait (barrier); + } + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_engines; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +for (i =0 ; i < n_execs; i++) { +uint32_t __bo; + + __bo = bo[i % (n_execs /2 )]; +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +igt_assert_eq (data[i].data,0xc0ffee ); + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +for (i =0 ; i <3 ; i++) +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + +for (i =0 ; i < n_execs /2 ; i++) +gem_close (fd, bo[i]); + +xe_vm_destroy (fd, vm); +if (flags &MULTI_VM ) { +xe_vm_destroy (fd, vm2); +xe_vm_destroy (fd, vm3); + } +xe_device_put (fd); +close (fd); +} + +static void +test_evict_cm (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,size_t bo_size,unsigned long flags, +pthread_barrier_t *barrier) +{ +uint32_t vm, vm2; +uint32_t bind_engines[2 ] = {0 ,0 }; +uint64_t addr =0x100000000 , base_addr =0x100000000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t *bo; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; +uint64_t vm_sync; +uint64_t exec_sync; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + bo =calloc (n_execs /2 ,sizeof (*bo)); +igt_assert (bo); + + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[0 ] =xe_bind_engine_create (fd, vm,0 ); +if (flags &MULTI_VM ) { + vm2 =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); +if (flags &BIND_ENGINE ) + bind_engines[1 ] =xe_bind_engine_create (fd, vm2,0 ); + } + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + +if (flags &MULTI_VM ) + engines[i] =xe_engine_create (fd, i &1 ? vm2 : vm, eci, +to_user_pointer (&ext)); +else + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); + } + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint32_t __bo; +int e = i % n_engines; + +if (i < n_execs /2 ) { +uint32_t _vm = (flags &EXTERNAL_OBJ ) && + i < n_execs /8 ?0 : vm; + +if (flags &MULTI_VM ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, +0 , bo_size); + }else if (flags &THREADED ) { + __bo = bo[i] =xe_bo_create (fd, eci->gt_id, + vm, bo_size); + }else { + __bo = bo[i] =xe_bo_create_flags (fd, _vm, + bo_size, +vram_memory (fd, eci->gt_id) | +system_memory (fd)); + } + }else { + __bo = bo[i % (n_execs /2 )]; + } +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +if (i < n_execs /2 ) +memset (data,0 ,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +if (i < n_execs /2 ) { + sync[0 ].addr =to_user_pointer (&data[i].vm_sync); +if (flags &MULTI_VM ) { +xe_vm_bind_async (fd, i &1 ? vm2 : vm, + i &1 ? bind_engines[1 ] : + bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + }else { +xe_vm_bind_async (fd, vm, bind_engines[0 ], __bo, +0 , addr, bo_size, sync,1 ); + } +#define TWENTY_SEC 20000 +xe_wait_ufence (fd, &data[i].vm_sync,USER_FENCE_VALUE , +NULL ,TWENTY_SEC ); + } + sync[0 ].addr = addr + (char *)&data[i].exec_sync - + (char *)data; + addr += bo_size; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + exec.engine_id = engines[e]; + exec.address = batch_addr; +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_EXEC , &exec),0 ); + +if (i +1 == n_execs /2 ) { + addr = base_addr; +if (barrier) +pthread_barrier_wait (barrier); + } + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_execs; i++) { +uint32_t __bo; + + __bo = bo[i % (n_execs /2 )]; +if (i) +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + data =xe_bo_map (fd, __bo, +ALIGN (sizeof (*data) * n_execs,0x1000 )); +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,TWENTY_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + } +munmap (data,ALIGN (sizeof (*data) * n_execs,0x1000 )); + +for (i =0 ; i < n_engines; i++) +xe_engine_destroy (fd, engines[i]); + +for (i =0 ; i <2 ; i++) +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + +for (i =0 ; i < n_execs /2 ; i++) +gem_close (fd, bo[i]); + +xe_vm_destroy (fd, vm); +if (flags &MULTI_VM ) +xe_vm_destroy (fd, vm2); +xe_device_put (fd); +close (fd); +} + +struct thread_data { +pthread_t thread; +pthread_mutex_t *mutex; +pthread_cond_t *cond; +pthread_barrier_t *barrier; +int fd; +struct drm_xe_engine_class_instance *eci; +int n_engines; +int n_execs; +uint64_t bo_size; +int flags; +bool *go; +}; + +static void *thread (void *data) +{ +struct thread_data *t = data; + +pthread_mutex_lock (t->mutex); +while (*t->go ==0 ) +pthread_cond_wait (t->cond, t->mutex); +pthread_mutex_unlock (t->mutex); + +if (t->flags &COMPUTE_THREAD ) +test_evict_cm (t->fd, t->eci, t->n_engines, t->n_execs, + t->bo_size, t->flags, t->barrier); +else +test_evict (t->fd, t->eci, t->n_engines, t->n_execs, + t->bo_size, t->flags, t->barrier); + +return NULL ; +} + +static void +threads (int fd,struct drm_xe_engine_class_instance *eci, +int n_threads,int n_engines,int n_execs,size_t bo_size, +unsigned long flags) +{ +pthread_barrier_t barrier; +bool go = false; +struct thread_data *threads_data; +pthread_mutex_t mutex; +pthread_cond_t cond; +int i; + + threads_data =calloc (n_threads,sizeof (*threads_data)); +igt_assert (threads_data); + +pthread_mutex_init (&mutex,0 ); +pthread_cond_init (&cond,0 ); +pthread_barrier_init (&barrier,NULL , n_threads); + +for (i =0 ; i < n_threads; ++i) { + threads_data[i].mutex = &mutex; + threads_data[i].cond = &cond; + threads_data[i].barrier = &barrier; + threads_data[i].fd = fd; + threads_data[i].eci = eci; + threads_data[i].n_engines = n_engines; + threads_data[i].n_execs = n_execs; + threads_data[i].bo_size = bo_size; + threads_data[i].flags = flags; +if ((i &1 && flags &MIXED_THREADS ) || flags &COMPUTE_THREAD ) + threads_data[i].flags |=COMPUTE_THREAD ; +else + threads_data[i].flags |=LEGACY_THREAD ; + threads_data[i].go = &go; + +pthread_create (&threads_data[i].thread,0 , thread, + &threads_data[i]); + } + +pthread_mutex_lock (&mutex); + go = true; +pthread_cond_broadcast (&cond); +pthread_mutex_unlock (&mutex); + +for (i =0 ; i < n_threads; ++i) +pthread_join (threads_data[i].thread,NULL ); +} + +static uint64_t calc_bo_size (uint64_t vram_size,int mul,int div) +{ +return (ALIGN (vram_size,0x40000000 ) * mul) / div; +} + +/* +* Table driven test that attempts to cover all possible scenarios of eviction +* (small / large objects, compute mode vs non-compute VMs, external BO or BOs +* tied to VM, multiple VMs using over 51% of the VRAM, evicting BOs from your +* own VM, and using a user bind or kernel VM engine to do the binds). All of +* these options are attempted to be mixed via different table entries. Single +* threaded sections exists for both compute and non-compute VMs, and thread +* sections exists which cover multiple compute VM, multiple non-compute VMs, +* and mixing of VMs. +*/ +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections[] = { + {"small" ,16 ,448 ,1 ,128 ,0 }, + {"small-external" ,16 ,448 ,1 ,128 ,EXTERNAL_OBJ }, + {"small-multi-vm" ,16 ,256 ,1 ,128 ,MULTI_VM }, + {"large" ,4 ,16 ,1 ,4 ,0 }, + {"large-external" ,4 ,16 ,1 ,4 ,EXTERNAL_OBJ }, + {"large-multi-vm" ,4 ,8 ,3 ,8 ,MULTI_VM }, + {"beng-small" ,16 ,448 ,1 ,128 ,BIND_ENGINE }, + {"beng-small-external" ,16 ,448 ,1 ,128 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-small-multi-vm" ,16 ,256 ,1 ,128 ,BIND_ENGINE | +MULTI_VM }, + {"beng-large" ,4 ,16 ,1 ,4 ,0 }, + {"beng-large-external" ,4 ,16 ,1 ,4 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-large-multi-vm" ,4 ,8 ,3 ,8 ,BIND_ENGINE |MULTI_VM }, + {NULL }, + }; +const struct section_cm { +const char *name; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections_cm[] = { + {"small-cm" ,16 ,448 ,1 ,128 ,0 }, + {"small-external-cm" ,16 ,448 ,1 ,128 ,EXTERNAL_OBJ }, + {"small-multi-vm-cm" ,16 ,256 ,1 ,128 ,MULTI_VM }, + {"large-cm" ,4 ,16 ,1 ,4 ,0 }, + {"large-external-cm" ,4 ,16 ,1 ,4 ,EXTERNAL_OBJ }, + {"large-multi-vm-cm" ,4 ,8 ,3 ,8 ,MULTI_VM }, + {"beng-small-cm" ,16 ,448 ,1 ,128 ,BIND_ENGINE }, + {"beng-small-external-cm" ,16 ,448 ,1 ,128 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-small-multi-vm-cm" ,16 ,256 ,1 ,128 ,BIND_ENGINE | +MULTI_VM }, + {"beng-large-cm" ,4 ,16 ,1 ,4 ,BIND_ENGINE }, + {"beng-large-external-cm" ,4 ,16 ,1 ,4 ,BIND_ENGINE | +EXTERNAL_OBJ }, + {"beng-large-multi-vm-cm" ,4 ,8 ,3 ,8 ,BIND_ENGINE | +MULTI_VM }, + {NULL }, + }; +const struct section_threads { +const char *name; +int n_threads; +int n_engines; +int n_execs; +int mul; +int div; +unsigned int flags; + } sections_threads[] = { + {"threads-small" ,2 ,16 ,128 ,1 ,128 , +THREADED }, + {"cm-threads-small" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |THREADED }, + {"mixed-threads-small" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |THREADED }, + {"mixed-many-threads-small" ,3 ,16 ,128 ,1 ,128 , +THREADED }, + {"threads-large" ,2 ,2 ,4 ,3 ,8 , +THREADED }, + {"cm-threads-large" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |THREADED }, + {"mixed-threads-large" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |THREADED }, + {"mixed-many-threads-large" ,3 ,2 ,4 ,3 ,8 , +THREADED }, + {"threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MULTI_VM |THREADED }, + {"cm-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |MULTI_VM |THREADED }, + {"mixed-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |MULTI_VM |THREADED }, + {"threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MULTI_VM |THREADED }, + {"cm-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |MULTI_VM |THREADED }, + {"mixed-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |MULTI_VM |THREADED }, + {"beng-threads-small" ,2 ,16 ,128 ,1 ,128 , +THREADED |BIND_ENGINE }, + {"beng-cm-threads-small" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-small" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |THREADED |BIND_ENGINE }, + {"beng-mixed-many-threads-small" ,3 ,16 ,128 ,1 ,128 , +THREADED |BIND_ENGINE }, + {"beng-threads-large" ,2 ,2 ,4 ,3 ,8 , +THREADED |BIND_ENGINE }, + {"beng-cm-threads-large" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-large" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |THREADED |BIND_ENGINE }, + {"beng-mixed-many-threads-large" ,3 ,2 ,4 ,3 ,8 , +THREADED |BIND_ENGINE }, + {"beng-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-cm-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +COMPUTE_THREAD |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-small-multi-vm" ,2 ,16 ,128 ,1 ,128 , +MIXED_THREADS |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-cm-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +COMPUTE_THREAD |MULTI_VM |THREADED |BIND_ENGINE }, + {"beng-mixed-threads-large-multi-vm" ,2 ,2 ,4 ,3 ,8 , +MIXED_THREADS |MULTI_VM |THREADED |BIND_ENGINE }, + {NULL }, + }; +uint64_t vram_size; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); +igt_require (xe_has_vram (fd)); + vram_size =xe_vram_size (fd,0 ); +igt_assert (vram_size); + +for_each_hw_engine (fd, hwe) +if (hwe->engine_class !=DRM_XE_ENGINE_CLASS_COPY ) +break ; + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +test_evict (-1 , hwe, s->n_engines, s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags,NULL ); + } + +for (const struct section_cm *s = sections_cm; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +test_evict_cm (-1 , hwe, s->n_engines, s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags,NULL ); + } + +for (const struct section_threads *s = sections_threads; s->name; s++) { + igt_subtest_f("evict-%s", s->name) +threads (-1 , hwe, s->n_threads, s->n_engines, + s->n_execs, +calc_bo_size (vram_size, s->mul, s->div), + s->flags); + } + +igt_fixture +close (fd ); +}tests/xe/xe_exec_balancer.c new file +714
-0@@ -0,0 +1,714 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality for virtual and parallel engines +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: virtual and parallel engines +* Test category: functionality test +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include "xe/xe_spin.h" +#include <string.h> + +#define MAX_INSTANCE 9 + +/** +* SUBTEST: virtual-all-active +* Description: +* Run a test to check if virtual engines can be running on all instances +* of a class simultaneously +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +*/ +static void test_all_active (int fd,int gt,int class) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_INSTANCE ]; +uint32_t syncobjs[MAX_INSTANCE ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +struct xe_spin spin; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, num_placements =0 ; + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * num_placements; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd),xe_get_default_alignment (fd)); + + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + +for (i =0 ; i < num_placements; i++) { +struct drm_xe_engine_create create = { + .vm_id = vm, + .width =1 , + .num_placements = num_placements, + .instances =to_user_pointer (eci), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + syncobjs[i] =syncobj_create (fd,0 ); + }; + + sync[0 ].handle =syncobj_create (fd,0 ); +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); + +for (i =0 ; i < num_placements; i++) { +uint64_t spin_offset = (char *)&data[i].spin - (char *)data; +uint64_t spin_addr = addr + spin_offset; + +xe_spin_init (&data[i].spin, spin_addr, false); + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[i]; + + exec.engine_id = engines[i]; + exec.address = spin_addr; +xe_exec (fd, &exec); +xe_spin_wait_started (&data[i].spin); + } + +for (i =0 ; i < num_placements; i++) { +xe_spin_end (&data[i].spin); +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); + } +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < num_placements; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +munmap (data, bo_size); +gem_close (fd, bo); +xe_vm_destroy (fd, vm); +} + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define VIRTUAL (0x1 << 4) +#define PARALLEL (0x1 << 5) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] test twice +* Run type: BAT +* +* SUBTEST: no-exec-%s +* Description: Run no-exec %arg[1] test +* Run type: BAT +* +* arg[1]: +* +* @virtual-basic: virtual basic +* @virtual-userptr: virtual userptr +* @virtual-rebind: virtual rebind +* @virtual-userptr-rebind: virtual userptr -rebind +* @virtual-userptr-invalidate: virtual userptr invalidate +* @virtual-userptr-invalidate-race: virtual userptr invalidate racy +* @parallel-basic: parallel basic +* @parallel-userptr: parallel userptr +* @parallel-rebind: parallel rebind +* @parallel-userptr-rebind: parallel userptr rebind +* @parallel-userptr-invalidate: parallel userptr invalidate +* @parallel-userptr-invalidate-race: parallel userptr invalidate racy +*/ +static void +test_exec (int fd,int gt,int class,int n_engines,int n_execs, +unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, j, b, num_placements =0 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd),xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), bo_size); +igt_assert (data); + } +memset (data,0 , bo_size); + }else { + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + } + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_engine_create create = { + .vm_id = vm, + .width = flags &PARALLEL ? num_placements :1 , + .num_placements = flags &PARALLEL ?1 : num_placements, + .instances =to_user_pointer (eci), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + syncobjs[i] =syncobj_create (fd,0 ); + }; + exec.num_batch_buffer = flags &PARALLEL ? num_placements :1 ; + + sync[0 ].handle =syncobj_create (fd,0 ); +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (data), addr, + bo_size, sync,1 ); + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +uint64_t batches[MAX_INSTANCE ]; +int e = i % n_engines; + +for (j =0 ; j < num_placements && flags &PARALLEL ; ++j) + batches[j] = batch_addr; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = flags &PARALLEL ? +to_user_pointer (batches) : batch_addr; +if (e != i) +syncobj_reset (fd, &syncobjs[e],1 ); +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { + sync[1 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, + sync +1 ,1 ); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 , +to_user_pointer (data), + addr, bo_size, sync, +1 ); + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +igt_assert (syncobj_wait (fd, &syncobjs[e],1 , +INT64_MAX ,0 ,NULL )); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + } + } + +for (i =0 ; i < n_engines && n_execs; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +} + +/** +* SUBTEST: once-cm-%s +* Description: Run compute mode virtual engine arg[1] test only once +* +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-cm-%s +* Description: Run compute mode virtual engine arg[1] test twice +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-cm-%s +* Description: Run compute mode virtual engine arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-cm-%s +* Description: Run compute mode virtual engine arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: no-exec-cm-%s +* Description: Run compute mode virtual engine arg[1] no-exec test +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @virtual-basic: virtual basic +* @virtual-userptr: virtual userptr +* @virtual-rebind: virtual rebind +* @virtual-userptr-rebind: virtual userptr rebind +* @virtual-userptr-invalidate: virtual userptr invalidate +* @virtual-userptr-invalidate-race: virtual userptr invalidate racy +*/ + +static void +test_cm (int fd,int gt,int class,int n_engines,int n_execs, +unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +struct drm_xe_engine_class_instance *hwe; +struct drm_xe_engine_class_instance eci[MAX_INSTANCE ]; +int i, j, b, num_placements =0 ; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + +for_each_hw_engine (fd, hwe) { +if (hwe->engine_class != class || hwe->gt_id != gt) +continue ; + + eci[num_placements++] = *hwe; + } +if (num_placements <2 ) +return ; + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { + bo =xe_bo_create (fd, gt, vm, bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; +struct drm_xe_engine_create create = { + .vm_id = vm, + .width =1 , + .num_placements = num_placements, + .instances =to_user_pointer (eci), + .extensions =to_user_pointer (&ext), + }; + +igt_assert_eq (igt_ioctl (fd,DRM_IOCTL_XE_ENGINE_CREATE , + &create),0 ); + engines[i] = create.engine_id; + } + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 ,to_user_pointer (data), addr, + bo_size, sync,1 ); + +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size,NULL , +0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm,0 , bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm,0 , +to_user_pointer (data), + addr, bo_size, sync, +1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +xe_wait_ufence (fd, &data[i].exec_sync, +USER_FENCE_VALUE ,NULL ,ONE_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + +if (flags &RACE ) { + map_fd =open ("/tmp" ,O_TMPFILE |O_RDWR , +0x666 ); +write (map_fd, data, bo_size); + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED , map_fd,0 ); + }else { + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED |MAP_ANONYMOUS ,-1 ,0 ); + } +igt_assert (data !=MAP_FAILED ); + } + } + + j = flags &INVALIDATE && n_execs ? n_execs -1 :0 ; +for (i = j; i < n_execs; i++) +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + +/* Wait for all execs to complete */ +if (flags &INVALIDATE ) +usleep (250000 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +xe_vm_unbind_async (fd, vm,0 ,0 , addr, bo_size, sync,1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +for (i =0 ; i < n_engines; i++) +xe_engine_destroy (fd, engines[i]); + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +} + + +igt_main +{ +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"virtual-basic" ,VIRTUAL }, + {"virtual-userptr" ,VIRTUAL |USERPTR }, + {"virtual-rebind" ,VIRTUAL |REBIND }, + {"virtual-userptr-rebind" ,VIRTUAL |USERPTR |REBIND }, + {"virtual-userptr-invalidate" ,VIRTUAL |USERPTR | +INVALIDATE }, + {"virtual-userptr-invalidate-race" ,VIRTUAL |USERPTR | +INVALIDATE |RACE }, + {"parallel-basic" ,PARALLEL }, + {"parallel-userptr" ,PARALLEL |USERPTR }, + {"parallel-rebind" ,PARALLEL |REBIND }, + {"parallel-userptr-rebind" ,PARALLEL |USERPTR |REBIND }, + {"parallel-userptr-invalidate" ,PARALLEL |USERPTR | +INVALIDATE }, + {"parallel-userptr-invalidate-race" ,PARALLEL |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int gt; +int class; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + + igt_subtest("virtual-all-active") +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_all_active (fd, gt, class); + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,1 , + s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,2 , + s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("many-engines-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("no-exec-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_exec (fd, gt, class,1 ,0 , + s->flags); + +if (s->flags &PARALLEL ) +continue ; + + igt_subtest_f("once-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,1 , s->flags); + + igt_subtest_f("twice-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,2 , s->flags); + + igt_subtest_f("many-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("many-engines-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 , + s->flags); + + igt_subtest_f("no-exec-cm-%s", s->name) +for_each_gt (fd, gt) +for_each_hw_engine_class (class) +test_cm (fd, gt, class,1 ,0 , s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_basic.c new file +350
-0@@ -0,0 +1,350 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality +* Category: Hardware building block +* Sub-category: execbuf +* Test category: functionality test +*/ + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define DEFER_ALLOC (0x1 << 5) +#define DEFER_BIND (0x1 << 6) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-many-vm-%s +* Description: Run %arg[1] test on many engines and many VMs +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] test twice +* Run type: BAT +* +* SUBTEST: no-exec-%s +* Description: Run no-exec %arg[1] test +* Run type: BAT +* +* arg[1]: +* +* @basic: basic +* @basic-defer-mmap: basic defer mmap +* @basic-defer-bind: basic defer bind +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate racy +* @bindengine: bind engine +* @bindengine-userptr: bind engine userptr description +* @bindengine-rebind: bind engine rebind description +* @bindengine-userptr-rebind: bind engine userptr rebind +* @bindengine-userptr-invalidate: bind engine userptr invalidate +* @bindengine-userptr-invalidate-race: bind engine userptr invalidate racy +*/ + +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,int n_vm,unsigned int flags) +{ +struct drm_xe_sync sync[2 ] = { + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + { .flags =DRM_XE_SYNC_SYNCOBJ |DRM_XE_SYNC_SIGNAL , }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =2 , + .syncs =to_user_pointer (&sync), + }; +uint64_t addr[MAX_N_ENGINES ]; +uint32_t vm[MAX_N_ENGINES ]; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +uint32_t syncobjs[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint32_t data; + } *data; +int i, b; + +igt_assert (n_engines <=MAX_N_ENGINES ); +igt_assert (n_vm <=MAX_N_ENGINES ); + +for (i =0 ; i < n_vm; ++i) + vm[i] =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + + addr[0 ] =0x1a0000 ; +for (i =1 ; i <MAX_N_ENGINES ; ++i) + addr[i] = addr[i -1 ] + (0x1ull <<32 ); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), bo_size); +igt_assert (data); + } +memset (data,0 , bo_size); + }else { +if (flags &DEFER_ALLOC ) { + bo =xe_bo_create_flags (fd, n_vm ==1 ? vm[0 ] :0 , + bo_size, +vram_if_possible (fd, eci->gt_id) | +XE_GEM_CREATE_FLAG_DEFER_BACKING ); + }else { + bo =xe_bo_create (fd, eci->gt_id, n_vm ==1 ? vm[0 ] :0 , + bo_size); + } +if (!(flags &DEFER_BIND )) + data =xe_bo_map (fd, bo, bo_size); + } + +for (i =0 ; i < n_engines; i++) { +uint32_t __vm = vm[i % n_vm]; + + engines[i] =xe_engine_create (fd, __vm, eci,0 ); +if (flags &BIND_ENGINE ) + bind_engines[i] =xe_bind_engine_create (fd, __vm,0 ); +else + bind_engines[i] =0 ; + syncobjs[i] =syncobj_create (fd,0 ); + }; + + sync[0 ].handle =syncobj_create (fd,0 ); +for (i =0 ; i < n_vm; ++i) { +if (bo) +xe_vm_bind_async (fd, vm[i], bind_engines[i], bo,0 , + addr[i], bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm[i], bind_engines[i], +to_user_pointer (data), addr[i], + bo_size, sync,1 ); + } + +if (flags &DEFER_BIND ) + data =xe_bo_map (fd, bo, bo_size); + +for (i =0 ; i < n_execs; i++) { +uint64_t __addr = addr[i % n_vm]; +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = __addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = __addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].flags &= ~DRM_XE_SYNC_SIGNAL ; + sync[1 ].flags |=DRM_XE_SYNC_SIGNAL ; + sync[1 ].handle = syncobjs[e]; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +if (e != i) +syncobj_reset (fd, &syncobjs[e],1 ); +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +uint32_t __vm = vm[i % n_vm]; + + sync[1 ].flags &= ~DRM_XE_SYNC_SIGNAL ; +xe_vm_unbind_async (fd, __vm, bind_engines[e],0 , + __addr, bo_size, sync +1 ,1 ); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; + addr[i % n_vm] += bo_size; + __addr = addr[i % n_vm]; +if (bo) +xe_vm_bind_async (fd, __vm, bind_engines[e], bo, +0 , __addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, __vm, + bind_engines[e], +to_user_pointer (data), + __addr, bo_size, sync, +1 ); + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +igt_assert (syncobj_wait (fd, &syncobjs[e],1 , +INT64_MAX ,0 ,NULL )); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + } + } + +for (i =0 ; i < n_engines && n_execs; i++) +igt_assert (syncobj_wait (fd, &syncobjs[i],1 ,INT64_MAX ,0 , +NULL )); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 ,INT64_MAX ,0 ,NULL )); + + sync[0 ].flags |=DRM_XE_SYNC_SIGNAL ; +for (i =0 ; i < n_vm; ++i) { +syncobj_reset (fd, &sync[0 ].handle,1 ); +xe_vm_unbind_async (fd, vm[i], bind_engines[i],0 , addr[i], + bo_size, sync,1 ); +igt_assert (syncobj_wait (fd, &sync[0 ].handle,1 , +INT64_MAX ,0 ,NULL )); + } + +for (i = (flags &INVALIDATE && n_execs) ? n_execs -1 :0 ; + i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +syncobj_destroy (fd, sync[0 ].handle); +for (i =0 ; i < n_engines; i++) { +syncobj_destroy (fd, syncobjs[i]); +xe_engine_destroy (fd, engines[i]); +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +for (i =0 ; i < n_vm; ++i) +xe_vm_destroy (fd, vm[i]); +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"basic" ,0 }, + {"basic-defer-mmap" ,DEFER_ALLOC }, + {"basic-defer-bind" ,DEFER_ALLOC |DEFER_BIND }, + {"userptr" ,USERPTR }, + {"rebind" ,REBIND }, + {"userptr-rebind" ,USERPTR |REBIND }, + {"userptr-invalidate" ,USERPTR |INVALIDATE }, + {"userptr-invalidate-race" ,USERPTR |INVALIDATE |RACE }, + {"bindengine" ,BIND_ENGINE }, + {"bindengine-userptr" ,BIND_ENGINE |USERPTR }, + {"bindengine-rebind" ,BIND_ENGINE |REBIND }, + {"bindengine-userptr-rebind" ,BIND_ENGINE |USERPTR |REBIND }, + {"bindengine-userptr-invalidate" ,BIND_ENGINE |USERPTR | +INVALIDATE }, + {"bindengine-userptr-invalidate-race" ,BIND_ENGINE |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,1 ,1 , s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,2 ,1 , s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,1 , + s->flags); + + igt_subtest_f("many-engines-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,1 , + s->flags); + + igt_subtest_f("many-engines-many-vm-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :1024 ,16 , + s->flags); + + igt_subtest_f("no-exec-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,0 ,1 , s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_compute_mode.c new file +364
-0@@ -0,0 +1,364 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf compute machine functionality +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: compute machine +* Test category: functionality test +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define VM_FOR_BO (0x1 << 5) +#define ENGINE_EARLY (0x1 << 6) + +/** +* SUBTEST: twice-%s +* Description: Run %arg[1] compute machine test twice +* Run type: BAT +* +* SUBTEST: once-%s +* Description: Run %arg[1] compute machine test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] compute machine test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @basic: basic +* @preempt-fence-early: preempt fence early +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate race +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: bindengine userptr invalidate +* @bindengine-userptr-invalidate-race: bindengine-userptr invalidate race +*/ + +/** +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] compute machine test on many engines +* +* arg[1]: +* +* @basic: basic +* @preempt-fence-early: preempt fence early +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: bindengine userptr invalidate +*/ +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +int i, j, b; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_COMPUTE_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +for (i =0 ; (flags &ENGINE_EARLY ) && i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { + bo =xe_bo_create (fd, eci->gt_id, flags &VM_FOR_BO ? vm :0 , + bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; !(flags &ENGINE_EARLY ) && i < n_engines; i++) { +struct drm_xe_ext_engine_set_property ext = { + .base.next_extension =0 , + .base.name =XE_ENGINE_EXTENSION_SET_PROPERTY , + .property =XE_ENGINE_SET_PROPERTY_COMPUTE_MODE , + .value =1 , + }; + + engines[i] =xe_engine_create (fd, vm, eci, +to_user_pointer (&ext)); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[0 ], bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, bind_engines[0 ], +to_user_pointer (data), addr, + bo_size, sync,1 ); +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm, bind_engines[e],0 , + addr, bo_size,NULL ,0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[e], bo, +0 , addr, bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, + bind_engines[e], +to_user_pointer (data), + addr, bo_size, sync, +1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +if (flags &INVALIDATE && i +1 != n_execs) { +if (!(flags &RACE )) { +/* +* Wait for exec completion and check data as +* userptr will likely change to different +* physical memory on next mmap call triggering +* an invalidate. +*/ +xe_wait_ufence (fd, &data[i].exec_sync, +USER_FENCE_VALUE ,NULL ,ONE_SEC ); +igt_assert_eq (data[i].data,0xc0ffee ); + }else if (i *2 != n_execs) { +/* +* We issue 1 mmap which races against running +* jobs. No real check here aside from this test +* not faulting on the GPU. +*/ +continue ; + } + +if (flags &RACE ) { + map_fd =open ("/tmp" ,O_TMPFILE |O_RDWR , +0x666 ); +write (map_fd, data, bo_size); + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED , map_fd,0 ); + }else { + data =mmap ((void *)MAP_ADDRESS , bo_size, +PROT_READ |PROT_WRITE ,MAP_SHARED | +MAP_FIXED |MAP_ANONYMOUS ,-1 ,0 ); + } +igt_assert (data !=MAP_FAILED ); + } + } + + j = flags &INVALIDATE ? n_execs -1 :0 ; +for (i = j; i < n_execs; i++) +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + +/* Wait for all execs to complete */ +if (flags &INVALIDATE ) +usleep (250000 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +xe_vm_unbind_async (fd, vm, bind_engines[0 ],0 , addr, bo_size, + sync,1 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + +for (i = j; i < n_execs; i++) +igt_assert_eq (data[i].data,0xc0ffee ); + +for (i =0 ; i < n_engines; i++) { +xe_engine_destroy (fd, engines[i]); +if (bind_engines[i]) +xe_engine_destroy (fd, bind_engines[i]); + } + +if (bo) { +munmap (data, bo_size); +gem_close (fd, bo); + }else if (!(flags &INVALIDATE )) { +free (data); + } +xe_vm_destroy (fd, vm); +if (map_fd !=-1 ) +close (map_fd); +} + +igt_main +{ +struct drm_xe_engine_class_instance *hwe; +const struct section { +const char *name; +unsigned int flags; + } sections[] = { + {"basic" ,0 }, + {"preempt-fence-early" ,VM_FOR_BO |ENGINE_EARLY }, + {"userptr" ,USERPTR }, + {"rebind" ,REBIND }, + {"userptr-rebind" ,USERPTR |REBIND }, + {"userptr-invalidate" ,USERPTR |INVALIDATE }, + {"userptr-invalidate-race" ,USERPTR |INVALIDATE |RACE }, + {"bindengine" ,BIND_ENGINE }, + {"bindengine-userptr" ,BIND_ENGINE |USERPTR }, + {"bindengine-rebind" ,BIND_ENGINE |REBIND }, + {"bindengine-userptr-rebind" ,BIND_ENGINE |USERPTR | +REBIND }, + {"bindengine-userptr-invalidate" ,BIND_ENGINE |USERPTR | +INVALIDATE }, + {"bindengine-userptr-invalidate-race" ,BIND_ENGINE |USERPTR | +INVALIDATE |RACE }, + {NULL }, + }; +int fd; + + igt_fixture { + fd =drm_open_driver (DRIVER_XE ); +xe_device_get (fd); + } + +for (const struct section *s = sections; s->name; s++) { + igt_subtest_f("once-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,1 , s->flags); + + igt_subtest_f("twice-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 ,2 , s->flags); + + igt_subtest_f("many-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,1 , + s->flags & (REBIND |INVALIDATE ) ? +64 :128 , + s->flags); + +if (s->flags &RACE ) +continue ; + + igt_subtest_f("many-engines-%s", s->name) +for_each_hw_engine (fd, hwe) +test_exec (fd, hwe,16 , + s->flags & (REBIND |INVALIDATE ) ? +64 :128 , + s->flags); + } + + igt_fixture { +xe_device_put (fd); +close (fd); + } +}tests/xe/xe_exec_fault_mode.c new file +575
-0@@ -0,0 +1,575 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2021 Intel Corporation +*/ + +/** +* TEST: Basic tests for execbuf functionality for virtual and parallel engines +* Category: Hardware building block +* Sub-category: execbuf +* Functionality: fault mode +* Test category: functionality test +* GPU requirements: GPU needs support for DRM_XE_VM_CREATE_FAULT_MODE +*/ + +#include <fcntl.h> + +#include "igt.h" +#include "lib/igt_syncobj.h" +#include "lib/intel_reg.h" +#include "xe_drm.h" + +#include "xe/xe_ioctl.h" +#include "xe/xe_query.h" +#include <string.h> + +#define MAX_N_ENGINES 16 +#define USERPTR (0x1 << 0) +#define REBIND (0x1 << 1) +#define INVALIDATE (0x1 << 2) +#define RACE (0x1 << 3) +#define BIND_ENGINE (0x1 << 4) +#define WAIT_ATOMIC (0x1 << 5) +#define IMMEDIATE (0x1 << 6) +#define PREFETCH (0x1 << 7) +#define INVALID_FAULT (0x1 << 8) + +/** +* SUBTEST: once-%s +* Description: Run %arg[1] fault mode test only once +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: twice-%s +* Description: Run %arg[1] fault mode test twice +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-%s +* Description: Run %arg[1] fault mode test many times +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* SUBTEST: many-engines-%s +* Description: Run %arg[1] fault mode test on many engines +* Run type: FULL +* TODO: change ``'Run type' == FULL`` to a better category +* +* arg[1]: +* +* @basic: basic +* @userptr: userptr +* @rebind: rebind +* @userptr-rebind: userptr rebind +* @userptr-invalidate: userptr invalidate +* @userptr-invalidate-race: userptr invalidate race +* @bindengine: bindengine +* @bindengine-userptr: bindengine userptr +* @bindengine-rebind: bindengine rebind +* @bindengine-userptr-rebind: bindengine userptr rebind +* @bindengine-userptr-invalidate: +* bindengine userptr invalidate +* @bindengine-userptr-invalidate-race: +* bindengine userptr invalidate race +* @basic-imm: basic imm +* @userptr-imm: userptr imm +* @rebind-imm: rebind imm +* @userptr-rebind-imm: userptr rebind imm +* @userptr-invalidate-imm: userptr invalidate imm +* @userptr-invalidate-race-imm: userptr invalidate race imm +* @bindengine-imm: bindengine imm +* @bindengine-userptr-imm: bindengine userptr imm +* @bindengine-rebind-imm: bindengine rebind imm +* @bindengine-userptr-rebind-imm: +* bindengine userptr rebind imm +* @bindengine-userptr-invalidate-imm: +* bindengine userptr invalidate imm +* @bindengine-userptr-invalidate-race-imm: +* bindengine userptr invalidate race imm +* @basic-prefetch: basic prefetch +* @userptr-prefetch: userptr prefetch +* @rebind-prefetch: rebind prefetch +* @userptr-rebind-prefetch: userptr rebind prefetch +* @userptr-invalidate-prefetch: userptr invalidate prefetch +* @userptr-invalidate-race-prefetch: userptr invalidate race prefetch +* @bindengine-prefetch: bindengine prefetch +* @bindengine-userptr-prefetch: bindengine userptr prefetch +* @bindengine-rebind-prefetch: bindengine rebind prefetch +* @bindengine-userptr-rebind-prefetch: bindengine userptr rebind prefetch +* @bindengine-userptr-invalidate-prefetch: +* bindengine userptr invalidate prefetch +* @bindengine-userptr-invalidate-race-prefetch: +* bindengine userptr invalidate race prefetch +* @invalid-fault: invalid fault +* @invalid-userptr-fault: invalid userptr fault +*/ + +static void +test_exec (int fd,struct drm_xe_engine_class_instance *eci, +int n_engines,int n_execs,unsigned int flags) +{ +uint32_t vm; +uint64_t addr =0x1a0000 ; +#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull +struct drm_xe_sync sync[1 ] = { + { .flags =DRM_XE_SYNC_USER_FENCE |DRM_XE_SYNC_SIGNAL , + .timeline_value =USER_FENCE_VALUE }, + }; +struct drm_xe_exec exec = { + .num_batch_buffer =1 , + .num_syncs =1 , + .syncs =to_user_pointer (&sync), + }; +uint32_t engines[MAX_N_ENGINES ]; +uint32_t bind_engines[MAX_N_ENGINES ]; +size_t bo_size; +uint32_t bo =0 ; +struct { +uint32_t batch[16 ]; +uint64_t pad; +uint64_t vm_sync; +uint64_t exec_sync; +uint32_t data; + } *data; +int i, j, b; +int map_fd =-1 ; + +igt_assert (n_engines <=MAX_N_ENGINES ); + + vm =xe_vm_create (fd,DRM_XE_VM_CREATE_ASYNC_BIND_OPS | +DRM_XE_VM_CREATE_FAULT_MODE ,0 ); + bo_size =sizeof (*data) * n_execs; + bo_size =ALIGN (bo_size +xe_cs_prefetch_size (fd), +xe_get_default_alignment (fd)); + +if (flags &USERPTR ) { +#define MAP_ADDRESS 0x00007fadeadbe000 +if (flags &INVALIDATE ) { + data =mmap ((void *)MAP_ADDRESS , bo_size,PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_FIXED | +MAP_ANONYMOUS ,-1 ,0 ); +igt_assert (data !=MAP_FAILED ); + }else { + data =aligned_alloc (xe_get_default_alignment (fd), + bo_size); +igt_assert (data); + } + }else { +if (flags &PREFETCH ) + bo =xe_bo_create_flags (fd,0 , bo_size, +all_memory_regions (fd)); +else + bo =xe_bo_create (fd, eci->gt_id,0 , bo_size); + data =xe_bo_map (fd, bo, bo_size); + } +memset (data,0 , bo_size); + +for (i =0 ; i < n_engines; i++) { + engines[i] =xe_engine_create (fd, vm, eci,0 ); +if (flags &BIND_ENGINE ) + bind_engines[i] = +xe_bind_engine_create (fd, vm,0 ); +else + bind_engines[i] =0 ; + }; + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); +if (flags &IMMEDIATE ) { +if (bo) +xe_vm_bind_async_flags (fd, vm, bind_engines[0 ], bo,0 , + addr, bo_size, sync,1 , +XE_VM_BIND_FLAG_IMMEDIATE ); +else +xe_vm_bind_userptr_async_flags (fd, vm, bind_engines[0 ], +to_user_pointer (data), + addr, bo_size, sync,1 , +XE_VM_BIND_FLAG_IMMEDIATE ); + }else { +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[0 ], bo,0 , addr, + bo_size, sync,1 ); +else +xe_vm_bind_userptr_async (fd, vm, bind_engines[0 ], +to_user_pointer (data), addr, + bo_size, sync,1 ); + } + +#define ONE_SEC 1000 +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL ,ONE_SEC ); + data[0 ].vm_sync =0 ; + +if (flags &PREFETCH ) { +/* Should move to system memory */ +xe_vm_prefetch_async (fd, vm, bind_engines[0 ],0 , addr, + bo_size, sync,1 ,0 ); +xe_wait_ufence (fd, &data[0 ].vm_sync,USER_FENCE_VALUE ,NULL , +ONE_SEC ); + data[0 ].vm_sync =0 ; + } + +for (i =0 ; i < n_execs; i++) { +uint64_t batch_offset = (char *)&data[i].batch - (char *)data; +uint64_t batch_addr = addr + batch_offset; +uint64_t sdi_offset = (char *)&data[i].data - (char *)data; +uint64_t sdi_addr = addr + sdi_offset; +int e = i % n_engines; + + b =0 ; + data[i].batch[b++] =MI_STORE_DWORD_IMM ; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >>32 ; + data[i].batch[b++] =0xc0ffee ; + data[i].batch[b++] =MI_BATCH_BUFFER_END ; +igt_assert (b <=ARRAY_SIZE (data[i].batch)); + + sync[0 ].addr = addr + (char *)&data[i].exec_sync - (char *)data; + + exec.engine_id = engines[e]; + exec.address = batch_addr; +xe_exec (fd, &exec); + +if (flags &REBIND && i +1 != n_execs) { +xe_wait_ufence (fd, &data[i].exec_sync,USER_FENCE_VALUE , +NULL ,ONE_SEC ); +xe_vm_unbind_async (fd, vm, bind_engines[e],0 , + addr, bo_size,NULL ,0 ); + + sync[0 ].addr =to_user_pointer (&data[0 ].vm_sync); + addr += bo_size; +if (bo) +xe_vm_bind_async (fd, vm, bind_engines[e], bo, +0 , addr, bo_size, sync,1 ); +else Lines of this file are not shown. View the raw message.
tests/xe/xe_prime_self_import.c new file +489
-0Lines of this file are not shown. View the raw message.
tests/xe/xe_test_config.json new file +133
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.