* [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
@ 2017-12-20 10:34 ` Roger He
[not found] ` <1513766101-15993-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-12-21 8:07 ` Thomas Hellstrom
2017-12-20 10:34 ` [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver Roger He
` (4 subsequent siblings)
5 siblings, 2 replies; 22+ messages in thread
From: Roger He @ 2017-12-20 10:34 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Cc: Roger He
Change-Id: I5279b5cd3560c4082b00f822219575a5f9c3808a
Signed-off-by: Roger He <Hongbo.He@amd.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------
drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++---
drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++---
drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++---
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++-
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++--
include/drm/ttm/ttm_memory.h | 3 ++-
13 files changed, 87 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index fa57aa8..c59f572 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
bool locked;
- ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
+ ret = ttm_mem_global_alloc(mem_glob, acc_size, ctx);
if (ret) {
pr_err("Out of kernel memory\n");
if (destroy)
diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index 9130bdf..525d3b6 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
struct ttm_mem_zone *single_zone,
uint64_t memory,
- bool no_wait, bool interruptible)
+ struct ttm_operation_ctx *ctx)
{
int count = TTM_MEMORY_ALLOC_RETRIES;
@@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
single_zone,
memory, true)
!= 0)) {
- if (no_wait)
+ if (ctx->no_wait_gpu)
return -ENOMEM;
if (unlikely(count-- == 0))
return -ENOMEM;
@@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
}
int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
- bool no_wait, bool interruptible)
+ struct ttm_operation_ctx *ctx)
{
/**
* Normal allocations of kernel memory are registered in
* all zones.
*/
- return ttm_mem_global_alloc_zone(glob, NULL, memory, no_wait,
- interruptible);
+ return ttm_mem_global_alloc_zone(glob, NULL, memory, ctx);
}
EXPORT_SYMBOL(ttm_mem_global_alloc);
@@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
{
struct ttm_mem_zone *zone = NULL;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
/**
* Page allocations may be registed in a single zone
@@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
if (glob->zone_dma32 && page_to_pfn(page) > 0x00100000UL)
zone = glob->zone_kernel;
#endif
- return ttm_mem_global_alloc_zone(glob, zone, size, false, false);
+ return ttm_mem_global_alloc_zone(glob, zone, size, &ctx);
}
void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,
diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
index 26a7ad0..1aa2baa 100644
--- a/drivers/gpu/drm/ttm/ttm_object.c
+++ b/drivers/gpu/drm/ttm/ttm_object.c
@@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
struct ttm_ref_object *ref;
struct drm_hash_item *hash;
struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
int ret = -EINVAL;
if (base->tfile != tfile && !base->shareable)
@@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
return -EPERM;
ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref),
- false, false);
+ &ctx);
if (unlikely(ret != 0))
return ret;
ref = kmalloc(sizeof(*ref), GFP_KERNEL);
@@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
dma_buf = prime->dma_buf;
if (!dma_buf || !get_dma_buf_unless_doomed(dma_buf)) {
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
-
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
exp_info.ops = &tdev->ops;
exp_info.size = prime->size;
exp_info.flags = flags;
@@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
* Need to create a new dma_buf, with memory accounting.
*/
ret = ttm_mem_global_alloc(tdev->mem_glob, tdev->dma_buf_size,
- false, true);
+ &ctx);
if (unlikely(ret != 0)) {
mutex_unlock(&prime->mutex);
goto out_unref;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
index 9c42e96..55d32ae 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
@@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state *
vmw_binding_state_alloc(struct vmw_private *dev_priv)
{
struct vmw_ctx_binding_state *cbs;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
int ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), sizeof(*cbs),
- false, false);
+ &ctx);
if (ret)
return ERR_PTR(ret);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
index c705632..ef97542 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
@@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
struct vmw_private *dev_priv = vmw_tt->dev_priv;
struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
struct vmw_sg_table *vsgt = &vmw_tt->vsgt;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
struct vmw_piter iter;
dma_addr_t old;
int ret = 0;
@@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
sgt_size = ttm_round_pot(sizeof(struct sg_table));
}
vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages;
- ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, false,
- true);
+ ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, &ctx);
if (unlikely(ret != 0))
return ret;
@@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
struct vmw_private *dev_priv = vmw_tt->dev_priv;
struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
if (ttm->state != tt_unpopulated)
@@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
size_t size =
ttm_round_pot(ttm->num_pages * sizeof(dma_addr_t));
- ret = ttm_mem_global_alloc(glob, size, false, true);
+ ret = ttm_mem_global_alloc(glob, size, &ctx);
if (unlikely(ret != 0))
return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index 4212b3e..3767ac3 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,
struct vmw_resource *tmp;
struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
+ struct ttm_operation_ctx ttm_opt_ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
if (!dev_priv->has_dx && dx) {
@@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
vmw_user_context_size,
- false, true);
+ &ttm_opt_ctx);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for context"
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
index 92df0b0..cbf54ea 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
@@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
u32 type)
{
struct vmw_cotable *vcotbl;
+ struct ttm_operation_ctx ttm_opt_ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
u32 num_entries;
@@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
cotable_acc_size = ttm_round_pot(sizeof(struct vmw_cotable));
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
- cotable_acc_size, false, true);
+ cotable_acc_size, &ttm_opt_ctx);
if (unlikely(ret))
return ERR_PTR(ret);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
index d6b1c50..6c5c75c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
@@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,
struct vmw_user_fence *ufence;
struct vmw_fence_obj *tmp;
struct ttm_mem_global *mem_glob = vmw_mem_glob(fman->dev_priv);
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
int ret;
/*
@@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,
*/
ret = ttm_mem_global_alloc(mem_glob, fman->user_fence_size,
- false, false);
+ &ctx);
if (unlikely(ret != 0))
return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index 004e18b..73b8e9a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
struct vmw_dx_shader *shader;
struct vmw_resource *res;
struct vmw_private *dev_priv = ctx->dev_priv;
+ struct ttm_operation_ctx ttm_opt_ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
if (!vmw_shader_dx_size)
@@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
return -EINVAL;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_shader_dx_size,
- false, true);
+ &ttm_opt_ctx);
if (ret) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for shader "
@@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
{
struct vmw_user_shader *ushader;
struct vmw_resource *res, *tmp;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
/*
@@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
vmw_user_shader_size,
- false, true);
+ &ctx);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for shader "
@@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
{
struct vmw_shader *shader;
struct vmw_resource *res;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
/*
@@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
vmw_shader_size,
- false, true);
+ &ctx);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for shader "
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
index 051d3b3..a0cb310 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
@@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
struct vmw_resource *res;
struct vmw_resource *tmp;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
size_t alloc_size;
size_t account_size;
int ret;
@@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
return ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
- false, true);
+ &ctx);
ttm_read_unlock(&dev_priv->reservation_sem);
if (ret) {
if (ret != -ERESTARTSYS)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
index 5a73eeb..d3573c3 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
@@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
struct vmw_private *dev_priv = ctx->dev_priv;
struct vmw_resource *res;
struct vmw_view *view;
+ struct ttm_operation_ctx ttm_opt_ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
size_t size;
int ret;
@@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
size = offsetof(struct vmw_view, cmd) + cmd_size;
- ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, false, true);
+ ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, &ttm_opt_ctx);
if (ret) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for view"
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 6ac094e..db1bb16 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
struct drm_vmw_surface_create_req *req = &arg->req;
struct drm_vmw_surface_arg *rep = &arg->rep;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
int ret;
int i, j;
uint32_t cur_bo_offset;
@@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
return ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
- size, false, true);
+ size, &ctx);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for surface"
@@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
{
struct vmw_private *dev_priv = vmw_priv(dev);
struct vmw_user_surface *user_srf;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = true,
+ .no_wait_gpu = false
+ };
struct vmw_surface *srf;
int ret;
u32 num_layers;
@@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
return ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
- user_accounting_size, false, true);
+ user_accounting_size, &ctx);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for surface"
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
index 85f3ad6..755c107 100644
--- a/include/drm/ttm/ttm_memory.h
+++ b/include/drm/ttm/ttm_memory.h
@@ -35,6 +35,7 @@
#include <linux/errno.h>
#include <linux/kobject.h>
#include <linux/mm.h>
+#include "ttm_bo_api.h"
/**
* struct ttm_mem_global - Global memory accounting structure.
@@ -79,7 +80,7 @@ struct ttm_mem_global {
extern int ttm_mem_global_init(struct ttm_mem_global *glob);
extern void ttm_mem_global_release(struct ttm_mem_global *glob);
extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
- bool no_wait, bool interruptible);
+ struct ttm_operation_ctx *ctx);
extern void ttm_mem_global_free(struct ttm_mem_global *glob,
uint64_t amount);
extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 22+ messages in thread[parent not found: <1513766101-15993-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>]
* Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
[not found] ` <1513766101-15993-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
@ 2017-12-20 13:33 ` Christian König
[not found] ` <15e3b956-8777-8fb1-2709-5409a756f0be-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 22+ messages in thread
From: Christian König @ 2017-12-20 13:33 UTC (permalink / raw)
To: Roger He, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Thomas Hellstrom,
Sinclair Yeh
Commit message needed! Something like:
Forward the operation context to ttm_mem_global_alloc as well.
Am 20.12.2017 um 11:34 schrieb Roger He:
> Change-Id: I5279b5cd3560c4082b00f822219575a5f9c3808a
> Signed-off-by: Roger He <Hongbo.He@amd.com>
With the commit message fixed, patch is Reviewed-by: Christian König
<christian.koenig@amd.com>.
I would like to get an rb or ab from Thomas and/or Sinclair as well,
since this is touching a lot of vmwgfx code.
Regards,
Christian.
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
> drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------
> drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++--
> include/drm/ttm/ttm_memory.h | 3 ++-
> 13 files changed, 87 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index fa57aa8..c59f572 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
> bool locked;
>
> - ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
> + ret = ttm_mem_global_alloc(mem_glob, acc_size, ctx);
> if (ret) {
> pr_err("Out of kernel memory\n");
> if (destroy)
> diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
> index 9130bdf..525d3b6 100644
> --- a/drivers/gpu/drm/ttm/ttm_memory.c
> +++ b/drivers/gpu/drm/ttm/ttm_memory.c
> @@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
> static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> struct ttm_mem_zone *single_zone,
> uint64_t memory,
> - bool no_wait, bool interruptible)
> + struct ttm_operation_ctx *ctx)
> {
> int count = TTM_MEMORY_ALLOC_RETRIES;
>
> @@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> single_zone,
> memory, true)
> != 0)) {
> - if (no_wait)
> + if (ctx->no_wait_gpu)
> return -ENOMEM;
> if (unlikely(count-- == 0))
> return -ENOMEM;
> @@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> }
>
> int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
> - bool no_wait, bool interruptible)
> + struct ttm_operation_ctx *ctx)
> {
> /**
> * Normal allocations of kernel memory are registered in
> * all zones.
> */
>
> - return ttm_mem_global_alloc_zone(glob, NULL, memory, no_wait,
> - interruptible);
> + return ttm_mem_global_alloc_zone(glob, NULL, memory, ctx);
> }
> EXPORT_SYMBOL(ttm_mem_global_alloc);
>
> @@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
> {
>
> struct ttm_mem_zone *zone = NULL;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
>
> /**
> * Page allocations may be registed in a single zone
> @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
> if (glob->zone_dma32 && page_to_pfn(page) > 0x00100000UL)
> zone = glob->zone_kernel;
> #endif
> - return ttm_mem_global_alloc_zone(glob, zone, size, false, false);
> + return ttm_mem_global_alloc_zone(glob, zone, size, &ctx);
> }
>
> void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,
> diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
> index 26a7ad0..1aa2baa 100644
> --- a/drivers/gpu/drm/ttm/ttm_object.c
> +++ b/drivers/gpu/drm/ttm/ttm_object.c
> @@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
> struct ttm_ref_object *ref;
> struct drm_hash_item *hash;
> struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret = -EINVAL;
>
> if (base->tfile != tfile && !base->shareable)
> @@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
> return -EPERM;
>
> ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref),
> - false, false);
> + &ctx);
> if (unlikely(ret != 0))
> return ret;
> ref = kmalloc(sizeof(*ref), GFP_KERNEL);
> @@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
> dma_buf = prime->dma_buf;
> if (!dma_buf || !get_dma_buf_unless_doomed(dma_buf)) {
> DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
> -
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> exp_info.ops = &tdev->ops;
> exp_info.size = prime->size;
> exp_info.flags = flags;
> @@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
> * Need to create a new dma_buf, with memory accounting.
> */
> ret = ttm_mem_global_alloc(tdev->mem_glob, tdev->dma_buf_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> mutex_unlock(&prime->mutex);
> goto out_unref;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> index 9c42e96..55d32ae 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> @@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state *
> vmw_binding_state_alloc(struct vmw_private *dev_priv)
> {
> struct vmw_ctx_binding_state *cbs;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), sizeof(*cbs),
> - false, false);
> + &ctx);
> if (ret)
> return ERR_PTR(ret);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> index c705632..ef97542 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> @@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
> struct vmw_private *dev_priv = vmw_tt->dev_priv;
> struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
> struct vmw_sg_table *vsgt = &vmw_tt->vsgt;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> struct vmw_piter iter;
> dma_addr_t old;
> int ret = 0;
> @@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
> sgt_size = ttm_round_pot(sizeof(struct sg_table));
> }
> vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages;
> - ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, false,
> - true);
> + ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> @@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
> container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
> struct vmw_private *dev_priv = vmw_tt->dev_priv;
> struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (ttm->state != tt_unpopulated)
> @@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
> if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
> size_t size =
> ttm_round_pot(ttm->num_pages * sizeof(dma_addr_t));
> - ret = ttm_mem_global_alloc(glob, size, false, true);
> + ret = ttm_mem_global_alloc(glob, size, &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> index 4212b3e..3767ac3 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> @@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,
> struct vmw_resource *tmp;
> struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (!dev_priv->has_dx && dx) {
> @@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_user_context_size,
> - false, true);
> + &ttm_opt_ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for context"
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> index 92df0b0..cbf54ea 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> @@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
> u32 type)
> {
> struct vmw_cotable *vcotbl;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
> u32 num_entries;
>
> @@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
> cotable_acc_size = ttm_round_pot(sizeof(struct vmw_cotable));
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - cotable_acc_size, false, true);
> + cotable_acc_size, &ttm_opt_ctx);
> if (unlikely(ret))
> return ERR_PTR(ret);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> index d6b1c50..6c5c75c 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> @@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,
> struct vmw_user_fence *ufence;
> struct vmw_fence_obj *tmp;
> struct ttm_mem_global *mem_glob = vmw_mem_glob(fman->dev_priv);
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,
> */
>
> ret = ttm_mem_global_alloc(mem_glob, fman->user_fence_size,
> - false, false);
> + &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> index 004e18b..73b8e9a 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> @@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
> struct vmw_dx_shader *shader;
> struct vmw_resource *res;
> struct vmw_private *dev_priv = ctx->dev_priv;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (!vmw_shader_dx_size)
> @@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
> return -EINVAL;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_shader_dx_size,
> - false, true);
> + &ttm_opt_ctx);
> if (ret) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> @@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
> {
> struct vmw_user_shader *ushader;
> struct vmw_resource *res, *tmp;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_user_shader_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> @@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
> {
> struct vmw_shader *shader;
> struct vmw_resource *res;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_shader_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> index 051d3b3..a0cb310 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> @@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
> struct vmw_resource *res;
> struct vmw_resource *tmp;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> size_t alloc_size;
> size_t account_size;
> int ret;
> @@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
> - false, true);
> + &ctx);
> ttm_read_unlock(&dev_priv->reservation_sem);
> if (ret) {
> if (ret != -ERESTARTSYS)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> index 5a73eeb..d3573c3 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> @@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
> struct vmw_private *dev_priv = ctx->dev_priv;
> struct vmw_resource *res;
> struct vmw_view *view;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> size_t size;
> int ret;
>
> @@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
>
> size = offsetof(struct vmw_view, cmd) + cmd_size;
>
> - ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, false, true);
> + ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, &ttm_opt_ctx);
> if (ret) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for view"
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> index 6ac094e..db1bb16 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> @@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
> struct drm_vmw_surface_create_req *req = &arg->req;
> struct drm_vmw_surface_arg *rep = &arg->rep;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
> int i, j;
> uint32_t cur_bo_offset;
> @@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - size, false, true);
> + size, &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for surface"
> @@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
> {
> struct vmw_private *dev_priv = vmw_priv(dev);
> struct vmw_user_surface *user_srf;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> struct vmw_surface *srf;
> int ret;
> u32 num_layers;
> @@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - user_accounting_size, false, true);
> + user_accounting_size, &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for surface"
> diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
> index 85f3ad6..755c107 100644
> --- a/include/drm/ttm/ttm_memory.h
> +++ b/include/drm/ttm/ttm_memory.h
> @@ -35,6 +35,7 @@
> #include <linux/errno.h>
> #include <linux/kobject.h>
> #include <linux/mm.h>
> +#include "ttm_bo_api.h"
>
> /**
> * struct ttm_mem_global - Global memory accounting structure.
> @@ -79,7 +80,7 @@ struct ttm_mem_global {
> extern int ttm_mem_global_init(struct ttm_mem_global *glob);
> extern void ttm_mem_global_release(struct ttm_mem_global *glob);
> extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
> - bool no_wait, bool interruptible);
> + struct ttm_operation_ctx *ctx);
> extern void ttm_mem_global_free(struct ttm_mem_global *glob,
> uint64_t amount);
> extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc
2017-12-20 10:34 ` [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc Roger He
[not found] ` <1513766101-15993-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
@ 2017-12-21 8:07 ` Thomas Hellstrom
1 sibling, 0 replies; 22+ messages in thread
From: Thomas Hellstrom @ 2017-12-21 8:07 UTC (permalink / raw)
To: Roger He, amd-gfx, dri-devel
With a suitable commit log, LGTM.
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
On 12/20/2017 11:34 AM, Roger He wrote:
> Change-Id: I5279b5cd3560c4082b00f822219575a5f9c3808a
> Signed-off-by: Roger He <Hongbo.He@amd.com>
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
> drivers/gpu/drm/ttm/ttm_memory.c | 15 +++++++++------
> drivers/gpu/drm/ttm/ttm_object.c | 13 ++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_binding.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 ++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 18 +++++++++++++++---
> drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_so.c | 6 +++++-
> drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 12 ++++++++++--
> include/drm/ttm/ttm_memory.h | 3 ++-
> 13 files changed, 87 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index fa57aa8..c59f572 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1133,7 +1133,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
> bool locked;
>
> - ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
> + ret = ttm_mem_global_alloc(mem_glob, acc_size, ctx);
> if (ret) {
> pr_err("Out of kernel memory\n");
> if (destroy)
> diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
> index 9130bdf..525d3b6 100644
> --- a/drivers/gpu/drm/ttm/ttm_memory.c
> +++ b/drivers/gpu/drm/ttm/ttm_memory.c
> @@ -508,7 +508,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
> static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> struct ttm_mem_zone *single_zone,
> uint64_t memory,
> - bool no_wait, bool interruptible)
> + struct ttm_operation_ctx *ctx)
> {
> int count = TTM_MEMORY_ALLOC_RETRIES;
>
> @@ -516,7 +516,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> single_zone,
> memory, true)
> != 0)) {
> - if (no_wait)
> + if (ctx->no_wait_gpu)
> return -ENOMEM;
> if (unlikely(count-- == 0))
> return -ENOMEM;
> @@ -527,15 +527,14 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
> }
>
> int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
> - bool no_wait, bool interruptible)
> + struct ttm_operation_ctx *ctx)
> {
> /**
> * Normal allocations of kernel memory are registered in
> * all zones.
> */
>
> - return ttm_mem_global_alloc_zone(glob, NULL, memory, no_wait,
> - interruptible);
> + return ttm_mem_global_alloc_zone(glob, NULL, memory, ctx);
> }
> EXPORT_SYMBOL(ttm_mem_global_alloc);
>
> @@ -544,6 +543,10 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
> {
>
> struct ttm_mem_zone *zone = NULL;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
>
> /**
> * Page allocations may be registed in a single zone
> @@ -557,7 +560,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
> if (glob->zone_dma32 && page_to_pfn(page) > 0x00100000UL)
> zone = glob->zone_kernel;
> #endif
> - return ttm_mem_global_alloc_zone(glob, zone, size, false, false);
> + return ttm_mem_global_alloc_zone(glob, zone, size, &ctx);
> }
>
> void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page,
> diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c
> index 26a7ad0..1aa2baa 100644
> --- a/drivers/gpu/drm/ttm/ttm_object.c
> +++ b/drivers/gpu/drm/ttm/ttm_object.c
> @@ -325,6 +325,10 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
> struct ttm_ref_object *ref;
> struct drm_hash_item *hash;
> struct ttm_mem_global *mem_glob = tfile->tdev->mem_glob;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret = -EINVAL;
>
> if (base->tfile != tfile && !base->shareable)
> @@ -350,7 +354,7 @@ int ttm_ref_object_add(struct ttm_object_file *tfile,
> return -EPERM;
>
> ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref),
> - false, false);
> + &ctx);
> if (unlikely(ret != 0))
> return ret;
> ref = kmalloc(sizeof(*ref), GFP_KERNEL);
> @@ -686,7 +690,10 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
> dma_buf = prime->dma_buf;
> if (!dma_buf || !get_dma_buf_unless_doomed(dma_buf)) {
> DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
> -
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> exp_info.ops = &tdev->ops;
> exp_info.size = prime->size;
> exp_info.flags = flags;
> @@ -696,7 +703,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
> * Need to create a new dma_buf, with memory accounting.
> */
> ret = ttm_mem_global_alloc(tdev->mem_glob, tdev->dma_buf_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> mutex_unlock(&prime->mutex);
> goto out_unref;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> index 9c42e96..55d32ae 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
> @@ -1202,10 +1202,14 @@ struct vmw_ctx_binding_state *
> vmw_binding_state_alloc(struct vmw_private *dev_priv)
> {
> struct vmw_ctx_binding_state *cbs;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), sizeof(*cbs),
> - false, false);
> + &ctx);
> if (ret)
> return ERR_PTR(ret);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> index c705632..ef97542 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> @@ -394,6 +394,10 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
> struct vmw_private *dev_priv = vmw_tt->dev_priv;
> struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
> struct vmw_sg_table *vsgt = &vmw_tt->vsgt;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> struct vmw_piter iter;
> dma_addr_t old;
> int ret = 0;
> @@ -417,8 +421,7 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)
> sgt_size = ttm_round_pot(sizeof(struct sg_table));
> }
> vmw_tt->sg_alloc_size = sgt_size + sgl_size * vsgt->num_pages;
> - ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, false,
> - true);
> + ret = ttm_mem_global_alloc(glob, vmw_tt->sg_alloc_size, &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> @@ -638,6 +641,10 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
> container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
> struct vmw_private *dev_priv = vmw_tt->dev_priv;
> struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (ttm->state != tt_unpopulated)
> @@ -646,7 +653,7 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
> if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
> size_t size =
> ttm_round_pot(ttm->num_pages * sizeof(dma_addr_t));
> - ret = ttm_mem_global_alloc(glob, size, false, true);
> + ret = ttm_mem_global_alloc(glob, size, &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> index 4212b3e..3767ac3 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
> @@ -746,6 +746,10 @@ static int vmw_context_define(struct drm_device *dev, void *data,
> struct vmw_resource *tmp;
> struct drm_vmw_context_arg *arg = (struct drm_vmw_context_arg *)data;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (!dev_priv->has_dx && dx) {
> @@ -768,7 +772,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_user_context_size,
> - false, true);
> + &ttm_opt_ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for context"
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> index 92df0b0..cbf54ea 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c
> @@ -573,6 +573,10 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
> u32 type)
> {
> struct vmw_cotable *vcotbl;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
> u32 num_entries;
>
> @@ -580,7 +584,7 @@ struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
> cotable_acc_size = ttm_round_pot(sizeof(struct vmw_cotable));
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - cotable_acc_size, false, true);
> + cotable_acc_size, &ttm_opt_ctx);
> if (unlikely(ret))
> return ERR_PTR(ret);
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> index d6b1c50..6c5c75c 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> @@ -588,6 +588,10 @@ int vmw_user_fence_create(struct drm_file *file_priv,
> struct vmw_user_fence *ufence;
> struct vmw_fence_obj *tmp;
> struct ttm_mem_global *mem_glob = vmw_mem_glob(fman->dev_priv);
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -596,7 +600,7 @@ int vmw_user_fence_create(struct drm_file *file_priv,
> */
>
> ret = ttm_mem_global_alloc(mem_glob, fman->user_fence_size,
> - false, false);
> + &ctx);
> if (unlikely(ret != 0))
> return ret;
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> index 004e18b..73b8e9a 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> @@ -607,6 +607,10 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
> struct vmw_dx_shader *shader;
> struct vmw_resource *res;
> struct vmw_private *dev_priv = ctx->dev_priv;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> if (!vmw_shader_dx_size)
> @@ -616,7 +620,7 @@ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
> return -EINVAL;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), vmw_shader_dx_size,
> - false, true);
> + &ttm_opt_ctx);
> if (ret) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> @@ -730,6 +734,10 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
> {
> struct vmw_user_shader *ushader;
> struct vmw_resource *res, *tmp;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -742,7 +750,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_user_shader_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> @@ -800,6 +808,10 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
> {
> struct vmw_shader *shader;
> struct vmw_resource *res;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
>
> /*
> @@ -812,7 +824,7 @@ static struct vmw_resource *vmw_shader_alloc(struct vmw_private *dev_priv,
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> vmw_shader_size,
> - false, true);
> + &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for shader "
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> index 051d3b3..a0cb310 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
> @@ -149,6 +149,10 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
> struct vmw_resource *res;
> struct vmw_resource *tmp;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> size_t alloc_size;
> size_t account_size;
> int ret;
> @@ -162,7 +166,7 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
> - false, true);
> + &ctx);
> ttm_read_unlock(&dev_priv->reservation_sem);
> if (ret) {
> if (ret != -ERESTARTSYS)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> index 5a73eeb..d3573c3 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_so.c
> @@ -329,6 +329,10 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
> struct vmw_private *dev_priv = ctx->dev_priv;
> struct vmw_resource *res;
> struct vmw_view *view;
> + struct ttm_operation_ctx ttm_opt_ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> size_t size;
> int ret;
>
> @@ -345,7 +349,7 @@ int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
>
> size = offsetof(struct vmw_view, cmd) + cmd_size;
>
> - ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, false, true);
> + ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, &ttm_opt_ctx);
> if (ret) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for view"
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> index 6ac094e..db1bb16 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> @@ -700,6 +700,10 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
> struct drm_vmw_surface_create_req *req = &arg->req;
> struct drm_vmw_surface_arg *rep = &arg->rep;
> struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> int ret;
> int i, j;
> uint32_t cur_bo_offset;
> @@ -741,7 +745,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - size, false, true);
> + size, &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for surface"
> @@ -1479,6 +1483,10 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
> {
> struct vmw_private *dev_priv = vmw_priv(dev);
> struct vmw_user_surface *user_srf;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = true,
> + .no_wait_gpu = false
> + };
> struct vmw_surface *srf;
> int ret;
> u32 num_layers;
> @@ -1525,7 +1533,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
> return ret;
>
> ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
> - user_accounting_size, false, true);
> + user_accounting_size, &ctx);
> if (unlikely(ret != 0)) {
> if (ret != -ERESTARTSYS)
> DRM_ERROR("Out of graphics memory for surface"
> diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
> index 85f3ad6..755c107 100644
> --- a/include/drm/ttm/ttm_memory.h
> +++ b/include/drm/ttm/ttm_memory.h
> @@ -35,6 +35,7 @@
> #include <linux/errno.h>
> #include <linux/kobject.h>
> #include <linux/mm.h>
> +#include "ttm_bo_api.h"
>
> /**
> * struct ttm_mem_global - Global memory accounting structure.
> @@ -79,7 +80,7 @@ struct ttm_mem_global {
> extern int ttm_mem_global_init(struct ttm_mem_global *glob);
> extern void ttm_mem_global_release(struct ttm_mem_global *glob);
> extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
> - bool no_wait, bool interruptible);
> + struct ttm_operation_ctx *ctx);
> extern void ttm_mem_global_free(struct ttm_mem_global *glob,
> uint64_t amount);
> extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-12-20 10:34 ` [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc Roger He
@ 2017-12-20 10:34 ` Roger He
2017-12-20 14:20 ` Christian König
2017-12-20 10:34 ` [PATCH 5/7] drm/ttm: use an operation ctx for ttm_tt_bind Roger He
` (3 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Roger He @ 2017-12-20 10:34 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Cc: Roger He
Change-Id: I803ea52d11e5c06add0dffab836c3aecc00b56dd
Signed-off-by: Roger He <Hongbo.He@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++---
drivers/gpu/drm/ast/ast_ttm.c | 5 +++--
drivers/gpu/drm/cirrus/cirrus_ttm.c | 5 +++--
drivers/gpu/drm/nouveau/nouveau_bo.c | 8 ++++----
drivers/gpu/drm/qxl/qxl_ttm.c | 5 +++--
drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++----
drivers/gpu/drm/ttm/ttm_agp_backend.c | 4 ++--
drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++++---
drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++++++-
drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++++--------
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 ++++-------
drivers/gpu/drm/ttm/ttm_tt.c | 6 +++++-
drivers/gpu/drm/virtio/virtgpu_object.c | 6 +++++-
drivers/gpu/drm/virtio/virtgpu_ttm.c | 5 +++--
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 +++++--------
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c | 13 +++++++++++--
include/drm/ttm/ttm_bo_driver.h | 5 +++--
include/drm/ttm/ttm_page_alloc.h | 11 +++++++----
18 files changed, 86 insertions(+), 58 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index f1b7d98..52aab9d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -990,7 +990,8 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_bo_device *bdev,
return >t->ttm.ttm;
}
-static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)
+static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
struct amdgpu_ttm_tt *gtt = (void *)ttm;
@@ -1018,11 +1019,11 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)
#ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
- return ttm_dma_populate(>t->ttm, adev->dev);
+ return ttm_dma_populate(>t->ttm, adev->dev, ctx);
}
#endif
- return ttm_populate_and_map_pages(adev->dev, >t->ttm);
+ return ttm_populate_and_map_pages(adev->dev, >t->ttm, ctx);
}
static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index 28da7c2..1413e94 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -216,9 +216,10 @@ static struct ttm_tt *ast_ttm_tt_create(struct ttm_bo_device *bdev,
return tt;
}
-static int ast_ttm_tt_populate(struct ttm_tt *ttm)
+static int ast_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
- return ttm_pool_populate(ttm);
+ return ttm_pool_populate(ttm, ctx);
}
static void ast_ttm_tt_unpopulate(struct ttm_tt *ttm)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index 2a5b54d..95e2d40 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -216,9 +216,10 @@ static struct ttm_tt *cirrus_ttm_tt_create(struct ttm_bo_device *bdev,
return tt;
}
-static int cirrus_ttm_tt_populate(struct ttm_tt *ttm)
+static int cirrus_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
- return ttm_pool_populate(ttm);
+ return ttm_pool_populate(ttm, ctx);
}
static void cirrus_ttm_tt_unpopulate(struct ttm_tt *ttm)
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 6b6fb20..b141c27 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1547,7 +1547,7 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
}
static int
-nouveau_ttm_tt_populate(struct ttm_tt *ttm)
+nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
struct ttm_dma_tt *ttm_dma = (void *)ttm;
struct nouveau_drm *drm;
@@ -1572,17 +1572,17 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
#if IS_ENABLED(CONFIG_AGP)
if (drm->agp.bridge) {
- return ttm_agp_tt_populate(ttm);
+ return ttm_agp_tt_populate(ttm, ctx);
}
#endif
#if IS_ENABLED(CONFIG_SWIOTLB) && IS_ENABLED(CONFIG_X86)
if (swiotlb_nr_tbl()) {
- return ttm_dma_populate((void *)ttm, dev);
+ return ttm_dma_populate((void *)ttm, dev, ctx);
}
#endif
- r = ttm_pool_populate(ttm);
+ r = ttm_pool_populate(ttm, ctx);
if (r) {
return r;
}
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 78ce118..989645c 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -291,14 +291,15 @@ static struct ttm_backend_func qxl_backend_func = {
.destroy = &qxl_ttm_backend_destroy,
};
-static int qxl_ttm_tt_populate(struct ttm_tt *ttm)
+static int qxl_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
int r;
if (ttm->state != tt_unpopulated)
return 0;
- r = ttm_pool_populate(ttm);
+ r = ttm_pool_populate(ttm, ctx);
if (r)
return r;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 557fd79..634fc6f 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -721,7 +721,8 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
return (struct radeon_ttm_tt *)ttm;
}
-static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
+static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
struct radeon_device *rdev;
@@ -750,17 +751,17 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
rdev = radeon_get_rdev(ttm->bdev);
#if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP) {
- return ttm_agp_tt_populate(ttm);
+ return ttm_agp_tt_populate(ttm, ctx);
}
#endif
#ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
- return ttm_dma_populate(>t->ttm, rdev->dev);
+ return ttm_dma_populate(>t->ttm, rdev->dev, ctx);
}
#endif
- return ttm_populate_and_map_pages(rdev->dev, >t->ttm);
+ return ttm_populate_and_map_pages(rdev->dev, >t->ttm, ctx);
}
static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 028ab60..3e795a0 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -133,12 +133,12 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
}
EXPORT_SYMBOL(ttm_agp_tt_create);
-int ttm_agp_tt_populate(struct ttm_tt *ttm)
+int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
if (ttm->state != tt_unpopulated)
return 0;
- return ttm_pool_populate(ttm);
+ return ttm_pool_populate(ttm, ctx);
}
EXPORT_SYMBOL(ttm_agp_tt_populate);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 6e353df..b7eb507 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -376,7 +376,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
* TTM might be null for moves within the same region.
*/
if (ttm && ttm->state == tt_unpopulated) {
- ret = ttm->bdev->driver->ttm_tt_populate(ttm);
+ ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
if (ret)
goto out1;
}
@@ -545,14 +545,19 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
unsigned long num_pages,
struct ttm_bo_kmap_obj *map)
{
- struct ttm_mem_reg *mem = &bo->mem; pgprot_t prot;
+ struct ttm_mem_reg *mem = &bo->mem;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
struct ttm_tt *ttm = bo->ttm;
+ pgprot_t prot;
int ret;
BUG_ON(!ttm);
if (ttm->state == tt_unpopulated) {
- ret = ttm->bdev->driver->ttm_tt_populate(ttm);
+ ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
if (ret)
return ret;
}
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index c8ebb75..65dfcdd 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -215,12 +215,17 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
cvma.vm_page_prot);
} else {
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
+
ttm = bo->ttm;
cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
cvma.vm_page_prot);
/* Allocate all page at once, most common usage */
- if (ttm->bdev->driver->ttm_tt_populate(ttm)) {
+ if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) {
retval = VM_FAULT_OOM;
goto out_io_unlock;
}
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index 8f93ff3..f1a3d55 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1058,13 +1058,9 @@ void ttm_page_alloc_fini(void)
_manager = NULL;
}
-int ttm_pool_populate(struct ttm_tt *ttm)
+int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
- struct ttm_operation_ctx ctx = {
- .interruptible = false,
- .no_wait_gpu = false
- };
unsigned i;
int ret;
@@ -1080,7 +1076,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)
for (i = 0; i < ttm->num_pages; ++i) {
ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
- PAGE_SIZE, &ctx);
+ PAGE_SIZE, ctx);
if (unlikely(ret != 0)) {
ttm_pool_unpopulate(ttm);
return -ENOMEM;
@@ -1117,12 +1113,13 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)
}
EXPORT_SYMBOL(ttm_pool_unpopulate);
-int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt)
+int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
+ struct ttm_operation_ctx *ctx)
{
unsigned i, j;
int r;
- r = ttm_pool_populate(&tt->ttm);
+ r = ttm_pool_populate(&tt->ttm, ctx);
if (r)
return r;
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index 8aac86a..3ac5391 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -923,14 +923,11 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)
* On success pages list will hold count number of correctly
* cached pages. On failure will hold the negative return value (-ENOMEM, etc).
*/
-int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
+int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
+ struct ttm_operation_ctx *ctx)
{
struct ttm_tt *ttm = &ttm_dma->ttm;
struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
- struct ttm_operation_ctx ctx = {
- .interruptible = false,
- .no_wait_gpu = false
- };
unsigned long num_pages = ttm->num_pages;
struct dma_pool *pool;
enum pool_type type;
@@ -966,7 +963,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
break;
ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
- pool->size, &ctx);
+ pool->size, ctx);
if (unlikely(ret != 0)) {
ttm_dma_unpopulate(ttm_dma, dev);
return -ENOMEM;
@@ -1002,7 +999,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
}
ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
- pool->size, &ctx);
+ pool->size, ctx);
if (unlikely(ret != 0)) {
ttm_dma_unpopulate(ttm_dma, dev);
return -ENOMEM;
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 8ebc8d3..b48d7a0 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -263,6 +263,10 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
{
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
int ret = 0;
if (!ttm)
@@ -271,7 +275,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
if (ttm->state == tt_bound)
return 0;
- ret = ttm->bdev->driver->ttm_tt_populate(ttm);
+ ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
if (ret)
return ret;
diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
index 6f66b73..0b90cdb 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -124,13 +124,17 @@ int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,
int ret;
struct page **pages = bo->tbo.ttm->pages;
int nr_pages = bo->tbo.num_pages;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
/* wtf swapping */
if (bo->pages)
return 0;
if (bo->tbo.ttm->state == tt_unpopulated)
- bo->tbo.ttm->bdev->driver->ttm_tt_populate(bo->tbo.ttm);
+ bo->tbo.ttm->bdev->driver->ttm_tt_populate(bo->tbo.ttm, &ctx);
bo->pages = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
if (!bo->pages)
goto out;
diff --git a/drivers/gpu/drm/virtio/virtgpu_ttm.c b/drivers/gpu/drm/virtio/virtgpu_ttm.c
index 488c6bd..72eb417 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ttm.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ttm.c
@@ -324,12 +324,13 @@ static struct ttm_backend_func virtio_gpu_backend_func = {
.destroy = &virtio_gpu_ttm_backend_destroy,
};
-static int virtio_gpu_ttm_tt_populate(struct ttm_tt *ttm)
+static int virtio_gpu_ttm_tt_populate(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx)
{
if (ttm->state != tt_unpopulated)
return 0;
- return ttm_pool_populate(ttm);
+ return ttm_pool_populate(ttm, ctx);
}
static void virtio_gpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
index ef97542..90b0d6b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
@@ -635,16 +635,12 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm)
}
-static int vmw_ttm_populate(struct ttm_tt *ttm)
+static int vmw_ttm_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
struct vmw_ttm_tt *vmw_tt =
container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
struct vmw_private *dev_priv = vmw_tt->dev_priv;
struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
- struct ttm_operation_ctx ctx = {
- .interruptible = true,
- .no_wait_gpu = false
- };
int ret;
if (ttm->state != tt_unpopulated)
@@ -653,15 +649,16 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
size_t size =
ttm_round_pot(ttm->num_pages * sizeof(dma_addr_t));
- ret = ttm_mem_global_alloc(glob, size, &ctx);
+ ret = ttm_mem_global_alloc(glob, size, ctx);
if (unlikely(ret != 0))
return ret;
- ret = ttm_dma_populate(&vmw_tt->dma_ttm, dev_priv->dev->dev);
+ ret = ttm_dma_populate(&vmw_tt->dma_ttm, dev_priv->dev->dev,
+ ctx);
if (unlikely(ret != 0))
ttm_mem_global_free(glob, size);
} else
- ret = ttm_pool_populate(ttm);
+ ret = ttm_pool_populate(ttm, ctx);
return ret;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
index b17f08f..736ca47 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
@@ -240,6 +240,10 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,
unsigned long offset;
unsigned long bo_size;
struct vmw_otable *otables = batch->otables;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
SVGAOTableType i;
int ret;
@@ -264,7 +268,7 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,
ret = ttm_bo_reserve(batch->otable_bo, false, true, NULL);
BUG_ON(ret != 0);
- ret = vmw_bo_driver.ttm_tt_populate(batch->otable_bo->ttm);
+ ret = vmw_bo_driver.ttm_tt_populate(batch->otable_bo->ttm, &ctx);
if (unlikely(ret != 0))
goto out_unreserve;
ret = vmw_bo_map_dma(batch->otable_bo);
@@ -430,6 +434,11 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv,
struct vmw_mob *mob)
{
int ret;
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
+
BUG_ON(mob->pt_bo != NULL);
ret = ttm_bo_create(&dev_priv->bdev, mob->num_pages * PAGE_SIZE,
@@ -442,7 +451,7 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv,
ret = ttm_bo_reserve(mob->pt_bo, false, true, NULL);
BUG_ON(ret != 0);
- ret = vmw_bo_driver.ttm_tt_populate(mob->pt_bo->ttm);
+ ret = vmw_bo_driver.ttm_tt_populate(mob->pt_bo->ttm, &ctx);
if (unlikely(ret != 0))
goto out_unreserve;
ret = vmw_bo_map_dma(mob->pt_bo);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 934fecf..84860ec 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -352,7 +352,8 @@ struct ttm_bo_driver {
* Returns:
* -ENOMEM: Out of memory.
*/
- int (*ttm_tt_populate)(struct ttm_tt *ttm);
+ int (*ttm_tt_populate)(struct ttm_tt *ttm,
+ struct ttm_operation_ctx *ctx);
/**
* ttm_tt_unpopulate
@@ -1077,7 +1078,7 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
struct agp_bridge_data *bridge,
unsigned long size, uint32_t page_flags,
struct page *dummy_read_page);
-int ttm_agp_tt_populate(struct ttm_tt *ttm);
+int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
#endif
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index 5938113..f8395dd 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -47,7 +47,7 @@ void ttm_page_alloc_fini(void);
*
* Add backing pages to all of @ttm
*/
-int ttm_pool_populate(struct ttm_tt *ttm);
+int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
/**
* ttm_pool_unpopulate:
@@ -61,7 +61,8 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);
/**
* Populates and DMA maps pages to fullfil a ttm_dma_populate() request
*/
-int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt);
+int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
+ struct ttm_operation_ctx *ctx);
/**
* Unpopulates and DMA unmaps pages as part of a
@@ -89,7 +90,8 @@ void ttm_dma_page_alloc_fini(void);
*/
int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
-int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
+int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
+ struct ttm_operation_ctx *ctx);
void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
#else
@@ -106,7 +108,8 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
return 0;
}
static inline int ttm_dma_populate(struct ttm_dma_tt *ttm_dma,
- struct device *dev)
+ struct device *dev,
+ struct ttm_operation_ctx *ctx)
{
return -ENOMEM;
}
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver
2017-12-20 10:34 ` [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver Roger He
@ 2017-12-20 14:20 ` Christian König
0 siblings, 0 replies; 22+ messages in thread
From: Christian König @ 2017-12-20 14:20 UTC (permalink / raw)
To: Roger He, amd-gfx, dri-devel
Am 20.12.2017 um 11:34 schrieb Roger He:
> Change-Id: I803ea52d11e5c06add0dffab836c3aecc00b56dd
> Signed-off-by: Roger He <Hongbo.He@amd.com>
Commit message! And please double check the coding style of
ast_ttm_tt_populate.
With that fixed that patch is Reviewed-by: Christian König
<christian.koenig@amd.com>.
Regards,
Christian.
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++---
> drivers/gpu/drm/ast/ast_ttm.c | 5 +++--
> drivers/gpu/drm/cirrus/cirrus_ttm.c | 5 +++--
> drivers/gpu/drm/nouveau/nouveau_bo.c | 8 ++++----
> drivers/gpu/drm/qxl/qxl_ttm.c | 5 +++--
> drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++----
> drivers/gpu/drm/ttm/ttm_agp_backend.c | 4 ++--
> drivers/gpu/drm/ttm/ttm_bo_util.c | 11 ++++++++---
> drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 ++++++-
> drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++++--------
> drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 ++++-------
> drivers/gpu/drm/ttm/ttm_tt.c | 6 +++++-
> drivers/gpu/drm/virtio/virtgpu_object.c | 6 +++++-
> drivers/gpu/drm/virtio/virtgpu_ttm.c | 5 +++--
> drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 13 +++++--------
> drivers/gpu/drm/vmwgfx/vmwgfx_mob.c | 13 +++++++++++--
> include/drm/ttm/ttm_bo_driver.h | 5 +++--
> include/drm/ttm/ttm_page_alloc.h | 11 +++++++----
> 18 files changed, 86 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index f1b7d98..52aab9d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -990,7 +990,8 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_bo_device *bdev,
> return >t->ttm.ttm;
> }
>
> -static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)
> +static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
> struct amdgpu_ttm_tt *gtt = (void *)ttm;
> @@ -1018,11 +1019,11 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm)
>
> #ifdef CONFIG_SWIOTLB
> if (swiotlb_nr_tbl()) {
> - return ttm_dma_populate(>t->ttm, adev->dev);
> + return ttm_dma_populate(>t->ttm, adev->dev, ctx);
> }
> #endif
>
> - return ttm_populate_and_map_pages(adev->dev, >t->ttm);
> + return ttm_populate_and_map_pages(adev->dev, >t->ttm, ctx);
> }
>
> static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
> diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
> index 28da7c2..1413e94 100644
> --- a/drivers/gpu/drm/ast/ast_ttm.c
> +++ b/drivers/gpu/drm/ast/ast_ttm.c
> @@ -216,9 +216,10 @@ static struct ttm_tt *ast_ttm_tt_create(struct ttm_bo_device *bdev,
> return tt;
> }
>
> -static int ast_ttm_tt_populate(struct ttm_tt *ttm)
> +static int ast_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> - return ttm_pool_populate(ttm);
> + return ttm_pool_populate(ttm, ctx);
> }
>
> static void ast_ttm_tt_unpopulate(struct ttm_tt *ttm)
> diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
> index 2a5b54d..95e2d40 100644
> --- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
> +++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
> @@ -216,9 +216,10 @@ static struct ttm_tt *cirrus_ttm_tt_create(struct ttm_bo_device *bdev,
> return tt;
> }
>
> -static int cirrus_ttm_tt_populate(struct ttm_tt *ttm)
> +static int cirrus_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> - return ttm_pool_populate(ttm);
> + return ttm_pool_populate(ttm, ctx);
> }
>
> static void cirrus_ttm_tt_unpopulate(struct ttm_tt *ttm)
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 6b6fb20..b141c27 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -1547,7 +1547,7 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
> }
>
> static int
> -nouveau_ttm_tt_populate(struct ttm_tt *ttm)
> +nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> {
> struct ttm_dma_tt *ttm_dma = (void *)ttm;
> struct nouveau_drm *drm;
> @@ -1572,17 +1572,17 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
>
> #if IS_ENABLED(CONFIG_AGP)
> if (drm->agp.bridge) {
> - return ttm_agp_tt_populate(ttm);
> + return ttm_agp_tt_populate(ttm, ctx);
> }
> #endif
>
> #if IS_ENABLED(CONFIG_SWIOTLB) && IS_ENABLED(CONFIG_X86)
> if (swiotlb_nr_tbl()) {
> - return ttm_dma_populate((void *)ttm, dev);
> + return ttm_dma_populate((void *)ttm, dev, ctx);
> }
> #endif
>
> - r = ttm_pool_populate(ttm);
> + r = ttm_pool_populate(ttm, ctx);
> if (r) {
> return r;
> }
> diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
> index 78ce118..989645c 100644
> --- a/drivers/gpu/drm/qxl/qxl_ttm.c
> +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
> @@ -291,14 +291,15 @@ static struct ttm_backend_func qxl_backend_func = {
> .destroy = &qxl_ttm_backend_destroy,
> };
>
> -static int qxl_ttm_tt_populate(struct ttm_tt *ttm)
> +static int qxl_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> int r;
>
> if (ttm->state != tt_unpopulated)
> return 0;
>
> - r = ttm_pool_populate(ttm);
> + r = ttm_pool_populate(ttm, ctx);
> if (r)
> return r;
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index 557fd79..634fc6f 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -721,7 +721,8 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
> return (struct radeon_ttm_tt *)ttm;
> }
>
> -static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
> +static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> struct radeon_device *rdev;
> @@ -750,17 +751,17 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
> rdev = radeon_get_rdev(ttm->bdev);
> #if IS_ENABLED(CONFIG_AGP)
> if (rdev->flags & RADEON_IS_AGP) {
> - return ttm_agp_tt_populate(ttm);
> + return ttm_agp_tt_populate(ttm, ctx);
> }
> #endif
>
> #ifdef CONFIG_SWIOTLB
> if (swiotlb_nr_tbl()) {
> - return ttm_dma_populate(>t->ttm, rdev->dev);
> + return ttm_dma_populate(>t->ttm, rdev->dev, ctx);
> }
> #endif
>
> - return ttm_populate_and_map_pages(rdev->dev, >t->ttm);
> + return ttm_populate_and_map_pages(rdev->dev, >t->ttm, ctx);
> }
>
> static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
> diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
> index 028ab60..3e795a0 100644
> --- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
> +++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
> @@ -133,12 +133,12 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
> }
> EXPORT_SYMBOL(ttm_agp_tt_create);
>
> -int ttm_agp_tt_populate(struct ttm_tt *ttm)
> +int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> {
> if (ttm->state != tt_unpopulated)
> return 0;
>
> - return ttm_pool_populate(ttm);
> + return ttm_pool_populate(ttm, ctx);
> }
> EXPORT_SYMBOL(ttm_agp_tt_populate);
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index 6e353df..b7eb507 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -376,7 +376,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
> * TTM might be null for moves within the same region.
> */
> if (ttm && ttm->state == tt_unpopulated) {
> - ret = ttm->bdev->driver->ttm_tt_populate(ttm);
> + ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
> if (ret)
> goto out1;
> }
> @@ -545,14 +545,19 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
> unsigned long num_pages,
> struct ttm_bo_kmap_obj *map)
> {
> - struct ttm_mem_reg *mem = &bo->mem; pgprot_t prot;
> + struct ttm_mem_reg *mem = &bo->mem;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> struct ttm_tt *ttm = bo->ttm;
> + pgprot_t prot;
> int ret;
>
> BUG_ON(!ttm);
>
> if (ttm->state == tt_unpopulated) {
> - ret = ttm->bdev->driver->ttm_tt_populate(ttm);
> + ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
> if (ret)
> return ret;
> }
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index c8ebb75..65dfcdd 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -215,12 +215,17 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
> cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
> cvma.vm_page_prot);
> } else {
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> +
> ttm = bo->ttm;
> cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
> cvma.vm_page_prot);
>
> /* Allocate all page at once, most common usage */
> - if (ttm->bdev->driver->ttm_tt_populate(ttm)) {
> + if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) {
> retval = VM_FAULT_OOM;
> goto out_io_unlock;
> }
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> index 8f93ff3..f1a3d55 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> @@ -1058,13 +1058,9 @@ void ttm_page_alloc_fini(void)
> _manager = NULL;
> }
>
> -int ttm_pool_populate(struct ttm_tt *ttm)
> +int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> {
> struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
> - struct ttm_operation_ctx ctx = {
> - .interruptible = false,
> - .no_wait_gpu = false
> - };
> unsigned i;
> int ret;
>
> @@ -1080,7 +1076,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)
>
> for (i = 0; i < ttm->num_pages; ++i) {
> ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
> - PAGE_SIZE, &ctx);
> + PAGE_SIZE, ctx);
> if (unlikely(ret != 0)) {
> ttm_pool_unpopulate(ttm);
> return -ENOMEM;
> @@ -1117,12 +1113,13 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)
> }
> EXPORT_SYMBOL(ttm_pool_unpopulate);
>
> -int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt)
> +int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
> + struct ttm_operation_ctx *ctx)
> {
> unsigned i, j;
> int r;
>
> - r = ttm_pool_populate(&tt->ttm);
> + r = ttm_pool_populate(&tt->ttm, ctx);
> if (r)
> return r;
>
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> index 8aac86a..3ac5391 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> @@ -923,14 +923,11 @@ static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)
> * On success pages list will hold count number of correctly
> * cached pages. On failure will hold the negative return value (-ENOMEM, etc).
> */
> -int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
> +int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
> + struct ttm_operation_ctx *ctx)
> {
> struct ttm_tt *ttm = &ttm_dma->ttm;
> struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
> - struct ttm_operation_ctx ctx = {
> - .interruptible = false,
> - .no_wait_gpu = false
> - };
> unsigned long num_pages = ttm->num_pages;
> struct dma_pool *pool;
> enum pool_type type;
> @@ -966,7 +963,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
> break;
>
> ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
> - pool->size, &ctx);
> + pool->size, ctx);
> if (unlikely(ret != 0)) {
> ttm_dma_unpopulate(ttm_dma, dev);
> return -ENOMEM;
> @@ -1002,7 +999,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)
> }
>
> ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
> - pool->size, &ctx);
> + pool->size, ctx);
> if (unlikely(ret != 0)) {
> ttm_dma_unpopulate(ttm_dma, dev);
> return -ENOMEM;
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index 8ebc8d3..b48d7a0 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -263,6 +263,10 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
>
> int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
> {
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> int ret = 0;
>
> if (!ttm)
> @@ -271,7 +275,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
> if (ttm->state == tt_bound)
> return 0;
>
> - ret = ttm->bdev->driver->ttm_tt_populate(ttm);
> + ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
> if (ret)
> return ret;
>
> diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
> index 6f66b73..0b90cdb 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> @@ -124,13 +124,17 @@ int virtio_gpu_object_get_sg_table(struct virtio_gpu_device *qdev,
> int ret;
> struct page **pages = bo->tbo.ttm->pages;
> int nr_pages = bo->tbo.num_pages;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
>
> /* wtf swapping */
> if (bo->pages)
> return 0;
>
> if (bo->tbo.ttm->state == tt_unpopulated)
> - bo->tbo.ttm->bdev->driver->ttm_tt_populate(bo->tbo.ttm);
> + bo->tbo.ttm->bdev->driver->ttm_tt_populate(bo->tbo.ttm, &ctx);
> bo->pages = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> if (!bo->pages)
> goto out;
> diff --git a/drivers/gpu/drm/virtio/virtgpu_ttm.c b/drivers/gpu/drm/virtio/virtgpu_ttm.c
> index 488c6bd..72eb417 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ttm.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ttm.c
> @@ -324,12 +324,13 @@ static struct ttm_backend_func virtio_gpu_backend_func = {
> .destroy = &virtio_gpu_ttm_backend_destroy,
> };
>
> -static int virtio_gpu_ttm_tt_populate(struct ttm_tt *ttm)
> +static int virtio_gpu_ttm_tt_populate(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx)
> {
> if (ttm->state != tt_unpopulated)
> return 0;
>
> - return ttm_pool_populate(ttm);
> + return ttm_pool_populate(ttm, ctx);
> }
>
> static void virtio_gpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> index ef97542..90b0d6b 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
> @@ -635,16 +635,12 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm)
> }
>
>
> -static int vmw_ttm_populate(struct ttm_tt *ttm)
> +static int vmw_ttm_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> {
> struct vmw_ttm_tt *vmw_tt =
> container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
> struct vmw_private *dev_priv = vmw_tt->dev_priv;
> struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
> - struct ttm_operation_ctx ctx = {
> - .interruptible = true,
> - .no_wait_gpu = false
> - };
> int ret;
>
> if (ttm->state != tt_unpopulated)
> @@ -653,15 +649,16 @@ static int vmw_ttm_populate(struct ttm_tt *ttm)
> if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
> size_t size =
> ttm_round_pot(ttm->num_pages * sizeof(dma_addr_t));
> - ret = ttm_mem_global_alloc(glob, size, &ctx);
> + ret = ttm_mem_global_alloc(glob, size, ctx);
> if (unlikely(ret != 0))
> return ret;
>
> - ret = ttm_dma_populate(&vmw_tt->dma_ttm, dev_priv->dev->dev);
> + ret = ttm_dma_populate(&vmw_tt->dma_ttm, dev_priv->dev->dev,
> + ctx);
> if (unlikely(ret != 0))
> ttm_mem_global_free(glob, size);
> } else
> - ret = ttm_pool_populate(ttm);
> + ret = ttm_pool_populate(ttm, ctx);
>
> return ret;
> }
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
> index b17f08f..736ca47 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
> @@ -240,6 +240,10 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,
> unsigned long offset;
> unsigned long bo_size;
> struct vmw_otable *otables = batch->otables;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> SVGAOTableType i;
> int ret;
>
> @@ -264,7 +268,7 @@ static int vmw_otable_batch_setup(struct vmw_private *dev_priv,
>
> ret = ttm_bo_reserve(batch->otable_bo, false, true, NULL);
> BUG_ON(ret != 0);
> - ret = vmw_bo_driver.ttm_tt_populate(batch->otable_bo->ttm);
> + ret = vmw_bo_driver.ttm_tt_populate(batch->otable_bo->ttm, &ctx);
> if (unlikely(ret != 0))
> goto out_unreserve;
> ret = vmw_bo_map_dma(batch->otable_bo);
> @@ -430,6 +434,11 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv,
> struct vmw_mob *mob)
> {
> int ret;
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false
> + };
> +
> BUG_ON(mob->pt_bo != NULL);
>
> ret = ttm_bo_create(&dev_priv->bdev, mob->num_pages * PAGE_SIZE,
> @@ -442,7 +451,7 @@ static int vmw_mob_pt_populate(struct vmw_private *dev_priv,
> ret = ttm_bo_reserve(mob->pt_bo, false, true, NULL);
>
> BUG_ON(ret != 0);
> - ret = vmw_bo_driver.ttm_tt_populate(mob->pt_bo->ttm);
> + ret = vmw_bo_driver.ttm_tt_populate(mob->pt_bo->ttm, &ctx);
> if (unlikely(ret != 0))
> goto out_unreserve;
> ret = vmw_bo_map_dma(mob->pt_bo);
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 934fecf..84860ec 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -352,7 +352,8 @@ struct ttm_bo_driver {
> * Returns:
> * -ENOMEM: Out of memory.
> */
> - int (*ttm_tt_populate)(struct ttm_tt *ttm);
> + int (*ttm_tt_populate)(struct ttm_tt *ttm,
> + struct ttm_operation_ctx *ctx);
>
> /**
> * ttm_tt_unpopulate
> @@ -1077,7 +1078,7 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
> struct agp_bridge_data *bridge,
> unsigned long size, uint32_t page_flags,
> struct page *dummy_read_page);
> -int ttm_agp_tt_populate(struct ttm_tt *ttm);
> +int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
> void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
> #endif
>
> diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
> index 5938113..f8395dd 100644
> --- a/include/drm/ttm/ttm_page_alloc.h
> +++ b/include/drm/ttm/ttm_page_alloc.h
> @@ -47,7 +47,7 @@ void ttm_page_alloc_fini(void);
> *
> * Add backing pages to all of @ttm
> */
> -int ttm_pool_populate(struct ttm_tt *ttm);
> +int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
>
> /**
> * ttm_pool_unpopulate:
> @@ -61,7 +61,8 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);
> /**
> * Populates and DMA maps pages to fullfil a ttm_dma_populate() request
> */
> -int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt);
> +int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
> + struct ttm_operation_ctx *ctx);
>
> /**
> * Unpopulates and DMA unmaps pages as part of a
> @@ -89,7 +90,8 @@ void ttm_dma_page_alloc_fini(void);
> */
> int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
>
> -int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
> +int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
> + struct ttm_operation_ctx *ctx);
> void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
>
> #else
> @@ -106,7 +108,8 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
> return 0;
> }
> static inline int ttm_dma_populate(struct ttm_dma_tt *ttm_dma,
> - struct device *dev)
> + struct device *dev,
> + struct ttm_operation_ctx *ctx)
> {
> return -ENOMEM;
> }
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 5/7] drm/ttm: use an operation ctx for ttm_tt_bind
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-12-20 10:34 ` [PATCH 2/7] drm/ttm: use an operation ctx for ttm_mem_global_alloc Roger He
2017-12-20 10:34 ` [PATCH 4/7] drm/ttm: use an operation ctx for ttm_tt_populate in ttm_bo_driver Roger He
@ 2017-12-20 10:34 ` Roger He
2017-12-20 10:35 ` [PATCH 7/7] drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs Roger He
` (2 subsequent siblings)
5 siblings, 0 replies; 22+ messages in thread
From: Roger He @ 2017-12-20 10:34 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Cc: Roger He
Change-Id: I42a7df8c50e1ce3b527ee9cb78809f8e58136f07
Signed-off-by: Roger He <Hongbo.He@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +-
drivers/gpu/drm/radeon/radeon_ttm.c | 2 +-
drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
drivers/gpu/drm/ttm/ttm_tt.c | 9 +++------
include/drm/ttm/ttm_bo_driver.h | 3 ++-
7 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 52aab9d..ed235b7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -497,7 +497,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
goto out_cleanup;
}
- r = ttm_tt_bind(bo->ttm, &tmp_mem);
+ r = ttm_tt_bind(bo->ttm, &tmp_mem, ctx);
if (unlikely(r)) {
goto out_cleanup;
}
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index b141c27..a83ba6a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1218,7 +1218,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
if (ret)
return ret;
- ret = ttm_tt_bind(bo->ttm, &tmp_reg);
+ ret = ttm_tt_bind(bo->ttm, &tmp_reg, &ctx);
if (ret)
goto out;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 634fc6f..0f6fdc2 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -339,7 +339,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
goto out_cleanup;
}
- r = ttm_tt_bind(bo->ttm, &tmp_mem);
+ r = ttm_tt_bind(bo->ttm, &tmp_mem, &ctx);
if (unlikely(r)) {
goto out_cleanup;
}
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index c59f572..e7595b4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -300,7 +300,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
goto out_err;
if (mem->mem_type != TTM_PL_SYSTEM) {
- ret = ttm_tt_bind(bo->ttm, mem);
+ ret = ttm_tt_bind(bo->ttm, mem, ctx);
if (ret)
goto out_err;
}
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index b7eb507..153de1b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -73,7 +73,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
return ret;
if (new_mem->mem_type != TTM_PL_SYSTEM) {
- ret = ttm_tt_bind(ttm, new_mem);
+ ret = ttm_tt_bind(ttm, new_mem, ctx);
if (unlikely(ret != 0))
return ret;
}
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index b48d7a0..5a046a3 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -261,12 +261,9 @@ void ttm_tt_unbind(struct ttm_tt *ttm)
}
}
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+ struct ttm_operation_ctx *ctx)
{
- struct ttm_operation_ctx ctx = {
- .interruptible = false,
- .no_wait_gpu = false
- };
int ret = 0;
if (!ttm)
@@ -275,7 +272,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
if (ttm->state == tt_bound)
return 0;
- ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
+ ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
if (ret)
return ret;
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 84860ec..94064b1 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -650,7 +650,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
*
* Bind the pages of @ttm to an aperture location identified by @bo_mem
*/
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
+int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
+ struct ttm_operation_ctx *ctx);
/**
* ttm_ttm_destroy:
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 7/7] drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
` (2 preceding siblings ...)
2017-12-20 10:34 ` [PATCH 5/7] drm/ttm: use an operation ctx for ttm_tt_bind Roger He
@ 2017-12-20 10:35 ` Roger He
[not found] ` <1513766101-15993-7-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-12-20 13:29 ` [PATCH 1/7] drm/ttm: call ttm_bo_swapout directly when ttm shrink Christian König
2017-12-21 7:34 ` Thomas Hellstrom
5 siblings, 1 reply; 22+ messages in thread
From: Roger He @ 2017-12-20 10:35 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Cc: Roger He
Change-Id: I1e87954564f38ad298bf6e4ff88c9f26f291a62d
Signed-off-by: Roger He <Hongbo.He@amd.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++----
drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++----
include/drm/ttm/ttm_bo_api.h | 3 ++-
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 313925c..ecb8916 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1686,18 +1686,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
* A buffer object shrink method that tries to swap out the first
* buffer object on the bo_global::swap_lru list.
*/
-int ttm_bo_swapout(struct ttm_bo_global *glob)
+int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
{
struct ttm_buffer_object *bo;
int ret = -EBUSY;
+ bool locked;
unsigned i;
spin_lock(&glob->lru_lock);
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
list_for_each_entry(bo, &glob->swap_lru[i], swap) {
- ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY;
- if (!ret)
+ if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) {
+ ret = 0;
break;
+ }
}
if (!ret)
break;
@@ -1773,7 +1775,12 @@ EXPORT_SYMBOL(ttm_bo_swapout);
void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
{
- while (ttm_bo_swapout(bdev->glob) == 0)
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
+
+ while (ttm_bo_swapout(bdev->glob, &ctx) == 0)
;
}
EXPORT_SYMBOL(ttm_bo_swapout_all);
diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index 8df0755..8817b86 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob,
*/
static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
- uint64_t extra)
+ uint64_t extra, struct ttm_operation_ctx *ctx)
{
int ret;
@@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
spin_unlock(&glob->lock);
- ret = ttm_bo_swapout(glob->bo_glob);
+ ret = ttm_bo_swapout(glob->bo_glob, ctx);
spin_lock(&glob->lock);
if (unlikely(ret != 0))
break;
@@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
static void ttm_shrink_work(struct work_struct *work)
{
+ struct ttm_operation_ctx ctx = {
+ .interruptible = false,
+ .no_wait_gpu = false
+ };
struct ttm_mem_global *glob =
container_of(work, struct ttm_mem_global, work);
- ttm_shrink(glob, true, 0ULL);
+ ttm_shrink(glob, true, 0ULL, &ctx);
}
static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
@@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob,
return -ENOMEM;
if (unlikely(count-- == 0))
return -ENOMEM;
- ttm_shrink(glob, false, memory + (memory >> 2) + 16);
+ ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx);
}
return 0;
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 24a8db7..f1c74c2 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
const char __user *wbuf, char __user *rbuf,
size_t count, loff_t *f_pos, bool write);
-int ttm_bo_swapout(struct ttm_bo_global *glob);
+int ttm_bo_swapout(struct ttm_bo_global *glob,
+ struct ttm_operation_ctx *ctx);
void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
#endif
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 1/7] drm/ttm: call ttm_bo_swapout directly when ttm shrink
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
` (3 preceding siblings ...)
2017-12-20 10:35 ` [PATCH 7/7] drm/ttm: enable swapout of per VM BOs during allocation and allows reaping of deleted BOs Roger He
@ 2017-12-20 13:29 ` Christian König
2017-12-21 7:34 ` Thomas Hellstrom
5 siblings, 0 replies; 22+ messages in thread
From: Christian König @ 2017-12-20 13:29 UTC (permalink / raw)
To: Roger He, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Am 20.12.2017 um 11:34 schrieb Roger He:
> then remove superfluous functions
We need a better commit message. Something like:
Remove the extra indirection, cause we have only one implementation anyway.
>
> Change-Id: Iea020f0e30a239e0265e7a1500168c7d7f819bd9
> Signed-off-by: Roger He <Hongbo.He@amd.com>
With the commit message fixed Reviewed-by: Christian König
<christian.koenig@amd.com>.
Regards,
Christian.
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 21 +++---------
> drivers/gpu/drm/ttm/ttm_memory.c | 12 ++-----
> include/drm/ttm/ttm_bo_api.h | 1 +
> include/drm/ttm/ttm_bo_driver.h | 1 -
> include/drm/ttm/ttm_memory.h | 69 +---------------------------------------
> 5 files changed, 9 insertions(+), 95 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 60bb5c1..fa57aa8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -42,7 +42,6 @@
> #include <linux/atomic.h>
> #include <linux/reservation.h>
>
> -static int ttm_bo_swapout(struct ttm_mem_shrink *shrink);
> static void ttm_bo_global_kobj_release(struct kobject *kobj);
>
> static struct attribute ttm_bo_count = {
> @@ -1454,7 +1453,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)
> struct ttm_bo_global *glob =
> container_of(kobj, struct ttm_bo_global, kobj);
>
> - ttm_mem_unregister_shrink(glob->mem_glob, &glob->shrink);
> __free_page(glob->dummy_read_page);
> kfree(glob);
> }
> @@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> mutex_init(&glob->device_list_mutex);
> spin_lock_init(&glob->lru_lock);
> glob->mem_glob = bo_ref->mem_glob;
> + glob->mem_glob->bo_glob = glob;
> glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
>
> if (unlikely(glob->dummy_read_page == NULL)) {
> @@ -1489,14 +1488,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
> INIT_LIST_HEAD(&glob->swap_lru[i]);
> INIT_LIST_HEAD(&glob->device_list);
> -
> - ttm_mem_init_shrink(&glob->shrink, ttm_bo_swapout);
> - ret = ttm_mem_register_shrink(glob->mem_glob, &glob->shrink);
> - if (unlikely(ret != 0)) {
> - pr_err("Could not register buffer object swapout\n");
> - goto out_no_shrink;
> - }
> -
> atomic_set(&glob->bo_count, 0);
>
> ret = kobject_init_and_add(
> @@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> if (unlikely(ret != 0))
> kobject_put(&glob->kobj);
> return ret;
> -out_no_shrink:
> - __free_page(glob->dummy_read_page);
> out_no_drp:
> kfree(glob);
> return ret;
> @@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
> * A buffer object shrink method that tries to swap out the first
> * buffer object on the bo_global::swap_lru list.
> */
> -
> -static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
> +int ttm_bo_swapout(struct ttm_bo_global *glob)
> {
> - struct ttm_bo_global *glob =
> - container_of(shrink, struct ttm_bo_global, shrink);
> struct ttm_buffer_object *bo;
> int ret = -EBUSY;
> unsigned i;
> @@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
> kref_put(&bo->list_kref, ttm_bo_release_list);
> return ret;
> }
> +EXPORT_SYMBOL(ttm_bo_swapout);
>
> void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
> {
> - while (ttm_bo_swapout(&bdev->glob->shrink) == 0)
> + while (ttm_bo_swapout(bdev->glob) == 0)
> ;
> }
> EXPORT_SYMBOL(ttm_bo_swapout_all);
> diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
> index e963749..9130bdf 100644
> --- a/drivers/gpu/drm/ttm/ttm_memory.c
> +++ b/drivers/gpu/drm/ttm/ttm_memory.c
> @@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
> uint64_t extra)
> {
> int ret;
> - struct ttm_mem_shrink *shrink;
>
> spin_lock(&glob->lock);
> - if (glob->shrink == NULL)
> - goto out;
>
> while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
> - shrink = glob->shrink;
> spin_unlock(&glob->lock);
> - ret = shrink->do_shrink(shrink);
> + ret = ttm_bo_swapout(glob->bo_glob);
> spin_lock(&glob->lock);
> if (unlikely(ret != 0))
> - goto out;
> + break;
> }
> -out:
> +
> spin_unlock(&glob->lock);
> }
>
> -
> -
> static void ttm_shrink_work(struct work_struct *work)
> {
> struct ttm_mem_global *glob =
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index c126330..24a8db7 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
> const char __user *wbuf, char __user *rbuf,
> size_t count, loff_t *f_pos, bool write);
>
> +int ttm_bo_swapout(struct ttm_bo_global *glob);
> void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
> int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
> #endif
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 5115718..934fecf 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -522,7 +522,6 @@ struct ttm_bo_global {
> struct kobject kobj;
> struct ttm_mem_global *mem_glob;
> struct page *dummy_read_page;
> - struct ttm_mem_shrink shrink;
> struct mutex device_list_mutex;
> spinlock_t lru_lock;
>
> diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
> index 2c1e359..85f3ad6 100644
> --- a/include/drm/ttm/ttm_memory.h
> +++ b/include/drm/ttm/ttm_memory.h
> @@ -37,20 +37,6 @@
> #include <linux/mm.h>
>
> /**
> - * struct ttm_mem_shrink - callback to shrink TTM memory usage.
> - *
> - * @do_shrink: The callback function.
> - *
> - * Arguments to the do_shrink functions are intended to be passed using
> - * inheritance. That is, the argument class derives from struct ttm_mem_shrink,
> - * and can be accessed using container_of().
> - */
> -
> -struct ttm_mem_shrink {
> - int (*do_shrink) (struct ttm_mem_shrink *);
> -};
> -
> -/**
> * struct ttm_mem_global - Global memory accounting structure.
> *
> * @shrink: A single callback to shrink TTM memory usage. Extend this
> @@ -76,7 +62,7 @@ struct ttm_mem_shrink {
> struct ttm_mem_zone;
> struct ttm_mem_global {
> struct kobject kobj;
> - struct ttm_mem_shrink *shrink;
> + struct ttm_bo_global *bo_glob;
> struct workqueue_struct *swap_queue;
> struct work_struct work;
> spinlock_t lock;
> @@ -90,59 +76,6 @@ struct ttm_mem_global {
> #endif
> };
>
> -/**
> - * ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object
> - *
> - * @shrink: The object to initialize.
> - * @func: The callback function.
> - */
> -
> -static inline void ttm_mem_init_shrink(struct ttm_mem_shrink *shrink,
> - int (*func) (struct ttm_mem_shrink *))
> -{
> - shrink->do_shrink = func;
> -}
> -
> -/**
> - * ttm_mem_register_shrink - register a struct ttm_mem_shrink object.
> - *
> - * @glob: The struct ttm_mem_global object to register with.
> - * @shrink: An initialized struct ttm_mem_shrink object to register.
> - *
> - * Returns:
> - * -EBUSY: There's already a callback registered. (May change).
> - */
> -
> -static inline int ttm_mem_register_shrink(struct ttm_mem_global *glob,
> - struct ttm_mem_shrink *shrink)
> -{
> - spin_lock(&glob->lock);
> - if (glob->shrink != NULL) {
> - spin_unlock(&glob->lock);
> - return -EBUSY;
> - }
> - glob->shrink = shrink;
> - spin_unlock(&glob->lock);
> - return 0;
> -}
> -
> -/**
> - * ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object.
> - *
> - * @glob: The struct ttm_mem_global object to unregister from.
> - * @shrink: A previously registert struct ttm_mem_shrink object.
> - *
> - */
> -
> -static inline void ttm_mem_unregister_shrink(struct ttm_mem_global *glob,
> - struct ttm_mem_shrink *shrink)
> -{
> - spin_lock(&glob->lock);
> - BUG_ON(glob->shrink != shrink);
> - glob->shrink = NULL;
> - spin_unlock(&glob->lock);
> -}
> -
> extern int ttm_mem_global_init(struct ttm_mem_global *glob);
> extern void ttm_mem_global_release(struct ttm_mem_global *glob);
> extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 1/7] drm/ttm: call ttm_bo_swapout directly when ttm shrink
[not found] ` <1513766101-15993-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
` (4 preceding siblings ...)
2017-12-20 13:29 ` [PATCH 1/7] drm/ttm: call ttm_bo_swapout directly when ttm shrink Christian König
@ 2017-12-21 7:34 ` Thomas Hellstrom
[not found] ` <b0f51ff0-950e-bbe0-0032-e0e714d94350-4+hqylr40dJg9hUCZPvPmw@public.gmane.org>
5 siblings, 1 reply; 22+ messages in thread
From: Thomas Hellstrom @ 2017-12-21 7:34 UTC (permalink / raw)
To: Roger He, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Roger,
5 out of 7 patches in this series are completely lacking a commit log
message, and thats not OK. Really.
https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#describe-your-changes
I'll review these, but IIRC the no_wait in the memory accounting code is
different in that it doesn't allow sleeping,
whereas in the bo code we had originally had no_wait_gpu and also
no_wait. (IIRC Maarten or Jerome removed the latter due to lack of
users.) Seems like these patches confuse the to. At the very least that
requires some form of motivation.
Also I wonder what testing is being performed on these changes prior to
submission?
We have pretty high number of critical deployments out there, that we
need to support.
/Thomas
On 12/20/2017 11:34 AM, Roger He wrote:
> then remove superfluous functions
>
> Change-Id: Iea020f0e30a239e0265e7a1500168c7d7f819bd9
> Signed-off-by: Roger He <Hongbo.He@amd.com>
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 21 +++---------
> drivers/gpu/drm/ttm/ttm_memory.c | 12 ++-----
> include/drm/ttm/ttm_bo_api.h | 1 +
> include/drm/ttm/ttm_bo_driver.h | 1 -
> include/drm/ttm/ttm_memory.h | 69 +---------------------------------------
> 5 files changed, 9 insertions(+), 95 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 60bb5c1..fa57aa8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -42,7 +42,6 @@
> #include <linux/atomic.h>
> #include <linux/reservation.h>
>
> -static int ttm_bo_swapout(struct ttm_mem_shrink *shrink);
> static void ttm_bo_global_kobj_release(struct kobject *kobj);
>
> static struct attribute ttm_bo_count = {
> @@ -1454,7 +1453,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)
> struct ttm_bo_global *glob =
> container_of(kobj, struct ttm_bo_global, kobj);
>
> - ttm_mem_unregister_shrink(glob->mem_glob, &glob->shrink);
> __free_page(glob->dummy_read_page);
> kfree(glob);
> }
> @@ -1479,6 +1477,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> mutex_init(&glob->device_list_mutex);
> spin_lock_init(&glob->lru_lock);
> glob->mem_glob = bo_ref->mem_glob;
> + glob->mem_glob->bo_glob = glob;
> glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
>
> if (unlikely(glob->dummy_read_page == NULL)) {
> @@ -1489,14 +1488,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
> INIT_LIST_HEAD(&glob->swap_lru[i]);
> INIT_LIST_HEAD(&glob->device_list);
> -
> - ttm_mem_init_shrink(&glob->shrink, ttm_bo_swapout);
> - ret = ttm_mem_register_shrink(glob->mem_glob, &glob->shrink);
> - if (unlikely(ret != 0)) {
> - pr_err("Could not register buffer object swapout\n");
> - goto out_no_shrink;
> - }
> -
> atomic_set(&glob->bo_count, 0);
>
> ret = kobject_init_and_add(
> @@ -1504,8 +1495,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref)
> if (unlikely(ret != 0))
> kobject_put(&glob->kobj);
> return ret;
> -out_no_shrink:
> - __free_page(glob->dummy_read_page);
> out_no_drp:
> kfree(glob);
> return ret;
> @@ -1688,11 +1677,8 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release);
> * A buffer object shrink method that tries to swap out the first
> * buffer object on the bo_global::swap_lru list.
> */
> -
> -static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
> +int ttm_bo_swapout(struct ttm_bo_global *glob)
> {
> - struct ttm_bo_global *glob =
> - container_of(shrink, struct ttm_bo_global, shrink);
> struct ttm_buffer_object *bo;
> int ret = -EBUSY;
> unsigned i;
> @@ -1774,10 +1760,11 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
> kref_put(&bo->list_kref, ttm_bo_release_list);
> return ret;
> }
> +EXPORT_SYMBOL(ttm_bo_swapout);
>
> void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
> {
> - while (ttm_bo_swapout(&bdev->glob->shrink) == 0)
> + while (ttm_bo_swapout(bdev->glob) == 0)
> ;
> }
> EXPORT_SYMBOL(ttm_bo_swapout_all);
> diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
> index e963749..9130bdf 100644
> --- a/drivers/gpu/drm/ttm/ttm_memory.c
> +++ b/drivers/gpu/drm/ttm/ttm_memory.c
> @@ -214,26 +214,20 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
> uint64_t extra)
> {
> int ret;
> - struct ttm_mem_shrink *shrink;
>
> spin_lock(&glob->lock);
> - if (glob->shrink == NULL)
> - goto out;
>
> while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
> - shrink = glob->shrink;
> spin_unlock(&glob->lock);
> - ret = shrink->do_shrink(shrink);
> + ret = ttm_bo_swapout(glob->bo_glob);
> spin_lock(&glob->lock);
> if (unlikely(ret != 0))
> - goto out;
> + break;
> }
> -out:
> +
> spin_unlock(&glob->lock);
> }
>
> -
> -
> static void ttm_shrink_work(struct work_struct *work)
> {
> struct ttm_mem_global *glob =
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index c126330..24a8db7 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -752,6 +752,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
> const char __user *wbuf, char __user *rbuf,
> size_t count, loff_t *f_pos, bool write);
>
> +int ttm_bo_swapout(struct ttm_bo_global *glob);
> void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
> int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
> #endif
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 5115718..934fecf 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -522,7 +522,6 @@ struct ttm_bo_global {
> struct kobject kobj;
> struct ttm_mem_global *mem_glob;
> struct page *dummy_read_page;
> - struct ttm_mem_shrink shrink;
> struct mutex device_list_mutex;
> spinlock_t lru_lock;
>
> diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
> index 2c1e359..85f3ad6 100644
> --- a/include/drm/ttm/ttm_memory.h
> +++ b/include/drm/ttm/ttm_memory.h
> @@ -37,20 +37,6 @@
> #include <linux/mm.h>
>
> /**
> - * struct ttm_mem_shrink - callback to shrink TTM memory usage.
> - *
> - * @do_shrink: The callback function.
> - *
> - * Arguments to the do_shrink functions are intended to be passed using
> - * inheritance. That is, the argument class derives from struct ttm_mem_shrink,
> - * and can be accessed using container_of().
> - */
> -
> -struct ttm_mem_shrink {
> - int (*do_shrink) (struct ttm_mem_shrink *);
> -};
> -
> -/**
> * struct ttm_mem_global - Global memory accounting structure.
> *
> * @shrink: A single callback to shrink TTM memory usage. Extend this
> @@ -76,7 +62,7 @@ struct ttm_mem_shrink {
> struct ttm_mem_zone;
> struct ttm_mem_global {
> struct kobject kobj;
> - struct ttm_mem_shrink *shrink;
> + struct ttm_bo_global *bo_glob;
> struct workqueue_struct *swap_queue;
> struct work_struct work;
> spinlock_t lock;
> @@ -90,59 +76,6 @@ struct ttm_mem_global {
> #endif
> };
>
> -/**
> - * ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object
> - *
> - * @shrink: The object to initialize.
> - * @func: The callback function.
> - */
> -
> -static inline void ttm_mem_init_shrink(struct ttm_mem_shrink *shrink,
> - int (*func) (struct ttm_mem_shrink *))
> -{
> - shrink->do_shrink = func;
> -}
> -
> -/**
> - * ttm_mem_register_shrink - register a struct ttm_mem_shrink object.
> - *
> - * @glob: The struct ttm_mem_global object to register with.
> - * @shrink: An initialized struct ttm_mem_shrink object to register.
> - *
> - * Returns:
> - * -EBUSY: There's already a callback registered. (May change).
> - */
> -
> -static inline int ttm_mem_register_shrink(struct ttm_mem_global *glob,
> - struct ttm_mem_shrink *shrink)
> -{
> - spin_lock(&glob->lock);
> - if (glob->shrink != NULL) {
> - spin_unlock(&glob->lock);
> - return -EBUSY;
> - }
> - glob->shrink = shrink;
> - spin_unlock(&glob->lock);
> - return 0;
> -}
> -
> -/**
> - * ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object.
> - *
> - * @glob: The struct ttm_mem_global object to unregister from.
> - * @shrink: A previously registert struct ttm_mem_shrink object.
> - *
> - */
> -
> -static inline void ttm_mem_unregister_shrink(struct ttm_mem_global *glob,
> - struct ttm_mem_shrink *shrink)
> -{
> - spin_lock(&glob->lock);
> - BUG_ON(glob->shrink != shrink);
> - glob->shrink = NULL;
> - spin_unlock(&glob->lock);
> -}
> -
> extern int ttm_mem_global_init(struct ttm_mem_global *glob);
> extern void ttm_mem_global_release(struct ttm_mem_global *glob);
> extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 22+ messages in thread