diff mbox

[v2,1/2] dmaengine: stm32-mdma: align TLEN and buffer length on burst

Message ID 1523457879-9869-2-git-send-email-pierre-yves.mordret@st.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pierre Yves MORDRET April 11, 2018, 2:44 p.m. UTC
Both buffer Transfer Length (TLEN if any) and transfer size have to be
aligned on burst size (burst beats*bus width).

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
---
  Version history:
    v1:
       * Initial
    v2:
---
---
 drivers/dma/stm32-mdma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Robin Murphy April 11, 2018, 3:14 p.m. UTC | #1
On 11/04/18 15:44, Pierre-Yves MORDRET wrote:
> Both buffer Transfer Length (TLEN if any) and transfer size have to be
> aligned on burst size (burst beats*bus width).
> 
> Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
> ---
>    Version history:
>      v1:
>         * Initial
>      v2:
> ---
> ---
>   drivers/dma/stm32-mdma.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index daa1602..fbcffa2 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -413,7 +413,7 @@ static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst,
>   	u32 best_burst = max_burst;
>   	u32 burst_len = best_burst * width;
>   
> -	while ((burst_len > 0) && (tlen % burst_len)) {
> +	while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) {
>   		best_burst = best_burst >> 1;
>   		burst_len = best_burst * width;
>   	}

FWIW, doesn't that whole loop come down to just:

	burst_len = min(ffs(tlen | buf_len), max_burst * width);

?

Robin.
Pierre Yves MORDRET April 13, 2018, 9:45 a.m. UTC | #2
Hi Robin

On 04/11/2018 05:14 PM, Robin Murphy wrote:
> On 11/04/18 15:44, Pierre-Yves MORDRET wrote:
>> Both buffer Transfer Length (TLEN if any) and transfer size have to be
>> aligned on burst size (burst beats*bus width).
>>
>> Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
>> ---
>>    Version history:
>>      v1:
>>         * Initial
>>      v2:
>> ---
>> ---
>>   drivers/dma/stm32-mdma.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
>> index daa1602..fbcffa2 100644
>> --- a/drivers/dma/stm32-mdma.c
>> +++ b/drivers/dma/stm32-mdma.c
>> @@ -413,7 +413,7 @@ static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst,
>>   	u32 best_burst = max_burst;
>>   	u32 burst_len = best_burst * width;
>>   
>> -	while ((burst_len > 0) && (tlen % burst_len)) {
>> +	while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) {
>>   		best_burst = best_burst >> 1;
>>   		burst_len = best_burst * width;
>>   	}
> 
> FWIW, doesn't that whole loop come down to just:
> 
> 	burst_len = min(ffs(tlen | buf_len), max_burst * width);

No sure it ends as expected. or I miss something or don't understand this statement
I tried with "relevant value" : i.e. best_burst = 32, Tlen=128(default) and
buf_len = 64, width= 4. This statements gets me something wrong output => 7
instead of 16 * 4.
I doubt :)

> 
> ?
> 
> Robin.
>
Robin Murphy April 13, 2018, 11:09 a.m. UTC | #3
On 13/04/18 10:45, Pierre Yves MORDRET wrote:
> Hi Robin
> 
> On 04/11/2018 05:14 PM, Robin Murphy wrote:
>> On 11/04/18 15:44, Pierre-Yves MORDRET wrote:
>>> Both buffer Transfer Length (TLEN if any) and transfer size have to be
>>> aligned on burst size (burst beats*bus width).
>>>
>>> Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
>>> ---
>>>     Version history:
>>>       v1:
>>>          * Initial
>>>       v2:
>>> ---
>>> ---
>>>    drivers/dma/stm32-mdma.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
>>> index daa1602..fbcffa2 100644
>>> --- a/drivers/dma/stm32-mdma.c
>>> +++ b/drivers/dma/stm32-mdma.c
>>> @@ -413,7 +413,7 @@ static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst,
>>>    	u32 best_burst = max_burst;
>>>    	u32 burst_len = best_burst * width;
>>>    
>>> -	while ((burst_len > 0) && (tlen % burst_len)) {
>>> +	while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) {
>>>    		best_burst = best_burst >> 1;
>>>    		burst_len = best_burst * width;
>>>    	}
>>
>> FWIW, doesn't that whole loop come down to just:
>>
>> 	burst_len = min(ffs(tlen | buf_len), max_burst * width);
> 
> No sure it ends as expected. or I miss something or don't understand this statement
> I tried with "relevant value" : i.e. best_burst = 32, Tlen=128(default) and
> buf_len = 64, width= 4. This statements gets me something wrong output => 7
> instead of 16 * 4.
> I doubt :)

