• Boris Brezillon's avatar
    drm/panthor: Add the scheduler logical block · de854881
    Boris Brezillon authored
    This is the piece of software interacting with the FW scheduler, and
    taking care of some scheduling aspects when the FW comes short of slots
    scheduling slots. Indeed, the FW only expose a few slots, and the kernel
    has to give all submission contexts, a chance to execute their jobs.
    
    The kernel-side scheduler is timeslice-based, with a round-robin queue
    per priority level.
    
    Job submission is handled with a 1:1 drm_sched_entity:drm_gpu_scheduler,
    allowing us to delegate the dependency tracking to the core.
    
    All the gory details should be documented inline.
    
    v6:
    - Add Maxime's and Heiko's acks
    - Make sure the scheduler is initialized before queueing the tick work
      in the MMU fault handler
    - Keep header inclusion alphabetically ordered
    
    v5:
    - Fix typos
    - Call panthor_kernel_bo_destroy(group->syncobjs) unconditionally
    - Don't move the group to the waiting list tail when it was already
      waiting for a different syncobj
    - Fix fatal_queues flagging in the tiler OOM path
    - Don't warn when more than one job timesout on a group
    - Add a warning message when we fail to allocate a heap chunk
    - Add Steve's R-b
    
    v4:
    - Check drmm_mutex_init() return code
    - s/drm_gem_vmap_unlocked/drm_gem_vunmap_unlocked/ in
      panthor_queue_put_syncwait_obj()
    - Drop unneeded WARN_ON() in cs_slot_sync_queue_state_locked()
    - Use atomic_xchg() instead of atomic_fetch_and(0)
    - Fix typos
    - Let panthor_kernel_bo_destroy() check for IS_ERR_OR_NULL() BOs
    - Defer TILER_OOM event handling to a separate workqueue to prevent
      deadlocks when the heap chunk allocation is blocked on mem-reclaim.
      This is just a temporary solution, until we add support for
      non-blocking/failable allocations
    - Pass the scheduler workqueue to drm_sched instead of instantiating
      a separate one (no longer needed now that heap chunk allocation
      happens on a dedicated wq)
    - Set WQ_MEM_RECLAIM on the scheduler workqueue, so we can handle
      job timeouts when the system is under mem pressure, and hopefully
      free up some memory retained by these jobs
    
    v3:
    - Rework the FW event handling logic to avoid races
    - Make sure MMU faults kill the group immediately
    - Use the panthor_kernel_bo abstraction for group/queue buffers
    - Make in_progress an atomic_t, so we can check it without the reset lock
      held
    - Don't limit the number of groups per context to the FW scheduler
      capacity. Fix the limit to 128 for now.
    - Add a panthor_job_vm() helper
    - Account for panthor_vm changes
    - Add our job fence as DMA_RESV_USAGE_WRITE to all external objects
      (was previously DMA_RESV_USAGE_BOOKKEEP). I don't get why, given
      we're supposed to be fully-explicit, but other drivers do that, so
      there must be a good reason
    - Account for drm_sched changes
    - Provide a panthor_queue_put_syncwait_obj()
    - Unconditionally return groups to their idle list in
      panthor_sched_suspend()
    - Condition of sched_queue_{,delayed_}work fixed to be only when a reset
      isn't pending or in progress.
    - Several typos in comments fixed.
    Co-developed-by: default avatarSteven Price <steven.price@arm.com>
    Signed-off-by: default avatarSteven Price <steven.price@arm.com>
    Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
    Reviewed-by: default avatarSteven Price <steven.price@arm.com>
    Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
    Acked-by: default avatarHeiko Stuebner <heiko@sntech.de>
    Link: https://patchwork.freedesktop.org/patch/msgid/20240229162230.2634044-11-boris.brezillon@collabora.com
    de854881
panthor_sched.c 97.2 KB