dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] drm/v3d: Fix perfmon locking and cross-queue isolation
@ 2026-07-04 12:15 Maíra Canal
  2026-07-04 12:15 ` [PATCH v3 1/2] drm/v3d: Refactor perfmon locking Maíra Canal
  2026-07-04 12:15 ` [PATCH v3 2/2] drm/v3d: Serialize jobs across queues when a perfmon is attached Maíra Canal
  0 siblings, 2 replies; 5+ messages in thread
From: Maíra Canal @ 2026-07-04 12:15 UTC (permalink / raw)
  To: Melissa Wen, Iago Toral, Tvrtko Ursulin, David Airlie,
	Simona Vetter
  Cc: kernel-dev, dri-devel, Maíra Canal

A v3d core is able to expose a single set of HW performance counters, so at
any moment at most one perfmon can be programmed in HW. Currently, the
driver tracks the active perfmon with v3d_dev->active_perfmon, but three
long-standing issues makes perfmon handling unreliable:

1. The active_perfmon pointer is accessed lock-free from scheduler
   callbacks, the GPU-reset path and the perfmon ioctls. Note that the
   v3d_perfmon->lock mutex serialized start/stop of one perfmon object
   against itself, but the invariant that needs protection is device-wide.

2. perfmon start/stop is hooked exclusively to run_job() callbacks via
   v3d_switch_perfmon(). If nothing is queued behind a perfmon-carrying
   job, the perfmon is never actually stopped.

3. A non-global perfmon should count events generated by a specific
   submission, but the scheduler can run jobs from different queues
   concurrently. Without explicit cross-queue serialization, an unrelated
   job running in parallel pollutes the counters and produces unusable
   results.

This series aims to address all three issues.

PATCH 1 moves the locking to where the invariant actually lives (fixing
issue #1) and replaces the sleeping mutex with a spinlock, which allows us
to stop the perfmon from the IRQ handler at job-completion time (the
natural boundary for "active perfmon follows the active job") and fixes
issue #2.

PATCH 2 addresses issue #3 by building on the new locking to enforce
cross-queue serialization when a non-global perfmon is attached, by adding
scheduler fence dependencies during submission. The fence dependencies
allow us to enforce two rules:

1. A job that carries a non-global perfmon waits for every job currently
   in-flight across all HW queues to finish.

2. While such a job is in-flight, any subsequently submitted job waits
   for it.

This allows us to ensure cross-queue isolation and the reliability of
the performance counter values.

To make sure that this series actually produces the expected results and
improves the overall reliability of v3d's performance monitors, this
series is accompanied by a IGT series [1], which was already merged.

[1] https://lore.kernel.org/igt-dev/20260514201637.1811428-1-mcanal@igalia.com/T/

Best regards,
- Maíra

---
v1 -> v2: https://lore.kernel.org/r/20260508-v3d-perfmon-lifetime-v1-0-f5b5642c085f@igalia.com

- Rebased on top of "[PATCH v2 00/14] drm/v3d: Scheduler and submission
  fixes and refactoring"
- [1/4] NEW PATCH: "drm/v3d: Fix global performance monitor reference counting"
        - Minimal patch for stable branches only fixing the reference leaks
          in global perfmons.
- [2/4] Start/stop the global perfmon inside the set_global_perfmon ioctl and
        simplify global perfmon management across the helpers (Iago Toral)
        - In the reset path, before stopping the perfmon for the HW reset,
          v3d_reset() now re-arms the global perfmon with v3d_perfmon_resume(),
          as the global perfmon's start/stop points live only in the IOCTL.
        - v3d_perfmon_get_values_ioctl() no longer stops the perfmon, it
          only captures the values. Lifecycle management is left to the job
          (per-job perfmons) or the SET_GLOBAL ioctl (global perfmon).
- [2/4] In v3d_perfmon_delete(), first, stop the perfmon and then, check if
        it's a global perfmon (Iago Toral)
- [2/4] Add some comments to explain the refcount logic for global perfmons
        (Iago Toral)
- [3/4] Move the job->queue introduction to this patch instead of the
        previous one.
- [4/4] NEW PATCH: "drm/v3d: Drop the queue argument from v3d_job_add_syncobjs()"

v2 -> v3: https://lore.kernel.org/r/20260531-v3d-perfmon-lifetime-v2-0-60ed4485a203@igalia.com

- Rebased on top of drm-misc-next.
- "[PATCH v2 1/4] drm/v3d: Fix global performance monitor reference counting"
  was applied to drm-misc-fixes.
- "[PATCH v2 4/4] drm/v3d: Drop the queue argument from v3d_job_add_syncobjs()"
  was no longer needed after "[PATCH v4 00/12] drm/v3d: Scheduler and
  submission fixes and refactoring" was applied to drm-misc-next.
- [1/2, 2/2] Add Iago's R-b (Iago Toral)

---
Maíra Canal (2):
      drm/v3d: Refactor perfmon locking
      drm/v3d: Serialize jobs across queues when a perfmon is attached

 drivers/gpu/drm/v3d/v3d_drv.h     |  47 ++++++++--
 drivers/gpu/drm/v3d/v3d_gem.c     |   7 +-
 drivers/gpu/drm/v3d/v3d_irq.c     |   7 +-
 drivers/gpu/drm/v3d/v3d_perfmon.c | 189 ++++++++++++++++++++++++++++----------
 drivers/gpu/drm/v3d/v3d_power.c   |   4 +
 drivers/gpu/drm/v3d/v3d_sched.c   |  26 +-----
 drivers/gpu/drm/v3d/v3d_submit.c  |  68 +++++++++++++-
 7 files changed, 261 insertions(+), 87 deletions(-)
---
base-commit: 903f8773ee96c5dc5fb9aec65227f39fd3e7a1dc
change-id: 20260505-v3d-perfmon-lifetime-48c9ded1091b


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-04 12:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 12:15 [PATCH v3 0/2] drm/v3d: Fix perfmon locking and cross-queue isolation Maíra Canal
2026-07-04 12:15 ` [PATCH v3 1/2] drm/v3d: Refactor perfmon locking Maíra Canal
2026-07-04 12:31   ` sashiko-bot
2026-07-04 12:15 ` [PATCH v3 2/2] drm/v3d: Serialize jobs across queues when a perfmon is attached Maíra Canal
2026-07-04 12:29   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox