diff mbox series

[v3,8/8] drm/drm-file: Show finer-grained BO sizes in drm_show_memory_stats

Message ID 20230905184533.959171-9-adrian.larumbe@collabora.com (mailing list archive)
State Superseded
Headers show
Series Add fdinfo support to Panfrost | expand

Commit Message

Adrián Larumbe Sept. 5, 2023, 6:45 p.m. UTC
The current implementation will try to pick the highest available size
display unit as soon as the BO size exceeds that of the previous
multiplier.

By selecting a higher threshold, we could show more accurate size numbers.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/drm_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Boris Brezillon Sept. 6, 2023, 8:11 a.m. UTC | #1
On Tue,  5 Sep 2023 19:45:24 +0100
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> The current implementation will try to pick the highest available size
> display unit as soon as the BO size exceeds that of the previous
> multiplier.
> 
> By selecting a higher threshold, we could show more accurate size numbers.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/drm_file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index 762965e3d503..0b5fbd493e05 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -879,7 +879,7 @@ static void print_size(struct drm_printer *p, const char *stat,
>  	unsigned u;
>  
>  	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
> -		if (sz < SZ_1K)
> +		if (sz < (SZ_1K * 10000))
>  			break;

This threshold looks a bit random. How about picking a unit that allows
us to print the size with no precision loss?

	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
		if (sz & (SZ_1K - 1))
			break;
	}


>  		sz = div_u64(sz, SZ_1K);
>  	}
Adrián Larumbe Sept. 9, 2023, 4:55 p.m. UTC | #2
On 06.09.2023 10:11, Boris Brezillon wrote:
>On Tue,  5 Sep 2023 19:45:24 +0100
>Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
>
>> The current implementation will try to pick the highest available size
>> display unit as soon as the BO size exceeds that of the previous
>> multiplier.
>> 
>> By selecting a higher threshold, we could show more accurate size numbers.
>> 
>> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
>> ---
>>  drivers/gpu/drm/drm_file.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
>> index 762965e3d503..0b5fbd493e05 100644
>> --- a/drivers/gpu/drm/drm_file.c
>> +++ b/drivers/gpu/drm/drm_file.c
>> @@ -879,7 +879,7 @@ static void print_size(struct drm_printer *p, const char *stat,
>>  	unsigned u;
>>  
>>  	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
>> -		if (sz < SZ_1K)
>> +		if (sz < (SZ_1K * 10000))
>>  			break;
>
>This threshold looks a bit random. How about picking a unit that allows
>us to print the size with no precision loss?
>
>	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
>		if (sz & (SZ_1K - 1))
>			break;
>	}

In this case I picked up on Rob Clark's suggestion of choosing a hard limit of
perhaps 10k or 100k times the current unit before moving on to the next one.
While this approach guarantees that we don't lose precision, it would render a
tad too long a number in KiB for BO's that aren't a multiple of a MiB.

>>  		sz = div_u64(sz, SZ_1K);
>>  	}
Boris Brezillon Sept. 11, 2023, 7:48 a.m. UTC | #3
On Sat, 9 Sep 2023 17:55:17 +0100
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> On 06.09.2023 10:11, Boris Brezillon wrote:
> >On Tue,  5 Sep 2023 19:45:24 +0100
> >Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> >  
> >> The current implementation will try to pick the highest available size
> >> display unit as soon as the BO size exceeds that of the previous
> >> multiplier.
> >> 
> >> By selecting a higher threshold, we could show more accurate size numbers.
> >> 
> >> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> >> ---
> >>  drivers/gpu/drm/drm_file.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> >> index 762965e3d503..0b5fbd493e05 100644
> >> --- a/drivers/gpu/drm/drm_file.c
> >> +++ b/drivers/gpu/drm/drm_file.c
> >> @@ -879,7 +879,7 @@ static void print_size(struct drm_printer *p, const char *stat,
> >>  	unsigned u;
> >>  
> >>  	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
> >> -		if (sz < SZ_1K)
> >> +		if (sz < (SZ_1K * 10000))
> >>  			break;  
> >
> >This threshold looks a bit random. How about picking a unit that allows
> >us to print the size with no precision loss?
> >
> >	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
> >		if (sz & (SZ_1K - 1))
> >			break;
> >	}  
> 
> In this case I picked up on Rob Clark's suggestion of choosing a hard limit of
> perhaps 10k or 100k times the current unit before moving on to the next one.
> While this approach guarantees that we don't lose precision, it would render a
> tad too long a number in KiB for BO's that aren't a multiple of a MiB.

I'd expect big BOs to have their size naturally aligned on something
bigger than a 4k page anyway, so I don't expect multi-MB/GB buffers to
be using the KiB unit in practice. It's just that it's weird to have,
8MiB printed as 8192KiB when we could have used the upper unit,
because it's naturally aligned on a megabyte.

Maybe we should have something like that instead:

	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
		if ((sz & (SZ_1K - 1)) &&
		    sz < UPPER_UNIT_THRESHOLD * SZ_1K)
			break;

		sz = div_u64(sz, SZ_1K);
	}
> 
> >>  		sz = div_u64(sz, SZ_1K);
> >>  	}
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index 762965e3d503..0b5fbd493e05 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -879,7 +879,7 @@  static void print_size(struct drm_printer *p, const char *stat,
 	unsigned u;
 
 	for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
-		if (sz < SZ_1K)
+		if (sz < (SZ_1K * 10000))
 			break;
 		sz = div_u64(sz, SZ_1K);
 	}