Heh, seems I confused myself halfway through and started thinking 
max_burst and width were the exponents x rather than the values 2^x...

A more representative guess should be:

	min(1 << __ffs(tlen | buf_len), max_burst * width);

but the general point I was trying to make is that a loop checking 
whether the bottom n bits of something are zero for different values of 
n is unnecessary when n can simply be calculated directly*.

Robin.


* in the case of this "just the lowest set bit" idiom there's also the 
shift-free ((x & (x - 1)) ^ x), but as well as being unreadable it's 
generally less efficient than (1 << __ffs(x)) for most modern ISAs.
Pierre Yves MORDRET April 13, 2018, 12:30 p.m. UTC | #4
On 04/13/2018 01:09 PM, Robin Murphy wrote:
> On 13/04/18 10:45, Pierre Yves MORDRET wrote:
>> Hi Robin
>>
>> On 04/11/2018 05:14 PM, Robin Murphy wrote:
>>> On 11/04/18 15:44, Pierre-Yves MORDRET wrote:
>>>> Both buffer Transfer Length (TLEN if any) and transfer size have to be
>>>> aligned on burst size (burst beats*bus width).
>>>>
>>>> Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
>>>> ---
>>>>     Version history:
>>>>       v1:
>>>>          * Initial
>>>>       v2:
>>>> ---
>>>> ---
>>>>    drivers/dma/stm32-mdma.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
>>>> index daa1602..fbcffa2 100644
>>>> --- a/drivers/dma/stm32-mdma.c
>>>> +++ b/drivers/dma/stm32-mdma.c
>>>> @@ -413,7 +413,7 @@ static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst,
>>>>    	u32 best_burst = max_burst;
>>>>    	u32 burst_len = best_burst * width;
>>>>    
>>>> -	while ((burst_len > 0) && (tlen % burst_len)) {
>>>> +	while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) {
>>>>    		best_burst = best_burst >> 1;
>>>>    		burst_len = best_burst * width;
>>>>    	}
>>>
>>> FWIW, doesn't that whole loop come down to just:
>>>
>>> 	burst_len = min(ffs(tlen | buf_len), max_burst * width);
>>
>> No sure it ends as expected. or I miss something or don't understand this statement
>> I tried with "relevant value" : i.e. best_burst = 32, Tlen=128(default) and
>> buf_len = 64, width= 4. This statements gets me something wrong output => 7
>> instead of 16 * 4.
>> I doubt :)
> 
> Heh, seems I confused myself halfway through and started thinking 
> max_burst and width were the exponents x rather than the values 2^x...
> 
> A more representative guess should be:
> 
> 	min(1 << __ffs(tlen | buf_len), max_burst * width);
> 
> but the general point I was trying to make is that a loop checking 
> whether the bottom n bits of something are zero for different values of 
> n is unnecessary when n can simply be calculated directly*.
> 
> Robin.

Got the point. I figure how to compute this value with __ffs. Your last
statement doesn't provide the good value, but the spirit is here. I just have to
adjust with what I want.

Thx

> 
> 
> * in the case of this "just the lowest set bit" idiom there's also the 
> shift-free ((x & (x - 1)) ^ x), but as well as being unreadable it's 
> generally less efficient than (1 << __ffs(x)) for most modern ISAs.
>
diff mbox

Patch

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index daa1602..fbcffa2 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -413,7 +413,7 @@  static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst,
 	u32 best_burst = max_burst;
 	u32 burst_len = best_burst * width;
 
-	while ((burst_len > 0) && (tlen % burst_len)) {
+	while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) {
 		best_burst = best_burst >> 1;
 		burst_len = best_burst * width;
 	}