[PATCH i-g-t 2/2] lib/xe: Abstract virtual/parallel setup
Matthew Brost
matthew.brost at intel.com
Fri Aug 16 18:40:37 UTC 2024
On Wed, Aug 14, 2024 at 10:50:13AM -0700, Lucas De Marchi wrote:
> Add 2 new functions, xe_gt_count_engines_by_class and
> xe_gt_fill_engines_by_class, that can be user as helpers to setup
> parallel/virtual exec queue. All the tests were basically looping
> and filtering engines that matched gt and class.
>
> Place these new functions in xe_util.c as currently we lack a better
> placement. xe_query.c and xe_gt.c could probably be other candidates,
> but they all mix all kind of namespaces too.
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
Reviewed-by: Matthew Brost <matthew.brost at intel.com>
> ---
> lib/xe/xe_util.c | 47 ++++++++++++++++++++++++++++++++++
> lib/xe/xe_util.h | 7 +++++
> tests/intel/xe_exec_balancer.c | 31 +++++-----------------
> tests/intel/xe_exec_reset.c | 11 +++-----
> tests/intel/xe_exec_threads.c | 30 +++++-----------------
> 5 files changed, 70 insertions(+), 56 deletions(-)
>
> diff --git a/lib/xe/xe_util.c b/lib/xe/xe_util.c
> index 050162b5e..9482819c2 100644
> --- a/lib/xe/xe_util.c
> +++ b/lib/xe/xe_util.c
> @@ -255,3 +255,50 @@ bool xe_is_gt_in_c6(int fd, int gt)
>
> return strcmp(gt_c_state, "gt-c6") == 0;
> }
> +
> +/**
> + * xe_gt_fill_engines_by_class:
> + * @fd: pointer to xe drm fd
> + * @gt: gt number
> + * @class: engine class to use to filter engines
> + * @eci: output argument to copy engines to
> + *
> + * Fill out @drm_xe_engine_class_instance with all the engines in @gt that have
> + * a certain @class.
> + *
> + * Return: number of engines that match the gt and clas
> + */
> +int xe_gt_fill_engines_by_class(int fd, int gt, int class,
> + struct drm_xe_engine_class_instance eci[static XE_MAX_ENGINE_INSTANCE])
> +{
> + struct drm_xe_engine_class_instance *hwe;
> + int n = 0;
> +
> + xe_for_each_engine(fd, hwe)
> + if (hwe->engine_class == class && hwe->gt_id == gt)
> + eci[n++] = *hwe;
> +
> + return n;
> +}
> +
> +/**
> + * xe_gt_count_engines_by_class:
> + * @fd: pointer to xe drm fd
> + * @gt: gt number
> + * @class: engine class to use to filter engines
> + *
> + * Count number of engines in @gt that have a certain @class.
> + *
> + * Return: number of engines that match the gt and clas
> + */
> +int xe_gt_count_engines_by_class(int fd, int gt, int class)
> +{
> + struct drm_xe_engine_class_instance *hwe;
> + int n = 0;
> +
> + xe_for_each_engine(fd, hwe)
> + if (hwe->engine_class == class && hwe->gt_id == gt)
> + n++;
> +
> + return n;
> +}
> diff --git a/lib/xe/xe_util.h b/lib/xe/xe_util.h
> index 6480ea01a..b9fbfc5cd 100644
> --- a/lib/xe/xe_util.h
> +++ b/lib/xe/xe_util.h
> @@ -12,6 +12,8 @@
> #include <stdint.h>
> #include <xe_drm.h>
>
> +#include "xe_query.h"
> +
> #define XE_IS_SYSMEM_MEMORY_REGION(fd, region) \
> (xe_region_class(fd, region) == DRM_XE_MEM_REGION_CLASS_SYSMEM)
> #define XE_IS_VRAM_MEMORY_REGION(fd, region) \
> @@ -47,4 +49,9 @@ void xe_bind_unbind_async(int fd, uint32_t vm, uint32_t bind_engine,
>
> bool xe_is_gt_in_c6(int fd, int gt);
>
> +int xe_gt_fill_engines_by_class(int fd, int gt, int class,
> + struct drm_xe_engine_class_instance eci[static XE_MAX_ENGINE_INSTANCE]);
> +int xe_gt_count_engines_by_class(int fd, int gt, int class);
> +
> +
> #endif /* XE_UTIL_H */
> diff --git a/tests/intel/xe_exec_balancer.c b/tests/intel/xe_exec_balancer.c
> index 53ea245a0..36dc56707 100644
> --- a/tests/intel/xe_exec_balancer.c
> +++ b/tests/intel/xe_exec_balancer.c
> @@ -22,6 +22,7 @@
> #include "xe/xe_ioctl.h"
> #include "xe/xe_query.h"
> #include "xe/xe_spin.h"
> +#include "xe/xe_util.h"
> #include <string.h>
>
> /**
> @@ -52,16 +53,10 @@ static void test_all_active(int fd, int gt, int class)
> struct xe_spin spin;
> } *data;
> struct xe_spin_opts spin_opts = { .preempt = false };
> - struct drm_xe_engine_class_instance *hwe;
> struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
> - int i, num_placements = 0;
> + int i, num_placements;
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class || hwe->gt_id != gt)
> - continue;
> -
> - eci[num_placements++] = *hwe;
> - }
> + num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
> if (num_placements < 2)
> return;
>
> @@ -184,18 +179,12 @@ test_exec(int fd, int gt, int class, int n_exec_queues, int n_execs,
> uint64_t pad;
> uint32_t data;
> } *data;
> - struct drm_xe_engine_class_instance *hwe;
> struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
> - int i, j, b, num_placements = 0;
> + int i, j, b, num_placements;
>
> igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class || hwe->gt_id != gt)
> - continue;
> -
> - eci[num_placements++] = *hwe;
> - }
> + num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
> if (num_placements < 2)
> return;
>
> @@ -403,19 +392,13 @@ test_cm(int fd, int gt, int class, int n_exec_queues, int n_execs,
> uint64_t exec_sync;
> uint32_t data;
> } *data;
> - struct drm_xe_engine_class_instance *hwe;
> struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
> - int i, j, b, num_placements = 0;
> + int i, j, b, num_placements;
> int map_fd = -1;
>
> igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class || hwe->gt_id != gt)
> - continue;
> -
> - eci[num_placements++] = *hwe;
> - }
> + num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
> if (num_placements < 2)
> return;
>
> diff --git a/tests/intel/xe_exec_reset.c b/tests/intel/xe_exec_reset.c
> index bcda78609..efb7f9e89 100644
> --- a/tests/intel/xe_exec_reset.c
> +++ b/tests/intel/xe_exec_reset.c
> @@ -20,6 +20,7 @@
> #include "xe/xe_ioctl.h"
> #include "xe/xe_query.h"
> #include "xe/xe_spin.h"
> +#include "xe/xe_util.h"
> #include <string.h>
>
> #define SYNC_OBJ_SIGNALED (0x1 << 0)
> @@ -162,21 +163,15 @@ test_balancer(int fd, int gt, int class, int n_exec_queues, int n_execs,
> uint32_t data;
> } *data;
> struct xe_spin_opts spin_opts = { .preempt = false };
> - struct drm_xe_engine_class_instance *hwe;
> struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
> - int i, j, b, num_placements = 0, bad_batches = 1;
> + int i, j, b, num_placements, bad_batches = 1;
>
> igt_assert_lte(n_exec_queues, MAX_N_EXECQUEUES);
>
> if (flags & CLOSE_FD)
> fd = drm_open_driver(DRIVER_XE);
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class || hwe->gt_id != gt)
> - continue;
> -
> - eci[num_placements++] = *hwe;
> - }
> + num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
> if (num_placements < 2)
> return;
>
> diff --git a/tests/intel/xe_exec_threads.c b/tests/intel/xe_exec_threads.c
> index 06452862e..6fdafdff5 100644
> --- a/tests/intel/xe_exec_threads.c
> +++ b/tests/intel/xe_exec_threads.c
> @@ -22,6 +22,7 @@
> #include "xe/xe_ioctl.h"
> #include "xe/xe_query.h"
> #include "xe/xe_spin.h"
> +#include "xe/xe_util.h"
> #include <string.h>
>
> #define MAX_N_EXEC_QUEUES 16
> @@ -64,9 +65,8 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
> uint64_t pad;
> uint32_t data;
> } *data;
> - struct drm_xe_engine_class_instance *hwe;
> struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
> - int i, j, b, num_placements = 0;
> + int i, j, b, num_placements;
> bool owns_vm = false, owns_fd = false;
>
> igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
> @@ -81,12 +81,7 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
> owns_vm = true;
> }
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class || hwe->gt_id != gt)
> - continue;
> -
> - eci[num_placements++] = *hwe;
> - }
> + num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
> igt_assert_lt(1, num_placements);
>
> bo_size = sizeof(*data) * n_execs;
> @@ -963,14 +958,7 @@ static void threads(int fd, int flags)
> if (flags & BALANCER) {
> xe_for_each_gt(fd, gt)
> xe_for_each_engine_class(class) {
> - int num_placements = 0;
> -
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class ||
> - hwe->gt_id != gt)
> - continue;
> - ++num_placements;
> - }
> + int num_placements = xe_gt_count_engines_by_class(fd, gt, class);
>
> if (num_placements > 1)
> n_engines += 2;
> @@ -1021,16 +1009,10 @@ static void threads(int fd, int flags)
> if (flags & BALANCER) {
> xe_for_each_gt(fd, gt)
> xe_for_each_engine_class(class) {
> - int num_placements = 0;
> + int num_placements;
> int *data_flags = (int[]){ VIRTUAL, PARALLEL, -1 };
>
> - xe_for_each_engine(fd, hwe) {
> - if (hwe->engine_class != class ||
> - hwe->gt_id != gt)
> - continue;
> - ++num_placements;
> - }
> -
> + num_placements = xe_gt_count_engines_by_class(fd, gt, class);
> if (num_placements <= 1)
> continue;
>
> --
> 2.43.0
>
More information about the igt-dev
mailing list