Skip to contentSkip to conversation

idpf: XDP chapter II: convert Tx completion to libeth

GIT PULL In review Tony Nguyen 3 participants 26 messages Aug 19, 2024 – Aug 29, 2024

Subsystems (5)
lore
Share & tools
lore

Tony Nguyen

author maintainer
#0 lore raw

Alexander Lobakin says:

XDP for idpf is currently 5 chapters:
* convert Rx to libeth;
* convert Tx completion and stats to libeth (this);
* generic XDP and XSk code changes;
* actual XDP for idpf via libeth_xdp;
* XSk for idpf (^).

Part II does the following:
* introduces generic libeth per-queue stats infra;
* adds generic libeth Tx completion routines;
* converts idpf to use generic libeth Tx comp routines;
* fixes Tx queue timeouts and robustifies Tx completion in general;
* fixes Tx event/descriptor flushes (writebacks);
* fully switches idpf per-queue stats to libeth.

Most idpf patches again remove more lines than adds.
The perf difference is not visible by eye in common scenarios, but
the stats are now more complete and reliable, and also survive ifups-ifdowns.
---
v1: https://lore.kernel.org/netdev/[email protected]/
- Rebased

iwl: https://lore.kernel.org/intel-wired-lan/[email protected]/

The following are changes since commit 1bf8e07c382bd4f04ede81ecc05267a8ffd60999:
dt-binding: ptp: fsl,ptp: add pci1957,ee02 compatible string for fsl,enetc-ptp
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue 200GbE

Alexander Lobakin (6):
unroll: add generic loop unroll helpers
libeth: add common queue stats
libie: add Tx buffer completion helpers
idpf: convert to libie Tx buffer completion
netdevice: add netdev_tx_reset_subqueue() shorthand
idpf: switch to libeth generic statistics

Joshua Hay (2):
idpf: refactor Tx completion routines
idpf: enable WB_ON_ITR

Michal Kubiak (1):
idpf: fix netdev Tx queue stop/wake

 drivers/net/ethernet/intel/idpf/idpf.h        |  21 +-
 drivers/net/ethernet/intel/idpf/idpf_dev.c    |   2 +
 .../net/ethernet/intel/idpf/idpf_ethtool.c    | 498 ++--------------
 drivers/net/ethernet/intel/idpf/idpf_lib.c    |  32 +-
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   | 172 +++---
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 539 +++++++++---------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   | 144 ++---
 drivers/net/ethernet/intel/idpf/idpf_vf_dev.c |   2 +
 .../net/ethernet/intel/idpf/idpf_virtchnl.c   |  37 +-
 drivers/net/ethernet/intel/idpf/virtchnl2.h   |  33 +-
 drivers/net/ethernet/intel/libeth/Makefile    |   4 +-
 drivers/net/ethernet/intel/libeth/netdev.c    | 157 +++++
 drivers/net/ethernet/intel/libeth/priv.h      |  21 +
 drivers/net/ethernet/intel/libeth/rx.c        |   5 -
 drivers/net/ethernet/intel/libeth/stats.c     | 360 ++++++++++++
 include/linux/netdevice.h                     |  13 +-
 include/linux/unroll.h                        |  50 ++
 include/net/libeth/netdev.h                   |  31 +
 include/net/libeth/stats.h                    | 141 +++++
 include/net/libeth/tx.h                       | 127 +++++
 include/net/libeth/types.h                    | 247 ++++++++
 21 files changed, 1634 insertions(+), 1002 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/libeth/netdev.c
 create mode 100644 drivers/net/ethernet/intel/libeth/priv.h
 create mode 100644 drivers/net/ethernet/intel/libeth/stats.c
 create mode 100644 include/linux/unroll.h
 create mode 100644 include/net/libeth/netdev.h
 create mode 100644 include/net/libeth/stats.h
 create mode 100644 include/net/libeth/tx.h
 create mode 100644 include/net/libeth/types.h
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

PATCH v2 1/9 unroll: add generic loop unroll helpers

From: Alexander Lobakin <[email protected]>

There are cases when we need to explicitly unroll loops. For example, cache operations, filling DMA descriptors on very high speeds etc. Add compiler-specific attribute macros to give the compiler a hint that we'd like to unroll a loop.
Example usage:

#define UNROLL_BATCH 8

	unrolled_count(UNROLL_BATCH)
	for (u32 i = 0; i < UNROLL_BATCH; i++)
		op(priv, i);

Note that sometimes the compilers won't unroll loops if they think this would have worse optimization and perf than without unrolling, and that unroll attributes are available only starting GCC 8. For older compiler versions, no hints/attributes will be applied.
For better unrolling/parallelization, don't have any variables that interfere between iterations except for the iterator itself.

---
 include/linux/unroll.h | 50 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 include/linux/unroll.h
include/linux/unroll.h new file +50 -0
new file mode 100644
index 000000000000..e305d155faa6
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2024 Intel Corporation */
+
+#ifndef _LINUX_UNROLL_H
+#define _LINUX_UNROLL_H
+
+#ifdef CONFIG_CC_IS_CLANG
+#define __pick_unrolled(x, y)	_Pragma(#x)
+#elif CONFIG_GCC_VERSION >= 80000
+#define __pick_unrolled(x, y)	_Pragma(#y)
+#else
+#define __pick_unrolled(x, y)	/* not supported */
+#endif
+
+/**
+ * unrolled - loop attributes to ask the compiler to unroll it
+ *
+ * Usage:
+ *
+ * #define BATCH 4
+ *	unrolled_count(BATCH)
+ *	for (u32 i = 0; i < BATCH; i++)
+ *		// loop body without cross-iteration dependencies
+ *
+ * This is only a hint and the compiler is free to disable unrolling if it
+ * thinks the count is suboptimal and may hurt performance and/or hugely
+ * increase object code size.
+ * Not having any cross-iteration dependencies (i.e. when iter x + 1 depends
+ * on what iter x will do with variables) is not a strict requirement, but
+ * provides best performance and object code size.
+ * Available only on Clang and GCC 8.x onwards.
+ */
+
+/* Ask the compiler to pick an optimal unroll count, Clang only */
+#define unrolled							    \
+	__pick_unrolled(clang loop unroll(enable), /* nothing */)
+
+/* Unroll each @n iterations of a loop */
+#define unrolled_count(n)						    \
+	__pick_unrolled(clang loop unroll_count(n), GCC unroll n)
+
+/* Unroll the whole loop */
+#define unrolled_full							    \
+	__pick_unrolled(clang loop unroll(full), GCC unroll 65534)
+
+/* Never unroll a loop */
+#define unrolled_none							    \
+	__pick_unrolled(clang loop unroll(disable), GCC unroll 1)
+
+#endif /* _LINUX_UNROLL_H */
Signature · 1 line
2.42.0
maintainer
#2 lore raw

Re: [PATCH net-next v2 1/9] unroll: add generic loop unroll helpers

Quoted 12 lines · On Mon, 19 Aug 2024 15:34:33 -0700 Tony Nguyen wrote:

There are cases when we need to explicitly unroll loops. For example, cache operations, filling DMA descriptors on very high speeds etc. Add compiler-specific attribute macros to give the compiler a hint that we'd like to unroll a loop.
Example usage:

#define UNROLL_BATCH 8

	unrolled_count(UNROLL_BATCH)
	for (u32 i = 0; i < UNROLL_BATCH; i++)
		op(priv, i);
Quoted 6 lines

Note that sometimes the compilers won't unroll loops if they think this would have worse optimization and perf than without unrolling, and that unroll attributes are available only starting GCC 8. For older compiler versions, no hints/attributes will be applied.
For better unrolling/parallelization, don't have any variables that interfere between iterations except for the iterator itself.

Please run the submissions thru get_maintainers

#3 lore raw

Re: [PATCH net-next v2 1/9] unroll: add generic loop unroll helpers

From: Jakub Kicinski <[email protected]>
Date: Tue, 20 Aug 2024 17:55:39 -0700

Quoted 13 lines · On Mon, 19 Aug 2024 15:34:33 -0700 Tony Nguyen wrote:
Quoted 12 lines

There are cases when we need to explicitly unroll loops. For example, cache operations, filling DMA descriptors on very high speeds etc. Add compiler-specific attribute macros to give the compiler a hint that we'd like to unroll a loop.
Example usage:

#define UNROLL_BATCH 8

	unrolled_count(UNROLL_BATCH)
	for (u32 i = 0; i < UNROLL_BATCH; i++)
		op(priv, i);
Quoted 8 lines
Quoted 6 lines

Note that sometimes the compilers won't unroll loops if they think this would have worse optimization and perf than without unrolling, and that unroll attributes are available only starting GCC 8. For older compiler versions, no hints/attributes will be applied.
For better unrolling/parallelization, don't have any variables that interfere between iterations except for the iterator itself.

Please run the submissions thru get_maintainers

I always do that. get_maintainers.pl gives nobody for linux/unroll.h.

Thanks,
Olek

maintainer
#4 lore raw

Re: [PATCH net-next v2 1/9] unroll: add generic loop unroll helpers

Quoted 3 lines · On Thu, 22 Aug 2024 17:15:25 +0200 Alexander Lobakin wrote:
Quoted 1 line

Please run the submissions thru get_maintainers

I always do that. get_maintainers.pl gives nobody for linux/unroll.h.

You gotta feed it the *patch*, not the path. For keyword matching on the contents. I wanted to print a warning when people use get_maintainer with a path but Linus blocked it. I'm convinced 99% of such uses are misguided.

But TBH I was directing the message at Tony as well. Please just feed the patches to get_maintainer when posting.

author maintainer
#5 lore raw

Re: [PATCH net-next v2 1/9] unroll: add generic loop unroll helpers

Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Thu, 22 Aug 2024 17:15:25 +0200 Alexander Lobakin wrote:
Quoted 1 line

Please run the submissions thru get_maintainers

I always do that. get_maintainers.pl gives nobody for linux/unroll.h.

Quoted 7 lines

You gotta feed it the *patch*, not the path. For keyword matching on the contents. I wanted to print a warning when people use get_maintainer with a path but Linus blocked it. I'm convinced 99% of such uses are misguided.

But TBH I was directing the message at Tony as well. Please just feed the patches to get_maintainer when posting.

Ack.

Thanks,
Tony

#6 lore raw

Re: [PATCH net-next v2 1/9] unroll: add generic loop unroll helpers

In reply to Jakub Kicinski

From: Jakub Kicinski <[email protected]>
Date: Thu, 22 Aug 2024 15:59:46 -0700

Quoted 6 lines · On Thu, 22 Aug 2024 17:15:25 +0200 Alexander Lobakin wrote:
Quoted 3 lines
Quoted 1 line

Please run the submissions thru get_maintainers

I always do that. get_maintainers.pl gives nobody for linux/unroll.h.

You gotta feed it the *patch*, not the path. For keyword matching on the

Oops, sorry. I always do that for patches, not paths, but here I wanted to use a shortcut not thinking that it may give completely different results =\

Quoted 6 lines

contents. I wanted to print a warning when people use get_maintainer with a path but Linus blocked it. I'm convinced 99% of such uses are misguided.

But TBH I was directing the message at Tony as well. Please just feed the patches to get_maintainer when posting.

Thanks,
Olek

author maintainer
#7 lore raw

PATCH v2 2/9 libeth: add common queue stats

In reply to Tony Nguyen

From: Alexander Lobakin <[email protected]>

Define common structures, inline helpers and Ethtool helpers to collect, update and export the statistics (RQ, SQ, XDPSQ). Use u64_stats_t right from the start, as well as the corresponding helpers to ensure tear-free operations.
For the NAPI parts of both Rx and Tx, also define small onstack containers to update them in polling loops and then sync the actual containers once a loop ends.
In order to implement fully generic Netlink per-queue stats callbacks, &libeth_netdev_priv is introduced and is required to be embedded at the start of the driver's netdev_priv structure.

Note on the stats types:
* onstack stats are u32 and are local to one NAPI loop or sending function. At the end of processing, they get added to the "live" stats below;
* "live" stats are u64_stats_t and they reflect the current session (interface up) only (Netlink queue stats). When an ifdown occurs, they get added to the "base" stats below;
* "base" stats are u64 guarded by a mutex, they survive ifdowns and don't get updated when the interface is up. This corresponds to the Netlink base stats.

Drivers are responsible for filling the onstack stats and calling stack -> live update functions; base stats are internal to libeth.

---
 drivers/net/ethernet/intel/libeth/Makefile |   4 +-
 drivers/net/ethernet/intel/libeth/netdev.c | 157 +++++++++
 drivers/net/ethernet/intel/libeth/priv.h   |  21 ++
 drivers/net/ethernet/intel/libeth/rx.c     |   5 -
 drivers/net/ethernet/intel/libeth/stats.c  | 360 +++++++++++++++++++++
 include/net/libeth/netdev.h                |  31 ++
 include/net/libeth/stats.h                 | 141 ++++++++
 include/net/libeth/types.h                 | 247 ++++++++++++++
 8 files changed, 960 insertions(+), 6 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/libeth/netdev.c
 create mode 100644 drivers/net/ethernet/intel/libeth/priv.h
 create mode 100644 drivers/net/ethernet/intel/libeth/stats.c
 create mode 100644 include/net/libeth/netdev.h
 create mode 100644 include/net/libeth/stats.h
 create mode 100644 include/net/libeth/types.h
