spi: spi-mtk-nor: Optimize timeout for dma read
Subsystems (2)
PATCH 1/1 spi: spi-mtk-nor: Optimize timeout for dma read
bayi cheng (1):
spi: spi-mtk-nor: Optimize timeout for dma read
drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/1 spi: spi-mtk-nor: Optimize timeout for dma read
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example, If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a 4KB data in spi mode. But the actual measurement exceeds 50s when a dma read timeout is encountered.
In order to be more accurately, It is necessary to use msecs_to_jiffies, After modification, the measured timeout value is about 130ms.
--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/spi/spi-mtk-nor.c +4 -3
@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel (from, sp->base +MTK_NOR_REG_DMA_FADR );
@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,mtk_nor_rmw (sp,MTK_NOR_REG_DMA_CTL ,MTK_NOR_DMA_START ,0 ); delay =CLK_TO_US (sp, (length +5 ) *BITS_PER_BYTE ); + timeout = (delay +1 ) *100 ;if (sp->has_irq) {if (!wait_for_completion_timeout (&sp->op_done, - (delay +1 ) *100 )) +msecs_to_jiffies (max_t (size_t, timeout /1000 ,10 )))) ret = -ETIMEDOUT ; }else { ret =readl_poll_timeout (sp->base +MTK_NOR_REG_DMA_CTL , reg, !(reg &MTK_NOR_DMA_START ), delay /3 , - (delay +1 ) *100 ); + timeout); }if (ret <0 )
Signature · 1 line
2.25.1
AngeloGioacchino Del Regno
maintainerIl 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 29 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example, If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a 4KB data in spi mode. But the actual measurement exceeds 50s when a dma read timeout is encountered.
In order to be more accurately, It is necessary to use
msecs_to_jiffies, After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi-mtk-nor.c +1
-1@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel (from, sp->base +MTK_NOR_REG_DMA_FADR );
drivers/spi/spi-mtk-nor.c static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, · line 383
Quoted 9 lines
drivers/spi/spi-mtk-nor.c +2
-1@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,mtk_nor_rmw (sp,MTK_NOR_REG_DMA_CTL ,MTK_NOR_DMA_START ,0 ); delay =CLK_TO_US (sp, (length +5 ) *BITS_PER_BYTE ); + timeout = (delay +1 ) *100 ;if (sp->has_irq) {if (!wait_for_completion_timeout (&sp->op_done, - (delay +1 ) *100 )) +msecs_to_jiffies (max_t (size_t, timeout /1000 ,10 ))))
You're giving a size_t variable to msecs_to_jiffies(), but checking jiffies.h, this function takes a const unsigned int param.
Please change the type to match that.
Aside from that, your timeout variable contains a timeout in microseconds and this means that actually using msecs_to_jiffies() is suboptimal here.
Please use usecs_to_jiffies() instead.
Regards,
Angelo
From: AngeloGioacchino Del Regno
Quoted 37 lines
Sent: 03 November 2022 09:44
Il 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 34 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example, If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a 4KB data in spi mode. But the actual measurement exceeds 50s when a dma read timeout is encountered.
In order to be more accurately, It is necessary to use
msecs_to_jiffies, After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi-mtk-nor.c +2
-1@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel (from, sp->base +MTK_NOR_REG_DMA_FADR );@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,mtk_nor_rmw (sp,MTK_NOR_REG_DMA_CTL ,MTK_NOR_DMA_START ,0 ); delay =CLK_TO_US (sp, (length +5 ) *BITS_PER_BYTE ); + timeout = (delay +1 ) *100 ;
Quoted 8 lines
drivers/spi/spi-mtk-nor.c static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, · line 383
Quoted 4 lines
drivers/spi/spi-mtk-nor.c +1
-1if (sp->has_irq) {if (!wait_for_completion_timeout (&sp->op_done, - (delay +1 ) *100 )) +msecs_to_jiffies (max_t (size_t, timeout /1000 ,10 ))))You're giving a
size_tvariable tomsecs_to_jiffies(), but checkingjiffies.h, this function takes aconst unsigned intparam.
Please change the type to match that.
The type shouldn't matter at all.
What matters is the domain of the value.
Quite why you need to use max_t(size_t, ...) is another matter. timeout is ulong so max(timeout/1000, 10ul) should be fine.
But is ulong even right?
The domain of the value is almost certainly the same on 32bit and 64bit. So you almost certainly need u32 or u64.
David
Quoted 8 lines
Aside from that, your
timeoutvariable contains a timeout in microseconds and this means that actually usingmsecs_to_jiffies()is suboptimal here.Please use
usecs_to_jiffies()instead.Regards,
Angelo
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 63 lines · David Laight
From: AngeloGioacchino Del Regno
Quoted 45 lines
Sent: 03 November 2022 09:44
Il 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 42 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example,
If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
4KB data in spi mode. But the actual measurement exceeds 50s when a
dma read timeout is encountered.In order to be more accurately, It is necessary to use
msecs_to_jiffies,
After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi-mtk- renamed from drivers/spi/spi-mtk-nor.c +0
-0
nor.c
indexd167699a1a96..3d989db80ee9100644drivers/spi/spi-mtk-nor.c +1
-1@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel(from, sp->base + MTK_NOR_REG_DMA_FADR);drivers/spi/spi-mtk-nor.c +1
-0@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, mtk_nor_rmw(sp, MTK_NOR_REG_DMA_CTL, MTK_NOR_DMA_START, 0); delay =CLK_TO_US (sp, (length +5 ) *BITS_PER_BYTE ); + timeout = (delay +1 ) *100 ;Quoted 10 lines
drivers/spi/spi-mtk-nor.c static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,
Quoted 5 lines
drivers/spi/spi-mtk-nor.c +1
-1if (sp->has_irq) {if (!wait_for_completion_timeout (&sp->op_done, - (delay +1 ) *100 )) +msecs_to_jiffies (max_t (size_t, timeout /1000 ,10 ))))You're giving a
size_tvariable tomsecs_to_jiffies(), but checkingjiffies.h,
this function takes aconst unsigned intparam. Please change the type to match that.The type shouldn't matter at all.
What matters is the domain of the value.Quite why you need to use
max_t(size_t, ...)is another matter. timeout is ulong somax(timeout/1000, 10ul)should be fine.
Quoted 7 lines
But is ulong even right?
The domain of the value is almost certainly the same on 32bit and 64bit.
So you almost certainly need u32 or u64.David
Hi David & Angelo
Thank you for your comments!
To sum up, I think the next version will make the following two changes:
1, The timeout value will not exceed u32, so the type of timeout will be changed from ulong to u32.
2, Change msecs_to_jiffies(max_t(size_t, timeout / 1000, 10)) to be msecs_to_jiffies(max(timeout/1000, 10ul)).
If you think these changes are not enough, please let me know, Thanks!
Best Regards,
Bayi
Quoted 15 lines
Quoted 10 lines
Aside from that, your
timeoutvariable contains a timeout in microseconds and
this means that actually usingmsecs_to_jiffies()is suboptimal here.Please use
usecs_to_jiffies()instead.Regards,
Angelo-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Quoted 86 lines · Bayi Cheng (程八意)
Quoted 67 lines · David Laight
From: AngeloGioacchino Del Regno
Quoted 47 lines
Sent: 03 November 2022 09:44
Il 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 44 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example,
If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
4KB data in spi mode. But the actual measurement exceeds 50s when
a
dma read timeout is encountered.In order to be more accurately, It is necessary to use
msecs_to_jiffies,
After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi-mtk- renamed from drivers/spi/spi-mtk-nor.c +0
-0
nor.c
indexd167699a1a96..3d989db80ee9100644drivers/spi/spi-mtk-nor.c +1
-1@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel(from, sp->base + MTK_NOR_REG_DMA_FADR);drivers/spi/spi-mtk-nor.c +0
-0@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct
mtk_nor
*sp, u32 from, unsigned int length,
mtk_nor_rmw(sp,MTK_NOR_REG_DMA_CTL,MTK_NOR_DMA_START,
0);delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);drivers/spi/spi-mtk-nor.c +1
-0+ timeout = (delay +1 ) *100 ;Quoted 12 lines
Quoted 7 lines
if (sp->has_irq) { if (!wait_for_completion_timeout(&sp->op_done,drivers/spi/spi-mtk-nor.c +0
-1- (delay + 1) *100))
drivers/spi/spi-mtk-nor.c +1
-0+ msecs_to_jiffies(max_t(size_t, timeout /1000,
10))))You're giving a
size_tvariable tomsecs_to_jiffies(), but checkingjiffies.h,
this function takes aconst unsigned intparam. Please change the type to match that.The type shouldn't matter at all.
What matters is the domain of the value.Quite why you need to use
max_t(size_t, ...)is another matter. timeout is ulong somax(timeout/1000, 10ul)should be fine.Quoted 7 lines
But is ulong even right?
The domain of the value is almost certainly the same on 32bit and 64bit.
So you almost certainly need u32 or u64.David
Hi David & Angelo
Thank you for your comments!
To sum up, I think the next version will make the following two changes:
1, The timeout value will not exceed u32, so the type of timeout will be changed from ulong to u32.
2, Changemsecs_to_jiffies(max_t(size_t, timeout / 1000, 10))to bemsecs_to_jiffies(max(timeout / 1000, 10U)).
Quoted 6 lines
If you think these changes are not enough, please let me know, Thanks!
Best Regards,
Bayi
Hi Angelo, Hi David,
Just a gentle ping on this.
Could you please review this patch and give us some suggestion?
PS: With your permission, I will make the following changes in the next version:
Change in v2:
-Change the type of "timeout" from ulong to u32. -Replace max_t with max.
Thanks.
BRs,
Bayi Cheng
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines
Aside from that, your
timeoutvariable contains a timeout in microseconds and
this means that actually usingmsecs_to_jiffies()is suboptimal here.Please use
usecs_to_jiffies()instead.Regards,
Angelo-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
MK1 1PT, UK
Registration No: 1397386 (Wales)
AngeloGioacchino Del Regno
maintainerIl 11/11/22 05:16, Bayi Cheng (程八意) ha scritto:
Quoted 99 lines · Bayi Cheng (程八意)
Quoted 86 lines · David Laight
Quoted 67 lines
From: AngeloGioacchino Del Regno
Quoted 47 lines
Sent: 03 November 2022 09:44
Il 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 44 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For example,
If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
4KB data in spi mode. But the actual measurement exceeds 50s when
a
dma read timeout is encountered.In order to be more accurately, It is necessary to use
msecs_to_jiffies,
After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi-mtk- renamed from drivers/spi/spi-mtk-nor.c +0
-0
nor.c
indexd167699a1a96..3d989db80ee9100644drivers/spi/spi-mtk-nor.c +1
-1@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length, dma_addr_t dma_addr) {int ret =0 ; -ulong delay; +ulong delay, timeout;u32 reg;writel(from, sp->base + MTK_NOR_REG_DMA_FADR);drivers/spi/spi-mtk-nor.c +0
-0@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct
mtk_nor
*sp, u32 from, unsigned int length,
mtk_nor_rmw(sp,MTK_NOR_REG_DMA_CTL,MTK_NOR_DMA_START,
0);delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);drivers/spi/spi-mtk-nor.c +1
-0+ timeout = (delay +1 ) *100 ;Quoted 12 lines
Quoted 7 lines
if (sp->has_irq) { if (!wait_for_completion_timeout(&sp->op_done,drivers/spi/spi-mtk-nor.c +0
-1- (delay + 1) *100))
drivers/spi/spi-mtk-nor.c +1
-0+ msecs_to_jiffies(max_t(size_t, timeout /1000,
10))))You're giving a
size_tvariable tomsecs_to_jiffies(), but checkingjiffies.h,
this function takes aconst unsigned intparam. Please change the type to match that.The type shouldn't matter at all.
What matters is the domain of the value.Quite why you need to use
max_t(size_t, ...)is another matter. timeout is ulong somax(timeout/1000, 10ul)should be fine.Quoted 7 lines
But is ulong even right?
The domain of the value is almost certainly the same on 32bit and 64bit.
So you almost certainly need u32 or u64.David
Hi David & Angelo
Thank you for your comments!
To sum up, I think the next version will make the following two changes:
1, The timeout value will not exceed u32, so the type of timeout will be changed from ulong to u32.
2, Changemsecs_to_jiffies(max_t(size_t, timeout / 1000, 10))to bemsecs_to_jiffies(max(timeout / 1000, 10U)).Quoted 6 lines
If you think these changes are not enough, please let me know, Thanks!
Best Regards,
BayiHi Angelo, Hi David,
Just a gentle ping on this.
Could you please review this patch and give us some suggestion?
Quoted 7 lines
PS: With your permission, I will make the following changes in the next version:
Change in v2:
-Change the type of "timeout" from ulong to u32. -Replacemax_twith max.
I still recommend to use usecs_to_jiffies() when appropriate, instead of converting usecs to msecs and using msecs_to_jiffies().
As for the rest in your list: yes, please.
Regards,
Angelo
Quoted 22 lines
Thanks.
BRs,
Bayi ChengQuoted 16 lines
Quoted 16 lines
Quoted 10 lines
Aside from that, your
timeoutvariable contains a timeout in microseconds and
this means that actually usingmsecs_to_jiffies()is suboptimal here.Please use
usecs_to_jiffies()instead.Regards,
Angelo-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
MK1 1PT, UK
Registration No: 1397386 (Wales)
Signature · 6 lines
AngeloGioacchino Del Regno Software Engineer Collabora Ltd. Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK Registered in England & Wales, no. 5513718
Quoted 118 lines · AngeloGioacchino Del Regno
Il 11/11/22 05:16, Bayi Cheng (程八意) ha scritto:
Quoted 108 lines · Bayi Cheng (程八意)
Quoted 95 lines · David Laight
Quoted 73 lines
From: AngeloGioacchino Del Regno
Quoted 53 lines
Sent: 03 November 2022 09:44
Il 03/11/22 06:28, Bayi Cheng ha scritto:
Quoted 50 lines
From: bayi cheng <[email protected]>
The timeout value of the current dma read is unreasonable. For
example,
If the spi flash clock is 26Mhz, It will takes about 1.3ms to
read a
4KB data in spi mode. But the actual measurement exceeds 50s
when
a
dma read timeout is encountered.In order to be more accurately, It is necessary to use
msecs_to_jiffies,
After modification, the measured timeout value is about 130ms.Signed-off-by bayi cheng <[email protected]>--- drivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/spi/spi- renamed from drivers/spi/spi-mtk-nor.c +0
-0mtk-
nor.c
indexd167699a1a96..3d989db80ee9100644drivers/spi/spi-mtk-nor.c +0
-0@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct
mtk_nor
*sp, u32 from, unsigned int length,
dma_addr_tdma_addr){ int ret = 0;drivers/spi/spi-mtk-nor.c +1
-1-ulong delay; +ulong delay, timeout;u32 reg;writel (from, sp->base +MTK_NOR_REG_DMA_FADR );@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct
mtk_nor
*sp, u32 from, unsigned int length,
mtk_nor_rmw(sp,MTK_NOR_REG_DMA_CTL,MTK_NOR_DMA_START,
0);delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);drivers/spi/spi-mtk-nor.c +1
-0+ timeout = (delay +1 ) *100 ;Quoted 12 lines
Quoted 7 lines
if (sp->has_irq) { if (!wait_for_completion_timeout(&sp->op_done,drivers/spi/spi-mtk-nor.c +0
-1- (delay + 1) *100))
drivers/spi/spi-mtk-nor.c +1
-0+ msecs_to_jiffies(max_t(size_t, timeout /1000,
10))))You're giving a
size_tvariable tomsecs_to_jiffies(), but checkingjiffies.h,
this function takes aconst unsigned intparam. Please change the type to match that.The type shouldn't matter at all.
What matters is the domain of the value.Quite why you need to use
max_t(size_t, ...)is another matter. timeout is ulong somax(timeout/1000, 10ul)should be fine.Quoted 8 lines
But is ulong even right?
The domain of the value is almost certainly the same on 32bit and
64bit.
So you almost certainly need u32 or u64.David
Hi David & Angelo
Thank you for your comments!
To sum up, I think the next version will make the following two changes:
1, The timeout value will not exceed u32, so the type of timeout will
be changed from ulong to u32.
2, Changemsecs_to_jiffies(max_t(size_t, timeout / 1000, 10))to bemsecs_to_jiffies(max(timeout / 1000, 10U)).Quoted 6 lines
If you think these changes are not enough, please let me know, Thanks!
Best Regards,
BayiHi Angelo, Hi David,
Just a gentle ping on this.
Could you please review this patch and give us some suggestion?Quoted 8 lines
PS: With your permission, I will make the following changes in the next
version:Change in v2:
-Change the type of "timeout" from ulong to u32. -Replacemax_twith max.
Quoted 9 lines
I still recommend to use
usecs_to_jiffies()when appropriate, instead of
converting usecs to msecs and usingmsecs_to_jiffies().As for the rest in your list: yes, please.
Regards,
Angelo
Hi Angelo,
Thanks for your comments!
I will change it to be usecs_to_jiffies(max(timeout, 10000U)) in the next patch.
BRs,
Bayi Cheng
Quoted 26 lines
Quoted 24 lines
Thanks.
BRs,
Bayi ChengQuoted 18 lines
Quoted 18 lines
Quoted 8 lines
Aside from that, your
timeoutvariable contains a timeout in
microseconds and
this means that actually usingmsecs_to_jiffies()is suboptimal
here.Quoted 4 lines
Please use
usecs_to_jiffies()instead.Regards,
Angelo-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
MK1 1PT, UK
Registration No: 1397386 (Wales)
Hi Bayi,
Please don't send cover letters for single patches [1], Thanks.
[1] https://lore.kernel.org/all/[email protected]/
BRs,
Allen
Quoted 6 lines · Bayi Cheng
bayi cheng (1):
spi: spi-mtk-nor: Optimize timeout for dma readdrivers/spi/spi-mtk-nor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)