Skip to content

Commit 5473f4d

Browse files
Thomas Hellströmmbrost05
authored andcommitted
drm/xe/bo: Introduce xe_bo_put_async
Introduce xe_bo_put_async to put a bo where the context is such that the bo destructor can't run due to lockdep problems or atomic context. If the put is the final put, freeing will be done from a work item. v5: - Kerenl doc for xe_bo_put_async (Thomas) v7: - Fix kernel doc (CI) Signed-off-by: Matthew Brost <[email protected]> Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Reviewed-by: Himal Prasad Ghimiray <[email protected]> Tested-by: Gwan-gyeong Mun <[email protected]> Reviewed-by: Gwan-gyeong Mun <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 73463da commit 5473f4d

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,31 @@ void xe_bo_put_commit(struct llist_head *deferred)
26602660
drm_gem_object_free(&bo->ttm.base.refcount);
26612661
}
26622662

2663+
static void xe_bo_dev_work_func(struct work_struct *work)
2664+
{
2665+
struct xe_bo_dev *bo_dev = container_of(work, typeof(*bo_dev), async_free);
2666+
2667+
xe_bo_put_commit(&bo_dev->async_list);
2668+
}
2669+
2670+
/**
2671+
* xe_bo_dev_init() - Initialize BO dev to manage async BO freeing
2672+
* @bo_dev: The BO dev structure
2673+
*/
2674+
void xe_bo_dev_init(struct xe_bo_dev *bo_dev)
2675+
{
2676+
INIT_WORK(&bo_dev->async_free, xe_bo_dev_work_func);
2677+
}
2678+
2679+
/**
2680+
* xe_bo_dev_fini() - Finalize BO dev managing async BO freeing
2681+
* @bo_dev: The BO dev structure
2682+
*/
2683+
void xe_bo_dev_fini(struct xe_bo_dev *bo_dev)
2684+
{
2685+
flush_work(&bo_dev->async_free);
2686+
}
2687+
26632688
void xe_bo_put(struct xe_bo *bo)
26642689
{
26652690
struct xe_tile *tile;

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,25 @@ xe_bo_put_deferred(struct xe_bo *bo, struct llist_head *deferred)
323323

324324
void xe_bo_put_commit(struct llist_head *deferred);
325325

326+
/**
327+
* xe_bo_put_async() - Put BO async
328+
* @bo: The bo to put.
329+
*
330+
* Put BO async, the final put is deferred to a worker to exit an IRQ context.
331+
*/
332+
static inline void
333+
xe_bo_put_async(struct xe_bo *bo)
334+
{
335+
struct xe_bo_dev *bo_device = &xe_bo_device(bo)->bo_device;
336+
337+
if (xe_bo_put_deferred(bo, &bo_device->async_list))
338+
schedule_work(&bo_device->async_free);
339+
}
340+
341+
void xe_bo_dev_init(struct xe_bo_dev *bo_device);
342+
343+
void xe_bo_dev_fini(struct xe_bo_dev *bo_device);
344+
326345
struct sg_table *xe_bo_sg(struct xe_bo *bo);
327346

328347
/*

drivers/gpu/drm/xe/xe_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
387387
{
388388
struct xe_device *xe = to_xe_device(dev);
389389

390+
xe_bo_dev_fini(&xe->bo_device);
391+
390392
if (xe->preempt_fence_wq)
391393
destroy_workqueue(xe->preempt_fence_wq);
392394

@@ -424,6 +426,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
424426
if (WARN_ON(err))
425427
goto err;
426428

429+
xe_bo_dev_init(&xe->bo_device);
427430
err = drmm_add_action_or_reset(&xe->drm, xe_device_destroy, NULL);
428431
if (err)
429432
goto err;

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,14 @@ struct xe_device {
525525
int mode;
526526
} wedged;
527527

528+
/** @bo_device: Struct to control async free of BOs */
529+
struct xe_bo_dev {
530+
/** @bo_device.async_free: Free worker */
531+
struct work_struct async_free;
532+
/** @bo_device.async_list: List of BOs to be freed */
533+
struct llist_head async_list;
534+
} bo_device;
535+
528536
/** @pmu: performance monitoring unit */
529537
struct xe_pmu pmu;
530538

0 commit comments

Comments
 (0)