Skip to contentSkip to conversation

net: busy-poll: use ktime_get_ns() instead of local_clock()

PATCH Applied Eric Dumazet 3 participants 3 messages Aug 27, 2024 – Aug 29, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: busy-poll: use ktime_get_ns() instead of local_clock()

Typically, busy-polling durations are below 100 usec.

When/if the busy-poller thread migrates to another cpu, local_clock() can be off by +/-2msec or more for small values of HZ, depending on the platform.

Use ktimer_get_ns() to ensure deterministic behavior, which is the whole point of busy-polling.

Fixes 060212928670 ("net: add low latency socket poll")
Fixes 9a3c71aa8024 ("net: convert low latency sockets to sched_clock()")
Fixes 37089834528b ("sched, net: Fixup busy_loop_us_clock()")
Cc Mina Almasry <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Joe Damato <[email protected]>
---
 include/net/busy_poll.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/busy_poll.h +1 -1
index 9b09acac538eed8dbaa2576bf2af926ecd98eb44..522f1da8b747ac73578d8fd93301d31835a6dae0 100644
@@ -68,7 +68,7 @@ static inline bool sk_can_busy_loop(struct sock *sk)
 static inline unsigned long busy_loop_current_time(void)
 {
 #ifdef CONFIG_NET_RX_BUSY_POLL
-	return (unsigned long)(local_clock() >> 10);
+	return (unsigned long)(ktime_get_ns() >> 10);
 #else
 	return 0;
 #endif
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Eric Dumazet

Typically, busy-polling durations are below 100 usec.

When/if the busy-poller thread migrates to another cpu, local_clock() can be off by +/-2msec or more for small values of HZ, depending on the platform.

Use ktimer_get_ns() to ensure deterministic behavior, which is the whole point of busy-polling.

Fixes 060212928670 ("net: add low latency socket poll")
Fixes 9a3c71aa8024 ("net: convert low latency sockets to sched_clock()")
Fixes 37089834528b ("sched, net: Fixup busy_loop_us_clock()")
Cc Mina Almasry <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Joe Damato <[email protected]>
---
 include/net/busy_poll.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/busy_poll.h +1 -1
index 9b09acac538eed8dbaa2576bf2af926ecd98eb44..522f1da8b747ac73578d8fd93301d31835a6dae0 100644
@@ -68,7 +68,7 @@ static inline bool sk_can_busy_loop(struct sock *sk)
 static inline unsigned long busy_loop_current_time(void)
 {
 #ifdef CONFIG_NET_RX_BUSY_POLL
-	return (unsigned long)(local_clock() >> 10);
+	return (unsigned long)(ktime_get_ns() >> 10);
 #else
 	return 0;
 #endif
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog

Makes sense to me, thanks.

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 27 Aug 2024 11:49:16 +0000 you wrote:

Typically, busy-polling durations are below 100 usec.

When/if the busy-poller thread migrates to another cpu, local_clock() can be off by +/-2msec or more for small values of HZ, depending on the platform.

Use ktimer_get_ns() to ensure deterministic behavior, which is the whole point of busy-polling.

[...]

Here is the summary with links:
- [net] net: busy-poll: use ktime_get_ns() instead of local_clock()

    https://git.kernel.org/netdev/net/c/0870b0d8b393

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html