drivers/net/ethernet/intel/libeth/Makefile +3 -1
index 52492b081132..b30a2804554f 100644
@@ -3,4 +3,6 @@
 
 obj-$(CONFIG_LIBETH)		+= libeth.o
 
-libeth-y			:= rx.o
+libeth-y			+= netdev.o
+libeth-y			+= rx.o
+libeth-y			+= stats.o
drivers/net/ethernet/intel/libeth/netdev.c new file +157 -0

157 lines not on this page · raw message

drivers/net/ethernet/intel/libeth/priv.h new file +21 -0
new file mode 100644
index 000000000000..6455aab0311c
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2024 Intel Corporation */
+
+#ifndef __LIBETH_PRIV_H
+#define __LIBETH_PRIV_H
+
+#include <linux/types.h>
+
+/* Stats */
+
+struct net_device;
+
+bool libeth_stats_init_priv(struct net_device *dev, u32 rqs, u32 sqs,
+			    u32 xdpsqs);
+void libeth_stats_free_priv(const struct net_device *dev);
+
+int libeth_stats_get_sset_count(struct net_device *dev);
+void libeth_stats_get_strings(struct net_device *dev, u8 *data);
+void libeth_stats_get_data(struct net_device *dev, u64 *data);
+
+#endif /* __LIBETH_PRIV_H */
drivers/net/ethernet/intel/libeth/rx.c +0 -5
index f20926669318..d31779bbfccd 100644
@@ -252,8 +252,3 @@ void libeth_rx_pt_gen_hash_type(struct libeth_rx_pt *pt)
 	pt->hash_type |= libeth_rx_pt_xdp_pl[pt->payload_layer];
 }
 EXPORT_SYMBOL_NS_GPL(libeth_rx_pt_gen_hash_type, LIBETH);
-
-/* Module */
-
-MODULE_DESCRIPTION("Common Ethernet library");
-MODULE_LICENSE("GPL");
drivers/net/ethernet/intel/libeth/stats.c new file +360 -0

360 lines not on this page · raw message

include/net/libeth/netdev.h new file +31 -0
new file mode 100644
index 000000000000..22a07f0b16d7
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2024 Intel Corporation */
+
+#ifndef __LIBETH_NETDEV_H
+#define __LIBETH_NETDEV_H
+
+#include <linux/types.h>
+
+struct ethtool_stats;
+
+struct net_device *__libeth_netdev_alloc(u32 priv, u32 rqs, u32 sqs,
+					 u32 xdpsqs);
+void libeth_netdev_free(struct net_device *dev);
+
+int __libeth_set_real_num_queues(struct net_device *dev, u32 rqs, u32 sqs,
+				 u32 xdpsqs);
+
+#define libeth_netdev_alloc(priv, rqs, sqs, ...)			\
+	__libeth_netdev_alloc(priv, rqs, sqs, (__VA_ARGS__ + 0))
+#define libeth_set_real_num_queues(dev, rqs, sqs, ...)			\
+	__libeth_set_real_num_queues(dev, rqs, sqs, (__VA_ARGS__ + 0))
+
+/* Ethtool */
+
+int libeth_ethtool_get_sset_count(struct net_device *dev, int sset);
+void libeth_ethtool_get_strings(struct net_device *dev, u32 sset, u8 *data);
+void libeth_ethtool_get_stats(struct net_device *dev,
+			      struct ethtool_stats *stats,
+			      u64 *data);
+
+#endif /* __LIBETH_NETDEV_H */
include/net/libeth/stats.h new file +141 -0

141 lines not on this page · raw message

include/net/libeth/types.h new file +247 -0

247 lines not on this page · raw message

Signature · 1 line
2.42.0
maintainer
#8 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Review

Quoted 4 lines · On Mon, 19 Aug 2024 15:34:34 -0700 Tony Nguyen wrote:

+ * Return: new &net_device on success, %NULL on error.
+ */

(quoted diff) +2 -0
+struct net_device *__libeth_netdev_alloc(u32 priv, u32 rqs, u32 sqs,
+					 u32 xdpsqs)

The netdev alloc / free / set num queues can be a separate patch

Quoted 1 line

+MODULE_DESCRIPTION("Common Ethernet library");

BTW for Intel? Or you want this to be part of the core? I thought Intel, but you should tell us if you have broader plans.

drivers/net/ethernet/intel/libeth/stats.c line 82

