diff mbox series

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

Message ID 20240827114916.223377-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 0870b0d8b393dde53106678a1e2cec9dfa52f9b7
Delegated to: Netdev Maintainers
Headers show
Series [net] net: busy-poll: use ktime_get_ns() instead of local_clock() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 4 blamed authors not CCed: mingo@kernel.org tglx@linutronix.de jesse.brandeburg@intel.com peterz@infradead.org; 4 maintainers not CCed: mingo@kernel.org tglx@linutronix.de jesse.brandeburg@intel.com peterz@infradead.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 147 this patch: 147
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-27--18-00 (tests: 714)

Commit Message

Eric Dumazet Aug. 27, 2024, 11:49 a.m. UTC
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()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Mina Almasry <almasrymina@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Joe Damato <jdamato@fastly.com>
---
 include/net/busy_poll.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Joe Damato Aug. 27, 2024, 11:58 a.m. UTC | #1
On Tue, Aug 27, 2024 at 11:49:16AM +0000, Eric Dumazet 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.
> 
> 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()")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Mina Almasry <almasrymina@google.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Joe Damato <jdamato@fastly.com>
> ---
>  include/net/busy_poll.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h
> index 9b09acac538eed8dbaa2576bf2af926ecd98eb44..522f1da8b747ac73578d8fd93301d31835a6dae0 100644
> --- a/include/net/busy_poll.h
> +++ b/include/net/busy_poll.h
> @@ -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
> -- 
> 2.46.0.295.g3b9ea8a38a-goog

Makes sense to me, thanks.

Reviewed-by: Joe Damato <jdamato@fastly.com>
patchwork-bot+netdevbpf@kernel.org Aug. 29, 2024, 1 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
diff mbox series

Patch

diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h
index 9b09acac538eed8dbaa2576bf2af926ecd98eb44..522f1da8b747ac73578d8fd93301d31835a6dae0 100644
--- a/include/net/busy_poll.h
+++ b/include/net/busy_poll.h
@@ -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