Skip to content

Commit f8246cf

Browse files
committed
drm/i915/gem: Drop free_work for GEM contexts
The free_list and worker was introduced in commit 5f09a9c ("drm/i915: Allow contexts to be unreferenced locklessly"), but subsequently made redundant by the removal of the last sleeping lock in commit 2935ed5 ("drm/i915: Remove logical HW ID"). As we can now free the GEM context immediately from any context, remove the deferral of the free_list v2: Lift removing the context from the global list into close(). Suggested-by: Mika Kuoppala <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Cc: Mika Kuoppala <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5f22cc0 commit f8246cf

File tree

6 files changed

+8
-60
lines changed

6 files changed

+8
-60
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,12 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx)
334334
return e;
335335
}
336336

337-
static void i915_gem_context_free(struct i915_gem_context *ctx)
337+
void i915_gem_context_release(struct kref *ref)
338338
{
339-
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
339+
struct i915_gem_context *ctx = container_of(ref, typeof(*ctx), ref);
340340

341-
spin_lock(&ctx->i915->gem.contexts.lock);
342-
list_del(&ctx->link);
343-
spin_unlock(&ctx->i915->gem.contexts.lock);
341+
trace_i915_context_free(ctx);
342+
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
344343

345344
mutex_destroy(&ctx->engines_mutex);
346345
mutex_destroy(&ctx->lut_mutex);
@@ -354,37 +353,6 @@ static void i915_gem_context_free(struct i915_gem_context *ctx)
354353
kfree_rcu(ctx, rcu);
355354
}
356355

357-
static void contexts_free_all(struct llist_node *list)
358-
{
359-
struct i915_gem_context *ctx, *cn;
360-
361-
llist_for_each_entry_safe(ctx, cn, list, free_link)
362-
i915_gem_context_free(ctx);
363-
}
364-
365-
static void contexts_flush_free(struct i915_gem_contexts *gc)
366-
{
367-
contexts_free_all(llist_del_all(&gc->free_list));
368-
}
369-
370-
static void contexts_free_worker(struct work_struct *work)
371-
{
372-
struct i915_gem_contexts *gc =
373-
container_of(work, typeof(*gc), free_work);
374-
375-
contexts_flush_free(gc);
376-
}
377-
378-
void i915_gem_context_release(struct kref *ref)
379-
{
380-
struct i915_gem_context *ctx = container_of(ref, typeof(*ctx), ref);
381-
struct i915_gem_contexts *gc = &ctx->i915->gem.contexts;
382-
383-
trace_i915_context_free(ctx);
384-
if (llist_add(&ctx->free_link, &gc->free_list))
385-
schedule_work(&gc->free_work);
386-
}
387-
388356
static inline struct i915_gem_engines *
389357
__context_engines_static(const struct i915_gem_context *ctx)
390358
{
@@ -633,6 +601,10 @@ static void context_close(struct i915_gem_context *ctx)
633601
*/
634602
lut_close(ctx);
635603

604+
spin_lock(&ctx->i915->gem.contexts.lock);
605+
list_del(&ctx->link);
606+
spin_unlock(&ctx->i915->gem.contexts.lock);
607+
636608
mutex_unlock(&ctx->mutex);
637609

638610
/*
@@ -850,9 +822,6 @@ i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
850822
!HAS_EXECLISTS(i915))
851823
return ERR_PTR(-EINVAL);
852824

853-
/* Reap the stale contexts */
854-
contexts_flush_free(&i915->gem.contexts);
855-
856825
ctx = __create_context(i915);
857826
if (IS_ERR(ctx))
858827
return ctx;
@@ -897,22 +866,13 @@ static void init_contexts(struct i915_gem_contexts *gc)
897866
{
898867
spin_lock_init(&gc->lock);
899868
INIT_LIST_HEAD(&gc->list);
900-
901-
INIT_WORK(&gc->free_work, contexts_free_worker);
902-
init_llist_head(&gc->free_list);
903869
}
904870

905871
void i915_gem_init__contexts(struct drm_i915_private *i915)
906872
{
907873
init_contexts(&i915->gem.contexts);
908874
}
909875

910-
void i915_gem_driver_release__contexts(struct drm_i915_private *i915)
911-
{
912-
flush_work(&i915->gem.contexts.free_work);
913-
rcu_barrier(); /* and flush the left over RCU frees */
914-
}
915-
916876
static int gem_context_register(struct i915_gem_context *ctx,
917877
struct drm_i915_file_private *fpriv,
918878
u32 *id)
@@ -986,7 +946,6 @@ int i915_gem_context_open(struct drm_i915_private *i915,
986946
void i915_gem_context_close(struct drm_file *file)
987947
{
988948
struct drm_i915_file_private *file_priv = file->driver_priv;
989-
struct drm_i915_private *i915 = file_priv->dev_priv;
990949
struct i915_address_space *vm;
991950
struct i915_gem_context *ctx;
992951
unsigned long idx;
@@ -998,8 +957,6 @@ void i915_gem_context_close(struct drm_file *file)
998957
xa_for_each(&file_priv->vm_xa, idx, vm)
999958
i915_vm_put(vm);
1000959
xa_destroy(&file_priv->vm_xa);
1001-
1002-
contexts_flush_free(&i915->gem.contexts);
1003960
}
1004961

1005962
int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,

drivers/gpu/drm/i915/gem/i915_gem_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ i915_gem_context_clear_user_engines(struct i915_gem_context *ctx)
110110

111111
/* i915_gem_context.c */
112112
void i915_gem_init__contexts(struct drm_i915_private *i915);
113-
void i915_gem_driver_release__contexts(struct drm_i915_private *i915);
114113

115114
int i915_gem_context_open(struct drm_i915_private *i915,
116115
struct drm_file *file);

drivers/gpu/drm/i915/gem/i915_gem_context_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ struct i915_gem_context {
108108

109109
/** link: place with &drm_i915_private.context_list */
110110
struct list_head link;
111-
struct llist_node free_link;
112111

113112
/**
114113
* @ref: reference count

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,6 @@ struct drm_i915_private {
11721172
struct i915_gem_contexts {
11731173
spinlock_t lock; /* locks list */
11741174
struct list_head list;
1175-
1176-
struct llist_head free_list;
1177-
struct work_struct free_work;
11781175
} contexts;
11791176

11801177
/*

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,6 @@ void i915_gem_driver_remove(struct drm_i915_private *dev_priv)
12071207

12081208
void i915_gem_driver_release(struct drm_i915_private *dev_priv)
12091209
{
1210-
i915_gem_driver_release__contexts(dev_priv);
1211-
12121210
intel_gt_driver_release(&dev_priv->gt);
12131211

12141212
intel_wa_list_free(&dev_priv->gt_wa_list);

drivers/gpu/drm/i915/selftests/mock_gem_device.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ static void mock_device_release(struct drm_device *dev)
6464
mock_device_flush(i915);
6565
intel_gt_driver_remove(&i915->gt);
6666

67-
i915_gem_driver_release__contexts(i915);
68-
6967
i915_gem_drain_workqueue(i915);
7068
i915_gem_drain_freed_objects(i915);
7169

0 commit comments

Comments
 (0)