Quoted 6 lines
drivers/net/ethernet/intel/libeth/stats.c new file +6 -0
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+									      \
+	memset(stats, 0, sizeof(*stats));				      \
+	u64_stats_init(&stats->syncp);					      \
+									      \
+	mutex_init(&priv->base_##pfx##s[qid].lock);			      \

the mutex is only for writes or for reads of base too? mutex is a bad idea for rtnl stats

Quoted 4 lines
drivers/net/ethernet/intel/libeth/stats.c new file +4 -0
+/* Netlink stats. Exported fields have the same names as in the NL structs */
+
+struct libeth_stats_export {
+	u16	li;

drivers/net/ethernet/intel/libeth/stats.c line 156

Quoted 10 lines
drivers/net/ethernet/intel/libeth/stats.c new file +10 -0
+	u16	gi;
+};
+
+#define LIBETH_STATS_EXPORT(lpfx, gpfx, field) {			      \
+	.li = (offsetof(struct libeth_##lpfx##_stats, field) -		      \
+	       offsetof(struct libeth_##lpfx##_stats, raw)) /		      \
+	      sizeof_field(struct libeth_##lpfx##_stats, field),	      \
+	.gi = offsetof(struct netdev_queue_stats_##gpfx, field) /	      \
+	      sizeof_field(struct netdev_queue_stats_##gpfx, field)	      \
+}

humpf

Quoted 11 lines
drivers/net/ethernet/intel/libeth/stats.c new file +11 -0
+#define LIBETH_STATS_DEFINE_EXPORT(pfx, gpfx)				      \
+static void								      \
+libeth_get_queue_stats_##gpfx(struct net_device *dev, int idx,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	const struct libeth_##pfx##_stats *qs;				      \
+	u64 *raw = (u64 *)stats;					      \
+	u32 start;							      \
+									      \
+	qs = READ_ONCE(priv->live_##pfx##s[idx]);			      \

drivers/net/ethernet/intel/libeth/stats.c line 209

Quoted 10 lines
drivers/net/ethernet/intel/libeth/stats.c new file +10 -0
+	if (!qs)							      \
+		return;							      \
+									      \
+	do {								      \
+		start = u64_stats_fetch_begin(&qs->syncp);		      \
+									      \
+		libeth_stats_foreach_export(pfx, exp)			      \
+			raw[exp->gi] = u64_stats_read(&qs->raw[exp->li]);     \
+	} while (u64_stats_fetch_retry(&qs->syncp, start));		      \
+}									      \

ugh. Please no

drivers/net/ethernet/intel/libeth/stats.c line 218

Quoted 9 lines
drivers/net/ethernet/intel/libeth/stats.c new file +9 -0
+									      \
+static void								      \
+libeth_get_##pfx##_base_stats(const struct net_device *dev,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	u64 *raw = (u64 *)stats;					      \
+									      \
+	memset(stats, 0, sizeof(*(stats)));				      \

Have you read the docs for any of the recent stats APIs?

Nack. Just implement the APIs in the driver, this does not seem like a sane starting point _at all_. You're going to waste more time coming up with such abstraction than you'd save implementing it for 10 drivers.

#9 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

From: Jakub Kicinski <[email protected]>
Date: Tue, 20 Aug 2024 18:17:57 -0700

Quoted 7 lines · On Mon, 19 Aug 2024 15:34:34 -0700 Tony Nguyen wrote:

Review

Quoted 4 lines

+ * Return: new &net_device on success, %NULL on error.
+ */

(quoted diff) +2 -0
+struct net_device *__libeth_netdev_alloc(u32 priv, u32 rqs, u32 sqs,
+					 u32 xdpsqs)

The netdev alloc / free / set num queues can be a separate patch

Ok sure.

Quoted 2 lines
Quoted 2 lines

+MODULE_DESCRIPTION("Common Ethernet library");

I just moved this line from libeth/rx.c :D

Quoted 3 lines

BTW for Intel? Or you want this to be part of the core? I thought Intel, but you should tell us if you have broader plans.

For now it's done as a lib inside Intel folder, BUT if any other vendor would like to use this, that would be great and then we could move it level up or some of these APIs can go into the core.
IOW depends on users.

libie in contrary contains HW-specific code and will always be Intel-specific.

Quoted 10 lines

drivers/net/ethernet/intel/libeth/stats.c line 82

Quoted 7 lines
drivers/net/ethernet/intel/libeth/stats.c new file +6 -0
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+									      \
+	memset(stats, 0, sizeof(*stats));				      \
+	u64_stats_init(&stats->syncp);					      \
+									      \
+	mutex_init(&priv->base_##pfx##s[qid].lock);			      \

the mutex is only for writes or for reads of base too? mutex is a bad idea for rtnl stats

Base stats are written only on ifdown, read anytime, mutex is used everywhere.
Hmm maybe a bad idea, what would be better, spinlock or just use u64_sync as well?

Quoted 17 lines
Quoted 5 lines
drivers/net/ethernet/intel/libeth/stats.c new file +4 -0
+/* Netlink stats. Exported fields have the same names as in the NL structs */
+
+struct libeth_stats_export {
+	u16	li;

drivers/net/ethernet/intel/libeth/stats.c line 156

Quoted 10 lines
drivers/net/ethernet/intel/libeth/stats.c new file +10 -0
+	u16	gi;
+};
+
+#define LIBETH_STATS_EXPORT(lpfx, gpfx, field) {			      \
+	.li = (offsetof(struct libeth_##lpfx##_stats, field) -		      \
+	       offsetof(struct libeth_##lpfx##_stats, raw)) /		      \
+	      sizeof_field(struct libeth_##lpfx##_stats, field),	      \
+	.gi = offsetof(struct netdev_queue_stats_##gpfx, field) /	      \
+	      sizeof_field(struct netdev_queue_stats_##gpfx, field)	      \
+}

humpf

Compression :D

Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/intel/libeth/stats.c new file +15 -0
+#define LIBETH_STATS_DEFINE_EXPORT(pfx, gpfx)				      \
+static void								      \
+libeth_get_queue_stats_##gpfx(struct net_device *dev, int idx,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	const struct libeth_##pfx##_stats *qs;				      \
+	u64 *raw = (u64 *)stats;					      \
+	u32 start;							      \
+									      \
+	qs = READ_ONCE(priv->live_##pfx##s[idx]);			      \
+	if (!qs)							      \
+		return;							      \
+									      \
+	do {								      \
Quoted 8 lines

drivers/net/ethernet/intel/libeth/stats.c line 209

Quoted 6 lines
drivers/net/ethernet/intel/libeth/stats.c new file +6 -0
+		start = u64_stats_fetch_begin(&qs->syncp);		      \
+									      \
+		libeth_stats_foreach_export(pfx, exp)			      \
+			raw[exp->gi] = u64_stats_read(&qs->raw[exp->li]);     \
+	} while (u64_stats_fetch_retry(&qs->syncp, start));		      \
+}									      \

ugh. Please no

So you mean just open-code reads/writes per each field than to compress it that way? Sure, that would be no problem. Object code doesn't even change (my first approach was per-field).

Quoted 12 lines

drivers/net/ethernet/intel/libeth/stats.c line 218

Quoted 10 lines
drivers/net/ethernet/intel/libeth/stats.c new file +9 -0
+									      \
+static void								      \
+libeth_get_##pfx##_base_stats(const struct net_device *dev,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	u64 *raw = (u64 *)stats;					      \
+									      \
+	memset(stats, 0, sizeof(*(stats)));				      \

Have you read the docs for any of the recent stats APIs?

You mean to leave 0xffs for unsupported fields?

Quoted 4 lines

Nack. Just implement the APIs in the driver, this does not seem like a sane starting point _at all_. You're going to waste more time coming up with such abstraction than you'd save implementing it for 10 drivers.

I believe this nack is for generic Netlink stats, not the whole, right? In general, I wasn't sure about whether it would be better to leave Netlink stats per driver or write it in libeth, so I wanted to see opinions of others. I'm fine with either way.

Thanks,
Olek

maintainer
#10 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Quoted 10 lines · On Thu, 22 Aug 2024 17:13:57 +0200 Alexander Lobakin wrote:
Quoted 2 lines

BTW for Intel? Or you want this to be part of the core? I thought Intel, but you should tell us if you have broader plans.

For now it's done as a lib inside Intel folder, BUT if any other vendor would like to use this, that would be great and then we could move it level up or some of these APIs can go into the core.
IOW depends on users.

libie in contrary contains HW-specific code and will always be Intel-specific.

Seems like an odd middle ground. If you believe it's generic finding another driver shouldn't be hard.

Quoted 10 lines
Quoted 9 lines

drivers/net/ethernet/intel/libeth/stats.c line 82

Quoted 6 lines
drivers/net/ethernet/intel/libeth/stats.c new file +6 -0
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+									      \
+	memset(stats, 0, sizeof(*stats));				      \
+	u64_stats_init(&stats->syncp);					      \
+									      \
+	mutex_init(&priv->base_##pfx##s[qid].lock);			      \  

the mutex is only for writes or for reads of base too? mutex is a bad idea for rtnl stats

Quoted 4 lines

Base stats are written only on ifdown, read anytime, mutex is used everywhere.
Hmm maybe a bad idea, what would be better, spinlock or just use u64_sync as well?

Depends quite a bit on whether driver uses per queues stats to get rtnl stats. And whether reading of the stats needs to sleep.

Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/intel/libeth/stats.c new file +15 -0
+#define LIBETH_STATS_DEFINE_EXPORT(pfx, gpfx)				      \
+static void								      \
+libeth_get_queue_stats_##gpfx(struct net_device *dev, int idx,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	const struct libeth_##pfx##_stats *qs;				      \
+	u64 *raw = (u64 *)stats;					      \
+	u32 start;							      \
+									      \
+	qs = READ_ONCE(priv->live_##pfx##s[idx]);			      \
+	if (!qs)							      \
+		return;							      \
+									      \
+	do {								      \
Quoted 8 lines

drivers/net/ethernet/intel/libeth/stats.c line 209

Quoted 6 lines
drivers/net/ethernet/intel/libeth/stats.c new file +6 -0
+		start = u64_stats_fetch_begin(&qs->syncp);		      \
+									      \
+		libeth_stats_foreach_export(pfx, exp)			      \
+			raw[exp->gi] = u64_stats_read(&qs->raw[exp->li]);     \
+	} while (u64_stats_fetch_retry(&qs->syncp, start));		      \
+}									      \  

ugh. Please no

Quoted 2 lines

So you mean just open-code reads/writes per each field than to compress it that way?

Yes. <rant> I don't understand why people try to be clever and complicate stats reading for minor LoC saving (almost everyone, including those working on fbnic). Just type the code in -- it makes maintaining it, grepping and adding a new stat without remembering all the details soo much easier. </rant>

Quoted 15 lines

Sure, that would be no problem. Object code doesn't even change (my first approach was per-field).

Quoted 11 lines

drivers/net/ethernet/intel/libeth/stats.c line 218

Quoted 9 lines
drivers/net/ethernet/intel/libeth/stats.c new file +9 -0
+									      \
+static void								      \
+libeth_get_##pfx##_base_stats(const struct net_device *dev,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	u64 *raw = (u64 *)stats;					      \
+									      \
+	memset(stats, 0, sizeof(*(stats)));				      \  

Have you read the docs for any of the recent stats APIs?

Quoted 1 line

You mean to leave 0xffs for unsupported fields?

Kinda of. But also I do mean to call out that you haven't read the doc for the interface over which you're building an abstraction 😵‍💫️

Quoted 8 lines
Quoted 3 lines

Nack. Just implement the APIs in the driver, this does not seem like a sane starting point _at all_. You're going to waste more time coming up with such abstraction than you'd save implementing it for 10 drivers.

I believe this nack is for generic Netlink stats, not the whole, right? In general, I wasn't sure about whether it would be better to leave Netlink stats per driver or write it in libeth, so I wanted to see opinions of others. I'm fine with either way.

We (I?) keep pushing more and more stats into the generic definitions, mostly as I find clear need for them in Meta's monitoring system. My main concern is that if you hide the stats collecting in a library it will make ensuring the consistency of the definition much harder, and it will propagate the use of old APIs (dreaded ethtool -S) into new drivers.

If you have useful helpers that can be broadly applicable that's great. This library as it stands will need a lot of work and a lot of convincing to go in.

#11 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

From: Jakub Kicinski <[email protected]>
Date: Thu, 22 Aug 2024 16:17:18 -0700

Quoted 9 lines · On Thu, 22 Aug 2024 17:13:57 +0200 Alexander Lobakin wrote:
Quoted 8 lines
Quoted 2 lines

BTW for Intel? Or you want this to be part of the core? I thought Intel, but you should tell us if you have broader plans.

For now it's done as a lib inside Intel folder, BUT if any other vendor would like to use this, that would be great and then we could move it level up or some of these APIs can go into the core.
IOW depends on users.

Quoted 5 lines
Quoted 2 lines

libie in contrary contains HW-specific code and will always be Intel-specific.

Seems like an odd middle ground. If you believe it's generic finding another driver shouldn't be hard.

But it's up to the vendors right, I can't force them to use this code or just switch their driver to use it :D

[...]

Quoted 8 lines
Quoted 2 lines

So you mean just open-code reads/writes per each field than to compress it that way?

Yes. <rant> I don't understand why people try to be clever and complicate stats reading for minor LoC saving (almost everyone, including those working on fbnic). Just type the code in -- it makes maintaining it, grepping and adding a new stat without remembering all the details soo much easier. </rant>

In some cases, not this one, iterating over an array means way less object code than open-coded per-field assignment. Just try do that for 50 fields and you'll see.

Quoted 16 lines
Quoted 16 lines

Sure, that would be no problem. Object code doesn't even change (my first approach was per-field).

Quoted 11 lines

drivers/net/ethernet/intel/libeth/stats.c line 218

Quoted 9 lines
drivers/net/ethernet/intel/libeth/stats.c new file +9 -0
+									      \
+static void								      \
+libeth_get_##pfx##_base_stats(const struct net_device *dev,		      \
+			      struct netdev_queue_stats_##gpfx *stats)	      \
+{									      \
+	const struct libeth_netdev_priv *priv = netdev_priv(dev);	      \
+	u64 *raw = (u64 *)stats;					      \
+									      \
+	memset(stats, 0, sizeof(*(stats)));				      \  

Have you read the docs for any of the recent stats APIs?

Quoted 4 lines
Quoted 1 line

You mean to leave 0xffs for unsupported fields?

Kinda of. But also I do mean to call out that you haven't read the doc for the interface over which you're building an abstraction 😵‍💫️

But I have...

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

Nack. Just implement the APIs in the driver, this does not seem like a sane starting point _at all_. You're going to waste more time coming up with such abstraction than you'd save implementing it for 10 drivers.

I believe this nack is for generic Netlink stats, not the whole, right? In general, I wasn't sure about whether it would be better to leave Netlink stats per driver or write it in libeth, so I wanted to see opinions of others. I'm fine with either way.

Quoted 6 lines

We (I?) keep pushing more and more stats into the generic definitions, mostly as I find clear need for them in Meta's monitoring system. My main concern is that if you hide the stats collecting in a library it will make ensuring the consistency of the definition much harder, and it will propagate the use of old APIs (dreaded ethtool -S) into new drivers.

But why should it propagate? People who want to use these generic stats will read the code and see which fields are collected and exported, so that they realize that, for example, packets, bytes and all that stuff are already exported and and they need to export only driver-specific ones...

Or do you mean the thing that this code exports stuff like packets/bytes to ethtool -S apart from the NL stats as well? I'll be happy to remove that for basic Rx/Tx queues (and leave only those which don't exist yet in the NL stats) and when you introduce more fields to NL stats, removing more from ethtool -S in this library will be easy. But let's say what should we do with XDP Tx queues? They're invisible to rtnl as they are past real_num_tx_queues.

Quoted 4 lines

If you have useful helpers that can be broadly applicable that's great. This library as it stands will need a lot of work and a lot of convincing to go in.

Be more precise and I'll rework the stuff you find bad/confusing/etc, excluding the points we discuss above* as I already noted them. Just saying "need a lot of work and a lot of convincing" doesn't help much. You can take a driver as an example (fbnic?) and elaborate why you wouldn't use this lib to implement the stats there.

* implementing NL stats in drivers, not here; not exporting NL stats to ethtool -S

A driver wants to export a field which is missing in the lib? It's a couple lines to add it. Another driver doesn't support this field and you want it to still be 0xff there? Already noted and I'm already implementing a different model.

Thanks,
Olek

maintainer
#12 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Quoted 5 lines · On Fri, 23 Aug 2024 14:59:17 +0200 Alexander Lobakin wrote:
Quoted 5 lines
Quoted 5 lines

For now it's done as a lib inside Intel folder, BUT if any other vendor would like to use this, that would be great and then we could move it level up or some of these APIs can go into the core.
IOW depends on users.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

libie in contrary contains HW-specific code and will always be Intel-specific.

Seems like an odd middle ground. If you believe it's generic finding another driver shouldn't be hard.

But it's up to the vendors right, I can't force them to use this code or just switch their driver to use it :D

It shouldn't be up to interpretation whether the library makes code better. If it doesn't -- what's the point of the library. If it does -- the other vendors better have a solid reason to push back.

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

So you mean just open-code reads/writes per each field than to compress it that way?

Yes. <rant> I don't understand why people try to be clever and complicate stats reading for minor LoC saving (almost everyone, including those working on fbnic). Just type the code in -- it makes maintaining it, grepping and adding a new stat without remembering all the details soo much easier. </rant>

Quoted 3 lines

In some cases, not this one, iterating over an array means way less object code than open-coded per-field assignment. Just try do that for 50 fields and you'll see.

Do you have numbers? How much binary code is 50 simple moves on x86?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You mean to leave 0xffs for unsupported fields?

Kinda of. But also I do mean to call out that you haven't read the doc for the interface over which you're building an abstraction 😵‍💫️

But I have...

Read, or saw it?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I believe this nack is for generic Netlink stats, not the whole, right? In general, I wasn't sure about whether it would be better to leave Netlink stats per driver or write it in libeth, so I wanted to see opinions of others. I'm fine with either way.

Quoted 8 lines
Quoted 6 lines

We (I?) keep pushing more and more stats into the generic definitions, mostly as I find clear need for them in Meta's monitoring system. My main concern is that if you hide the stats collecting in a library it will make ensuring the consistency of the definition much harder, and it will propagate the use of old APIs (dreaded ethtool -S) into new drivers.

But why should it propagate?

I'm saying it shouldn't. The next NIC driver Intel (inevitably :)) creates should not report generic stuff via ethtool -S. If it plugs in your library - it will.

Quoted 8 lines

People who want to use these generic stats
will read the code and see which fields are collected and exported, so that they realize that, for example, packets, bytes and all that stuff are already exported and and they need to export only driver-specific ones...

Or do you mean the thing that this code exports stuff like packets/bytes to ethtool -S apart from the NL stats as well?

Yes, this.

Quoted 4 lines

I'll be happy to remove that for basic Rx/Tx queues (and leave only those which don't exist yet in the NL stats) and when you introduce more fields to NL stats, removing more from ethtool -S in this library will be easy.

I don't scale to remembering 1 easy thing for each driver we have.

Quoted 2 lines

But let's say what should we do with XDP Tx
queues? They're invisible to rtnl as they are past real_num_tx_queues.

They go to ethtool -S today. It should be relatively easy to start reporting them. I didn't add them because I don't have a clear use case at the moment.

Quoted 9 lines
Quoted 3 lines

If you have useful helpers that can be broadly applicable that's great. This library as it stands will need a lot of work and a lot of convincing to go in.

Be more precise and I'll rework the stuff you find bad/confusing/etc, excluding the points we discuss above* as I already noted them. Just saying "need a lot of work and a lot of convincing" doesn't help much. You can take a driver as an example (fbnic?) and elaborate why you wouldn't use this lib to implement the stats there.

The other way around. Why would I? What is this layer of indirection buying us? To add a statistic today I have to plug it into 4 places:
- queue struct
- the place it gets incremented
- the place it gets reported
- aggregation when ring is freed (BUILD_BUG_ON() will remind of this)

This is pretty intuitive and not much work at all. The complexity of the library and how hard it is to read the 200 LoC macros by far outweighs the 2 LoC I can save. Not to mention that I potentially save space on all the stats I'm not implementing.

I'd argue that anything that the library can usefully do can be just moved into the core.

Quoted 7 lines

* implementing NL stats in drivers, not here; not exporting NL stats to ethtool -S

A driver wants to export a field which is missing in the lib? It's a couple lines to add it. Another driver doesn't support this field and you want it to still be 0xff there? Already noted and I'm already implementing a different model.

I think it will be very useful if you could step back and put on paper what your goals are with this work, exactly.

#13 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

From: Jakub Kicinski <[email protected]>
Date: Mon, 26 Aug 2024 18:09:21 -0700

Quoted 12 lines · On Fri, 23 Aug 2024 14:59:17 +0200 Alexander Lobakin wrote:
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

For now it's done as a lib inside Intel folder, BUT if any other vendor would like to use this, that would be great and then we could move it level up or some of these APIs can go into the core.
IOW depends on users.

libie in contrary contains HW-specific code and will always be Intel-specific.

Seems like an odd middle ground. If you believe it's generic finding another driver shouldn't be hard.

Quoted 6 lines
Quoted 2 lines

But it's up to the vendors right, I can't force them to use this code or just switch their driver to use it :D

It shouldn't be up to interpretation whether the library makes code better. If it doesn't -- what's the point of the library. If it does -- the other vendors better have a solid reason to push back.

Potential reasons to push back (by "we" I mean some vendor X):

* we want our names for Ethtool stats, not yours ("txq_X" instead of "sqX" and so on), we have scripts which already parse our names blah
* we have our own infra and we just don't want / have time/resources to refactor and then test since it's not something critical

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

So you mean just open-code reads/writes per each field than to compress it that way?

Yes. <rant> I don't understand why people try to be clever and complicate stats reading for minor LoC saving (almost everyone, including those working on fbnic). Just type the code in -- it makes maintaining it, grepping and adding a new stat without remembering all the details soo much easier. </rant>

Quoted 5 lines
Quoted 3 lines

In some cases, not this one, iterating over an array means way less object code than open-coded per-field assignment. Just try do that for 50 fields and you'll see.

Do you have numbers? How much binary code is 50 simple moves on x86?

	for (u32 i = 0; i < 50; i++)
		structX->field[i] = something * i;

open-coding this loop to assign 50 fields manually gives me +483 bytes of object code on -O2.

But these two lines scale better than adding a new assignment for each new field (and then forget to do that for some field and debug why the stats are incorrect).

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

You mean to leave 0xffs for unsupported fields?

Kinda of. But also I do mean to call out that you haven't read the doc for the interface over which you're building an abstraction 😵‍💫️

But I have...

Read, or saw it?

Something in between these two, but I'll reread since you're insisting.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

I believe this nack is for generic Netlink stats, not the whole, right? In general, I wasn't sure about whether it would be better to leave Netlink stats per driver or write it in libeth, so I wanted to see opinions of others. I'm fine with either way.

We (I?) keep pushing more and more stats into the generic definitions, mostly as I find clear need for them in Meta's monitoring system. My main concern is that if you hide the stats collecting in a library it will make ensuring the consistency of the definition much harder, and it will propagate the use of old APIs (dreaded ethtool -S) into new drivers.

Quoted 3 lines
Quoted 1 line

But why should it propagate?

I'm saying it shouldn't. The next NIC driver Intel (inevitably :))

FYI I already nack inside Intel any new drivers since I was promised that each next generation will be based on top of idpf.

Quoted 9 lines

creates should not report generic stuff via ethtool -S. If it plugs in your library - it will.

Quoted 6 lines

People who want to use these generic stats
will read the code and see which fields are collected and exported, so that they realize that, for example, packets, bytes and all that stuff are already exported and and they need to export only driver-specific ones...

Quoted 4 lines
Quoted 2 lines

Or do you mean the thing that this code exports stuff like packets/bytes to ethtool -S apart from the NL stats as well?

Yes, this.

This was my mistake as generic per-queue NL stats went into the kernel pretty recently... Removing Ethtool counterparts anyway.

Quoted 7 lines
Quoted 5 lines

I'll be happy to remove that for basic Rx/Tx queues (and leave only those which don't exist yet in the NL stats) and when you introduce more fields to NL stats, removing more from ethtool -S in this library will be easy.

I don't scale to remembering 1 easy thing for each driver we have.

Introducing a new field is adding 1 line with its name to the macro since everything else gets expanded from these macros anyway.

Quoted 7 lines
Quoted 3 lines

But let's say what should we do with XDP Tx
queues? They're invisible to rtnl as they are past real_num_tx_queues.

They go to ethtool -S today. It should be relatively easy to start reporting them. I didn't add them because I don't have a clear use case at the moment.

The same as for regular Tx: debugging, imbalance etc.

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines

If you have useful helpers that can be broadly applicable that's great. This library as it stands will need a lot of work and a lot of convincing to go in.

Be more precise and I'll rework the stuff you find bad/confusing/etc, excluding the points we discuss above* as I already noted them. Just saying "need a lot of work and a lot of convincing" doesn't help much. You can take a driver as an example (fbnic?) and elaborate why you wouldn't use this lib to implement the stats there.

Quoted 4 lines

The other way around. Why would I? What is this layer of indirection
buying us? To add a statistic today I have to plug it into 4 places:
- queue struct
- the place it gets incremented> - the place it gets reported> - aggregation when ring is freed

(BUILD_BUG_ON() will remind of this)

Quoted 4 lines

This is pretty intuitive and not much work at all. The complexity of the library and how hard it is to read the 200 LoC macros by far outweighs the 2 LoC I can save. Not to mention that I potentially

See below regarding "2 LoC"

Quoted 1 line

save space on all the stats I'm not implementing.

The stats I introduced here are supported by most, if not every, modern NIC drivers. Not supporting header split or HW GRO will save you 16 bytes on the queue struct which I don't think is a game changer.

Quoted 3 lines

I'd argue that anything that the library can usefully do can be just moved into the core.

I don't say anything from the lib can be easily moved to the core. The library was started to reduce copy-paste between Intel drivers and resides right now inside intel/ folder.
But since this lib doesn't have any HW-specific code I wouldn't mind if any other vendor would start using it, and I don't necessarily mean stats here, but anything he might want to.

Quoted 11 lines
Quoted 8 lines

* implementing NL stats in drivers, not here; not exporting NL stats to ethtool -S

A driver wants to export a field which is missing in the lib? It's a couple lines to add it. Another driver doesn't support this field and you want it to still be 0xff there? Already noted and I'm already implementing a different model.

I think it will be very useful if you could step back and put on paper what your goals are with this work, exactly.

My goals:

* reduce boilerplate code in drivers: declaring stats structures, Ethtool stats names, all these collecting, aggregating etc etc, you see in the last commit of the series how many LoCs get deleted from idpf, +/- the same amount would be removed from any other driver

* reduce the time people debug and fix bugs in stats since it will be just in one place, not in each driver

* have more consistent names in ethtool -S

* have more consistent stats sets in drivers since even within Intel drivers it's a bit of a mess which stats are exported etc.

Most of your pushback here sounds like if I would try to introduce this in the core code, but I don't do that here. This infra saves a lot of locs and time when used in the Intel drivers and it would be totally fine for me if some pieces of the lib goes into the core, but these stats don't.
I didn't declare anywhere that everyone must use it or that it's core code, do you want me to change this MODULE_DESCRIPTION()?

Thanks,
Olek

maintainer
#14 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Quoted 11 lines · On Tue, 27 Aug 2024 17:31:55 +0200 Alexander Lobakin wrote:
Quoted 6 lines
Quoted 2 lines

But it's up to the vendors right, I can't force them to use this code or just switch their driver to use it :D

It shouldn't be up to interpretation whether the library makes code better. If it doesn't -- what's the point of the library. If it does -- the other vendors better have a solid reason to push back.

Potential reasons to push back (by "we" I mean some vendor X):

* we want our names for Ethtool stats, not yours ("txq_X" instead of "sqX" and so on), we have scripts which already parse our names blah

If the stat is standardized in a library why is it dumped via ethtool -S

Quoted 2 lines

* we have our own infra and we just don't want / have time/resources to refactor and then test since it's not something critical

Quite hypothetical.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

In some cases, not this one, iterating over an array means way less object code than open-coded per-field assignment. Just try do that for 50 fields and you'll see.

Do you have numbers? How much binary code is 50 simple moves on x86?

	for (u32 i = 0; i < 50; i++)
		structX->field[i] = something * i;

open-coding this loop to assign 50 fields manually gives me +483 bytes of object code on -O2.

10 bytes per stat then. The stat itself is 8 times number of queues.

Quoted 3 lines

But these two lines scale better than adding a new assignment for each new field (and then forget to do that for some field and debug why the stats are incorrect).

Scale? This is control path code, first prio is for it to be correct, second to be readable.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

But I have...

Read, or saw it?

Something in between these two, but I'll reread since you're insisting.

Please do. Docs for *any* the stats I've added in the last 3 years will do.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

But why should it propagate?

I'm saying it shouldn't. The next NIC driver Intel (inevitably :))

FYI I already nack inside Intel any new drivers since I was promised that each next generation will be based on top of idpf.

I don't mind new drivers, how they get written is a bigger problem, but that's a different discussion.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I'll be happy to remove that for basic Rx/Tx queues (and leave only those which don't exist yet in the NL stats) and when you introduce more fields to NL stats, removing more from ethtool -S in this library will be easy.

I don't scale to remembering 1 easy thing for each driver we have.

Introducing a new field is adding 1 line with its name to the macro since everything else gets expanded from these macros anyway.

Are you saying that people on your team struggle to add a statistic? #1 correctness, #2 readability. LoC only matters indirectly under #2.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But let's say what should we do with XDP Tx
queues? They're invisible to rtnl as they are past real_num_tx_queues.

They go to ethtool -S today. It should be relatively easy to start reporting them. I didn't add them because I don't have a clear use case at the moment.

The same as for regular Tx: debugging, imbalance etc.

I'm not trying to imply they are useless. I just that I, subjectively, don't have a clear use case in Meta's production env.

Quoted 5 lines
Quoted 1 line

save space on all the stats I'm not implementing.

The stats I introduced here are supported by most, if not every, modern NIC drivers. Not supporting header split or HW GRO will save you 16 bytes on the queue struct which I don't think is a game changer.

You don't understand. I built some infra over the last 3 years. You didn't bother reading it. Now you pop our own thing to the side, extending ethtool -S which is _unusable_ in a multi-vendor, production environment.

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

* implementing NL stats in drivers, not here; not exporting NL stats to ethtool -S

A driver wants to export a field which is missing in the lib? It's a couple lines to add it. Another driver doesn't support this field and you want it to still be 0xff there? Already noted and I'm already implementing a different model.

I think it will be very useful if you could step back and put on paper what your goals are with this work, exactly.

Quoted 6 lines

My goals:

* reduce boilerplate code in drivers: declaring stats structures, Ethtool stats names, all these collecting, aggregating etc etc, you see in the last commit of the series how many LoCs get deleted from idpf, +/- the same amount would be removed from any other driver

 21 files changed, 1634 insertions(+), 1002 deletions(-)
Quoted 2 lines

* reduce the time people debug and fix bugs in stats since it will be just in one place, not in each driver

Examples ?

Quoted 1 line

* have more consistent names in ethtool -S

Forget it, better infra exists. Your hack to make stat count "consistent" doesn't work either. Unless you assume only one process can call ethtool -S at a time.

Quoted 2 lines

* have more consistent stats sets in drivers since even within Intel drivers it's a bit of a mess which stats are exported etc.

Consistently undocumented :( qstats exist and are documented.

Quoted 3 lines

Most of your pushback here sounds like if I would try to introduce this in the core code, but I don't do that here. This infra saves a lot of locs

s/saves/may save/ ?

Quoted 5 lines

and time when used in the Intel drivers and it would be totally fine for me if some pieces of the lib goes into the core, but these stats don't.
I didn't declare anywhere that everyone must use it or that it's core code, do you want me to change this MODULE_DESCRIPTION()?

I deeply dislike the macro templating. Complex local systems of this sort make it really painful to do cross-driver changes. It's fine for you because you wrote this, but speaking from experience (mlx5) it makes modifying the driver for an outside much harder.

If you think the core infra is lacking, please improve it instead of inventing your own, buggy one.

#15 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

From: Jakub Kicinski <[email protected]>
Date: Tue, 27 Aug 2024 11:29:33 -0700

Quoted 8 lines · On Tue, 27 Aug 2024 17:31:55 +0200 Alexander Lobakin wrote:
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

But it's up to the vendors right, I can't force them to use this code or just switch their driver to use it :D

It shouldn't be up to interpretation whether the library makes code better. If it doesn't -- what's the point of the library. If it does -- the other vendors better have a solid reason to push back.

Quoted 6 lines
Quoted 4 lines

Potential reasons to push back (by "we" I mean some vendor X):

* we want our names for Ethtool stats, not yours ("txq_X" instead of "sqX" and so on), we have scripts which already parse our names blah

If the stat is standardized in a library why is it dumped via ethtool -S

So do you mean that I need to make these stats generic Netlink instead of adding Ethtool stats?

[...]

Quoted 11 lines
Quoted 2 lines

FYI I already nack inside Intel any new drivers since I was promised that each next generation will be based on top of idpf.

I don't mind new drivers, how they get written is a bigger problem, but that's a different discussion.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I'll be happy to remove that for basic Rx/Tx queues (and leave only those which don't exist yet in the NL stats) and when you introduce more fields to NL stats, removing more from ethtool -S in this library will be easy.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I don't scale to remembering 1 easy thing for each driver we have.

Introducing a new field is adding 1 line with its name to the macro since everything else gets expanded from these macros anyway.

Are you saying that people on your team struggle to add a statistic?

For sure no. I just let the preprocessor do mechanical things instead of manual retyping stuff.

Quoted 1 line

#1 correctness, #2 readability. LoC only matters indirectly under #2.

#1 -- manual retyping is more error-prone?
#2 -- gcc -E ?

Anyway, just side notes, I get what you're saying and partially agree.

Quoted 15 lines
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

But let's say what should we do with XDP Tx
queues? They're invisible to rtnl as they are past real_num_tx_queues.

They go to ethtool -S today. It should be relatively easy to start reporting them. I didn't add them because I don't have a clear use case at the moment.

The same as for regular Tx: debugging, imbalance etc.

I'm not trying to imply they are useless. I just that I, subjectively, don't have a clear use case in Meta's production env.

Quoted 2 lines
Quoted 1 line

save space on all the stats I'm not implementing.

Quoted 8 lines
Quoted 3 lines

The stats I introduced here are supported by most, if not every, modern NIC drivers. Not supporting header split or HW GRO will save you 16 bytes on the queue struct which I don't think is a game changer.

You don't understand. I built some infra over the last 3 years. You didn't bother reading it. Now you pop our own thing to the side, extending ethtool -S which is _unusable_ in a multi-vendor, production environment.

I read everything at the time you introduced it. I remember Ethernet standard stats, rmon, per-queue generic stats etc. I respect it and I like it.
So just let me repeat my question so that all misunderstandings are
gone: did I get it correctly that instead of adding Ethtool stats, I need to add new fields to the per-queue Netlink stats? I clearly don't have any issues with that and I'll be happy to drop Ethtool stats from the lib at all.

(except XDP stats, they still go to ethtool -S for now? Or should I try making them generic as well?)

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

* implementing NL stats in drivers, not here; not exporting NL stats to ethtool -S

A driver wants to export a field which is missing in the lib? It's a couple lines to add it. Another driver doesn't support this field and you want it to still be 0xff there? Already noted and I'm already implementing a different model.

I think it will be very useful if you could step back and put on paper what your goals are with this work, exactly.

Quoted 8 lines
Quoted 6 lines

My goals:

* reduce boilerplate code in drivers: declaring stats structures, Ethtool stats names, all these collecting, aggregating etc etc, you see in the last commit of the series how many LoCs get deleted from idpf, +/- the same amount would be removed from any other driver

 21 files changed, 1634 insertions(+), 1002 deletions(-)

Did you notice my "in the last commit"?

8 changed files with 232 additions and 691 deletions.

Quoted 5 lines
Quoted 3 lines

* reduce the time people debug and fix bugs in stats since it will be just in one place, not in each driver

Examples ?

Eeeh I remember there were commits as between the drivers, the logic to count some stats was inconsistent? But I don't have any links, so this is not an argument. But I also fixed bugs a couple time which were the same in several Intel drivers, that can always happen.

Quoted 10 lines
Quoted 2 lines

* have more consistent names in ethtool -S

Forget it, better infra exists. Your hack to make stat count "consistent" doesn't work either. Unless you assume only one process can call ethtool -S at a time.

Quoted 2 lines

* have more consistent stats sets in drivers since even within Intel drivers it's a bit of a mess which stats are exported etc.

Quoted 7 lines

Consistently undocumented :( qstats exist and are documented.

Quoted 3 lines

Most of your pushback here sounds like if I would try to introduce this in the core code, but I don't do that here. This infra saves a lot of locs

s/saves/may save/ ?

Series for more drivers are in progress, they really remove way more than add.

Quoted 7 lines
Quoted 6 lines

and time when used in the Intel drivers and it would be totally fine for me if some pieces of the lib goes into the core, but these stats don't.
I didn't declare anywhere that everyone must use it or that it's core code, do you want me to change this MODULE_DESCRIPTION()?

Quoted 7 lines

I deeply dislike the macro templating. Complex local systems of this sort make it really painful to do cross-driver changes. It's fine for you because you wrote this, but speaking from experience (mlx5) it makes modifying the driver for an outside much harder.

If you think the core infra is lacking, please improve it instead of inventing your own, buggy one.

Don't get me wrong, I did it via Ethtool not because I don't like your infra or so, strongly the opposite. Maybe it was just something like "I did it thousand times so I automatically did this that way for the 1001th time", or just because I wanted to deduplicate the Intel code and there, all the stats are in the Ethtool only, dunno =\

Thanks,
Olek

maintainer
#16 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Quoted 9 lines · On Wed, 28 Aug 2024 17:06:17 +0200 Alexander Lobakin wrote:
Quoted 8 lines
Quoted 3 lines

The stats I introduced here are supported by most, if not every, modern NIC drivers. Not supporting header split or HW GRO will save you 16 bytes on the queue struct which I don't think is a game changer.

You don't understand. I built some infra over the last 3 years. You didn't bother reading it. Now you pop our own thing to the side, extending ethtool -S which is _unusable_ in a multi-vendor, production environment.

Quoted 8 lines

I read everything at the time you introduced it. I remember Ethernet standard stats, rmon, per-queue generic stats etc. I respect it and I like it.
So just let me repeat my question so that all misunderstandings are
gone: did I get it correctly that instead of adding Ethtool stats, I need to add new fields to the per-queue Netlink stats? I clearly don't have any issues with that and I'll be happy to drop Ethtool stats from the lib at all.

That's half of it, the other half is excess of macro magic.

Quoted 2 lines

(except XDP stats, they still go to ethtool -S for now? Or should I try making them generic as well?)

Either way is fine by me. You may want to float the XDP stats first as a smaller series, just extending the spec and exposing from some driver already implementing qstat. In case someone else does object.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

* reduce boilerplate code in drivers: declaring stats structures, Ethtool stats names, all these collecting, aggregating etc etc, you see in the last commit of the series how many LoCs get deleted from idpf, +/- the same amount would be removed from any other driver

 21 files changed, 1634 insertions(+), 1002 deletions(-)  

Did you notice my "in the last commit"?

I may not have. But as you said, most drivers end up with some level of boilerplate around stats. So unless the stuff is used by more than one driver, and the savings are realized, the argument about saving LoC has to be heavily discounted. Queue xkcd 927. I should reiterate that I don't think LoC saving is a strong argument in the first place.

#17 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

From: Jakub Kicinski <[email protected]>
Date: Wed, 28 Aug 2024 13:22:35 -0700

Quoted 19 lines · On Wed, 28 Aug 2024 17:06:17 +0200 Alexander Lobakin wrote:
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

The stats I introduced here are supported by most, if not every, modern NIC drivers. Not supporting header split or HW GRO will save you 16 bytes on the queue struct which I don't think is a game changer.

You don't understand. I built some infra over the last 3 years. You didn't bother reading it. Now you pop our own thing to the side, extending ethtool -S which is _unusable_ in a multi-vendor, production environment.

Quoted 8 lines

I read everything at the time you introduced it. I remember Ethernet standard stats, rmon, per-queue generic stats etc. I respect it and I like it.
So just let me repeat my question so that all misunderstandings are
gone: did I get it correctly that instead of adding Ethtool stats, I need to add new fields to the per-queue Netlink stats? I clearly don't have any issues with that and I'll be happy to drop Ethtool stats from the lib at all.

Quoted 8 lines

That's half of it, the other half is excess of macro magic.

Quoted 2 lines

(except XDP stats, they still go to ethtool -S for now? Or should I try making them generic as well?)

Either way is fine by me. You may want to float the XDP stats first as a smaller series, just extending the spec and exposing from some driver already implementing qstat. In case someone else does object.

I think I'll do that the following way. To not delay this series and XDP for idpf in general, I'll drop these stats for now, leaving only onstack containers (they will be used in libeth_xdp etc.), without the macro magic. But at the same time I'll work on extending the NL queue stats, incl. XDP ones, and send them separately when they're done. Would that be fine?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

* reduce boilerplate code in drivers: declaring stats structures, Ethtool stats names, all these collecting, aggregating etc etc, you see in the last commit of the series how many LoCs get deleted from idpf, +/- the same amount would be removed from any other driver

 21 files changed, 1634 insertions(+), 1002 deletions(-)  
Quoted 7 lines
Quoted 1 line

Did you notice my "in the last commit"?

I may not have. But as you said, most drivers end up with some level of boilerplate around stats. So unless the stuff is used by more than one driver, and the savings are realized, the argument about saving LoC has to be heavily discounted. Queue xkcd 927. I should reiterate that I don't think LoC saving is a strong argument in the first place.

Yes, I got that. In general, you're right this hurts readability a lot.

Thanks,
Olek

maintainer
#18 lore raw

Re: [PATCH net-next v2 2/9] libeth: add common queue stats

Quoted 10 lines · On Thu, 29 Aug 2024 14:01:06 +0200 Alexander Lobakin wrote:
Quoted 3 lines

Either way is fine by me. You may want to float the XDP stats first as a smaller series, just extending the spec and exposing from some driver already implementing qstat. In case someone else does object.

I think I'll do that the following way. To not delay this series and XDP for idpf in general, I'll drop these stats for now, leaving only onstack containers (they will be used in libeth_xdp etc.), without the macro magic. But at the same time I'll work on extending the NL queue stats, incl. XDP ones, and send them separately when they're done. Would that be fine?

Modulo implementation details -- SGTM!

author maintainer
#19 lore raw

PATCH v2 3/9 libie: add Tx buffer completion helpers

In reply to Tony Nguyen

From: Alexander Lobakin <[email protected]>

Software-side Tx buffers for storing DMA, frame size, skb pointers etc. are pretty much generic and every driver defines them the same way. The same can be said for software Tx completions -- same napi_consume_skb()s and all that...
Add a couple simple wrappers for doing that to stop repeating the old tale at least within the Intel code. Drivers are free to use 'priv' member at the end of the structure.

---
 include/net/libeth/tx.h | 127 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100644 include/net/libeth/tx.h
include/net/libeth/tx.h new file +127 -0
new file mode 100644
index 000000000000..facfeca96858
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2024 Intel Corporation */
+
+#ifndef __LIBETH_TX_H
+#define __LIBETH_TX_H
+
+#include <net/libeth/stats.h>
+
+/* Tx buffer completion */
+
+/**
+ * enum libeth_sqe_type - type of &libeth_sqe to act on Tx completion
+ * @LIBETH_SQE_EMPTY: unused/empty, no action required
+ * @LIBETH_SQE_CTX: context descriptor with empty SQE, no action required
+ * @LIBETH_SQE_SLAB: kmalloc-allocated buffer, unmap and kfree()
+ * @LIBETH_SQE_FRAG: mapped skb frag, only unmap DMA
+ * @LIBETH_SQE_SKB: &sk_buff, unmap and napi_consume_skb(), update stats
+ */
+enum libeth_sqe_type {
+	LIBETH_SQE_EMPTY		= 0U,
+	LIBETH_SQE_CTX,
+	LIBETH_SQE_SLAB,
+	LIBETH_SQE_FRAG,
+	LIBETH_SQE_SKB,
+};
+
+/**
+ * struct libeth_sqe - represents a Send Queue Element / Tx buffer
+ * @type: type of the buffer, see the enum above
+ * @rs_idx: index of the last buffer from the batch this one was sent in
+ * @raw: slab buffer to free via kfree()
+ * @skb: &sk_buff to consume
+ * @dma: DMA address to unmap
+ * @len: length of the mapped region to unmap
+ * @nr_frags: number of frags in the frame this buffer belongs to
+ * @packets: number of physical packets sent for this frame
+ * @bytes: number of physical bytes sent for this frame
+ * @priv: driver-private scratchpad
+ */
+struct libeth_sqe {
+	enum libeth_sqe_type		type:32;
+	u32				rs_idx;
+
+	union {
+		void				*raw;
+		struct sk_buff			*skb;
+	};
+
+	DEFINE_DMA_UNMAP_ADDR(dma);
+	DEFINE_DMA_UNMAP_LEN(len);
+
+	u32				nr_frags;
+	u32				packets;
+	u32				bytes;
+
+	unsigned long			priv;
+} __aligned_largest;
+
+/**
+ * LIBETH_SQE_CHECK_PRIV - check the driver's private SQE data
+ * @p: type or name of the object the driver wants to fit into &libeth_sqe
+ *
+ * Make sure the driver's private data fits into libeth_sqe::priv. To be used
+ * right after its declaration.
+ */
+#define LIBETH_SQE_CHECK_PRIV(p)					  \
+	static_assert(sizeof(p) <= sizeof_field(struct libeth_sqe, priv))
+
+/**
+ * struct libeth_cq_pp - completion queue poll params
+ * @dev: &device to perform DMA unmapping
+ * @ss: onstack NAPI stats to fill
+ * @napi: whether it's called from the NAPI context
+ *
+ * libeth uses this structure to access objects needed for performing full
+ * Tx complete operation without passing lots of arguments and change the
+ * prototypes each time a new one is added.
+ */
+struct libeth_cq_pp {
+	struct device			*dev;
+	struct libeth_sq_napi_stats	*ss;
+
+	bool				napi;
+};
+
+/**
+ * libeth_tx_complete - perform Tx completion for one SQE
+ * @sqe: SQE to complete
+ * @cp: poll params
+ *
+ * Do Tx complete for all the types of buffers, incl. freeing, unmapping,
+ * updating the stats etc.
+ */
+static inline void libeth_tx_complete(struct libeth_sqe *sqe,
+				      const struct libeth_cq_pp *cp)
+{
+	switch (sqe->type) {
+	case LIBETH_SQE_EMPTY:
+		return;
+	case LIBETH_SQE_SKB:
+	case LIBETH_SQE_FRAG:
+	case LIBETH_SQE_SLAB:
+		dma_unmap_page(cp->dev, dma_unmap_addr(sqe, dma),
+			       dma_unmap_len(sqe, len), DMA_TO_DEVICE);
+		break;
+	default:
+		break;
+	}
+
+	switch (sqe->type) {
+	case LIBETH_SQE_SKB:
+		cp->ss->packets += sqe->packets;
+		cp->ss->bytes += sqe->bytes;
+
+		napi_consume_skb(sqe->skb, cp->napi);
+		break;
+	case LIBETH_SQE_SLAB:
+		kfree(sqe->raw);
+		break;
+	default:
+		break;
+	}
+
+	sqe->type = LIBETH_SQE_EMPTY;
+}
+
+#endif /* __LIBETH_TX_H */
Signature · 1 line
2.42.0
author maintainer
#20 lore raw

PATCH v2 4/9 idpf: convert to libie Tx buffer completion

In reply to Tony Nguyen

From: Alexander Lobakin <[email protected]>

&idpf_tx_buffer is almost identical to the previous generations, as well as the way it's handled. Moreover, relying on dma_unmap_addr() and !!buf->skb instead of explicit defining of buffer's type was never good. Use the newly added libeth helpers to do it properly and reduce the copy-paste around the Tx code.

---
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  82 +++-----
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 195 ++++++------------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   |  50 +----
 3 files changed, 101 insertions(+), 226 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +30 -52
index fe64febf7436..98f26a4b835f 100644
@@ -2,6 +2,7 @@
 /* Copyright (C) 2023 Intel Corporation */
 
 #include <net/libeth/rx.h>
+#include <net/libeth/tx.h>
 
 #include "idpf.h"
 
@@ -224,6 +225,7 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 		/* record length, and DMA address */
 		dma_unmap_len_set(tx_buf, len, size);
 		dma_unmap_addr_set(tx_buf, dma, dma);
+		tx_buf->type = LIBETH_SQE_FRAG;
 
 		/* align size to end of page */
 		max_data += -dma & (IDPF_TX_MAX_READ_REQ_SIZE - 1);
@@ -245,6 +247,8 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 				i = 0;
 			}
 
+			tx_q->tx_buf[i].type = LIBETH_SQE_EMPTY;
+
 			dma += max_data;
 			size -= max_data;
 
@@ -282,13 +286,13 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 	tx_desc->qw1 = idpf_tx_singleq_build_ctob(td_cmd, offsets,
 						  size, td_tag);
 
-	IDPF_SINGLEQ_BUMP_RING_IDX(tx_q, i);
+	first->type = LIBETH_SQE_SKB;
+	first->rs_idx = i;
 
-	/* set next_to_watch value indicating a packet is present */
-	first->next_to_watch = tx_desc;
+	IDPF_SINGLEQ_BUMP_RING_IDX(tx_q, i);
 
 	nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
-	netdev_tx_sent_queue(nq, first->bytecount);
+	netdev_tx_sent_queue(nq, first->bytes);
 
 	idpf_tx_buf_hw_update(tx_q, i, netdev_xmit_more());
 }
@@ -306,8 +310,7 @@ idpf_tx_singleq_get_ctx_desc(struct idpf_tx_queue *txq)
 	struct idpf_base_tx_ctx_desc *ctx_desc;
 	int ntu = txq->next_to_use;
 
-	memset(&txq->tx_buf[ntu], 0, sizeof(struct idpf_tx_buf));
-	txq->tx_buf[ntu].ctx_entry = true;
+	txq->tx_buf[ntu].type = LIBETH_SQE_CTX;
 
 	ctx_desc = &txq->base_ctx[ntu];
 
@@ -396,11 +399,11 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb,
 	first->skb = skb;
 
 	if (tso) {
-		first->gso_segs = offload.tso_segs;
-		first->bytecount = skb->len + ((first->gso_segs - 1) * offload.tso_hdr_len);
+		first->packets = offload.tso_segs;
+		first->bytes = skb->len + ((first->packets - 1) * offload.tso_hdr_len);
 	} else {
-		first->bytecount = max_t(unsigned int, skb->len, ETH_ZLEN);
-		first->gso_segs = 1;
+		first->bytes = max_t(unsigned int, skb->len, ETH_ZLEN);
+		first->packets = 1;
 	}
 	idpf_tx_singleq_map(tx_q, first, &offload);
 
@@ -420,10 +423,15 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb,
 static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 				  int *cleaned)
 {
-	unsigned int total_bytes = 0, total_pkts = 0;
+	struct libeth_sq_napi_stats ss = { };
 	struct idpf_base_tx_desc *tx_desc;
 	u32 budget = tx_q->clean_budget;
 	s16 ntc = tx_q->next_to_clean;
+	struct libeth_cq_pp cp = {
+		.dev	= tx_q->dev,
+		.ss	= &ss,
+		.napi	= napi_budget,
+	};
 	struct idpf_netdev_priv *np;
 	struct idpf_tx_buf *tx_buf;
 	struct netdev_queue *nq;
@@ -441,47 +449,23 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 		 * such. We can skip this descriptor since there is no buffer
 		 * to clean.
 		 */
-		if (tx_buf->ctx_entry) {
-			/* Clear this flag here to avoid stale flag values when
-			 * this buffer is used for actual data in the future.
-			 * There are cases where the tx_buf struct / the flags
-			 * field will not be cleared before being reused.
-			 */
-			tx_buf->ctx_entry = false;
+		if (unlikely(tx_buf->type <= LIBETH_SQE_CTX)) {
+			tx_buf->type = LIBETH_SQE_EMPTY;
 			goto fetch_next_txq_desc;
 		}
 
-		/* if next_to_watch is not set then no work pending */
-		eop_desc = (struct idpf_base_tx_desc *)tx_buf->next_to_watch;
-		if (!eop_desc)
-			break;
-
-		/* prevent any other reads prior to eop_desc */
+		/* prevent any other reads prior to type */
 		smp_rmb();
 
+		eop_desc = &tx_q->base_tx[tx_buf->rs_idx];
+
 		/* if the descriptor isn't done, no work yet to do */
 		if (!(eop_desc->qw1 &
 		      cpu_to_le64(IDPF_TX_DESC_DTYPE_DESC_DONE)))
 			break;
 
-		/* clear next_to_watch to prevent false hangs */
-		tx_buf->next_to_watch = NULL;
-
 		/* update the statistics for this packet */
-		total_bytes += tx_buf->bytecount;
-		total_pkts += tx_buf->gso_segs;
-
-		napi_consume_skb(tx_buf->skb, napi_budget);
-
-		/* unmap skb header data */
-		dma_unmap_single(tx_q->dev,
-				 dma_unmap_addr(tx_buf, dma),
-				 dma_unmap_len(tx_buf, len),
-				 DMA_TO_DEVICE);
-
-		/* clear tx_buf data */
-		tx_buf->skb = NULL;
-		dma_unmap_len_set(tx_buf, len, 0);
+		libeth_tx_complete(tx_buf, &cp);
 
 		/* unmap remaining buffers */
 		while (tx_desc != eop_desc) {
@@ -495,13 +479,7 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 			}
 
 			/* unmap any remaining paged data */
-			if (dma_unmap_len(tx_buf, len)) {
-				dma_unmap_page(tx_q->dev,
-					       dma_unmap_addr(tx_buf, dma),
-					       dma_unmap_len(tx_buf, len),
-					       DMA_TO_DEVICE);
-				dma_unmap_len_set(tx_buf, len, 0);
-			}
+			libeth_tx_complete(tx_buf, &cp);
 		}
 
 		/* update budget only if we did something */
@@ -521,11 +499,11 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 	ntc += tx_q->desc_count;
 	tx_q->next_to_clean = ntc;
 
-	*cleaned += total_pkts;
+	*cleaned += ss.packets;
 
 	u64_stats_update_begin(&tx_q->stats_sync);
-	u64_stats_add(&tx_q->q_stats.packets, total_pkts);
-	u64_stats_add(&tx_q->q_stats.bytes, total_bytes);
+	u64_stats_add(&tx_q->q_stats.packets, ss.packets);
+	u64_stats_add(&tx_q->q_stats.bytes, ss.bytes);
 	u64_stats_update_end(&tx_q->stats_sync);
 
 	np = netdev_priv(tx_q->netdev);
@@ -533,7 +511,7 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 
 	dont_wake = np->state != __IDPF_VPORT_UP ||
 		    !netif_carrier_ok(tx_q->netdev);
-	__netif_txq_completed_wake(nq, total_pkts, total_bytes,
+	__netif_txq_completed_wake(nq, ss.packets, ss.bytes,
 				   IDPF_DESC_UNUSED(tx_q), IDPF_TX_WAKE_THRESH,
 				   dont_wake);
 
drivers/net/ethernet/intel/idpf/idpf_txrx.c +68 -127

355 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_txrx.h +3 -47

74 lines not on this page · raw message

Signature · 1 line
2.42.0
author maintainer
#21 lore raw

PATCH v2 5/9 netdevice: add netdev_tx_reset_subqueue() shorthand

In reply to Tony Nguyen

From: Alexander Lobakin <[email protected]>

Add a shorthand similar to other net*_subqueue() helpers for resetting the queue by its index w/o obtaining &netdev_tx_queue beforehand manually.

---
 include/linux/netdevice.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
include/linux/netdevice.h +12 -1
index 0ef3eaa23f4b..22a4adff8bb2 100644
@@ -3545,6 +3545,17 @@ static inline void netdev_tx_reset_queue(struct netdev_queue *q)
 #endif
 }
 
+/**
+ * netdev_tx_reset_subqueue - reset the BQL stats and state of a netdev queue
+ * @dev: network device
+ * @qid: stack index of the queue to reset
+ */
+static inline void netdev_tx_reset_subqueue(const struct net_device *dev,
+					    u32 qid)
+{
+	netdev_tx_reset_queue(netdev_get_tx_queue(dev, qid));
+}
+
 /**
  * 	netdev_reset_queue - reset the packets and bytes count of a network device
  * 	@dev_queue: network device
@@ -3554,7 +3565,7 @@ static inline void netdev_tx_reset_queue(struct netdev_queue *q)
  */
 static inline void netdev_reset_queue(struct net_device *dev_queue)
 {
-	netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
+	netdev_tx_reset_subqueue(dev_queue, 0);
 }
 
 /**
Signature · 1 line
2.42.0
author maintainer
#22 lore raw

PATCH v2 6/9 idpf: refactor Tx completion routines

In reply to Tony Nguyen

From: Joshua Hay <[email protected]>

Add a mechanism to guard against stashing partial packets into the hash table to make the driver more robust, with more efficient decision making when cleaning.

Don't stash partial packets. This can happen when an RE (Report Event) completion is received in flow scheduling mode, or when an out of order RS (Report Status) completion is received. The first buffer with the skb is stashed, but some or all of its frags are not because the stack is out of reserve buffers. This leaves the ring in a weird state since the frags are still on the ring.

Use the field libeth_sqe::nr_frags to track the number of fragments/tx_bufs representing the packet. The clean routines check to make sure there are enough reserve buffers on the stack before stashing any part of the packet. If there are not, next_to_clean is left pointing to the first buffer of the packet that failed to be stashed. This leaves the whole packet on the ring, and the next time around, cleaning will start from this packet.

An RS completion is still expected for this packet in either case. So instead of being cleaned from the hash table, it will be cleaned from the ring directly. This should all still be fine since the DESC_UNUSED and BUFS_UNUSED will reflect the state of the ring. If we ever fall below the thresholds, the TxQ will still be stopped, giving the completion queue time to catch up. This may lead to stopping the queue more frequently, but it guarantees the Tx ring will always be in a good state.

Also, always use the idpf_tx_splitq_clean function to clean descriptors, i.e. use it from clean_buf_ring as well. This way we avoid duplicating the logic and make sure we're using the same reserve buffers guard rail.

This does require a switch from the s16 next_to_clean overflow descriptor ring wrap calculation to u16 and the normal ring size check.

---
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  24 +--
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 164 +++++++++++-------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   |   6 +-
 3 files changed, 118 insertions(+), 76 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +14 -10
index 98f26a4b835f..947d3ff9677c 100644
@@ -239,15 +239,16 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 								  offsets,
 								  max_data,
 								  td_tag);
-			tx_desc++;
-			i++;
-
-			if (i == tx_q->desc_count) {
+			if (unlikely(++i == tx_q->desc_count)) {
+				tx_buf = &tx_q->tx_buf[0];
 				tx_desc = &tx_q->base_tx[0];
 				i = 0;
+			} else {
+				tx_buf++;
+				tx_desc++;
 			}
 
-			tx_q->tx_buf[i].type = LIBETH_SQE_EMPTY;
+			tx_buf->type = LIBETH_SQE_EMPTY;
 
 			dma += max_data;
 			size -= max_data;
@@ -261,12 +262,14 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 
 		tx_desc->qw1 = idpf_tx_singleq_build_ctob(td_cmd, offsets,
 							  size, td_tag);
-		tx_desc++;
-		i++;
 
-		if (i == tx_q->desc_count) {
+		if (unlikely(++i == tx_q->desc_count)) {
+			tx_buf = &tx_q->tx_buf[0];
 			tx_desc = &tx_q->base_tx[0];
 			i = 0;
+		} else {
+			tx_buf++;
+			tx_desc++;
 		}
 
 		size = skb_frag_size(frag);
@@ -274,8 +277,6 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
 
 		dma = skb_frag_dma_map(tx_q->dev, frag, 0, size,
 				       DMA_TO_DEVICE);
-
-		tx_buf = &tx_q->tx_buf[i];
 	}
 
 	skb_tx_timestamp(first->skb);
@@ -454,6 +455,9 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 			goto fetch_next_txq_desc;
 		}
 
+		if (unlikely(tx_buf->type != LIBETH_SQE_SKB))
+			break;
+
 		/* prevent any other reads prior to type */
 		smp_rmb();
 
drivers/net/ethernet/intel/idpf/idpf_txrx.c +101 -63

339 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_txrx.h +3 -3
index fa87754c7340..2478f71adb95 100644
@@ -127,7 +127,7 @@ do {								\
  */
 #define IDPF_TX_COMPLQ_PENDING(txq)	\
 	(((txq)->num_completions_pending >= (txq)->complq->num_completions ? \
-	0 : U64_MAX) + \
+	0 : U32_MAX) + \
 	(txq)->num_completions_pending - (txq)->complq->num_completions)
 
 #define IDPF_TX_SPLITQ_COMPL_TAG_WIDTH	16
@@ -787,7 +787,7 @@ struct idpf_compl_queue {
 	u32 next_to_use;
 	u32 next_to_clean;
 
-	u32 num_completions;
+	aligned_u64 num_completions;
 	__cacheline_group_end_aligned(read_write);
 
 	__cacheline_group_begin_aligned(cold);
@@ -919,7 +919,7 @@ struct idpf_txq_group {
 
 	struct idpf_compl_queue *complq;
 
-	u32 num_completions_pending;
+	aligned_u64 num_completions_pending;
 };
 
 static inline int idpf_q_vector_to_mem(const struct idpf_q_vector *q_vector)
Signature · 1 line
2.42.0
author maintainer
#23 lore raw

PATCH v2 7/9 idpf: fix netdev Tx queue stop/wake

In reply to Tony Nguyen

From: Michal Kubiak <[email protected]>

netif_txq_maybe_stop() returns -1, 0, or 1, while idpf_tx_maybe_stop_common() says it returns 0 or -EBUSY. As a result, there sometimes are Tx queue timeout warnings despite that the queue is empty or there is at least enough space to restart it. Make idpf_tx_maybe_stop_common() inline and returning true or false, handling the return of netif_txq_maybe_stop() properly. Use a correct goto in idpf_tx_maybe_stop_splitq() to avoid stopping the queue or incrementing the stops counter twice.

Fixes 6818c4d5b3c2 ("idpf: add splitq start_xmit")
Fixes a5ab9ee0df0b ("idpf: add singleq start_xmit and napi poll")
---
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  4 +++
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 35 +++++--------------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   |  9 ++++-
 3 files changed, 21 insertions(+), 27 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +4 -0
index 947d3ff9677c..5ba360abbe66 100644
@@ -375,6 +375,10 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb,
 				      IDPF_TX_DESCS_FOR_CTX)) {
 		idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false);
 
+		u64_stats_update_begin(&tx_q->stats_sync);
+		u64_stats_inc(&tx_q->q_stats.q_busy);
+		u64_stats_update_end(&tx_q->stats_sync);
+
 		return NETDEV_TX_BUSY;
 	}
 
drivers/net/ethernet/intel/idpf/idpf_txrx.c +9 -26
index c1df4341e9ab..60f875decd8a 100644
@@ -2128,29 +2128,6 @@ void idpf_tx_splitq_build_flow_desc(union idpf_tx_flex_desc *desc,
 	desc->flow.qw1.compl_tag = cpu_to_le16(params->compl_tag);
 }
 
-/**
- * idpf_tx_maybe_stop_common - 1st level check for common Tx stop conditions
- * @tx_q: the queue to be checked
- * @size: number of descriptors we want to assure is available
- *
- * Returns 0 if stop is not needed
- */
-int idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q, unsigned int size)
-{
-	struct netdev_queue *nq;
-
-	if (likely(IDPF_DESC_UNUSED(tx_q) >= size))
-		return 0;
-
-	u64_stats_update_begin(&tx_q->stats_sync);
-	u64_stats_inc(&tx_q->q_stats.q_busy);
-	u64_stats_update_end(&tx_q->stats_sync);
-
-	nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
-
-	return netif_txq_maybe_stop(nq, IDPF_DESC_UNUSED(tx_q), size, size);
-}
-
 /**
  * idpf_tx_maybe_stop_splitq - 1st level check for Tx splitq stop conditions
  * @tx_q: the queue to be checked
@@ -2162,7 +2139,7 @@ static int idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q,
 				     unsigned int descs_needed)
 {
 	if (idpf_tx_maybe_stop_common(tx_q, descs_needed))
-		goto splitq_stop;
+		goto out;
 
 	/* If there are too many outstanding completions expected on the
 	 * completion queue, stop the TX queue to give the device some time to
@@ -2181,10 +2158,12 @@ static int idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q,
 	return 0;
 
 splitq_stop:
+	netif_stop_subqueue(tx_q->netdev, tx_q->idx);
+
+out:
 	u64_stats_update_begin(&tx_q->stats_sync);
 	u64_stats_inc(&tx_q->q_stats.q_busy);
 	u64_stats_update_end(&tx_q->stats_sync);
-	netif_stop_subqueue(tx_q->netdev, tx_q->idx);
 
 	return -EBUSY;
 }
@@ -2207,7 +2186,11 @@ void idpf_tx_buf_hw_update(struct idpf_tx_queue *tx_q, u32 val,
 	nq = netdev_get_tx_queue(tx_q->netdev, tx_q->idx);
 	tx_q->next_to_use = val;
 
-	idpf_tx_maybe_stop_common(tx_q, IDPF_TX_DESC_NEEDED);
+	if (idpf_tx_maybe_stop_common(tx_q, IDPF_TX_DESC_NEEDED)) {
+		u64_stats_update_begin(&tx_q->stats_sync);
+		u64_stats_inc(&tx_q->q_stats.q_busy);
+		u64_stats_update_end(&tx_q->stats_sync);
+	}
 
 	/* Force memory writes to complete before letting h/w
 	 * know there are new descriptors to fetch.  (Only
drivers/net/ethernet/intel/idpf/idpf_txrx.h +8 -1
index 2478f71adb95..df3574ac58c2 100644
@@ -1020,7 +1020,6 @@ void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb,
 			   struct idpf_tx_buf *first, u16 ring_idx);
 unsigned int idpf_tx_desc_count_required(struct idpf_tx_queue *txq,
 					 struct sk_buff *skb);
-int idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q, unsigned int size);
 void idpf_tx_timeout(struct net_device *netdev, unsigned int txqueue);
 netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb,
 				  struct idpf_tx_queue *tx_q);
@@ -1029,4 +1028,12 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rxq,
 				      u16 cleaned_count);
 int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off);
 
+static inline bool idpf_tx_maybe_stop_common(struct idpf_tx_queue *tx_q,
+					     u32 needed)
+{
+	return !netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx,
+					  IDPF_DESC_UNUSED(tx_q),
+					  needed, needed);
+}
+
 #endif /* !_IDPF_TXRX_H_ */
Signature · 1 line
2.42.0
author maintainer
#24 lore raw

PATCH v2 8/9 idpf: enable WB_ON_ITR

In reply to Tony Nguyen

From: Joshua Hay <[email protected]>

Tell hardware to write back completed descriptors even when interrupts are disabled. Otherwise, descriptors might not be written back until the hardware can flush a full cacheline of descriptors. This can cause unnecessary delays when traffic is light (or even trigger Tx queue timeout).

The example scenario to reproduce the Tx timeout if the fix is not applied:
- configure at least 2 Tx queues to be assigned to the same q_vector,
- generate a huge Tx traffic on the first Tx queue
- try to send a few packets using the second Tx queue.
In such a case Tx timeout will appear on the second Tx queue because no completion descriptors are written back for that queue while interrupts are disabled due to NAPI polling.

Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")
Fixes a5ab9ee0df0b ("idpf: add singleq start_xmit and napi poll")
---
 drivers/net/ethernet/intel/idpf/idpf_dev.c    |  2 ++
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  6 ++++-
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   |  7 ++++-
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   | 27 ++++++++++++++++++-
 drivers/net/ethernet/intel/idpf/idpf_vf_dev.c |  2 ++
 5 files changed, 41 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_dev.c +2 -0
index 3df9935685e9..6c913a703df6 100644
@@ -97,8 +97,10 @@ static int idpf_intr_reg_init(struct idpf_vport *vport)
 		intr->dyn_ctl = idpf_get_reg_addr(adapter,
 						  reg_vals[vec_id].dyn_ctl_reg);
 		intr->dyn_ctl_intena_m = PF_GLINT_DYN_CTL_INTENA_M;
+		intr->dyn_ctl_intena_msk_m = PF_GLINT_DYN_CTL_INTENA_MSK_M;
 		intr->dyn_ctl_itridx_s = PF_GLINT_DYN_CTL_ITR_INDX_S;
 		intr->dyn_ctl_intrvl_s = PF_GLINT_DYN_CTL_INTERVAL_S;
+		intr->dyn_ctl_wb_on_itr_m = PF_GLINT_DYN_CTL_WB_ON_ITR_M;
 
 		spacing = IDPF_ITR_IDX_SPACING(reg_vals[vec_id].itrn_index_spacing,
 					       IDPF_PF_ITR_IDX_SPACING);
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +5 -1
index 5ba360abbe66..dfd7cf1d9aa0 100644
@@ -1120,8 +1120,10 @@ int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget)
 						    &work_done);
 
 	/* If work not completed, return budget and polling will return */
-	if (!clean_complete)
+	if (!clean_complete) {
+		idpf_vport_intr_set_wb_on_itr(q_vector);
 		return budget;
+	}
 
 	work_done = min_t(int, work_done, budget - 1);
 
@@ -1130,6 +1132,8 @@ int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget)
 	 */
 	if (likely(napi_complete_done(napi, work_done)))
 		idpf_vport_intr_update_itr_ena_irq(q_vector);
