drm/panfrost
Subsystems (8)
Boris Brezillon
maintainerv6 cover drm/panfrost
Hello,
Bunch of improvements to make the panfrost driver more robust and allow queuing jobs at the HW level.
Changes in v6:
* Collected acks/reviews
* Got rid of the cancel_delayed_work() calls in the reset path
Changes in this v5:
* Document what's excepted in the ->timedout_job() hook
* Add a patch increasing the AS_ACTIVE polling timeout
* Fix a few minor things here and there (see each commit for a detailed changelog) and collect R-b/A-b tags
Changes in this v4:
* fixing the reset serialization
* fixing a deadlock in the reset path
* moving the exception enum to a private header
Regards,
Boris
Boris Brezillon (15):
drm/sched: Document what the timedout_job method should do drm/sched: Allow using a dedicated workqueue for the timeout/fault tdr drm/panfrost: Make ->run_job() return an ERR_PTR() when appropriate drm/panfrost: Get rid of the unused JS_STATUS_EVENT_ACTIVE definition drm/panfrost: Drop the pfdev argument passed to
panfrost_exception_name()
drm/panfrost: Do the exception -> string translation using a table drm/panfrost: Expose a helper to trigger a GPU reset drm/panfrost: Use a threaded IRQ for job interrupts drm/panfrost: Simplify the reset serialization logic drm/panfrost: Make sure job interrupts are masked before resetting drm/panfrost: Disable the AS on unhandled page faults drm/panfrost: Reset the GPU when the AS_ACTIVE bit is stuck drm/panfrost: Don't reset the GPU on job faults unless we really have
to
drm/panfrost: Kill in-flight jobs on FD close drm/panfrost: Increase the AS_ACTIVE polling timeout
Steven Price (1):
drm/panfrost: Queue jobs on the hardware
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 +- drivers/gpu/drm/lima/lima_sched.c | 3 +- drivers/gpu/drm/panfrost/panfrost_device.c | 139 +++-- drivers/gpu/drm/panfrost/panfrost_device.h | 91 ++- drivers/gpu/drm/panfrost/panfrost_gpu.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 626 +++++++++++++++------ drivers/gpu/drm/panfrost/panfrost_mmu.c | 43 +- drivers/gpu/drm/panfrost/panfrost_regs.h | 3 - drivers/gpu/drm/scheduler/sched_main.c | 14 +- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 37 +- 12 files changed, 717 insertions(+), 256 deletions(-)
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 1/16 drm/sched: Document what the timedout_job method should do
The documentation is a bit vague and doesn't really describe what the ->timedout_job() is expected to do. Let's add a few more details.
v5:
* New patch
--- include/drm/gpu_scheduler.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/drm/gpu_scheduler.h +14 -0
@@ -239,6 +239,20 @@ struct drm_sched_backend_ops {* @timedout_job: Called when a job has taken too long to execute, * to trigger GPU recovery. * +* This method is called in a workqueue context. +* +* Drivers typically issue a reset to recover from GPU hangs, and this +* procedure usually follows the following workflow: +* +* 1. Stop the scheduler using drm_sched_stop(). This will park the +* scheduler thread and cancel the timeout work, guaranteeing that +* nothing is queued while we reset the hardware queue +* 2. Try to gracefully stop non-faulty jobs (optional) +* 3. Issue a GPU reset (driver-specific) +* 4. Re-submit jobs using drm_sched_resubmit_jobs() +* 5. Restart the scheduler using drm_sched_start(). At that point, new +* jobs can be queued, and the scheduler thread is unblocked +* * Return DRM_GPU_SCHED_STAT_NOMINAL, when all is normal, * and the underlying driver has started or completed recovery. *
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 2/16 drm/sched: Allow using a dedicated workqueue for the timeout/fault tdr
In reply to Boris BrezillonMali Midgard/Bifrost GPUs have 3 hardware queues but only a global GPU reset. This leads to extra complexity when we need to synchronize timeout works with the reset work. One solution to address that is to have an ordered workqueue at the driver level that will be used by the different schedulers to queue their timeout work. Thanks to the serialization provided by the ordered workqueue we are guaranteed that timeout handlers are executed sequentially, and can thus easily reset the GPU from the timeout handler without extra synchronization.
v5:
* Add a new paragraph to the timedout_job() method
v3:
* New patch
v4:
* Actually use the timeout_wq to queue the timeout work
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 ++- drivers/gpu/drm/lima/lima_sched.c | 3 ++- drivers/gpu/drm/panfrost/panfrost_job.c | 3 ++- drivers/gpu/drm/scheduler/sched_main.c | 14 +++++++++----- drivers/gpu/drm/v3d/v3d_sched.c | 10 +++++----- include/drm/gpu_scheduler.h | 23 ++++++++++++++++++++++- 7 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -1
@@ -490,7 +490,7 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, r =drm_sched_init (&ring->sched, &amdgpu_sched_ops, num_hw_submission, amdgpu_job_hang_limit, - timeout, sched_score, ring->name); + timeout,NULL , sched_score, ring->name);if (r) {DRM_ERROR ("Failed to create scheduler on ring %s.\n" , ring->name);
drivers/gpu/drm/etnaviv/etnaviv_sched.c +2 -1
@@ -190,7 +190,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, etnaviv_hw_jobs_limit, etnaviv_job_hang_limit, -msecs_to_jiffies (500 ),NULL ,dev_name (gpu->dev)); +msecs_to_jiffies (500 ),NULL ,NULL , +dev_name (gpu->dev));if (ret)return ret;
drivers/gpu/drm/lima/lima_sched.c +2 -1
@@ -508,7 +508,8 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work);return drm_sched_init (&pipe->base, &lima_sched_ops,1 , - lima_job_hang_limit,msecs_to_jiffies (timeout), + lima_job_hang_limit, +msecs_to_jiffies (timeout),NULL ,NULL , name); }
drivers/gpu/drm/panfrost/panfrost_job.c +2 -1
@@ -615,7 +615,8 @@ int panfrost_job_init(struct panfrost_device *pfdev) ret =drm_sched_init (&js->queue[j].sched, &panfrost_sched_ops, -1 ,0 ,msecs_to_jiffies (JOB_TIMEOUT_MS ), +1 ,0 , +msecs_to_jiffies (JOB_TIMEOUT_MS ),NULL ,NULL ,"pan_js" );if (ret) {dev_err (pfdev->dev,"Failed to create scheduler: %d." , ret);
drivers/gpu/drm/scheduler/sched_main.c +9 -5
@@ -232,7 +232,7 @@ static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched) {if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list)) -schedule_delayed_work (&sched->work_tdr, sched->timeout); +queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); }/**
@@ -244,7 +244,7 @@ static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched)*/ void drm_sched_fault (struct drm_gpu_scheduler *sched) { -mod_delayed_work (system_wq, &sched->work_tdr,0 ); +mod_delayed_work (sched->timeout_wq, &sched->work_tdr,0 ); }EXPORT_SYMBOL (drm_sched_fault);
@@ -270,7 +270,7 @@ unsigned long drm_sched_suspend_timeout(struct drm_gpu_scheduler *sched)* Modify the timeout to an arbitrarily large value. This also prevents * the timeout to be restarted when new submissions arrive */ -if (mod_delayed_work (system_wq, &sched->work_tdr,MAX_SCHEDULE_TIMEOUT ) +if (mod_delayed_work (sched->timeout_wq, &sched->work_tdr,MAX_SCHEDULE_TIMEOUT ) &&time_after (sched_timeout, now))return sched_timeout - now;else
@@ -294,7 +294,7 @@ void drm_sched_resume_timeout(struct drm_gpu_scheduler *sched,if (list_empty (&sched->pending_list))cancel_delayed_work (&sched->work_tdr);else -mod_delayed_work (system_wq, &sched->work_tdr, remaining); +mod_delayed_work (sched->timeout_wq, &sched->work_tdr, remaining);spin_unlock (&sched->job_list_lock); }
@@ -847,6 +847,8 @@ static int drm_sched_main(void *param)* @hw_submission: number of hw submissions that can be in flight * @hang_limit: number of times to allow a job to hang before dropping it * @timeout: timeout value in jiffies for the scheduler +* @timeout_wq: workqueue to use for timeout work. If NULL, the system_wq is +* used * @score: optional score atomic shared with other schedulers * @name: name used for debugging *
@@ -854,7 +856,8 @@ static int drm_sched_main(void *param)*/ int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, -unsigned hw_submission,unsigned hang_limit,long timeout, +unsigned hw_submission,unsigned hang_limit, +long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name) {int i, ret;
@@ -862,6 +865,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->hw_submission_limit = hw_submission; sched->name = name; sched->timeout = timeout; + sched->timeout_wq = timeout_wq ? : system_wq; sched->hang_limit = hang_limit; sched->score = score ? score : &sched->_score;for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)
drivers/gpu/drm/v3d/v3d_sched.c +5 -5
@@ -402,7 +402,7 @@ v3d_sched_init(struct v3d_dev *v3d) ret =drm_sched_init (&v3d->queue[V3D_BIN ].sched, &v3d_bin_sched_ops, hw_jobs_limit, job_hang_limit, -msecs_to_jiffies (hang_limit_ms), +msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_bin" );if (ret) {dev_err (v3d->drm.dev,"Failed to create bin scheduler: %d." , ret);
@@ -412,7 +412,7 @@ v3d_sched_init(struct v3d_dev *v3d) ret =drm_sched_init (&v3d->queue[V3D_RENDER ].sched, &v3d_render_sched_ops, hw_jobs_limit, job_hang_limit, -msecs_to_jiffies (hang_limit_ms), +msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_render" );if (ret) { dev_err(v3d->drm.dev, "Failed to create render scheduler: %d.",
@@ -424,7 +424,7 @@ v3d_sched_init(struct v3d_dev *v3d) ret =drm_sched_init (&v3d->queue[V3D_TFU ].sched, &v3d_tfu_sched_ops, hw_jobs_limit, job_hang_limit, -msecs_to_jiffies (hang_limit_ms), +msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_tfu" );if (ret) { dev_err(v3d->drm.dev, "Failed to create TFU scheduler: %d.",
@@ -437,7 +437,7 @@ v3d_sched_init(struct v3d_dev *v3d) ret =drm_sched_init (&v3d->queue[V3D_CSD ].sched, &v3d_csd_sched_ops, hw_jobs_limit, job_hang_limit, -msecs_to_jiffies (hang_limit_ms), +msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_csd" );if (ret) { dev_err(v3d->drm.dev, "Failed to create CSD scheduler: %d.",
@@ -449,7 +449,7 @@ v3d_sched_init(struct v3d_dev *v3d) ret =drm_sched_init (&v3d->queue[V3D_CACHE_CLEAN ].sched, &v3d_cache_clean_sched_ops, hw_jobs_limit, job_hang_limit, -msecs_to_jiffies (hang_limit_ms), +msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_cache_clean" );if (ret) { dev_err(v3d->drm.dev, "Failed to create CACHE_CLEAN scheduler: %d.",
include/drm/gpu_scheduler.h +22 -1
@@ -253,6 +253,24 @@ struct drm_sched_backend_ops {* 5. Restart the scheduler using drm_sched_start(). At that point, new * jobs can be queued, and the scheduler thread is unblocked * +* Note that some GPUs have distinct hardware queues but need to reset +* the GPU globally, which requires extra synchronization between the +* timeout handler of the different &drm_gpu_scheduler. One way to +* achieve this synchronization is to create an ordered workqueue +* (using alloc_ordered_workqueue()) at the driver level, and pass this +* queue to drm_sched_init(), to guarantee that timeout handlers are +* executed sequentially. The above workflow needs to be slightly +* adjusted in that case: +* +* 1. Stop all schedulers impacted by the reset using drm_sched_stop() +* 2. Try to gracefully stop non-faulty jobs on all queues impacted by +* the reset (optional) +* 3. Issue a GPU reset on all faulty queues (driver-specific) +* 4. Re-submit jobs on all schedulers impacted by the reset using +* drm_sched_resubmit_jobs() +* 5. Restart all schedulers that were stopped in step #1 using +* drm_sched_start() +* * Return DRM_GPU_SCHED_STAT_NOMINAL, when all is normal, * and the underlying driver has started or completed recovery. *
@@ -283,6 +301,7 @@ struct drm_sched_backend_ops {* finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. +* @timeout_wq: workqueue used to queue @work_tdr * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. * @thread: the kthread on which the scheduler which run.
@@ -307,6 +326,7 @@ struct drm_gpu_scheduler {wait_queue_head_t job_scheduled;atomic_t hw_rq_count;atomic64_t job_id_count; +struct workqueue_struct *timeout_wq;struct delayed_work work_tdr;struct task_struct *thread;struct list_head pending_list;
@@ -320,7 +340,8 @@ struct drm_gpu_scheduler {int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, -uint32_t hw_submission,unsigned hang_limit,long timeout, +uint32_t hw_submission,unsigned hang_limit, +long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name);void drm_sched_fini (struct drm_gpu_scheduler *sched);
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 3/16 drm/panfrost: Make ->run_job() return an ERR_PTR() when appropriate
In reply to Boris BrezillonIf the fence creation fail, we can return the error pointer directly. The core will update the fence error accordingly.
--- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_job.c +1 -1
@@ -344,7 +344,7 @@ static struct dma_fence *panfrost_job_run(struct drm_sched_job *sched_job) fence =panfrost_fence_create (pfdev, slot);if (IS_ERR (fence)) -return NULL ; +return fence;if (job->done_fence)dma_fence_put (job->done_fence);
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 4/16 drm/panfrost: Get rid of the unused JS_STATUS_EVENT_ACTIVE definition
In reply to Boris BrezillonException types will be defined as an enum.
v4:
* Fix typo in the commit message
--- drivers/gpu/drm/panfrost/panfrost_regs.h | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_regs.h +0 -3
@@ -262,9 +262,6 @@#define JS_COMMAND_SOFT_STOP_1 0x06/* Execute SOFT_STOP if JOB_CHAIN_FLAG is 1 */ #define JS_COMMAND_HARD_STOP_1 0x07/* Execute HARD_STOP if JOB_CHAIN_FLAG is 1 */ -#define JS_STATUS_EVENT_ACTIVE 0x08 - -/* MMU regs */ #define MMU_INT_RAWSTAT 0x2000#define MMU_INT_CLEAR 0x2004
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 5/16 drm/panfrost: Drop the pfdev argument passed to panfrost_exception_name()
In reply to Boris BrezillonCurrently unused. We'll add it back if we need per-GPU definitions.
--- drivers/gpu/drm/panfrost/panfrost_device.c | 2 +- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_gpu.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +1 -1
@@ -292,7 +292,7 @@ void panfrost_device_fini(struct panfrost_device *pfdev)panfrost_clk_fini (pfdev); } -const char *panfrost_exception_name (struct panfrost_device *pfdev,u32 exception_code) +const char *panfrost_exception_name (u32 exception_code) {switch (exception_code) {/* Non-Fault Status code */
drivers/gpu/drm/panfrost/panfrost_device.h +1 -1
@@ -173,6 +173,6 @@ void panfrost_device_reset(struct panfrost_device *pfdev);int panfrost_device_resume (struct device *dev);int panfrost_device_suspend (struct device *dev); -const char *panfrost_exception_name (struct panfrost_device *pfdev,u32 exception_code); +const char *panfrost_exception_name (u32 exception_code);#endif
drivers/gpu/drm/panfrost/panfrost_gpu.c +1 -1
@@ -33,7 +33,7 @@ static irqreturn_t panfrost_gpu_irq_handler(int irq, void *data) address |=gpu_read (pfdev,GPU_FAULT_ADDRESS_LO );dev_warn (pfdev->dev,"GPU Fault 0x%08x (%s) at 0x%016llx\n" , - fault_status &0xFF ,panfrost_exception_name (pfdev, fault_status), + fault_status &0xFF ,panfrost_exception_name (fault_status), address);if (state &GPU_IRQ_MULTIPLE_FAULT )
drivers/gpu/drm/panfrost/panfrost_job.c +1 -1
@@ -489,7 +489,7 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , j, -panfrost_exception_name (pfdev,job_read (pfdev,JS_STATUS (j))), +panfrost_exception_name (job_read (pfdev,JS_STATUS (j))),job_read (pfdev,JS_HEAD_LO (j)),job_read (pfdev,JS_TAIL_LO (j)));
drivers/gpu/drm/panfrost/panfrost_mmu.c +1 -1
@@ -675,7 +675,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data)"TODO" , fault_status, (fault_status & (1 <<10 ) ?"DECODER FAULT" :"SLAVE FAULT" ), - exception_type,panfrost_exception_name (pfdev, exception_type), + exception_type,panfrost_exception_name (exception_type), access_type,access_type_name (pfdev, fault_status), source_id);
Signature · 1 line
2.31.1
Re: [PATCH v6 05/16] drm/panfrost: Drop the pfdev argument passed to panfrost_exception_name()
Quoted 79 lines · Boris Brezillon
Currently unused. We'll add it back if we need per-GPU definitions.
Signed-off-by Boris Brezillon <[email protected]>Reviewed-by Steven Price <[email protected]>--- drivers/gpu/drm/panfrost/panfrost_device.c | 2 +- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_gpu.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-1@@ -292,7 +292,7 @@ void panfrost_device_fini(struct panfrost_device *pfdev)panfrost_clk_fini (pfdev); } -const char *panfrost_exception_name (struct panfrost_device *pfdev,u32 exception_code) +const char *panfrost_exception_name (u32 exception_code) {switch (exception_code) {/* Non-Fault Status code */ drivers/gpu/drm/panfrost/panfrost_device.h +1
-1@@ -173,6 +173,6 @@ void panfrost_device_reset(struct panfrost_device *pfdev);int panfrost_device_resume (struct device *dev);int panfrost_device_suspend (struct device *dev); -const char *panfrost_exception_name (struct panfrost_device *pfdev,u32 exception_code); +const char *panfrost_exception_name (u32 exception_code);#endif drivers/gpu/drm/panfrost/panfrost_gpu.c +1
-1@@ -33,7 +33,7 @@ static irqreturn_t panfrost_gpu_irq_handler(int irq, void *data) address |=gpu_read (pfdev,GPU_FAULT_ADDRESS_LO );dev_warn (pfdev->dev,"GPU Fault 0x%08x (%s) at 0x%016llx\n" , - fault_status &0xFF ,panfrost_exception_name (pfdev, fault_status), + fault_status &0xFF ,panfrost_exception_name (fault_status), address);if (state &GPU_IRQ_MULTIPLE_FAULT )drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -489,7 +489,7 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , j, -panfrost_exception_name (pfdev,job_read (pfdev,JS_STATUS (j))), +panfrost_exception_name (job_read (pfdev,JS_STATUS (j))),job_read (pfdev,JS_HEAD_LO (j)),job_read (pfdev,JS_TAIL_LO (j)));drivers/gpu/drm/panfrost/panfrost_mmu.c +1
-1@@ -675,7 +675,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data)"TODO" , fault_status, (fault_status & (1 <<10 ) ?"DECODER FAULT" :"SLAVE FAULT" ), - exception_type,panfrost_exception_name (pfdev, exception_type), + exception_type,panfrost_exception_name (exception_type), access_type,access_type_name (pfdev, fault_status), source_id);Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 6/16 drm/panfrost: Do the exception -> string translation using a table
In reply to Boris BrezillonDo the exception -> string translation using a table. This way we get rid of those magic numbers and can easily add new fields if we need to attach extra information to exception types.
v4:
* Don't expose exception type to userspace
* Merge the enum definition and the enum -> string table declaration in the same patch
v3:
* Drop the error field
--- drivers/gpu/drm/panfrost/panfrost_device.c | 130 +++++++++++++-------- drivers/gpu/drm/panfrost/panfrost_device.h | 69 +++++++++++ 2 files changed, 152 insertions(+), 47 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +83 -47
@@ -292,55 +292,91 @@ void panfrost_device_fini(struct panfrost_device *pfdev)panfrost_clk_fini (pfdev); } -const char *panfrost_exception_name (u32 exception_code) -{ -switch (exception_code) { -/* Non-Fault Status code */ -case 0x00 :return "NOT_STARTED/IDLE/OK" ; -case 0x01 :return "DONE" ; -case 0x02 :return "INTERRUPTED" ; -case 0x03 :return "STOPPED" ; -case 0x04 :return "TERMINATED" ; -case 0x08 :return "ACTIVE" ; -/* Job exceptions */ -case 0x40 :return "JOB_CONFIG_FAULT" ; -case 0x41 :return "JOB_POWER_FAULT" ; -case 0x42 :return "JOB_READ_FAULT" ; -case 0x43 :return "JOB_WRITE_FAULT" ; -case 0x44 :return "JOB_AFFINITY_FAULT" ; -case 0x48 :return "JOB_BUS_FAULT" ; -case 0x50 :return "INSTR_INVALID_PC" ; -case 0x51 :return "INSTR_INVALID_ENC" ; -case 0x52 :return "INSTR_TYPE_MISMATCH" ; -case 0x53 :return "INSTR_OPERAND_FAULT" ; -case 0x54 :return "INSTR_TLS_FAULT" ; -case 0x55 :return "INSTR_BARRIER_FAULT" ; -case 0x56 :return "INSTR_ALIGN_FAULT" ; -case 0x58 :return "DATA_INVALID_FAULT" ; -case 0x59 :return "TILE_RANGE_FAULT" ; -case 0x5A :return "ADDR_RANGE_FAULT" ; -case 0x60 :return "OUT_OF_MEMORY" ; -/* GPU exceptions */ -case 0x80 :return "DELAYED_BUS_FAULT" ; -case 0x88 :return "SHAREABILITY_FAULT" ; -/* MMU exceptions */ -case 0xC1 :return "TRANSLATION_FAULT_LEVEL1" ; -case 0xC2 :return "TRANSLATION_FAULT_LEVEL2" ; -case 0xC3 :return "TRANSLATION_FAULT_LEVEL3" ; -case 0xC4 :return "TRANSLATION_FAULT_LEVEL4" ; -case 0xC8 :return "PERMISSION_FAULT" ; - case 0xC9 ... 0xCF: return "PERMISSION_FAULT"; -case 0xD1 :return "TRANSTAB_BUS_FAULT_LEVEL1" ; -case 0xD2 :return "TRANSTAB_BUS_FAULT_LEVEL2" ; -case 0xD3 :return "TRANSTAB_BUS_FAULT_LEVEL3" ; -case 0xD4 :return "TRANSTAB_BUS_FAULT_LEVEL4" ; -case 0xD8 :return "ACCESS_FLAG" ; - case 0xD9 ... 0xDF: return "ACCESS_FLAG"; - case 0xE0 ... 0xE7: return "ADDRESS_SIZE_FAULT"; - case 0xE8 ... 0xEF: return "MEMORY_ATTRIBUTES_FAULT"; +#define PANFROST_EXCEPTION (id) \ + [DRM_PANFROST_EXCEPTION_ ## id] = { \ + .name = #id, \ } -return "UNKNOWN" ; +struct panfrost_exception_info { +const char *name; +}; + +static const struct panfrost_exception_info panfrost_exception_infos[] = { +PANFROST_EXCEPTION (OK ), +PANFROST_EXCEPTION (DONE ), +PANFROST_EXCEPTION (INTERRUPTED ), +PANFROST_EXCEPTION (STOPPED ), +PANFROST_EXCEPTION (TERMINATED ), +PANFROST_EXCEPTION (KABOOM ), +PANFROST_EXCEPTION (EUREKA ), +PANFROST_EXCEPTION (ACTIVE ), +PANFROST_EXCEPTION (JOB_CONFIG_FAULT ), +PANFROST_EXCEPTION (JOB_POWER_FAULT ), +PANFROST_EXCEPTION (JOB_READ_FAULT ), +PANFROST_EXCEPTION (JOB_WRITE_FAULT ), +PANFROST_EXCEPTION (JOB_AFFINITY_FAULT ), +PANFROST_EXCEPTION (JOB_BUS_FAULT ), +PANFROST_EXCEPTION (INSTR_INVALID_PC ), +PANFROST_EXCEPTION (INSTR_INVALID_ENC ), +PANFROST_EXCEPTION (INSTR_TYPE_MISMATCH ), +PANFROST_EXCEPTION (INSTR_OPERAND_FAULT ), +PANFROST_EXCEPTION (INSTR_TLS_FAULT ), +PANFROST_EXCEPTION (INSTR_BARRIER_FAULT ), +PANFROST_EXCEPTION (INSTR_ALIGN_FAULT ), +PANFROST_EXCEPTION (DATA_INVALID_FAULT ), +PANFROST_EXCEPTION (TILE_RANGE_FAULT ), +PANFROST_EXCEPTION (ADDR_RANGE_FAULT ), +PANFROST_EXCEPTION (IMPRECISE_FAULT ), +PANFROST_EXCEPTION (OOM ), +PANFROST_EXCEPTION (OOM_AFBC ), +PANFROST_EXCEPTION (UNKNOWN ), +PANFROST_EXCEPTION (DELAYED_BUS_FAULT ), +PANFROST_EXCEPTION (GPU_SHAREABILITY_FAULT ), +PANFROST_EXCEPTION (SYS_SHAREABILITY_FAULT ), +PANFROST_EXCEPTION (GPU_CACHEABILITY_FAULT ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_0 ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_1 ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_2 ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_3 ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_4 ), +PANFROST_EXCEPTION (TRANSLATION_FAULT_IDENTITY ), +PANFROST_EXCEPTION (PERM_FAULT_0 ), +PANFROST_EXCEPTION (PERM_FAULT_1 ), +PANFROST_EXCEPTION (PERM_FAULT_2 ), +PANFROST_EXCEPTION (PERM_FAULT_3 ), +PANFROST_EXCEPTION (TRANSTAB_BUS_FAULT_0 ), +PANFROST_EXCEPTION (TRANSTAB_BUS_FAULT_1 ), +PANFROST_EXCEPTION (TRANSTAB_BUS_FAULT_2 ), +PANFROST_EXCEPTION (TRANSTAB_BUS_FAULT_3 ), +PANFROST_EXCEPTION (ACCESS_FLAG_0 ), +PANFROST_EXCEPTION (ACCESS_FLAG_1 ), +PANFROST_EXCEPTION (ACCESS_FLAG_2 ), +PANFROST_EXCEPTION (ACCESS_FLAG_3 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_IN0 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_IN1 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_IN2 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_IN3 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_OUT0 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_OUT1 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_OUT2 ), +PANFROST_EXCEPTION (ADDR_SIZE_FAULT_OUT3 ), +PANFROST_EXCEPTION (MEM_ATTR_FAULT_0 ), +PANFROST_EXCEPTION (MEM_ATTR_FAULT_1 ), +PANFROST_EXCEPTION (MEM_ATTR_FAULT_2 ), +PANFROST_EXCEPTION (MEM_ATTR_FAULT_3 ), +PANFROST_EXCEPTION (MEM_ATTR_NONCACHE_0 ), +PANFROST_EXCEPTION (MEM_ATTR_NONCACHE_1 ), +PANFROST_EXCEPTION (MEM_ATTR_NONCACHE_2 ), +PANFROST_EXCEPTION (MEM_ATTR_NONCACHE_3 ), +}; + +const char *panfrost_exception_name (u32 exception_code) +{ +if (WARN_ON (exception_code >=ARRAY_SIZE (panfrost_exception_infos) || + !panfrost_exception_infos[exception_code].name)) +return "Unknown exception type" ; + +return panfrost_exception_infos[exception_code].name; }void panfrost_device_reset (struct panfrost_device *pfdev)
drivers/gpu/drm/panfrost/panfrost_device.h +69 -0
75 lines not on this page · raw message
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 7/16 drm/panfrost: Expose a helper to trigger a GPU reset
In reply to Boris BrezillonExpose a helper to trigger a GPU reset so we can easily trigger reset operations outside the job timeout handler.
--- drivers/gpu/drm/panfrost/panfrost_device.h | 8 ++++++++ drivers/gpu/drm/panfrost/panfrost_job.c | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +8 -0
@@ -244,4 +244,12 @@ enum drm_panfrost_exception_type {const char *panfrost_exception_name (u32 exception_code); +static inline void +panfrost_device_schedule_reset (struct panfrost_device *pfdev) +{ +/* Schedule a reset if there's no reset in progress. */ +if (!atomic_xchg (&pfdev->reset.pending,1 )) +schedule_work (&pfdev->reset.work); +} +#endif
drivers/gpu/drm/panfrost/panfrost_job.c +1 -3
@@ -447,9 +447,7 @@ static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_jobif (!panfrost_scheduler_stop (&pfdev->js->queue[js], sched_job))return DRM_GPU_SCHED_STAT_NOMINAL ; -/* Schedule a reset if there's no reset in progress. */ -if (!atomic_xchg (&pfdev->reset.pending,1 )) -schedule_work (&pfdev->reset.work); +panfrost_device_schedule_reset (pfdev);return DRM_GPU_SCHED_STAT_NOMINAL ; }
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 8/16 drm/panfrost: Use a threaded IRQ for job interrupts
In reply to Boris BrezillonThis should avoid switching to interrupt context when the GPU is under heavy use.
v3:
* Don't take the job_lock in panfrost_job_handle_irq()
--- drivers/gpu/drm/panfrost/panfrost_job.c | 53 ++++++++++++++++++------- 1 file changed, 38 insertions(+), 15 deletions(-)
drivers/gpu/drm/panfrost/panfrost_job.c +38 -15
@@ -459,19 +459,12 @@ static const struct drm_sched_backend_ops panfrost_sched_ops = { .free_job = panfrost_job_free }; -static irqreturn_t panfrost_job_irq_handler (int irq,void *data) +static void panfrost_job_handle_irq (struct panfrost_device *pfdev,u32 status) { -struct panfrost_device *pfdev = data; -u32 status =job_read (pfdev,JOB_INT_STAT );int j;dev_dbg (pfdev->dev,"jobslot irq status=%x\n" , status); -if (!status) -return IRQ_NONE ; - -pm_runtime_mark_last_busy (pfdev->dev); -for (j =0 ; status; j++) {u32 mask =MK_JS_MASK (j);
@@ -508,7 +501,6 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)if (status &JOB_INT_MASK_DONE (j)) {struct panfrost_job *job; -spin_lock (&pfdev->js->job_lock); job = pfdev->jobs[j];/* Only NULL if job timeout occurred */ if (job) {
@@ -520,21 +512,49 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)dma_fence_signal_locked (job->done_fence);pm_runtime_put_autosuspend (pfdev->dev); } -spin_unlock (&pfdev->js->job_lock); } status &= ~mask; } +} +static irqreturn_t panfrost_job_irq_handler_thread (int irq,void *data) +{ +struct panfrost_device *pfdev = data; +u32 status =job_read (pfdev,JOB_INT_RAWSTAT ); + +while (status) { +pm_runtime_mark_last_busy (pfdev->dev); + +spin_lock (&pfdev->js->job_lock); +panfrost_job_handle_irq (pfdev, status); +spin_unlock (&pfdev->js->job_lock); + status =job_read (pfdev,JOB_INT_RAWSTAT ); + } + +job_write (pfdev,JOB_INT_MASK , +GENMASK (16 +NUM_JOB_SLOTS -1 ,16 ) | +GENMASK (NUM_JOB_SLOTS -1 ,0 ));return IRQ_HANDLED ; } +static irqreturn_t panfrost_job_irq_handler (int irq,void *data) +{ +struct panfrost_device *pfdev = data; +u32 status =job_read (pfdev,JOB_INT_STAT ); + +if (!status) +return IRQ_NONE ; + +job_write (pfdev,JOB_INT_MASK ,0 ); +return IRQ_WAKE_THREAD ; +} +static void panfrost_reset (struct work_struct *work) {struct panfrost_device *pfdev =container_of (work, struct panfrost_device, reset.work); -unsigned long flags;unsigned int i;bool cookie;
@@ -564,7 +584,7 @@ static void panfrost_reset(struct work_struct *work)/* All timers have been stopped, we can safely reset the pending state. */ atomic_set (&pfdev->reset.pending,0 ); -spin_lock_irqsave (&pfdev->js->job_lock, flags); +spin_lock (&pfdev->js->job_lock);for (i =0 ; i <NUM_JOB_SLOTS ; i++) {if (pfdev->jobs[i]) {pm_runtime_put_noidle (pfdev->dev);
@@ -572,7 +592,7 @@ static void panfrost_reset(struct work_struct *work) pfdev->jobs[i] =NULL ; } } -spin_unlock_irqrestore (&pfdev->js->job_lock, flags); +spin_unlock (&pfdev->js->job_lock);panfrost_device_reset (pfdev);
@@ -599,8 +619,11 @@ int panfrost_job_init(struct panfrost_device *pfdev)if (irq <=0 )return -ENODEV ; - ret =devm_request_irq (pfdev->dev, irq, panfrost_job_irq_handler, -IRQF_SHARED ,KBUILD_MODNAME "-job" , pfdev); + ret =devm_request_threaded_irq (pfdev->dev, irq, + panfrost_job_irq_handler, + panfrost_job_irq_handler_thread, +IRQF_SHARED ,KBUILD_MODNAME "-job" , + pfdev);if (ret) {dev_err (pfdev->dev,"failed to request job irq" );return ret;
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 9/16 drm/panfrost: Simplify the reset serialization logic
In reply to Boris BrezillonNow that we can pass our own workqueue to drm_sched_init(), we can use an ordered workqueue on for both the scheduler timeout tdr and our own reset work (which we use when the reset is not caused by a fault/timeout on a specific job, like when we have AS_ACTIVE bit stuck). This guarantees that the timeout handlers and reset handler can't run concurrently which drastically simplifies the locking.
v5:
* Don't call cancel_delayed_timeout() in the reset path (those works are canceled in drm_sched_stop())
v4:
* Actually pass the reset workqueue to drm_sched_init()
* Don't call cancel_work_sync() in panfrost_reset(). It will deadlock since it might be called from the reset work, which is executing and cancel_work_sync() will wait for the handler to return. Checking the reset pending status should avoid spurious resets
v3:
* New patch
--- drivers/gpu/drm/panfrost/panfrost_device.h | 6 +- drivers/gpu/drm/panfrost/panfrost_job.c | 186 ++++++++------------- 2 files changed, 69 insertions(+), 123 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +3 -3
@@ -109,6 +109,7 @@ struct panfrost_device {struct mutex sched_lock;struct { +struct workqueue_struct *wq;struct work_struct work;atomic_t pending; } reset;
@@ -247,9 +248,8 @@ const char *panfrost_exception_name(u32 exception_code);static inline void panfrost_device_schedule_reset (struct panfrost_device *pfdev) { -/* Schedule a reset if there's no reset in progress. */ -if (!atomic_xchg (&pfdev->reset.pending,1 )) -schedule_work (&pfdev->reset.work); +atomic_set (&pfdev->reset.pending,1 ); +queue_work (pfdev->reset.wq, &pfdev->reset.work); }#endif
drivers/gpu/drm/panfrost/panfrost_job.c +66 -120
271 lines not on this page · raw message
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 10/16 drm/panfrost: Make sure job interrupts are masked before resetting
In reply to Boris BrezillonThis is not yet needed because we let active jobs be killed during by the reset and we don't really bother making sure they can be restarted. But once we start adding soft-stop support, controlling when we deal with the remaining interrrupts and making sure those are handled before the reset is issued gets tricky if we keep job interrupts active.
Let's prepare for that and mask+flush job IRQs before issuing a reset.
v4:
* Add a comment explaining why we WARN_ON(!job) in the irq handler
* Keep taking the job_lock when evicting stalled jobs
v3:
* New patch
--- drivers/gpu/drm/panfrost/panfrost_job.c | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/gpu/drm/panfrost/panfrost_job.c +22 -5
@@ -34,6 +34,7 @@ struct panfrost_queue_state {struct panfrost_job_slot {struct panfrost_queue_state queue[NUM_JOB_SLOTS ];spinlock_t job_lock; +int irq; }; static struct panfrost_job *
@@ -389,6 +390,15 @@ static void panfrost_reset(struct panfrost_device *pfdev,if (bad)drm_sched_increase_karma (bad); +/* Mask job interrupts and synchronize to make sure we won't be +* interrupted during our reset. +*/ +job_write (pfdev,JOB_INT_MASK ,0 ); +synchronize_irq (pfdev->js->irq); + +/* Schedulers are stopped and interrupts are masked+flushed, we don't +* need to protect the 'evict unfinished jobs' lock with the job_lock. +*/ spin_lock (&pfdev->js->job_lock);for (i =0 ; i <NUM_JOB_SLOTS ; i++) {if (pfdev->jobs[i]) {
@@ -486,7 +496,14 @@ static void panfrost_job_handle_irq(struct panfrost_device *pfdev, u32 status)struct panfrost_job *job; job = pfdev->jobs[j]; -/* Only NULL if job timeout occurred */ +/* The only reason this job could be NULL is if the +* job IRQ handler is called just after the +* in-flight job eviction in the reset path, and +* this shouldn't happen because the job IRQ has +* been masked and synchronized when this eviction +* happens. +*/ +WARN_ON (!job);if (job) { pfdev->jobs[j] =NULL ;
@@ -546,7 +563,7 @@ static void panfrost_reset_work(struct work_struct *work)int panfrost_job_init (struct panfrost_device *pfdev) {struct panfrost_job_slot *js; -int ret, j, irq; +int ret, j;INIT_WORK (&pfdev->reset.work, panfrost_reset_work);
@@ -556,11 +573,11 @@ int panfrost_job_init(struct panfrost_device *pfdev)spin_lock_init (&js->job_lock); - irq =platform_get_irq_byname (to_platform_device (pfdev->dev),"job" ); -if (irq <=0 ) + js->irq =platform_get_irq_byname (to_platform_device (pfdev->dev),"job" ); +if (js->irq <=0 )return -ENODEV ; - ret = devm_request_threaded_irq(pfdev->dev, irq, + ret = devm_request_threaded_irq(pfdev->dev, js->irq, panfrost_job_irq_handler, panfrost_job_irq_handler_thread, IRQF_SHARED, KBUILD_MODNAME "-job",
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 11/16 drm/panfrost: Disable the AS on unhandled page faults
In reply to Boris BrezillonIf we don't do that, we have to wait for the job timeout to expire before the fault jobs gets killed.
v3:
* Make sure the AS is re-enabled when new jobs are submitted to the context
--- drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_mmu.c | 34 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +1 -0
@@ -97,6 +97,7 @@ struct panfrost_device {spinlock_t as_lock;unsigned long as_in_use_mask;unsigned long as_alloc_mask; +unsigned long as_faulty_mask;struct list_head as_lru_list;struct panfrost_job_slot *js;
drivers/gpu/drm/panfrost/panfrost_mmu.c +31 -3
@@ -154,6 +154,7 @@ u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) as = mmu->as;if (as >=0 ) {int en =atomic_inc_return (&mmu->as_count); +u32 mask =BIT (as) |BIT (16 + as);/* * AS can be retained by active jobs or a perfcnt context,
@@ -162,6 +163,18 @@ u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu)WARN_ON (en >= (NUM_JOB_SLOTS +1 ));list_move (&mmu->list, &pfdev->as_lru_list); + +if (pfdev->as_faulty_mask & mask) { +/* Unhandled pagefault on this AS, the MMU was +* disabled. We need to re-enable the MMU after +* clearing+unmasking the AS interrupts. +*/ +mmu_write (pfdev,MMU_INT_CLEAR , mask); +mmu_write (pfdev,MMU_INT_MASK , ~pfdev->as_faulty_mask); + pfdev->as_faulty_mask &= ~mask; +panfrost_mmu_enable (pfdev, mmu); + } + goto out; }
@@ -211,6 +224,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_lock (&pfdev->as_lock); pfdev->as_alloc_mask =0 ; + pfdev->as_faulty_mask =0 ;list_for_each_entry_safe (mmu, mmu_tmp, &pfdev->as_lru_list, list) { mmu->as =-1 ;
@@ -661,7 +675,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data)if ((status & mask) ==BIT (as) && (exception_type &0xF8 ) ==0xC0 ) ret =panfrost_mmu_map_fault_addr (pfdev, as, addr); -if (ret) +if (ret) {/* terminal fault, print info about the fault */ dev_err (pfdev->dev, "Unhandled Page fault in AS%d at VA 0x%016llX\n"
@@ -679,14 +693,28 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data) access_type,access_type_name (pfdev, fault_status), source_id); +spin_lock (&pfdev->as_lock); +/* Ignore MMU interrupts on this AS until it's been +* re-enabled. +*/ + pfdev->as_faulty_mask |= mask; + +/* Disable the MMU to kill jobs on this AS. */ +panfrost_mmu_disable (pfdev, as); +spin_unlock (&pfdev->as_lock); + } + status &= ~mask;/* If we received new MMU interrupts, process them before returning. */ if (!status) - status =mmu_read (pfdev,MMU_INT_RAWSTAT ); + status =mmu_read (pfdev,MMU_INT_RAWSTAT ) & ~pfdev->as_faulty_mask; } -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +spin_lock (&pfdev->as_lock); +mmu_write (pfdev,MMU_INT_MASK , ~pfdev->as_faulty_mask); +spin_unlock (&pfdev->as_lock); +return IRQ_HANDLED ; };
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 12/16 drm/panfrost: Reset the GPU when the AS_ACTIVE bit is stuck
In reply to Boris BrezillonThings are unlikely to resolve until we reset the GPU. Let's not wait for other faults/timeout to happen to trigger this reset.
--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_mmu.c +4 -1
@@ -36,8 +36,11 @@ static int wait_ready(struct panfrost_device *pfdev, u32 as_nr) ret =readl_relaxed_poll_timeout_atomic (pfdev->iomem +AS_STATUS (as_nr), val, !(val &AS_STATUS_AS_ACTIVE ),10 ,1000 ); -if (ret) +if (ret) { +/* The GPU hung, let's trigger a reset */ +panfrost_device_schedule_reset (pfdev);dev_err (pfdev->dev,"AS_ACTIVE bit stuck\n" ); + }return ret; }
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 13/16 drm/panfrost: Don't reset the GPU on job faults unless we really have to
In reply to Boris BrezillonIf we can recover from a fault without a reset there's no reason to issue one.
v3:
* Drop the mention of Valhall requiring a reset on JOB_BUS_FAULT
* Set the fence error to -EINVAL instead of having per-exception error codes
--- drivers/gpu/drm/panfrost/panfrost_device.c | 9 +++++++++ drivers/gpu/drm/panfrost/panfrost_device.h | 2 ++ drivers/gpu/drm/panfrost/panfrost_job.c | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +9 -0
@@ -379,6 +379,15 @@ const char *panfrost_exception_name(u32 exception_code)return panfrost_exception_infos[exception_code].name; } +bool panfrost_exception_needs_reset (const struct panfrost_device *pfdev, +u32 exception_code) +{ +/* Right now, none of the GPU we support need a reset, but this +* might change. +*/ +return false; +} +void panfrost_device_reset (struct panfrost_device *pfdev) {panfrost_gpu_soft_reset (pfdev);
drivers/gpu/drm/panfrost/panfrost_device.h +2 -0
@@ -245,6 +245,8 @@ enum drm_panfrost_exception_type { };const char *panfrost_exception_name (u32 exception_code); +bool panfrost_exception_needs_reset (const struct panfrost_device *pfdev, +u32 exception_code);static inline void panfrost_device_schedule_reset (struct panfrost_device *pfdev)
drivers/gpu/drm/panfrost/panfrost_job.c +14 -2
@@ -482,14 +482,26 @@ static void panfrost_job_handle_irq(struct panfrost_device *pfdev, u32 status)job_write (pfdev,JOB_INT_CLEAR , mask);if (status &JOB_INT_MASK_ERR (j)) { +u32 js_status =job_read (pfdev,JS_STATUS (j)); +job_write (pfdev,JS_COMMAND_NEXT (j),JS_COMMAND_NOP );dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , j, -panfrost_exception_name (job_read (pfdev,JS_STATUS (j))), +panfrost_exception_name (js_status),job_read (pfdev,JS_HEAD_LO (j)),job_read (pfdev,JS_TAIL_LO (j))); -drm_sched_fault (&pfdev->js->queue[j].sched); + +/* If we need a reset, signal it to the timeout +* handler, otherwise, update the fence error field and +* signal the job fence. +*/ +if (panfrost_exception_needs_reset (pfdev, js_status)) { +drm_sched_fault (&pfdev->js->queue[j].sched); + }else { +dma_fence_set_error (pfdev->jobs[j]->done_fence, -EINVAL ); + status |=JOB_INT_MASK_DONE (j); + } }if (status &JOB_INT_MASK_DONE (j)) {
Signature · 1 line
2.31.1
Boris Brezillon
maintainerPATCH v6 14/16 drm/panfrost: Kill in-flight jobs on FD close
In reply to Boris BrezillonIf the process who submitted these jobs decided to close the FD before the jobs are done it probably means it doesn't care about the result.
v5:
* Add a panfrost_exception_is_fault() helper and the DRM_PANFROST_EXCEPTION_MAX_NON_FAULT value
v4:
* Don't disable/restore irqs when taking the job_lock (not needed since this lock is never taken from an interrupt context)
v3:
* Set fence error to ECANCELED when a TERMINATED exception is received
--- drivers/gpu/drm/panfrost/panfrost_device.h | 7 ++++ drivers/gpu/drm/panfrost/panfrost_job.c | 42 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +7 -0
@@ -184,6 +184,7 @@ enum drm_panfrost_exception_type {DRM_PANFROST_EXCEPTION_KABOOM =0x05 ,DRM_PANFROST_EXCEPTION_EUREKA =0x06 ,DRM_PANFROST_EXCEPTION_ACTIVE =0x08 , +DRM_PANFROST_EXCEPTION_MAX_NON_FAULT =0x3f ,DRM_PANFROST_EXCEPTION_JOB_CONFIG_FAULT =0x40 ,DRM_PANFROST_EXCEPTION_JOB_POWER_FAULT =0x41 , DRM_PANFROST_EXCEPTION_JOB_READ_FAULT = 0x42,
@@ -244,6 +245,12 @@ enum drm_panfrost_exception_type { DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_3 = 0xef, }; +static inline bool +panfrost_exception_is_fault (u32 exception_code) +{ +return exception_code >DRM_PANFROST_EXCEPTION_MAX_NON_FAULT ; +} +const char *panfrost_exception_name (u32 exception_code);bool panfrost_exception_needs_reset (const struct panfrost_device *pfdev,u32 exception_code);
drivers/gpu/drm/panfrost/panfrost_job.c +36 -6
67 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v6 14/16] drm/panfrost: Kill in-flight jobs on FD close
Quoted 11 lines · Boris Brezillon
If the process who submitted these jobs decided to close the FD before the jobs are done it probably means it doesn't care about the result.
v5:
* Add apanfrost_exception_is_fault()helper and theDRM_PANFROST_EXCEPTION_MAX_NON_FAULTvaluev4:
* Don't disable/restore irqs when taking thejob_lock(not needed since this lock is never taken from an interrupt context)
Quoted 8 lines
v3:
* Set fence error to ECANCELED when a TERMINATED exception is receivedSigned-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panfrost/panfrost_device.h | 7 ++++ drivers/gpu/drm/panfrost/panfrost_job.c | 42 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-)
The panfrost_exception_is_fault() makes the code much more readable - thanks!
Quoted 101 lines
drivers/gpu/drm/panfrost/panfrost_device.h +7
-0@@ -184,6 +184,7 @@ enum drm_panfrost_exception_type {DRM_PANFROST_EXCEPTION_KABOOM =0x05 ,DRM_PANFROST_EXCEPTION_EUREKA =0x06 ,DRM_PANFROST_EXCEPTION_ACTIVE =0x08 , +DRM_PANFROST_EXCEPTION_MAX_NON_FAULT =0x3f ,DRM_PANFROST_EXCEPTION_JOB_CONFIG_FAULT =0x40 ,DRM_PANFROST_EXCEPTION_JOB_POWER_FAULT =0x41 , DRM_PANFROST_EXCEPTION_JOB_READ_FAULT = 0x42,@@ -244,6 +245,12 @@ enum drm_panfrost_exception_type { DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_3 = 0xef, }; +static inline bool +panfrost_exception_is_fault (u32 exception_code) +{ +return exception_code >DRM_PANFROST_EXCEPTION_MAX_NON_FAULT ; +} +const char *panfrost_exception_name (u32 exception_code);bool panfrost_exception_needs_reset (const struct panfrost_device *pfdev,u32 exception_code);drivers/gpu/drm/panfrost/panfrost_job.c +36
-6@@ -483,14 +483,21 @@ static void panfrost_job_handle_irq(struct panfrost_device *pfdev, u32 status)if (status &JOB_INT_MASK_ERR (j)) {u32 js_status =job_read (pfdev,JS_STATUS (j)); +const char *exception_name =panfrost_exception_name (js_status);job_write (pfdev,JS_COMMAND_NEXT (j),JS_COMMAND_NOP ); -dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , - j, -panfrost_exception_name (js_status), -job_read (pfdev,JS_HEAD_LO (j)), -job_read (pfdev,JS_TAIL_LO (j))); +if (!panfrost_exception_is_fault (js_status)) { +dev_dbg (pfdev->dev,"js interrupt, js=%d, status=%s, head=0x%x, tail=0x%x" , + j, exception_name, +job_read (pfdev,JS_HEAD_LO (j)), +job_read (pfdev,JS_TAIL_LO (j))); + }else { +dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , + j, exception_name, +job_read (pfdev,JS_HEAD_LO (j)), +job_read (pfdev,JS_TAIL_LO (j))); + }/* If we need a reset, signal it to the timeout * handler, otherwise, update the fence error field and @@ -499,7 +506,16 @@ static void panfrost_job_handle_irq(struct panfrost_device *pfdev, u32 status)if (panfrost_exception_needs_reset (pfdev, js_status)) {drm_sched_fault (&pfdev->js->queue[j].sched); }else { -dma_fence_set_error (pfdev->jobs[j]->done_fence, -EINVAL ); +int error =0 ; + +if (js_status ==DRM_PANFROST_EXCEPTION_TERMINATED ) + error = -ECANCELED ; +else if (panfrost_exception_is_fault (js_status)) + error = -EINVAL ; + +if (error) +dma_fence_set_error (pfdev->jobs[j]->done_fence, error); + status |=JOB_INT_MASK_DONE (j); } }@@ -665,10 +681,24 @@ int panfrost_job_open(struct panfrost_file_priv *panfrost_priv)void panfrost_job_close (struct panfrost_file_priv *panfrost_priv) { +struct panfrost_device *pfdev = panfrost_priv->pfdev;int i;for (i =0 ; i <NUM_JOB_SLOTS ; i++)drm_sched_entity_destroy (&panfrost_priv->sched_entity[i]); + +/* Kill in-flight jobs */ +spin_lock (&pfdev->js->job_lock); +for (i =0 ; i <NUM_JOB_SLOTS ; i++) { +struct drm_sched_entity *entity = &panfrost_priv->sched_entity[i]; +struct panfrost_job *job = pfdev->jobs[i]; + +if (!job || job->base.entity != entity) +continue ; + +job_write (pfdev,JS_COMMAND (i),JS_COMMAND_HARD_STOP ); + } +spin_unlock (&pfdev->js->job_lock); }int panfrost_job_is_idle (struct panfrost_device *pfdev)
Boris Brezillon
maintainerPATCH v6 15/16 drm/panfrost: Queue jobs on the hardware
In reply to Boris BrezillonFrom: Steven Price <[email protected]>
The hardware has a set of '_NEXT' registers that can hold a second job while the first is executing. Make use of these registers to enqueue a second job per slot.
v5:
* Fix a comment in panfrost_job_init()
v3:
* Fix the done/err job dequeuing logic to get a valid active state
* Only enable the second slot on GPUs supporting jobchain disambiguation
* Split interrupt handling in sub-functions
--- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 467 +++++++++++++++------ 2 files changed, 351 insertions(+), 118 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +1 -1
@@ -102,7 +102,7 @@ struct panfrost_device {struct panfrost_job_slot *js; -struct panfrost_job *jobs[NUM_JOB_SLOTS ]; +struct panfrost_job *jobs[NUM_JOB_SLOTS ][2 ];struct list_head scheduled_jobs;struct panfrost_perfcnt *perfcnt;
drivers/gpu/drm/panfrost/panfrost_job.c +350 -117
581 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v6 15/16] drm/panfrost: Queue jobs on the hardware
Quoted 9 lines · Boris Brezillon
From: Steven Price <[email protected]>
The hardware has a set of '
_NEXT' registers that can hold a second job while the first is executing. Make use of these registers to enqueue a second job per slot.v5:
* Fix a comment inpanfrost_job_init()
Quoted 7 lines
v3:
* Fix the done/err job dequeuing logic to get a valid active state
* Only enable the second slot on GPUs supporting jobchain disambiguation
* Split interrupt handling in sub-functionsSigned-off-by Steven Price <[email protected]>Signed-off-by Boris Brezillon <[email protected]>
FWIW (it has changed a bit since my original version):
Quoted 617 lines
--- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 467 +++++++++++++++------ 2 files changed, 351 insertions(+), 118 deletions(-)drivers/gpu/drm/panfrost/panfrost_device.h +1
-1@@ -102,7 +102,7 @@ struct panfrost_device {struct panfrost_job_slot *js; -struct panfrost_job *jobs[NUM_JOB_SLOTS ]; +struct panfrost_job *jobs[NUM_JOB_SLOTS ][2 ];struct list_head scheduled_jobs;struct panfrost_perfcnt *perfcnt;drivers/gpu/drm/panfrost/panfrost_job.c +350
-117@@ -4,6 +4,7 @@#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/io.h> +#include <linux/iopoll.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/dma-resv.h> @@ -140,9 +141,52 @@ static void panfrost_job_write_affinity(struct panfrost_device *pfdev,job_write (pfdev,JS_AFFINITY_NEXT_HI (js), affinity >>32 ); } +static u32 +panfrost_get_job_chain_flag (const struct panfrost_job *job) +{ +struct panfrost_fence *f =to_panfrost_fence (job->done_fence); + +if (!panfrost_has_hw_feature (job->pfdev,HW_FEATURE_JOBCHAIN_DISAMBIGUATION )) +return 0 ; + +return (f->seqno &1 ) ?JS_CONFIG_JOB_CHAIN_FLAG :0 ; +} + +static struct panfrost_job * +panfrost_dequeue_job (struct panfrost_device *pfdev,int slot) +{ +struct panfrost_job *job = pfdev->jobs[slot][0 ]; + +WARN_ON (!job); + pfdev->jobs[slot][0 ] = pfdev->jobs[slot][1 ]; + pfdev->jobs[slot][1 ] =NULL ; + +return job; +} + +static unsigned int +panfrost_enqueue_job (struct panfrost_device *pfdev,int slot, +struct panfrost_job *job) +{ +if (WARN_ON (!job)) +return 0 ; + +if (!pfdev->jobs[slot][0 ]) { + pfdev->jobs[slot][0 ] = job; +return 0 ; + } + +WARN_ON (pfdev->jobs[slot][1 ]); + pfdev->jobs[slot][1 ] = job; +WARN_ON (panfrost_get_job_chain_flag (job) == +panfrost_get_job_chain_flag (pfdev->jobs[slot][0 ])); +return 1 ; +} +static void panfrost_job_hw_submit (struct panfrost_job *job,int js) {struct panfrost_device *pfdev = job->pfdev; +unsigned int subslot;u32 cfg;u64 jc_head = job->jc;int ret;@@ -168,7 +212,8 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)* start */ cfg |=JS_CONFIG_THREAD_PRI (8 ) |JS_CONFIG_START_FLUSH_CLEAN_INVALIDATE | -JS_CONFIG_END_FLUSH_CLEAN_INVALIDATE ; +JS_CONFIG_END_FLUSH_CLEAN_INVALIDATE | +panfrost_get_job_chain_flag (job);if (panfrost_has_hw_feature (pfdev,HW_FEATURE_FLUSH_REDUCTION )) cfg |=JS_CONFIG_ENABLE_FLUSH_REDUCTION ;@@ -182,10 +227,17 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)job_write (pfdev,JS_FLUSH_ID_NEXT (js), job->flush_id);/* GO ! */ -dev_dbg (pfdev->dev,"JS: Submitting atom %p to js[%d] with head=0x%llx" , - job, js, jc_head); -job_write (pfdev,JS_COMMAND_NEXT (js),JS_COMMAND_START ); +spin_lock (&pfdev->js->job_lock); + subslot =panfrost_enqueue_job (pfdev, js, job); +/* Don't queue the job if a reset is in progress */ +if (!atomic_read (&pfdev->reset.pending)) { +job_write (pfdev,JS_COMMAND_NEXT (js),JS_COMMAND_START ); +dev_dbg (pfdev->dev, +"JS: Submitting atom %p to js[%d][%d] with head=0x%llx AS %d" , + job, js, subslot, jc_head, cfg &0xf ); + } +spin_unlock (&pfdev->js->job_lock); } static int panfrost_acquire_object_fences(struct drm_gem_object **bos,@@ -332,7 +384,11 @@ static struct dma_fence *panfrost_job_run(struct drm_sched_job *sched_job)if (unlikely (job->base.s_fence->finished.error))return NULL ; - pfdev->jobs[slot] = job; +/* Nothing to execute: can happen if the job has finished while +* we were resetting the GPU. +*/ +if (!job->jc) +return NULL ; fence =panfrost_fence_create (pfdev, slot);if (IS_ERR (fence))@@ -360,11 +416,218 @@ void panfrost_job_enable_interrupts(struct panfrost_device *pfdev)job_write (pfdev,JOB_INT_MASK , irq_mask); } -static void panfrost_reset (struct panfrost_device *pfdev, -struct drm_sched_job *bad) +static void panfrost_job_handle_err (struct panfrost_device *pfdev, +struct panfrost_job *job, +unsigned int js) { -unsigned int i; +u32 js_status =job_read (pfdev,JS_STATUS (js)); +const char *exception_name =panfrost_exception_name (js_status); +bool signal_fence = true; + +if (!panfrost_exception_is_fault (js_status)) { +dev_dbg (pfdev->dev,"js event, js=%d, status=%s, head=0x%x, tail=0x%x" , + js, exception_name, +job_read (pfdev,JS_HEAD_LO (js)), +job_read (pfdev,JS_TAIL_LO (js))); + }else { +dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , + js, exception_name, +job_read (pfdev,JS_HEAD_LO (js)), +job_read (pfdev,JS_TAIL_LO (js))); + } + +if (js_status ==DRM_PANFROST_EXCEPTION_STOPPED ) { +/* Update the job head so we can resume */ + job->jc =job_read (pfdev,JS_TAIL_LO (js)) | + ((u64 )job_read (pfdev,JS_TAIL_HI (js)) <<32 ); + +/* The job will be resumed, don't signal the fence */ + signal_fence = false; + }else if (js_status ==DRM_PANFROST_EXCEPTION_TERMINATED ) { +/* Job has been hard-stopped, flag it as canceled */ +dma_fence_set_error (job->done_fence, -ECANCELED ); + job->jc =0 ; + }else if (panfrost_exception_is_fault (js_status)) { +/* We might want to provide finer-grained error code based on +* the exception type, but unconditionally setting to EINVAL +* is good enough for now. +*/ +dma_fence_set_error (job->done_fence, -EINVAL ); + job->jc =0 ; + } + +panfrost_mmu_as_put (pfdev, job->file_priv->mmu); +panfrost_devfreq_record_idle (&pfdev->pfdevfreq); + +if (signal_fence) +dma_fence_signal_locked (job->done_fence); + +pm_runtime_put_autosuspend (pfdev->dev); + +if (panfrost_exception_needs_reset (pfdev, js_status)) { +atomic_set (&pfdev->reset.pending,1 ); +drm_sched_fault (&pfdev->js->queue[js].sched); + } +} + +static void panfrost_job_handle_done (struct panfrost_device *pfdev, +struct panfrost_job *job) +{ +/* Set ->jc to 0 to avoid re-submitting an already finished job (can +* happen when we receive the DONE interrupt while doing a GPU reset). +*/ + job->jc =0 ; +panfrost_mmu_as_put (pfdev, job->file_priv->mmu); +panfrost_devfreq_record_idle (&pfdev->pfdevfreq); + +dma_fence_signal_locked (job->done_fence); +pm_runtime_put_autosuspend (pfdev->dev); +} + +static void panfrost_job_handle_irq (struct panfrost_device *pfdev,u32 status) +{ +struct panfrost_job *done[NUM_JOB_SLOTS ][2 ] = {}; +struct panfrost_job *failed[NUM_JOB_SLOTS ] = {}; +u32 js_state =0 , js_events =0 ; +unsigned int i, j; + +/* First we collect all failed/done jobs. */ +while (status) { +u32 js_state_mask =0 ; + +for (j =0 ; j <NUM_JOB_SLOTS ; j++) { +if (status &MK_JS_MASK (j)) + js_state_mask |=MK_JS_MASK (j); + +if (status &JOB_INT_MASK_DONE (j)) { +if (done[j][0 ]) + done[j][1 ] =panfrost_dequeue_job (pfdev, j); +else + done[j][0 ] =panfrost_dequeue_job (pfdev, j); + } + +if (status &JOB_INT_MASK_ERR (j)) { +/* Cancel the next submission. Will be submitted +* after we're done handling this failure if +* there's no reset pending. +*/ +job_write (pfdev,JS_COMMAND_NEXT (j),JS_COMMAND_NOP ); + failed[j] =panfrost_dequeue_job (pfdev, j); + } + } + +/* JS_STATE is sampled when JOB_INT_CLEAR is written. +* For each BIT(slot) or BIT(slot + 16) bit written to +* JOB_INT_CLEAR, the corresponding bits in JS_STATE +* (BIT(slot) and BIT(slot + 16)) are updated, but this +* is racy. If we only have one job done at the time we +* read JOB_INT_RAWSTAT but the second job fails before we +* clear the status, we end up with a status containing +* only the DONE bit and consider both jobs as DONE since +* JS_STATE reports both NEXT and CURRENT as inactive. +* To prevent that, let's repeat this clear+read steps +* until status is 0. +*/ +job_write (pfdev,JOB_INT_CLEAR , status); + js_state &= ~js_state_mask; + js_state |=job_read (pfdev,JOB_INT_JS_STATE ) & js_state_mask; + js_events |= status; + status =job_read (pfdev,JOB_INT_RAWSTAT ); + } + +/* Then we handle the dequeued jobs. */ +for (j =0 ; j <NUM_JOB_SLOTS ; j++) { +if (!(js_events &MK_JS_MASK (j))) +continue ; + +if (failed[j]) { +panfrost_job_handle_err (pfdev, failed[j], j); + }else if (pfdev->jobs[j][0 ] && !(js_state &MK_JS_MASK (j))) { +/* When the current job doesn't fail, the JM dequeues +* the next job without waiting for an ACK, this means +* we can have 2 jobs dequeued and only catch the +* interrupt when the second one is done. If both slots +* are inactive, but one job remains in pfdev->jobs[j], +* consider it done. Of course that doesn't apply if a +* failure happened since we cancelled execution of the +* job in _NEXT (see above). +*/ +if (WARN_ON (!done[j][0 ])) + done[j][0 ] =panfrost_dequeue_job (pfdev, j); +else + done[j][1 ] =panfrost_dequeue_job (pfdev, j); + } + +for (i =0 ; i <ARRAY_SIZE (done[0 ]) && done[j][i]; i++) +panfrost_job_handle_done (pfdev, done[j][i]); + } + +/* And finally we requeue jobs that were waiting in the second slot +* and have been stopped if we detected a failure on the first slot. +*/ +for (j =0 ; j <NUM_JOB_SLOTS ; j++) { +if (!(js_events &MK_JS_MASK (j))) +continue ; + +if (!failed[j] || !pfdev->jobs[j][0 ]) +continue ; + +if (pfdev->jobs[j][0 ]->jc ==0 ) { +/* The job was cancelled, signal the fence now */ +struct panfrost_job *canceled =panfrost_dequeue_job (pfdev, j); + +dma_fence_set_error (canceled->done_fence, -ECANCELED ); +panfrost_job_handle_done (pfdev, canceled); + }else if (!atomic_read (&pfdev->reset.pending)) { +/* Requeue the job we removed if no reset is pending */ +job_write (pfdev,JS_COMMAND_NEXT (j),JS_COMMAND_START ); + } + } +} + +static void panfrost_job_handle_irqs (struct panfrost_device *pfdev) +{ +u32 status =job_read (pfdev,JOB_INT_RAWSTAT ); + +while (status) { +pm_runtime_mark_last_busy (pfdev->dev); + +spin_lock (&pfdev->js->job_lock); +panfrost_job_handle_irq (pfdev, status); +spin_unlock (&pfdev->js->job_lock); + status =job_read (pfdev,JOB_INT_RAWSTAT ); + } +} + +static u32 panfrost_active_slots (struct panfrost_device *pfdev, +u32 *js_state_mask,u32 js_state) +{ +u32 rawstat; + +if (!(js_state & *js_state_mask)) +return 0 ; + + rawstat =job_read (pfdev,JOB_INT_RAWSTAT ); +if (rawstat) { +unsigned int i; + +for (i =0 ; i <NUM_JOB_SLOTS ; i++) { +if (rawstat &MK_JS_MASK (i)) + *js_state_mask &= ~MK_JS_MASK (i); + } + } + +return js_state & *js_state_mask; +} + +static void +panfrost_reset (struct panfrost_device *pfdev, +struct drm_sched_job *bad) +{ +u32 js_state, js_state_mask =0xffffffff ; +unsigned int i, j;bool cookie; +int ret;if (!atomic_read (&pfdev->reset.pending))return ;@@ -396,21 +659,46 @@ static void panfrost_reset(struct panfrost_device *pfdev,job_write (pfdev,JOB_INT_MASK ,0 );synchronize_irq (pfdev->js->irq); -/* Schedulers are stopped and interrupts are masked+flushed, we don't -* need to protect the 'evict unfinished jobs' lock with the job_lock. +for (i =0 ; i <NUM_JOB_SLOTS ; i++) { +/* Cancel the next job and soft-stop the running job. */ +job_write (pfdev,JS_COMMAND_NEXT (i),JS_COMMAND_NOP ); +job_write (pfdev,JS_COMMAND (i),JS_COMMAND_SOFT_STOP ); + } + +/* Wait at most 10ms for soft-stops to complete */ + ret =readl_poll_timeout (pfdev->iomem +JOB_INT_JS_STATE , js_state, + !panfrost_active_slots (pfdev, &js_state_mask, js_state), +10 ,10000 ); + +if (ret) +dev_err (pfdev->dev,"Soft-stop failed\n" ); + +/* Handle the remaining interrupts before we reset. */ +panfrost_job_handle_irqs (pfdev); + +/* Remaining interrupts have been handled, but we might still have +* stuck jobs. Let's make sure the PM counters stay balanced by +* manually calling pm_runtime_put_noidle() and +* panfrost_devfreq_record_idle() for each stuck job. */ spin_lock (&pfdev->js->job_lock);for (i =0 ; i <NUM_JOB_SLOTS ; i++) { -if (pfdev->jobs[i]) { +for (j =0 ; j <ARRAY_SIZE (pfdev->jobs[0 ]) && pfdev->jobs[i][j]; j++) {pm_runtime_put_noidle (pfdev->dev);panfrost_devfreq_record_idle (&pfdev->pfdevfreq); - pfdev->jobs[i] =NULL ; } } +memset (pfdev->jobs,0 ,sizeof (pfdev->jobs));spin_unlock (&pfdev->js->job_lock); +/* Proceed with reset now. */ panfrost_device_reset (pfdev); +/* panfrost_device_reset() unmasks job interrupts, but we want to +* keep them masked a bit longer. +*/ +job_write (pfdev,JOB_INT_MASK ,0 ); +/* GPU has been reset, we can clear the reset pending bit. */ atomic_set (&pfdev->reset.pending,0 );@@ -426,9 +714,15 @@ static void panfrost_reset(struct panfrost_device *pfdev,drm_sched_resubmit_jobs (&pfdev->js->queue[i].sched); cookie =dma_fence_begin_signalling (); +/* Restart the schedulers */ for (i =0 ; i <NUM_JOB_SLOTS ; i++)drm_sched_start (&pfdev->js->queue[i].sched, true); +/* Re-enable job interrupts now that everything has been restarted. */ +job_write (pfdev,JOB_INT_MASK , +GENMASK (16 +NUM_JOB_SLOTS -1 ,16 ) | +GENMASK (NUM_JOB_SLOTS -1 ,0 )); +dma_fence_end_signalling (cookie); }@@ -460,6 +754,14 @@ static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_jobreturn DRM_GPU_SCHED_STAT_NOMINAL ; } +static void panfrost_reset_work (struct work_struct *work) +{ +struct panfrost_device *pfdev; + + pfdev = container_of(work, struct panfrost_device, reset.work); +panfrost_reset (pfdev,NULL ); +} +static const struct drm_sched_backend_ops panfrost_sched_ops = { .dependency = panfrost_job_dependency, .run_job = panfrost_job_run,@@ -467,100 +769,11 @@ static const struct drm_sched_backend_ops panfrost_sched_ops = { .free_job = panfrost_job_free }; -static void panfrost_job_handle_irq (struct panfrost_device *pfdev,u32 status) -{ -int j; - -dev_dbg (pfdev->dev,"jobslot irq status=%x\n" , status); - -for (j =0 ; status; j++) { -u32 mask =MK_JS_MASK (j); - -if (!(status & mask)) -continue ; - -job_write (pfdev,JOB_INT_CLEAR , mask); - -if (status &JOB_INT_MASK_ERR (j)) { -u32 js_status =job_read (pfdev,JS_STATUS (j)); -const char *exception_name =panfrost_exception_name (js_status); - -job_write (pfdev,JS_COMMAND_NEXT (j),JS_COMMAND_NOP ); - -if (!panfrost_exception_is_fault (js_status)) { -dev_dbg (pfdev->dev,"js interrupt, js=%d, status=%s, head=0x%x, tail=0x%x" , - j, exception_name, -job_read (pfdev,JS_HEAD_LO (j)), -job_read (pfdev,JS_TAIL_LO (j))); - }else { -dev_err (pfdev->dev,"js fault, js=%d, status=%s, head=0x%x, tail=0x%x" , - j, exception_name, -job_read (pfdev,JS_HEAD_LO (j)), -job_read (pfdev,JS_TAIL_LO (j))); - } - -/* If we need a reset, signal it to the timeout -* handler, otherwise, update the fence error field and -* signal the job fence. -*/ -if (panfrost_exception_needs_reset (pfdev, js_status)) { -drm_sched_fault (&pfdev->js->queue[j].sched); - }else { -int error =0 ; - -if (js_status ==DRM_PANFROST_EXCEPTION_TERMINATED ) - error = -ECANCELED ; -else if (panfrost_exception_is_fault (js_status)) - error = -EINVAL ; - -if (error) -dma_fence_set_error (pfdev->jobs[j]->done_fence, error); - - status |=JOB_INT_MASK_DONE (j); - } - } - -if (status &JOB_INT_MASK_DONE (j)) { -struct panfrost_job *job; - - job = pfdev->jobs[j]; -/* The only reason this job could be NULL is if the -* job IRQ handler is called just after the -* in-flight job eviction in the reset path, and -* this shouldn't happen because the job IRQ has -* been masked and synchronized when this eviction -* happens. -*/ -WARN_ON (!job); -if (job) { - pfdev->jobs[j] =NULL ; - -panfrost_mmu_as_put (pfdev, job->file_priv->mmu); -panfrost_devfreq_record_idle (&pfdev->pfdevfreq); - -dma_fence_signal_locked (job->done_fence); -pm_runtime_put_autosuspend (pfdev->dev); - } - } - - status &= ~mask; - } -} -static irqreturn_t panfrost_job_irq_handler_thread (int irq,void *data) {struct panfrost_device *pfdev = data; -u32 status =job_read (pfdev,JOB_INT_RAWSTAT ); - -while (status) { -pm_runtime_mark_last_busy (pfdev->dev); - -spin_lock (&pfdev->js->job_lock); -panfrost_job_handle_irq (pfdev, status); -spin_unlock (&pfdev->js->job_lock); - status =job_read (pfdev,JOB_INT_RAWSTAT ); - } +panfrost_job_handle_irqs (pfdev);job_write (pfdev,JOB_INT_MASK ,GENMASK (16 +NUM_JOB_SLOTS -1 ,16 ) |GENMASK (NUM_JOB_SLOTS -1 ,0 ));@@ -579,26 +792,24 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)return IRQ_WAKE_THREAD ; } -static void panfrost_reset_work (struct work_struct *work) -{ -struct panfrost_device *pfdev =container_of (work, - struct panfrost_device, - reset.work); - -panfrost_reset (pfdev,NULL ); -} -int panfrost_job_init (struct panfrost_device *pfdev) {struct panfrost_job_slot *js; +unsigned int nentries =2 ;int ret, j; -INIT_WORK (&pfdev->reset.work, panfrost_reset_work); +/* All GPUs have two entries per queue, but without jobchain +* disambiguation stopping the right job in the close path is tricky, +* so let's just advertise one entry in that case. +*/ +if (!panfrost_has_hw_feature (pfdev,HW_FEATURE_JOBCHAIN_DISAMBIGUATION )) + nentries =1 ; pfdev->js = js =devm_kzalloc (pfdev->dev,sizeof (*js),GFP_KERNEL );if (!js)return -ENOMEM ; +INIT_WORK (&pfdev->reset.work, panfrost_reset_work);spin_lock_init (&js->job_lock); js->irq =platform_get_irq_byname (to_platform_device (pfdev->dev),"job" );@@ -624,7 +835,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) ret =drm_sched_init (&js->queue[j].sched, &panfrost_sched_ops, -1 ,0 , + nentries,0 ,msecs_to_jiffies (JOB_TIMEOUT_MS ), pfdev->reset.wq,NULL ,"pan_js" );@@ -691,12 +902,34 @@ void panfrost_job_close(struct panfrost_file_priv *panfrost_priv)spin_lock (&pfdev->js->job_lock);for (i =0 ; i <NUM_JOB_SLOTS ; i++) {struct drm_sched_entity *entity = &panfrost_priv->sched_entity[i]; -struct panfrost_job *job = pfdev->jobs[i]; +int j; -if (!job || job->base.entity != entity) -continue ; +for (j =ARRAY_SIZE (pfdev->jobs[0 ]) -1 ; j >=0 ; j--) { +struct panfrost_job *job = pfdev->jobs[i][j]; +u32 cmd; -job_write (pfdev,JS_COMMAND (i),JS_COMMAND_HARD_STOP ); +if (!job || job->base.entity != entity) +continue ; + +if (j ==1 ) { +/* Try to cancel the job before it starts */ +job_write (pfdev,JS_COMMAND_NEXT (i),JS_COMMAND_NOP ); +/* Reset the job head so it doesn't get restarted if +* the job in the first slot failed. +*/ + job->jc =0 ; + } + +if (panfrost_has_hw_feature (pfdev,HW_FEATURE_JOBCHAIN_DISAMBIGUATION )) { + cmd =panfrost_get_job_chain_flag (job) ? +JS_COMMAND_HARD_STOP_1 : +JS_COMMAND_HARD_STOP_0 ; + }else { + cmd =JS_COMMAND_HARD_STOP ; + } + +job_write (pfdev,JS_COMMAND (i), cmd); + } }spin_unlock (&pfdev->js->job_lock); }
Boris Brezillon
maintainerPATCH v6 16/16 drm/panfrost: Increase the AS_ACTIVE polling timeout
In reply to Boris BrezillonExperience has shown that 1ms is sometimes not enough, even when the GPU is running at its maximum frequency, not to mention that an MMU operation might take longer if the GPU is running at a lower frequency, which is likely to be the case if devfreq is active.
Let's pick a significantly bigger timeout value (1ms -> 100ms) to be on the safe side.
v5:
* New patch
--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_mmu.c +1 -1
@@ -34,7 +34,7 @@ static int wait_ready(struct panfrost_device *pfdev, u32 as_nr)/* Wait for the MMU status to indicate there is no active command, in * case one is pending. */ ret =readl_relaxed_poll_timeout_atomic (pfdev->iomem +AS_STATUS (as_nr), - val, !(val &AS_STATUS_AS_ACTIVE ),10 ,1000 ); + val, !(val &AS_STATUS_AS_ACTIVE ),10 ,100000 );if (ret) {/* The GPU hung, let's trigger a reset */
Signature · 1 line
2.31.1
Re: [PATCH v6 16/16] drm/panfrost: Increase the AS_ACTIVE polling timeout
Quoted 5 lines · Boris Brezillon
Experience has shown that 1ms is sometimes not enough, even when the GPU is running at its maximum frequency, not to mention that an MMU operation might take longer if the GPU is running at a lower frequency, which is likely to be the case if devfreq is active.
Quoted 7 lines
Let's pick a significantly bigger timeout value (1ms -> 100ms) to be on the safe side.
v5:
* New patchSigned-off-by Boris Brezillon <[email protected]>
Quoted 18 lines
--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_mmu.c +1
-1@@ -34,7 +34,7 @@ static int wait_ready(struct panfrost_device *pfdev, u32 as_nr)/* Wait for the MMU status to indicate there is no active command, in * case one is pending. */ ret =readl_relaxed_poll_timeout_atomic (pfdev->iomem +AS_STATUS (as_nr), - val, !(val &AS_STATUS_AS_ACTIVE ),10 ,1000 ); + val, !(val &AS_STATUS_AS_ACTIVE ),10 ,100000 );if (ret) {/* The GPU hung, let's trigger a reset */
Boris Brezillon
maintainerQuoted 43 lines · On Wed, 30 Jun 2021 08:27:35 +0200 Boris Brezillon…
Hello,
Bunch of improvements to make the panfrost driver more robust and allow queuing jobs at the HW level.
Changes in v6:
* Collected acks/reviews
* Got rid of thecancel_delayed_work()calls in the reset pathChanges in this v5:
* Document what's excepted in the ->timedout_job() hook
* Add a patch increasing theAS_ACTIVEpolling timeout
* Fix a few minor things here and there (see each commit for a detailed changelog) and collect R-b/A-b tagsChanges in this v4:
* fixing the reset serialization
* fixing a deadlock in the reset path
* moving the exception enum to a private headerRegards,
Boris
Boris Brezillon (15):
drm/sched: Document what thetimedout_jobmethod should do drm/sched: Allow using a dedicated workqueue for the timeout/fault tdr drm/panfrost: Make ->run_job() return anERR_PTR()when appropriate drm/panfrost: Get rid of the unusedJS_STATUS_EVENT_ACTIVEdefinition drm/panfrost: Drop the pfdev argument passed to
panfrost_exception_name()
drm/panfrost: Do the exception -> string translation using a table drm/panfrost: Expose a helper to trigger a GPU reset drm/panfrost: Use a threaded IRQ for job interrupts drm/panfrost: Simplify the reset serialization logic drm/panfrost: Make sure job interrupts are masked before resetting drm/panfrost: Disable the AS on unhandled page faults drm/panfrost: Reset the GPU when theAS_ACTIVEbit is stuck drm/panfrost: Don't reset the GPU on job faults unless we really have
to
drm/panfrost: Kill in-flight jobs on FD close drm/panfrost: Increase theAS_ACTIVEpolling timeout
Quoted 2 lines
Steven Price (1):
drm/panfrost: Queue jobs on the hardware
Series queued to drm-misc-next.
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 +- drivers/gpu/drm/lima/lima_sched.c | 3 +- drivers/gpu/drm/panfrost/panfrost_device.c | 139 +++-- drivers/gpu/drm/panfrost/panfrost_device.h | 91 ++- drivers/gpu/drm/panfrost/panfrost_gpu.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 626 +++++++++++++++------ drivers/gpu/drm/panfrost/panfrost_mmu.c | 43 +- drivers/gpu/drm/panfrost/panfrost_regs.h | 3 - drivers/gpu/drm/scheduler/sched_main.c | 14 +- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 37 +- 12 files changed, 717 insertions(+), 256 deletions(-)