public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] time/timecounter: inline timecounter_cyc2time()
@ 2025-11-29  9:57 Eric Dumazet
  2025-11-29 17:06 ` Willem de Bruijn
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Eric Dumazet @ 2025-11-29  9:57 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Stephen Boyd, Jakub Kicinski,
	Paolo Abeni
  Cc: linux-kernel, netdev, Eric Dumazet, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

New network transport protocols want NIC drivers to get hwtstamps
of all incoming packets, and possibly all outgoing packets.

Swift congestion control is used by good old TCP transport and is
our primary need for timecounter_cyc2time(). This will be upstreamed soon.

This means timecounter_cyc2time() can be called more than 100 million
times per second on a busy server.

Inlining timecounter_cyc2time() brings a 12 % improvement on a
UDP receive stress test on a 100Gbit NIC.

Note that FDO, LTO, PGO are unable to magically help for this
case, presumably because NIC drivers are almost exclusively shipped
as modules.

Add an unlikely() around the cc_cyc2ns_backwards() case,
even if FDO (when used) is able to take care of this optimization.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/
Cc: Kevin Yang <yyd@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
---
 include/linux/timecounter.h | 33 +++++++++++++++++++++++++++++++--
 kernel/time/timecounter.c   | 35 -----------------------------------
 2 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
index dce03a5cafb7cfe61bd83304ef49f7721735da64..de21312ebed0f41946304f95f05cc625ea7f2a68 100644
--- a/include/linux/timecounter.h
+++ b/include/linux/timecounter.h
@@ -115,6 +115,16 @@ extern void timecounter_init(struct timecounter *tc,
  */
 extern u64 timecounter_read(struct timecounter *tc);
 
+/*
+ * This is like cyclecounter_cyc2ns(), but it is used for computing a
+ * time previous to the time stored in the cycle counter.
+ */
+static inline u64 cc_cyc2ns_backwards(const struct cyclecounter *cc,
+				      u64 cycles, u64 frac)
+{
+	return ((cycles * cc->mult) - frac) >> cc->shift;
+}
+
 /**
  * timecounter_cyc2time - convert a cycle counter to same
  *                        time base as values returned by
@@ -131,7 +141,26 @@ extern u64 timecounter_read(struct timecounter *tc);
  *
  * Returns: cycle counter converted to nanoseconds since the initial time stamp
  */
-extern u64 timecounter_cyc2time(const struct timecounter *tc,
-				u64 cycle_tstamp);
+static inline u64 timecounter_cyc2time(const struct timecounter *tc,
+				       u64 cycle_tstamp)
+{
+	const struct cyclecounter *cc = tc->cc;
+	u64 delta = (cycle_tstamp - tc->cycle_last) & cc->mask;
+	u64 nsec = tc->nsec, frac = tc->frac;
+
+	/*
+	 * Instead of always treating cycle_tstamp as more recent
+	 * than tc->cycle_last, detect when it is too far in the
+	 * future and treat it as old time stamp instead.
+	 */
+	if (unlikely(delta > cc->mask / 2)) {
+		delta = (tc->cycle_last - cycle_tstamp) & cc->mask;
+		nsec -= cc_cyc2ns_backwards(cc, delta, frac);
+	} else {
+		nsec += cyclecounter_cyc2ns(cc, delta, tc->mask, &frac);
+	}
+
+	return nsec;
+}
 
 #endif
diff --git a/kernel/time/timecounter.c b/kernel/time/timecounter.c
index 3d2a354cfe1c1b205aa960a748a76f8dd94335e2..2e64dbb6302d71d8b092d92dda0b71c99cdc053d 100644
--- a/kernel/time/timecounter.c
+++ b/kernel/time/timecounter.c
@@ -62,38 +62,3 @@ u64 timecounter_read(struct timecounter *tc)
 }
 EXPORT_SYMBOL_GPL(timecounter_read);
 
-/*
- * This is like cyclecounter_cyc2ns(), but it is used for computing a
- * time previous to the time stored in the cycle counter.
- */
-static u64 cc_cyc2ns_backwards(const struct cyclecounter *cc,
-			       u64 cycles, u64 mask, u64 frac)
-{
-	u64 ns = (u64) cycles;
-
-	ns = ((ns * cc->mult) - frac) >> cc->shift;
-
-	return ns;
-}
-
-u64 timecounter_cyc2time(const struct timecounter *tc,
-			 u64 cycle_tstamp)
-{
-	u64 delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
-	u64 nsec = tc->nsec, frac = tc->frac;
-
-	/*
-	 * Instead of always treating cycle_tstamp as more recent
-	 * than tc->cycle_last, detect when it is too far in the
-	 * future and treat it as old time stamp instead.
-	 */
-	if (delta > tc->cc->mask / 2) {
-		delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
-		nsec -= cc_cyc2ns_backwards(tc->cc, delta, tc->mask, frac);
-	} else {
-		nsec += cyclecounter_cyc2ns(tc->cc, delta, tc->mask, &frac);
-	}
-
-	return nsec;
-}
-EXPORT_SYMBOL_GPL(timecounter_cyc2time);
-- 
2.52.0.107.ga0afd4fd5b-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2025-11-29  9:57 [PATCH] time/timecounter: inline timecounter_cyc2time() Eric Dumazet
@ 2025-11-29 17:06 ` Willem de Bruijn
  2025-12-01 18:16   ` Kevin Yang
  2025-12-10  0:51 ` Thomas Gleixner
  2026-01-20  8:18 ` Jason Xing
  2 siblings, 1 reply; 8+ messages in thread
From: Willem de Bruijn @ 2025-11-29 17:06 UTC (permalink / raw)
  To: Eric Dumazet, John Stultz, Thomas Gleixner, Stephen Boyd,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, netdev, Eric Dumazet, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

Eric Dumazet wrote:
> New network transport protocols want NIC drivers to get hwtstamps
> of all incoming packets, and possibly all outgoing packets.
> 
> Swift congestion control is used by good old TCP transport and is
> our primary need for timecounter_cyc2time(). This will be upstreamed soon.
> 
> This means timecounter_cyc2time() can be called more than 100 million
> times per second on a busy server.
> 
> Inlining timecounter_cyc2time() brings a 12 % improvement on a
> UDP receive stress test on a 100Gbit NIC.
> 
> Note that FDO, LTO, PGO are unable to magically help for this
> case, presumably because NIC drivers are almost exclusively shipped
> as modules.
> 
> Add an unlikely() around the cc_cyc2ns_backwards() case,
> even if FDO (when used) is able to take care of this optimization.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Link: https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/
> Cc: Kevin Yang <yyd@google.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Neal Cardwell <ncardwell@google.com>
> Cc: Yuchung Cheng <ycheng@google.com>

Reviewed-by: Willem de Bruijn <willemb@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2025-11-29 17:06 ` Willem de Bruijn
@ 2025-12-01 18:16   ` Kevin Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Kevin Yang @ 2025-12-01 18:16 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: Eric Dumazet, John Stultz, Thomas Gleixner, Stephen Boyd,
	Jakub Kicinski, Paolo Abeni, linux-kernel, netdev, Eric Dumazet,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

Reviewed-by: Kevin Yang <yyd@google.com>


On Sat, Nov 29, 2025 at 12:06 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> Eric Dumazet wrote:
> > New network transport protocols want NIC drivers to get hwtstamps
> > of all incoming packets, and possibly all outgoing packets.
> >
> > Swift congestion control is used by good old TCP transport and is
> > our primary need for timecounter_cyc2time(). This will be upstreamed soon.
> >
> > This means timecounter_cyc2time() can be called more than 100 million
> > times per second on a busy server.
> >
> > Inlining timecounter_cyc2time() brings a 12 % improvement on a
> > UDP receive stress test on a 100Gbit NIC.
> >
> > Note that FDO, LTO, PGO are unable to magically help for this
> > case, presumably because NIC drivers are almost exclusively shipped
> > as modules.
> >
> > Add an unlikely() around the cc_cyc2ns_backwards() case,
> > even if FDO (when used) is able to take care of this optimization.
> >
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Link: https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/
> > Cc: Kevin Yang <yyd@google.com>
> > Cc: Willem de Bruijn <willemb@google.com>
> > Cc: Neal Cardwell <ncardwell@google.com>
> > Cc: Yuchung Cheng <ycheng@google.com>
>
> Reviewed-by: Willem de Bruijn <willemb@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2025-11-29  9:57 [PATCH] time/timecounter: inline timecounter_cyc2time() Eric Dumazet
  2025-11-29 17:06 ` Willem de Bruijn