+	else
+		idpf_vport_intr_set_wb_on_itr(q_vector);
 
 	return work_done;
 }
drivers/net/ethernet/intel/idpf/idpf_txrx.c +6 -1
index 60f875decd8a..c60f3f917226 100644
@@ -3711,6 +3711,7 @@ void idpf_vport_intr_update_itr_ena_irq(struct idpf_q_vector *q_vector)
 	/* net_dim() updates ITR out-of-band using a work item */
 	idpf_net_dim(q_vector);
 
+	q_vector->wb_on_itr = false;
 	intval = idpf_vport_intr_buildreg_itr(q_vector,
 					      IDPF_NO_ITR_UPDATE_IDX, 0);
 
@@ -4013,8 +4014,10 @@ static int idpf_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 	clean_complete &= idpf_tx_splitq_clean_all(q_vector, budget, &work_done);
 
 	/* If work not completed, return budget and polling will return */
-	if (!clean_complete)
+	if (!clean_complete) {
+		idpf_vport_intr_set_wb_on_itr(q_vector);
 		return budget;
+	}
 
 	work_done = min_t(int, work_done, budget - 1);
 
@@ -4023,6 +4026,8 @@ static int idpf_vport_splitq_napi_poll(struct napi_struct *napi, int budget)
 	 */
 	if (likely(napi_complete_done(napi, work_done)))
 		idpf_vport_intr_update_itr_ena_irq(q_vector);
+	else
+		idpf_vport_intr_set_wb_on_itr(q_vector);
 
 	/* Switch to poll mode in the tear-down path after sending disable
 	 * queues virtchnl message, as the interrupts will be disabled after
drivers/net/ethernet/intel/idpf/idpf_txrx.h +26 -1
index df3574ac58c2..b4a87f8661a8 100644
@@ -349,9 +349,11 @@ struct idpf_vec_regs {
  * struct idpf_intr_reg
  * @dyn_ctl: Dynamic control interrupt register
  * @dyn_ctl_intena_m: Mask for dyn_ctl interrupt enable
+ * @dyn_ctl_intena_msk_m: Mask for dyn_ctl interrupt enable mask
  * @dyn_ctl_itridx_s: Register bit offset for ITR index
  * @dyn_ctl_itridx_m: Mask for ITR index
  * @dyn_ctl_intrvl_s: Register bit offset for ITR interval
+ * @dyn_ctl_wb_on_itr_m: Mask for WB on ITR feature
  * @rx_itr: RX ITR register
  * @tx_itr: TX ITR register
  * @icr_ena: Interrupt cause register offset
@@ -360,9 +362,11 @@ struct idpf_vec_regs {
 struct idpf_intr_reg {
 	void __iomem *dyn_ctl;
 	u32 dyn_ctl_intena_m;
+	u32 dyn_ctl_intena_msk_m;
 	u32 dyn_ctl_itridx_s;
 	u32 dyn_ctl_itridx_m;
 	u32 dyn_ctl_intrvl_s;
+	u32 dyn_ctl_wb_on_itr_m;
 	void __iomem *rx_itr;
 	void __iomem *tx_itr;
 	void __iomem *icr_ena;
@@ -383,6 +387,7 @@ struct idpf_intr_reg {
  * @intr_reg: See struct idpf_intr_reg
  * @napi: napi handler
  * @total_events: Number of interrupts processed
+ * @wb_on_itr: WB on ITR enabled or not
  * @tx_dim: Data for TX net_dim algorithm
  * @tx_itr_value: TX interrupt throttling rate
  * @tx_intr_mode: Dynamic ITR or not
@@ -413,6 +418,7 @@ struct idpf_q_vector {
 	__cacheline_group_begin_aligned(read_write);
 	struct napi_struct napi;
 	u16 total_events;
+	bool wb_on_itr;
 
 	struct dim tx_dim;
 	u16 tx_itr_value;
@@ -431,7 +437,7 @@ struct idpf_q_vector {
 	cpumask_var_t affinity_mask;
 	__cacheline_group_end_aligned(cold);
 };
-libeth_cacheline_set_assert(struct idpf_q_vector, 104,
+libeth_cacheline_set_assert(struct idpf_q_vector, 112,
 			    424 + 2 * sizeof(struct dim),
 			    8 + sizeof(cpumask_var_t));
 
@@ -989,6 +995,25 @@ static inline void idpf_tx_splitq_build_desc(union idpf_tx_flex_desc *desc,
 		idpf_tx_splitq_build_flow_desc(desc, params, td_cmd, size);
 }
 
+/**
+ * idpf_vport_intr_set_wb_on_itr - enable descriptor writeback on disabled interrupts
+ * @q_vector: pointer to queue vector struct
+ */
+static inline void idpf_vport_intr_set_wb_on_itr(struct idpf_q_vector *q_vector)
+{
+	struct idpf_intr_reg *reg;
+
+	if (q_vector->wb_on_itr)
+		return;
+
+	q_vector->wb_on_itr = true;
+	reg = &q_vector->intr_reg;
+
+	writel(reg->dyn_ctl_wb_on_itr_m | reg->dyn_ctl_intena_msk_m |
+	       (IDPF_NO_ITR_UPDATE_IDX << reg->dyn_ctl_itridx_s),
+	       reg->dyn_ctl);
+}
+
 int idpf_vport_singleq_napi_poll(struct napi_struct *napi, int budget);
 void idpf_vport_init_num_qs(struct idpf_vport *vport,
 			    struct virtchnl2_create_vport *vport_msg);
drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +2 -0
index 629cb5cb7c9f..99b8dbaf4225 100644
@@ -97,7 +97,9 @@ static int idpf_vf_intr_reg_init(struct idpf_vport *vport)
 		intr->dyn_ctl = idpf_get_reg_addr(adapter,
 						  reg_vals[vec_id].dyn_ctl_reg);
 		intr->dyn_ctl_intena_m = VF_INT_DYN_CTLN_INTENA_M;
+		intr->dyn_ctl_intena_msk_m = VF_INT_DYN_CTLN_INTENA_MSK_M;
 		intr->dyn_ctl_itridx_s = VF_INT_DYN_CTLN_ITR_INDX_S;
+		intr->dyn_ctl_wb_on_itr_m = VF_INT_DYN_CTLN_WB_ON_ITR_M;
 
 		spacing = IDPF_ITR_IDX_SPACING(reg_vals[vec_id].itrn_index_spacing,
 					       IDPF_VF_ITR_IDX_SPACING);
Signature · 1 line
2.42.0
author maintainer
#25 lore raw

PATCH v2 9/9 idpf: switch to libeth generic statistics

In reply to Tony Nguyen

From: Alexander Lobakin <[email protected]>

Fully reimplement idpf's per-queue stats using the libeth infra. Embed &libeth_netdev_priv to the beginning of &idpf_netdev_priv(), call the necessary init/deinit helpers and the corresponding Ethtool helpers.
Update hotpath counters such as hsplit and tso/gso using the onstack containers instead of direct accesses to queue->stats.

