dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: fix error handling if no BO can be swapped out
@ 2021-04-20 14:32 Shiwu Zhang
  2021-04-21 13:34 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Shiwu Zhang @ 2021-04-20 14:32 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig

In case that all pre-allocated BOs are busy, just continue to populate
BOs since likely half of system memory in total is still free.

Signed-off-by: Shiwu Zhang <shiwu.zhang@amd.com>
---
 drivers/gpu/drm/ttm/ttm_device.c | 4 ++--
 drivers/gpu/drm/ttm/ttm_tt.c     | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index 1f2024164d72..0200709db9be 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -133,7 +133,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 	struct ttm_resource_manager *man;
 	struct ttm_buffer_object *bo;
 	unsigned i, j;
-	int ret;
+	int ret=-EBUSY;
 
 	spin_lock(&bdev->lru_lock);
 	for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
@@ -161,7 +161,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 		}
 	}
 	spin_unlock(&bdev->lru_lock);
-	return 0;
+	return ret;
 }
 EXPORT_SYMBOL(ttm_device_swapout);
 
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 48c407cff112..4e1e06a04428 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -329,6 +329,8 @@ int ttm_tt_populate(struct ttm_device *bdev,
 	       ttm_dma32_pages_limit) {
 
 		ret = ttm_global_swapout(ctx, GFP_KERNEL);
+		if (ret == -EBUSY)
+			break;
 		if (ret < 0)
 			goto error;
 	}
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/ttm: fix error handling if no BO can be swapped out
  2021-04-20 14:32 [PATCH] drm/ttm: fix error handling if no BO can be swapped out Shiwu Zhang
@ 2021-04-21 13:34 ` Christian König
  2021-04-22  8:39   ` Zhang, Morris
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2021-04-21 13:34 UTC (permalink / raw)
  To: Shiwu Zhang, dri-devel



Am 20.04.21 um 16:32 schrieb Shiwu Zhang:
> In case that all pre-allocated BOs are busy, just continue to populate
> BOs since likely half of system memory in total is still free.
>
> Signed-off-by: Shiwu Zhang <shiwu.zhang@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_device.c | 4 ++--
>   drivers/gpu/drm/ttm/ttm_tt.c     | 2 ++
>   2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
> index 1f2024164d72..0200709db9be 100644
> --- a/drivers/gpu/drm/ttm/ttm_device.c
> +++ b/drivers/gpu/drm/ttm/ttm_device.c
> @@ -133,7 +133,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   	struct ttm_resource_manager *man;
>   	struct ttm_buffer_object *bo;
>   	unsigned i, j;
> -	int ret;
> +	int ret=-EBUSY;
>   
>   	spin_lock(&bdev->lru_lock);
>   	for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
> @@ -161,7 +161,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   		}
>   	}
>   	spin_unlock(&bdev->lru_lock);
> -	return 0;
> +	return ret;

The function should return the number of pages swapped out. Returning 0 
here is already perfectly ok.

>   }
>   EXPORT_SYMBOL(ttm_device_swapout);
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index 48c407cff112..4e1e06a04428 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -329,6 +329,8 @@ int ttm_tt_populate(struct ttm_device *bdev,
>   	       ttm_dma32_pages_limit) {
>   
>   		ret = ttm_global_swapout(ctx, GFP_KERNEL);
> +		if (ret == -EBUSY)
> +			break;
>   		if (ret < 0)
>   			goto error;

Here we should just have a check for ret == 0 instead of testing for -EBUSY.

Regards,
Christian.

>   	}

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] drm/ttm: fix error handling if no BO can be swapped out
  2021-04-21 13:34 ` Christian König
@ 2021-04-22  8:39   ` Zhang, Morris
  0 siblings, 0 replies; 3+ messages in thread
From: Zhang, Morris @ 2021-04-22  8:39 UTC (permalink / raw)
  To: Koenig, Christian, dri-devel

[AMD Official Use Only - Internal Distribution Only]

Hi Chris,

Yes. I'll rework the patch. Thanks for your comments.

--Brs,
Morris Zhang
MLSE Linux  ML SRDC
Ext. 25147

-----Original Message-----
From: Koenig, Christian <Christian.Koenig@amd.com> 
Sent: Wednesday, April 21, 2021 9:34 PM
To: Zhang, Morris <Shiwu.Zhang@amd.com>; dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/ttm: fix error handling if no BO can be swapped out



Am 20.04.21 um 16:32 schrieb Shiwu Zhang:
> In case that all pre-allocated BOs are busy, just continue to populate 
> BOs since likely half of system memory in total is still free.
>
> Signed-off-by: Shiwu Zhang <shiwu.zhang@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_device.c | 4 ++--
>   drivers/gpu/drm/ttm/ttm_tt.c     | 2 ++
>   2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_device.c 
> b/drivers/gpu/drm/ttm/ttm_device.c
> index 1f2024164d72..0200709db9be 100644
> --- a/drivers/gpu/drm/ttm/ttm_device.c
> +++ b/drivers/gpu/drm/ttm/ttm_device.c
> @@ -133,7 +133,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   	struct ttm_resource_manager *man;
>   	struct ttm_buffer_object *bo;
>   	unsigned i, j;
> -	int ret;
> +	int ret=-EBUSY;
>   
>   	spin_lock(&bdev->lru_lock);
>   	for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) { @@ -161,7 
> +161,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   		}
>   	}
>   	spin_unlock(&bdev->lru_lock);
> -	return 0;
> +	return ret;

The function should return the number of pages swapped out. Returning 0 here is already perfectly ok.

>   }
>   EXPORT_SYMBOL(ttm_device_swapout);
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c 
> b/drivers/gpu/drm/ttm/ttm_tt.c index 48c407cff112..4e1e06a04428 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -329,6 +329,8 @@ int ttm_tt_populate(struct ttm_device *bdev,
>   	       ttm_dma32_pages_limit) {
>   
>   		ret = ttm_global_swapout(ctx, GFP_KERNEL);
> +		if (ret == -EBUSY)
> +			break;
>   		if (ret < 0)
>   			goto error;

Here we should just have a check for ret == 0 instead of testing for -EBUSY.

Regards,
Christian.

>   	}
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-22  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 14:32 [PATCH] drm/ttm: fix error handling if no BO can be swapped out Shiwu Zhang
2021-04-21 13:34 ` Christian König
2021-04-22  8:39   ` Zhang, Morris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).