@ 2025-12-10  0:51 ` Thomas Gleixner
  2026-01-20  8:18 ` Jason Xing
  2 siblings, 0 replies; 8+ messages in thread
From: Thomas Gleixner @ 2025-12-10  0:51 UTC (permalink / raw)
  To: Eric Dumazet, John Stultz, Stephen Boyd, Jakub Kicinski,
	Paolo Abeni
  Cc: linux-kernel, netdev, Eric Dumazet, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

On Sat, Nov 29 2025 at 09:57, Eric Dumazet wrote:
> Add an unlikely() around the cc_cyc2ns_backwards() case,
> even if FDO (when used) is able to take care of this optimization.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Earmarked for post rc1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2025-11-29  9:57 [PATCH] time/timecounter: inline timecounter_cyc2time() Eric Dumazet
  2025-11-29 17:06 ` Willem de Bruijn
  2025-12-10  0:51 ` Thomas Gleixner
@ 2026-01-20  8:18 ` Jason Xing
  2026-01-20  9:06   ` Thomas Gleixner
  2 siblings, 1 reply; 8+ messages in thread
From: Jason Xing @ 2026-01-20  8:18 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: John Stultz, Thomas Gleixner, Stephen Boyd, Jakub Kicinski,
	Paolo Abeni, linux-kernel, netdev, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