---
 drivers/net/ethernet/intel/idpf/idpf.h        |  21 +-
 .../net/ethernet/intel/idpf/idpf_ethtool.c    | 498 ++----------------
 drivers/net/ethernet/intel/idpf/idpf_lib.c    |  32 +-
 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  76 +--
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 172 +++---
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   |  54 +-
 .../net/ethernet/intel/idpf/idpf_virtchnl.c   |  37 +-
 drivers/net/ethernet/intel/idpf/virtchnl2.h   |  33 +-
 8 files changed, 232 insertions(+), 691 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +6 -15
index 2c31ad87587a..7df35ec7302c 100644
@@ -138,6 +138,7 @@ enum idpf_vport_state {
 
 /**
  * struct idpf_netdev_priv - Struct to store vport back pointer
+ * @priv: libeth private structure
  * @adapter: Adapter back pointer
  * @vport: Vport back pointer
  * @vport_id: Vport identifier
@@ -147,6 +148,8 @@ enum idpf_vport_state {
  * @stats_lock: Lock to protect stats update
  */
 struct idpf_netdev_priv {
+	struct libeth_netdev_priv priv;
+
 	struct idpf_adapter *adapter;
 	struct idpf_vport *vport;
 	u32 vport_id;
@@ -155,6 +158,7 @@ struct idpf_netdev_priv {
 	struct rtnl_link_stats64 netstats;
 	spinlock_t stats_lock;
 };
+libeth_netdev_priv_assert(struct idpf_netdev_priv, priv);
 
 /**
  * struct idpf_reset_reg - Reset register offsets/masks
@@ -232,19 +236,6 @@ enum idpf_vport_flags {
 	IDPF_VPORT_FLAGS_NBITS,
 };
 
-struct idpf_port_stats {
-	struct u64_stats_sync stats_sync;
-	u64_stats_t rx_hw_csum_err;
-	u64_stats_t rx_hsplit;
-	u64_stats_t rx_hsplit_hbo;
-	u64_stats_t rx_bad_descs;
-	u64_stats_t tx_linearize;
-	u64_stats_t tx_busy;
-	u64_stats_t tx_drops;
-	u64_stats_t tx_dma_map_errs;
-	struct virtchnl2_vport_stats vport_stats;
-};
-
 /**
  * struct idpf_vport - Handle for netdevices and queue resources
  * @num_txq: Number of allocated TX queues
@@ -285,7 +276,7 @@ struct idpf_port_stats {
  * @default_mac_addr: device will give a default MAC to use
  * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation
  * @tx_itr_profile: TX profiles for Dynamic Interrupt Moderation
- * @port_stats: per port csum, header split, and other offload stats
+ * @vport_stats: vport stats reported by HW
  * @link_up: True if link is up
  * @link_speed_mbps: Link speed in mbps
  * @sw_marker_wq: workqueue for marker packets
@@ -328,7 +319,7 @@ struct idpf_vport {
 	u8 default_mac_addr[ETH_ALEN];
 	u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
 	u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
-	struct idpf_port_stats port_stats;
+	struct virtchnl2_vport_stats vport_stats;
 
 	bool link_up;
 	u32 link_speed_mbps;
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +37 -461

559 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_lib.c +9 -23
index 4f20343e49a9..26cc2f13331b 100644
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /* Copyright (C) 2023 Intel Corporation */
 
+#include <net/libeth/netdev.h>
+
 #include "idpf.h"
 #include "idpf_virtchnl.h"
 
@@ -726,9 +728,9 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)
 		return idpf_init_mac_addr(vport, netdev);
 	}
 
