drm/imagination: Implement job submission and scheduling
Subsystems (3)
PATCH v4 14/17 drm/imagination: Implement job submission and scheduling
Implement job submission ioctl. Job scheduling is implemented using drm_sched.
Jobs are submitted in a stream format. This is intended to allow the UAPI data format to be independent of the actual FWIF structures in use, which vary depending on the GPU in use.
The stream formats are documented at:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/f8d2b42ae65c2f16f36a43e0ae39d288431e4263/src/imagination/csbgen/rogue_kmd_stream.xml
This patch depends on:
drm/sched: Convert drm scheduler to use a work queue rather than kthread:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Move schedule policy to scheduler / entity:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Start run wq before TDR in drm_sched_start:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Submit job before starting TDR:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Add helper to set TDR timeout:
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Make sure we wait for all dependencies in kill_jobs_cb():
https://lore.kernel.org/dri-devel/[email protected]/
drm/sched: Call drm_sched_fence_set_parent() from drm_sched_fence_scheduled():
https://lore.kernel.org/dri-devel/[email protected]/
Changes since v3:
- Support partial render jobs
- Add job timeout handler
- Split sync handling out of job code
- Use drm_dev_{enter,exit}
Changes since v2:
- Use drm_sched for job scheduling
--- drivers/gpu/drm/imagination/Makefile | 3 + drivers/gpu/drm/imagination/pvr_context.c | 127 +- drivers/gpu/drm/imagination/pvr_context.h | 44 + drivers/gpu/drm/imagination/pvr_device.c | 31 + drivers/gpu/drm/imagination/pvr_device.h | 40 + drivers/gpu/drm/imagination/pvr_drv.c | 44 +- drivers/gpu/drm/imagination/pvr_job.c | 605 +++++++ drivers/gpu/drm/imagination/pvr_job.h | 161 ++ drivers/gpu/drm/imagination/pvr_power.c | 28 + drivers/gpu/drm/imagination/pvr_queue.c | 1457 +++++++++++++++++ drivers/gpu/drm/imagination/pvr_queue.h | 179 ++ drivers/gpu/drm/imagination/pvr_stream_defs.c | 226 +++ drivers/gpu/drm/imagination/pvr_sync.c | 287 ++++ drivers/gpu/drm/imagination/pvr_sync.h | 84 + 14 files changed, 3311 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/imagination/pvr_job.c create mode 100644 drivers/gpu/drm/imagination/pvr_job.h create mode 100644 drivers/gpu/drm/imagination/pvr_queue.c create mode 100644 drivers/gpu/drm/imagination/pvr_queue.h create mode 100644 drivers/gpu/drm/imagination/pvr_sync.c create mode 100644 drivers/gpu/drm/imagination/pvr_sync.h
drivers/gpu/drm/imagination/Makefile +3 -0
@@ -18,10 +18,13 @@ powervr-y := \ pvr_fw_trace.o \ pvr_gem.o \ pvr_hwrt.o \ + pvr_job.o \ pvr_mmu.o \ pvr_power.o \ + pvr_queue.o \ pvr_stream.o \ pvr_stream_defs.o \ + pvr_sync.o \ pvr_vm.o \ pvr_vm_mips.o
drivers/gpu/drm/imagination/pvr_context.c +125 -2
174 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_context.h +44 -0
58 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_device.c +31 -0
@@ -6,7 +6,9 @@#include "pvr_fw.h" #include "pvr_power.h" +#include "pvr_queue.h" #include "pvr_rogue_cr_defs.h" +#include "pvr_stream.h" #include "pvr_vm.h" #include <drm/drm_print.h>
@@ -117,6 +119,32 @@ static int pvr_device_clk_init(struct pvr_device *pvr_dev)return 0 ; } +/** +* pvr_device_process_active_queues() - Process all queue related events. +* @pvr_dev: PowerVR device to check +* +* This is called any time we receive a FW event. It iterates over all +* active queues and calls pvr_queue_process() on them. +*/ +void pvr_device_process_active_queues (struct pvr_device *pvr_dev) +{ +struct pvr_queue *queue, *tmp_queue; +LIST_HEAD (active_queues); + +mutex_lock (&pvr_dev->queues.lock); + +/* Move all active queues to a temporary list. Queues that remain +* active after we're done processing them are re-inserted to +* the queues.active list by pvr_queue_process(). +*/ +list_splice_init (&pvr_dev->queues.active, &active_queues); + +list_for_each_entry_safe (queue, tmp_queue, &active_queues, node) +pvr_queue_process (queue); + +mutex_unlock (&pvr_dev->queues.lock); +} +static irqreturn_t pvr_device_irq_thread_handler (int irq,void *data) {struct pvr_device *pvr_dev = data;
@@ -132,6 +160,7 @@ static irqreturn_t pvr_device_irq_thread_handler(int irq, void *data)if (pvr_dev->fw_dev.booted) {pvr_fwccb_process (pvr_dev);pvr_kccb_wake_up_waiters (pvr_dev); +pvr_device_process_active_queues (pvr_dev); }pm_runtime_mark_last_busy (from_pvr_device (pvr_dev)->dev);
@@ -391,6 +420,8 @@ pvr_device_gpu_init(struct pvr_device *pvr_dev)else return -EINVAL ; +pvr_stream_create_musthave_masks (pvr_dev); + err =pvr_set_dma_info (pvr_dev);if (err)return err;
drivers/gpu/drm/imagination/pvr_device.h +40 -0
@@ -167,6 +167,26 @@ struct pvr_device {*/ struct xarray free_list_ids; +/** +* @job_ids: Array of jobs belonging to this device. Array members +* are of type "struct pvr_job *". +*/ +struct xarray job_ids; + +/** +* @queues: Queue-related fields. +*/ +struct { +/** @active: Active queue list. */ +struct list_head active; + +/** @idle: Idle queue list. */ +struct list_head idle; + +/** @lock: Lock protecting access to the active/idle lists. */ +struct mutex lock; + } queues; +struct {/** @work: Work item for watchdog callback. */ struct delayed_work work;
@@ -293,6 +313,25 @@ struct pvr_file {* This array is used to allocate handles returned to userspace. */ struct xarray vm_ctx_handles; + +/** +* @submit_lock: Lock used to prevent concurrent access to the queues +* targeted by a SUBMIT_JOBS ioctl. +* +* drm_sched_job_arm() and drm_sched_entity_push_job() need to be called +* in the same critical section, so that the seqno assigned to job fences +* in drm_sched_job_arm() are consistent with the order in the entity +* list. +* +* Jobs submission is implemented as an atomic operation where all jobs +* are submitted or none of them are. We also allow jobs to be passed +* fences issued by previous jobs in the job array, and that requires +* calling drm_sched_job_arm() on a job, before proceeding with the next +* job in the list. For all these reasons the region protected by the lock +* is quite large, which is likely to hurt perfs on apps that submit +* things to different VkQueues in separate threads. +*/ +struct mutex submit_lock; };/**
@@ -436,6 +475,7 @@ packed_bvnc_to_pvr_gpu_id(u64 bvnc, struct pvr_gpu_id *gpu_id)int pvr_device_init (struct pvr_device *pvr_dev);void pvr_device_fini (struct pvr_device *pvr_dev); +void pvr_device_reset (struct pvr_device *pvr_dev);bool pvr_device_has_uapi_quirk (struct pvr_device *pvr_dev,u32 quirk);
drivers/gpu/drm/imagination/pvr_drv.c +41 -3
119 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_job.c new file +605 -0
605 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_job.h new file +161 -0
161 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_power.c +28 -0
@@ -5,6 +5,7 @@#include "pvr_fw.h" #include "pvr_fw_startstop.h" #include "pvr_power.h" +#include "pvr_queue.h" #include "pvr_rogue_fwif.h" #include <drm/drm_drv.h>
@@ -149,6 +150,21 @@ pvr_watchdog_kccb_stalled(struct pvr_device *pvr_dev) pvr_dev->watchdog.kccb_stall_count =0 ;return true; } + }else if (pvr_dev->watchdog.old_kccb_cmds_executed == kccb_cmds_executed) { +bool has_active_contexts; + +mutex_lock (&pvr_dev->queues.lock); + has_active_contexts =list_empty (&pvr_dev->queues.active); +mutex_unlock (&pvr_dev->queues.lock); + +if (has_active_contexts) { +/* Send a HEALTH_CHECK command so we can verify FW is still alive. */ +struct rogue_fwif_kccb_cmd health_check_cmd; + + health_check_cmd.cmd_type =ROGUE_FWIF_KCCB_CMD_HEALTH_CHECK ; + +pvr_kccb_send_cmd_powered (pvr_dev, &health_check_cmd,NULL ); + } }else { pvr_dev->watchdog.old_kccb_cmds_executed = kccb_cmds_executed; pvr_dev->watchdog.kccb_stall_count =0 ;
@@ -312,6 +328,7 @@ pvr_power_device_idle(struct device *dev)int pvr_power_reset (struct pvr_device *pvr_dev,bool hard_reset) { +bool queues_disabled = false;int err;/*
@@ -326,6 +343,11 @@ pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset)disable_irq (pvr_dev->irq); do { + if (hard_reset) { + pvr_queue_device_pre_reset(pvr_dev); + queues_disabled = true; + } + err = pvr_power_fw_disable(pvr_dev, hard_reset); if (!err) { if (hard_reset) {
@@ -361,6 +383,9 @@ pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset) } }while (err); +if (queues_disabled) +pvr_queue_device_post_reset (pvr_dev); +enable_irq (pvr_dev->irq);up_write (&pvr_dev->reset_sem);
@@ -375,6 +400,9 @@ pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset)/* Leave IRQs disabled if the device is lost. */ +if (queues_disabled) +pvr_queue_device_post_reset (pvr_dev); +up_write (&pvr_dev->reset_sem);pvr_power_put (pvr_dev);
drivers/gpu/drm/imagination/pvr_queue.c new file +1457 -0
1,457 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_queue.h new file +179 -0
179 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_stream_defs.c +226 -0
56 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_sync.c new file +287 -0
287 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_sync.h new file +84 -0
84 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.41.0
Part of the diff is not shown here. View the raw message.