On Sat, Nov 29, 2025 at 5:57 PM Eric Dumazet <edumazet@google.com> wrote:
>
> New network transport protocols want NIC drivers to get hwtstamps
> of all incoming packets, and possibly all outgoing packets.
>
> Swift congestion control is used by good old TCP transport and is
> our primary need for timecounter_cyc2time(). This will be upstreamed soon.
>
> This means timecounter_cyc2time() can be called more than 100 million
> times per second on a busy server.
>
> Inlining timecounter_cyc2time() brings a 12 % improvement on a
> UDP receive stress test on a 100Gbit NIC.
>
> Note that FDO, LTO, PGO are unable to magically help for this
> case, presumably because NIC drivers are almost exclusively shipped
> as modules.
>
> Add an unlikely() around the cc_cyc2ns_backwards() case,
> even if FDO (when used) is able to take care of this optimization.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Link: https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/
> Cc: Kevin Yang <yyd@google.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: Neal Cardwell <ncardwell@google.com>
> Cc: Yuchung Cheng <ycheng@google.com>

When I'm browsing the modification related to SWIFT, I noticed this
patch seems to have not been merged yet?

Thanks,
Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2026-01-20  8:18 ` Jason Xing
@ 2026-01-20  9:06   ` Thomas Gleixner
  2026-01-20  9:11     ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2026-01-20  9:06 UTC (permalink / raw)
  To: Jason Xing, Eric Dumazet
  Cc: John Stultz, Stephen Boyd, Jakub Kicinski, Paolo Abeni,
	linux-kernel, netdev, Eric Dumazet, Kevin Yang, Willem de Bruijn,
	Neal Cardwell, Yuchung Cheng