-	netdev = alloc_etherdev_mqs(sizeof(struct idpf_netdev_priv),
-				    vport_config->max_q.max_txq,
-				    vport_config->max_q.max_rxq);
+	netdev = libeth_netdev_alloc(sizeof(struct idpf_netdev_priv),
+				     vport_config->max_q.max_rxq,
+				     vport_config->max_q.max_txq);
 	if (!netdev)
 		return -ENOMEM;
 
@@ -743,7 +745,7 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)
 
 	err = idpf_init_mac_addr(vport, netdev);
 	if (err) {
-		free_netdev(vport->netdev);
+		libeth_netdev_free(vport->netdev);
 		vport->netdev = NULL;
 
 		return err;
@@ -932,7 +934,7 @@ static void idpf_decfg_netdev(struct idpf_vport *vport)
 	vport->rx_ptype_lkup = NULL;
 
 	unregister_netdev(vport->netdev);
-	free_netdev(vport->netdev);
+	libeth_netdev_free(vport->netdev);
 	vport->netdev = NULL;
 
 	adapter->netdevs[vport->idx] = NULL;
@@ -1253,23 +1255,6 @@ static void idpf_restore_features(struct idpf_vport *vport)
 		idpf_restore_mac_filters(vport);
 }
 
-/**
- * idpf_set_real_num_queues - set number of queues for netdev
- * @vport: virtual port structure
- *
- * Returns 0 on success, negative on failure.
- */
-static int idpf_set_real_num_queues(struct idpf_vport *vport)
-{
-	int err;
-
-	err = netif_set_real_num_rx_queues(vport->netdev, vport->num_rxq);
-	if (err)
-		return err;
-
-	return netif_set_real_num_tx_queues(vport->netdev, vport->num_txq);
-}
-
 /**
  * idpf_up_complete - Complete interface up sequence
  * @vport: virtual port structure
@@ -1911,7 +1896,8 @@ int idpf_initiate_soft_reset(struct idpf_vport *vport,
 	if (reset_cause == IDPF_SR_Q_CHANGE)
 		idpf_vport_alloc_vec_indexes(vport);
 
-	err = idpf_set_real_num_queues(vport);
+	err = libeth_set_real_num_queues(vport->netdev, vport->num_rxq,
+					 vport->num_txq);
 	if (err)
 		goto err_open;
 
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +39 -37

212 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_txrx.c +90 -82

474 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_txrx.h +16 -38

118 lines not on this page · raw message

drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +17 -20
index 70986e12da28..3fcc8ac70b74 100644
@@ -2292,47 +2292,44 @@ int idpf_send_set_sriov_vfs_msg(struct idpf_adapter *adapter, u16 num_vfs)
  */
 int idpf_send_get_stats_msg(struct idpf_vport *vport)
 {
+	struct virtchnl2_vport_stats *stats_msg = &vport->vport_stats;
 	struct idpf_netdev_priv *np = netdev_priv(vport->netdev);
 	struct rtnl_link_stats64 *netstats = &np->netstats;
-	struct virtchnl2_vport_stats stats_msg = {};
 	struct idpf_vc_xn_params xn_params = {};
 	ssize_t reply_sz;
 
-
 	/* Don't send get_stats message if the link is down */
 	if (np->state <= __IDPF_VPORT_DOWN)
 		return 0;
 
-	stats_msg.vport_id = cpu_to_le32(vport->vport_id);
+	stats_msg->vport_id = cpu_to_le32(vport->vport_id);
 
 	xn_params.vc_op = VIRTCHNL2_OP_GET_STATS;
-	xn_params.send_buf.iov_base = &stats_msg;
-	xn_params.send_buf.iov_len = sizeof(stats_msg);
+	xn_params.send_buf.iov_base = stats_msg;
+	xn_params.send_buf.iov_len = sizeof(*stats_msg);
 	xn_params.recv_buf = xn_params.send_buf;
 	xn_params.timeout_ms = IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC;
 
 	reply_sz = idpf_vc_xn_exec(vport->adapter, &xn_params);
 	if (reply_sz < 0)
 		return reply_sz;
-	if (reply_sz < sizeof(stats_msg))
+	if (reply_sz < sizeof(*stats_msg))
 		return -EIO;
 
 	spin_lock_bh(&np->stats_lock);
 
-	netstats->rx_packets = le64_to_cpu(stats_msg.rx_unicast) +
-			       le64_to_cpu(stats_msg.rx_multicast) +
-			       le64_to_cpu(stats_msg.rx_broadcast);
-	netstats->tx_packets = le64_to_cpu(stats_msg.tx_unicast) +
-			       le64_to_cpu(stats_msg.tx_multicast) +
-			       le64_to_cpu(stats_msg.tx_broadcast);
-	netstats->rx_bytes = le64_to_cpu(stats_msg.rx_bytes);
-	netstats->tx_bytes = le64_to_cpu(stats_msg.tx_bytes);
-	netstats->rx_errors = le64_to_cpu(stats_msg.rx_errors);
-	netstats->tx_errors = le64_to_cpu(stats_msg.tx_errors);
-	netstats->rx_dropped = le64_to_cpu(stats_msg.rx_discards);
-	netstats->tx_dropped = le64_to_cpu(stats_msg.tx_discards);
-
-	vport->port_stats.vport_stats = stats_msg;
+	netstats->rx_packets = le64_to_cpu(stats_msg->rx_unicast) +
+			       le64_to_cpu(stats_msg->rx_multicast) +
+			       le64_to_cpu(stats_msg->rx_broadcast);
+	netstats->tx_packets = le64_to_cpu(stats_msg->tx_unicast) +
+			       le64_to_cpu(stats_msg->tx_multicast) +
+			       le64_to_cpu(stats_msg->tx_broadcast);
+	netstats->rx_bytes = le64_to_cpu(stats_msg->rx_bytes);
+	netstats->tx_bytes = le64_to_cpu(stats_msg->tx_bytes);
+	netstats->rx_errors = le64_to_cpu(stats_msg->rx_errors);
+	netstats->tx_errors = le64_to_cpu(stats_msg->tx_errors);
+	netstats->rx_dropped = le64_to_cpu(stats_msg->rx_discards);
+	netstats->tx_dropped = le64_to_cpu(stats_msg->tx_discards);
 
 	spin_unlock_bh(&np->stats_lock);
 
drivers/net/ethernet/intel/idpf/virtchnl2.h +18 -15
index 63deb120359c..19d62cfc17be 100644
@@ -1021,6 +1021,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_get_ptype_info);
  * struct virtchnl2_vport_stats - Vport statistics.
  * @vport_id: Vport id.
  * @pad: Padding.
+ * @counters: grouped counters for bulk operations
  * @rx_bytes: Received bytes.
  * @rx_unicast: Received unicast packets.
  * @rx_multicast: Received multicast packets.
@@ -1045,21 +1046,23 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_get_ptype_info);
 struct virtchnl2_vport_stats {
 	__le32 vport_id;
 	u8 pad[4];
-	__le64 rx_bytes;
-	__le64 rx_unicast;
-	__le64 rx_multicast;
-	__le64 rx_broadcast;
-	__le64 rx_discards;
-	__le64 rx_errors;
-	__le64 rx_unknown_protocol;
-	__le64 tx_bytes;
-	__le64 tx_unicast;
-	__le64 tx_multicast;
-	__le64 tx_broadcast;
-	__le64 tx_discards;
-	__le64 tx_errors;
-	__le64 rx_invalid_frame_length;
-	__le64 rx_overflow_drop;
+	struct_group(counters,
+		__le64 rx_bytes;
+		__le64 rx_unicast;
+		__le64 rx_multicast;
+		__le64 rx_broadcast;
+		__le64 rx_discards;
+		__le64 rx_errors;
+		__le64 rx_unknown_protocol;
+		__le64 tx_bytes;
+		__le64 tx_unicast;
+		__le64 tx_multicast;
+		__le64 tx_broadcast;
+		__le64 tx_discards;
+		__le64 tx_errors;
+		__le64 rx_invalid_frame_length;
+		__le64 rx_overflow_drop;
+	);
 };
 VIRTCHNL2_CHECK_STRUCT_LEN(128, virtchnl2_vport_stats);
 
Signature · 1 line
2.42.0