* [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency
@ 2026-08-11 11:23 Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 1/9] drm/panthor: Make panthor_irq::state a non-atomic field Boris Brezillon
` (8 more replies)
0 siblings, 9 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Right now, panthor is one of the rare drivers to signal fences
from work items (not even from the threaded IRQ handler). We
tried moving the job_completion check to hardirq handlers like
other drivers do, but the duration of this handler gets
slightly over the few usec (20+ usecs) we usually expect from
hardird handlers, and we're not sure we want to hold off the
processing of other interrupts for that long. So this series
just gets rid of the threaded-handler -> work_item indirection
and checks for job completion (and thus, fence signalling)
directly in the threaded handler.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
Changes in v6:
- Rebase on drm-misc-next
- Link to v5: https://lore.kernel.org/r/20260625-panthor-signal-from-irq-v5-0-8836a74e0ef9@collabora.com
Changes in v5:
- Add a fix for a theoretical IOMEM access in suspended state (patch 1)
- Make sure we don't delay a pending immediate tick in
sched_resume_tick() (patch 2)
- Make sure we initialize panthor_irq::state properly in the irq_request
helper
- Link to v4: https://lore.kernel.org/r/20260625-panthor-signal-from-irq-v4-0-3d2908912afa@collabora.com
Changes in v4:
- Add a bunch of fixes for bugs reported by shashiko
- Link to v3: https://lore.kernel.org/r/20260623-panthor-signal-from-irq-v3-0-2ece396f8ee0@collabora.com
Changes in v3:
- Save/restore the irq state in the raw handler.
- Rename panthor_irq::mask_lock into panthor_irq::lock
- Use the __always_inline specifier on
panthor_irq_default_threaded_handler()
- Use devm_request_threaded_irq() even when the threaded handler is
NULL
- Drop the patch that dynamically enables request-related interrupts
(FW-side race) after the polling period has expired
- Don't process FW events from the hardirq handler (too heavy for an
hardirq handler according to our testing)
- Link to v2: https://lore.kernel.org/r/20260512-panthor-signal-from-irq-v2-0-95c614a739cb@collabora.com
Changes in v2:
- Fix commit message in patch 4
- Move devm_kasprintf() before panthor_irq_resume() in patch 3
- Fix erroneous lockdep_assert_held() in patch 6
- Make sure events_lock is held when calling
csg_slot_sync_update_locked() in patch 6
- Restore a csg_slot_sync_update_locked() call in patch 7
- Fix a potential deadlock in patch 9
- Drop the IRQ coalescing patch (formerly patch 10)
- Change panthor_irq_request() so we don't have to define a dummy
threaded handler, and we can let RT kernels move the hard handler
to a thread
- Add patches to transition GPU event processing to the hard IRQ handler
- Link to v1: https://lore.kernel.org/r/20260429-panthor-signal-from-irq-v1-0-4b92ae4142d2@collabora.com
---
Boris Brezillon (9):
drm/panthor: Make panthor_irq::state a non-atomic field
drm/panthor: Move the register accessors before the IRQ helpers
drm/panthor: Replace the panthor_irq macro machinery by inline helpers
drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked()
drm/panthor: Get rid of panthor_group::fatal_lock
drm/panthor: Protect events processing with a separate spinlock
drm/panthor: Don't defer job completion checks
drm/panthor: Don't defer FW event processing
drm/panthor: Automate CSG IRQ processing at group unbind time
drivers/gpu/drm/panthor/panthor_device.h | 286 +++++++++--------
drivers/gpu/drm/panthor/panthor_fw.c | 22 +-
drivers/gpu/drm/panthor/panthor_gpu.c | 28 +-
drivers/gpu/drm/panthor/panthor_mmu.c | 39 +--
drivers/gpu/drm/panthor/panthor_pwr.c | 24 +-
drivers/gpu/drm/panthor/panthor_sched.c | 517 +++++++++++++++----------------
6 files changed, 451 insertions(+), 465 deletions(-)
---
base-commit: b961eb36d7b04147104cff2fd8bc0e94f4713324
change-id: 20260429-panthor-signal-from-irq-d33684f4d292
Best regards,
--
Boris Brezillon <boris.brezillon@collabora.com>
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v6 1/9] drm/panthor: Make panthor_irq::state a non-atomic field
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 2/9] drm/panthor: Move the register accessors before the IRQ helpers Boris Brezillon
` (7 subsequent siblings)
8 siblings, 0 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
The only place where panthor_irq::state is accessed without
panthor_irq::mask_lock held is in the prologue of _irq_suspend(),
which is not really a fast-path. So let's simplify things by assuming
panthor_irq::state must always be accessed with the mask_lock held,
and add a scoped_guard() in _irq_suspend().
While at it, rename the lock so it's clear it doesn't just protect
access to the panthor_irq::mask or the INT_MASK register.
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_device.h | 61 +++++++++++++++-----------------
1 file changed, 28 insertions(+), 33 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index 0fda64fbe5f2..4e5f7b0fb53f 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -92,17 +92,21 @@ struct panthor_irq {
u32 mask;
/**
- * @mask_lock: protects modifications to _INT_MASK and @mask.
+ * @lock: protects modifications to _INT_MASK, @mask and @state.
*
* In paths where _INT_MASK is updated based on a state
* transition/check, it's crucial for the state update/check to be
* inside the locked section, otherwise it introduces a race window
* leading to potential _INT_MASK inconsistencies.
*/
- spinlock_t mask_lock;
+ spinlock_t lock;
- /** @state: one of &enum panthor_irq_state reflecting the current state. */
- atomic_t state;
+ /**
+ * @state: one of &enum panthor_irq_state reflecting the current state.
+ *
+ * Must be accessed with lock held.
+ */
+ enum panthor_irq_state state;
};
/**
@@ -510,22 +514,15 @@ const char *panthor_exception_name(struct panthor_device *ptdev,
static irqreturn_t panthor_ ## __name ## _irq_raw_handler(int irq, void *data) \
{ \
struct panthor_irq *pirq = data; \
- enum panthor_irq_state old_state; \
\
- guard(spinlock_irqsave)(&pirq->mask_lock); \
- old_state = atomic_cmpxchg(&pirq->state, \
- PANTHOR_IRQ_STATE_ACTIVE, \
- PANTHOR_IRQ_STATE_PROCESSING); \
- if (old_state != PANTHOR_IRQ_STATE_ACTIVE) \
+ guard(spinlock_irqsave)(&pirq->lock); \
+ if (pirq->state != PANTHOR_IRQ_STATE_ACTIVE) \
return IRQ_NONE; \
\
- if (!gpu_read(pirq->iomem, INT_STAT)) { \
- atomic_cmpxchg(&pirq->state, \
- PANTHOR_IRQ_STATE_PROCESSING, \
- PANTHOR_IRQ_STATE_ACTIVE); \
+ if (!gpu_read(pirq->iomem, INT_STAT)) \
return IRQ_NONE; \
- } \
\
+ pirq->state = PANTHOR_IRQ_STATE_PROCESSING; \
gpu_write(pirq->iomem, INT_MASK, 0); \
return IRQ_WAKE_THREAD; \
} \
@@ -554,14 +551,11 @@ static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *da
ret = IRQ_HANDLED; \
} \
\
- scoped_guard(spinlock_irqsave, &pirq->mask_lock) { \
- enum panthor_irq_state old_state; \
- \
- old_state = atomic_cmpxchg(&pirq->state, \
- PANTHOR_IRQ_STATE_PROCESSING, \
- PANTHOR_IRQ_STATE_ACTIVE); \
- if (old_state == PANTHOR_IRQ_STATE_PROCESSING) \
+ scoped_guard(spinlock_irqsave, &pirq->lock) { \
+ if (pirq->state == PANTHOR_IRQ_STATE_PROCESSING) { \
+ pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
+ } \
} \
\
return ret; \
@@ -569,19 +563,20 @@ static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *da
\
static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) \
{ \
- scoped_guard(spinlock_irqsave, &pirq->mask_lock) { \
- atomic_set(&pirq->state, PANTHOR_IRQ_STATE_SUSPENDING); \
+ scoped_guard(spinlock_irqsave, &pirq->lock) { \
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDING; \
gpu_write(pirq->iomem, INT_MASK, 0); \
} \
synchronize_irq(pirq->irq); \
- atomic_set(&pirq->state, PANTHOR_IRQ_STATE_SUSPENDED); \
+ scoped_guard(spinlock_irqsave, &pirq->lock) \
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
} \
\
static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq) \
{ \
- guard(spinlock_irqsave)(&pirq->mask_lock); \
+ guard(spinlock_irqsave)(&pirq->lock); \
\
- atomic_set(&pirq->state, PANTHOR_IRQ_STATE_ACTIVE); \
+ pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
gpu_write(pirq->iomem, INT_CLEAR, pirq->mask); \
gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
} \
@@ -594,8 +589,8 @@ static int panthor_request_ ## __name ## _irq(struct panthor_device *ptdev, \
pirq->irq = irq; \
pirq->mask = 0; \
pirq->iomem = iomem; \
- spin_lock_init(&pirq->mask_lock); \
- atomic_set(&pirq->state, PANTHOR_IRQ_STATE_SUSPENDED); \
+ spin_lock_init(&pirq->lock); \
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
gpu_write(pirq->iomem, INT_MASK, 0); \
\
return devm_request_threaded_irq(ptdev->base.dev, irq, \
@@ -607,7 +602,7 @@ static int panthor_request_ ## __name ## _irq(struct panthor_device *ptdev, \
\
static inline void panthor_ ## __name ## _irq_enable_events(struct panthor_irq *pirq, u32 mask) \
{ \
- guard(spinlock_irqsave)(&pirq->mask_lock); \
+ guard(spinlock_irqsave)(&pirq->lock); \
pirq->mask |= mask; \
\
/* The only situation where we need to write the new mask is if the IRQ is active. \
@@ -615,13 +610,13 @@ static inline void panthor_ ## __name ## _irq_enable_events(struct panthor_irq *
* on the PROCESSING -> ACTIVE transition. \
* If the IRQ is suspended/suspending, the mask is restored at resume time. \
*/ \
- if (atomic_read(&pirq->state) == PANTHOR_IRQ_STATE_ACTIVE) \
+ if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
} \
\
static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq *pirq, u32 mask)\
{ \
- guard(spinlock_irqsave)(&pirq->mask_lock); \
+ guard(spinlock_irqsave)(&pirq->lock); \
pirq->mask &= ~mask; \
\
/* The only situation where we need to write the new mask is if the IRQ is active. \
@@ -629,7 +624,7 @@ static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq
* on the PROCESSING -> ACTIVE transition. \
* If the IRQ is suspended/suspending, the mask is restored at resume time. \
*/ \
- if (atomic_read(&pirq->state) == PANTHOR_IRQ_STATE_ACTIVE) \
+ if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
}
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 2/9] drm/panthor: Move the register accessors before the IRQ helpers
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 1/9] drm/panthor: Make panthor_irq::state a non-atomic field Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers Boris Brezillon
` (6 subsequent siblings)
8 siblings, 0 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
We're about to add an IRQ inline helper using gpu_read(). Move things
around to avoid forward declarations.
No functional changes.
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_device.h | 142 +++++++++++++++----------------
1 file changed, 71 insertions(+), 71 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index 4e5f7b0fb53f..b102ea77fd1a 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -495,6 +495,77 @@ panthor_exception_is_fault(u32 exception_code)
const char *panthor_exception_name(struct panthor_device *ptdev,
u32 exception_code);
+static inline void gpu_write(void __iomem *iomem, u32 reg, u32 data)
+{
+ writel(data, iomem + reg);
+}
+
+static inline u32 gpu_read(void __iomem *iomem, u32 reg)
+{
+ return readl(iomem + reg);
+}
+
+static inline u32 gpu_read_relaxed(void __iomem *iomem, u32 reg)
+{
+ return readl_relaxed(iomem + reg);
+}
+
+static inline void gpu_write64(void __iomem *iomem, u32 reg, u64 data)
+{
+ gpu_write(iomem, reg, lower_32_bits(data));
+ gpu_write(iomem, reg + 4, upper_32_bits(data));
+}
+
+static inline u64 gpu_read64(void __iomem *iomem, u32 reg)
+{
+ return (gpu_read(iomem, reg) | ((u64)gpu_read(iomem, reg + 4) << 32));
+}
+
+static inline u64 gpu_read64_relaxed(void __iomem *iomem, u32 reg)
+{
+ return (gpu_read_relaxed(iomem, reg) |
+ ((u64)gpu_read_relaxed(iomem, reg + 4) << 32));
+}
+
+static inline u64 gpu_read64_counter(void __iomem *iomem, u32 reg)
+{
+ u32 lo, hi1, hi2;
+ do {
+ hi1 = gpu_read(iomem, reg + 4);
+ lo = gpu_read(iomem, reg);
+ hi2 = gpu_read(iomem, reg + 4);
+ } while (hi1 != hi2);
+ return lo | ((u64)hi2 << 32);
+}
+
+#define gpu_read_poll_timeout(iomem, reg, val, cond, delay_us, timeout_us) \
+ read_poll_timeout(gpu_read, val, cond, delay_us, timeout_us, false, \
+ iomem, reg)
+
+#define gpu_read_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
+ timeout_us) \
+ read_poll_timeout_atomic(gpu_read, val, cond, delay_us, timeout_us, \
+ false, iomem, reg)
+
+#define gpu_read64_poll_timeout(iomem, reg, val, cond, delay_us, timeout_us) \
+ read_poll_timeout(gpu_read64, val, cond, delay_us, timeout_us, false, \
+ iomem, reg)
+
+#define gpu_read64_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
+ timeout_us) \
+ read_poll_timeout_atomic(gpu_read64, val, cond, delay_us, timeout_us, \
+ false, iomem, reg)
+
+#define gpu_read_relaxed_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
+ timeout_us) \
+ read_poll_timeout_atomic(gpu_read_relaxed, val, cond, delay_us, \
+ timeout_us, false, iomem, reg)
+
+#define gpu_read64_relaxed_poll_timeout(iomem, reg, val, cond, delay_us, \
+ timeout_us) \
+ read_poll_timeout(gpu_read64_relaxed, val, cond, delay_us, timeout_us, \
+ false, iomem, reg)
+
#define INT_RAWSTAT 0x0
#define INT_CLEAR 0x4
#define INT_MASK 0x8
@@ -630,75 +701,4 @@ static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq
extern struct workqueue_struct *panthor_cleanup_wq;
-static inline void gpu_write(void __iomem *iomem, u32 reg, u32 data)
-{
- writel(data, iomem + reg);
-}
-
-static inline u32 gpu_read(void __iomem *iomem, u32 reg)
-{
- return readl(iomem + reg);
-}
-
-static inline u32 gpu_read_relaxed(void __iomem *iomem, u32 reg)
-{
- return readl_relaxed(iomem + reg);
-}
-
-static inline void gpu_write64(void __iomem *iomem, u32 reg, u64 data)
-{
- gpu_write(iomem, reg, lower_32_bits(data));
- gpu_write(iomem, reg + 4, upper_32_bits(data));
-}
-
-static inline u64 gpu_read64(void __iomem *iomem, u32 reg)
-{
- return (gpu_read(iomem, reg) | ((u64)gpu_read(iomem, reg + 4) << 32));
-}
-
-static inline u64 gpu_read64_relaxed(void __iomem *iomem, u32 reg)
-{
- return (gpu_read_relaxed(iomem, reg) |
- ((u64)gpu_read_relaxed(iomem, reg + 4) << 32));
-}
-
-static inline u64 gpu_read64_counter(void __iomem *iomem, u32 reg)
-{
- u32 lo, hi1, hi2;
- do {
- hi1 = gpu_read(iomem, reg + 4);
- lo = gpu_read(iomem, reg);
- hi2 = gpu_read(iomem, reg + 4);
- } while (hi1 != hi2);
- return lo | ((u64)hi2 << 32);
-}
-
-#define gpu_read_poll_timeout(iomem, reg, val, cond, delay_us, timeout_us) \
- read_poll_timeout(gpu_read, val, cond, delay_us, timeout_us, false, \
- iomem, reg)
-
-#define gpu_read_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
- timeout_us) \
- read_poll_timeout_atomic(gpu_read, val, cond, delay_us, timeout_us, \
- false, iomem, reg)
-
-#define gpu_read64_poll_timeout(iomem, reg, val, cond, delay_us, timeout_us) \
- read_poll_timeout(gpu_read64, val, cond, delay_us, timeout_us, false, \
- iomem, reg)
-
-#define gpu_read64_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
- timeout_us) \
- read_poll_timeout_atomic(gpu_read64, val, cond, delay_us, timeout_us, \
- false, iomem, reg)
-
-#define gpu_read_relaxed_poll_timeout_atomic(iomem, reg, val, cond, delay_us, \
- timeout_us) \
- read_poll_timeout_atomic(gpu_read_relaxed, val, cond, delay_us, \
- timeout_us, false, iomem, reg)
-
-#define gpu_read64_relaxed_poll_timeout(iomem, reg, val, cond, delay_us, \
- timeout_us) \
- read_poll_timeout(gpu_read64_relaxed, val, cond, delay_us, timeout_us, \
- false, iomem, reg)
-
#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 1/9] drm/panthor: Make panthor_irq::state a non-atomic field Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 2/9] drm/panthor: Move the register accessors before the IRQ helpers Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-18 17:08 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked() Boris Brezillon
` (5 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Now that panthor_irq contains the iomem region, there's no real need
for the macro-based panthor_irq helper generation logic. We can just
provide inline helpers that do the same and let the compiler optimize
indirect function calls. The only extra annoyance is the fact we have
to open-code the panthor_xxx_irq_threaded_handler() implementation, but
those are single-line functions, so it's acceptable.
While at it, we changed the prototype of the IRQ handlers to take
a panthor_irq instead of panthor_device, since that's the thing
that's passed around when it comes to panthor_irq, and the
panthor_device can be directly extracted from there.
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_device.h | 247 +++++++++++++++----------------
drivers/gpu/drm/panthor/panthor_fw.c | 22 ++-
drivers/gpu/drm/panthor/panthor_gpu.c | 28 ++--
drivers/gpu/drm/panthor/panthor_mmu.c | 39 ++---
drivers/gpu/drm/panthor/panthor_pwr.c | 24 +--
5 files changed, 188 insertions(+), 172 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index b102ea77fd1a..b55a3f9edd41 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -571,132 +571,127 @@ static inline u64 gpu_read64_counter(void __iomem *iomem, u32 reg)
#define INT_MASK 0x8
#define INT_STAT 0xc
-/**
- * PANTHOR_IRQ_HANDLER() - Define interrupt handlers and the interrupt
- * registration function.
- *
- * The boiler-plate to gracefully deal with shared interrupts is
- * auto-generated. All you have to do is call PANTHOR_IRQ_HANDLER()
- * just after the actual handler. The handler prototype is:
- *
- * void (*handler)(struct panthor_device *, u32 status);
- */
-#define PANTHOR_IRQ_HANDLER(__name, __handler) \
-static irqreturn_t panthor_ ## __name ## _irq_raw_handler(int irq, void *data) \
-{ \
- struct panthor_irq *pirq = data; \
- \
- guard(spinlock_irqsave)(&pirq->lock); \
- if (pirq->state != PANTHOR_IRQ_STATE_ACTIVE) \
- return IRQ_NONE; \
- \
- if (!gpu_read(pirq->iomem, INT_STAT)) \
- return IRQ_NONE; \
- \
- pirq->state = PANTHOR_IRQ_STATE_PROCESSING; \
- gpu_write(pirq->iomem, INT_MASK, 0); \
- return IRQ_WAKE_THREAD; \
-} \
- \
-static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *data) \
-{ \
- struct panthor_irq *pirq = data; \
- struct panthor_device *ptdev = pirq->ptdev; \
- irqreturn_t ret = IRQ_NONE; \
- \
- while (true) { \
- /* It's safe to access pirq->mask without the lock held here. If a new \
- * event gets added to the mask and the corresponding IRQ is pending, \
- * we'll process it right away instead of adding an extra raw -> threaded \
- * round trip. If an event is removed and the status bit is set, it will \
- * be ignored, just like it would have been if the mask had been adjusted \
- * right before the HW event kicks in. TLDR; it's all expected races we're \
- * covered for. \
- */ \
- u32 status = gpu_read(pirq->iomem, INT_RAWSTAT) & pirq->mask; \
- \
- if (!status) \
- break; \
- \
- __handler(ptdev, status); \
- ret = IRQ_HANDLED; \
- } \
- \
- scoped_guard(spinlock_irqsave, &pirq->lock) { \
- if (pirq->state == PANTHOR_IRQ_STATE_PROCESSING) { \
- pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
- gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
- } \
- } \
- \
- return ret; \
-} \
- \
-static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) \
-{ \
- scoped_guard(spinlock_irqsave, &pirq->lock) { \
- pirq->state = PANTHOR_IRQ_STATE_SUSPENDING; \
- gpu_write(pirq->iomem, INT_MASK, 0); \
- } \
- synchronize_irq(pirq->irq); \
- scoped_guard(spinlock_irqsave, &pirq->lock) \
- pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
-} \
- \
-static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq) \
-{ \
- guard(spinlock_irqsave)(&pirq->lock); \
- \
- pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
- gpu_write(pirq->iomem, INT_CLEAR, pirq->mask); \
- gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
-} \
- \
-static int panthor_request_ ## __name ## _irq(struct panthor_device *ptdev, \
- struct panthor_irq *pirq, \
- int irq, void __iomem *iomem) \
-{ \
- pirq->ptdev = ptdev; \
- pirq->irq = irq; \
- pirq->mask = 0; \
- pirq->iomem = iomem; \
- spin_lock_init(&pirq->lock); \
- pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
- gpu_write(pirq->iomem, INT_MASK, 0); \
- \
- return devm_request_threaded_irq(ptdev->base.dev, irq, \
- panthor_ ## __name ## _irq_raw_handler, \
- panthor_ ## __name ## _irq_threaded_handler, \
- IRQF_SHARED, KBUILD_MODNAME "-" # __name, \
- pirq); \
-} \
- \
-static inline void panthor_ ## __name ## _irq_enable_events(struct panthor_irq *pirq, u32 mask) \
-{ \
- guard(spinlock_irqsave)(&pirq->lock); \
- pirq->mask |= mask; \
- \
- /* The only situation where we need to write the new mask is if the IRQ is active. \
- * If it's being processed, the mask will be restored for us in _irq_threaded_handler() \
- * on the PROCESSING -> ACTIVE transition. \
- * If the IRQ is suspended/suspending, the mask is restored at resume time. \
- */ \
- if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
- gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
-} \
- \
-static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq *pirq, u32 mask)\
-{ \
- guard(spinlock_irqsave)(&pirq->lock); \
- pirq->mask &= ~mask; \
- \
- /* The only situation where we need to write the new mask is if the IRQ is active. \
- * If it's being processed, the mask will be restored for us in _irq_threaded_handler() \
- * on the PROCESSING -> ACTIVE transition. \
- * If the IRQ is suspended/suspending, the mask is restored at resume time. \
- */ \
- if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
- gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
+static inline irqreturn_t panthor_irq_default_raw_handler(int irq, void *data)
+{
+ struct panthor_irq *pirq = data;
+
+ guard(spinlock_irqsave)(&pirq->lock);
+ if (pirq->state != PANTHOR_IRQ_STATE_ACTIVE)
+ return IRQ_NONE;
+
+ if (!gpu_read(pirq->iomem, INT_STAT))
+ return IRQ_NONE;
+
+ pirq->state = PANTHOR_IRQ_STATE_PROCESSING;
+ gpu_write(pirq->iomem, INT_MASK, 0);
+ return IRQ_WAKE_THREAD;
+}
+
+static __always_inline irqreturn_t
+panthor_irq_default_threaded_handler(void *data,
+ void (*slow_handler)(struct panthor_irq *, u32))
+{
+ struct panthor_irq *pirq = data;
+ irqreturn_t ret = IRQ_NONE;
+
+ while (true) {
+ /* It's safe to access pirq->mask without the lock held here. If a new
+ * event gets added to the mask and the corresponding IRQ is pending,
+ * we'll process it right away instead of adding an extra raw -> threaded
+ * round trip. If an event is removed and the status bit is set, it will
+ * be ignored, just like it would have been if the mask had been adjusted
+ * right before the HW event kicks in. TLDR; it's all expected races we're
+ * covered for.
+ */
+ u32 status = gpu_read(pirq->iomem, INT_RAWSTAT) & pirq->mask;
+
+ if (!status)
+ break;
+
+ slow_handler(pirq, status);
+ ret = IRQ_HANDLED;
+ }
+
+ scoped_guard(spinlock_irqsave, &pirq->lock) {
+ if (pirq->state == PANTHOR_IRQ_STATE_PROCESSING) {
+ pirq->state = PANTHOR_IRQ_STATE_ACTIVE;
+ gpu_write(pirq->iomem, INT_MASK, pirq->mask);
+ }
+ }
+
+ return ret;
+}
+
+static inline void panthor_irq_suspend(struct panthor_irq *pirq)
+{
+ scoped_guard(spinlock_irqsave, &pirq->lock) {
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDING;
+ gpu_write(pirq->iomem, INT_MASK, 0);
+ }
+ synchronize_irq(pirq->irq);
+ scoped_guard(spinlock_irqsave, &pirq->lock)
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDED;
+}
+
+static inline void panthor_irq_resume(struct panthor_irq *pirq)
+{
+ guard(spinlock_irqsave)(&pirq->lock);
+ pirq->state = PANTHOR_IRQ_STATE_ACTIVE;
+ gpu_write(pirq->iomem, INT_CLEAR, pirq->mask);
+ gpu_write(pirq->iomem, INT_MASK, pirq->mask);
+}
+
+static inline void panthor_irq_enable_events(struct panthor_irq *pirq, u32 mask)
+{
+ guard(spinlock_irqsave)(&pirq->lock);
+ pirq->mask |= mask;
+
+ /* The only situation where we need to write the new mask is if the IRQ is active.
+ * If it's being processed, the mask will be restored for us in _irq_threaded_handler()
+ * on the PROCESSING -> ACTIVE transition.
+ * If the IRQ is suspended/suspending, the mask is restored at resume time.
+ */
+ if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE)
+ gpu_write(pirq->iomem, INT_MASK, pirq->mask);
+}
+
+static inline void panthor_irq_disable_events(struct panthor_irq *pirq, u32 mask)
+{
+ guard(spinlock_irqsave)(&pirq->lock);
+ pirq->mask &= ~mask;
+
+ /* The only situation where we need to write the new mask is if the IRQ is active.
+ * If it's being processed, the mask will be restored for us in _irq_threaded_handler()
+ * on the PROCESSING -> ACTIVE transition.
+ * If the IRQ is suspended/suspending, the mask is restored at resume time.
+ */
+ if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE)
+ gpu_write(pirq->iomem, INT_MASK, pirq->mask);
+}
+
+static inline int
+panthor_irq_request(struct panthor_device *ptdev, struct panthor_irq *pirq,
+ int irq, void __iomem *iomem, const char *name,
+ irqreturn_t (*threaded_handler)(int, void *data))
+{
+ const char *full_name;
+
+ pirq->ptdev = ptdev;
+ pirq->irq = irq;
+ pirq->mask = 0;
+ pirq->iomem = iomem;
+ spin_lock_init(&pirq->lock);
+ pirq->state = PANTHOR_IRQ_STATE_SUSPENDED;
+
+ full_name = devm_kasprintf(ptdev->base.dev, GFP_KERNEL, KBUILD_MODNAME "-%s", name);
+ if (!full_name)
+ return -ENOMEM;
+
+ gpu_write(pirq->iomem, INT_MASK, 0);
+ return devm_request_threaded_irq(ptdev->base.dev, irq,
+ panthor_irq_default_raw_handler,
+ threaded_handler,
+ IRQF_SHARED, full_name, pirq);
}
extern struct workqueue_struct *panthor_cleanup_wq;
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index fc1a423e48a8..68965175105f 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -1072,8 +1072,9 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev)
msecs_to_jiffies(PING_INTERVAL_MS));
}
-static void panthor_job_irq_handler(struct panthor_device *ptdev, u32 status)
+static void panthor_job_irq_handler(struct panthor_irq *pirq, u32 status)
{
+ struct panthor_device *ptdev = pirq->ptdev;
u32 duration;
u64 start = 0;
@@ -1099,7 +1100,11 @@ static void panthor_job_irq_handler(struct panthor_device *ptdev, u32 status)
trace_gpu_job_irq(ptdev->base.dev, status, duration);
}
}
-PANTHOR_IRQ_HANDLER(job, panthor_job_irq_handler);
+
+static irqreturn_t panthor_job_irq_threaded_handler(int irq, void *data)
+{
+ return panthor_irq_default_threaded_handler(data, panthor_job_irq_handler);
+}
static int panthor_fw_start(struct panthor_device *ptdev)
{
@@ -1107,8 +1112,8 @@ static int panthor_fw_start(struct panthor_device *ptdev)
bool timedout = false;
ptdev->fw->booted = false;
- panthor_job_irq_enable_events(&ptdev->fw->irq, ~0);
- panthor_job_irq_resume(&ptdev->fw->irq);
+ panthor_irq_enable_events(&ptdev->fw->irq, ~0);
+ panthor_irq_resume(&ptdev->fw->irq);
gpu_write(fw->iomem, MCU_CONTROL, MCU_CONTROL_AUTO);
if (!wait_event_timeout(ptdev->fw->req_waitqueue,
@@ -1218,7 +1223,7 @@ void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang)
ptdev->reset.fast = true;
}
- panthor_job_irq_suspend(&ptdev->fw->irq);
+ panthor_irq_suspend(&ptdev->fw->irq);
panthor_fw_stop(ptdev);
}
@@ -1287,7 +1292,7 @@ void panthor_fw_unplug(struct panthor_device *ptdev)
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev)) {
/* Make sure the IRQ handler cannot be called after that point. */
- panthor_job_irq_suspend(&ptdev->fw->irq);
+ panthor_irq_suspend(&ptdev->fw->irq);
panthor_fw_stop(ptdev);
}
@@ -1482,8 +1487,9 @@ int panthor_fw_init(struct panthor_device *ptdev)
if (irq <= 0)
return -ENODEV;
- ret = panthor_request_job_irq(ptdev, &fw->irq, irq,
- ptdev->iomem + JOB_INT_BASE);
+ ret = panthor_irq_request(ptdev, &fw->irq, irq,
+ ptdev->iomem + JOB_INT_BASE, "job",
+ panthor_job_irq_threaded_handler);
if (ret) {
drm_err(&ptdev->base, "failed to request job irq");
return ret;
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
index c013d6bf9a59..7f287242285a 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.c
+++ b/drivers/gpu/drm/panthor/panthor_gpu.c
@@ -86,8 +86,9 @@ static void panthor_gpu_l2_config_set(struct panthor_device *ptdev)
gpu_write(gpu->iomem, GPU_L2_CONFIG, l2_config);
}
-static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
+static void panthor_gpu_irq_handler(struct panthor_irq *pirq, u32 status)
{
+ struct panthor_device *ptdev = pirq->ptdev;
struct panthor_gpu *gpu = ptdev->gpu;
gpu_write(gpu->irq.iomem, INT_CLEAR, status);
@@ -116,7 +117,11 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
}
spin_unlock(&ptdev->gpu->reqs_lock);
}
-PANTHOR_IRQ_HANDLER(gpu, panthor_gpu_irq_handler);
+
+static irqreturn_t panthor_gpu_irq_threaded_handler(int irq, void *data)
+{
+ return panthor_irq_default_threaded_handler(data, panthor_gpu_irq_handler);
+}
/**
* panthor_gpu_unplug() - Called when the GPU is unplugged.
@@ -128,7 +133,7 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)
/* Make sure the IRQ handler is not running after that point. */
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
- panthor_gpu_irq_suspend(&ptdev->gpu->irq);
+ panthor_irq_suspend(&ptdev->gpu->irq);
/* Wake-up all waiters. */
spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
@@ -169,13 +174,14 @@ int panthor_gpu_init(struct panthor_device *ptdev)
if (irq < 0)
return irq;
- ret = panthor_request_gpu_irq(ptdev, &ptdev->gpu->irq, irq,
- ptdev->iomem + GPU_INT_BASE);
+ ret = panthor_irq_request(ptdev, &ptdev->gpu->irq, irq,
+ ptdev->iomem + GPU_INT_BASE, "gpu",
+ panthor_gpu_irq_threaded_handler);
if (ret)
return ret;
- panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_INTERRUPTS_MASK);
- panthor_gpu_irq_resume(&ptdev->gpu->irq);
+ panthor_irq_enable_events(&ptdev->gpu->irq, GPU_INTERRUPTS_MASK);
+ panthor_irq_resume(&ptdev->gpu->irq);
return 0;
}
@@ -183,7 +189,7 @@ int panthor_gpu_power_changed_on(struct panthor_device *ptdev)
{
guard(pm_runtime_active)(ptdev->base.dev);
- panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
+ panthor_irq_enable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
return 0;
}
@@ -192,7 +198,7 @@ void panthor_gpu_power_changed_off(struct panthor_device *ptdev)
{
guard(pm_runtime_active)(ptdev->base.dev);
- panthor_gpu_irq_disable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
+ panthor_irq_disable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
}
/**
@@ -425,7 +431,7 @@ void panthor_gpu_suspend(struct panthor_device *ptdev)
else
panthor_hw_l2_power_off(ptdev);
- panthor_gpu_irq_suspend(&ptdev->gpu->irq);
+ panthor_irq_suspend(&ptdev->gpu->irq);
}
/**
@@ -437,7 +443,7 @@ void panthor_gpu_suspend(struct panthor_device *ptdev)
*/
void panthor_gpu_resume(struct panthor_device *ptdev)
{
- panthor_gpu_irq_resume(&ptdev->gpu->irq);
+ panthor_irq_resume(&ptdev->gpu->irq);
panthor_hw_l2_power_on(ptdev);
}
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 0182b72f1932..d43ba1c7cd2a 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -601,17 +601,13 @@ static u32 panthor_mmu_as_fault_mask(struct panthor_device *ptdev, u32 as)
return BIT(as);
}
-/* Forward declaration to call helpers within as_enable/disable */
-static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status);
-PANTHOR_IRQ_HANDLER(mmu, panthor_mmu_irq_handler);
-
static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
u64 transtab, u64 transcfg, u64 memattr)
{
struct panthor_mmu *mmu = ptdev->mmu;
- panthor_mmu_irq_enable_events(&ptdev->mmu->irq,
- panthor_mmu_as_fault_mask(ptdev, as_nr));
+ panthor_irq_enable_events(&ptdev->mmu->irq,
+ panthor_mmu_as_fault_mask(ptdev, as_nr));
gpu_write64(mmu->iomem, AS_TRANSTAB(as_nr), transtab);
gpu_write64(mmu->iomem, AS_MEMATTR(as_nr), memattr);
@@ -629,8 +625,8 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
lockdep_assert_held(&ptdev->mmu->as.slots_lock);
- panthor_mmu_irq_disable_events(&ptdev->mmu->irq,
- panthor_mmu_as_fault_mask(ptdev, as_nr));
+ panthor_irq_disable_events(&ptdev->mmu->irq,
+ panthor_mmu_as_fault_mask(ptdev, as_nr));
/* Flush+invalidate RW caches, invalidate RO ones. */
ret = panthor_gpu_flush_caches(ptdev, CACHE_CLEAN | CACHE_INV,
@@ -1859,8 +1855,9 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
mutex_unlock(&ptdev->mmu->as.slots_lock);
}
-static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
+static void panthor_mmu_irq_handler(struct panthor_irq *pirq, u32 status)
{
+ struct panthor_device *ptdev = pirq->ptdev;
struct panthor_mmu *mmu = ptdev->mmu;
bool has_unhandled_faults = false;
@@ -1923,6 +1920,11 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
panthor_sched_report_mmu_fault(ptdev);
}
+static irqreturn_t panthor_mmu_irq_threaded_handler(int irq, void *data)
+{
+ return panthor_irq_default_threaded_handler(data, panthor_mmu_irq_handler);
+}
+
/**
* panthor_mmu_suspend() - Suspend the MMU logic
* @ptdev: Device.
@@ -1947,7 +1949,7 @@ void panthor_mmu_suspend(struct panthor_device *ptdev)
}
mutex_unlock(&ptdev->mmu->as.slots_lock);
- panthor_mmu_irq_suspend(&ptdev->mmu->irq);
+ panthor_irq_suspend(&ptdev->mmu->irq);
}
/**
@@ -1966,7 +1968,7 @@ void panthor_mmu_resume(struct panthor_device *ptdev)
ptdev->mmu->as.faulty_mask = 0;
mutex_unlock(&ptdev->mmu->as.slots_lock);
- panthor_mmu_irq_resume(&ptdev->mmu->irq);
+ panthor_irq_resume(&ptdev->mmu->irq);
}
/**
@@ -1983,7 +1985,7 @@ void panthor_mmu_pre_reset(struct panthor_device *ptdev)
{
struct panthor_vm *vm;
- panthor_mmu_irq_suspend(&ptdev->mmu->irq);
+ panthor_irq_suspend(&ptdev->mmu->irq);
mutex_lock(&ptdev->mmu->vm.lock);
ptdev->mmu->vm.reset_in_progress = true;
@@ -2020,7 +2022,7 @@ void panthor_mmu_post_reset(struct panthor_device *ptdev)
mutex_unlock(&ptdev->mmu->as.slots_lock);
- panthor_mmu_irq_resume(&ptdev->mmu->irq);
+ panthor_irq_resume(&ptdev->mmu->irq);
/* Restart the VM_BIND queues. */
mutex_lock(&ptdev->mmu->vm.lock);
@@ -3352,7 +3354,7 @@ panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
void panthor_mmu_unplug(struct panthor_device *ptdev)
{
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
- panthor_mmu_irq_suspend(&ptdev->mmu->irq);
+ panthor_irq_suspend(&ptdev->mmu->irq);
mutex_lock(&ptdev->mmu->as.slots_lock);
for (u32 i = 0; i < ARRAY_SIZE(ptdev->mmu->as.slots); i++) {
@@ -3413,8 +3415,9 @@ int panthor_mmu_init(struct panthor_device *ptdev)
if (irq <= 0)
return -ENODEV;
- ret = panthor_request_mmu_irq(ptdev, &mmu->irq, irq,
- ptdev->iomem + MMU_INT_BASE);
+ ret = panthor_irq_request(ptdev, &mmu->irq, irq,
+ ptdev->iomem + MMU_INT_BASE, "mmu",
+ panthor_mmu_irq_threaded_handler);
if (ret)
return ret;
@@ -3435,8 +3438,8 @@ int panthor_mmu_init(struct panthor_device *ptdev)
if (ret)
return ret;
- panthor_mmu_irq_enable_events(&mmu->irq, panthor_mmu_fault_mask(ptdev, ~0));
- panthor_mmu_irq_resume(&mmu->irq);
+ panthor_irq_enable_events(&mmu->irq, panthor_mmu_fault_mask(ptdev, ~0));
+ panthor_irq_resume(&mmu->irq);
return 0;
}
diff --git a/drivers/gpu/drm/panthor/panthor_pwr.c b/drivers/gpu/drm/panthor/panthor_pwr.c
index f2c2c3000590..dd7b6ef8ea20 100644
--- a/drivers/gpu/drm/panthor/panthor_pwr.c
+++ b/drivers/gpu/drm/panthor/panthor_pwr.c
@@ -56,8 +56,9 @@ struct panthor_pwr {
wait_queue_head_t reqs_acked;
};
-static void panthor_pwr_irq_handler(struct panthor_device *ptdev, u32 status)
+static void panthor_pwr_irq_handler(struct panthor_irq *pirq, u32 status)
{
+ struct panthor_device *ptdev = pirq->ptdev;
struct panthor_pwr *pwr = ptdev->pwr;
spin_lock(&ptdev->pwr->reqs_lock);
@@ -75,7 +76,11 @@ static void panthor_pwr_irq_handler(struct panthor_device *ptdev, u32 status)
}
spin_unlock(&ptdev->pwr->reqs_lock);
}
-PANTHOR_IRQ_HANDLER(pwr, panthor_pwr_irq_handler);
+
+static irqreturn_t panthor_pwr_irq_threaded_handler(int irq, void *data)
+{
+ return panthor_irq_default_threaded_handler(data, panthor_pwr_irq_handler);
+}
static void panthor_pwr_write_command(struct panthor_device *ptdev, u32 command, u64 args)
{
@@ -454,7 +459,7 @@ void panthor_pwr_unplug(struct panthor_device *ptdev)
/* Make sure the IRQ handler is not running after that point. */
if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
- panthor_pwr_irq_suspend(&ptdev->pwr->irq);
+ panthor_irq_suspend(&ptdev->pwr->irq);
/* Wake-up all waiters. */
spin_lock_irqsave(&ptdev->pwr->reqs_lock, flags);
@@ -484,13 +489,14 @@ int panthor_pwr_init(struct panthor_device *ptdev)
if (irq < 0)
return irq;
- err = panthor_request_pwr_irq(ptdev, &pwr->irq, irq,
- pwr->iomem + PWR_INT_BASE);
+ err = panthor_irq_request(ptdev, &pwr->irq, irq,
+ pwr->iomem + PWR_INT_BASE, "pwr",
+ panthor_pwr_irq_threaded_handler);
if (err)
return err;
- panthor_pwr_irq_enable_events(&pwr->irq, PWR_INTERRUPTS_MASK);
- panthor_pwr_irq_resume(&pwr->irq);
+ panthor_irq_enable_events(&pwr->irq, PWR_INTERRUPTS_MASK);
+ panthor_irq_resume(&pwr->irq);
return 0;
}
@@ -566,7 +572,7 @@ void panthor_pwr_suspend(struct panthor_device *ptdev)
if (!ptdev->pwr)
return;
- panthor_pwr_irq_suspend(&ptdev->pwr->irq);
+ panthor_irq_suspend(&ptdev->pwr->irq);
}
void panthor_pwr_resume(struct panthor_device *ptdev)
@@ -574,5 +580,5 @@ void panthor_pwr_resume(struct panthor_device *ptdev)
if (!ptdev->pwr)
return;
- panthor_pwr_irq_resume(&ptdev->pwr->irq);
+ panthor_irq_resume(&ptdev->pwr->irq);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked()
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (2 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-17 15:09 ` Steven Price
2026-08-18 17:08 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock Boris Brezillon
` (4 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
By scheduling an immediate tick, we already force idleness re-evaluation,
which gives the scheduler the opportunity to evict idle groups
and schedule onces that have jobs pending.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 5832dccfc093..baa06731797c 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1733,8 +1733,6 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
lockdep_assert_held(&sched->lock);
- sched->might_have_idle_groups = true;
-
/* Schedule a tick so we can evict idle groups and schedule non-idle
* ones. This will also update runtime PM and devfreq busy/idle states,
* so the device can lower its frequency or get suspended.
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (3 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked() Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-17 15:12 ` Steven Price
2026-08-18 17:09 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock Boris Brezillon
` (3 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
This lock is never used, and we're about to make fatal_queues an
atomic to cope with concurrent updates.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index baa06731797c..9adf1e21eb83 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -565,9 +565,6 @@ struct panthor_group {
/** @idle_queues: Bitmask reflecting the idle queues. */
u32 idle_queues;
- /** @fatal_lock: Lock used to protect access to fatal fields. */
- spinlock_t fatal_lock;
-
/** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
u32 fatal_queues;
@@ -3675,7 +3672,6 @@ int panthor_group_create(struct panthor_file *pfile,
if (!group)
return -ENOMEM;
- spin_lock_init(&group->fatal_lock);
kref_init(&group->refcount);
group->state = PANTHOR_CS_GROUP_CREATED;
group->csg_id = -1;
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (4 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-17 15:21 ` Steven Price
2026-08-18 17:13 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 7/9] drm/panthor: Don't defer job completion checks Boris Brezillon
` (2 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Add a specific spinlock for events processing so we can selectively
move some event processing to the threaded IRQ handler. For events to be
processed, we need to have access to the group attached to the CSG slot
which also forces us to protect the csg_slots[] updates with this
lock.
Note that fatal_queues/timedout are turned into atomics to avoid having
to take the events_lock every time those are checked or updated.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 123 ++++++++++++++++++++------------
1 file changed, 78 insertions(+), 45 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 9adf1e21eb83..794105e239e6 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -254,8 +254,21 @@ struct panthor_scheduler {
struct list_head waiting;
} groups;
+ /**
+ * @events_lock: Lock taken when processing events.
+ *
+ * This also needs to be taken when csg_slots are updated, to make sure
+ * the event processing logic doesn't touch groups that have left the CSG
+ * slot.
+ */
+ spinlock_t events_lock;
+
/**
* @csg_slots: FW command stream group slots.
+ *
+ * Updates to these slots must happen with both panthor_scheduler::lock and
+ * panthor_scheduler::events_lock held. As a result, reads can happen with
+ * either of these locks held.
*/
struct panthor_csg_slot csg_slots[MAX_CSGS];
@@ -565,8 +578,13 @@ struct panthor_group {
/** @idle_queues: Bitmask reflecting the idle queues. */
u32 idle_queues;
- /** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
- u32 fatal_queues;
+ /**
+ * @fatal_queues: Bitmask reflecting the queues that hit a fatal exception.
+ *
+ * This is an atomic because we don't want to acquire the events_lock
+ * every time we need to check the group state.
+ */
+ atomic_t fatal_queues;
/** @tiler_oom: Mask of queues that have a tiler OOM event to process. */
atomic_t tiler_oom;
@@ -602,8 +620,14 @@ struct panthor_group {
* any timeout situation is unrecoverable, and the group becomes useless. We
* simply wait for all references to be dropped so we can release the group
* object.
+ *
+ * This is an atomic because it can be set from both a scheduling context
+ * (protected with panthor_scheduler::lock) and an event processing context
+ * (protected with panthor_scheduler::events_lock). We could protect access
+ * with the events_lock, but this is simpler to make it an atomic since the
+ * only allowed transition is false -> true.
*/
- bool timedout;
+ atomic_t timedout;
/**
* @innocent: True when the group becomes unusable because the group suspension
@@ -996,7 +1020,6 @@ static int
group_bind_locked(struct panthor_group *group, u32 csg_id)
{
struct panthor_device *ptdev = group->ptdev;
- struct panthor_csg_slot *csg_slot;
int ret;
lockdep_assert_held(&ptdev->scheduler->lock);
@@ -1009,9 +1032,7 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
if (ret)
return ret;
- csg_slot = &ptdev->scheduler->csg_slots[csg_id];
group_get(group);
- group->csg_id = csg_id;
/* Dummy doorbell allocation: doorbell is assigned to the group and
* all queues use the same doorbell.
@@ -1023,7 +1044,10 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
for (u32 i = 0; i < group->queue_count; i++)
group->queues[i]->doorbell_id = csg_id + 1;
- csg_slot->group = group;
+ scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
+ ptdev->scheduler->csg_slots[csg_id].group = group;
+ group->csg_id = csg_id;
+ }
return 0;
}
@@ -1038,7 +1062,6 @@ static int
group_unbind_locked(struct panthor_group *group)
{
struct panthor_device *ptdev = group->ptdev;
- struct panthor_csg_slot *slot;
lockdep_assert_held(&ptdev->scheduler->lock);
@@ -1048,9 +1071,12 @@ group_unbind_locked(struct panthor_group *group)
if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
return -EINVAL;
- slot = &ptdev->scheduler->csg_slots[group->csg_id];
+ scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
+ ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
+ group->csg_id = -1;
+ }
+
panthor_vm_idle(group->vm);
- group->csg_id = -1;
/* Tiler OOM events will be re-issued next time the group is scheduled. */
atomic_set(&group->tiler_oom, 0);
@@ -1060,8 +1086,6 @@ group_unbind_locked(struct panthor_group *group)
for (u32 i = 0; i < group->queue_count; i++)
group->queues[i]->doorbell_id = -1;
- slot->group = NULL;
-
group_put(group);
return 0;
}
@@ -1079,8 +1103,9 @@ group_can_run(struct panthor_group *group)
{
return group->state != PANTHOR_CS_GROUP_TERMINATED &&
group->state != PANTHOR_CS_GROUP_UNKNOWN_STATE &&
- !group->destroyed && group->fatal_queues == 0 &&
- !group->timedout;
+ !group->destroyed &&
+ !atomic_read(&group->fatal_queues) &&
+ !atomic_read(&group->timedout);
}
static bool
@@ -1479,7 +1504,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
u32 fatal;
u64 info;
- lockdep_assert_held(&sched->lock);
+ lockdep_assert_held(&sched->events_lock);
cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
fatal = cs_iface->output->fatal;
@@ -1489,7 +1514,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
drm_warn(&ptdev->base, "CS_FATAL: pid=%d, comm=%s\n",
group->task_info.pid, group->task_info.comm);
- group->fatal_queues |= BIT(cs_id);
+ atomic_or(BIT(cs_id), &group->fatal_queues);
}
if (CS_EXCEPTION_TYPE(fatal) == DRM_PANTHOR_EXCEPTION_CS_UNRECOVERABLE) {
@@ -1527,7 +1552,7 @@ cs_slot_process_fault_event_locked(struct panthor_device *ptdev,
u32 fault;
u64 info;
- lockdep_assert_held(&sched->lock);
+ lockdep_assert_held(&sched->events_lock);
cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
fault = cs_iface->output->fault;
@@ -1619,7 +1644,7 @@ static int group_process_tiler_oom(struct panthor_group *group, u32 cs_id)
*/
if (ret && ret != -ENOMEM) {
drm_warn(&ptdev->base, "Failed to extend the tiler heap\n");
- group->fatal_queues |= BIT(cs_id);
+ atomic_or(BIT(cs_id), &group->fatal_queues);
sched_queue_delayed_work(sched, tick, 0);
goto out_put_heap_pool;
}
@@ -1679,7 +1704,7 @@ cs_slot_process_tiler_oom_event_locked(struct panthor_device *ptdev,
struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
struct panthor_group *group = csg_slot->group;
- lockdep_assert_held(&sched->lock);
+ lockdep_assert_held(&sched->events_lock);
if (drm_WARN_ON(&ptdev->base, !group))
return;
@@ -1700,7 +1725,7 @@ static bool cs_slot_process_irq_locked(struct panthor_device *ptdev,
struct panthor_fw_cs_iface *cs_iface;
u32 req, ack, events;
- lockdep_assert_held(&ptdev->scheduler->lock);
+ lockdep_assert_held(&ptdev->scheduler->events_lock);
cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
req = cs_iface->input->req;
@@ -1728,7 +1753,7 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
{
struct panthor_scheduler *sched = ptdev->scheduler;
- lockdep_assert_held(&sched->lock);
+ lockdep_assert_held(&sched->events_lock);
/* Schedule a tick so we can evict idle groups and schedule non-idle
* ones. This will also update runtime PM and devfreq busy/idle states,
@@ -1743,7 +1768,7 @@ static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
struct panthor_csg_slot *csg_slot = &ptdev->scheduler->csg_slots[csg_id];
struct panthor_group *group = csg_slot->group;
- lockdep_assert_held(&ptdev->scheduler->lock);
+ lockdep_assert_held(&ptdev->scheduler->events_lock);
if (group)
group_queue_work(group, sync_upd);
@@ -1758,14 +1783,14 @@ csg_slot_process_progress_timer_event_locked(struct panthor_device *ptdev, u32 c
struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
struct panthor_group *group = csg_slot->group;
- lockdep_assert_held(&sched->lock);
+ lockdep_assert_held(&sched->events_lock);
group = csg_slot->group;
if (!drm_WARN_ON(&ptdev->base, !group)) {
drm_warn(&ptdev->base, "CSG_PROGRESS_TIMER_EVENT: pid=%d, comm=%s\n",
group->task_info.pid, group->task_info.comm);
- group->timedout = true;
+ atomic_set(&group->timedout, true);
}
drm_warn(&ptdev->base, "CSG slot %d progress timeout\n", csg_id);
@@ -1779,7 +1804,7 @@ static void sched_process_csg_irq_locked(struct panthor_device *ptdev, u32 csg_i
struct panthor_fw_csg_iface *csg_iface;
u32 ring_cs_db_mask = 0;
- lockdep_assert_held(&ptdev->scheduler->lock);
+ lockdep_assert_held(&ptdev->scheduler->events_lock);
if (drm_WARN_ON(&ptdev->base, csg_id >= ptdev->scheduler->csg_slot_count))
return;
@@ -1837,7 +1862,7 @@ static void sched_process_idle_event_locked(struct panthor_device *ptdev)
{
struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
- lockdep_assert_held(&ptdev->scheduler->lock);
+ lockdep_assert_held(&ptdev->scheduler->events_lock);
/* Acknowledge the idle event and schedule a tick. */
panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack, GLB_IDLE);
@@ -1853,7 +1878,7 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
u32 req, ack, evts;
- lockdep_assert_held(&ptdev->scheduler->lock);
+ lockdep_assert_held(&ptdev->scheduler->events_lock);
req = READ_ONCE(glb_iface->input->req);
ack = READ_ONCE(glb_iface->output->ack);
@@ -1870,7 +1895,7 @@ static void process_fw_events_work(struct work_struct *work)
u32 events = atomic_xchg(&sched->fw_events, 0);
struct panthor_device *ptdev = sched->ptdev;
- mutex_lock(&sched->lock);
+ guard(spinlock)(&sched->events_lock);
if (events & JOB_INT_GLOBAL_IF) {
sched_process_global_irq_locked(ptdev);
@@ -1883,8 +1908,6 @@ static void process_fw_events_work(struct work_struct *work)
sched_process_csg_irq_locked(ptdev, csg_id);
events &= ~BIT(csg_id);
}
-
- mutex_unlock(&sched->lock);
}
/**
@@ -2131,11 +2154,12 @@ tick_ctx_init(struct panthor_scheduler *sched,
* CSG IRQs, so we can flag the faulty queue.
*/
if (panthor_vm_has_unhandled_faults(group->vm)) {
- sched_process_csg_irq_locked(ptdev, i);
+ scoped_guard(spinlock, &sched->events_lock)
+ sched_process_csg_irq_locked(ptdev, i);
/* No fatal fault reported, flag all queues as faulty. */
- if (!group->fatal_queues)
- group->fatal_queues |= GENMASK(group->queue_count - 1, 0);
+ atomic_cmpxchg(&group->fatal_queues, 0,
+ GENMASK(group->queue_count - 1, 0));
}
tick_ctx_insert_old_group(sched, ctx, group);
@@ -2168,9 +2192,9 @@ group_term_post_processing(struct panthor_group *group)
struct panthor_syncobj_64b *syncobj;
int err;
- if (group->fatal_queues & BIT(i))
+ if (atomic_read(&group->fatal_queues) & BIT(i))
err = -EINVAL;
- else if (group->timedout)
+ else if (atomic_read(&group->timedout))
err = -ETIMEDOUT;
else
err = -ECANCELED;
@@ -2331,8 +2355,10 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
* any pending interrupts before we start the new
* group.
*/
- if (group->csg_id >= 0)
+ if (group->csg_id >= 0) {
+ guard(spinlock)(&sched->events_lock);
sched_process_csg_irq_locked(ptdev, group->csg_id);
+ }
group_unbind_locked(group);
}
@@ -2861,7 +2887,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
/* We consider group suspension failures as fatal and flag the
* group as unusable by setting timedout=true.
*/
- csg_slot->group->timedout = true;
+ atomic_set(&csg_slot->group->timedout, true);
csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
CSG_STATE_TERMINATE,
@@ -2910,10 +2936,12 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
u32 csg_id = ffs(slot_mask) - 1;
struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
- if (flush_caches_failed)
+ if (flush_caches_failed) {
csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
- else
+ } else {
+ guard(spinlock)(&sched->events_lock);
csg_slot_sync_update_locked(ptdev, csg_id);
+ }
slot_mask &= ~BIT(csg_id);
}
@@ -2928,8 +2956,10 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
group_get(group);
- if (group->csg_id >= 0)
+ if (group->csg_id >= 0) {
+ guard(spinlock)(&sched->events_lock);
sched_process_csg_irq_locked(ptdev, group->csg_id);
+ }
group_unbind_locked(group);
@@ -3421,7 +3451,7 @@ queue_timedout_job(struct drm_sched_job *sched_job)
queue_stop(queue, job);
mutex_lock(&sched->lock);
- group->timedout = true;
+ atomic_set(&group->timedout, true);
if (group->csg_id >= 0) {
sched_queue_delayed_work(ptdev->scheduler, tick, 0);
} else {
@@ -3843,12 +3873,13 @@ int panthor_group_get_state(struct panthor_file *pfile,
memset(get_state, 0, sizeof(*get_state));
mutex_lock(&sched->lock);
- if (group->timedout)
+ if (atomic_read(&group->timedout))
get_state->state |= DRM_PANTHOR_GROUP_STATE_TIMEDOUT;
- if (group->fatal_queues) {
+
+ get_state->fatal_queues = atomic_read(&group->fatal_queues);
+ if (get_state->fatal_queues)
get_state->state |= DRM_PANTHOR_GROUP_STATE_FATAL_FAULT;
- get_state->fatal_queues = group->fatal_queues;
- }
+
if (group->innocent)
get_state->state |= DRM_PANTHOR_GROUP_STATE_INNOCENT;
mutex_unlock(&sched->lock);
@@ -4146,6 +4177,8 @@ int panthor_sched_init(struct panthor_device *ptdev)
INIT_WORK(&sched->sync_upd_work, sync_upd_work);
INIT_WORK(&sched->fw_events_work, process_fw_events_work);
+ spin_lock_init(&sched->events_lock);
+
ret = drmm_mutex_init(&ptdev->base, &sched->lock);
if (ret)
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 7/9] drm/panthor: Don't defer job completion checks
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (5 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-17 15:29 ` Steven Price
2026-08-11 11:23 ` [PATCH v6 8/9] drm/panthor: Don't defer FW event processing Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time Boris Brezillon
8 siblings, 1 reply; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Call group_check_job_completion() directly from
csg_slot_sync_update_locked() instead of deferring it.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 182 +++++++++++++++-----------------
1 file changed, 87 insertions(+), 95 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 794105e239e6..1ef9da55030c 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -697,9 +697,6 @@ struct panthor_group {
*/
struct panthor_kernel_bo *protm_suspend_buf;
- /** @sync_upd_work: Work used to check/signal job fences. */
- struct work_struct sync_upd_work;
-
/** @tiler_oom_work: Work used to process tiler OOM events happening on this group. */
struct work_struct tiler_oom_work;
@@ -1762,6 +1759,92 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
sched_queue_delayed_work(sched, tick, 0);
}
+static void update_fdinfo_stats(struct panthor_job *job)
+{
+ struct panthor_group *group = job->group;
+ struct panthor_queue *queue = group->queues[job->queue_idx];
+ struct panthor_gpu_usage *fdinfo = &group->fdinfo.data;
+ struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
+ struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
+
+ scoped_guard(spinlock_irqsave, &group->fdinfo.lock) {
+ if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
+ fdinfo->cycles += data->cycles.after - data->cycles.before;
+ if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
+ fdinfo->time += data->time.after - data->time.before;
+ }
+}
+
+static bool queue_check_job_completion(struct panthor_queue *queue)
+{
+ struct panthor_syncobj_64b *syncobj = NULL;
+ struct panthor_job *job, *job_tmp;
+ bool cookie, progress = false;
+ LIST_HEAD(done_jobs);
+
+ cookie = dma_fence_begin_signalling();
+ scoped_guard(spinlock_irqsave, &queue->fence_ctx.lock) {
+ list_for_each_entry_safe(job, job_tmp, &queue->fence_ctx.in_flight_jobs, node) {
+ if (!syncobj) {
+ struct panthor_group *group = job->group;
+
+ syncobj = group->syncobjs->kmap +
+ (job->queue_idx * sizeof(*syncobj));
+ }
+
+ if (syncobj->seqno < job->done_fence->seqno)
+ break;
+
+ list_move_tail(&job->node, &done_jobs);
+ dma_fence_signal_locked(job->done_fence);
+ }
+
+ if (list_empty(&queue->fence_ctx.in_flight_jobs)) {
+ /* If we have no job left, we cancel the timer, and reset remaining
+ * time to its default so it can be restarted next time
+ * queue_resume_timeout() is called.
+ */
+ queue_suspend_timeout_locked(queue);
+
+ /* If there's no job pending, we consider it progress to avoid a
+ * spurious timeout if the timeout handler and the sync update
+ * handler raced.
+ */
+ progress = true;
+ } else if (!list_empty(&done_jobs)) {
+ queue_reset_timeout_locked(queue);
+ progress = true;
+ }
+ }
+ dma_fence_end_signalling(cookie);
+
+ list_for_each_entry_safe(job, job_tmp, &done_jobs, node) {
+ if (job->profiling.mask)
+ update_fdinfo_stats(job);
+ list_del_init(&job->node);
+ panthor_job_put(&job->base);
+ }
+
+ return progress;
+}
+
+static void group_check_job_completion(struct panthor_group *group)
+{
+ u32 queue_idx;
+ bool cookie;
+
+ cookie = dma_fence_begin_signalling();
+ for (queue_idx = 0; queue_idx < group->queue_count; queue_idx++) {
+ struct panthor_queue *queue = group->queues[queue_idx];
+
+ if (!queue)
+ continue;
+
+ queue_check_job_completion(queue);
+ }
+ dma_fence_end_signalling(cookie);
+}
+
static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
u32 csg_id)
{
@@ -1771,7 +1854,7 @@ static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
lockdep_assert_held(&ptdev->scheduler->events_lock);
if (group)
- group_queue_work(group, sync_upd);
+ group_check_job_completion(group);
sched_queue_work(ptdev->scheduler, sync_upd);
}
@@ -3043,22 +3126,6 @@ void panthor_sched_post_reset(struct panthor_device *ptdev, bool reset_failed)
}
}
-static void update_fdinfo_stats(struct panthor_job *job)
-{
- struct panthor_group *group = job->group;
- struct panthor_queue *queue = group->queues[job->queue_idx];
- struct panthor_gpu_usage *fdinfo = &group->fdinfo.data;
- struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
- struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
-
- scoped_guard(spinlock, &group->fdinfo.lock) {
- if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
- fdinfo->cycles += data->cycles.after - data->cycles.before;
- if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
- fdinfo->time += data->time.after - data->time.before;
- }
-}
-
void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
{
struct panthor_group_pool *gpool = pfile->groups;
@@ -3079,80 +3146,6 @@ void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
xa_unlock(&gpool->xa);
}
-static bool queue_check_job_completion(struct panthor_queue *queue)
-{
- struct panthor_syncobj_64b *syncobj = NULL;
- struct panthor_job *job, *job_tmp;
- bool cookie, progress = false;
- LIST_HEAD(done_jobs);
-
- cookie = dma_fence_begin_signalling();
- scoped_guard(spinlock_irqsave, &queue->fence_ctx.lock) {
- list_for_each_entry_safe(job, job_tmp, &queue->fence_ctx.in_flight_jobs, node) {
- if (!syncobj) {
- struct panthor_group *group = job->group;
-
- syncobj = group->syncobjs->kmap +
- (job->queue_idx * sizeof(*syncobj));
- }
-
- if (syncobj->seqno < job->done_fence->seqno)
- break;
-
- list_move_tail(&job->node, &done_jobs);
- dma_fence_signal_locked(job->done_fence);
- }
-
- if (list_empty(&queue->fence_ctx.in_flight_jobs)) {
- /* If we have no job left, we cancel the timer, and reset remaining
- * time to its default so it can be restarted next time
- * queue_resume_timeout() is called.
- */
- queue_suspend_timeout_locked(queue);
-
- /* If there's no job pending, we consider it progress to avoid a
- * spurious timeout if the timeout handler and the sync update
- * handler raced.
- */
- progress = true;
- } else if (!list_empty(&done_jobs)) {
- queue_reset_timeout_locked(queue);
- progress = true;
- }
- }
- dma_fence_end_signalling(cookie);
-
- list_for_each_entry_safe(job, job_tmp, &done_jobs, node) {
- if (job->profiling.mask)
- update_fdinfo_stats(job);
- list_del_init(&job->node);
- panthor_job_put(&job->base);
- }
-
- return progress;
-}
-
-static void group_sync_upd_work(struct work_struct *work)
-{
- struct panthor_group *group =
- container_of(work, struct panthor_group, sync_upd_work);
- u32 queue_idx;
- bool cookie;
-
- cookie = dma_fence_begin_signalling();
- for (queue_idx = 0; queue_idx < group->queue_count; queue_idx++) {
- struct panthor_queue *queue = group->queues[queue_idx];
-
- if (!queue)
- continue;
-
- queue_check_job_completion(queue);
- }
- dma_fence_end_signalling(cookie);
-
- group_put(group);
-}
-
struct panthor_job_ringbuf_instrs {
u64 buffer[MAX_INSTRS_PER_JOB];
u32 count;
@@ -3718,7 +3711,6 @@ int panthor_group_create(struct panthor_file *pfile,
INIT_LIST_HEAD(&group->wait_node);
INIT_LIST_HEAD(&group->run_node);
INIT_WORK(&group->term_work, group_term_work);
- INIT_WORK(&group->sync_upd_work, group_sync_upd_work);
INIT_WORK(&group->tiler_oom_work, group_tiler_oom_work);
INIT_WORK(&group->release_work, group_release_work);
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 8/9] drm/panthor: Don't defer FW event processing
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (6 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 7/9] drm/panthor: Don't defer job completion checks Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-17 15:35 ` Steven Price
2026-08-18 17:15 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time Boris Brezillon
8 siblings, 2 replies; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Avoid a workqueue roundtrip and process things immediately from
panthor_sched_report_fw_events().
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 48 +++++++--------------------------
1 file changed, 9 insertions(+), 39 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 1ef9da55030c..8016b0a55173 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -177,23 +177,6 @@ struct panthor_scheduler {
*/
struct work_struct sync_upd_work;
- /**
- * @fw_events_work: Work used to process FW events outside the interrupt path.
- *
- * Even if the interrupt is threaded, we need any event processing
- * that require taking the panthor_scheduler::lock to be processed
- * outside the interrupt path so we don't block the tick logic when
- * it calls panthor_fw_{csg,wait}_wait_acks(). Since most of the
- * event processing requires taking this lock, we just delegate all
- * FW event processing to the scheduler workqueue.
- */
- struct work_struct fw_events_work;
-
- /**
- * @fw_events: Bitmask encoding pending FW events.
- */
- atomic_t fw_events;
-
/**
* @resched_target: When the next tick should occur.
*
@@ -1971,14 +1954,17 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
sched_process_idle_event_locked(ptdev);
}
-static void process_fw_events_work(struct work_struct *work)
+/**
+ * panthor_sched_report_fw_events() - Report FW events to the scheduler.
+ * @ptdev: Device.
+ * @events: Bitmask of pending FW events to report.
+ */
+void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
{
- struct panthor_scheduler *sched = container_of(work, struct panthor_scheduler,
- fw_events_work);
- u32 events = atomic_xchg(&sched->fw_events, 0);
- struct panthor_device *ptdev = sched->ptdev;
+ if (!ptdev->scheduler)
+ return;
- guard(spinlock)(&sched->events_lock);
+ guard(spinlock)(&ptdev->scheduler->events_lock);
if (events & JOB_INT_GLOBAL_IF) {
sched_process_global_irq_locked(ptdev);
@@ -1993,20 +1979,6 @@ static void process_fw_events_work(struct work_struct *work)
}
}
-/**
- * panthor_sched_report_fw_events() - Report FW events to the scheduler.
- * @ptdev: Device.
- * @events: Bitmask of pending FW events to report.
- */
-void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
-{
- if (!ptdev->scheduler)
- return;
-
- atomic_or(events, &ptdev->scheduler->fw_events);
- sched_queue_work(ptdev->scheduler, fw_events);
-}
-
static const char *fence_get_driver_name(struct dma_fence *fence)
{
return "panthor";
@@ -4082,7 +4054,6 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
struct panthor_scheduler *sched = ptdev->scheduler;
disable_delayed_work_sync(&sched->tick_work);
- disable_work_sync(&sched->fw_events_work);
disable_work_sync(&sched->sync_upd_work);
mutex_lock(&sched->lock);
@@ -4167,7 +4138,6 @@ int panthor_sched_init(struct panthor_device *ptdev)
sched->tick_period = msecs_to_jiffies(10);
INIT_DELAYED_WORK(&sched->tick_work, tick_work);
INIT_WORK(&sched->sync_upd_work, sync_upd_work);
- INIT_WORK(&sched->fw_events_work, process_fw_events_work);
spin_lock_init(&sched->events_lock);
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
` (7 preceding siblings ...)
2026-08-11 11:23 ` [PATCH v6 8/9] drm/panthor: Don't defer FW event processing Boris Brezillon
@ 2026-08-11 11:23 ` Boris Brezillon
2026-08-18 17:20 ` Liviu Dudau
8 siblings, 1 reply; 21+ messages in thread
From: Boris Brezillon @ 2026-08-11 11:23 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel, Boris Brezillon
Make the sched_process_csg_irq_locked() call part of
group_unbind_locked() so we don't have to manually call it in
tick_ctx_apply()/panthor_sched_suspend().
This implies moving group_[un]bind_locked() around to avoid a
forward declaration.
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 182 +++++++++++++++-----------------
1 file changed, 84 insertions(+), 98 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 8016b0a55173..57308cd90e96 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -989,87 +989,6 @@ group_get(struct panthor_group *group)
return group;
}
-/**
- * group_bind_locked() - Bind a group to a group slot
- * @group: Group.
- * @csg_id: Slot.
- *
- * Return: 0 on success, a negative error code otherwise.
- */
-static int
-group_bind_locked(struct panthor_group *group, u32 csg_id)
-{
- struct panthor_device *ptdev = group->ptdev;
- int ret;
-
- lockdep_assert_held(&ptdev->scheduler->lock);
-
- if (drm_WARN_ON(&ptdev->base, group->csg_id != -1 || csg_id >= MAX_CSGS ||
- ptdev->scheduler->csg_slots[csg_id].group))
- return -EINVAL;
-
- ret = panthor_vm_active(group->vm);
- if (ret)
- return ret;
-
- group_get(group);
-
- /* Dummy doorbell allocation: doorbell is assigned to the group and
- * all queues use the same doorbell.
- *
- * TODO: Implement LRU-based doorbell assignment, so the most often
- * updated queues get their own doorbell, thus avoiding useless checks
- * on queues belonging to the same group that are rarely updated.
- */
- for (u32 i = 0; i < group->queue_count; i++)
- group->queues[i]->doorbell_id = csg_id + 1;
-
- scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
- ptdev->scheduler->csg_slots[csg_id].group = group;
- group->csg_id = csg_id;
- }
-
- return 0;
-}
-
-/**
- * group_unbind_locked() - Unbind a group from a slot.
- * @group: Group to unbind.
- *
- * Return: 0 on success, a negative error code otherwise.
- */
-static int
-group_unbind_locked(struct panthor_group *group)
-{
- struct panthor_device *ptdev = group->ptdev;
-
- lockdep_assert_held(&ptdev->scheduler->lock);
-
- if (drm_WARN_ON(&ptdev->base, group->csg_id < 0 || group->csg_id >= MAX_CSGS))
- return -EINVAL;
-
- if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
- return -EINVAL;
-
- scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
- ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
- group->csg_id = -1;
- }
-
- panthor_vm_idle(group->vm);
-
- /* Tiler OOM events will be re-issued next time the group is scheduled. */
- atomic_set(&group->tiler_oom, 0);
- if (cancel_work(&group->tiler_oom_work))
- group_put(group);
-
- for (u32 i = 0; i < group->queue_count; i++)
- group->queues[i]->doorbell_id = -1;
-
- group_put(group);
- return 0;
-}
-
static bool
group_is_idle(struct panthor_group *group)
{
@@ -1979,6 +1898,89 @@ void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
}
}
+/**
+ * group_bind_locked() - Bind a group to a group slot
+ * @group: Group.
+ * @csg_id: Slot.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+static int
+group_bind_locked(struct panthor_group *group, u32 csg_id)
+{
+ struct panthor_device *ptdev = group->ptdev;
+ int ret;
+
+ lockdep_assert_held(&ptdev->scheduler->lock);
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id != -1 || csg_id >= MAX_CSGS ||
+ ptdev->scheduler->csg_slots[csg_id].group))
+ return -EINVAL;
+
+ ret = panthor_vm_active(group->vm);
+ if (ret)
+ return ret;
+
+ group_get(group);
+
+ /* Dummy doorbell allocation: doorbell is assigned to the group and
+ * all queues use the same doorbell.
+ *
+ * TODO: Implement LRU-based doorbell assignment, so the most often
+ * updated queues get their own doorbell, thus avoiding useless checks
+ * on queues belonging to the same group that are rarely updated.
+ */
+ for (u32 i = 0; i < group->queue_count; i++)
+ group->queues[i]->doorbell_id = csg_id + 1;
+
+ scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
+ ptdev->scheduler->csg_slots[csg_id].group = group;
+ group->csg_id = csg_id;
+ }
+
+ return 0;
+}
+
+/**
+ * group_unbind_locked() - Unbind a group from a slot.
+ * @group: Group to unbind.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+static int
+group_unbind_locked(struct panthor_group *group)
+{
+ struct panthor_device *ptdev = group->ptdev;
+
+ lockdep_assert_held(&ptdev->scheduler->lock);
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id < 0 || group->csg_id >= MAX_CSGS))
+ return -EINVAL;
+
+ if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
+ return -EINVAL;
+
+ scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
+ /* Process all pending IRQs before returning the slot. */
+ sched_process_csg_irq_locked(ptdev, group->csg_id);
+ ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
+ group->csg_id = -1;
+ }
+
+ panthor_vm_idle(group->vm);
+
+ /* Tiler OOM events will be re-issued next time the group is scheduled. */
+ atomic_set(&group->tiler_oom, 0);
+ if (cancel_work(&group->tiler_oom_work))
+ group_put(group);
+
+ for (u32 i = 0; i < group->queue_count; i++)
+ group->queues[i]->doorbell_id = -1;
+
+ group_put(group);
+ return 0;
+}
+
static const char *fence_get_driver_name(struct dma_fence *fence)
{
return "panthor";
@@ -2405,18 +2407,8 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
/* Unbind evicted groups. */
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
- list_for_each_entry(group, &ctx->old_groups[prio], run_node) {
- /* This group is gone. Process interrupts to clear
- * any pending interrupts before we start the new
- * group.
- */
- if (group->csg_id >= 0) {
- guard(spinlock)(&sched->events_lock);
- sched_process_csg_irq_locked(ptdev, group->csg_id);
- }
-
+ list_for_each_entry(group, &ctx->old_groups[prio], run_node)
group_unbind_locked(group);
- }
}
for (i = 0; i < sched->csg_slot_count; i++) {
@@ -3010,12 +3002,6 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
continue;
group_get(group);
-
- if (group->csg_id >= 0) {
- guard(spinlock)(&sched->events_lock);
- sched_process_csg_irq_locked(ptdev, group->csg_id);
- }
-
group_unbind_locked(group);
drm_WARN_ON(&group->ptdev->base, !list_empty(&group->run_node));
--
2.55.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked()
2026-08-11 11:23 ` [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked() Boris Brezillon
@ 2026-08-17 15:09 ` Steven Price
2026-08-18 17:08 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Steven Price @ 2026-08-17 15:09 UTC (permalink / raw)
To: Boris Brezillon, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
On 11/08/2026 12:23, Boris Brezillon wrote:
> By scheduling an immediate tick, we already force idleness re-evaluation,
> which gives the scheduler the opportunity to evict idle groups
> and schedule onces that have jobs pending.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 5832dccfc093..baa06731797c 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -1733,8 +1733,6 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
>
> lockdep_assert_held(&sched->lock);
>
> - sched->might_have_idle_groups = true;
> -
> /* Schedule a tick so we can evict idle groups and schedule non-idle
> * ones. This will also update runtime PM and devfreq busy/idle states,
> * so the device can lower its frequency or get suspended.
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock
2026-08-11 11:23 ` [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock Boris Brezillon
@ 2026-08-17 15:12 ` Steven Price
2026-08-18 17:09 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Steven Price @ 2026-08-17 15:12 UTC (permalink / raw)
To: Boris Brezillon, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
On 11/08/2026 12:23, Boris Brezillon wrote:
> This lock is never used, and we're about to make fatal_queues an
> atomic to cope with concurrent updates.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Although it does make me wonder if there's a fix that needs backporting...
Thanks,
Steve
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index baa06731797c..9adf1e21eb83 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -565,9 +565,6 @@ struct panthor_group {
> /** @idle_queues: Bitmask reflecting the idle queues. */
> u32 idle_queues;
>
> - /** @fatal_lock: Lock used to protect access to fatal fields. */
> - spinlock_t fatal_lock;
> -
> /** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
> u32 fatal_queues;
>
> @@ -3675,7 +3672,6 @@ int panthor_group_create(struct panthor_file *pfile,
> if (!group)
> return -ENOMEM;
>
> - spin_lock_init(&group->fatal_lock);
> kref_init(&group->refcount);
> group->state = PANTHOR_CS_GROUP_CREATED;
> group->csg_id = -1;
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock
2026-08-11 11:23 ` [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock Boris Brezillon
@ 2026-08-17 15:21 ` Steven Price
2026-08-18 17:13 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Steven Price @ 2026-08-17 15:21 UTC (permalink / raw)
To: Boris Brezillon, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
On 11/08/2026 12:23, Boris Brezillon wrote:
> Add a specific spinlock for events processing so we can selectively
> move some event processing to the threaded IRQ handler. For events to be
> processed, we need to have access to the group attached to the CSG slot
> which also forces us to protect the csg_slots[] updates with this
> lock.
>
> Note that fatal_queues/timedout are turned into atomics to avoid having
> to take the events_lock every time those are checked or updated.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Although one nit below if you respin.
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 123 ++++++++++++++++++++------------
> 1 file changed, 78 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 9adf1e21eb83..794105e239e6 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -254,8 +254,21 @@ struct panthor_scheduler {
> struct list_head waiting;
> } groups;
>
> + /**
> + * @events_lock: Lock taken when processing events.
> + *
> + * This also needs to be taken when csg_slots are updated, to make sure
> + * the event processing logic doesn't touch groups that have left the CSG
> + * slot.
> + */
> + spinlock_t events_lock;
> +
> /**
> * @csg_slots: FW command stream group slots.
> + *
> + * Updates to these slots must happen with both panthor_scheduler::lock and
> + * panthor_scheduler::events_lock held. As a result, reads can happen with
> + * either of these locks held.
Technically this isn't quite true - priority can be changed with only
sched->lock. Perhaps the following would be slightly more accurate wording?
* Updates to the group binding must happen with both
* panthor_scheduler::lock and panthor_scheduler::events_lock held.
* The group binding may therefore be read while holding either lock.
* Other slot fields are protected by panthor_scheduler::lock.
Thanks,
Steve
> */
> struct panthor_csg_slot csg_slots[MAX_CSGS];
>
> @@ -565,8 +578,13 @@ struct panthor_group {
> /** @idle_queues: Bitmask reflecting the idle queues. */
> u32 idle_queues;
>
> - /** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
> - u32 fatal_queues;
> + /**
> + * @fatal_queues: Bitmask reflecting the queues that hit a fatal exception.
> + *
> + * This is an atomic because we don't want to acquire the events_lock
> + * every time we need to check the group state.
> + */
> + atomic_t fatal_queues;
>
> /** @tiler_oom: Mask of queues that have a tiler OOM event to process. */
> atomic_t tiler_oom;
> @@ -602,8 +620,14 @@ struct panthor_group {
> * any timeout situation is unrecoverable, and the group becomes useless. We
> * simply wait for all references to be dropped so we can release the group
> * object.
> + *
> + * This is an atomic because it can be set from both a scheduling context
> + * (protected with panthor_scheduler::lock) and an event processing context
> + * (protected with panthor_scheduler::events_lock). We could protect access
> + * with the events_lock, but this is simpler to make it an atomic since the
> + * only allowed transition is false -> true.
> */
> - bool timedout;
> + atomic_t timedout;
>
> /**
> * @innocent: True when the group becomes unusable because the group suspension
> @@ -996,7 +1020,6 @@ static int
> group_bind_locked(struct panthor_group *group, u32 csg_id)
> {
> struct panthor_device *ptdev = group->ptdev;
> - struct panthor_csg_slot *csg_slot;
> int ret;
>
> lockdep_assert_held(&ptdev->scheduler->lock);
> @@ -1009,9 +1032,7 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
> if (ret)
> return ret;
>
> - csg_slot = &ptdev->scheduler->csg_slots[csg_id];
> group_get(group);
> - group->csg_id = csg_id;
>
> /* Dummy doorbell allocation: doorbell is assigned to the group and
> * all queues use the same doorbell.
> @@ -1023,7 +1044,10 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
> for (u32 i = 0; i < group->queue_count; i++)
> group->queues[i]->doorbell_id = csg_id + 1;
>
> - csg_slot->group = group;
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + ptdev->scheduler->csg_slots[csg_id].group = group;
> + group->csg_id = csg_id;
> + }
>
> return 0;
> }
> @@ -1038,7 +1062,6 @@ static int
> group_unbind_locked(struct panthor_group *group)
> {
> struct panthor_device *ptdev = group->ptdev;
> - struct panthor_csg_slot *slot;
>
> lockdep_assert_held(&ptdev->scheduler->lock);
>
> @@ -1048,9 +1071,12 @@ group_unbind_locked(struct panthor_group *group)
> if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
> return -EINVAL;
>
> - slot = &ptdev->scheduler->csg_slots[group->csg_id];
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
> + group->csg_id = -1;
> + }
> +
> panthor_vm_idle(group->vm);
> - group->csg_id = -1;
>
> /* Tiler OOM events will be re-issued next time the group is scheduled. */
> atomic_set(&group->tiler_oom, 0);
> @@ -1060,8 +1086,6 @@ group_unbind_locked(struct panthor_group *group)
> for (u32 i = 0; i < group->queue_count; i++)
> group->queues[i]->doorbell_id = -1;
>
> - slot->group = NULL;
> -
> group_put(group);
> return 0;
> }
> @@ -1079,8 +1103,9 @@ group_can_run(struct panthor_group *group)
> {
> return group->state != PANTHOR_CS_GROUP_TERMINATED &&
> group->state != PANTHOR_CS_GROUP_UNKNOWN_STATE &&
> - !group->destroyed && group->fatal_queues == 0 &&
> - !group->timedout;
> + !group->destroyed &&
> + !atomic_read(&group->fatal_queues) &&
> + !atomic_read(&group->timedout);
> }
>
> static bool
> @@ -1479,7 +1504,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
> u32 fatal;
> u64 info;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> fatal = cs_iface->output->fatal;
> @@ -1489,7 +1514,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
> drm_warn(&ptdev->base, "CS_FATAL: pid=%d, comm=%s\n",
> group->task_info.pid, group->task_info.comm);
>
> - group->fatal_queues |= BIT(cs_id);
> + atomic_or(BIT(cs_id), &group->fatal_queues);
> }
>
> if (CS_EXCEPTION_TYPE(fatal) == DRM_PANTHOR_EXCEPTION_CS_UNRECOVERABLE) {
> @@ -1527,7 +1552,7 @@ cs_slot_process_fault_event_locked(struct panthor_device *ptdev,
> u32 fault;
> u64 info;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> fault = cs_iface->output->fault;
> @@ -1619,7 +1644,7 @@ static int group_process_tiler_oom(struct panthor_group *group, u32 cs_id)
> */
> if (ret && ret != -ENOMEM) {
> drm_warn(&ptdev->base, "Failed to extend the tiler heap\n");
> - group->fatal_queues |= BIT(cs_id);
> + atomic_or(BIT(cs_id), &group->fatal_queues);
> sched_queue_delayed_work(sched, tick, 0);
> goto out_put_heap_pool;
> }
> @@ -1679,7 +1704,7 @@ cs_slot_process_tiler_oom_event_locked(struct panthor_device *ptdev,
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> if (drm_WARN_ON(&ptdev->base, !group))
> return;
> @@ -1700,7 +1725,7 @@ static bool cs_slot_process_irq_locked(struct panthor_device *ptdev,
> struct panthor_fw_cs_iface *cs_iface;
> u32 req, ack, events;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> req = cs_iface->input->req;
> @@ -1728,7 +1753,7 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
> {
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> /* Schedule a tick so we can evict idle groups and schedule non-idle
> * ones. This will also update runtime PM and devfreq busy/idle states,
> @@ -1743,7 +1768,7 @@ static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
> struct panthor_csg_slot *csg_slot = &ptdev->scheduler->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> if (group)
> group_queue_work(group, sync_upd);
> @@ -1758,14 +1783,14 @@ csg_slot_process_progress_timer_event_locked(struct panthor_device *ptdev, u32 c
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> group = csg_slot->group;
> if (!drm_WARN_ON(&ptdev->base, !group)) {
> drm_warn(&ptdev->base, "CSG_PROGRESS_TIMER_EVENT: pid=%d, comm=%s\n",
> group->task_info.pid, group->task_info.comm);
>
> - group->timedout = true;
> + atomic_set(&group->timedout, true);
> }
>
> drm_warn(&ptdev->base, "CSG slot %d progress timeout\n", csg_id);
> @@ -1779,7 +1804,7 @@ static void sched_process_csg_irq_locked(struct panthor_device *ptdev, u32 csg_i
> struct panthor_fw_csg_iface *csg_iface;
> u32 ring_cs_db_mask = 0;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> if (drm_WARN_ON(&ptdev->base, csg_id >= ptdev->scheduler->csg_slot_count))
> return;
> @@ -1837,7 +1862,7 @@ static void sched_process_idle_event_locked(struct panthor_device *ptdev)
> {
> struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> /* Acknowledge the idle event and schedule a tick. */
> panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack, GLB_IDLE);
> @@ -1853,7 +1878,7 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
> struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
> u32 req, ack, evts;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> req = READ_ONCE(glb_iface->input->req);
> ack = READ_ONCE(glb_iface->output->ack);
> @@ -1870,7 +1895,7 @@ static void process_fw_events_work(struct work_struct *work)
> u32 events = atomic_xchg(&sched->fw_events, 0);
> struct panthor_device *ptdev = sched->ptdev;
>
> - mutex_lock(&sched->lock);
> + guard(spinlock)(&sched->events_lock);
>
> if (events & JOB_INT_GLOBAL_IF) {
> sched_process_global_irq_locked(ptdev);
> @@ -1883,8 +1908,6 @@ static void process_fw_events_work(struct work_struct *work)
> sched_process_csg_irq_locked(ptdev, csg_id);
> events &= ~BIT(csg_id);
> }
> -
> - mutex_unlock(&sched->lock);
> }
>
> /**
> @@ -2131,11 +2154,12 @@ tick_ctx_init(struct panthor_scheduler *sched,
> * CSG IRQs, so we can flag the faulty queue.
> */
> if (panthor_vm_has_unhandled_faults(group->vm)) {
> - sched_process_csg_irq_locked(ptdev, i);
> + scoped_guard(spinlock, &sched->events_lock)
> + sched_process_csg_irq_locked(ptdev, i);
>
> /* No fatal fault reported, flag all queues as faulty. */
> - if (!group->fatal_queues)
> - group->fatal_queues |= GENMASK(group->queue_count - 1, 0);
> + atomic_cmpxchg(&group->fatal_queues, 0,
> + GENMASK(group->queue_count - 1, 0));
> }
>
> tick_ctx_insert_old_group(sched, ctx, group);
> @@ -2168,9 +2192,9 @@ group_term_post_processing(struct panthor_group *group)
> struct panthor_syncobj_64b *syncobj;
> int err;
>
> - if (group->fatal_queues & BIT(i))
> + if (atomic_read(&group->fatal_queues) & BIT(i))
> err = -EINVAL;
> - else if (group->timedout)
> + else if (atomic_read(&group->timedout))
> err = -ETIMEDOUT;
> else
> err = -ECANCELED;
> @@ -2331,8 +2355,10 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
> * any pending interrupts before we start the new
> * group.
> */
> - if (group->csg_id >= 0)
> + if (group->csg_id >= 0) {
> + guard(spinlock)(&sched->events_lock);
> sched_process_csg_irq_locked(ptdev, group->csg_id);
> + }
>
> group_unbind_locked(group);
> }
> @@ -2861,7 +2887,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
> /* We consider group suspension failures as fatal and flag the
> * group as unusable by setting timedout=true.
> */
> - csg_slot->group->timedout = true;
> + atomic_set(&csg_slot->group->timedout, true);
>
> csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
> CSG_STATE_TERMINATE,
> @@ -2910,10 +2936,12 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
> u32 csg_id = ffs(slot_mask) - 1;
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
>
> - if (flush_caches_failed)
> + if (flush_caches_failed) {
> csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
> - else
> + } else {
> + guard(spinlock)(&sched->events_lock);
> csg_slot_sync_update_locked(ptdev, csg_id);
> + }
>
> slot_mask &= ~BIT(csg_id);
> }
> @@ -2928,8 +2956,10 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
>
> group_get(group);
>
> - if (group->csg_id >= 0)
> + if (group->csg_id >= 0) {
> + guard(spinlock)(&sched->events_lock);
> sched_process_csg_irq_locked(ptdev, group->csg_id);
> + }
>
> group_unbind_locked(group);
>
> @@ -3421,7 +3451,7 @@ queue_timedout_job(struct drm_sched_job *sched_job)
> queue_stop(queue, job);
>
> mutex_lock(&sched->lock);
> - group->timedout = true;
> + atomic_set(&group->timedout, true);
> if (group->csg_id >= 0) {
> sched_queue_delayed_work(ptdev->scheduler, tick, 0);
> } else {
> @@ -3843,12 +3873,13 @@ int panthor_group_get_state(struct panthor_file *pfile,
> memset(get_state, 0, sizeof(*get_state));
>
> mutex_lock(&sched->lock);
> - if (group->timedout)
> + if (atomic_read(&group->timedout))
> get_state->state |= DRM_PANTHOR_GROUP_STATE_TIMEDOUT;
> - if (group->fatal_queues) {
> +
> + get_state->fatal_queues = atomic_read(&group->fatal_queues);
> + if (get_state->fatal_queues)
> get_state->state |= DRM_PANTHOR_GROUP_STATE_FATAL_FAULT;
> - get_state->fatal_queues = group->fatal_queues;
> - }
> +
> if (group->innocent)
> get_state->state |= DRM_PANTHOR_GROUP_STATE_INNOCENT;
> mutex_unlock(&sched->lock);
> @@ -4146,6 +4177,8 @@ int panthor_sched_init(struct panthor_device *ptdev)
> INIT_WORK(&sched->sync_upd_work, sync_upd_work);
> INIT_WORK(&sched->fw_events_work, process_fw_events_work);
>
> + spin_lock_init(&sched->events_lock);
> +
> ret = drmm_mutex_init(&ptdev->base, &sched->lock);
> if (ret)
> return ret;
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 7/9] drm/panthor: Don't defer job completion checks
2026-08-11 11:23 ` [PATCH v6 7/9] drm/panthor: Don't defer job completion checks Boris Brezillon
@ 2026-08-17 15:29 ` Steven Price
0 siblings, 0 replies; 21+ messages in thread
From: Steven Price @ 2026-08-17 15:29 UTC (permalink / raw)
To: Boris Brezillon, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
On 11/08/2026 12:23, Boris Brezillon wrote:
> Call group_check_job_completion() directly from
> csg_slot_sync_update_locked() instead of deferring it.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 182 +++++++++++++++-----------------
> 1 file changed, 87 insertions(+), 95 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 794105e239e6..1ef9da55030c 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -697,9 +697,6 @@ struct panthor_group {
> */
> struct panthor_kernel_bo *protm_suspend_buf;
>
> - /** @sync_upd_work: Work used to check/signal job fences. */
> - struct work_struct sync_upd_work;
> -
> /** @tiler_oom_work: Work used to process tiler OOM events happening on this group. */
> struct work_struct tiler_oom_work;
>
> @@ -1762,6 +1759,92 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
> sched_queue_delayed_work(sched, tick, 0);
> }
>
> +static void update_fdinfo_stats(struct panthor_job *job)
> +{
> + struct panthor_group *group = job->group;
> + struct panthor_queue *queue = group->queues[job->queue_idx];
> + struct panthor_gpu_usage *fdinfo = &group->fdinfo.data;
> + struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
> + struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
> +
> + scoped_guard(spinlock_irqsave, &group->fdinfo.lock) {
You've switched to spinlock_irqsave here, but
panthor_fdinfo_gather_group_samples() is still using plain spinlock. I
don't think we need the _irqsave as things stand here (we're in a
threaded IRQ handler).
With that fixed:
Reviewed-by: Steven Price <steven.price@arm.com>
Thanks,
Steve
> + if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
> + fdinfo->cycles += data->cycles.after - data->cycles.before;
> + if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
> + fdinfo->time += data->time.after - data->time.before;
> + }
> +}
> +
> +static bool queue_check_job_completion(struct panthor_queue *queue)
> +{
> + struct panthor_syncobj_64b *syncobj = NULL;
> + struct panthor_job *job, *job_tmp;
> + bool cookie, progress = false;
> + LIST_HEAD(done_jobs);
> +
> + cookie = dma_fence_begin_signalling();
> + scoped_guard(spinlock_irqsave, &queue->fence_ctx.lock) {
> + list_for_each_entry_safe(job, job_tmp, &queue->fence_ctx.in_flight_jobs, node) {
> + if (!syncobj) {
> + struct panthor_group *group = job->group;
> +
> + syncobj = group->syncobjs->kmap +
> + (job->queue_idx * sizeof(*syncobj));
> + }
> +
> + if (syncobj->seqno < job->done_fence->seqno)
> + break;
> +
> + list_move_tail(&job->node, &done_jobs);
> + dma_fence_signal_locked(job->done_fence);
> + }
> +
> + if (list_empty(&queue->fence_ctx.in_flight_jobs)) {
> + /* If we have no job left, we cancel the timer, and reset remaining
> + * time to its default so it can be restarted next time
> + * queue_resume_timeout() is called.
> + */
> + queue_suspend_timeout_locked(queue);
> +
> + /* If there's no job pending, we consider it progress to avoid a
> + * spurious timeout if the timeout handler and the sync update
> + * handler raced.
> + */
> + progress = true;
> + } else if (!list_empty(&done_jobs)) {
> + queue_reset_timeout_locked(queue);
> + progress = true;
> + }
> + }
> + dma_fence_end_signalling(cookie);
> +
> + list_for_each_entry_safe(job, job_tmp, &done_jobs, node) {
> + if (job->profiling.mask)
> + update_fdinfo_stats(job);
> + list_del_init(&job->node);
> + panthor_job_put(&job->base);
> + }
> +
> + return progress;
> +}
> +
> +static void group_check_job_completion(struct panthor_group *group)
> +{
> + u32 queue_idx;
> + bool cookie;
> +
> + cookie = dma_fence_begin_signalling();
> + for (queue_idx = 0; queue_idx < group->queue_count; queue_idx++) {
> + struct panthor_queue *queue = group->queues[queue_idx];
> +
> + if (!queue)
> + continue;
> +
> + queue_check_job_completion(queue);
> + }
> + dma_fence_end_signalling(cookie);
> +}
> +
> static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
> u32 csg_id)
> {
> @@ -1771,7 +1854,7 @@ static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
> lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> if (group)
> - group_queue_work(group, sync_upd);
> + group_check_job_completion(group);
>
> sched_queue_work(ptdev->scheduler, sync_upd);
> }
> @@ -3043,22 +3126,6 @@ void panthor_sched_post_reset(struct panthor_device *ptdev, bool reset_failed)
> }
> }
>
> -static void update_fdinfo_stats(struct panthor_job *job)
> -{
> - struct panthor_group *group = job->group;
> - struct panthor_queue *queue = group->queues[job->queue_idx];
> - struct panthor_gpu_usage *fdinfo = &group->fdinfo.data;
> - struct panthor_job_profiling_data *slots = queue->profiling.slots->kmap;
> - struct panthor_job_profiling_data *data = &slots[job->profiling.slot];
> -
> - scoped_guard(spinlock, &group->fdinfo.lock) {
> - if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_CYCLES)
> - fdinfo->cycles += data->cycles.after - data->cycles.before;
> - if (job->profiling.mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP)
> - fdinfo->time += data->time.after - data->time.before;
> - }
> -}
> -
> void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
> {
> struct panthor_group_pool *gpool = pfile->groups;
> @@ -3079,80 +3146,6 @@ void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
> xa_unlock(&gpool->xa);
> }
>
> -static bool queue_check_job_completion(struct panthor_queue *queue)
> -{
> - struct panthor_syncobj_64b *syncobj = NULL;
> - struct panthor_job *job, *job_tmp;
> - bool cookie, progress = false;
> - LIST_HEAD(done_jobs);
> -
> - cookie = dma_fence_begin_signalling();
> - scoped_guard(spinlock_irqsave, &queue->fence_ctx.lock) {
> - list_for_each_entry_safe(job, job_tmp, &queue->fence_ctx.in_flight_jobs, node) {
> - if (!syncobj) {
> - struct panthor_group *group = job->group;
> -
> - syncobj = group->syncobjs->kmap +
> - (job->queue_idx * sizeof(*syncobj));
> - }
> -
> - if (syncobj->seqno < job->done_fence->seqno)
> - break;
> -
> - list_move_tail(&job->node, &done_jobs);
> - dma_fence_signal_locked(job->done_fence);
> - }
> -
> - if (list_empty(&queue->fence_ctx.in_flight_jobs)) {
> - /* If we have no job left, we cancel the timer, and reset remaining
> - * time to its default so it can be restarted next time
> - * queue_resume_timeout() is called.
> - */
> - queue_suspend_timeout_locked(queue);
> -
> - /* If there's no job pending, we consider it progress to avoid a
> - * spurious timeout if the timeout handler and the sync update
> - * handler raced.
> - */
> - progress = true;
> - } else if (!list_empty(&done_jobs)) {
> - queue_reset_timeout_locked(queue);
> - progress = true;
> - }
> - }
> - dma_fence_end_signalling(cookie);
> -
> - list_for_each_entry_safe(job, job_tmp, &done_jobs, node) {
> - if (job->profiling.mask)
> - update_fdinfo_stats(job);
> - list_del_init(&job->node);
> - panthor_job_put(&job->base);
> - }
> -
> - return progress;
> -}
> -
> -static void group_sync_upd_work(struct work_struct *work)
> -{
> - struct panthor_group *group =
> - container_of(work, struct panthor_group, sync_upd_work);
> - u32 queue_idx;
> - bool cookie;
> -
> - cookie = dma_fence_begin_signalling();
> - for (queue_idx = 0; queue_idx < group->queue_count; queue_idx++) {
> - struct panthor_queue *queue = group->queues[queue_idx];
> -
> - if (!queue)
> - continue;
> -
> - queue_check_job_completion(queue);
> - }
> - dma_fence_end_signalling(cookie);
> -
> - group_put(group);
> -}
> -
> struct panthor_job_ringbuf_instrs {
> u64 buffer[MAX_INSTRS_PER_JOB];
> u32 count;
> @@ -3718,7 +3711,6 @@ int panthor_group_create(struct panthor_file *pfile,
> INIT_LIST_HEAD(&group->wait_node);
> INIT_LIST_HEAD(&group->run_node);
> INIT_WORK(&group->term_work, group_term_work);
> - INIT_WORK(&group->sync_upd_work, group_sync_upd_work);
> INIT_WORK(&group->tiler_oom_work, group_tiler_oom_work);
> INIT_WORK(&group->release_work, group_release_work);
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 8/9] drm/panthor: Don't defer FW event processing
2026-08-11 11:23 ` [PATCH v6 8/9] drm/panthor: Don't defer FW event processing Boris Brezillon
@ 2026-08-17 15:35 ` Steven Price
2026-08-18 17:15 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Steven Price @ 2026-08-17 15:35 UTC (permalink / raw)
To: Boris Brezillon, Liviu Dudau, Chia-I Wu
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
On 11/08/2026 12:23, Boris Brezillon wrote:
> Avoid a workqueue roundtrip and process things immediately from
> panthor_sched_report_fw_events().
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 48 +++++++--------------------------
> 1 file changed, 9 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 1ef9da55030c..8016b0a55173 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -177,23 +177,6 @@ struct panthor_scheduler {
> */
> struct work_struct sync_upd_work;
>
> - /**
> - * @fw_events_work: Work used to process FW events outside the interrupt path.
> - *
> - * Even if the interrupt is threaded, we need any event processing
> - * that require taking the panthor_scheduler::lock to be processed
> - * outside the interrupt path so we don't block the tick logic when
> - * it calls panthor_fw_{csg,wait}_wait_acks(). Since most of the
> - * event processing requires taking this lock, we just delegate all
> - * FW event processing to the scheduler workqueue.
> - */
> - struct work_struct fw_events_work;
> -
> - /**
> - * @fw_events: Bitmask encoding pending FW events.
> - */
> - atomic_t fw_events;
> -
> /**
> * @resched_target: When the next tick should occur.
> *
> @@ -1971,14 +1954,17 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
> sched_process_idle_event_locked(ptdev);
> }
>
> -static void process_fw_events_work(struct work_struct *work)
> +/**
> + * panthor_sched_report_fw_events() - Report FW events to the scheduler.
> + * @ptdev: Device.
> + * @events: Bitmask of pending FW events to report.
> + */
> +void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
> {
> - struct panthor_scheduler *sched = container_of(work, struct panthor_scheduler,
> - fw_events_work);
> - u32 events = atomic_xchg(&sched->fw_events, 0);
> - struct panthor_device *ptdev = sched->ptdev;
> + if (!ptdev->scheduler)
> + return;
>
> - guard(spinlock)(&sched->events_lock);
> + guard(spinlock)(&ptdev->scheduler->events_lock);
>
> if (events & JOB_INT_GLOBAL_IF) {
> sched_process_global_irq_locked(ptdev);
> @@ -1993,20 +1979,6 @@ static void process_fw_events_work(struct work_struct *work)
> }
> }
>
> -/**
> - * panthor_sched_report_fw_events() - Report FW events to the scheduler.
> - * @ptdev: Device.
> - * @events: Bitmask of pending FW events to report.
> - */
> -void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
> -{
> - if (!ptdev->scheduler)
> - return;
> -
> - atomic_or(events, &ptdev->scheduler->fw_events);
> - sched_queue_work(ptdev->scheduler, fw_events);
> -}
> -
> static const char *fence_get_driver_name(struct dma_fence *fence)
> {
> return "panthor";
> @@ -4082,7 +4054,6 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> disable_delayed_work_sync(&sched->tick_work);
> - disable_work_sync(&sched->fw_events_work);
> disable_work_sync(&sched->sync_upd_work);
>
> mutex_lock(&sched->lock);
> @@ -4167,7 +4138,6 @@ int panthor_sched_init(struct panthor_device *ptdev)
> sched->tick_period = msecs_to_jiffies(10);
> INIT_DELAYED_WORK(&sched->tick_work, tick_work);
> INIT_WORK(&sched->sync_upd_work, sync_upd_work);
> - INIT_WORK(&sched->fw_events_work, process_fw_events_work);
>
> spin_lock_init(&sched->events_lock);
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers
2026-08-11 11:23 ` [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers Boris Brezillon
@ 2026-08-18 17:08 ` Liviu Dudau
0 siblings, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:08 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:37PM +0200, Boris Brezillon wrote:
> Now that panthor_irq contains the iomem region, there's no real need
> for the macro-based panthor_irq helper generation logic. We can just
> provide inline helpers that do the same and let the compiler optimize
> indirect function calls. The only extra annoyance is the fact we have
> to open-code the panthor_xxx_irq_threaded_handler() implementation, but
> those are single-line functions, so it's acceptable.
>
> While at it, we changed the prototype of the IRQ handlers to take
> a panthor_irq instead of panthor_device, since that's the thing
> that's passed around when it comes to panthor_irq, and the
> panthor_device can be directly extracted from there.
>
> Reviewed-by: Steven Price <steven.price@arm.com>
> Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_device.h | 247 +++++++++++++++----------------
> drivers/gpu/drm/panthor/panthor_fw.c | 22 ++-
> drivers/gpu/drm/panthor/panthor_gpu.c | 28 ++--
> drivers/gpu/drm/panthor/panthor_mmu.c | 39 ++---
> drivers/gpu/drm/panthor/panthor_pwr.c | 24 +--
> 5 files changed, 188 insertions(+), 172 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
> index b102ea77fd1a..b55a3f9edd41 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.h
> +++ b/drivers/gpu/drm/panthor/panthor_device.h
> @@ -571,132 +571,127 @@ static inline u64 gpu_read64_counter(void __iomem *iomem, u32 reg)
> #define INT_MASK 0x8
> #define INT_STAT 0xc
>
> -/**
> - * PANTHOR_IRQ_HANDLER() - Define interrupt handlers and the interrupt
> - * registration function.
> - *
> - * The boiler-plate to gracefully deal with shared interrupts is
> - * auto-generated. All you have to do is call PANTHOR_IRQ_HANDLER()
> - * just after the actual handler. The handler prototype is:
> - *
> - * void (*handler)(struct panthor_device *, u32 status);
> - */
> -#define PANTHOR_IRQ_HANDLER(__name, __handler) \
> -static irqreturn_t panthor_ ## __name ## _irq_raw_handler(int irq, void *data) \
> -{ \
> - struct panthor_irq *pirq = data; \
> - \
> - guard(spinlock_irqsave)(&pirq->lock); \
> - if (pirq->state != PANTHOR_IRQ_STATE_ACTIVE) \
> - return IRQ_NONE; \
> - \
> - if (!gpu_read(pirq->iomem, INT_STAT)) \
> - return IRQ_NONE; \
> - \
> - pirq->state = PANTHOR_IRQ_STATE_PROCESSING; \
> - gpu_write(pirq->iomem, INT_MASK, 0); \
> - return IRQ_WAKE_THREAD; \
> -} \
> - \
> -static irqreturn_t panthor_ ## __name ## _irq_threaded_handler(int irq, void *data) \
> -{ \
> - struct panthor_irq *pirq = data; \
> - struct panthor_device *ptdev = pirq->ptdev; \
> - irqreturn_t ret = IRQ_NONE; \
> - \
> - while (true) { \
> - /* It's safe to access pirq->mask without the lock held here. If a new \
> - * event gets added to the mask and the corresponding IRQ is pending, \
> - * we'll process it right away instead of adding an extra raw -> threaded \
> - * round trip. If an event is removed and the status bit is set, it will \
> - * be ignored, just like it would have been if the mask had been adjusted \
> - * right before the HW event kicks in. TLDR; it's all expected races we're \
> - * covered for. \
> - */ \
> - u32 status = gpu_read(pirq->iomem, INT_RAWSTAT) & pirq->mask; \
> - \
> - if (!status) \
> - break; \
> - \
> - __handler(ptdev, status); \
> - ret = IRQ_HANDLED; \
> - } \
> - \
> - scoped_guard(spinlock_irqsave, &pirq->lock) { \
> - if (pirq->state == PANTHOR_IRQ_STATE_PROCESSING) { \
> - pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
> - gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
> - } \
> - } \
> - \
> - return ret; \
> -} \
> - \
> -static inline void panthor_ ## __name ## _irq_suspend(struct panthor_irq *pirq) \
> -{ \
> - scoped_guard(spinlock_irqsave, &pirq->lock) { \
> - pirq->state = PANTHOR_IRQ_STATE_SUSPENDING; \
> - gpu_write(pirq->iomem, INT_MASK, 0); \
> - } \
> - synchronize_irq(pirq->irq); \
> - scoped_guard(spinlock_irqsave, &pirq->lock) \
> - pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
> -} \
> - \
> -static inline void panthor_ ## __name ## _irq_resume(struct panthor_irq *pirq) \
> -{ \
> - guard(spinlock_irqsave)(&pirq->lock); \
> - \
> - pirq->state = PANTHOR_IRQ_STATE_ACTIVE; \
> - gpu_write(pirq->iomem, INT_CLEAR, pirq->mask); \
> - gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
> -} \
> - \
> -static int panthor_request_ ## __name ## _irq(struct panthor_device *ptdev, \
> - struct panthor_irq *pirq, \
> - int irq, void __iomem *iomem) \
> -{ \
> - pirq->ptdev = ptdev; \
> - pirq->irq = irq; \
> - pirq->mask = 0; \
> - pirq->iomem = iomem; \
> - spin_lock_init(&pirq->lock); \
> - pirq->state = PANTHOR_IRQ_STATE_SUSPENDED; \
> - gpu_write(pirq->iomem, INT_MASK, 0); \
> - \
> - return devm_request_threaded_irq(ptdev->base.dev, irq, \
> - panthor_ ## __name ## _irq_raw_handler, \
> - panthor_ ## __name ## _irq_threaded_handler, \
> - IRQF_SHARED, KBUILD_MODNAME "-" # __name, \
> - pirq); \
> -} \
> - \
> -static inline void panthor_ ## __name ## _irq_enable_events(struct panthor_irq *pirq, u32 mask) \
> -{ \
> - guard(spinlock_irqsave)(&pirq->lock); \
> - pirq->mask |= mask; \
> - \
> - /* The only situation where we need to write the new mask is if the IRQ is active. \
> - * If it's being processed, the mask will be restored for us in _irq_threaded_handler() \
> - * on the PROCESSING -> ACTIVE transition. \
> - * If the IRQ is suspended/suspending, the mask is restored at resume time. \
> - */ \
> - if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
> - gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
> -} \
> - \
> -static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq *pirq, u32 mask)\
> -{ \
> - guard(spinlock_irqsave)(&pirq->lock); \
> - pirq->mask &= ~mask; \
> - \
> - /* The only situation where we need to write the new mask is if the IRQ is active. \
> - * If it's being processed, the mask will be restored for us in _irq_threaded_handler() \
> - * on the PROCESSING -> ACTIVE transition. \
> - * If the IRQ is suspended/suspending, the mask is restored at resume time. \
> - */ \
> - if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE) \
> - gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
> +static inline irqreturn_t panthor_irq_default_raw_handler(int irq, void *data)
> +{
> + struct panthor_irq *pirq = data;
> +
> + guard(spinlock_irqsave)(&pirq->lock);
> + if (pirq->state != PANTHOR_IRQ_STATE_ACTIVE)
> + return IRQ_NONE;
> +
> + if (!gpu_read(pirq->iomem, INT_STAT))
> + return IRQ_NONE;
> +
> + pirq->state = PANTHOR_IRQ_STATE_PROCESSING;
> + gpu_write(pirq->iomem, INT_MASK, 0);
> + return IRQ_WAKE_THREAD;
> +}
> +
> +static __always_inline irqreturn_t
> +panthor_irq_default_threaded_handler(void *data,
> + void (*slow_handler)(struct panthor_irq *, u32))
> +{
> + struct panthor_irq *pirq = data;
> + irqreturn_t ret = IRQ_NONE;
> +
> + while (true) {
> + /* It's safe to access pirq->mask without the lock held here. If a new
> + * event gets added to the mask and the corresponding IRQ is pending,
> + * we'll process it right away instead of adding an extra raw -> threaded
> + * round trip. If an event is removed and the status bit is set, it will
> + * be ignored, just like it would have been if the mask had been adjusted
> + * right before the HW event kicks in. TLDR; it's all expected races we're
> + * covered for.
> + */
> + u32 status = gpu_read(pirq->iomem, INT_RAWSTAT) & pirq->mask;
> +
> + if (!status)
> + break;
> +
> + slow_handler(pirq, status);
> + ret = IRQ_HANDLED;
> + }
> +
> + scoped_guard(spinlock_irqsave, &pirq->lock) {
> + if (pirq->state == PANTHOR_IRQ_STATE_PROCESSING) {
> + pirq->state = PANTHOR_IRQ_STATE_ACTIVE;
> + gpu_write(pirq->iomem, INT_MASK, pirq->mask);
> + }
> + }
> +
> + return ret;
> +}
> +
> +static inline void panthor_irq_suspend(struct panthor_irq *pirq)
> +{
> + scoped_guard(spinlock_irqsave, &pirq->lock) {
> + pirq->state = PANTHOR_IRQ_STATE_SUSPENDING;
> + gpu_write(pirq->iomem, INT_MASK, 0);
> + }
> + synchronize_irq(pirq->irq);
> + scoped_guard(spinlock_irqsave, &pirq->lock)
> + pirq->state = PANTHOR_IRQ_STATE_SUSPENDED;
> +}
> +
> +static inline void panthor_irq_resume(struct panthor_irq *pirq)
> +{
> + guard(spinlock_irqsave)(&pirq->lock);
> + pirq->state = PANTHOR_IRQ_STATE_ACTIVE;
> + gpu_write(pirq->iomem, INT_CLEAR, pirq->mask);
> + gpu_write(pirq->iomem, INT_MASK, pirq->mask);
> +}
> +
> +static inline void panthor_irq_enable_events(struct panthor_irq *pirq, u32 mask)
> +{
> + guard(spinlock_irqsave)(&pirq->lock);
> + pirq->mask |= mask;
> +
> + /* The only situation where we need to write the new mask is if the IRQ is active.
> + * If it's being processed, the mask will be restored for us in _irq_threaded_handler()
> + * on the PROCESSING -> ACTIVE transition.
> + * If the IRQ is suspended/suspending, the mask is restored at resume time.
> + */
> + if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE)
> + gpu_write(pirq->iomem, INT_MASK, pirq->mask);
> +}
> +
> +static inline void panthor_irq_disable_events(struct panthor_irq *pirq, u32 mask)
> +{
> + guard(spinlock_irqsave)(&pirq->lock);
> + pirq->mask &= ~mask;
> +
> + /* The only situation where we need to write the new mask is if the IRQ is active.
> + * If it's being processed, the mask will be restored for us in _irq_threaded_handler()
> + * on the PROCESSING -> ACTIVE transition.
> + * If the IRQ is suspended/suspending, the mask is restored at resume time.
> + */
> + if (pirq->state == PANTHOR_IRQ_STATE_ACTIVE)
> + gpu_write(pirq->iomem, INT_MASK, pirq->mask);
> +}
> +
> +static inline int
> +panthor_irq_request(struct panthor_device *ptdev, struct panthor_irq *pirq,
> + int irq, void __iomem *iomem, const char *name,
> + irqreturn_t (*threaded_handler)(int, void *data))
> +{
> + const char *full_name;
> +
> + pirq->ptdev = ptdev;
> + pirq->irq = irq;
> + pirq->mask = 0;
> + pirq->iomem = iomem;
> + spin_lock_init(&pirq->lock);
> + pirq->state = PANTHOR_IRQ_STATE_SUSPENDED;
> +
> + full_name = devm_kasprintf(ptdev->base.dev, GFP_KERNEL, KBUILD_MODNAME "-%s", name);
> + if (!full_name)
> + return -ENOMEM;
> +
> + gpu_write(pirq->iomem, INT_MASK, 0);
> + return devm_request_threaded_irq(ptdev->base.dev, irq,
> + panthor_irq_default_raw_handler,
> + threaded_handler,
> + IRQF_SHARED, full_name, pirq);
> }
>
> extern struct workqueue_struct *panthor_cleanup_wq;
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> index fc1a423e48a8..68965175105f 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> @@ -1072,8 +1072,9 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev)
> msecs_to_jiffies(PING_INTERVAL_MS));
> }
>
> -static void panthor_job_irq_handler(struct panthor_device *ptdev, u32 status)
> +static void panthor_job_irq_handler(struct panthor_irq *pirq, u32 status)
> {
> + struct panthor_device *ptdev = pirq->ptdev;
> u32 duration;
> u64 start = 0;
>
> @@ -1099,7 +1100,11 @@ static void panthor_job_irq_handler(struct panthor_device *ptdev, u32 status)
> trace_gpu_job_irq(ptdev->base.dev, status, duration);
> }
> }
> -PANTHOR_IRQ_HANDLER(job, panthor_job_irq_handler);
> +
> +static irqreturn_t panthor_job_irq_threaded_handler(int irq, void *data)
> +{
> + return panthor_irq_default_threaded_handler(data, panthor_job_irq_handler);
> +}
>
> static int panthor_fw_start(struct panthor_device *ptdev)
> {
> @@ -1107,8 +1112,8 @@ static int panthor_fw_start(struct panthor_device *ptdev)
> bool timedout = false;
>
> ptdev->fw->booted = false;
> - panthor_job_irq_enable_events(&ptdev->fw->irq, ~0);
> - panthor_job_irq_resume(&ptdev->fw->irq);
> + panthor_irq_enable_events(&ptdev->fw->irq, ~0);
> + panthor_irq_resume(&ptdev->fw->irq);
> gpu_write(fw->iomem, MCU_CONTROL, MCU_CONTROL_AUTO);
>
> if (!wait_event_timeout(ptdev->fw->req_waitqueue,
> @@ -1218,7 +1223,7 @@ void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang)
> ptdev->reset.fast = true;
> }
>
> - panthor_job_irq_suspend(&ptdev->fw->irq);
> + panthor_irq_suspend(&ptdev->fw->irq);
> panthor_fw_stop(ptdev);
> }
>
> @@ -1287,7 +1292,7 @@ void panthor_fw_unplug(struct panthor_device *ptdev)
>
> if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev)) {
> /* Make sure the IRQ handler cannot be called after that point. */
> - panthor_job_irq_suspend(&ptdev->fw->irq);
> + panthor_irq_suspend(&ptdev->fw->irq);
> panthor_fw_stop(ptdev);
> }
>
> @@ -1482,8 +1487,9 @@ int panthor_fw_init(struct panthor_device *ptdev)
> if (irq <= 0)
> return -ENODEV;
>
> - ret = panthor_request_job_irq(ptdev, &fw->irq, irq,
> - ptdev->iomem + JOB_INT_BASE);
> + ret = panthor_irq_request(ptdev, &fw->irq, irq,
> + ptdev->iomem + JOB_INT_BASE, "job",
> + panthor_job_irq_threaded_handler);
> if (ret) {
> drm_err(&ptdev->base, "failed to request job irq");
> return ret;
> diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
> index c013d6bf9a59..7f287242285a 100644
> --- a/drivers/gpu/drm/panthor/panthor_gpu.c
> +++ b/drivers/gpu/drm/panthor/panthor_gpu.c
> @@ -86,8 +86,9 @@ static void panthor_gpu_l2_config_set(struct panthor_device *ptdev)
> gpu_write(gpu->iomem, GPU_L2_CONFIG, l2_config);
> }
>
> -static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
> +static void panthor_gpu_irq_handler(struct panthor_irq *pirq, u32 status)
> {
> + struct panthor_device *ptdev = pirq->ptdev;
> struct panthor_gpu *gpu = ptdev->gpu;
>
> gpu_write(gpu->irq.iomem, INT_CLEAR, status);
> @@ -116,7 +117,11 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
> }
> spin_unlock(&ptdev->gpu->reqs_lock);
> }
> -PANTHOR_IRQ_HANDLER(gpu, panthor_gpu_irq_handler);
> +
> +static irqreturn_t panthor_gpu_irq_threaded_handler(int irq, void *data)
> +{
> + return panthor_irq_default_threaded_handler(data, panthor_gpu_irq_handler);
> +}
>
> /**
> * panthor_gpu_unplug() - Called when the GPU is unplugged.
> @@ -128,7 +133,7 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)
>
> /* Make sure the IRQ handler is not running after that point. */
> if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
> - panthor_gpu_irq_suspend(&ptdev->gpu->irq);
> + panthor_irq_suspend(&ptdev->gpu->irq);
>
> /* Wake-up all waiters. */
> spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
> @@ -169,13 +174,14 @@ int panthor_gpu_init(struct panthor_device *ptdev)
> if (irq < 0)
> return irq;
>
> - ret = panthor_request_gpu_irq(ptdev, &ptdev->gpu->irq, irq,
> - ptdev->iomem + GPU_INT_BASE);
> + ret = panthor_irq_request(ptdev, &ptdev->gpu->irq, irq,
> + ptdev->iomem + GPU_INT_BASE, "gpu",
> + panthor_gpu_irq_threaded_handler);
> if (ret)
> return ret;
>
> - panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_INTERRUPTS_MASK);
> - panthor_gpu_irq_resume(&ptdev->gpu->irq);
> + panthor_irq_enable_events(&ptdev->gpu->irq, GPU_INTERRUPTS_MASK);
> + panthor_irq_resume(&ptdev->gpu->irq);
> return 0;
> }
>
> @@ -183,7 +189,7 @@ int panthor_gpu_power_changed_on(struct panthor_device *ptdev)
> {
> guard(pm_runtime_active)(ptdev->base.dev);
>
> - panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
> + panthor_irq_enable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
>
> return 0;
> }
> @@ -192,7 +198,7 @@ void panthor_gpu_power_changed_off(struct panthor_device *ptdev)
> {
> guard(pm_runtime_active)(ptdev->base.dev);
>
> - panthor_gpu_irq_disable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
> + panthor_irq_disable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK);
> }
>
> /**
> @@ -425,7 +431,7 @@ void panthor_gpu_suspend(struct panthor_device *ptdev)
> else
> panthor_hw_l2_power_off(ptdev);
>
> - panthor_gpu_irq_suspend(&ptdev->gpu->irq);
> + panthor_irq_suspend(&ptdev->gpu->irq);
> }
>
> /**
> @@ -437,7 +443,7 @@ void panthor_gpu_suspend(struct panthor_device *ptdev)
> */
> void panthor_gpu_resume(struct panthor_device *ptdev)
> {
> - panthor_gpu_irq_resume(&ptdev->gpu->irq);
> + panthor_irq_resume(&ptdev->gpu->irq);
> panthor_hw_l2_power_on(ptdev);
> }
>
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 0182b72f1932..d43ba1c7cd2a 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -601,17 +601,13 @@ static u32 panthor_mmu_as_fault_mask(struct panthor_device *ptdev, u32 as)
> return BIT(as);
> }
>
> -/* Forward declaration to call helpers within as_enable/disable */
> -static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status);
> -PANTHOR_IRQ_HANDLER(mmu, panthor_mmu_irq_handler);
> -
> static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
> u64 transtab, u64 transcfg, u64 memattr)
> {
> struct panthor_mmu *mmu = ptdev->mmu;
>
> - panthor_mmu_irq_enable_events(&ptdev->mmu->irq,
> - panthor_mmu_as_fault_mask(ptdev, as_nr));
> + panthor_irq_enable_events(&ptdev->mmu->irq,
> + panthor_mmu_as_fault_mask(ptdev, as_nr));
>
> gpu_write64(mmu->iomem, AS_TRANSTAB(as_nr), transtab);
> gpu_write64(mmu->iomem, AS_MEMATTR(as_nr), memattr);
> @@ -629,8 +625,8 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
>
> lockdep_assert_held(&ptdev->mmu->as.slots_lock);
>
> - panthor_mmu_irq_disable_events(&ptdev->mmu->irq,
> - panthor_mmu_as_fault_mask(ptdev, as_nr));
> + panthor_irq_disable_events(&ptdev->mmu->irq,
> + panthor_mmu_as_fault_mask(ptdev, as_nr));
>
> /* Flush+invalidate RW caches, invalidate RO ones. */
> ret = panthor_gpu_flush_caches(ptdev, CACHE_CLEAN | CACHE_INV,
> @@ -1859,8 +1855,9 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
> mutex_unlock(&ptdev->mmu->as.slots_lock);
> }
>
> -static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
> +static void panthor_mmu_irq_handler(struct panthor_irq *pirq, u32 status)
> {
> + struct panthor_device *ptdev = pirq->ptdev;
> struct panthor_mmu *mmu = ptdev->mmu;
> bool has_unhandled_faults = false;
>
> @@ -1923,6 +1920,11 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
> panthor_sched_report_mmu_fault(ptdev);
> }
>
> +static irqreturn_t panthor_mmu_irq_threaded_handler(int irq, void *data)
> +{
> + return panthor_irq_default_threaded_handler(data, panthor_mmu_irq_handler);
> +}
> +
> /**
> * panthor_mmu_suspend() - Suspend the MMU logic
> * @ptdev: Device.
> @@ -1947,7 +1949,7 @@ void panthor_mmu_suspend(struct panthor_device *ptdev)
> }
> mutex_unlock(&ptdev->mmu->as.slots_lock);
>
> - panthor_mmu_irq_suspend(&ptdev->mmu->irq);
> + panthor_irq_suspend(&ptdev->mmu->irq);
> }
>
> /**
> @@ -1966,7 +1968,7 @@ void panthor_mmu_resume(struct panthor_device *ptdev)
> ptdev->mmu->as.faulty_mask = 0;
> mutex_unlock(&ptdev->mmu->as.slots_lock);
>
> - panthor_mmu_irq_resume(&ptdev->mmu->irq);
> + panthor_irq_resume(&ptdev->mmu->irq);
> }
>
> /**
> @@ -1983,7 +1985,7 @@ void panthor_mmu_pre_reset(struct panthor_device *ptdev)
> {
> struct panthor_vm *vm;
>
> - panthor_mmu_irq_suspend(&ptdev->mmu->irq);
> + panthor_irq_suspend(&ptdev->mmu->irq);
>
> mutex_lock(&ptdev->mmu->vm.lock);
> ptdev->mmu->vm.reset_in_progress = true;
> @@ -2020,7 +2022,7 @@ void panthor_mmu_post_reset(struct panthor_device *ptdev)
>
> mutex_unlock(&ptdev->mmu->as.slots_lock);
>
> - panthor_mmu_irq_resume(&ptdev->mmu->irq);
> + panthor_irq_resume(&ptdev->mmu->irq);
>
> /* Restart the VM_BIND queues. */
> mutex_lock(&ptdev->mmu->vm.lock);
> @@ -3352,7 +3354,7 @@ panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
> void panthor_mmu_unplug(struct panthor_device *ptdev)
> {
> if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
> - panthor_mmu_irq_suspend(&ptdev->mmu->irq);
> + panthor_irq_suspend(&ptdev->mmu->irq);
>
> mutex_lock(&ptdev->mmu->as.slots_lock);
> for (u32 i = 0; i < ARRAY_SIZE(ptdev->mmu->as.slots); i++) {
> @@ -3413,8 +3415,9 @@ int panthor_mmu_init(struct panthor_device *ptdev)
> if (irq <= 0)
> return -ENODEV;
>
> - ret = panthor_request_mmu_irq(ptdev, &mmu->irq, irq,
> - ptdev->iomem + MMU_INT_BASE);
> + ret = panthor_irq_request(ptdev, &mmu->irq, irq,
> + ptdev->iomem + MMU_INT_BASE, "mmu",
> + panthor_mmu_irq_threaded_handler);
> if (ret)
> return ret;
>
> @@ -3435,8 +3438,8 @@ int panthor_mmu_init(struct panthor_device *ptdev)
> if (ret)
> return ret;
>
> - panthor_mmu_irq_enable_events(&mmu->irq, panthor_mmu_fault_mask(ptdev, ~0));
> - panthor_mmu_irq_resume(&mmu->irq);
> + panthor_irq_enable_events(&mmu->irq, panthor_mmu_fault_mask(ptdev, ~0));
> + panthor_irq_resume(&mmu->irq);
> return 0;
> }
>
> diff --git a/drivers/gpu/drm/panthor/panthor_pwr.c b/drivers/gpu/drm/panthor/panthor_pwr.c
> index f2c2c3000590..dd7b6ef8ea20 100644
> --- a/drivers/gpu/drm/panthor/panthor_pwr.c
> +++ b/drivers/gpu/drm/panthor/panthor_pwr.c
> @@ -56,8 +56,9 @@ struct panthor_pwr {
> wait_queue_head_t reqs_acked;
> };
>
> -static void panthor_pwr_irq_handler(struct panthor_device *ptdev, u32 status)
> +static void panthor_pwr_irq_handler(struct panthor_irq *pirq, u32 status)
> {
> + struct panthor_device *ptdev = pirq->ptdev;
> struct panthor_pwr *pwr = ptdev->pwr;
>
> spin_lock(&ptdev->pwr->reqs_lock);
> @@ -75,7 +76,11 @@ static void panthor_pwr_irq_handler(struct panthor_device *ptdev, u32 status)
> }
> spin_unlock(&ptdev->pwr->reqs_lock);
> }
> -PANTHOR_IRQ_HANDLER(pwr, panthor_pwr_irq_handler);
> +
> +static irqreturn_t panthor_pwr_irq_threaded_handler(int irq, void *data)
> +{
> + return panthor_irq_default_threaded_handler(data, panthor_pwr_irq_handler);
> +}
>
> static void panthor_pwr_write_command(struct panthor_device *ptdev, u32 command, u64 args)
> {
> @@ -454,7 +459,7 @@ void panthor_pwr_unplug(struct panthor_device *ptdev)
>
> /* Make sure the IRQ handler is not running after that point. */
> if (!IS_ENABLED(CONFIG_PM) || pm_runtime_active(ptdev->base.dev))
> - panthor_pwr_irq_suspend(&ptdev->pwr->irq);
> + panthor_irq_suspend(&ptdev->pwr->irq);
>
> /* Wake-up all waiters. */
> spin_lock_irqsave(&ptdev->pwr->reqs_lock, flags);
> @@ -484,13 +489,14 @@ int panthor_pwr_init(struct panthor_device *ptdev)
> if (irq < 0)
> return irq;
>
> - err = panthor_request_pwr_irq(ptdev, &pwr->irq, irq,
> - pwr->iomem + PWR_INT_BASE);
> + err = panthor_irq_request(ptdev, &pwr->irq, irq,
> + pwr->iomem + PWR_INT_BASE, "pwr",
> + panthor_pwr_irq_threaded_handler);
> if (err)
> return err;
>
> - panthor_pwr_irq_enable_events(&pwr->irq, PWR_INTERRUPTS_MASK);
> - panthor_pwr_irq_resume(&pwr->irq);
> + panthor_irq_enable_events(&pwr->irq, PWR_INTERRUPTS_MASK);
> + panthor_irq_resume(&pwr->irq);
> return 0;
> }
>
> @@ -566,7 +572,7 @@ void panthor_pwr_suspend(struct panthor_device *ptdev)
> if (!ptdev->pwr)
> return;
>
> - panthor_pwr_irq_suspend(&ptdev->pwr->irq);
> + panthor_irq_suspend(&ptdev->pwr->irq);
> }
>
> void panthor_pwr_resume(struct panthor_device *ptdev)
> @@ -574,5 +580,5 @@ void panthor_pwr_resume(struct panthor_device *ptdev)
> if (!ptdev->pwr)
> return;
>
> - panthor_pwr_irq_resume(&ptdev->pwr->irq);
> + panthor_irq_resume(&ptdev->pwr->irq);
> }
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked()
2026-08-11 11:23 ` [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked() Boris Brezillon
2026-08-17 15:09 ` Steven Price
@ 2026-08-18 17:08 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:08 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:38PM +0200, Boris Brezillon wrote:
> By scheduling an immediate tick, we already force idleness re-evaluation,
> which gives the scheduler the opportunity to evict idle groups
> and schedule onces that have jobs pending.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 5832dccfc093..baa06731797c 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -1733,8 +1733,6 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
>
> lockdep_assert_held(&sched->lock);
>
> - sched->might_have_idle_groups = true;
> -
> /* Schedule a tick so we can evict idle groups and schedule non-idle
> * ones. This will also update runtime PM and devfreq busy/idle states,
> * so the device can lower its frequency or get suspended.
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock
2026-08-11 11:23 ` [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock Boris Brezillon
2026-08-17 15:12 ` Steven Price
@ 2026-08-18 17:09 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:09 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:39PM +0200, Boris Brezillon wrote:
> This lock is never used, and we're about to make fatal_queues an
> atomic to cope with concurrent updates.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index baa06731797c..9adf1e21eb83 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -565,9 +565,6 @@ struct panthor_group {
> /** @idle_queues: Bitmask reflecting the idle queues. */
> u32 idle_queues;
>
> - /** @fatal_lock: Lock used to protect access to fatal fields. */
> - spinlock_t fatal_lock;
> -
> /** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
> u32 fatal_queues;
>
> @@ -3675,7 +3672,6 @@ int panthor_group_create(struct panthor_file *pfile,
> if (!group)
> return -ENOMEM;
>
> - spin_lock_init(&group->fatal_lock);
> kref_init(&group->refcount);
> group->state = PANTHOR_CS_GROUP_CREATED;
> group->csg_id = -1;
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock
2026-08-11 11:23 ` [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock Boris Brezillon
2026-08-17 15:21 ` Steven Price
@ 2026-08-18 17:13 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:13 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:40PM +0200, Boris Brezillon wrote:
> Add a specific spinlock for events processing so we can selectively
> move some event processing to the threaded IRQ handler. For events to be
> processed, we need to have access to the group attached to the CSG slot
> which also forces us to protect the csg_slots[] updates with this
> lock.
>
> Note that fatal_queues/timedout are turned into atomics to avoid having
> to take the events_lock every time those are checked or updated.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 123 ++++++++++++++++++++------------
> 1 file changed, 78 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 9adf1e21eb83..794105e239e6 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -254,8 +254,21 @@ struct panthor_scheduler {
> struct list_head waiting;
> } groups;
>
> + /**
> + * @events_lock: Lock taken when processing events.
> + *
> + * This also needs to be taken when csg_slots are updated, to make sure
> + * the event processing logic doesn't touch groups that have left the CSG
> + * slot.
> + */
> + spinlock_t events_lock;
> +
> /**
> * @csg_slots: FW command stream group slots.
> + *
> + * Updates to these slots must happen with both panthor_scheduler::lock and
> + * panthor_scheduler::events_lock held. As a result, reads can happen with
> + * either of these locks held.
> */
> struct panthor_csg_slot csg_slots[MAX_CSGS];
>
> @@ -565,8 +578,13 @@ struct panthor_group {
> /** @idle_queues: Bitmask reflecting the idle queues. */
> u32 idle_queues;
>
> - /** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
> - u32 fatal_queues;
> + /**
> + * @fatal_queues: Bitmask reflecting the queues that hit a fatal exception.
> + *
> + * This is an atomic because we don't want to acquire the events_lock
> + * every time we need to check the group state.
> + */
> + atomic_t fatal_queues;
>
> /** @tiler_oom: Mask of queues that have a tiler OOM event to process. */
> atomic_t tiler_oom;
> @@ -602,8 +620,14 @@ struct panthor_group {
> * any timeout situation is unrecoverable, and the group becomes useless. We
> * simply wait for all references to be dropped so we can release the group
> * object.
> + *
> + * This is an atomic because it can be set from both a scheduling context
> + * (protected with panthor_scheduler::lock) and an event processing context
> + * (protected with panthor_scheduler::events_lock). We could protect access
> + * with the events_lock, but this is simpler to make it an atomic since the
> + * only allowed transition is false -> true.
> */
> - bool timedout;
> + atomic_t timedout;
>
> /**
> * @innocent: True when the group becomes unusable because the group suspension
> @@ -996,7 +1020,6 @@ static int
> group_bind_locked(struct panthor_group *group, u32 csg_id)
> {
> struct panthor_device *ptdev = group->ptdev;
> - struct panthor_csg_slot *csg_slot;
> int ret;
>
> lockdep_assert_held(&ptdev->scheduler->lock);
> @@ -1009,9 +1032,7 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
> if (ret)
> return ret;
>
> - csg_slot = &ptdev->scheduler->csg_slots[csg_id];
> group_get(group);
> - group->csg_id = csg_id;
>
> /* Dummy doorbell allocation: doorbell is assigned to the group and
> * all queues use the same doorbell.
> @@ -1023,7 +1044,10 @@ group_bind_locked(struct panthor_group *group, u32 csg_id)
> for (u32 i = 0; i < group->queue_count; i++)
> group->queues[i]->doorbell_id = csg_id + 1;
>
> - csg_slot->group = group;
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + ptdev->scheduler->csg_slots[csg_id].group = group;
> + group->csg_id = csg_id;
> + }
>
> return 0;
> }
> @@ -1038,7 +1062,6 @@ static int
> group_unbind_locked(struct panthor_group *group)
> {
> struct panthor_device *ptdev = group->ptdev;
> - struct panthor_csg_slot *slot;
>
> lockdep_assert_held(&ptdev->scheduler->lock);
>
> @@ -1048,9 +1071,12 @@ group_unbind_locked(struct panthor_group *group)
> if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
> return -EINVAL;
>
> - slot = &ptdev->scheduler->csg_slots[group->csg_id];
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
> + group->csg_id = -1;
> + }
> +
> panthor_vm_idle(group->vm);
> - group->csg_id = -1;
>
> /* Tiler OOM events will be re-issued next time the group is scheduled. */
> atomic_set(&group->tiler_oom, 0);
> @@ -1060,8 +1086,6 @@ group_unbind_locked(struct panthor_group *group)
> for (u32 i = 0; i < group->queue_count; i++)
> group->queues[i]->doorbell_id = -1;
>
> - slot->group = NULL;
> -
> group_put(group);
> return 0;
> }
> @@ -1079,8 +1103,9 @@ group_can_run(struct panthor_group *group)
> {
> return group->state != PANTHOR_CS_GROUP_TERMINATED &&
> group->state != PANTHOR_CS_GROUP_UNKNOWN_STATE &&
> - !group->destroyed && group->fatal_queues == 0 &&
> - !group->timedout;
> + !group->destroyed &&
> + !atomic_read(&group->fatal_queues) &&
> + !atomic_read(&group->timedout);
> }
>
> static bool
> @@ -1479,7 +1504,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
> u32 fatal;
> u64 info;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> fatal = cs_iface->output->fatal;
> @@ -1489,7 +1514,7 @@ cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
> drm_warn(&ptdev->base, "CS_FATAL: pid=%d, comm=%s\n",
> group->task_info.pid, group->task_info.comm);
>
> - group->fatal_queues |= BIT(cs_id);
> + atomic_or(BIT(cs_id), &group->fatal_queues);
> }
>
> if (CS_EXCEPTION_TYPE(fatal) == DRM_PANTHOR_EXCEPTION_CS_UNRECOVERABLE) {
> @@ -1527,7 +1552,7 @@ cs_slot_process_fault_event_locked(struct panthor_device *ptdev,
> u32 fault;
> u64 info;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> fault = cs_iface->output->fault;
> @@ -1619,7 +1644,7 @@ static int group_process_tiler_oom(struct panthor_group *group, u32 cs_id)
> */
> if (ret && ret != -ENOMEM) {
> drm_warn(&ptdev->base, "Failed to extend the tiler heap\n");
> - group->fatal_queues |= BIT(cs_id);
> + atomic_or(BIT(cs_id), &group->fatal_queues);
> sched_queue_delayed_work(sched, tick, 0);
> goto out_put_heap_pool;
> }
> @@ -1679,7 +1704,7 @@ cs_slot_process_tiler_oom_event_locked(struct panthor_device *ptdev,
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> if (drm_WARN_ON(&ptdev->base, !group))
> return;
> @@ -1700,7 +1725,7 @@ static bool cs_slot_process_irq_locked(struct panthor_device *ptdev,
> struct panthor_fw_cs_iface *cs_iface;
> u32 req, ack, events;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> cs_iface = panthor_fw_get_cs_iface(ptdev, csg_id, cs_id);
> req = cs_iface->input->req;
> @@ -1728,7 +1753,7 @@ static void csg_slot_process_idle_event_locked(struct panthor_device *ptdev, u32
> {
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> /* Schedule a tick so we can evict idle groups and schedule non-idle
> * ones. This will also update runtime PM and devfreq busy/idle states,
> @@ -1743,7 +1768,7 @@ static void csg_slot_sync_update_locked(struct panthor_device *ptdev,
> struct panthor_csg_slot *csg_slot = &ptdev->scheduler->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> if (group)
> group_queue_work(group, sync_upd);
> @@ -1758,14 +1783,14 @@ csg_slot_process_progress_timer_event_locked(struct panthor_device *ptdev, u32 c
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
> struct panthor_group *group = csg_slot->group;
>
> - lockdep_assert_held(&sched->lock);
> + lockdep_assert_held(&sched->events_lock);
>
> group = csg_slot->group;
> if (!drm_WARN_ON(&ptdev->base, !group)) {
> drm_warn(&ptdev->base, "CSG_PROGRESS_TIMER_EVENT: pid=%d, comm=%s\n",
> group->task_info.pid, group->task_info.comm);
>
> - group->timedout = true;
> + atomic_set(&group->timedout, true);
> }
>
> drm_warn(&ptdev->base, "CSG slot %d progress timeout\n", csg_id);
> @@ -1779,7 +1804,7 @@ static void sched_process_csg_irq_locked(struct panthor_device *ptdev, u32 csg_i
> struct panthor_fw_csg_iface *csg_iface;
> u32 ring_cs_db_mask = 0;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> if (drm_WARN_ON(&ptdev->base, csg_id >= ptdev->scheduler->csg_slot_count))
> return;
> @@ -1837,7 +1862,7 @@ static void sched_process_idle_event_locked(struct panthor_device *ptdev)
> {
> struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> /* Acknowledge the idle event and schedule a tick. */
> panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack, GLB_IDLE);
> @@ -1853,7 +1878,7 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
> struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
> u32 req, ack, evts;
>
> - lockdep_assert_held(&ptdev->scheduler->lock);
> + lockdep_assert_held(&ptdev->scheduler->events_lock);
>
> req = READ_ONCE(glb_iface->input->req);
> ack = READ_ONCE(glb_iface->output->ack);
> @@ -1870,7 +1895,7 @@ static void process_fw_events_work(struct work_struct *work)
> u32 events = atomic_xchg(&sched->fw_events, 0);
> struct panthor_device *ptdev = sched->ptdev;
>
> - mutex_lock(&sched->lock);
> + guard(spinlock)(&sched->events_lock);
>
> if (events & JOB_INT_GLOBAL_IF) {
> sched_process_global_irq_locked(ptdev);
> @@ -1883,8 +1908,6 @@ static void process_fw_events_work(struct work_struct *work)
> sched_process_csg_irq_locked(ptdev, csg_id);
> events &= ~BIT(csg_id);
> }
> -
> - mutex_unlock(&sched->lock);
> }
>
> /**
> @@ -2131,11 +2154,12 @@ tick_ctx_init(struct panthor_scheduler *sched,
> * CSG IRQs, so we can flag the faulty queue.
> */
> if (panthor_vm_has_unhandled_faults(group->vm)) {
> - sched_process_csg_irq_locked(ptdev, i);
> + scoped_guard(spinlock, &sched->events_lock)
> + sched_process_csg_irq_locked(ptdev, i);
>
> /* No fatal fault reported, flag all queues as faulty. */
> - if (!group->fatal_queues)
> - group->fatal_queues |= GENMASK(group->queue_count - 1, 0);
> + atomic_cmpxchg(&group->fatal_queues, 0,
> + GENMASK(group->queue_count - 1, 0));
> }
>
> tick_ctx_insert_old_group(sched, ctx, group);
> @@ -2168,9 +2192,9 @@ group_term_post_processing(struct panthor_group *group)
> struct panthor_syncobj_64b *syncobj;
> int err;
>
> - if (group->fatal_queues & BIT(i))
> + if (atomic_read(&group->fatal_queues) & BIT(i))
> err = -EINVAL;
> - else if (group->timedout)
> + else if (atomic_read(&group->timedout))
> err = -ETIMEDOUT;
> else
> err = -ECANCELED;
> @@ -2331,8 +2355,10 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
> * any pending interrupts before we start the new
> * group.
> */
> - if (group->csg_id >= 0)
> + if (group->csg_id >= 0) {
> + guard(spinlock)(&sched->events_lock);
> sched_process_csg_irq_locked(ptdev, group->csg_id);
> + }
>
> group_unbind_locked(group);
> }
> @@ -2861,7 +2887,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
> /* We consider group suspension failures as fatal and flag the
> * group as unusable by setting timedout=true.
> */
> - csg_slot->group->timedout = true;
> + atomic_set(&csg_slot->group->timedout, true);
>
> csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
> CSG_STATE_TERMINATE,
> @@ -2910,10 +2936,12 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
> u32 csg_id = ffs(slot_mask) - 1;
> struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
>
> - if (flush_caches_failed)
> + if (flush_caches_failed) {
> csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
> - else
> + } else {
> + guard(spinlock)(&sched->events_lock);
> csg_slot_sync_update_locked(ptdev, csg_id);
> + }
>
> slot_mask &= ~BIT(csg_id);
> }
> @@ -2928,8 +2956,10 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
>
> group_get(group);
>
> - if (group->csg_id >= 0)
> + if (group->csg_id >= 0) {
> + guard(spinlock)(&sched->events_lock);
> sched_process_csg_irq_locked(ptdev, group->csg_id);
> + }
>
> group_unbind_locked(group);
>
> @@ -3421,7 +3451,7 @@ queue_timedout_job(struct drm_sched_job *sched_job)
> queue_stop(queue, job);
>
> mutex_lock(&sched->lock);
> - group->timedout = true;
> + atomic_set(&group->timedout, true);
> if (group->csg_id >= 0) {
> sched_queue_delayed_work(ptdev->scheduler, tick, 0);
> } else {
> @@ -3843,12 +3873,13 @@ int panthor_group_get_state(struct panthor_file *pfile,
> memset(get_state, 0, sizeof(*get_state));
>
> mutex_lock(&sched->lock);
> - if (group->timedout)
> + if (atomic_read(&group->timedout))
> get_state->state |= DRM_PANTHOR_GROUP_STATE_TIMEDOUT;
> - if (group->fatal_queues) {
> +
> + get_state->fatal_queues = atomic_read(&group->fatal_queues);
> + if (get_state->fatal_queues)
> get_state->state |= DRM_PANTHOR_GROUP_STATE_FATAL_FAULT;
> - get_state->fatal_queues = group->fatal_queues;
> - }
> +
> if (group->innocent)
> get_state->state |= DRM_PANTHOR_GROUP_STATE_INNOCENT;
> mutex_unlock(&sched->lock);
> @@ -4146,6 +4177,8 @@ int panthor_sched_init(struct panthor_device *ptdev)
> INIT_WORK(&sched->sync_upd_work, sync_upd_work);
> INIT_WORK(&sched->fw_events_work, process_fw_events_work);
>
> + spin_lock_init(&sched->events_lock);
> +
> ret = drmm_mutex_init(&ptdev->base, &sched->lock);
> if (ret)
> return ret;
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 8/9] drm/panthor: Don't defer FW event processing
2026-08-11 11:23 ` [PATCH v6 8/9] drm/panthor: Don't defer FW event processing Boris Brezillon
2026-08-17 15:35 ` Steven Price
@ 2026-08-18 17:15 ` Liviu Dudau
1 sibling, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:15 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:42PM +0200, Boris Brezillon wrote:
> Avoid a workqueue roundtrip and process things immediately from
> panthor_sched_report_fw_events().
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 48 +++++++--------------------------
> 1 file changed, 9 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 1ef9da55030c..8016b0a55173 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -177,23 +177,6 @@ struct panthor_scheduler {
> */
> struct work_struct sync_upd_work;
>
> - /**
> - * @fw_events_work: Work used to process FW events outside the interrupt path.
> - *
> - * Even if the interrupt is threaded, we need any event processing
> - * that require taking the panthor_scheduler::lock to be processed
> - * outside the interrupt path so we don't block the tick logic when
> - * it calls panthor_fw_{csg,wait}_wait_acks(). Since most of the
> - * event processing requires taking this lock, we just delegate all
> - * FW event processing to the scheduler workqueue.
> - */
> - struct work_struct fw_events_work;
> -
> - /**
> - * @fw_events: Bitmask encoding pending FW events.
> - */
> - atomic_t fw_events;
> -
> /**
> * @resched_target: When the next tick should occur.
> *
> @@ -1971,14 +1954,17 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
> sched_process_idle_event_locked(ptdev);
> }
>
> -static void process_fw_events_work(struct work_struct *work)
> +/**
> + * panthor_sched_report_fw_events() - Report FW events to the scheduler.
> + * @ptdev: Device.
> + * @events: Bitmask of pending FW events to report.
> + */
> +void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
> {
> - struct panthor_scheduler *sched = container_of(work, struct panthor_scheduler,
> - fw_events_work);
> - u32 events = atomic_xchg(&sched->fw_events, 0);
> - struct panthor_device *ptdev = sched->ptdev;
> + if (!ptdev->scheduler)
> + return;
>
> - guard(spinlock)(&sched->events_lock);
> + guard(spinlock)(&ptdev->scheduler->events_lock);
>
> if (events & JOB_INT_GLOBAL_IF) {
> sched_process_global_irq_locked(ptdev);
> @@ -1993,20 +1979,6 @@ static void process_fw_events_work(struct work_struct *work)
> }
> }
>
> -/**
> - * panthor_sched_report_fw_events() - Report FW events to the scheduler.
> - * @ptdev: Device.
> - * @events: Bitmask of pending FW events to report.
> - */
> -void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
> -{
> - if (!ptdev->scheduler)
> - return;
> -
> - atomic_or(events, &ptdev->scheduler->fw_events);
> - sched_queue_work(ptdev->scheduler, fw_events);
> -}
> -
> static const char *fence_get_driver_name(struct dma_fence *fence)
> {
> return "panthor";
> @@ -4082,7 +4054,6 @@ void panthor_sched_unplug(struct panthor_device *ptdev)
> struct panthor_scheduler *sched = ptdev->scheduler;
>
> disable_delayed_work_sync(&sched->tick_work);
> - disable_work_sync(&sched->fw_events_work);
> disable_work_sync(&sched->sync_upd_work);
>
> mutex_lock(&sched->lock);
> @@ -4167,7 +4138,6 @@ int panthor_sched_init(struct panthor_device *ptdev)
> sched->tick_period = msecs_to_jiffies(10);
> INIT_DELAYED_WORK(&sched->tick_work, tick_work);
> INIT_WORK(&sched->sync_upd_work, sync_upd_work);
> - INIT_WORK(&sched->fw_events_work, process_fw_events_work);
>
> spin_lock_init(&sched->events_lock);
>
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time
2026-08-11 11:23 ` [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time Boris Brezillon
@ 2026-08-18 17:20 ` Liviu Dudau
0 siblings, 0 replies; 21+ messages in thread
From: Liviu Dudau @ 2026-08-18 17:20 UTC (permalink / raw)
To: Boris Brezillon
Cc: Steven Price, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel
On Tue, Aug 11, 2026 at 01:23:43PM +0200, Boris Brezillon wrote:
> Make the sched_process_csg_irq_locked() call part of
> group_unbind_locked() so we don't have to manually call it in
> tick_ctx_apply()/panthor_sched_suspend().
>
> This implies moving group_[un]bind_locked() around to avoid a
> forward declaration.
Not sure why group_bind_locked() had to move. Aestethics?
Makes the patch a bit harder to review as one function is copied
verbatim while the other gets a line added. Minor sigh in the
end, so please ignore.
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
>
> Reviewed-by: Steven Price <steven.price@arm.com>
> Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 182 +++++++++++++++-----------------
> 1 file changed, 84 insertions(+), 98 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 8016b0a55173..57308cd90e96 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -989,87 +989,6 @@ group_get(struct panthor_group *group)
> return group;
> }
>
> -/**
> - * group_bind_locked() - Bind a group to a group slot
> - * @group: Group.
> - * @csg_id: Slot.
> - *
> - * Return: 0 on success, a negative error code otherwise.
> - */
> -static int
> -group_bind_locked(struct panthor_group *group, u32 csg_id)
> -{
> - struct panthor_device *ptdev = group->ptdev;
> - int ret;
> -
> - lockdep_assert_held(&ptdev->scheduler->lock);
> -
> - if (drm_WARN_ON(&ptdev->base, group->csg_id != -1 || csg_id >= MAX_CSGS ||
> - ptdev->scheduler->csg_slots[csg_id].group))
> - return -EINVAL;
> -
> - ret = panthor_vm_active(group->vm);
> - if (ret)
> - return ret;
> -
> - group_get(group);
> -
> - /* Dummy doorbell allocation: doorbell is assigned to the group and
> - * all queues use the same doorbell.
> - *
> - * TODO: Implement LRU-based doorbell assignment, so the most often
> - * updated queues get their own doorbell, thus avoiding useless checks
> - * on queues belonging to the same group that are rarely updated.
> - */
> - for (u32 i = 0; i < group->queue_count; i++)
> - group->queues[i]->doorbell_id = csg_id + 1;
> -
> - scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> - ptdev->scheduler->csg_slots[csg_id].group = group;
> - group->csg_id = csg_id;
> - }
> -
> - return 0;
> -}
> -
> -/**
> - * group_unbind_locked() - Unbind a group from a slot.
> - * @group: Group to unbind.
> - *
> - * Return: 0 on success, a negative error code otherwise.
> - */
> -static int
> -group_unbind_locked(struct panthor_group *group)
> -{
> - struct panthor_device *ptdev = group->ptdev;
> -
> - lockdep_assert_held(&ptdev->scheduler->lock);
> -
> - if (drm_WARN_ON(&ptdev->base, group->csg_id < 0 || group->csg_id >= MAX_CSGS))
> - return -EINVAL;
> -
> - if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
> - return -EINVAL;
> -
> - scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> - ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
> - group->csg_id = -1;
> - }
> -
> - panthor_vm_idle(group->vm);
> -
> - /* Tiler OOM events will be re-issued next time the group is scheduled. */
> - atomic_set(&group->tiler_oom, 0);
> - if (cancel_work(&group->tiler_oom_work))
> - group_put(group);
> -
> - for (u32 i = 0; i < group->queue_count; i++)
> - group->queues[i]->doorbell_id = -1;
> -
> - group_put(group);
> - return 0;
> -}
> -
> static bool
> group_is_idle(struct panthor_group *group)
> {
> @@ -1979,6 +1898,89 @@ void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
> }
> }
>
> +/**
> + * group_bind_locked() - Bind a group to a group slot
> + * @group: Group.
> + * @csg_id: Slot.
> + *
> + * Return: 0 on success, a negative error code otherwise.
> + */
> +static int
> +group_bind_locked(struct panthor_group *group, u32 csg_id)
> +{
> + struct panthor_device *ptdev = group->ptdev;
> + int ret;
> +
> + lockdep_assert_held(&ptdev->scheduler->lock);
> +
> + if (drm_WARN_ON(&ptdev->base, group->csg_id != -1 || csg_id >= MAX_CSGS ||
> + ptdev->scheduler->csg_slots[csg_id].group))
> + return -EINVAL;
> +
> + ret = panthor_vm_active(group->vm);
> + if (ret)
> + return ret;
> +
> + group_get(group);
> +
> + /* Dummy doorbell allocation: doorbell is assigned to the group and
> + * all queues use the same doorbell.
> + *
> + * TODO: Implement LRU-based doorbell assignment, so the most often
> + * updated queues get their own doorbell, thus avoiding useless checks
> + * on queues belonging to the same group that are rarely updated.
> + */
> + for (u32 i = 0; i < group->queue_count; i++)
> + group->queues[i]->doorbell_id = csg_id + 1;
> +
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + ptdev->scheduler->csg_slots[csg_id].group = group;
> + group->csg_id = csg_id;
> + }
> +
> + return 0;
> +}
> +
> +/**
> + * group_unbind_locked() - Unbind a group from a slot.
> + * @group: Group to unbind.
> + *
> + * Return: 0 on success, a negative error code otherwise.
> + */
> +static int
> +group_unbind_locked(struct panthor_group *group)
> +{
> + struct panthor_device *ptdev = group->ptdev;
> +
> + lockdep_assert_held(&ptdev->scheduler->lock);
> +
> + if (drm_WARN_ON(&ptdev->base, group->csg_id < 0 || group->csg_id >= MAX_CSGS))
> + return -EINVAL;
> +
> + if (drm_WARN_ON(&ptdev->base, group->state == PANTHOR_CS_GROUP_ACTIVE))
> + return -EINVAL;
> +
> + scoped_guard(spinlock, &ptdev->scheduler->events_lock) {
> + /* Process all pending IRQs before returning the slot. */
> + sched_process_csg_irq_locked(ptdev, group->csg_id);
> + ptdev->scheduler->csg_slots[group->csg_id].group = NULL;
> + group->csg_id = -1;
> + }
> +
> + panthor_vm_idle(group->vm);
> +
> + /* Tiler OOM events will be re-issued next time the group is scheduled. */
> + atomic_set(&group->tiler_oom, 0);
> + if (cancel_work(&group->tiler_oom_work))
> + group_put(group);
> +
> + for (u32 i = 0; i < group->queue_count; i++)
> + group->queues[i]->doorbell_id = -1;
> +
> + group_put(group);
> + return 0;
> +}
> +
> static const char *fence_get_driver_name(struct dma_fence *fence)
> {
> return "panthor";
> @@ -2405,18 +2407,8 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
>
> /* Unbind evicted groups. */
> for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
> - list_for_each_entry(group, &ctx->old_groups[prio], run_node) {
> - /* This group is gone. Process interrupts to clear
> - * any pending interrupts before we start the new
> - * group.
> - */
> - if (group->csg_id >= 0) {
> - guard(spinlock)(&sched->events_lock);
> - sched_process_csg_irq_locked(ptdev, group->csg_id);
> - }
> -
> + list_for_each_entry(group, &ctx->old_groups[prio], run_node)
> group_unbind_locked(group);
> - }
> }
>
> for (i = 0; i < sched->csg_slot_count; i++) {
> @@ -3010,12 +3002,6 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
> continue;
>
> group_get(group);
> -
> - if (group->csg_id >= 0) {
> - guard(spinlock)(&sched->events_lock);
> - sched_process_csg_irq_locked(ptdev, group->csg_id);
> - }
> -
> group_unbind_locked(group);
>
> drm_WARN_ON(&group->ptdev->base, !list_empty(&group->run_node));
>
> --
> 2.55.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-08-18 17:21 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 11:23 [PATCH v6 0/9] drm/panthor: Reduce dma_fence signalling latency Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 1/9] drm/panthor: Make panthor_irq::state a non-atomic field Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 2/9] drm/panthor: Move the register accessors before the IRQ helpers Boris Brezillon
2026-08-11 11:23 ` [PATCH v6 3/9] drm/panthor: Replace the panthor_irq macro machinery by inline helpers Boris Brezillon
2026-08-18 17:08 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 4/9] drm/panthor: Don't update might_have_idle_groups in process_idle_event_locked() Boris Brezillon
2026-08-17 15:09 ` Steven Price
2026-08-18 17:08 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 5/9] drm/panthor: Get rid of panthor_group::fatal_lock Boris Brezillon
2026-08-17 15:12 ` Steven Price
2026-08-18 17:09 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 6/9] drm/panthor: Protect events processing with a separate spinlock Boris Brezillon
2026-08-17 15:21 ` Steven Price
2026-08-18 17:13 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 7/9] drm/panthor: Don't defer job completion checks Boris Brezillon
2026-08-17 15:29 ` Steven Price
2026-08-11 11:23 ` [PATCH v6 8/9] drm/panthor: Don't defer FW event processing Boris Brezillon
2026-08-17 15:35 ` Steven Price
2026-08-18 17:15 ` Liviu Dudau
2026-08-11 11:23 ` [PATCH v6 9/9] drm/panthor: Automate CSG IRQ processing at group unbind time Boris Brezillon
2026-08-18 17:20 ` Liviu Dudau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.