On Tue, Jan 20 2026 at 16:18, Jason Xing wrote:
> On Sat, Nov 29, 2025 at 5:57 PM Eric Dumazet <edumazet@google.com> wrote:
>
> When I'm browsing the modification related to SWIFT, I noticed this
> patch seems to have not been merged yet?

It's in the tip tree and scheduled for the next merge window.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2026-01-20  9:06   ` Thomas Gleixner
@ 2026-01-20  9:11     ` Eric Dumazet
  2026-01-21  2:47       ` Jason Xing
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2026-01-20  9:11 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Jason Xing, John Stultz, Stephen Boyd, Jakub Kicinski,
	Paolo Abeni, linux-kernel, netdev, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

On Tue, Jan 20, 2026 at 10:06 AM Thomas Gleixner <tglx@kernel.org> wrote:
>
> On Tue, Jan 20 2026 at 16:18, Jason Xing wrote:
> > On Sat, Nov 29, 2025 at 5:57 PM Eric Dumazet <edumazet@google.com> wrote:
> >
> > When I'm browsing the modification related to SWIFT, I noticed this
> > patch seems to have not been merged yet?
>
> It's in the tip tree and scheduled for the next merge window.

You beat me to it, thank you

tip tree :

commit 4725344462362e2ce2645f354737a8ea4280fa57
Author:     Eric Dumazet <edumazet@google.com>
AuthorDate: Sat Nov 29 09:57:40 2025 +0000
Commit:     Thomas Gleixner <tglx@kernel.org>
CommitDate: Mon Dec 15 20:16:49 2025 +0100

    time/timecounter: Inline timecounter_cyc2time()

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] time/timecounter: inline timecounter_cyc2time()
  2026-01-20  9:11     ` Eric Dumazet
@ 2026-01-21  2:47       ` Jason Xing
  0 siblings, 0 replies; 8+ messages in thread
From: Jason Xing @ 2026-01-21  2:47 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Thomas Gleixner, John Stultz, Stephen Boyd, Jakub Kicinski,
	Paolo Abeni, linux-kernel, netdev, Eric Dumazet, Kevin Yang,
	Willem de Bruijn, Neal Cardwell, Yuchung Cheng

On Tue, Jan 20, 2026 at 5:11 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Tue, Jan 20, 2026 at 10:06 AM Thomas Gleixner <tglx@kernel.org> wrote:
> >
> > On Tue, Jan 20 2026 at 16:18, Jason Xing wrote:
> > > On Sat, Nov 29, 2025 at 5:57 PM Eric Dumazet <edumazet@google.com> wrote:
> > >
> > > When I'm browsing the modification related to SWIFT, I noticed this
> > > patch seems to have not been merged yet?
> >
> > It's in the tip tree and scheduled for the next merge window.
>
> You beat me to it, thank you
>
> tip tree :
>
> commit 4725344462362e2ce2645f354737a8ea4280fa57
> Author:     Eric Dumazet <edumazet@google.com>
> AuthorDate: Sat Nov 29 09:57:40 2025 +0000
> Commit:     Thomas Gleixner <tglx@kernel.org>
> CommitDate: Mon Dec 15 20:16:49 2025 +0100
>
>     time/timecounter: Inline timecounter_cyc2time()

Thanks, I see now :)

Thanks,
Jason

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-21  2:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29  9:57 [PATCH] time/timecounter: inline timecounter_cyc2time() Eric Dumazet
2025-11-29 17:06 ` Willem de Bruijn
2025-12-01 18:16   ` Kevin Yang
2025-12-10  0:51 ` Thomas Gleixner
2026-01-20  8:18 ` Jason Xing
2026-01-20  9:06   ` Thomas Gleixner
2026-01-20  9:11     ` Eric Dumazet
2026-01-21  2:47       ` Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox