* [PATCH] drm/amdgpu: simplify allocation of scratch regs
@ 2017-01-16 20:56 Nils Wallménius
[not found] ` <20170116205648.2570-1-nils.wallmenius-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Nils Wallménius @ 2017-01-16 20:56 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Nils Wallménius
The scratch regs are sequential so there's no need to keep
them in an array, we can just return the index of the first
free register + the base register. Also change the array
of bools for keeping track of the free regs to a bitfield.
Signed-off-by: Nils Wallménius <nils.wallmenius@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 +--
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++--------------
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 7 +------
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 7 +------
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 7 +------
5 files changed, 11 insertions(+), 34 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index ffeda245..9531480 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -794,8 +794,7 @@ struct amdgpu_kiq {
struct amdgpu_scratch {
unsigned num_reg;
uint32_t reg_base;
- bool free[32];
- uint32_t reg[32];
+ uint32_t free_mask;
};
/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 01a42b6..1994335 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
{
int i;
- for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
- if (adev->gfx.scratch.free[i]) {
- adev->gfx.scratch.free[i] = false;
- *reg = adev->gfx.scratch.reg[i];
- return 0;
- }
+ i = ffs(adev->gfx.scratch.free_mask);
+ if (i != 0 && i <= adev->gfx.scratch.num_reg) {
+ i--;
+ adev->gfx.scratch.free_mask &= ~(1u << i);
+ *reg = adev->gfx.scratch.reg_base + i;
+ return 0;
}
return -EINVAL;
}
@@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
*/
void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
{
- int i;
-
- for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
- if (adev->gfx.scratch.reg[i] == reg) {
- adev->gfx.scratch.free[i] = true;
- return;
- }
- }
+ adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
}
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
index b323f5e..e013243 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
@@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
static void gfx_v6_0_scratch_init(struct amdgpu_device *adev)
{
- int i;
-
adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
- for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
- adev->gfx.scratch.free[i] = true;
- adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
- }
+ adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
}
static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index c4e1401..cfed6db 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
*/
static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
{
- int i;
-
adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
- for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
- adev->gfx.scratch.free[i] = true;
- adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
- }
+ adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
}
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index c8c45ba..69543d4 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
{
- int i;
-
adev->gfx.scratch.num_reg = 7;
adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
- for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
- adev->gfx.scratch.free[i] = true;
- adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
- }
+ adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
}
static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
--
2.10.2
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu: simplify allocation of scratch regs
[not found] ` <20170116205648.2570-1-nils.wallmenius-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-01-17 10:18 ` Christian König
[not found] ` <c3b5469d-be9d-f4a3-d158-8335b9a0f63a-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2017-01-17 10:18 UTC (permalink / raw)
To: Nils Wallménius, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Am 16.01.2017 um 21:56 schrieb Nils Wallménius:
> The scratch regs are sequential so there's no need to keep
> them in an array, we can just return the index of the first
> free register + the base register. Also change the array
> of bools for keeping track of the free regs to a bitfield.
>
> Signed-off-by: Nils Wallménius <nils.wallmenius@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>.
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 +--
> drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++--------------
> drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 7 +------
> drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 7 +------
> drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 7 +------
> 5 files changed, 11 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index ffeda245..9531480 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -794,8 +794,7 @@ struct amdgpu_kiq {
> struct amdgpu_scratch {
> unsigned num_reg;
> uint32_t reg_base;
> - bool free[32];
> - uint32_t reg[32];
> + uint32_t free_mask;
> };
>
> /*
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> index 01a42b6..1994335 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> @@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
> {
> int i;
>
> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
> - if (adev->gfx.scratch.free[i]) {
> - adev->gfx.scratch.free[i] = false;
> - *reg = adev->gfx.scratch.reg[i];
> - return 0;
> - }
> + i = ffs(adev->gfx.scratch.free_mask);
> + if (i != 0 && i <= adev->gfx.scratch.num_reg) {
> + i--;
> + adev->gfx.scratch.free_mask &= ~(1u << i);
> + *reg = adev->gfx.scratch.reg_base + i;
> + return 0;
> }
> return -EINVAL;
> }
> @@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
> */
> void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
> {
> - int i;
> -
> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
> - if (adev->gfx.scratch.reg[i] == reg) {
> - adev->gfx.scratch.free[i] = true;
> - return;
> - }
> - }
> + adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
> }
>
> /**
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> index b323f5e..e013243 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> @@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
>
> static void gfx_v6_0_scratch_init(struct amdgpu_device *adev)
> {
> - int i;
> -
> adev->gfx.scratch.num_reg = 7;
> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
> - adev->gfx.scratch.free[i] = true;
> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
> - }
> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
> }
>
> static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> index c4e1401..cfed6db 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> @@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
> */
> static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
> {
> - int i;
> -
> adev->gfx.scratch.num_reg = 7;
> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
> - adev->gfx.scratch.free[i] = true;
> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
> - }
> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
> }
>
> /**
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> index c8c45ba..69543d4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> @@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
>
> static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
> {
> - int i;
> -
> adev->gfx.scratch.num_reg = 7;
> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
> - adev->gfx.scratch.free[i] = true;
> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
> - }
> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
> }
>
> static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu: simplify allocation of scratch regs
[not found] ` <c3b5469d-be9d-f4a3-d158-8335b9a0f63a-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
@ 2017-01-17 19:50 ` Alex Deucher
0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2017-01-17 19:50 UTC (permalink / raw)
To: Christian König; +Cc: Nils Wallménius, amd-gfx list
On Tue, Jan 17, 2017 at 5:18 AM, Christian König
<deathsimple@vodafone.de> wrote:
> Am 16.01.2017 um 21:56 schrieb Nils Wallménius:
>>
>> The scratch regs are sequential so there's no need to keep
>> them in an array, we can just return the index of the first
>> free register + the base register. Also change the array
>> of bools for keeping track of the free regs to a bitfield.
>>
>> Signed-off-by: Nils Wallménius <nils.wallmenius@gmail.com>
>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>.
Applied. thanks!
Alex
>
>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 +--
>> drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++--------------
>> drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 7 +------
>> drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 7 +------
>> drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 7 +------
>> 5 files changed, 11 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index ffeda245..9531480 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -794,8 +794,7 @@ struct amdgpu_kiq {
>> struct amdgpu_scratch {
>> unsigned num_reg;
>> uint32_t reg_base;
>> - bool free[32];
>> - uint32_t reg[32];
>> + uint32_t free_mask;
>> };
>> /*
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
>> index 01a42b6..1994335 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
>> @@ -42,12 +42,12 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev,
>> uint32_t *reg)
>> {
>> int i;
>> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
>> - if (adev->gfx.scratch.free[i]) {
>> - adev->gfx.scratch.free[i] = false;
>> - *reg = adev->gfx.scratch.reg[i];
>> - return 0;
>> - }
>> + i = ffs(adev->gfx.scratch.free_mask);
>> + if (i != 0 && i <= adev->gfx.scratch.num_reg) {
>> + i--;
>> + adev->gfx.scratch.free_mask &= ~(1u << i);
>> + *reg = adev->gfx.scratch.reg_base + i;
>> + return 0;
>> }
>> return -EINVAL;
>> }
>> @@ -62,14 +62,7 @@ int amdgpu_gfx_scratch_get(struct amdgpu_device *adev,
>> uint32_t *reg)
>> */
>> void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
>> {
>> - int i;
>> -
>> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
>> - if (adev->gfx.scratch.reg[i] == reg) {
>> - adev->gfx.scratch.free[i] = true;
>> - return;
>> - }
>> - }
>> + adev->gfx.scratch.free_mask |= 1u << (reg -
>> adev->gfx.scratch.reg_base);
>> }
>> /**
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
>> index b323f5e..e013243 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
>> @@ -1794,14 +1794,9 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device
>> *adev)
>> static void gfx_v6_0_scratch_init(struct amdgpu_device *adev)
>> {
>> - int i;
>> -
>> adev->gfx.scratch.num_reg = 7;
>> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
>> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
>> - adev->gfx.scratch.free[i] = true;
>> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
>> - }
>> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) -
>> 1;
>> }
>> static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
>> index c4e1401..cfed6db 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
>> @@ -2003,14 +2003,9 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device
>> *adev)
>> */
>> static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
>> {
>> - int i;
>> -
>> adev->gfx.scratch.num_reg = 7;
>> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
>> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
>> - adev->gfx.scratch.free[i] = true;
>> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
>> - }
>> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) -
>> 1;
>> }
>> /**
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> index c8c45ba..69543d4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
>> @@ -749,14 +749,9 @@ static void gfx_v8_0_init_golden_registers(struct
>> amdgpu_device *adev)
>> static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
>> {
>> - int i;
>> -
>> adev->gfx.scratch.num_reg = 7;
>> adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
>> - for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
>> - adev->gfx.scratch.free[i] = true;
>> - adev->gfx.scratch.reg[i] = adev->gfx.scratch.reg_base + i;
>> - }
>> + adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) -
>> 1;
>> }
>> static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
>
>
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-17 19:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-16 20:56 [PATCH] drm/amdgpu: simplify allocation of scratch regs Nils Wallménius
[not found] ` <20170116205648.2570-1-nils.wallmenius-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-17 10:18 ` Christian König
[not found] ` <c3b5469d-be9d-f4a3-d158-8335b9a0f63a-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-17 19:50 ` Alex Deucher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox