* [PATCH] net: stmmac: Change the busy-wait loops timing
@ 2025-06-06 10:19 Bartlomiej Dziag
2025-06-06 13:55 ` Andrew Lunn
2025-06-07 16:21 ` Simon Horman
0 siblings, 2 replies; 3+ messages in thread
From: Bartlomiej Dziag @ 2025-06-06 10:19 UTC (permalink / raw)
Cc: bartlomiejdziag, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Maxime Chevallier, Daniel Machon, Wojciech Drewek, Oleksij Rempel,
Alexis Lothoré, netdev, linux-stm32, linux-arm-kernel,
linux-kernel
After writing a new value to the PTP_TAR or PTP_STSUR registers,
the driver waits for the addend/adjust operations to complete.
Sometimes, the first check operation fails, resulting in
a 10 milliseconds busy-loop before performing the next check.
Since updating the registers takes much less than 10 milliseconds,
the kernel gets stuck unnecessarily. This may increase the CPU usage.
Fix that with changing the busy-loop interval to 5 microseconds.
The registers will be checked more often.
Signed-off-by: Bartlomiej Dziag <bartlomiejdziag@gmail.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index e2840fa241f2..f8e1278a1837 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -144,11 +144,11 @@ static int config_addend(void __iomem *ioaddr, u32 addend)
writel(value, ioaddr + PTP_TCR);
/* wait for present addend update to complete */
- limit = 10;
+ limit = 10000;
while (limit--) {
if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSADDREG))
break;
- mdelay(10);
+ udelay(5);
}
if (limit < 0)
return -EBUSY;
@@ -187,11 +187,11 @@ static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
writel(value, ioaddr + PTP_TCR);
/* wait for present system time adjust/update to complete */
- limit = 10;
+ limit = 10000;
while (limit--) {
if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSUPDT))
break;
- mdelay(10);
+ udelay(5);
}
if (limit < 0)
return -EBUSY;
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: stmmac: Change the busy-wait loops timing
2025-06-06 10:19 [PATCH] net: stmmac: Change the busy-wait loops timing Bartlomiej Dziag
@ 2025-06-06 13:55 ` Andrew Lunn
2025-06-07 16:21 ` Simon Horman
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2025-06-06 13:55 UTC (permalink / raw)
To: Bartlomiej Dziag
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Maxime Chevallier,
Daniel Machon, Wojciech Drewek, Oleksij Rempel,
Alexis Lothoré, netdev, linux-stm32, linux-arm-kernel,
linux-kernel
On Fri, Jun 06, 2025 at 12:19:49PM +0200, Bartlomiej Dziag wrote:
> After writing a new value to the PTP_TAR or PTP_STSUR registers,
> the driver waits for the addend/adjust operations to complete.
> Sometimes, the first check operation fails, resulting in
> a 10 milliseconds busy-loop before performing the next check.
> Since updating the registers takes much less than 10 milliseconds,
> the kernel gets stuck unnecessarily. This may increase the CPU usage.
> Fix that with changing the busy-loop interval to 5 microseconds.
> The registers will be checked more often.
>
> Signed-off-by: Bartlomiej Dziag <bartlomiejdziag@gmail.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> index e2840fa241f2..f8e1278a1837 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> @@ -144,11 +144,11 @@ static int config_addend(void __iomem *ioaddr, u32 addend)
> writel(value, ioaddr + PTP_TCR);
>
> /* wait for present addend update to complete */
> - limit = 10;
> + limit = 10000;
> while (limit--) {
> if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSADDREG))
> break;
> - mdelay(10);
> + udelay(5);
I would actually suggest rewriting this using the macros from iopoll.h.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: stmmac: Change the busy-wait loops timing
2025-06-06 10:19 [PATCH] net: stmmac: Change the busy-wait loops timing Bartlomiej Dziag
2025-06-06 13:55 ` Andrew Lunn
@ 2025-06-07 16:21 ` Simon Horman
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-06-07 16:21 UTC (permalink / raw)
To: Bartlomiej Dziag
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Maxime Chevallier,
Daniel Machon, Wojciech Drewek, Oleksij Rempel,
Alexis Lothoré, netdev, linux-stm32, linux-arm-kernel,
linux-kernel
On Fri, Jun 06, 2025 at 12:19:49PM +0200, Bartlomiej Dziag wrote:
> After writing a new value to the PTP_TAR or PTP_STSUR registers,
> the driver waits for the addend/adjust operations to complete.
> Sometimes, the first check operation fails, resulting in
> a 10 milliseconds busy-loop before performing the next check.
> Since updating the registers takes much less than 10 milliseconds,
> the kernel gets stuck unnecessarily. This may increase the CPU usage.
> Fix that with changing the busy-loop interval to 5 microseconds.
> The registers will be checked more often.
Hi Bartlomiej,
I am curious.
Does it always take much less than 10ms, or is that usually so.
If it is the former, then do we need to wait for in the order of
10000 x 5us = 50ms before giving up?
>
> Signed-off-by: Bartlomiej Dziag <bartlomiejdziag@gmail.com>
...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-07 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 10:19 [PATCH] net: stmmac: Change the busy-wait loops timing Bartlomiej Dziag
2025-06-06 13:55 ` Andrew Lunn
2025-06-07 16:21 ` Simon Horman
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).