tests/v3d_perfmon: Fix V3D 7.1 regression and extend perfmon testing
v2 cover tests/v3d_perfmon: Fix V3D 7.1 regression and extend perfmon testing
This series extends the V3D perfmon coverage in two directions: it fixes an existing test that regressed on V3D 7.1 (Raspberry Pi 5), and it adds coverage for the new DRM_IOCTL_V3D_PERFMON_SET_GLOBAL ioctl plus companion counter-isolation tests.
PATCH 1 fixes create-perfmon-invalid-counters, which currently fails on V3D 7.1 because it hardcodes V3D_PERFCNT_NUM (only valid for V3D 4.2) instead of querying DRM_V3D_PARAM_MAX_PERF_COUNTERS as the UAPI prescribes.
PATCHES 2-4 are the plumbing for the new tests:
- sync the v3d UAPI header to expose DRM_IOCTL_V3D_PERFMON_SET_GLOBAL;
- extend igt_v3d_perfmon_get_values() so callers can read counter
values back into a caller-provided buffer;
- add a small helper to query the V3D hardware version, since counter IDs and other details differ between v4.2 and v7.1.
PATCH 5 adds the new test coverage:
- get-values-check-monotonically, which submits ten CL jobs in a row
and asserts the counter values grow strictly between reads;
- global-perfmon subtests covering input validation, single-perfmon semantics (EBUSY), implicit clear on perfmon destroy and on fd close, precedence over per-job perfmon (EAGAIN), and cross-fd accumulation;
- perfmon-counter-isolation and perfmon-counter-isolation-subsequent-cl, which verify that the driver's queue serialization keeps pending CSD or earlier-CL work from leaking into a perfmon window.
Tested on Raspberry Pi 4 (V3D 4.2) and Raspberry Pi 5 (V3D 7.1).
Best regards,
- Maíra
---
v1 -> v2: https://lore.kernel.org/igt-dev/[email protected]/T/
- [1/5, 2/5, 3/5, 4/5] Add Iago's R-b (Iago Toral)
- [5/5] Set out_sync only for the last job instead of setting it for all jobs (Iago Toral)
- [5/5] In "global-perfmon-valid-perfmon", also wait for the last to complete in the second submission (Iago Toral)
- [5/5] In "perfmon-counter-isolation-subsequent-cl", only wait for the second syncobj after we retrieve job1's values (Iago Toral)
- [5/5] Create two macros to define the number of CL and CSD jobs submitted
Maíra Canal (5):
tests/v3d_perfmon: Don't use the deprecated V3D_PERFCNT_NUM drm-uapi/v3d: Sync v3d UAPI
lib/v3d: Allow callers to retrieve perfmon counter values lib/v3d: Add helper to query the V3D hardware version tests/v3d_perfmon: Add global perfmon and counter isolation tests
include/drm-uapi/v3d_drm.h | 21 ++ lib/igt_v3d.c | 22 +- lib/igt_v3d.h | 3 +- tests/v3d/v3d_perfmon.c | 576 ++++++++++++++++++++++++++++++++++++- tests/v3d/v3d_submit_cl.c | 4 +- tests/v3d/v3d_submit_csd.c | 4 +- 6 files changed, 616 insertions(+), 14 deletions(-)
Signature · 1 line
2.54.0
PATCH v2 1/5 tests/v3d_perfmon: Don't use the deprecated V3D_PERFCNT_NUM
As described in the UAPI, one shouldn't use V3D_PERFCNT_NUM to retrieve the maximum number of performance counters, as this value is only valid for V3D 4.2. One should retrieve this parameter from the kernel using DRM_V3D_PARAM_MAX_PERF_COUNTERS.
Due to this inconsistency, the test "create-perfmon-invalid-counters" is currently failing in V3D 7.1 (Raspberry Pi 5).
Update the "create-perfmon-invalid-counters" test to the UAPI guideline by replacing V3D_PERFCNT_NUM with the value retrieved from DRM_IOCTL_V3D_GET_PARAM.
--- tests/v3d/v3d_perfmon.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
tests/v3d/v3d_perfmon.c +11 -1
@@ -37,8 +37,18 @@ int igt_main() igt_subtest("create-perfmon-invalid-counters") {struct drm_v3d_perfmon_create create = { .ncounters =1 , - .counters = {V3D_PERFCNT_NUM }, }; +uint32_t total_perfcnt_num; + + total_perfcnt_num =igt_v3d_get_param (fd,DRM_V3D_PARAM_MAX_PERF_COUNTERS ); +igt_assert (total_perfcnt_num || errno !=EINVAL ); + +/* Fallback if kernel < v6.11 */ +if (!total_perfcnt_num) + total_perfcnt_num =V3D_PERFCNT_NUM ; + + create.counters[0 ] = total_perfcnt_num; +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_CREATE , &create,EINVAL ); }
Signature · 1 line
2.54.0
PATCH v2 2/5 drm-uapi/v3d: Sync v3d UAPI
In reply to Maíra CanalUpdate the UAPI header to expose support to a new ioctl:DRM_IOCTL_V3D_PERFMON_SET_GLOBAL. Sync the v3d UAPI with Linux 7.0.
--- include/drm-uapi/v3d_drm.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
include/drm-uapi/v3d_drm.h +21 -0
@@ -43,6 +43,7 @@ extern "C" {#define DRM_V3D_PERFMON_GET_VALUES 0x0a#define DRM_V3D_SUBMIT_CPU 0x0b#define DRM_V3D_PERFMON_GET_COUNTER 0x0c +#define DRM_V3D_PERFMON_SET_GLOBAL 0x0d#define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl)#define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo)
@@ -61,6 +62,8 @@ extern "C" {#define DRM_IOCTL_V3D_SUBMIT_CPU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CPU, struct drm_v3d_submit_cpu)#define DRM_IOCTL_V3D_PERFMON_GET_COUNTER DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_COUNTER, \ struct drm_v3d_perfmon_get_counter) +#define DRM_IOCTL_V3D_PERFMON_SET_GLOBAL DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_PERFMON_SET_GLOBAL, \ + struct drm_v3d_perfmon_set_global)#define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01#define DRM_V3D_SUBMIT_EXTENSION 0x02
@@ -290,6 +293,9 @@ enum drm_v3d_param {DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT ,DRM_V3D_PARAM_SUPPORTS_CPU_QUEUE ,DRM_V3D_PARAM_MAX_PERF_COUNTERS , +DRM_V3D_PARAM_SUPPORTS_SUPER_PAGES , +DRM_V3D_PARAM_GLOBAL_RESET_COUNTER , + DRM_V3D_PARAM_CONTEXT_RESET_COUNTER, }; struct drm_v3d_get_param {
@@ -765,6 +771,21 @@ struct drm_v3d_perfmon_get_counter {__u8 reserved[7 ]; }; +#define DRM_V3D_PERFMON_CLEAR_GLOBAL 0x0001 + +/** +* struct drm_v3d_perfmon_set_global - ioctl to define a global performance +* monitor +* +* The global performance monitor will be used for all jobs. If a global +* performance monitor is defined, jobs with a self-defined performance +* monitor won't be allowed. +*/ +struct drm_v3d_perfmon_set_global { +__u32 flags; +__u32 id; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.54.0
Re: [PATCH i-g-t v2 2/5] drm-uapi/v3d: Sync v3d UAPI
Hi Maíra,
Quoted 5 lines · Maíra Canal
Update the UAPI header to expose support to a new ioctl:
DRM_IOCTL_V3D_PERFMON_SET_GLOBAL. Sync the v3d UAPI with Linux 7.0.Reviewed-by Iago Toral Quiroga <[email protected]>Signed-off-by Maíra Canal <[email protected]>
Can you write in commit description in what kernel commit from drm-next you synced? Something like seen in panthor
https://patchwork.freedesktop.org/patch/723725/?series=166234&rev=1
drm-uapi/panthor: sync with kernel 5731bca6a656
Sync Panthor drm uapi with drm-next up to commit 5731bca6a656, this will bring following changes:
commit 5731bca6a656 ("drm/panthor: Support sparse mappings")
commit a07a79ff4b51 ("drm/panthor: Delete spurious whitespace from uAPI header")
...
last commit with which it was synced.
So here:
Sync v3d upai with drm-next up to commit 769c153cfc3c, this will bring following changes:
769c153cfc3c ("drm/v3d: Add parameter to retrieve the number of GPU resets per-fd") 5774b3cfdedb ("drm/v3d: Add parameter to retrieve the global number of GPU resets") c6eabbab359c ("drm/v3d: Add DRM_IOCTL_V3D_PERFMON_SET_GLOBAL")
...
the only challange here is which is a last one to cite.
With this LGTM
Regards,
Kamil
Quoted 60 lines
--- include/drm-uapi/v3d_drm.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)include/drm-uapi/v3d_drm.h +21
-0@@ -43,6 +43,7 @@ extern "C" {#define DRM_V3D_PERFMON_GET_VALUES 0x0a#define DRM_V3D_SUBMIT_CPU 0x0b#define DRM_V3D_PERFMON_GET_COUNTER 0x0c +#define DRM_V3D_PERFMON_SET_GLOBAL 0x0d#define DRM_IOCTL_V3D_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CL, struct drm_v3d_submit_cl)#define DRM_IOCTL_V3D_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_WAIT_BO, struct drm_v3d_wait_bo)@@ -61,6 +62,8 @@ extern "C" {#define DRM_IOCTL_V3D_SUBMIT_CPU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CPU, struct drm_v3d_submit_cpu)#define DRM_IOCTL_V3D_PERFMON_GET_COUNTER DRM_IOWR(DRM_COMMAND_BASE + DRM_V3D_PERFMON_GET_COUNTER, \ struct drm_v3d_perfmon_get_counter) +#define DRM_IOCTL_V3D_PERFMON_SET_GLOBAL DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_PERFMON_SET_GLOBAL, \ + struct drm_v3d_perfmon_set_global)#define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01#define DRM_V3D_SUBMIT_EXTENSION 0x02@@ -290,6 +293,9 @@ enum drm_v3d_param {DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT ,DRM_V3D_PARAM_SUPPORTS_CPU_QUEUE ,DRM_V3D_PARAM_MAX_PERF_COUNTERS , +DRM_V3D_PARAM_SUPPORTS_SUPER_PAGES , +DRM_V3D_PARAM_GLOBAL_RESET_COUNTER , + DRM_V3D_PARAM_CONTEXT_RESET_COUNTER, }; struct drm_v3d_get_param {@@ -765,6 +771,21 @@ struct drm_v3d_perfmon_get_counter {__u8 reserved[7 ]; }; +#define DRM_V3D_PERFMON_CLEAR_GLOBAL 0x0001 + +/** +* struct drm_v3d_perfmon_set_global - ioctl to define a global performance +* monitor +* +* The global performance monitor will be used for all jobs. If a global +* performance monitor is defined, jobs with a self-defined performance +* monitor won't be allowed. +*/ +struct drm_v3d_perfmon_set_global { +__u32 flags; +__u32 id; +}; +#if defined(__cplusplus) }#endif Signature · 1 line
2.54.0
PATCH v2 3/5 lib/v3d: Allow callers to retrieve perfmon counter values
In reply to Maíra Canaligt_v3d_perfmon_get_values() previously allocated an internal buffer, issued the ioctl, and immediately freed the buffer, which made it only useful for exercising the ioctl path, but not for inspecting the results.
Add a values parameter so callers can supply their own allocated buffer and read back the counter values. When NULL is passed, the function allocates and frees a temporary buffer as before, preserving the existing behavior.
Update all callers in v3d tests to pass NULL, keeping their behavior unchanged.
--- lib/igt_v3d.c | 10 ++++++---- lib/igt_v3d.h | 2 +- tests/v3d/v3d_perfmon.c | 6 +++--- tests/v3d/v3d_submit_cl.c | 4 ++-- tests/v3d/v3d_submit_csd.c | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-)
lib/igt_v3d.c +6 -4
@@ -163,17 +163,19 @@ uint32_t igt_v3d_perfmon_create(int fd, uint32_t ncounters, uint8_t *counters)return create.id; } -void igt_v3d_perfmon_get_values (int fd,uint32_t id) +void igt_v3d_perfmon_get_values (int fd,uint32_t id,uint64_t *values) { -uint64_t *values =calloc (DRM_V3D_MAX_PERF_COUNTERS ,sizeof (*values)); +uint64_t *allocated_values = values ?: +calloc (DRM_V3D_MAX_PERF_COUNTERS ,sizeof (*allocated_values));struct drm_v3d_perfmon_get_values get = { .id = id, - .values_ptr =to_user_pointer (values) + .values_ptr =to_user_pointer (allocated_values), };do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_GET_VALUES , &get); -free (values); +if (!values) +free (allocated_values); }void igt_v3d_perfmon_destroy (int fd,uint32_t id)
lib/igt_v3d.h +1 -1
@@ -79,7 +79,7 @@ void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo);void igt_v3d_wait_bo (int fd,struct v3d_bo *bo,uint64_t timeout_ns);uint32_t igt_v3d_perfmon_create (int fd,uint32_t ncounters,uint8_t *counters); -void igt_v3d_perfmon_get_values (int fd,uint32_t id); +void igt_v3d_perfmon_get_values (int fd,uint32_t id,uint64_t *values);void igt_v3d_perfmon_destroy (int fd,uint32_t id);void igt_v3d_set_multisync (struct drm_v3d_multi_sync *ms,enum v3d_queue wait_stage);
tests/v3d/v3d_perfmon.c +3 -3
@@ -75,7 +75,7 @@ int igt_main()igt_v3d_perfmon_destroy (fd, id1);/* Make sure that the second perfmon it is still acessible */ -igt_v3d_perfmon_get_values (fd, id2); +igt_v3d_perfmon_get_values (fd, id2,NULL );igt_v3d_perfmon_destroy (fd, id2); }
@@ -120,7 +120,7 @@ int igt_main() V3D_PERFCNT_CLE_ACTIVE };uint32_t id =igt_v3d_perfmon_create (fd,3 , counters); -igt_v3d_perfmon_get_values (fd, id); +igt_v3d_perfmon_get_values (fd, id,NULL );igt_v3d_perfmon_destroy (fd, id); }
@@ -143,7 +143,7 @@ int igt_main() .id = id, }; -igt_v3d_perfmon_get_values (fd, id); +igt_v3d_perfmon_get_values (fd, id,NULL );igt_v3d_perfmon_destroy (fd, id);
tests/v3d/v3d_submit_cl.c +2 -2
@@ -367,11 +367,11 @@ int igt_main()do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit);igt_assert (syncobj_wait (fd, &job->submit->out_sync,1 ,INT64_MAX ,0 ,NULL )); -igt_v3d_perfmon_get_values (fd, job->submit->perfmon_id); +igt_v3d_perfmon_get_values (fd, job->submit->perfmon_id,NULL );igt_v3d_free_cl_job (fd, job); -igt_v3d_perfmon_get_values (fd, id); +igt_v3d_perfmon_get_values (fd, id,NULL );igt_v3d_perfmon_destroy (fd, id); }
tests/v3d/v3d_submit_csd.c +2 -2
@@ -351,11 +351,11 @@ int igt_main()do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CSD , job->submit);igt_assert (syncobj_wait (fd, &job->submit->out_sync,1 ,INT64_MAX ,0 ,NULL )); -igt_v3d_perfmon_get_values (fd, job->submit->perfmon_id); +igt_v3d_perfmon_get_values (fd, job->submit->perfmon_id,NULL );igt_v3d_free_csd_job (fd, job); -igt_v3d_perfmon_get_values (fd, id); +igt_v3d_perfmon_get_values (fd, id,NULL );igt_v3d_perfmon_destroy (fd, id); }
Signature · 1 line
2.54.0
PATCH v2 4/5 lib/v3d: Add helper to query the V3D hardware version
In reply to Maíra CanalAdd a helper to help tests to branch on the hardware version. Some HW configurations can change from v42 to v71, such as performance counter IDs, and this helper will assist tests to retrieve the HW version.
--- lib/igt_v3d.c | 12 ++++++++++++ lib/igt_v3d.h | 1 + 2 files changed, 13 insertions(+)
lib/igt_v3d.c +12 -0
@@ -114,6 +114,18 @@ igt_v3d_get_param(int fd, enum drm_v3d_param param)return get.value; } +uint32_t +igt_v3d_get_version (int fd) +{ +uint32_t ident0 =igt_v3d_get_param (fd,DRM_V3D_PARAM_V3D_CORE0_IDENT0 ); +uint32_t ident1 =igt_v3d_get_param (fd,DRM_V3D_PARAM_V3D_CORE0_IDENT1 ); + +uint32_t major = (ident0 >>24 ) &0xff ; +uint32_t minor = (ident1 >>0 ) &0xf ; + +return major *10 + minor; +} +void *igt_v3d_mmap_bo (int fd,uint32_t handle,uint32_t size,unsigned prot) {
lib/igt_v3d.h +1 -0
@@ -72,6 +72,7 @@ void igt_v3d_free_bo(int fd, struct v3d_bo *bo);/* IOCTL wrappers */ uint32_t igt_v3d_get_bo_offset (int fd,uint32_t handle);uint32_t igt_v3d_get_param (int fd,enum drm_v3d_param param); +uint32_t igt_v3d_get_version (int fd);void *igt_v3d_mmap_bo (int fd,uint32_t handle,uint32_t size,unsigned prot);void igt_v3d_bo_mmap (int fd,struct v3d_bo *bo);
Signature · 1 line
2.54.0
PATCH v2 5/5 tests/v3d_perfmon: Add global perfmon and counter isolation tests
In reply to Maíra CanalExercise the DRM_IOCTL_V3D_PERFMON_SET_GLOBAL ioctl with a set of subtests covering:
- Input validation: invalid flags, invalid perfmon id, and clearing a perfmon that was never set as global all return errors.
- Single-perfmon semantics: setting a second global perfmon while one is already active returns EBUSY.
- Implicit clear on destroy: destroying a global perfmon releases the slot, allowing a new one to be set without EBUSY.
- Precedence over per-job perfmon: submitting a CL job with a per-job perfmon_id while a global perfmon is active is rejected with EAGAIN.
- Cross-fd tracking: a global perfmon set on one file descriptor accumulates cycles from CL jobs submitted on a second file descriptor, and that second fd cannot install its own global perfmon while the first is active.
- fd close: closing a file descriptor that owns an active global perfmon clears it cleanly without crashing the driver.
Add two counter isolation subtests:
- perfmon-counter-isolation: blocks 100 CSD jobs behind a sw_sync fence, then submits a CL job with a perfmon. The driver's queue serialization must drain all pending CSD work before opening the perfmon window, so compute-active-cycles must read zero after the CL job completes.
- perfmon-counter-isolation-subsequent-cl: a non-perfmon CL job submitted after a perfmon CL job must be serialized behind it and must not contribute to its counter values.
Also add get-values-check-monotonically, which submits ten CL jobs in a loop and asserts that each get-values call returns strictly larger values than the previous one.
--- tests/v3d/v3d_perfmon.c | 558 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 557 insertions(+), 1 deletion(-)
tests/v3d/v3d_perfmon.c +557 -1
@@ -1,19 +1,28 @@// SPDX-License-Identifier: MIT /* * Copyright © 2022 Igalia S.L. +* Copyright © 2026 Raspberry Pi Ltd */ +#include <sys/ioctl.h> +#include "igt.h" +#include "igt_syncobj.h" #include "igt_v3d.h" +#include "sw_sync.h" + +#define V3D_PERFMON_NUM_CL_JOBS 10 +#define V3D_PERFMON_NUM_CSD_JOBS 100IGT_TEST_DESCRIPTION ("Tests for the V3D's performance monitors" );int igt_main () { -int fd; +int fd, ver; igt_fixture() { fd =drm_open_driver (DRIVER_V3D ); + ver =igt_v3d_get_version (fd);igt_require (igt_v3d_get_param (fd,DRM_V3D_PARAM_SUPPORTS_PERFMON )); }
@@ -124,6 +133,65 @@ int igt_main()igt_v3d_perfmon_destroy (fd, id); } +igt_describe ("Make sure the values returned by the perfmon are increasing monotonically." ); + igt_subtest("get-values-check-monotonically") { +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id, out_sync; +uint64_t *prev, *curr; +uint8_t counters[4 ]; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) { + counters[0 ] =3 ;/* CLE-bin-thread-active-cycles */ + counters[1 ] =64 ;/* PTB-memory-writes */ + counters[2 ] =66 ;/* core-memory-reads */ + counters[3 ] =71 ;/* PTB-memory-words-writes */ + }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CLE_ACTIVE ; + counters[1 ] =V3D_PERFCNT_PTB_MEM_WRITES ; + counters[2 ] =V3D_PERFCNT_CORE_MEM_READS ; + counters[3 ] =V3D_PERFCNT_PTB_W_MEM_WORDS ; + }else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + + prev =calloc (ARRAY_SIZE (counters),sizeof (*prev)); + curr =calloc (ARRAY_SIZE (counters),sizeof (*curr)); + +igt_v3d_perfmon_get_values (fd, id, prev); + +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (prev[i],0 ); + + out_sync =syncobj_create (fd,0 ); + job->submit->out_sync = out_sync; + job->submit->perfmon_id = id; + +/* Check if the counters are increasing monotonically. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id, curr); + +for (int j =0 ; j <ARRAY_SIZE (counters); j++) +igt_assert_lt (prev[j], curr[j]); + +igt_swap (prev, curr); + } + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); +igt_v3d_perfmon_destroy (fd, id); + +free (prev); +free (curr); + } +igt_describe ("Make sure that destroying a non-existent perfmon fails." ); igt_subtest("destroy-invalid-perfmon") {struct drm_v3d_perfmon_destroy destroy = {
@@ -151,6 +219,494 @@ int igt_main()do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_GET_VALUES , &get,EINVAL ); } +igt_describe ("Make sure that setting a global perfmon fails for an invalid flag." ); + igt_subtest("global-perfmon-invalid-flag") { +struct drm_v3d_perfmon_set_global set_global = { + .flags =0xdeadbeef , + }; +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + } + +igt_describe ("Make sure that setting a global perfmon fails for an invalid identifier." ); + igt_subtest("global-perfmon-invalid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = { + .id =0xdeadbeef , + }; +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + } + +igt_describe ("Make sure that clearing a valid identifier that it's not a global perfmon fails." ); + igt_subtest("global-perfmon-clear-unset-perfmon") { +uint8_t counters[] = {V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1 , +V3D_PERFCNT_TMU_CONFIG_ACCESSES , +V3D_PERFCNT_TLB_PARTIAL_QUADS , +V3D_PERFCNT_L2T_SLC0_READS }; +uint32_t id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +struct drm_v3d_perfmon_set_global set_global = { + .id = id, + .flags =DRM_V3D_PERFMON_CLEAR_GLOBAL , + }; + +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + +igt_v3d_perfmon_destroy (fd, id); + } + +igt_describe ("Make sure that the IOCTL fails when one sets a global perfmon, but one is already set." ); + igt_subtest("global-perfmon-set-valid-perfmon-twice") { +uint8_t counters[] = {V3D_PERFCNT_L2T_HITS ,V3D_PERFCNT_L2T_MISSES }; +uint32_t id1 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +uint32_t id2 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + +struct drm_v3d_perfmon_set_global set_global = { + .id = id1, + }; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + + set_global.id = id2; +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EBUSY ); + +igt_v3d_perfmon_destroy (fd, id1); +igt_v3d_perfmon_destroy (fd, id2); + } + +igt_describe ("Make sure that destroying a global perfmon clears it even without " +"DRM_V3D_PERFMON_CLEAR_GLOBAL." ); + igt_subtest("global-perfmon-destroy") { +uint8_t counters[] = {V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1 , +V3D_PERFCNT_L2T_SLC0_READS }; +uint32_t id1 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +uint32_t id2 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +struct drm_v3d_perfmon_set_global set_global = { .id = id1 }; + +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, id1); + +/* Returns success as global perfmon was cleared during destroy. */ + set_global.id = id2; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, id2); + } + +igt_describe ("Make sure that submitting a per-job perfmon is rejected when a " +"global perfmon is active, and that the global perfmon keeps tracking." ); + igt_subtest("global-perfmon-precedes-per-job") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id_global, id_job, out_sync; +uint64_t values; +uint8_t counter; +int ret; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id_global =igt_v3d_perfmon_create (fd,1 , &counter); + id_job =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = id_global; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +/* Submitting a per-job perfmon while a global one is active must +* be rejected: the global perfmon takes precedence. +*/ + job->submit->perfmon_id = id_job; + +/* Don't use drmIoctl(), as it restarts the ioctl if errno is EAGAIN. */ + ret =ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert_eq (ret,-1 ); +igt_assert_eq (errno,EAGAIN ); + +/* Submit a plain job (no per-job perfmon). */ + out_sync =syncobj_create (fd,0 ); + job->submit->perfmon_id =0 ; + job->submit->out_sync = out_sync; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +/* The global perfmon kept tracking. */ +igt_v3d_perfmon_get_values (fd, id_global, &values); +igt_assert_lt (0 , values); + +igt_v3d_perfmon_destroy (fd, id_global); +igt_v3d_perfmon_destroy (fd, id_job); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + +igt_describe ("Make sure that the global perfmon is tracking all jobs consistently." ); + igt_subtest("global-perfmon-valid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint64_t *values1, *values2; +uint32_t id, out_sync; +uint8_t counters[2 ]; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) { + counters[0 ] =0 ;/* cycle-count */ + counters[1 ] =1 ;/* core-active */ + }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CYCLE_COUNT ; + counters[1 ] =V3D_PERFCNT_CLE_ACTIVE ; + }else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + + values1 =calloc (ARRAY_SIZE (counters),sizeof (*values1)); + values2 =calloc (ARRAY_SIZE (counters),sizeof (*values2)); + + set_global.id = id; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Wait for the last job to complete so counters are captured. */ +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); +syncobj_destroy (fd, out_sync); + +igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon is active, the cycle-count must have +* increased with time. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_lt (values1[i], values2[i]); + + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Wait for the last job to complete so counters are captured. */ +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); +igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon was cleared, the perfmon is inactive +* and it must preserve its values. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (values1[i], values2[i]); + +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + +free (values1); +free (values2); + } + +igt_describe ("Make sure that a global perfmon tracks jobs from other file descriptors." ); + igt_subtest("global-perfmon-multifd") { +struct drm_v3d_perfmon_set_global set_global = {0 }, + set_global2 = {0 }; +int fd2 =drm_open_driver_render (DRIVER_V3D ); +struct v3d_cl_job *job =igt_v3d_noop_job (fd2); +uint32_t id1, id2, out_sync; +uint64_t values1, values2; +uint8_t counter; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + +/* Create and set global perfmon from fd. */ + id1 =igt_v3d_perfmon_create (fd,1 , &counter); + set_global.id = id1; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id1, &values1); + +/* Submit jobs from the second fd; the global perfmon should track them. */ + out_sync =syncobj_create (fd2,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd2,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +igt_assert (syncobj_wait (fd2, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id1, &values2); +igt_assert_lt (values1, values2); + +/* fd2 cannot set its own global perfmon while fd's is active. */ + id2 =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global2.id = id2; +do_ioctl_err (fd2,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global2,EBUSY ); + +igt_v3d_perfmon_destroy (fd2, id2); +igt_v3d_perfmon_destroy (fd, id1); + +syncobj_destroy (fd2, out_sync); +igt_v3d_free_cl_job (fd2, job); + +drm_close_driver (fd2); + } + +igt_describe ("Make sure closing a file descriptor with an active global " +"perfmon does not crash the driver." ); + igt_subtest("global-perfmon-destroy-multifd") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +int fd2 =drm_open_driver (DRIVER_V3D ); +uint32_t id, new_id, out_sync; +uint8_t counter =0 ; + +/* Create and set global perfmon from fd2. */ + id =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global.id = id; +do_ioctl (fd2,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +/* Keep HW busy from fd while fd2 is closed. */ + out_sync =syncobj_create (fd,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Closing fd2 must cleanly stop the active global perfmon and +* clear the global perfmon without crashing. +*/ +drm_close_driver (fd2); + +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +/* fd can now set a new global perfmon without EBUSY. */ + new_id =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = new_id; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, new_id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + +igt_describe ("Make sure a perfmon CL job is not contaminated by concurrent CSD " +"work on a different queue." ); + igt_subtest("perfmon-counter-isolation") { +struct v3d_csd_job *csd_job =igt_v3d_empty_shader (fd); +struct v3d_cl_job *cl_job =igt_v3d_noop_job (fd); +uint32_t id, blocker, cl_out; +int timeline, fence_fd; +uint8_t counter; +uint64_t values; + +igt_require_sw_sync (); + +/* +* compute-active-cycles is zero during pure CL work and non-zero +* while a CSD job is executing. Submitting CSD jobs alongside a +* perfmon CL job lets us distinguish "CSD ran while the perfmon +* window was open" (isolation broken) from "CSD finished before +* the perfmon window opened" (isolation correct). +*/ +if (ver >=71 ) + counter =4 ;/* compute-active-cycles */ +else if (ver >=42 ) + counter =V3D_PERFCNT_COMPUTE_ACTIVE ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. All CSD jobs will +* wait on this fence and stay queued until we increment the +* sw_sync timeline. +*/ + timeline =sw_sync_timeline_create (); + fence_fd =sw_sync_timeline_create_fence (timeline,1 ); + + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + cl_out =syncobj_create (fd,0 ); + +/* +* Block all CSD jobs with the unsignaled SW fence so they are +* still queued when the CL perfmon job is submitted. +*/ + csd_job->submit->in_sync = blocker; +for (int i =0 ; i <V3D_PERFMON_NUM_CSD_JOBS ; i++) +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CSD , csd_job->submit); + +/* +* Submit the CL job with the perfmon. v3d perfmon serialization +* must add a fence dependency on the CSD done fences so the CL +* job is forced to wait for all previous jobs to complete before +* its perfmon window opens. +*/ + cl_job->submit->out_sync = cl_out; + cl_job->submit->perfmon_id = id; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , cl_job->submit); + +/* +* With serialization, the CL job waits for all CSD work to finish +* first, so the perfmon sees only pure CL activity. Without it, +* the two queues would race and CSD cycles would pollute the counter. +*/ +sw_sync_timeline_inc (timeline,1 ); +igt_assert (syncobj_wait (fd, &cl_out,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id, &values); + +/* All CSD activity finished before the perfmon window opened, +* so no compute cycles must have been counted during the CL job. +*/ +igt_assert_eq (values,0 ); + +close (timeline); +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, cl_out); +igt_v3d_free_cl_job (fd, cl_job); +igt_v3d_free_csd_job (fd, csd_job); + } + +igt_describe ("Make sure a non-perfmon CL job submitted after a perfmon CL job " +"is serialized behind it and does not contaminate its counter values." ); + igt_subtest("perfmon-counter-isolation-subsequent-cl") { +struct v3d_cl_job *job1 =igt_v3d_noop_job (fd); +struct v3d_cl_job *job2 =igt_v3d_noop_job (fd); +uint64_t id, values, values_after_j2; +uint32_t blocker, out1, out2; +int timeline, fence_fd; +uint8_t counter; + +igt_require_sw_sync (); + +/* +* Different V3D versions have different performance counters IDs +* for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. job1 will wait on +* this fence and stay blocked until we increment the timeline. +*/ + timeline =sw_sync_timeline_create (); + fence_fd =sw_sync_timeline_create_fence (timeline,1 ); + + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + out1 =syncobj_create (fd,0 ); + out2 =syncobj_create (fd,0 ); + +/* job1: BIN job is blocked until we signal the blocker. */ + job1->submit->in_sync_bcl = blocker; + job1->submit->perfmon_id = id; + job1->submit->out_sync = out1; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job1->submit); + +/* job2: no perfmon, must wait for job1 due to job serialization. */ + job2->submit->out_sync = out2; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job2->submit); + +/* job2 is serialized behind job1, so it cannot have completed yet. */ +igt_assert_eq (syncobj_wait_err (fd, &out2,1 ,0 ,0 ), -ETIME ); + +/* While job1 has not started, the perfmon must still read zero. */ +igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_eq (values,0 ); + +/* Release the blocker. */ +sw_sync_timeline_inc (timeline,1 ); + +igt_assert (syncobj_wait (fd, &out1,1 ,INT64_MAX ,0 ,NULL )); + +/* job1 must have contributed cycles to the perfmon. */ +igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_lt (0 , values); + +igt_assert (syncobj_wait (fd, &out2,1 ,INT64_MAX ,0 ,NULL )); + +/* job2 doesn't have a perfmon attached, so a second read must +* return the same value. +*/ +igt_v3d_perfmon_get_values (fd, id, &values_after_j2); +igt_assert_eq (values, values_after_j2); + +close (timeline); +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, out1); +syncobj_destroy (fd, out2); + +igt_v3d_perfmon_destroy (fd, id); + +igt_v3d_free_cl_job (fd, job1); +igt_v3d_free_cl_job (fd, job2); + } + igt_fixture()drm_close_driver (fd); }
Signature · 1 line
2.54.0
Re: [PATCH i-g-t v2 5/5] tests/v3d_perfmon: Add global perfmon and counter isolation tests
Quoted 771 lines · Maíra Canal
Exercise the
DRM_IOCTL_V3D_PERFMON_SET_GLOBALioctl with a set of subtests covering:- Input validation: invalid flags, invalid perfmon id, and clearing a
perfmon that was never set as global all return errors.
- Single-perfmon semantics: setting a second global perfmon while one is
already active returns EBUSY.
- Implicit clear on destroy: destroying a global perfmon releases the
slot, allowing a new one to be set without EBUSY.
- Precedence over per-job perfmon: submitting a CL job with a per- job
perfmon_idwhile a global perfmon is active is rejected with EAGAIN.
- Cross-fd tracking: a global perfmon set on one file descriptor accumulates cycles from CL jobs submitted on a second file descriptor,
and that second fd cannot install its own global perfmon while the first is active.
- fd close: closing a file descriptor that owns an active global perfmon clears it cleanly without crashing the driver.Add two counter isolation subtests:
- perfmon-counter-isolation: blocks 100 CSD jobs behind a
sw_syncfence,
then submits a CL job with a perfmon. The driver's queue serialization
must drain all pending CSD work before opening the perfmon window, so
compute-active-cycles must read zero after the CL job completes.
- perfmon-counter-isolation-subsequent-cl: a non-perfmon CL job submitted
after a perfmon CL job must be serialized behind it and must not contribute to its counter values.Also add get-values-check-monotonically, which submits ten CL jobs in a
loop and asserts that each get-values call returns strictly larger values
than the previous one.Signed-off-by Maíra Canal <[email protected]>---
tests/v3d/v3d_perfmon.c | 558
+++++++++++++++++++++++++++++++++++++++-1 file changed, 557 insertions(+), 1 deletion(-)tests/v3d/v3d_perfmon.c +1
-0@@ -1,19 +1,28 @@ // SPDX-License-Identifier: MIT /** Copyright © 2022 Igalia S.L. +* Copyright © 2026 Raspberry Pi Ltd */ tests/v3d/v3d_perfmon.c +2
-0+#include <sys/ioctl.h> +#include "
igt.h"
+#include "igt_syncobj.h"
#include "igt_v3d.h"tests/v3d/v3d_perfmon.c +4
-0+#include "sw_sync.h" + +#define V3D_PERFMON_NUM_CL_JOBS 10 +#define V3D_PERFMON_NUM_CSD_JOBS 100
IGT_TEST_DESCRIPTION("Tests for the V3D's performance monitors");
intigt_main()
{tests/v3d/v3d_perfmon.c +1
-1-int fd; +int fd, ver;
igt_fixture(){
fd =drm_open_driver(DRIVER_V3D);tests/v3d/v3d_perfmon.c +1
-0+ ver =igt_v3d_get_version (fd);igt_require(igt_v3d_get_param(fd,
DRM_V3D_PARAM_SUPPORTS_PERFMON));
}tests/v3d/v3d_perfmon.c +0
-0@@ -124,6 +133,65 @@ int igt_main() igt_v3d_perfmon_destroy(fd, id); }tests/v3d/v3d_perfmon.c +1
-0+ igt_describe("Make sure the values returned by the perfmonare increasing monotonically.");
tests/v3d/v3d_perfmon.c +8
-0+ igt_subtest("get-values-check-monotonically") { +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id, out_sync; +uint64_t *prev, *curr; +uint8_t counters[4 ]; + +/* +* Different V3D versions have different performance counters
tests/v3d/v3d_perfmon.c +4
-0+* IDs for the same counters. +*/ +if (ver >=71 ) { + counters[0] = 3; /* CLE-bin-thread-active-cycles */
tests/v3d/v3d_perfmon.c +3
-0+ counters[1 ] =64 ;/* PTB-memory-writes */ + counters[2 ] =66 ;/* core-memory-reads */ + counters[3 ] =71 ;/* PTB-memory-words-writes */
tests/v3d/v3d_perfmon.c +7
-0+ }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CLE_ACTIVE ; + counters[1 ] =V3D_PERFCNT_PTB_MEM_WRITES ; + counters[2 ] =V3D_PERFCNT_CORE_MEM_READS ; + counters[3 ] =V3D_PERFCNT_PTB_W_MEM_WORDS ; + }else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +2
-0+ + id = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +14
-0+ + prev =calloc (ARRAY_SIZE (counters),sizeof (*prev)); + curr =calloc (ARRAY_SIZE (counters),sizeof (*curr)); + +igt_v3d_perfmon_get_values (fd, id, prev); + +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (prev[i],0 ); + + out_sync =syncobj_create (fd,0 ); + job->submit->out_sync = out_sync; + job->submit->perfmon_id = id; + +/* Check if the counters are increasing monotonically. */
tests/v3d/v3d_perfmon.c +2
-0+for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +1
-0+ igt_assert(syncobj_wait(fd, &out_sync, 1,
INT64_MAX, 0, NULL));tests/v3d/v3d_perfmon.c +4
-0+ +igt_v3d_perfmon_get_values (fd, id, curr); + + for (int j = 0; j < ARRAY_SIZE(counters);j++)
tests/v3d/v3d_perfmon.c +13
-0+igt_assert_lt (prev[j], curr[j]); + +igt_swap (prev, curr); + } + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); +igt_v3d_perfmon_destroy (fd, id); + +free (prev); +free (curr); + } +
igt_describe("Make sure that destroying a non-existent perfmon fails.");igt_subtest("destroy-invalid-perfmon"){ structdrm_v3d_perfmon_destroydestroy = {tests/v3d/v3d_perfmon.c +0
-0@@ -151,6 +219,494 @@ int igt_main() do_ioctl_err(fd, DRM_IOCTL_V3D_PERFMON_GET_VALUES, &get,EINVAL ); }tests/v3d/v3d_perfmon.c +1
-0+ igt_describe("Make sure that setting a global perfmon failsfor an invalid flag.");
tests/v3d/v3d_perfmon.c +5
-0+ igt_subtest("global-perfmon-invalid-flag") { +struct drm_v3d_perfmon_set_global set_global = { + .flags =0xdeadbeef , + }; + do_ioctl_err(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global, EINVAL);tests/v3d/v3d_perfmon.c +3
-0+ } + + igt_describe("Make sure that setting a global perfmon failsfor an invalid identifier.");
tests/v3d/v3d_perfmon.c +5
-0+ igt_subtest("global-perfmon-invalid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = { + .id =0xdeadbeef , + }; + do_ioctl_err(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global, EINVAL);tests/v3d/v3d_perfmon.c +3
-0+ } + + igt_describe("Make sure that clearing a valid identifierthat it's not a global perfmon fails.");
tests/v3d/v3d_perfmon.c +2
-0+ igt_subtest("global-perfmon-clear-unset-perfmon") { +uint8_t counters[] = {
V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1,tests/v3d/v3d_perfmon.c +1
-0+
V3D_PERFCNT_TMU_CONFIG_ACCESSES,tests/v3d/v3d_perfmon.c +1
-0+
V3D_PERFCNT_TLB_PARTIAL_QUADS,tests/v3d/v3d_perfmon.c +2
-0+ V3D_PERFCNT_L2T_SLC0_READS }; + uint32_t id = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +6
-0+struct drm_v3d_perfmon_set_global set_global = { + .id = id, + .flags =DRM_V3D_PERFMON_CLEAR_GLOBAL , + }; + + do_ioctl_err(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global, EINVAL);tests/v3d/v3d_perfmon.c +5
-0+ +igt_v3d_perfmon_destroy (fd, id); + } + + igt_describe("Make sure that the IOCTL fails when one sets aglobal perfmon, but one is already set.");
tests/v3d/v3d_perfmon.c +2
-0+ igt_subtest("global-perfmon-set-valid-perfmon-twice") { + uint8_t counters[] = { V3D_PERFCNT_L2T_HITS,
V3D_PERFCNT_L2T_MISSES};tests/v3d/v3d_perfmon.c +1
-0+ uint32_t id1 = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +1
-0+ uint32_t id2 = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +5
-0+ +struct drm_v3d_perfmon_set_global set_global = { + .id = id1, + }; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +3
-0+ + set_global.id = id2; + do_ioctl_err(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global, EBUSY);tests/v3d/v3d_perfmon.c +6
-0+ +igt_v3d_perfmon_destroy (fd, id1); +igt_v3d_perfmon_destroy (fd, id2); + } + + igt_describe("Make sure that destroying a global perfmonclears it even without "
tests/v3d/v3d_perfmon.c +3
-0+ "DRM_V3D_PERFMON_CLEAR_GLOBAL."); + igt_subtest("global-perfmon-destroy") { + uint8_t counters[] = {
V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1,tests/v3d/v3d_perfmon.c +2
-0+ V3D_PERFCNT_L2T_SLC0_READS }; + uint32_t id1 = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +1
-0+ uint32_t id2 = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +1
-0+ struct drm_v3d_perfmon_set_global set_global = { .id= id1 };
tests/v3d/v3d_perfmon.c +2
-0+ + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +4
-0+ +igt_v3d_perfmon_destroy (fd, id1); + +/* Returns success as global perfmon was cleared during destroy. */
tests/v3d/v3d_perfmon.c +2
-0+ set_global.id = id2; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +5
-0+ +igt_v3d_perfmon_destroy (fd, id2); + } + + igt_describe("Make sure that submitting a per-job perfmon isrejected when a "
tests/v3d/v3d_perfmon.c +1
-0+ "global perfmon is active, and that the globalperfmon keeps tracking.");
tests/v3d/v3d_perfmon.c +2
-0+ igt_subtest("global-perfmon-precedes-per-job") { +struct drm_v3d_perfmon_set_global set_global = {0 };
tests/v3d/v3d_perfmon.c +8
-0+struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id_global, id_job, out_sync; +uint64_t values; +uint8_t counter; +int ret; + +/* +* Different V3D versions have different performance counters
tests/v3d/v3d_perfmon.c +8
-0+* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +6
-0+ + id_global =igt_v3d_perfmon_create (fd,1 , &counter); + id_job =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = id_global; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +2
-0+ +/* Submitting a per-job perfmon while a global one is active must
tests/v3d/v3d_perfmon.c +5
-0+* be rejected: the global perfmon takes precedence. +*/ + job->submit->perfmon_id = id_job; + +/* Don't use drmIoctl(), as it restarts the ioctl if errno is EAGAIN. */
tests/v3d/v3d_perfmon.c +1
-0+ ret = ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +9
-0+igt_assert_eq (ret,-1 ); +igt_assert_eq (errno,EAGAIN ); + +/* Submit a plain job (no per-job perfmon). */ + out_sync =syncobj_create (fd,0 ); + job->submit->perfmon_id =0 ; + job->submit->out_sync = out_sync; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + igt_assert(syncobj_wait(fd, &out_sync, 1, INT64_MAX,0, NULL));
tests/v3d/v3d_perfmon.c +13
-0+ +/* The global perfmon kept tracking. */ +igt_v3d_perfmon_get_values (fd, id_global, &values); +igt_assert_lt (0 , values); + +igt_v3d_perfmon_destroy (fd, id_global); +igt_v3d_perfmon_destroy (fd, id_job); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + + igt_describe("Make sure that the global perfmon is trackingall jobs consistently.");
tests/v3d/v3d_perfmon.c +2
-0+ igt_subtest("global-perfmon-valid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = {0 };
tests/v3d/v3d_perfmon.c +7
-0+struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint64_t *values1, *values2; +uint32_t id, out_sync; +uint8_t counters[2 ]; + +/* +* Different V3D versions have different performance counters
tests/v3d/v3d_perfmon.c +10
-0+* IDs for the same counters. +*/ +if (ver >=71 ) { + counters[0 ] =0 ;/* cycle-count */ + counters[1 ] =1 ;/* core-active */ + }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CYCLE_COUNT ; + counters[1 ] =V3D_PERFCNT_CLE_ACTIVE ; + }else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +2
-0+ + id = igt_v3d_perfmon_create(fd,
ARRAY_SIZE(counters), counters);tests/v3d/v3d_perfmon.c +2
-0+ + values1 = calloc(ARRAY_SIZE(counters),
sizeof(*values1));tests/v3d/v3d_perfmon.c +1
-0+ values2 = calloc(ARRAY_SIZE(counters),
sizeof(*values2));tests/v3d/v3d_perfmon.c +3
-0+ + set_global.id = id; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +6
-0+ +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */
tests/v3d/v3d_perfmon.c +6
-0+for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +3
-0+ } + +/* Wait for the last job to complete so counters are captured. */
tests/v3d/v3d_perfmon.c +1
-0+ igt_assert(syncobj_wait(fd, &out_sync, 1, INT64_MAX,0, NULL));
tests/v3d/v3d_perfmon.c +5
-0+syncobj_destroy (fd, out_sync); + +igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon is active, the cycle-count must have
tests/v3d/v3d_perfmon.c +7
-0+* increased with time. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_lt (values1[i], values2[i]); + + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +6
-0+ +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */
tests/v3d/v3d_perfmon.c +6
-0+for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +3
-0+ } + +/* Wait for the last job to complete so counters are captured. */
tests/v3d/v3d_perfmon.c +1
-0+ igt_assert(syncobj_wait(fd, &out_sync, 1, INT64_MAX,0, NULL));
tests/v3d/v3d_perfmon.c +3
-0+igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon was cleared, the perfmon is inactive
tests/v3d/v3d_perfmon.c +15
-0+* and it must preserve its values. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (values1[i], values2[i]); + +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + +free (values1); +free (values2); + } + + igt_describe("Make sure that a global perfmon tracks jobsfrom other file descriptors.");
tests/v3d/v3d_perfmon.c +2
-0+ igt_subtest("global-perfmon-multifd") { +struct drm_v3d_perfmon_set_global set_global = {0 },
tests/v3d/v3d_perfmon.c +1
-0+ set_global2 = { 0};
tests/v3d/v3d_perfmon.c +8
-0+int fd2 =drm_open_driver_render (DRIVER_V3D ); +struct v3d_cl_job *job =igt_v3d_noop_job (fd2); +uint32_t id1, id2, out_sync; +uint64_t values1, values2; +uint8_t counter; + +/* +* Different V3D versions have different performance counters
tests/v3d/v3d_perfmon.c +8
-0+* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +5
-0+ +/* Create and set global perfmon from fd. */ + id1 =igt_v3d_perfmon_create (fd,1 , &counter); + set_global.id = id1; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +4
-0+ +igt_v3d_perfmon_get_values (fd, id1, &values1); + +/* Submit jobs from the second fd; the global perfmon should track them. */
tests/v3d/v3d_perfmon.c +8
-0+ out_sync =syncobj_create (fd2,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + + do_ioctl(fd2, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +3
-0+ } + + igt_assert(syncobj_wait(fd2, &out_sync, 1,
INT64_MAX, 0, NULL));tests/v3d/v3d_perfmon.c +5
-0+ +igt_v3d_perfmon_get_values (fd, id1, &values2); +igt_assert_lt (values1, values2); + +/* fd2 cannot set its own global perfmon while fd's is active. */
tests/v3d/v3d_perfmon.c +3
-0+ id2 =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global2.id = id2; + do_ioctl_err(fd2, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global2, EBUSY);tests/v3d/v3d_perfmon.c +11
-0+ +igt_v3d_perfmon_destroy (fd2, id2); +igt_v3d_perfmon_destroy (fd, id1); + +syncobj_destroy (fd2, out_sync); +igt_v3d_free_cl_job (fd2, job); + +drm_close_driver (fd2); + } + + igt_describe("Make sure closing a file descriptor with anactive global "
tests/v3d/v3d_perfmon.c +3
-0+ "perfmon does not crash the driver."); + igt_subtest("global-perfmon-destroy-multifd") { + struct drm_v3d_perfmon_set_global set_global = { 0};
tests/v3d/v3d_perfmon.c +9
-0+struct v3d_cl_job *job =igt_v3d_noop_job (fd); +int fd2 =drm_open_driver (DRIVER_V3D ); +uint32_t id, new_id, out_sync; +uint8_t counter =0 ; + +/* Create and set global perfmon from fd2. */ + id =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global.id = id; + do_ioctl(fd2, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +10
-0+ +/* Keep HW busy from fd while fd2 is closed. */ + out_sync =syncobj_create (fd,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +3
-0+ } + +/* Closing fd2 must cleanly stop the active global perfmon and
tests/v3d/v3d_perfmon.c +5
-0+* clear the global perfmon without crashing. +*/ +drm_close_driver (fd2); + + igt_assert(syncobj_wait(fd, &out_sync, 1, INT64_MAX,0, NULL));
tests/v3d/v3d_perfmon.c +2
-0+ +/* fd can now set a new global perfmon without EBUSY. */
tests/v3d/v3d_perfmon.c +4
-0+ new_id =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = new_id; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +3
-0+ + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; + do_ioctl(fd, DRM_IOCTL_V3D_PERFMON_SET_GLOBAL,
&set_global);tests/v3d/v3d_perfmon.c +8
-0+ +igt_v3d_perfmon_destroy (fd, new_id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + + igt_describe("Make sure a perfmon CL job is not contaminatedby concurrent CSD "
tests/v3d/v3d_perfmon.c +3
-0+ "work on a different queue."); + igt_subtest("perfmon-counter-isolation") { + struct v3d_csd_job *csd_job =
igt_v3d_empty_shader(fd);tests/v3d/v3d_perfmon.c +10
-0+struct v3d_cl_job *cl_job =igt_v3d_noop_job (fd); +uint32_t id, blocker, cl_out; +int timeline, fence_fd; +uint8_t counter; +uint64_t values; + +igt_require_sw_sync (); + +/* +* compute-active-cycles is zero during pure CL work and non-zero
tests/v3d/v3d_perfmon.c +1
-0+* while a CSD job is executing. Submitting CSD jobs alongside a
tests/v3d/v3d_perfmon.c +1
-0+* perfmon CL job lets us distinguish "CSD ran while the perfmon
tests/v3d/v3d_perfmon.c +1
-0+* window was open" (isolation broken) from "CSD finished before
tests/v3d/v3d_perfmon.c +8
-0+* the perfmon window opened" (isolation correct). +*/ +if (ver >=71 ) + counter =4 ;/* compute-active-cycles */ +else if (ver >=42 ) + counter =V3D_PERFCNT_COMPUTE_ACTIVE ; +else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +5
-0+ + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. All CSD jobs will
tests/v3d/v3d_perfmon.c +1
-0+* wait on this fence and stay queued until we increment the
tests/v3d/v3d_perfmon.c +4
-0+* sw_sync timeline. +*/ + timeline =sw_sync_timeline_create (); + fence_fd = sw_sync_timeline_create_fence(timeline,1);
tests/v3d/v3d_perfmon.c +9
-0+ + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + cl_out =syncobj_create (fd,0 ); + +/* +* Block all CSD jobs with the unsignaled SW fence so they are
tests/v3d/v3d_perfmon.c +1
-0+* still queued when the CL perfmon job is submitted.
tests/v3d/v3d_perfmon.c +4
-0+*/ + csd_job->submit->in_sync = blocker; +for (int i =0 ; i <V3D_PERFMON_NUM_CSD_JOBS ; i++) + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CSD,
csd_job->submit);tests/v3d/v3d_perfmon.c +3
-0+ +/* +* Submit the CL job with the perfmon. v3d perfmon serialization
tests/v3d/v3d_perfmon.c +1
-0+* must add a fence dependency on the CSD done fences so the CL
tests/v3d/v3d_perfmon.c +1
-0+* job is forced to wait for all previous jobs to complete before
tests/v3d/v3d_perfmon.c +5
-0+* its perfmon window opens. +*/ + cl_job->submit->out_sync = cl_out; + cl_job->submit->perfmon_id = id; + do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, cl_job-Quoted 1 line
submit);
tests/v3d/v3d_perfmon.c +3
-0+ +/* +* With serialization, the CL job waits for all CSD work to finish
tests/v3d/v3d_perfmon.c +1
-0+* first, so the perfmon sees only pure CL activity. Without it,
tests/v3d/v3d_perfmon.c +1
-0+* the two queues would race and CSD cycles would pollute the counter.
tests/v3d/v3d_perfmon.c +3
-0+*/ +sw_sync_timeline_inc (timeline,1 ); + igt_assert(syncobj_wait(fd, &cl_out, 1, INT64_MAX,0, NULL));
tests/v3d/v3d_perfmon.c +4
-0+ +igt_v3d_perfmon_get_values (fd, id, &values); + +/* All CSD activity finished before the perfmon window opened,
tests/v3d/v3d_perfmon.c +1
-0+* so no compute cycles must have been counted during the CL job.
tests/v3d/v3d_perfmon.c +13
-0+*/ +igt_assert_eq (values,0 ); + +close (timeline); +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, cl_out); +igt_v3d_free_cl_job (fd, cl_job); +igt_v3d_free_csd_job (fd, csd_job); + } + + igt_describe("Make sure a non-perfmon CL job submitted aftera perfmon CL job "
tests/v3d/v3d_perfmon.c +1
-0+ "is serialized behind it and does notcontaminate its counter values.");
tests/v3d/v3d_perfmon.c +12
-0+ igt_subtest("perfmon-counter-isolation-subsequent-cl") { +struct v3d_cl_job *job1 =igt_v3d_noop_job (fd); +struct v3d_cl_job *job2 =igt_v3d_noop_job (fd); +uint64_t id, values, values_after_j2; +uint32_t blocker, out1, out2; +int timeline, fence_fd; +uint8_t counter; + +igt_require_sw_sync (); + +/* +* Different V3D versions have different performance counters IDs
tests/v3d/v3d_perfmon.c +8
-0+* for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else + igt_abort_on_f(true, "This V3D version isnot supported.");
tests/v3d/v3d_perfmon.c +5
-0+ + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. job1 will wait on
tests/v3d/v3d_perfmon.c +1
-0+* this fence and stay blocked until we increment the timeline.
tests/v3d/v3d_perfmon.c +3
-0+*/ + timeline =sw_sync_timeline_create (); + fence_fd = sw_sync_timeline_create_fence(timeline,1);
tests/v3d/v3d_perfmon.c +9
-0+ + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + out1 =syncobj_create (fd,0 ); + out2 =syncobj_create (fd,0 ); + +/* job1: BIN job is blocked until we signal the blocker. */
tests/v3d/v3d_perfmon.c +6
-0+ job1->submit->in_sync_bcl = blocker; + job1->submit->perfmon_id = id; + job1->submit->out_sync = out1; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job1->submit); + +/* job2: no perfmon, must wait for job1 due to job serialization. */
tests/v3d/v3d_perfmon.c +4
-0+ job2->submit->out_sync = out2; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job2->submit); + +/* job2 is serialized behind job1, so it cannot have completed yet. */
tests/v3d/v3d_perfmon.c +3
-1+ igt_assert_eq(syncobj_wait_err(fd, &out2, 1, 0, 0), -ETIME); + +/* While job1 has not started, the perfmon must still read zero. */
tests/v3d/v3d_perfmon.c +7
-0+igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_eq (values,0 ); + +/* Release the blocker. */ +sw_sync_timeline_inc (timeline,1 ); + + igt_assert(syncobj_wait(fd, &out1, 1, INT64_MAX, 0,NULL));
tests/v3d/v3d_perfmon.c +2
-0+ +/* job1 must have contributed cycles to the perfmon. */
tests/v3d/v3d_perfmon.c +4
-0+igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_lt (0 , values); + + igt_assert(syncobj_wait(fd, &out2, 1, INT64_MAX, 0,NULL));
tests/v3d/v3d_perfmon.c +2
-0+ +/* job2 doesn't have a perfmon attached, so a second read must
tests/v3d/v3d_perfmon.c +3
-0+* return the same value. +*/ + igt_v3d_perfmon_get_values(fd, id,
&values_after_j2);tests/v3d/v3d_perfmon.c +13
-0+igt_assert_eq (values, values_after_j2); + +close (timeline); +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, out1); +syncobj_destroy (fd, out2); + +igt_v3d_perfmon_destroy (fd, id); + +igt_v3d_free_cl_job (fd, job1); +igt_v3d_free_cl_job (fd, job2); + } +
igt_fixture()
drm_close_driver(fd);
}
Re: [PATCH i-g-t v2 5/5] tests/v3d_perfmon: Add global perfmon and counter isolation tests
In reply to Maíra CanalHi Maíra,
Quoted 28 lines · Maíra Canal
Exercise the
DRM_IOCTL_V3D_PERFMON_SET_GLOBALioctl with a set of subtests covering:- Input validation: invalid flags, invalid perfmon id, and clearing a perfmon that was never set as global all return errors.
- Single-perfmon semantics: setting a second global perfmon while one is already active returns EBUSY.
- Implicit clear on destroy: destroying a global perfmon releases the slot, allowing a new one to be set without EBUSY.
- Precedence over per-job perfmon: submitting a CL job with a per-jobperfmon_idwhile a global perfmon is active is rejected with EAGAIN.
- Cross-fd tracking: a global perfmon set on one file descriptor accumulates cycles from CL jobs submitted on a second file descriptor, and that second fd cannot install its own global perfmon while the first is active.
- fd close: closing a file descriptor that owns an active global perfmon clears it cleanly without crashing the driver.Add two counter isolation subtests:
- perfmon-counter-isolation: blocks 100 CSD jobs behind a
sw_syncfence, then submits a CL job with a perfmon. The driver's queue serialization must drain all pending CSD work before opening the perfmon window, so compute-active-cycles must read zero after the CL job completes.
- perfmon-counter-isolation-subsequent-cl: a non-perfmon CL job submitted after a perfmon CL job must be serialized behind it and must not contribute to its counter values.
Quoted 3 lines
Also add get-values-check-monotonically, which submits ten CL jobs in a loop and asserts that each get-values call returns strictly larger values than the previous one.
Few style nits, see below.
Quoted 56 lines
Signed-off-by Maíra Canal <[email protected]>--- tests/v3d/v3d_perfmon.c | 558 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 557 insertions(+), 1 deletion(-)tests/v3d/v3d_perfmon.c +22
-1@@ -1,19 +1,28 @@// SPDX-License-Identifier: MIT /* * Copyright © 2022 Igalia S.L. +* Copyright © 2026 Raspberry Pi Ltd */ +#include <sys/ioctl.h> +#include "igt.h" +#include "igt_syncobj.h" #include "igt_v3d.h" +#include "sw_sync.h" + +#define V3D_PERFMON_NUM_CL_JOBS 10 +#define V3D_PERFMON_NUM_CSD_JOBS 100IGT_TEST_DESCRIPTION ("Tests for the V3D's performance monitors" );int igt_main () { -int fd; +int fd, ver; igt_fixture() { fd =drm_open_driver (DRIVER_V3D ); + ver =igt_v3d_get_version (fd);igt_require (igt_v3d_get_param (fd,DRM_V3D_PARAM_SUPPORTS_PERFMON )); }@@ -124,6 +133,65 @@ int igt_main()igt_v3d_perfmon_destroy (fd, id); } +igt_describe ("Make sure the values returned by the perfmon are increasing monotonically." ); + igt_subtest("get-values-check-monotonically") { +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id, out_sync; +uint64_t *prev, *curr; +uint8_t counters[4 ]; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) {
tests/v3d/v3d_perfmon.c int igt_main() · line 157
Quoted 10 lines
tests/v3d/v3d_perfmon.c +10
-0+ counters[0 ] =3 ;/* CLE-bin-thread-active-cycles */ + counters[1 ] =64 ;/* PTB-memory-writes */ + counters[2 ] =66 ;/* core-memory-reads */ + counters[3 ] =71 ;/* PTB-memory-words-writes */ + }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CLE_ACTIVE ; + counters[1 ] =V3D_PERFCNT_PTB_MEM_WRITES ; + counters[2 ] =V3D_PERFCNT_CORE_MEM_READS ; + counters[3 ] =V3D_PERFCNT_PTB_W_MEM_WORDS ; + }else
Use braces here:
} else {tests/v3d/v3d_perfmon.c int igt_main() · line 158
Quoted 1 line
tests/v3d/v3d_perfmon.c +1
-0+igt_abort_on_f (true,"This V3D version is not supported." );
and close it here.
Quoted 40 lines
tests/v3d/v3d_perfmon.c +36
-0+ + id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + + prev =calloc (ARRAY_SIZE (counters),sizeof (*prev)); + curr =calloc (ARRAY_SIZE (counters),sizeof (*curr)); + +igt_v3d_perfmon_get_values (fd, id, prev); + +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (prev[i],0 ); + + out_sync =syncobj_create (fd,0 ); + job->submit->out_sync = out_sync; + job->submit->perfmon_id = id; + +/* Check if the counters are increasing monotonically. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id, curr); + +for (int j =0 ; j <ARRAY_SIZE (counters); j++) +igt_assert_lt (prev[j], curr[j]); + +igt_swap (prev, curr); + } + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); +igt_v3d_perfmon_destroy (fd, id); + +free (prev); +free (curr); + } +igt_describe ("Make sure that destroying a non-existent perfmon fails." ); igt_subtest("destroy-invalid-perfmon") {struct drm_v3d_perfmon_destroy destroy = {
tests/v3d/v3d_perfmon.c int igt_main() · line 226
Quoted 8 lines
tests/v3d/v3d_perfmon.c +5
-0@@ -151,6 +219,494 @@ int igt_main()do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_GET_VALUES , &get,EINVAL ); } +igt_describe ("Make sure that setting a global perfmon fails for an invalid flag." ); + igt_subtest("global-perfmon-invalid-flag") { +struct drm_v3d_perfmon_set_global set_global = { + .flags =0xdeadbeef , + };
Add newline.
tests/v3d/v3d_perfmon.c int igt_main() · line 234
Quoted 8 lines
tests/v3d/v3d_perfmon.c +8
-0+do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + } + +igt_describe ("Make sure that setting a global perfmon fails for an invalid identifier." ); + igt_subtest("global-perfmon-invalid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = { + .id =0xdeadbeef , + };
Add newline.
Quoted 19 lines
tests/v3d/v3d_perfmon.c +19
-0+do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + } + +igt_describe ("Make sure that clearing a valid identifier that it's not a global perfmon fails." ); + igt_subtest("global-perfmon-clear-unset-perfmon") { +uint8_t counters[] = {V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1 , +V3D_PERFCNT_TMU_CONFIG_ACCESSES , +V3D_PERFCNT_TLB_PARTIAL_QUADS , +V3D_PERFCNT_L2T_SLC0_READS }; +uint32_t id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +struct drm_v3d_perfmon_set_global set_global = { + .id = id, + .flags =DRM_V3D_PERFMON_CLEAR_GLOBAL , + }; + +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EINVAL ); + +igt_v3d_perfmon_destroy (fd, id); + }
tests/v3d/v3d_perfmon.c int igt_main() · line 263
Quoted 10 lines
tests/v3d/v3d_perfmon.c +10
-0+ +igt_describe ("Make sure that the IOCTL fails when one sets a global perfmon, but one is already set." ); + igt_subtest("global-perfmon-set-valid-perfmon-twice") { +uint8_t counters[] = {V3D_PERFCNT_L2T_HITS ,V3D_PERFCNT_L2T_MISSES }; +uint32_t id1 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +uint32_t id2 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + +struct drm_v3d_perfmon_set_global set_global = { + .id = id1, + };
Add newline.
Quoted 93 lines
tests/v3d/v3d_perfmon.c +93
-0+do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + + set_global.id = id2; +do_ioctl_err (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global,EBUSY ); + +igt_v3d_perfmon_destroy (fd, id1); +igt_v3d_perfmon_destroy (fd, id2); + } + +igt_describe ("Make sure that destroying a global perfmon clears it even without " +"DRM_V3D_PERFMON_CLEAR_GLOBAL." ); + igt_subtest("global-perfmon-destroy") { +uint8_t counters[] = {V3D_PERFCNT_AXI_WRITE_STALLS_WATCH_1 , +V3D_PERFCNT_L2T_SLC0_READS }; +uint32_t id1 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +uint32_t id2 =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); +struct drm_v3d_perfmon_set_global set_global = { .id = id1 }; + +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, id1); + +/* Returns success as global perfmon was cleared during destroy. */ + set_global.id = id2; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, id2); + } + +igt_describe ("Make sure that submitting a per-job perfmon is rejected when a " +"global perfmon is active, and that the global perfmon keeps tracking." ); + igt_subtest("global-perfmon-precedes-per-job") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint32_t id_global, id_job, out_sync; +uint64_t values; +uint8_t counter; +int ret; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id_global =igt_v3d_perfmon_create (fd,1 , &counter); + id_job =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = id_global; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +/* Submitting a per-job perfmon while a global one is active must +* be rejected: the global perfmon takes precedence. +*/ + job->submit->perfmon_id = id_job; + +/* Don't use drmIoctl(), as it restarts the ioctl if errno is EAGAIN. */ + ret =ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert_eq (ret,-1 ); +igt_assert_eq (errno,EAGAIN ); + +/* Submit a plain job (no per-job perfmon). */ + out_sync =syncobj_create (fd,0 ); + job->submit->perfmon_id =0 ; + job->submit->out_sync = out_sync; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +/* The global perfmon kept tracking. */ +igt_v3d_perfmon_get_values (fd, id_global, &values); +igt_assert_lt (0 , values); + +igt_v3d_perfmon_destroy (fd, id_global); +igt_v3d_perfmon_destroy (fd, id_job); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + +igt_describe ("Make sure that the global perfmon is tracking all jobs consistently." ); + igt_subtest("global-perfmon-valid-perfmon") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +uint64_t *values1, *values2; +uint32_t id, out_sync; +uint8_t counters[2 ]; + +/*
tests/v3d/v3d_perfmon.c int igt_main() · line 366
Quoted 10 lines
tests/v3d/v3d_perfmon.c +10
-0+* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) { + counters[0 ] =0 ;/* cycle-count */ + counters[1 ] =1 ;/* core-active */ + }else if (ver >=42 ) { + counters[0 ] =V3D_PERFCNT_CYCLE_COUNT ; + counters[1 ] =V3D_PERFCNT_CLE_ACTIVE ; + }else
Same here, use braces '} else {'
tests/v3d/v3d_perfmon.c int igt_main() · line 367
Quoted 1 line
tests/v3d/v3d_perfmon.c +1
-0+igt_abort_on_f (true,"This V3D version is not supported." );
and close it here.
With this fixed
Regards,
Kamil
Quoted 348 lines
tests/v3d/v3d_perfmon.c +342
-0+ + id =igt_v3d_perfmon_create (fd,ARRAY_SIZE (counters), counters); + + values1 =calloc (ARRAY_SIZE (counters),sizeof (*values1)); + values2 =calloc (ARRAY_SIZE (counters),sizeof (*values2)); + + set_global.id = id; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Wait for the last job to complete so counters are captured. */ +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); +syncobj_destroy (fd, out_sync); + +igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon is active, the cycle-count must have +* increased with time. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_lt (values1[i], values2[i]); + + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id, values1); + + out_sync =syncobj_create (fd,0 ); + +/* Submit an arbitrary number of CL jobs to stress the perfcnts. */ +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Wait for the last job to complete so counters are captured. */ +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); +igt_v3d_perfmon_get_values (fd, id, values2); + +/* As the global perfmon was cleared, the perfmon is inactive +* and it must preserve its values. +*/ +for (int i =0 ; i <ARRAY_SIZE (counters); i++) +igt_assert_eq (values1[i], values2[i]); + +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + +free (values1); +free (values2); + } + +igt_describe ("Make sure that a global perfmon tracks jobs from other file descriptors." ); + igt_subtest("global-perfmon-multifd") { +struct drm_v3d_perfmon_set_global set_global = {0 }, + set_global2 = {0 }; +int fd2 =drm_open_driver_render (DRIVER_V3D ); +struct v3d_cl_job *job =igt_v3d_noop_job (fd2); +uint32_t id1, id2, out_sync; +uint64_t values1, values2; +uint8_t counter; + +/* +* Different V3D versions have different performance counters +* IDs for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + +/* Create and set global perfmon from fd. */ + id1 =igt_v3d_perfmon_create (fd,1 , &counter); + set_global.id = id1; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_get_values (fd, id1, &values1); + +/* Submit jobs from the second fd; the global perfmon should track them. */ + out_sync =syncobj_create (fd2,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd2,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +igt_assert (syncobj_wait (fd2, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id1, &values2); +igt_assert_lt (values1, values2); + +/* fd2 cannot set its own global perfmon while fd's is active. */ + id2 =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global2.id = id2; +do_ioctl_err (fd2,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global2,EBUSY ); + +igt_v3d_perfmon_destroy (fd2, id2); +igt_v3d_perfmon_destroy (fd, id1); + +syncobj_destroy (fd2, out_sync); +igt_v3d_free_cl_job (fd2, job); + +drm_close_driver (fd2); + } + +igt_describe ("Make sure closing a file descriptor with an active global " +"perfmon does not crash the driver." ); + igt_subtest("global-perfmon-destroy-multifd") { +struct drm_v3d_perfmon_set_global set_global = {0 }; +struct v3d_cl_job *job =igt_v3d_noop_job (fd); +int fd2 =drm_open_driver (DRIVER_V3D ); +uint32_t id, new_id, out_sync; +uint8_t counter =0 ; + +/* Create and set global perfmon from fd2. */ + id =igt_v3d_perfmon_create (fd2,1 , &counter); + set_global.id = id; +do_ioctl (fd2,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +/* Keep HW busy from fd while fd2 is closed. */ + out_sync =syncobj_create (fd,0 ); + +for (int i =0 ; i <V3D_PERFMON_NUM_CL_JOBS ; i++) { +/* Attach the out sync to the last job */ +if (i ==V3D_PERFMON_NUM_CL_JOBS -1 ) + job->submit->out_sync = out_sync; + +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job->submit); + } + +/* Closing fd2 must cleanly stop the active global perfmon and +* clear the global perfmon without crashing. +*/ +drm_close_driver (fd2); + +igt_assert (syncobj_wait (fd, &out_sync,1 ,INT64_MAX ,0 ,NULL )); + +/* fd can now set a new global perfmon without EBUSY. */ + new_id =igt_v3d_perfmon_create (fd,1 , &counter); + + set_global.id = new_id; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + + set_global.flags =DRM_V3D_PERFMON_CLEAR_GLOBAL ; +do_ioctl (fd,DRM_IOCTL_V3D_PERFMON_SET_GLOBAL , &set_global); + +igt_v3d_perfmon_destroy (fd, new_id); + +syncobj_destroy (fd, out_sync); +igt_v3d_free_cl_job (fd, job); + } + +igt_describe ("Make sure a perfmon CL job is not contaminated by concurrent CSD " +"work on a different queue." ); + igt_subtest("perfmon-counter-isolation") { +struct v3d_csd_job *csd_job =igt_v3d_empty_shader (fd); +struct v3d_cl_job *cl_job =igt_v3d_noop_job (fd); +uint32_t id, blocker, cl_out; +int timeline, fence_fd; +uint8_t counter; +uint64_t values; + +igt_require_sw_sync (); + +/* +* compute-active-cycles is zero during pure CL work and non-zero +* while a CSD job is executing. Submitting CSD jobs alongside a +* perfmon CL job lets us distinguish "CSD ran while the perfmon +* window was open" (isolation broken) from "CSD finished before +* the perfmon window opened" (isolation correct). +*/ +if (ver >=71 ) + counter =4 ;/* compute-active-cycles */ +else if (ver >=42 ) + counter =V3D_PERFCNT_COMPUTE_ACTIVE ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. All CSD jobs will +* wait on this fence and stay queued until we increment the +* sw_sync timeline. +*/ + timeline =sw_sync_timeline_create (); + fence_fd =sw_sync_timeline_create_fence (timeline,1 ); + + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + cl_out =syncobj_create (fd,0 ); + +/* +* Block all CSD jobs with the unsignaled SW fence so they are +* still queued when the CL perfmon job is submitted. +*/ + csd_job->submit->in_sync = blocker; +for (int i =0 ; i <V3D_PERFMON_NUM_CSD_JOBS ; i++) +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CSD , csd_job->submit); + +/* +* Submit the CL job with the perfmon. v3d perfmon serialization +* must add a fence dependency on the CSD done fences so the CL +* job is forced to wait for all previous jobs to complete before +* its perfmon window opens. +*/ + cl_job->submit->out_sync = cl_out; + cl_job->submit->perfmon_id = id; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , cl_job->submit); + +/* +* With serialization, the CL job waits for all CSD work to finish +* first, so the perfmon sees only pure CL activity. Without it, +* the two queues would race and CSD cycles would pollute the counter. +*/ +sw_sync_timeline_inc (timeline,1 ); +igt_assert (syncobj_wait (fd, &cl_out,1 ,INT64_MAX ,0 ,NULL )); + +igt_v3d_perfmon_get_values (fd, id, &values); + +/* All CSD activity finished before the perfmon window opened, +* so no compute cycles must have been counted during the CL job. +*/ +igt_assert_eq (values,0 ); + +close (timeline); +igt_v3d_perfmon_destroy (fd, id); + +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, cl_out); +igt_v3d_free_cl_job (fd, cl_job); +igt_v3d_free_csd_job (fd, csd_job); + } + +igt_describe ("Make sure a non-perfmon CL job submitted after a perfmon CL job " +"is serialized behind it and does not contaminate its counter values." ); + igt_subtest("perfmon-counter-isolation-subsequent-cl") { +struct v3d_cl_job *job1 =igt_v3d_noop_job (fd); +struct v3d_cl_job *job2 =igt_v3d_noop_job (fd); +uint64_t id, values, values_after_j2; +uint32_t blocker, out1, out2; +int timeline, fence_fd; +uint8_t counter; + +igt_require_sw_sync (); + +/* +* Different V3D versions have different performance counters IDs +* for the same counters. +*/ +if (ver >=71 ) + counter =0 ;/* cycle-count */ +else if (ver >=42 ) + counter =V3D_PERFCNT_CYCLE_COUNT ; +else +igt_abort_on_f (true,"This V3D version is not supported." ); + + id =igt_v3d_perfmon_create (fd,1 , &counter); + +/* +* Create an unsignaled fence via sw_sync. job1 will wait on +* this fence and stay blocked until we increment the timeline. +*/ + timeline =sw_sync_timeline_create (); + fence_fd =sw_sync_timeline_create_fence (timeline,1 ); + + blocker =syncobj_create (fd,0 ); +syncobj_import_sync_file (fd, blocker, fence_fd); +close (fence_fd); + + out1 =syncobj_create (fd,0 ); + out2 =syncobj_create (fd,0 ); + +/* job1: BIN job is blocked until we signal the blocker. */ + job1->submit->in_sync_bcl = blocker; + job1->submit->perfmon_id = id; + job1->submit->out_sync = out1; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job1->submit); + +/* job2: no perfmon, must wait for job1 due to job serialization. */ + job2->submit->out_sync = out2; +do_ioctl (fd,DRM_IOCTL_V3D_SUBMIT_CL , job2->submit); + +/* job2 is serialized behind job1, so it cannot have completed yet. */ +igt_assert_eq (syncobj_wait_err (fd, &out2,1 ,0 ,0 ), -ETIME ); + +/* While job1 has not started, the perfmon must still read zero. */ +igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_eq (values,0 ); + +/* Release the blocker. */ +sw_sync_timeline_inc (timeline,1 ); + +igt_assert (syncobj_wait (fd, &out1,1 ,INT64_MAX ,0 ,NULL )); + +/* job1 must have contributed cycles to the perfmon. */ +igt_v3d_perfmon_get_values (fd, id, &values); +igt_assert_lt (0 , values); + +igt_assert (syncobj_wait (fd, &out2,1 ,INT64_MAX ,0 ,NULL )); + +/* job2 doesn't have a perfmon attached, so a second read must +* return the same value. +*/ +igt_v3d_perfmon_get_values (fd, id, &values_after_j2); +igt_assert_eq (values, values_after_j2); + +close (timeline); +syncobj_destroy (fd, blocker); +syncobj_destroy (fd, out1); +syncobj_destroy (fd, out2); + +igt_v3d_perfmon_destroy (fd, id); + +igt_v3d_free_cl_job (fd, job1); +igt_v3d_free_cl_job (fd, job2); + } + igt_fixture()drm_close_driver (fd); }Signature · 1 line
2.54.0