drm/i915: Remove context pointer from ppgtt struct
Subsystems (2)
PATCH 1/1 drm/i915: Remove context pointer from ppgtt struct
After new vma/ppgtt lifetime rules, the ppgtt can outlive the context it was created for.
- Renamed create_vm_for_ctx to i915_ppgtt_create as ctx/ppgtt are no longer referenced.
- Updated per_file_stats to cope with this change.
--- drivers/gpu/drm/i915/i915_debugfs.c | 6 +++--- drivers/gpu/drm/i915/i915_gem_context.c | 5 ++--- drivers/gpu/drm/i915/i915_gem_gtt.h | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +3 -3
@@ -322,7 +322,7 @@ static int per_file_stats(int id, void *ptr, void *data)if (USES_FULL_PPGTT (obj->base.dev)) {list_for_each_entry (vma, &obj->vma_list, vma_link) { -struct i915_hw_ppgtt *ppgtt; +struct intel_context *ctx;if (!drm_mm_node_allocated (&vma->node))continue ;
@@ -332,8 +332,8 @@ static int per_file_stats(int id, void *ptr, void *data)continue ; } - ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base); -if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv) + ctx = container_of(vma->vm, struct intel_context, vm); +if (ctx && ctx->file_priv != stats->file_priv)continue ;if (obj->ring)/* XXX per-vma statistic */
drivers/gpu/drm/i915/i915_gem_context.c +2 -3
@@ -210,7 +210,7 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size) }static struct i915_hw_ppgtt * -create_vm_for_ctx (struct drm_device *dev,struct intel_context *ctx) +i915_ppgtt_create (struct drm_device *dev) {struct i915_hw_ppgtt *ppgtt;int ret;
@@ -225,7 +225,6 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)return ERR_PTR (ret); } - ppgtt->ctx = ctx;return ppgtt; }
@@ -315,7 +314,7 @@ i915_gem_create_context(struct drm_device *dev, }if (create_vm) { -struct i915_hw_ppgtt *ppgtt =create_vm_for_ctx (dev, ctx); +struct i915_hw_ppgtt *ppgtt =i915_ppgtt_create (dev);if (IS_ERR_OR_NULL (ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
drivers/gpu/drm/i915/i915_gem_gtt.h +0 -2
@@ -258,8 +258,6 @@ struct i915_hw_ppgtt {dma_addr_t *gen8_pt_dma_addr[4 ]; }; -struct intel_context *ctx; -int (*enable)(struct i915_hw_ppgtt *ppgtt); int (*switch_mm)(struct i915_hw_ppgtt *ppgtt, struct intel_engine_cs *ring,
Signature · 1 line
2.0.3
Quoted 29 lines · Michel Thierry
After new vma/ppgtt lifetime rules, the ppgtt can outlive the context it was created for.
- Renamed
create_vm_for_ctxtoi915_ppgtt_createas ctx/ppgtt are no longer referenced.
- Updatedper_file_statsto cope with this change.Cc Daniel Vetter <[email protected]>Signed-off-by Michel Thierry <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 6 +++--- drivers/gpu/drm/i915/i915_gem_context.c | 5 ++--- drivers/gpu/drm/i915/i915_gem_gtt.h | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-)drivers/gpu/drm/i915/i915_debugfs.c +1
-1@@ -322,7 +322,7 @@ static int per_file_stats(int id, void *ptr, void *data)if (USES_FULL_PPGTT (obj->base.dev)) {list_for_each_entry (vma, &obj->vma_list, vma_link) { -struct i915_hw_ppgtt *ppgtt; +struct intel_context *ctx;if (!drm_mm_node_allocated (&vma->node))continue ;
drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data) · line 335
Quoted 6 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-2@@ -332,8 +332,8 @@ static int per_file_stats(int id, void *ptr, void *data)continue ; } - ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base); -if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv) + ctx = container_of(vma->vm, struct intel_context, vm);
That doesn't really work.
-Daniel
Quoted 54 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-0+if (ctx && ctx->file_priv != stats->file_priv)continue ;if (obj->ring)/* XXX per-vma statistic */ drivers/gpu/drm/i915/i915_gem_context.c +2
-3@@ -210,7 +210,7 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size) }static struct i915_hw_ppgtt * -create_vm_for_ctx (struct drm_device *dev,struct intel_context *ctx) +i915_ppgtt_create (struct drm_device *dev) {struct i915_hw_ppgtt *ppgtt;int ret;@@ -225,7 +225,6 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)return ERR_PTR (ret); } - ppgtt->ctx = ctx;return ppgtt; }@@ -315,7 +314,7 @@ i915_gem_create_context(struct drm_device *dev, }if (create_vm) { -struct i915_hw_ppgtt *ppgtt =create_vm_for_ctx (dev, ctx); +struct i915_hw_ppgtt *ppgtt =i915_ppgtt_create (dev);if (IS_ERR_OR_NULL (ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",drivers/gpu/drm/i915/i915_gem_gtt.h +0
-2@@ -258,8 +258,6 @@ struct i915_hw_ppgtt {dma_addr_t *gen8_pt_dma_addr[4 ]; }; -struct intel_context *ctx; -int (*enable)(struct i915_hw_ppgtt *ppgtt); int (*switch_mm)(struct i915_hw_ppgtt *ppgtt, struct intel_engine_cs *ring,Signature · 6 lines
2.0.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 27 lines
-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Wednesday, July 30, 2014 12:59 PM
To: Thierry, Michel
Cc: [email protected]; Daniel Vetter
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Remove context pointer from ppgtt structQuoted 15 lines · Michel Thierry
After new vma/ppgtt lifetime rules, the ppgtt can outlive the context it was created for.
- Renamed
create_vm_for_ctxtoi915_ppgtt_createas ctx/ppgtt are no longer referenced.
- Updatedper_file_statsto cope with this change.Cc Daniel Vetter <[email protected]>Signed-off-by Michel Thierry <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 6 +++--- drivers/gpu/drm/i915/i915_gem_context.c | 5 ++--- drivers/gpu/drm/i915/i915_gem_gtt.h | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-)
Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_debugfs.cdrivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void
Quoted 4 lines
index 96612a5..35c0f09 100644
drivers/gpu/drm/i915/i915_debugfs.c +0
-0@@ -322,7 +322,7 @@ static int per_file_stats(int id, void *ptr, void
*data)
Quoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void
Quoted 9 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1if (USES_FULL_PPGTT (obj->base.dev)) {list_for_each_entry (vma, &obj->vma_list, vma_link) { -struct i915_hw_ppgtt *ppgtt; +struct intel_context *ctx;if (!drm_mm_node_allocated (&vma->node))continue ;@@ -332,8 +332,8 @@ static int per_file_stats(int id, void *ptr, void
*data)
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void *data)
Quoted 4 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-1continue ; } - ppgtt = container_of(vma->vm, struct
i915_hw_ppgtt, base);
Quoted 7 lines
drivers/gpu/drm/i915/i915_debugfs.c static int per_file_stats(int id, void *ptr, void · line 336
Quoted 3 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1-if (ppgtt->ctx && ppgtt->ctx->file_priv != stats- file_priv) + ctx = container_of(vma->vm, struct intel_context,vm);
That doesn't really work.
-Daniel
Indeed, sorry about that. I'm sending v2.
Quoted 55 lines
Review
Quoted 6 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-0+if (ctx && ctx->file_priv != stats->file_priv)continue ;drivers/gpu/drm/i915/i915_debugfs.c +0
-0if (obj->ring)/* XXX per-vma statistic */ (quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gem_context.cdrivers/gpu/drm/i915/i915_gem_context.c i915_gem_alloc_context_obj(struct drm_device
Quoted 4 lines
index 3e7cb50..43da325 100644
drivers/gpu/drm/i915/i915_gem_context.c +0
-0@@ -210,7 +210,7 @@ i915_gem_alloc_context_obj(struct drm_device*dev,
size_tsize)drivers/gpu/drm/i915/i915_gem_context.c create_vm_for_ctx(struct drm_device *dev, struct
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem_context.c +1
-1}static struct i915_hw_ppgtt * -create_vm_for_ctx (struct drm_device *dev,struct intel_context *ctx) +i915_ppgtt_create (struct drm_device *dev) {struct i915_hw_ppgtt *ppgtt;int ret;@@ -225,7 +225,6 @@ create_vm_for_ctx(struct drm_device *dev, struct
intel_context*ctx)Review
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem_context.c +1
-2return ERR_PTR (ret); } - ppgtt->ctx = ctx;return ppgtt; }@@ -315,7 +314,7 @@ i915_gem_create_context(struct drm_device *dev, }if (create_vm) { -struct i915_hw_ppgtt *ppgtt =create_vm_for_ctx (dev, ctx); +struct i915_hw_ppgtt *ppgtt =i915_ppgtt_create (dev);if (IS_ERR_OR_NULL (ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gem_gtt.hQuoted 15 lines
index 8d6f7c1..dd70b0f 100644
drivers/gpu/drm/i915/i915_gem_gtt.h +0
-3@@ -258,8 +258,6 @@ struct i915_hw_ppgtt {dma_addr_t *gen8_pt_dma_addr[4 ]; }; -struct intel_context *ctx; -int (*enable)(struct i915_hw_ppgtt *ppgtt); int (*switch_mm)(struct i915_hw_ppgtt *ppgtt, struct intel_engine_cs *ring, --2.0.3
Quoted 9 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915: Remove context pointer from ppgtt struct
In reply to Michel ThierryAfter new vma/ppgtt lifetime rules, the ppgtt can outlive the context it was created for.
- Renamed create_vm_for_ctx to i915_ppgtt_create as ctx/ppgtt are no longer referenced.
- Updated per_file_stats to cope with this change.
v2: Get the right context for this ppgtt.
--- drivers/gpu/drm/i915/i915_debugfs.c | 25 ++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_gem_context.c | 5 ++--- drivers/gpu/drm/i915/i915_gem_gtt.h | 2 -- 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +24 -1
@@ -308,6 +308,27 @@ struct file_stats {size_t active, inactive; }; +static struct intel_context * +i915_get_ppgtt_context (struct drm_i915_file_private *file_priv, +struct i915_hw_ppgtt *ppgtt) +{ +struct drm_i915_private *dev_priv = file_priv->dev_priv; +struct intel_context *ctx; +struct i915_hw_ppgtt *ctx_ppgtt; + +list_for_each_entry (ctx, &dev_priv->context_list, link) { +if (ctx->legacy_hw_ctx.rcs_state ==NULL ) +continue ; +else { + ctx_ppgtt =ctx_to_ppgtt (ctx); +if (ppgtt == ctx_ppgtt) +return ctx; + } + } + +return NULL ; +} +static int per_file_stats (int id,void *ptr,void *data) {struct drm_i915_gem_object *obj = ptr;
@@ -322,6 +343,7 @@ static int per_file_stats(int id, void *ptr, void *data)if (USES_FULL_PPGTT (obj->base.dev)) {list_for_each_entry (vma, &obj->vma_list, vma_link) { +struct intel_context *ctx;struct i915_hw_ppgtt *ppgtt;if (!drm_mm_node_allocated (&vma->node))
@@ -333,7 +355,8 @@ static int per_file_stats(int id, void *ptr, void *data) } ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base); -if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv) + ctx =i915_get_ppgtt_context (stats->file_priv, ppgtt); +if (ctx && ctx->file_priv != stats->file_priv)continue ;if (obj->ring)/* XXX per-vma statistic */
drivers/gpu/drm/i915/i915_gem_context.c +2 -3
@@ -182,7 +182,7 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size) }static struct i915_hw_ppgtt * -create_vm_for_ctx (struct drm_device *dev,struct intel_context *ctx) +i915_ppgtt_create (struct drm_device *dev) {struct i915_hw_ppgtt *ppgtt;int ret;
@@ -197,7 +197,6 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)return ERR_PTR (ret); } - ppgtt->ctx = ctx;return ppgtt; }
@@ -287,7 +286,7 @@ i915_gem_create_context(struct drm_device *dev, }if (create_vm) { -struct i915_hw_ppgtt *ppgtt =create_vm_for_ctx (dev, ctx); +struct i915_hw_ppgtt *ppgtt =i915_ppgtt_create (dev);if (IS_ERR_OR_NULL (ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
drivers/gpu/drm/i915/i915_gem_gtt.h +0 -2
@@ -258,8 +258,6 @@ struct i915_hw_ppgtt {dma_addr_t *gen8_pt_dma_addr[4 ]; }; -struct intel_context *ctx; -int (*enable)(struct i915_hw_ppgtt *ppgtt); int (*switch_mm)(struct i915_hw_ppgtt *ppgtt, struct intel_engine_cs *ring,
Signature · 1 line
2.0.3
Quoted 27 lines · Michel Thierry
After new vma/ppgtt lifetime rules, the ppgtt can outlive the context it was created for.
- Renamed
create_vm_for_ctxtoi915_ppgtt_createas ctx/ppgtt are no longer referenced.
- Updatedper_file_statsto cope with this change.v2: Get the right context for this ppgtt.
Cc Daniel Vetter <[email protected]>Signed-off-by Michel Thierry <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 25 ++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_gem_context.c | 5 ++--- drivers/gpu/drm/i915/i915_gem_gtt.h | 2 -- 3 files changed, 26 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_debugfs.c +3
-0@@ -308,6 +308,27 @@ struct file_stats {size_t active, inactive; }; +static struct intel_context * +i915_get_ppgtt_context (struct drm_i915_file_private *file_priv, +struct i915_hw_ppgtt *ppgtt)
drivers/gpu/drm/i915/i915_debugfs.c struct file_stats { · line 323
Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +10
-0+{ +struct drm_i915_private *dev_priv = file_priv->dev_priv; +struct intel_context *ctx; +struct i915_hw_ppgtt *ctx_ppgtt; + +list_for_each_entry (ctx, &dev_priv->context_list, link) { +if (ctx->legacy_hw_ctx.rcs_state ==NULL ) +continue ; +else { + ctx_ppgtt =ctx_to_ppgtt (ctx);
More cans of worms: You can't actually do that because we don't actually store a ppgtt in ctx->vm, at least not always. That should be replaceable with a ctx->ppgtt pointer, but there's more.
I think I'll take a look at this myself and do some untangling ... -Daniel
Quoted 75 lines
drivers/gpu/drm/i915/i915_debugfs.c +11
-1+if (ppgtt == ctx_ppgtt) +return ctx; + } + } + +return NULL ; +} +static int per_file_stats (int id,void *ptr,void *data) {struct drm_i915_gem_object *obj = ptr;@@ -322,6 +343,7 @@ static int per_file_stats(int id, void *ptr, void *data)if (USES_FULL_PPGTT (obj->base.dev)) {list_for_each_entry (vma, &obj->vma_list, vma_link) { +struct intel_context *ctx;struct i915_hw_ppgtt *ppgtt;if (!drm_mm_node_allocated (&vma->node))@@ -333,7 +355,8 @@ static int per_file_stats(int id, void *ptr, void *data) } ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base); -if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv) + ctx =i915_get_ppgtt_context (stats->file_priv, ppgtt); +if (ctx && ctx->file_priv != stats->file_priv)continue ;if (obj->ring)/* XXX per-vma statistic */ drivers/gpu/drm/i915/i915_gem_context.c +2
-3@@ -182,7 +182,7 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size) }static struct i915_hw_ppgtt * -create_vm_for_ctx (struct drm_device *dev,struct intel_context *ctx) +i915_ppgtt_create (struct drm_device *dev) {struct i915_hw_ppgtt *ppgtt;int ret;@@ -197,7 +197,6 @@ create_vm_for_ctx(struct drm_device *dev, struct intel_context *ctx)return ERR_PTR (ret); } - ppgtt->ctx = ctx;return ppgtt; }@@ -287,7 +286,7 @@ i915_gem_create_context(struct drm_device *dev, }if (create_vm) { -struct i915_hw_ppgtt *ppgtt =create_vm_for_ctx (dev, ctx); +struct i915_hw_ppgtt *ppgtt =i915_ppgtt_create (dev);if (IS_ERR_OR_NULL (ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",drivers/gpu/drm/i915/i915_gem_gtt.h +0
-2@@ -258,8 +258,6 @@ struct i915_hw_ppgtt {dma_addr_t *gen8_pt_dma_addr[4 ]; }; -struct intel_context *ctx; -int (*enable)(struct i915_hw_ppgtt *ppgtt); int (*switch_mm)(struct i915_hw_ppgtt *ppgtt, struct intel_engine_cs *ring,Signature · 1 line
2.0.3
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 1 line · Daniel Vetter
I think I'll take a look at this myself and do some untangling ...
Ok, I've taken a look and also spotted an issue in your patch. I've submitted the patches to intel-gfx and also uploaded them to
http://cgit.freedesktop.org/~danvet/drm/log/?h=ctx-cleanup
Can you please review them all?
Thanks, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch