net: intel: start The Great Code Dedup + Page Pool for iavf
Subsystems (11)
Alexander Lobakin
maintainerv3 cover net: intel: start The Great Code Dedup + Page Pool for iavf
Here's a two-shot: introduce Intel Ethernet common library (libie) and switch iavf to Page Pool. Details in the commit messages; here's summary:
Not a secret there's a ton of code duplication between two and more Intel ethernet modules. Before introducing new changes, which would need to be copied over again, start decoupling the already existing duplicate functionality into a new module, which will be shared between several Intel Ethernet drivers.
The first thing that came to my mind was "libie" -- "Intel Ethernet common library". Also this sounds like "lovelie" and can be expanded as "lib Internet Explorer" :P I'm open for anything else (but justified). The series is only the beginning. From now on, adding every new feature or doing any good driver refactoring will remove much more lines than add for quite some time. There's a basic roadmap with some deduplications planned already, not speaking of that touching every line now asks: "can I share this?".
PP conversion for iavf lands within the same series as these two are tied closely. libie will support Page Pool model only, so a driver can't use much of the lib until it's converted. iavf is only the example, the rest will eventually be converted soon on a per-driver basis. That is when it gets really interesting. Stay tech.
Alexander Lobakin (12):
net: intel: introduce Intel Ethernet common library
iavf: kill "legacy-rx" for good
iavf: optimize Rx buffer allocation a bunch
iavf: remove page splitting/recycling
iavf: always use a full order-0 page
net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h>
net: page_pool: avoid calling no-op externals when possible
net: page_pool: add DMA-sync-for-CPU inline helpers
iavf: switch to Page Pool
libie: add common queue stats
libie: add per-queue Page Pool stats
iavf: switch queue stats to libie
MAINTAINERS | 3 +- drivers/net/ethernet/engleder/tsnep_main.c | 1 + drivers/net/ethernet/freescale/fec_main.c | 1 + drivers/net/ethernet/intel/Kconfig | 12 +- drivers/net/ethernet/intel/Makefile | 1 + drivers/net/ethernet/intel/i40e/i40e_common.c | 253 ------- drivers/net/ethernet/intel/i40e/i40e_main.c | 1 + .../net/ethernet/intel/i40e/i40e_prototype.h | 7 - drivers/net/ethernet/intel/i40e/i40e_txrx.c | 74 +- drivers/net/ethernet/intel/i40e/i40e_type.h | 88 --- drivers/net/ethernet/intel/iavf/iavf.h | 2 +- drivers/net/ethernet/intel/iavf/iavf_common.c | 253 ------- .../net/ethernet/intel/iavf/iavf_ethtool.c | 227 +----- drivers/net/ethernet/intel/iavf/iavf_main.c | 45 +- .../net/ethernet/intel/iavf/iavf_prototype.h | 7 - drivers/net/ethernet/intel/iavf/iavf_txrx.c | 715 +++++------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 185 +---- drivers/net/ethernet/intel/iavf/iavf_type.h | 90 --- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 16 +- .../net/ethernet/intel/ice/ice_lan_tx_rx.h | 316 -------- drivers/net/ethernet/intel/ice/ice_main.c | 1 + drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 74 +- drivers/net/ethernet/intel/libie/Makefile | 7 + drivers/net/ethernet/intel/libie/internal.h | 23 + drivers/net/ethernet/intel/libie/rx.c | 158 ++++ drivers/net/ethernet/intel/libie/stats.c | 190 +++++ .../marvell/octeontx2/nic/otx2_common.c | 1 + .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + .../ethernet/mellanox/mlx5/core/en/params.c | 1 + .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 1 + include/linux/net/intel/libie/rx.h | 170 +++++ include/linux/net/intel/libie/stats.h | 214 ++++++ include/linux/skbuff.h | 4 +- include/net/page_pool.h | 69 +- net/core/page_pool.c | 10 + 36 files changed, 1141 insertions(+), 2081 deletions(-) create mode 100644 drivers/net/ethernet/intel/libie/Makefile create mode 100644 drivers/net/ethernet/intel/libie/internal.h create mode 100644 drivers/net/ethernet/intel/libie/rx.c create mode 100644 drivers/net/ethernet/intel/libie/stats.c create mode 100644 include/linux/net/intel/libie/rx.h create mode 100644 include/linux/net/intel/libie/stats.h
---
Directly to net-next, has non-Intel code changes (0006-0008).
From v2[0]:
* 0006: fix page_pool.h include in OcteonTX2 files (Jakub, Patchwork);
* no functional changes.
From v1[1]:
* 0006: new (me, Jakub);
* 0008: give the helpers more intuitive names (Jakub, Ilias);
* -^-: also expand their kdoc a bit for the same reason;
* -^-: fix kdoc copy-paste issue (Patchwork, Jakub);
* 0011: drop inline from C file (Patchwork, Jakub).
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://lore.kernel.org/netdev/[email protected]
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 1/12 net: intel: introduce Intel Ethernet common library
Not a secret there's a ton of code duplication between two and more Intel ethernet modules.
Before introducing new changes, which would need to be copied over again, start decoupling the already existing duplicate functionality into a new module, which will be shared between several Intel Ethernet drivers. Add the lookup table which converts 8/10-bit hardware packet type into a parsed bitfield structure for easy checking packet format parameters, such as payload level, IP version, etc. This is currently used by i40e, ice and iavf and it's all the same in all three drivers.
The only difference introduced in this implementation is that instead of defining a 256 (or 1024 in case of ice) element array, add unlikely() condition to limit the input to 154 (current maximum non-reserved packet type). There's no reason to waste 600 (or even 3600) bytes only to not hurt very unlikely exception packets.
The hash computation function now takes payload level directly as a pkt_hash_type. There's a couple cases when non-IP ptypes are marked as L3 payload and in the previous versions their hash level would be 2, not
3. But skb_set_hash() only sees difference between L4 and non-L4, thus this won't change anything at all.
The module is behind the hidden Kconfig symbol, which the drivers will select when needed. The exports are behind 'LIBIE' namespace to limit the scope of the functions.
--- MAINTAINERS | 3 +- drivers/net/ethernet/intel/Kconfig | 11 +- drivers/net/ethernet/intel/Makefile | 1 + drivers/net/ethernet/intel/i40e/i40e_common.c | 253 -------------- drivers/net/ethernet/intel/i40e/i40e_main.c | 1 + .../net/ethernet/intel/i40e/i40e_prototype.h | 7 - drivers/net/ethernet/intel/i40e/i40e_txrx.c | 74 +--- drivers/net/ethernet/intel/i40e/i40e_type.h | 88 ----- drivers/net/ethernet/intel/iavf/iavf_common.c | 253 -------------- drivers/net/ethernet/intel/iavf/iavf_main.c | 1 + .../net/ethernet/intel/iavf/iavf_prototype.h | 7 - drivers/net/ethernet/intel/iavf/iavf_txrx.c | 70 +--- drivers/net/ethernet/intel/iavf/iavf_type.h | 88 ----- .../net/ethernet/intel/ice/ice_lan_tx_rx.h | 316 ------------------ drivers/net/ethernet/intel/ice/ice_main.c | 1 + drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 74 +--- drivers/net/ethernet/intel/libie/Makefile | 6 + drivers/net/ethernet/intel/libie/rx.c | 110 ++++++ include/linux/net/intel/libie/rx.h | 128 +++++++ 19 files changed, 312 insertions(+), 1180 deletions(-) create mode 100644 drivers/net/ethernet/intel/libie/Makefile create mode 100644 drivers/net/ethernet/intel/libie/rx.c create mode 100644 include/linux/net/intel/libie/rx.h
MAINTAINERS +2 -1
@@ -10340,7 +10340,8 @@ F: Documentation/networking/device_drivers/ethernet/intel/ F: drivers/net/ethernet/intel/ F: drivers/net/ethernet/intel/*/ F: include/linux/avf/virtchnl.h -F: include/linux/net/intel/iidc.h +F: include/linux/net/intel/ +F: include/linux/net/intel/*/ INTEL ETHERNET PROTOCOL DRIVER FOR RDMA M: Mustafa Ismail <[email protected]>
drivers/net/ethernet/intel/Kconfig +10 -1
@@ -84,6 +84,12 @@ config E1000E_HWTS devices. The cross-timestamp is available through the PTP clock driver precise cross-timestamp ioctl (PTP_SYS_OFFSET_PRECISE). +config LIBIE + tristate + help + libie (Intel Ethernet library) is a common library containing + routines shared by several Intel Ethernet drivers. + config IGB tristate "Intel(R) 82575/82576 PCI-Express Gigabit Ethernet support" depends on PCI
@@ -225,6 +231,7 @@ config I40E depends on PTP_1588_CLOCK_OPTIONAL depends on PCI select AUXILIARY_BUS + select LIBIE help This driver supports Intel(R) Ethernet Controller XL710 Family of devices. For more information on how to identify your adapter, go
@@ -254,8 +261,9 @@ config IAVF tristate config I40EVF tristate "Intel(R) Ethernet Adaptive Virtual Function support" - select IAVF depends on PCI_MSI + select IAVF + select LIBIE help This driver supports virtual functions for Intel XL710, X710, X722, XXV710, and all devices advertising support for
@@ -282,6 +290,7 @@ config ICE depends on GNSS || GNSS = n select AUXILIARY_BUS select DIMLIB + select LIBIE select NET_DEVLINK select PLDMFW help
drivers/net/ethernet/intel/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_I40E) += i40e/ obj-$(CONFIG_IAVF) += iavf/ obj-$(CONFIG_FM10K) += fm10k/ obj-$(CONFIG_ICE) += ice/ +obj-$(CONFIG_LIBIE) += libie/
drivers/net/ethernet/intel/i40e/i40e_common.c +0 -253
259 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -0
@@ -97,6 +97,7 @@ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXXMODULE_AUTHOR ("Intel Corporation, <[email protected]>" );MODULE_DESCRIPTION ("Intel(R) Ethernet Connection XL710 Network Driver" ); +MODULE_IMPORT_NS (LIBIE );MODULE_LICENSE ("GPL v2" );static struct workqueue_struct *i40e_wq;
drivers/net/ethernet/intel/i40e/i40e_prototype.h +0 -7
@@ -380,13 +380,6 @@ void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status);int i40e_set_mac_type (struct i40e_hw *hw); -extern struct i40e_rx_ptype_decoded i40e_ptype_lookup[]; - -static inline struct i40e_rx_ptype_decoded decode_rx_desc_ptype (u8 ptype) -{ -return i40e_ptype_lookup[ptype]; -} -/** * i40e_virtchnl_link_speed - Convert AdminQ link_speed to virtchnl definition * @link_speed: the speed to convert
drivers/net/ethernet/intel/i40e/i40e_txrx.c +18 -56
132 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_type.h +0 -88
94 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_common.c +0 -253
259 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -0
@@ -46,6 +46,7 @@ MODULE_DEVICE_TABLE(pci, iavf_pci_tbl);MODULE_ALIAS ("i40evf" );MODULE_AUTHOR ("Intel Corporation, <[email protected]>" );MODULE_DESCRIPTION ("Intel(R) Ethernet Adaptive Virtual Function Network Driver" ); +MODULE_IMPORT_NS (LIBIE );MODULE_LICENSE ("GPL v2" );static const struct net_device_ops iavf_netdev_ops;
drivers/net/ethernet/intel/iavf/iavf_prototype.h +0 -7
@@ -51,13 +51,6 @@ enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw, u16 seid,enum iavf_status iavf_set_mac_type (struct iavf_hw *hw); -extern struct iavf_rx_ptype_decoded iavf_ptype_lookup[]; - -static inline struct iavf_rx_ptype_decoded decode_rx_desc_ptype (u8 ptype) -{ -return iavf_ptype_lookup[ptype]; -} -void iavf_vf_parse_hw_config (struct iavf_hw *hw,struct virtchnl_vf_resource *msg);enum iavf_status iavf_vf_reset (struct iavf_hw *hw);
drivers/net/ethernet/intel/iavf/iavf_txrx.c +16 -54
125 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_type.h +0 -88
94 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h +0 -316
326 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_main.c +1 -0
@@ -34,6 +34,7 @@ static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";MODULE_AUTHOR ("Intel Corporation, <[email protected]>" );MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_IMPORT_NS (LIBIE );MODULE_LICENSE ("GPL v2" );MODULE_FIRMWARE (ICE_DDP_PKG_FILE );
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +18 -56
137 lines not on this page · raw message
drivers/net/ethernet/intel/libie/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright(c) 2023 Intel Corporation. + +obj-$(CONFIG_LIBIE) += libie.o + +libie-objs += rx.o
drivers/net/ethernet/intel/libie/rx.c new file +110 -0
110 lines not on this page · raw message
include/linux/net/intel/libie/rx.h new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 2/12 iavf: kill "legacy-rx" for good
In reply to Alexander LobakinEver since build_skb() became stable, the old way with allocating an skb for storing the headers separately, which will be then copied manually, was slower, less flexible and thus obsolete.
* it had higher pressure on MM since it actually allocates new pages, which then get split and refcount-biased (NAPI page cache);
* it implies memcpy() of packet headers (40+ bytes per each frame);
* the actual header length was calculated via eth_get_headlen(), which invokes Flow Dissector and thus wastes a bunch of CPU cycles;
* XDP makes it even more weird since it requires headroom for long and also tailroom for some time (since mbuf landed). Take a look at the ice driver, which is built around work-arounds to make XDP work with it.
Even on some quite low-end hardware (not a common case for 100G NICs) it was performing worse.
The only advantage "legacy-rx" had is that it didn't require any reserved headroom and tailroom. But iavf didn't use this, as it always splits pages into two halves of 2k, while that save would only be useful when striding. And again, XDP effectively removes that sole pro.
There's a train of features to land in IAVF soon: Page Pool, XDP, XSk, multi-buffer etc. Each new would require adding more and more Danse Macabre for absolutely no reason, besides making hotpath less and less effective.
Remove the "feature" with all the related code. This includes at least one very hot branch (typically hit on each new frame), which was either always-true or always-false at least for a complete NAPI bulk of 64 frames, the whole private flags cruft and so on. Some stats:
Function: add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-774 (-774) RO Data: add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-40 (-40)
--- drivers/net/ethernet/intel/iavf/iavf.h | 2 +- .../net/ethernet/intel/iavf/iavf_ethtool.c | 140 ------------------ drivers/net/ethernet/intel/iavf/iavf_main.c | 10 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 84 +---------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 18 +-- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 3 +- 6 files changed, 8 insertions(+), 249 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +1 -1
@@ -298,7 +298,7 @@ struct iavf_adapter {#define IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS BIT(12)#define IAVF_FLAG_PROMISC_ON BIT(13)#define IAVF_FLAG_ALLMULTI_ON BIT(14) -#define IAVF_FLAG_LEGACY_RX BIT(15) +/* BIT(15) is free, was IAVF_FLAG_LEGACY_RX */ #define IAVF_FLAG_REINIT_ITR_NEEDED BIT(16)#define IAVF_FLAG_QUEUES_DISABLED BIT(17)#define IAVF_FLAG_SETUP_NETDEV_FEATURES BIT(18)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +0 -140
181 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -9
@@ -713,9 +713,7 @@ static void iavf_configure_rx(struct iavf_adapter *adapter)struct iavf_hw *hw = &adapter->hw;int i; -/* Legacy Rx will always default to a 2048 buffer size. */ -#if (PAGE_SIZE <8192 ) -if (!(adapter->flags &IAVF_FLAG_LEGACY_RX )) { +if (PAGE_SIZE <8192 ) {struct net_device *netdev = adapter->netdev;/* For jumbo frames on systems with 4K pages we have to use
@@ -732,16 +730,10 @@ static void iavf_configure_rx(struct iavf_adapter *adapter) (netdev->mtu <= ETH_DATA_LEN)) rx_buf_len =IAVF_RXBUFFER_1536 -NET_IP_ALIGN ; } -#endif for (i =0 ; i < adapter->num_active_queues; i++) { adapter->rx_rings[i].tail = hw->hw_addr +IAVF_QRX_TAIL1 (i); adapter->rx_rings[i].rx_buf_len = rx_buf_len; - -if (adapter->flags &IAVF_FLAG_LEGACY_RX ) -clear_ring_build_skb_enabled (&adapter->rx_rings[i]); -else -set_ring_build_skb_enabled (&adapter->rx_rings[i]); } }
drivers/net/ethernet/intel/iavf/iavf_txrx.c +3 -81
115 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +2 -16
@@ -362,7 +362,8 @@ struct iavf_ring {u16 flags;#define IAVF_TXR_FLAGS_WB_ON_ITR BIT(0) -#define IAVF_RXR_FLAGS_BUILD_SKB_ENABLED BIT(1) +/* BIT(1) is free, was IAVF_RXR_FLAGS_BUILD_SKB_ENABLED */ +/* BIT(2) is free */ #define IAVF_TXRX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(3)#define IAVF_TXR_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(4)#define IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2 BIT(5)
@@ -393,21 +394,6 @@ struct iavf_ring {*/ }____cacheline_internodealigned_in_smp ; -static inline bool ring_uses_build_skb (struct iavf_ring *ring) -{ -return !!(ring->flags &IAVF_RXR_FLAGS_BUILD_SKB_ENABLED ); -} - -static inline void set_ring_build_skb_enabled (struct iavf_ring *ring) -{ - ring->flags |=IAVF_RXR_FLAGS_BUILD_SKB_ENABLED ; -} - -static inline void clear_ring_build_skb_enabled (struct iavf_ring *ring) -{ - ring->flags &= ~IAVF_RXR_FLAGS_BUILD_SKB_ENABLED ; -} -#define IAVF_ITR_ADAPTIVE_MIN_INC 0x0002#define IAVF_ITR_ADAPTIVE_MIN_USECS 0x0002#define IAVF_ITR_ADAPTIVE_MAX_USECS 0x007e
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1 -2
@@ -290,8 +290,7 @@ void iavf_configure_queues(struct iavf_adapter *adapter)return ;/* Limit maximum frame size when jumbo frames is not enabled */ -if (!(adapter->flags &IAVF_FLAG_LEGACY_RX ) && - (adapter->netdev->mtu <=ETH_DATA_LEN )) +if (adapter->netdev->mtu <=ETH_DATA_LEN ) max_frame =IAVF_RXBUFFER_1536 -NET_IP_ALIGN ; vqci->vsi_id = adapter->vsi_res->vsi_id;
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 3/12 iavf: optimize Rx buffer allocation a bunch
In reply to Alexander LobakinThe Rx hotpath code of IAVF is not well-optimized TBH. Before doing any further buffer model changes, shake it up a bit. Notably:
1. Cache more variables on the stack.
DMA device, Rx page size, NTC -- these are the most common things used all throughout the hotpath, often in loops on each iteration. Instead of fetching (or even calculating, as with the page size) them from the ring all the time, cache them on the stack at the beginning of the NAPI polling callback. NTC will be written back at the end, the rest are used read-only, so no sync needed.
2. Don't move the recycled buffers around the ring.
The idea of passing the page of the right-now-recycled-buffer to a different buffer, in this case, the first one that needs to be allocated, moreover, on each new frame, is fundamentally wrong. It involves a few o' fetches, branches and then writes (and one Rx buffer struct is at least 32 bytes) where they're completely unneeded, but gives no good -- the result is the same as if we'd recycle it inplace, at the same position where it was used. So drop this and let the main refilling function take care of all the buffers, which were processed and now need to be recycled/refilled.
3. Don't allocate with %GPF_ATOMIC on ifup.
This involved introducing the @gfp parameter to a couple functions. Doesn't change anything for Rx -> softirq.
4. 1 budget unit == 1 descriptor, not skb.
There could be underflow when receiving a lot of fragmented frames. If each of them would consist of 2 frags, it means that we'd process 64 descriptors at the point where we pass the 32th skb to the stack. But the driver would count that only as a half, which could make NAPI re-enable interrupts prematurely and create unnecessary CPU load.
5. Shortcut !size case.
It's super rare, but possible -- for example, if the last buffer of the fragmented frame contained only FCS, which was then stripped by the HW. Instead of checking for size several times when processing, quickly reuse the buffer and jump to the skb fields part.
6. Refill the ring after finishing the polling loop. Previously, the loop wasn't starting a new iteration after the 64th desc, meaning that we were always leaving 16 buffers non-refilled until the next NAPI poll. It's better to refill them while they're still hot, so do that right after exiting the loop as well. For a full cycle of 64 descs, there will be 4 refills of 16 descs from now on.
Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174)
+ up to 2% performance.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 259 +++++++++----------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 3 +- 3 files changed, 114 insertions(+), 150 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
@@ -1236,7 +1236,7 @@ static void iavf_configure(struct iavf_adapter *adapter)for (i =0 ; i < adapter->num_active_queues; i++) {struct iavf_ring *ring = &adapter->rx_rings[i]; -iavf_alloc_rx_buffers (ring,IAVF_DESC_UNUSED (ring)); +iavf_alloc_rx_buffers (ring); } }
drivers/net/ethernet/intel/iavf/iavf_txrx.c +112 -147
464 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +1 -2
@@ -383,7 +383,6 @@ struct iavf_ring {struct iavf_q_vector *q_vector;/* Backreference to associated vector */ struct rcu_head rcu;/* to avoid race on free */ -u16 next_to_alloc;struct sk_buff *skb;/* When iavf_clean_rx_ring_irq() must * return before it sees the EOP for * the current packet, we save that skb
@@ -426,7 +425,7 @@ static inline unsigned int iavf_rx_pg_order(struct iavf_ring *ring)#define iavf_rx_pg_size (_ring) (PAGE_SIZE << iavf_rx_pg_order(_ring)) -bool iavf_alloc_rx_buffers (struct iavf_ring *rxr,u16 cleaned_count); +void iavf_alloc_rx_buffers (struct iavf_ring *rxr);netdev_tx_t iavf_xmit_frame (struct sk_buff *skb,struct net_device *netdev);void iavf_clean_tx_ring (struct iavf_ring *tx_ring);void iavf_clean_rx_ring (struct iavf_ring *rx_ring);
Signature · 1 line
2.40.1
Re: [PATCH net-next v3 03/12] iavf: optimize Rx buffer allocation a bunch
Quoted 42 lines · Alexander Lobakin
The Rx hotpath code of IAVF is not well-optimized TBH. Before doing any further buffer model changes, shake it up a bit. Notably:
1. Cache more variables on the stack.
DMA device, Rx page size, NTC -- these are the most common things used all throughout the hotpath, often in loops on each iteration. Instead of fetching (or even calculating, as with the page size) them from the ring all the time, cache them on the stack at the beginning of the NAPI polling callback. NTC will be written back at the end, the rest are used read-only, so no sync needed.
2. Don't move the recycled buffers around the ring.
The idea of passing the page of the right-now-recycled-buffer to a different buffer, in this case, the first one that needs to be allocated, moreover, on each new frame, is fundamentally wrong. It involves a few o' fetches, branches and then writes (and one Rx buffer struct is at least 32 bytes) where they're completely unneeded, but gives no good -- the result is the same as if we'd recycle it inplace, at the same position where it was used. So drop this and let the main refilling function take care of all the buffers, which were processed and now need to be recycled/refilled.
3. Don't allocate with %GPF_ATOMIC on ifup.
This involved introducing the @gfp parameter to a couple functions. Doesn't change anything for Rx -> softirq.
4. 1 budget unit == 1 descriptor, not skb.
There could be underflow when receiving a lot of fragmented frames. If each of them would consist of 2 frags, it means that we'd process 64 descriptors at the point where we pass the 32th skb to the stack. But the driver would count that only as a half, which could make NAPI re-enable interrupts prematurely and create unnecessary CPU load.
5. Shortcut !size case.
It's super rare, but possible -- for example, if the last buffer of the fragmented frame contained only FCS, which was then stripped by the HW. Instead of checking for size several times when processing, quickly reuse the buffer and jump to the skb fields part.
6. Refill the ring after finishing the polling loop. Previously, the loop wasn't starting a new iteration after the 64th desc, meaning that we were always leaving 16 buffers non-refilled until the next NAPI poll. It's better to refill them while they're still hot, so do that right after exiting the loop as well. For a full cycle of 64 descs, there will be 4 refills of 16 descs from now on.
Quoted 5 lines
Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174)
+ up to 2% performance.
Signed-off-by Alexander Lobakin <[email protected]>
What is the workload that is showing the performance improvement?
<...>
drivers/net/ethernet/intel/iavf/iavf_txrx.c static bool iavf_is_non_eop(struct iavf_ring *rx_ring, · line 1298
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-0@@ -1350,14 +1297,6 @@ static bool iavf_is_non_eop(struct iavf_ring *rx_ring,union iavf_rx_desc *rx_desc, struct sk_buff *skb)
I am pretty sure the skb pointer here is an unused variable. We needed it for ixgbe to support RSC. I don't think you have any code that uses it in this function and I know we removed the variable for i40e, see commit d06e2f05b4f18 ("i40e: adjust i40e_is_non_eop").
Re: [PATCH net-next v3 03/12] iavf: optimize Rx buffer allocation a bunch
In reply to Alexander LobakinQuoted 10 lines · Alexander Lobakin
The Rx hotpath code of IAVF is not well-optimized TBH. Before doing any further buffer model changes, shake it up a bit. Notably:
1. Cache more variables on the stack.
DMA device, Rx page size, NTC -- these are the most common things used all throughout the hotpath, often in loops on each iteration. Instead of fetching (or even calculating, as with the page size) them from the ring all the time, cache them on the stack at the beginning of the NAPI polling callback. NTC will be written back at the end, the rest are used read-only, so no sync needed.
I like calculating page size once per napi istance. Reduces a bunch of branches ;)
Yet another optimization I did on other drivers was to store rx_offset within ring struct. I skipped iavf for some reason. I can follow-up with that, but I'm bringing this up so we keep an eye on it.
Quoted 11 lines
2. Don't move the recycled buffers around the ring.
The idea of passing the page of the right-now-recycled-buffer to a different buffer, in this case, the first one that needs to be allocated, moreover, on each new frame, is fundamentally wrong. It involves a few o' fetches, branches and then writes (and one Rx buffer struct is at least 32 bytes) where they're completely unneeded, but gives no good -- the result is the same as if we'd recycle it inplace, at the same position where it was used. So drop this and let the main refilling function take care of all the buffers, which were processed and now need to be recycled/refilled.
3. Don't allocate with %GPF_ATOMIC on ifup.
s/GPF/GFP
Quoted 8 lines
This involved introducing the @gfp parameter to a couple functions. Doesn't change anything for Rx -> softirq.
4. 1 budget unit == 1 descriptor, not skb.
There could be underflow when receiving a lot of fragmented frames. If each of them would consist of 2 frags, it means that we'd process 64 descriptors at the point where we pass the 32th skb to the stack. But the driver would count that only as a half, which could make NAPI re-enable interrupts prematurely and create unnecessary CPU load.
How would this affect 9k MTU workloads?
Quoted 5 lines
5. Shortcut !size case.
It's super rare, but possible -- for example, if the last buffer of the fragmented frame contained only FCS, which was then stripped by the HW. Instead of checking for size several times when processing, quickly reuse the buffer and jump to the skb fields part.
would be good to say about pagecnt_bias handling.
Quoted 7 lines
6. Refill the ring after finishing the polling loop. Previously, the loop wasn't starting a new iteration after the 64th desc, meaning that we were always leaving 16 buffers non-refilled until the next NAPI poll. It's better to refill them while they're still hot, so do that right after exiting the loop as well. For a full cycle of 64 descs, there will be 4 refills of 16 descs from now on.
As said on different sub-thread, I'd rather see the bullets above as a separate patches.
Quoted 4 lines
Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174)
+ up to 2% performance.
I am sort of not buying that. You are removing iavf_reuse_rx_page() here which is responsible for reusing the page, but on next patch that is supposed to avoid page split perf drops by 30%. A bit confusing?
Quoted 180 lines
Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 259 +++++++++----------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 3 +- 3 files changed, 114 insertions(+), 150 deletions(-)drivers/net/ethernet/intel/iavf/iavf_main.c +1
-1@@ -1236,7 +1236,7 @@ static void iavf_configure(struct iavf_adapter *adapter)for (i =0 ; i < adapter->num_active_queues; i++) {struct iavf_ring *ring = &adapter->rx_rings[i]; -iavf_alloc_rx_buffers (ring,IAVF_DESC_UNUSED (ring)); +iavf_alloc_rx_buffers (ring); } }drivers/net/ethernet/intel/iavf/iavf_txrx.c +32
-36@@ -736,7 +736,6 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring)/* Zero out the descriptor ring */ memset (rx_ring->desc,0 , rx_ring->size); - rx_ring->next_to_alloc =0 ; rx_ring->next_to_clean =0 ; rx_ring->next_to_use =0 ; }@@ -792,7 +791,6 @@ int iavf_setup_rx_descriptors(struct iavf_ring *rx_ring) goto err; } - rx_ring->next_to_alloc =0 ; rx_ring->next_to_clean =0 ; rx_ring->next_to_use =0 ;@@ -812,9 +810,6 @@ static inline void iavf_release_rx_desc(struct iavf_ring *rx_ring, u32 val) { rx_ring->next_to_use = val; -/* update next to alloc since we have filled the ring */ - rx_ring->next_to_alloc = val; -/* Force memory writes to complete before letting h/w * know there are new descriptors to fetch. (Only * applicable for weak-ordered memory model archs, @@ -828,12 +823,17 @@ static inline void iavf_release_rx_desc(struct iavf_ring *rx_ring, u32 val)* iavf_alloc_mapped_page - recycle or make a new page * @rx_ring: ring to use * @bi: rx_buffer struct to modify +* @dev: device used for DMA mapping +* @order: page order to allocate +* @gfp: GFP mask to allocate page * * Returns true if the page was successfully allocated or * reused. **/ static bool iavf_alloc_mapped_page (struct iavf_ring *rx_ring, -struct iavf_rx_buffer *bi) +struct iavf_rx_buffer *bi, +struct device *dev,u32 order, +gfp_t gfp) {struct page *page = bi->page;dma_addr_t dma;@@ -845,23 +845,21 @@ static bool iavf_alloc_mapped_page(struct iavf_ring *rx_ring, }/* alloc new page for storage */ - page =dev_alloc_pages (iavf_rx_pg_order (rx_ring)); + page =__dev_alloc_pages (gfp, order);if (unlikely (!page)) { rx_ring->rx_stats.alloc_page_failed++;return false; }/* map page for use */ - dma =dma_map_page_attrs (rx_ring->dev, page,0 , -iavf_rx_pg_size (rx_ring), -DMA_FROM_DEVICE , -IAVF_RX_DMA_ATTR ); + dma =dma_map_page_attrs (dev, page,0 ,PAGE_SIZE << order, +DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR );/* if mapping failed free memory back to system since * there isn't much point in holding memory we can't use */ -if (dma_mapping_error (rx_ring->dev, dma)) { -__free_pages (page,iavf_rx_pg_order (rx_ring)); +if (dma_mapping_error (dev, dma)) { +__free_pages (page, order); rx_ring->rx_stats.alloc_page_failed++;return false; }@@ -898,32 +896,36 @@ static void iavf_receive_skb(struct iavf_ring *rx_ring, }/** -* iavf_alloc_rx_buffers - Replace used receive buffers +* __iavf_alloc_rx_buffers - Replace used receive buffers * @rx_ring: ring to place buffers on -* @cleaned_count: number of buffers to replace +* @to_refill: number of buffers to replace +* @gfp: GFP mask to allocate pages * -* Returns false if all allocations were successful, true if any fail +* Returns 0 if all allocations were successful or the number of buffers left +* to refill in case of an allocation failure. **/ -bool iavf_alloc_rx_buffers (struct iavf_ring *rx_ring,u16 cleaned_count) +static u32 __iavf_alloc_rx_buffers (struct iavf_ring *rx_ring,u32 to_refill, +gfp_t gfp) { -u16 ntu = rx_ring->next_to_use; +u32 order =iavf_rx_pg_order (rx_ring); +struct device *dev = rx_ring->dev; +u32 ntu = rx_ring->next_to_use;union iavf_rx_desc *rx_desc;struct iavf_rx_buffer *bi;/* do nothing if no valid netdev defined */ -if (!rx_ring->netdev || !cleaned_count) -return false; +if (unlikely (!rx_ring->netdev || !to_refill)) +return 0 ; rx_desc =IAVF_RX_DESC (rx_ring, ntu); bi = &rx_ring->rx_bi[ntu]; do { - if (!iavf_alloc_mapped_page(rx_ring, bi)) - goto no_buffers; + if (!iavf_alloc_mapped_page(rx_ring, bi, dev, order, gfp)) + break; /* sync the buffer for use by the device */ - dma_sync_single_range_for_device(rx_ring->dev, bi->dma, - bi->page_offset, + dma_sync_single_range_for_device(dev, bi->dma, bi->page_offset, rx_ring->rx_buf_len, DMA_FROM_DEVICE);@@ -943,23 +945,17 @@ bool iavf_alloc_rx_buffers(struct iavf_ring *rx_ring, u16 cleaned_count)/* clear the status bits for the next_to_use descriptor */ rx_desc->wb.qword1.status_error_len =0 ; - - cleaned_count--; - }while (cleaned_count); + }while (--to_refill);if (rx_ring->next_to_use != ntu)iavf_release_rx_desc (rx_ring, ntu); -return false; - -no_buffers: -if (rx_ring->next_to_use != ntu) -iavf_release_rx_desc (rx_ring, ntu); +return to_refill; +} -/* make sure to come back via polling to try again after -* allocation failure -*/ -return true; +void iavf_alloc_rx_buffers (struct iavf_ring *rxr) +{ +__iavf_alloc_rx_buffers (rxr,IAVF_DESC_UNUSED (rxr),GFP_KERNEL ); }/** @@ -1104,32 +1100,6 @@ static bool iavf_cleanup_headers(struct iavf_ring *rx_ring, struct sk_buff *skb)return false; }
drivers/net/ethernet/intel/iavf/iavf_txrx.c static bool iavf_cleanup_headers(struct iavf_ring *rx_ring, struct sk_buff *skb) · line 1115
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-9-/** -* iavf_reuse_rx_page - page flip buffer and store it back on the ring -* @rx_ring: rx descriptor ring to store buffers on -* @old_buff: donor buffer to have page reused -* -* Synchronizes page for reuse by the adapter -**/ -static void iavf_reuse_rx_page (struct iavf_ring *rx_ring, -struct iavf_rx_buffer *old_buff)
this is recycling logic so i feel this removal belongs to patch 04, right?
Quoted 72 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +11
-29-{ -struct iavf_rx_buffer *new_buff; -u16 nta = rx_ring->next_to_alloc; - - new_buff = &rx_ring->rx_bi[nta]; - -/* update, and store next to alloc */ - nta++; - rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta :0 ; - -/* transfer page from old buffer to new buffer */ - new_buff->dma = old_buff->dma; - new_buff->page = old_buff->page; - new_buff->page_offset = old_buff->page_offset; - new_buff->pagecnt_bias = old_buff->pagecnt_bias; -} -/** * iavf_can_reuse_rx_page - Determine if this page can be reused by * the adapter for another receive @@ -1191,30 +1161,26 @@ static bool iavf_can_reuse_rx_page(struct iavf_rx_buffer *rx_buffer)/** * iavf_add_rx_frag - Add contents of Rx buffer to sk_buff -* @rx_ring: rx descriptor ring to transact packets on -* @rx_buffer: buffer containing page to add * @skb: sk_buff to place the data into +* @rx_buffer: buffer containing page to add * @size: packet length from rx_desc +* @pg_size: Rx buffer page size * * This function will add the data contained in rx_buffer->page to the skb. * It will just attach the page as a frag to the skb. * * The function will then update the page offset. **/ -static void iavf_add_rx_frag (struct iavf_ring *rx_ring, +static void iavf_add_rx_frag (struct sk_buff *skb,struct iavf_rx_buffer *rx_buffer, -struct sk_buff *skb, -unsigned int size) +u32 size,u32 pg_size) {#if (PAGE_SIZE <8192 ) -unsigned int truesize =iavf_rx_pg_size (rx_ring) /2 ; +unsigned int truesize = pg_size /2 ;#else unsigned int truesize =SKB_DATA_ALIGN (size +IAVF_SKB_PAD );#endif -if (!size) -return ; -skb_add_rx_frag (skb,skb_shinfo (skb)->nr_frags, rx_buffer->page, rx_buffer->page_offset, size, truesize);@@ -1224,63 +1190,47 @@ static void iavf_add_rx_frag(struct iavf_ring *rx_ring,#else rx_buffer->page_offset += truesize;#endif + +/* We have pulled a buffer for use, so decrement pagecnt_bias */ + rx_buffer->pagecnt_bias--; }/** -* iavf_get_rx_buffer - Fetch Rx buffer and synchronize data for use -* @rx_ring: rx descriptor ring to transact packets on -* @size: size of buffer to add to skb +* iavf_sync_rx_buffer - Synchronize received data for use +* @dev: device used for DMA mapping +* @buf: Rx buffer containing the data
drivers/net/ethernet/intel/iavf/iavf_txrx.c static void iavf_add_rx_frag(struct iavf_ring *rx_ring, · line 1207
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +4
-4+* @size: size of the received data * -* This function will pull an Rx buffer from the ring and synchronize it -* for use by the CPU. +* This function will synchronize the Rx buffer for use by the CPU. */ -static struct iavf_rx_buffer *iavf_get_rx_buffer (struct iavf_ring *rx_ring, -const unsigned int size) +static void iavf_sync_rx_buffer (struct device *dev,struct iavf_rx_buffer *buf, +u32 size)
you have peeled out all of the contents of this function, why not calling dma_sync_single_range_for_cpu() directly?
Quoted 79 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +14
-32{ -struct iavf_rx_buffer *rx_buffer; - - rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean]; -prefetchw (rx_buffer->page); -if (!size) -return rx_buffer; - -/* we are reusing so sync this buffer for CPU use */ -dma_sync_single_range_for_cpu (rx_ring->dev, - rx_buffer->dma, - rx_buffer->page_offset, - size, +dma_sync_single_range_for_cpu (dev, buf->dma, buf->page_offset, size,DMA_FROM_DEVICE ); - -/* We have pulled a buffer for use, so decrement pagecnt_bias */ - rx_buffer->pagecnt_bias--; - -return rx_buffer; }/** * iavf_build_skb - Build skb around an existing buffer -* @rx_ring: Rx descriptor ring to transact packets on -* @rx_buffer: Rx buffer to pull data from -* @size: size of buffer to add to skb +* @rx_buffer: Rx buffer with the data +* @size: size of the data +* @pg_size: size of the Rx page * * This function builds an skb around an existing Rx buffer, taking care * to set up the skb correctly and avoid any memcpy overhead. */ -static struct sk_buff *iavf_build_skb (struct iavf_ring *rx_ring, -struct iavf_rx_buffer *rx_buffer, -unsigned int size) +static struct sk_buff *iavf_build_skb (struct iavf_rx_buffer *rx_buffer, +u32 size,u32 pg_size) {void *va;#if (PAGE_SIZE <8192 ) -unsigned int truesize =iavf_rx_pg_size (rx_ring) /2 ; +unsigned int truesize = pg_size /2 ;#else unsigned int truesize =SKB_DATA_ALIGN (sizeof (struct skb_shared_info )) +SKB_DATA_ALIGN (IAVF_SKB_PAD + size);#endif struct sk_buff *skb; -if (!rx_buffer || !size) -return NULL ;/* prefetch first cache line of first page */ va =page_address (rx_buffer->page) + rx_buffer->page_offset;net_prefetch (va);@@ -1301,36 +1251,33 @@ static struct sk_buff *iavf_build_skb(struct iavf_ring *rx_ring, rx_buffer->page_offset += truesize;#endif + rx_buffer->pagecnt_bias--; +return skb; }/** -* iavf_put_rx_buffer - Clean up used buffer and either recycle or free +* iavf_put_rx_buffer - Recycle or free used buffer * @rx_ring: rx descriptor ring to transact packets on -* @rx_buffer: rx buffer to pull data from +* @dev: device used for DMA mapping +* @rx_buffer: Rx buffer to handle +* @pg_size: Rx page size * -* This function will clean up the contents of the rx_buffer. It will -* either recycle the buffer or unmap it and free the associated resources. +* Either recycle the buffer if possible or unmap and free the page. */ -static void iavf_put_rx_buffer (struct iavf_ring *rx_ring, -struct iavf_rx_buffer *rx_buffer)
drivers/net/ethernet/intel/iavf/iavf_txrx.c static struct sk_buff *iavf_build_skb(struct iavf_ring *rx_ring, · line 1272
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +2
-5+static void iavf_put_rx_buffer (struct iavf_ring *rx_ring,struct device *dev, +struct iavf_rx_buffer *rx_buffer,u32 pg_size) { -if (!rx_buffer) -return ; -if (iavf_can_reuse_rx_page (rx_buffer)) { -/* hand second half of page back to the ring */ -iavf_reuse_rx_page (rx_ring, rx_buffer); rx_ring->rx_stats.page_reuse_count++;
what is the purpose of not reusing the page but bumping the meaningless stat? ;)
Quoted 72 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +18
-24- }else { -/* we are not reusing the buffer so unmap it */ -dma_unmap_page_attrs (rx_ring->dev, rx_buffer->dma, -iavf_rx_pg_size (rx_ring), -DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR ); -__page_frag_cache_drain (rx_buffer->page, - rx_buffer->pagecnt_bias); +return ; } +/* we are not reusing the buffer so unmap it */ +dma_unmap_page_attrs (dev, rx_buffer->dma, pg_size, +DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR ); +__page_frag_cache_drain (rx_buffer->page, rx_buffer->pagecnt_bias); +/* clear contents of buffer_info */ rx_buffer->page =NULL ; }@@ -1350,14 +1297,6 @@ static bool iavf_is_non_eop(struct iavf_ring *rx_ring, union iavf_rx_desc *rx_desc, struct sk_buff *skb) { - u32 ntc = rx_ring->next_to_clean + 1; - -/* fetch, update, and store next to clean */ - ntc = (ntc < rx_ring->count) ? ntc :0 ; - rx_ring->next_to_clean = ntc; - -prefetch (IAVF_RX_DESC (rx_ring, ntc)); - /* if we are the last buffer then there is nothing else to do */ #define IAVF_RXD_EOF BIT(IAVF_RX_DESC_STATUS_EOF_SHIFT) if (likely(iavf_test_staterr(rx_desc, IAVF_RXD_EOF)))@@ -1383,11 +1322,16 @@ static bool iavf_is_non_eop(struct iavf_ring *rx_ring,static int iavf_clean_rx_irq (struct iavf_ring *rx_ring,int budget) {unsigned int total_rx_bytes =0 , total_rx_packets =0 ; +const gfp_t gfp =GFP_ATOMIC | __GFP_NOWARN; +u32 to_refill =IAVF_DESC_UNUSED (rx_ring); +u32 pg_size =iavf_rx_pg_size (rx_ring);struct sk_buff *skb = rx_ring->skb; -u16 cleaned_count =IAVF_DESC_UNUSED (rx_ring); -bool failure = false; +struct device *dev = rx_ring->dev; +u32 ntc = rx_ring->next_to_clean; +u32 ring_size = rx_ring->count; +u32 cleaned_count =0 ; -while (likely (total_rx_packets < (unsigned int )budget)) { +while (likely (cleaned_count < budget)) {struct iavf_rx_buffer *rx_buffer;union iavf_rx_desc *rx_desc;unsigned int size;@@ -1396,13 +1340,11 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)u64 qword;/* return some buffers to hardware, one at a time is too slow */ -if (cleaned_count >=IAVF_RX_BUFFER_WRITE ) { - failure = failure || -iavf_alloc_rx_buffers (rx_ring, cleaned_count); - cleaned_count =0 ; - } +if (to_refill >=IAVF_RX_BUFFER_WRITE ) + to_refill =__iavf_alloc_rx_buffers (rx_ring, to_refill, + gfp); - rx_desc =IAVF_RX_DESC (rx_ring, rx_ring->next_to_clean); + rx_desc =IAVF_RX_DESC (rx_ring, ntc);/* status_error_len will always be zero for unused descriptors * because it's cleared in cleanup, and overlaps with hdr_addr
drivers/net/ethernet/intel/iavf/iavf_txrx.c static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) · line 1373
Quoted 9 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +5
-1@@ -1424,24 +1366,38 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)IAVF_RXD_QW1_LENGTH_PBUF_SHIFT ;iavf_trace (clean_rx_irq, rx_ring, rx_desc, skb); - rx_buffer =iavf_get_rx_buffer (rx_ring, size); + rx_buffer = &rx_ring->rx_bi[ntc]; + +/* Very rare, but possible case. The most common reason: +* the last fragment contained FCS only, which was then +* stripped by the HW.
you could also mention this is happening for fragmented frames
Quoted 88 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +26
-7+*/ +if (unlikely (!size)) + goto skip_data; + +iavf_sync_rx_buffer (dev, rx_buffer, size);/* retrieve a buffer from the ring */ if (skb) -iavf_add_rx_frag (rx_ring, rx_buffer, skb, size); +iavf_add_rx_frag (skb, rx_buffer, size, pg_size);else - skb =iavf_build_skb (rx_ring, rx_buffer, size); + skb =iavf_build_skb (rx_buffer, size, pg_size);/* exit if we failed to retrieve a buffer */ if (!skb) { rx_ring->rx_stats.alloc_buff_failed++; -if (rx_buffer && size) - rx_buffer->pagecnt_bias++;break ; } -iavf_put_rx_buffer (rx_ring, rx_buffer); +skip_data: +iavf_put_rx_buffer (rx_ring, dev, rx_buffer, pg_size); + cleaned_count++; + to_refill++; +if (unlikely (++ntc == ring_size)) + ntc =0 ; + +prefetch (IAVF_RX_DESC (rx_ring, ntc));if (iavf_is_non_eop (rx_ring, rx_desc, skb))continue ;@@ -1488,8 +1444,18 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) total_rx_packets++; } + rx_ring->next_to_clean = ntc; rx_ring->skb = skb; +if (to_refill >=IAVF_RX_BUFFER_WRITE ) { + to_refill =__iavf_alloc_rx_buffers (rx_ring, to_refill, gfp); +/* guarantee a trip back through this routine if there was +* a failure +*/ +if (unlikely (to_refill)) + cleaned_count = budget; + } +u64_stats_update_begin (&rx_ring->syncp); rx_ring->stats.packets += total_rx_packets; rx_ring->stats.bytes += total_rx_bytes;@@ -1497,8 +1463,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) rx_ring->q_vector->rx.total_packets += total_rx_packets; rx_ring->q_vector->rx.total_bytes += total_rx_bytes; -/* guarantee a trip back through this routine if there was a failure */ -return failure ? budget : (int )total_rx_packets; +return cleaned_count; }static inline u32 iavf_buildreg_itr (const int type,u16 itr)drivers/net/ethernet/intel/iavf/iavf_txrx.h +1
-2@@ -383,7 +383,6 @@ struct iavf_ring {struct iavf_q_vector *q_vector;/* Backreference to associated vector */ struct rcu_head rcu;/* to avoid race on free */ -u16 next_to_alloc;struct sk_buff *skb;/* When iavf_clean_rx_ring_irq() must * return before it sees the EOP for * the current packet, we save that skb @@ -426,7 +425,7 @@ static inline unsigned int iavf_rx_pg_order(struct iavf_ring *ring)#define iavf_rx_pg_size (_ring) (PAGE_SIZE << iavf_rx_pg_order(_ring)) -bool iavf_alloc_rx_buffers (struct iavf_ring *rxr,u16 cleaned_count); +void iavf_alloc_rx_buffers (struct iavf_ring *rxr);netdev_tx_t iavf_xmit_frame (struct sk_buff *skb,struct net_device *netdev);void iavf_clean_tx_ring (struct iavf_ring *tx_ring);void iavf_clean_rx_ring (struct iavf_ring *rx_ring);Signature · 1 line
2.40.1
Alexander Lobakin
maintainerRe: [PATCH net-next v3 03/12] iavf: optimize Rx buffer allocation a bunch
From: Maciej Fijalkowski <[email protected]>
Date: Wed, 31 May 2023 18:39:44 +0200
Quoted 12 lines · Alexander Lobakin
Quoted 10 lines
The Rx hotpath code of IAVF is not well-optimized TBH. Before doing any further buffer model changes, shake it up a bit. Notably:
1. Cache more variables on the stack.
DMA device, Rx page size, NTC -- these are the most common things used all throughout the hotpath, often in loops on each iteration. Instead of fetching (or even calculating, as with the page size) them from the ring all the time, cache them on the stack at the beginning of the NAPI polling callback. NTC will be written back at the end, the rest are used read-only, so no sync needed.
Quoted 6 lines
I like calculating page size once per napi istance. Reduces a bunch of branches ;)
Yet another optimization I did on other drivers was to store
rx_offsetwithin ring struct. I skipped iavf for some reason. I can follow-up with that, but I'm bringing this up so we keep an eye on it.
rx_offset is stored as Page Pool param in its struct. So no follow-ups here needed :)
[...]
Quoted 3 lines
Quoted 1 line
3. Don't allocate with %GPF_ATOMIC on ifup.
s/GPF/GFP
Breh :s
Quoted 11 lines
Quoted 9 lines
This involved introducing the @gfp parameter to a couple functions. Doesn't change anything for Rx -> softirq.
4. 1 budget unit == 1 descriptor, not skb.
There could be underflow when receiving a lot of fragmented frames. If each of them would consist of 2 frags, it means that we'd process 64 descriptors at the point where we pass the 32th skb to the stack. But the driver would count that only as a half, which could make NAPI re-enable interrupts prematurely and create unnecessary CPU load.How would this affect 9k MTU workloads?
Not measured =\ But I feel like I'll drop this bullet, so will see.
Quoted 8 lines
Quoted 6 lines
5. Shortcut !size case.
It's super rare, but possible -- for example, if the last buffer of the fragmented frame contained only FCS, which was then stripped by the HW. Instead of checking for size several times when processing, quickly reuse the buffer and jump to the skb fields part.would be good to say about
pagecnt_biashandling.
?? Bias is changed only when the buffer contains data, in this case it's not changed, so the buffer is ready to be reused.
[...]
Quoted 7 lines
Quoted 3 lines
Function: add/remove: 4/2 grow/shrink: 0/5 up/down: 473/-647 (-174)
+ up to 2% performance.
I am sort of not buying that. You are removing
iavf_reuse_rx_page()here which is responsible for reusing the page, but on next patch that is supposed to avoid page split perf drops by 30%. A bit confusing?
Nope. reuse_rx_page() only adds overhead since it moves reusable buffers around the ring, while without it they get reused in-place. That's why it doesn't cause any regressions. The next patch removes page reuse completely, hence the perf changes.
[...]
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static bool iavf_cleanup_headers(struct iavf_ring *rx_ring, struct sk_buff *skb) · line 1115
Quoted 2 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-2-static void iavf_reuse_rx_page (struct iavf_ring *rx_ring, -struct iavf_rx_buffer *old_buff)this is recycling logic so i feel this removal belongs to patch 04, right?
(above)
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-3-{ -struct iavf_rx_buffer *new_buff; -u16 nta = rx_ring->next_to_alloc;
[...]
Quoted 7 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static void iavf_add_rx_frag(struct iavf_ring *rx_ring, · line 1207
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +2
-2-static struct iavf_rx_buffer *iavf_get_rx_buffer (struct iavf_ring *rx_ring, -const unsigned int size) +static void iavf_sync_rx_buffer (struct device *dev,struct iavf_rx_buffer *buf, +u32 size)you have peeled out all of the contents of this function, why not calling
dma_sync_single_range_for_cpu()directly?
Pretty long line, so I decided to leave it here. It gets removed anyway when Page Pool is here.
[...]
Quoted 7 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static struct sk_buff *iavf_build_skb(struct iavf_ring *rx_ring, · line 1272
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-2if (iavf_can_reuse_rx_page (rx_buffer)) { -/* hand second half of page back to the ring */ -iavf_reuse_rx_page (rx_ring, rx_buffer); rx_ring->rx_stats.page_reuse_count++;what is the purpose of not reusing the page but bumping the meaningless stat? ;)
Also above. It's reused, just not moved around the ring :D
[...]
Quoted 2 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) · line 1372
Quoted 2 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +2
-0+/* Very rare, but possible case. The most common reason: +* the last fragment contained FCS only, which was then
^^^^^^^^
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) · line 1373
Quoted 1 line
drivers/net/ethernet/intel/iavf/iavf_txrx.c +1
-0+* stripped by the HW. you could also mention this is happening for fragmented frames
Mmm?
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget) · line 1376
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +3
-0+*/ +if (unlikely (!size)) + goto skip_data;
Thanks,
Olek
Alexander Lobakin
maintainerPATCH v3 4/12 iavf: remove page splitting/recycling
In reply to Alexander LobakinAs an intermediate step, remove all page splitting/recyclig code. Just always allocate a new page and don't touch its refcount, so that it gets freed by the core stack later.
The change allows to greatly simplify certain parts of the code:
Function: add/remove: 2/3 grow/shrink: 0/5 up/down: 543/-963 (-420)
&iavf_rx_buf can even now retire in favor of just storing an array of pages used for Rx. Their DMA addresses can be stored in page::dma_addr -- use Page Pool's function for that.
No surprise perf loses up to 30% here, but that regression will go away once PP lands.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 280 ++++++-------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 17 +- 3 files changed, 88 insertions(+), 211 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
@@ -1236,7 +1236,7 @@ static void iavf_configure(struct iavf_adapter *adapter)for (i =0 ; i < adapter->num_active_queues; i++) {struct iavf_ring *ring = &adapter->rx_rings[i]; -iavf_alloc_rx_buffers (ring); +iavf_alloc_rx_pages (ring); } }
drivers/net/ethernet/intel/iavf/iavf_txrx.c +85 -195
516 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +2 -15
@@ -272,17 +272,6 @@ struct iavf_tx_buffer {u32 tx_flags; }; -struct iavf_rx_buffer { -dma_addr_t dma; -struct page *page; -#if (BITS_PER_LONG >32 ) || (PAGE_SIZE >=65536 ) -__u32 page_offset; -#else -__u16 page_offset; -#endif -__u16 pagecnt_bias; -}; -struct iavf_queue_stats {u64 packets;u64 bytes;
@@ -302,8 +291,6 @@ struct iavf_rx_queue_stats {u64 non_eop_descs;u64 alloc_page_failed;u64 alloc_buff_failed; -u64 page_reuse_count; -u64 realloc_count; };enum iavf_ring_state_t {
@@ -331,7 +318,7 @@ struct iavf_ring {struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi; -struct iavf_rx_buffer *rx_bi; +struct page **rx_pages; };DECLARE_BITMAP (state, __IAVF_RING_STATE_NBITS);u16 queue_index;/* Queue number of ring */
@@ -425,7 +412,7 @@ static inline unsigned int iavf_rx_pg_order(struct iavf_ring *ring)#define iavf_rx_pg_size (_ring) (PAGE_SIZE << iavf_rx_pg_order(_ring)) -void iavf_alloc_rx_buffers (struct iavf_ring *rxr); +void iavf_alloc_rx_pages (struct iavf_ring *rxr);netdev_tx_t iavf_xmit_frame (struct sk_buff *skb,struct net_device *netdev);void iavf_clean_tx_ring (struct iavf_ring *tx_ring);void iavf_clean_rx_ring (struct iavf_ring *rx_ring);
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 5/12 iavf: always use a full order-0 page
In reply to Alexander LobakinThe current scheme with trying to pick the smallest buffer possible for the current MTU in order to flip/split pages is not very optimal. For example, on default MTU of 1500 it gives only 192 bytes of headroom, while XDP may require up to 258. But this also involves unnecessary code complication, which sometimes is even hard to follow.
As page split is no more, always allocate order-0 pages. This optimizes performance a bit and drops some bytes off the object code. Next, always pick the maximum buffer length available for this %PAGE_SIZE to set it up in the hardware. This means it now becomes a constant value, which also has its positive impact.
On x64 this means (without XDP):
4096 page
64 head, 320 tail
3712 HW buffer size
3686 max MTU w/o frags
Previously, the maximum MTU w/o splitting a frame into several buffers was 3046.
Increased buffer size allows us to reach the maximum frame size w/ frags supported by HW: 16382 bytes (MTU 16356). Reflect it in the netdev config as well. Relying on max single buffer size when calculating MTU was not correct.
Move around a couple of fields in &iavf_ring after ::rx_buf_len removal to reduce holes and improve cache locality.
Instead of providing the Rx definitions, which can and will be reused in rest of the drivers, exclusively for IAVF, do that in the libie header. Non-PP drivers could still use at least some of them and lose a couple copied lines.
Function: add/remove: 0/0 grow/shrink: 3/9 up/down: 18/-265 (-247)
+ even reclaims a half percent of performance, nice.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 32 +----- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 96 +++++++---------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 100 +----------------- drivers/net/ethernet/intel/iavf/iavf_type.h | 2 - .../net/ethernet/intel/iavf/iavf_virtchnl.c | 15 +-- include/linux/net/intel/libie/rx.h | 35 ++++++ 6 files changed, 85 insertions(+), 195 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +4 -28
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2013 - 2018 Intel Corporation. */ +#include <linux/net/intel/libie/rx.h> +#include "iavf.h" #include "iavf_prototype.h" #include "iavf_client.h"
@@ -709,32 +711,10 @@ static void iavf_configure_tx(struct iavf_adapter *adapter)**/ static void iavf_configure_rx (struct iavf_adapter *adapter) { -unsigned int rx_buf_len =IAVF_RXBUFFER_2048 ;struct iavf_hw *hw = &adapter->hw; -int i; - -if (PAGE_SIZE <8192 ) { -struct net_device *netdev = adapter->netdev; -/* For jumbo frames on systems with 4K pages we have to use -* an order 1 page, so we might as well increase the size -* of our Rx buffer to make better use of the available space -*/ - rx_buf_len =IAVF_RXBUFFER_3072 ; - -/* We use a 1536 buffer size for configurations with -* standard Ethernet mtu. On x86 this gives us enough room -* for shared info and 192 bytes of padding. -*/ -if (!IAVF_2K_TOO_SMALL_WITH_PADDING && - (netdev->mtu <=ETH_DATA_LEN )) - rx_buf_len =IAVF_RXBUFFER_1536 -NET_IP_ALIGN ; - } - -for (i =0 ; i < adapter->num_active_queues; i++) { +for (u32 i =0 ; i < adapter->num_active_queues; i++) adapter->rx_rings[i].tail = hw->hw_addr +IAVF_QRX_TAIL1 (i); - adapter->rx_rings[i].rx_buf_len = rx_buf_len; - } }/**
@@ -2577,11 +2557,7 @@ static void iavf_init_config_adapter(struct iavf_adapter *adapter) netdev->netdev_ops = &iavf_netdev_ops;iavf_set_ethtool_ops (netdev); - netdev->watchdog_timeo =5 *HZ ; - -/* MTU range: 68 - 9710 */ - netdev->min_mtu =ETH_MIN_MTU ; - netdev->max_mtu =IAVF_MAX_RXBUFFER -IAVF_PACKET_HDR_PAD ; + netdev->max_mtu =LIBIE_MAX_MTU ;if (!is_valid_ether_addr (adapter->hw.mac.addr)) { dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
drivers/net/ethernet/intel/iavf/iavf_txrx.c +38 -58
236 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +3 -97
145 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_type.h +0 -2
@@ -10,8 +10,6 @@#include "iavf_adminq.h" #include "iavf_devids.h" -#define IAVF_RXQ_CTX_DBUFF_SHIFT 7 -/* IAVF_MASK is a macro used on 32 bit registers */ #define IAVF_MASK (mask, shift) ((u32)(mask) << (shift))
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +5 -10
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2013 - 2018 Intel Corporation. */ +#include <linux/net/intel/libie/rx.h> +#include "iavf.h" #include "iavf_prototype.h" #include "iavf_client.h"
@@ -269,13 +271,12 @@ int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)void iavf_configure_queues (struct iavf_adapter *adapter) {struct virtchnl_vsi_queue_config_info *vqci; -int i, max_frame = adapter->vf_res->max_mtu; +u32 i, max_frame = adapter->vf_res->max_mtu;int pairs = adapter->num_active_queues;struct virtchnl_queue_pair_info *vqpi;size_t len; -if (max_frame >IAVF_MAX_RXBUFFER || !max_frame) - max_frame =IAVF_MAX_RXBUFFER ; + max_frame =min_not_zero (max_frame,LIBIE_MAX_RX_FRM_LEN );if (adapter->current_op !=VIRTCHNL_OP_UNKNOWN ) {/* bail because we already have a command pending */
@@ -289,10 +290,6 @@ void iavf_configure_queues(struct iavf_adapter *adapter)if (!vqci)return ; -/* Limit maximum frame size when jumbo frames is not enabled */ -if (adapter->netdev->mtu <=ETH_DATA_LEN ) - max_frame =IAVF_RXBUFFER_1536 -NET_IP_ALIGN ; - vqci->vsi_id = adapter->vsi_res->vsi_id; vqci->num_queue_pairs = pairs; vqpi = vqci->qpair;
@@ -309,9 +306,7 @@ void iavf_configure_queues(struct iavf_adapter *adapter) vqpi->rxq.ring_len = adapter->rx_rings[i].count; vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma; vqpi->rxq.max_pkt_size = max_frame; - vqpi->rxq.databuffer_size = -ALIGN (adapter->rx_rings[i].rx_buf_len, -BIT_ULL (IAVF_RXQ_CTX_DBUFF_SHIFT )); + vqpi->rxq.databuffer_size =LIBIE_RX_BUF_LEN ; vqpi++; }
include/linux/net/intel/libie/rx.h +35 -0
@@ -4,6 +4,7 @@#ifndef __LIBIE_RX_H#define __LIBIE_RX_H +#include <linux/if_vlan.h> #include <linux/netdevice.h> /* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed
@@ -125,4 +126,38 @@ static inline void libie_skb_set_hash(struct sk_buff *skb, u32 hash, skb_set_hash(skb, hash, parsed.payload_layer); } +/* Rx MTU/buffer/truesize helpers. Mostly pure software-side; HW-defined values +* are valid for all Intel HW. +*/ + +/* Space reserved in front of each frame */ +#define LIBIE_SKB_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN) +/* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */ +#define LIBIE_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN) + +/* Truesize: total space wasted on each frame. Always use order-0 pages */ +#define LIBIE_RX_PAGE_ORDER 0 +#define LIBIE_RX_TRUESIZE (PAGE_SIZE << LIBIE_RX_PAGE_ORDER) +/* Rx buffer size config is a multiple of 128 */ +#define LIBIE_RX_BUF_LEN_ALIGN 128 +/* HW-writeable space in one buffer: truesize - headroom/tailroom, +* HW-aligned +*/ +#define __LIBIE_RX_BUF_LEN \ + ALIGN_DOWN(SKB_MAX_ORDER(LIBIE_SKB_HEADROOM, LIBIE_RX_PAGE_ORDER), \ + LIBIE_RX_BUF_LEN_ALIGN) +/* The largest size for a single descriptor as per HW */ +#define LIBIE_MAX_RX_BUF_LEN 9728U +/* "True" HW-writeable space: minimum from SW and HW values */ +#define LIBIE_RX_BUF_LEN min_t(u32, __LIBIE_RX_BUF_LEN, \ + LIBIE_MAX_RX_BUF_LEN) + +/* The maximum frame size as per HW (S/G) */ +#define __LIBIE_MAX_RX_FRM_LEN 16382U +/* ATST, HW can chain up to 5 Rx descriptors */ +#define LIBIE_MAX_RX_FRM_LEN min_t(u32, __LIBIE_MAX_RX_FRM_LEN, \ + LIBIE_RX_BUF_LEN * 5) +/* Maximum frame size minus LL overhead */ +#define LIBIE_MAX_MTU (LIBIE_MAX_RX_FRM_LEN - LIBIE_RX_LL_LEN) +#endif /* __LIBIE_RX_H */
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 6/12 net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h>
In reply to Alexander LobakinCurrently, touching <net/page_pool.h> triggers a rebuild of more than a half of the kernel. That's because it's included in <linux/skbuff.h>.
In 6a5bcd84e886 ("page_pool: Allow drivers to hint on SKB recycling"), Matteo included it to be able to call a couple functions defined there. Then, in 57f05bc2ab24 ("page_pool: keep pp info as long as page pool owns the page") one of the calls was removed, so only one left. It's call to page_pool_return_skb_page() in napi_frag_unref(). The function is external and doesn't have any dependencies. Having include of very niche page_pool.h only for that looks like an overkill. Instead, move the declaration of that function to skbuff.h itself, with a small comment that it's a special guest and should not be touched. Now, after a few include fixes in the drivers, touching page_pool.h only triggers rebuilding of the drivers using it and a couple core networking files.
--- drivers/net/ethernet/engleder/tsnep_main.c | 1 + drivers/net/ethernet/freescale/fec_main.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/params.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 1 + include/linux/skbuff.h | 4 +++- include/net/page_pool.h | 2 -- 9 files changed, 10 insertions(+), 3 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +1 -0
@@ -28,6 +28,7 @@#include <linux/iopoll.h> #include <linux/bpf.h> #include <linux/bpf_trace.h> +#include <net/page_pool.h> #include <net/xdp_sock_drv.h> #define TSNEP_RX_OFFSET (max(NET_SKB_PAD, XDP_PACKET_HEADROOM) + NET_IP_ALIGN)
drivers/net/ethernet/freescale/fec_main.c +1 -0
@@ -38,6 +38,7 @@#include <linux/in.h> #include <linux/ip.h> #include <net/ip.h> +#include <net/page_pool.h> #include <net/selftests.h> #include <net/tso.h> #include <linux/tcp.h>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -0
@@ -7,6 +7,7 @@#include <linux/interrupt.h> #include <linux/pci.h> +#include <net/page_pool.h> #include <net/tso.h> #include "otx2_reg.h"
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -16,6 +16,7 @@#include <linux/bpf.h> #include <linux/bpf_trace.h> #include <linux/bitfield.h> +#include <net/page_pool.h> #include "otx2_reg.h" #include "otx2_common.h"
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +1 -0
@@ -6,6 +6,7 @@#include "en/port.h" #include "en_accel/en_accel.h" #include "en_accel/ipsec.h" +#include <net/page_pool.h> #include <net/xdp_sock_drv.h> static u8 mlx5e_mpwrq_min_page_shift (struct mlx5_core_dev *mdev)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +1 -0
@@ -35,6 +35,7 @@#include "en/xdp.h" #include "en/params.h" #include <linux/bitfield.h> +#include <net/page_pool.h> int mlx5e_xdp_max_mtu (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk) {
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
@@ -15,6 +15,7 @@#include <linux/average.h> #include <linux/soc/mediatek/mtk_wed.h> #include <net/mac80211.h> +#include <net/page_pool.h> #include "util.h" #include "testmode.h"
include/linux/skbuff.h +3 -1
@@ -32,7 +32,6 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif
@@ -3422,6 +3421,9 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f)__skb_frag_ref (&skb_shinfo (skb)->frags[f]); } +/* Internal from net/core/page_pool.c, do not use in drivers directly */ +bool page_pool_return_skb_page (struct page *page,bool napi_safe); +static inline void napi_frag_unref (skb_frag_t *frag,bool recycle,bool napi_safe) {
include/net/page_pool.h +0 -2
@@ -240,8 +240,6 @@ inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool)return pool->p.dma_dir; } -bool page_pool_return_skb_page (struct page *page,bool napi_safe); -struct page_pool *page_pool_create (const struct page_pool_params *params);struct xdp_mem_info ;
Signature · 1 line
2.40.1
Re: [PATCH net-next v3 06/12] net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h>
Quoted 30 lines · Alexander Lobakin
Currently, touching <
net/page_pool.h> triggers a rebuild of more than a half of the kernel. That's because it's included in <linux/skbuff.h>.In
6a5bcd84e886("page_pool: Allow drivers to hint on SKB recycling"), Matteo included it to be able to call a couple functions defined there. Then, in57f05bc2ab24("page_pool: keep pp info as long as page pool owns the page") one of the calls was removed, so only one left. It's call topage_pool_return_skb_page()innapi_frag_unref(). The function is external and doesn't have any dependencies. Having include of very nichepage_pool.honly for that looks like an overkill. Instead, move the declaration of that function toskbuff.hitself, with a small comment that it's a special guest and should not be touched. Now, after a few include fixes in the drivers, touchingpage_pool.honly triggers rebuilding of the drivers using it and a couple core networking files.Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/engleder/tsnep_main.c | 1 + drivers/net/ethernet/freescale/fec_main.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/params.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 1 + include/linux/skbuff.h | 4 +++- include/net/page_pool.h | 2 -- 9 files changed, 10 insertions(+), 3 deletions(-)
<...>
Quoted 27 lines
include/linux/skbuff.h +3
-1@@ -32,7 +32,6 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif @@ -3422,6 +3421,9 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f)__skb_frag_ref (&skb_shinfo (skb)->frags[f]); } +/* Internal from net/core/page_pool.c, do not use in drivers directly */ +bool page_pool_return_skb_page (struct page *page,bool napi_safe); +static inline void napi_frag_unref (skb_frag_t *frag,bool recycle,bool napi_safe) {include/net/page_pool.h +0
-0
include/net/page_pool.h inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool) · line 245
Quoted 8 lines
include/net/page_pool.h +0
-2@@ -240,8 +240,6 @@ inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool)return pool->p.dma_dir; } -bool page_pool_return_skb_page (struct page *page,bool napi_safe); -struct page_pool *page_pool_create (const struct page_pool_params *params);struct xdp_mem_info ;
So the code as-is works, so I am providing my "Reviewed-by".
Consider the rest of this a suggestion or a "nice to have".
I wonder if we shouldn't also look at restructuring the function and just moving it to net/core/skbuff.c somewhere next to skb_pp_recycle.
I suspect we could look at pulling parts of it out as well. The pp_magic check should always be succeeding unless we have pages getting routed the wrong way somewhere. So maybe we should look at pulling it out and moving it to another part of the path such as __page_pool_put_page() and making it a bit more visible to catch those cases.
Alexander Lobakin
maintainerRe: [PATCH net-next v3 06/12] net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h>
From: Alexander H Duyck <[email protected]>
Date: Wed, 31 May 2023 08:21:03 -0700
Quoted 78 lines · Alexander Lobakin
Quoted 30 lines
Currently, touching <
net/page_pool.h> triggers a rebuild of more than a half of the kernel. That's because it's included in <linux/skbuff.h>.In
6a5bcd84e886("page_pool: Allow drivers to hint on SKB recycling"), Matteo included it to be able to call a couple functions defined there. Then, in57f05bc2ab24("page_pool: keep pp info as long as page pool owns the page") one of the calls was removed, so only one left. It's call topage_pool_return_skb_page()innapi_frag_unref(). The function is external and doesn't have any dependencies. Having include of very nichepage_pool.honly for that looks like an overkill. Instead, move the declaration of that function toskbuff.hitself, with a small comment that it's a special guest and should not be touched. Now, after a few include fixes in the drivers, touchingpage_pool.honly triggers rebuilding of the drivers using it and a couple core networking files.Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/engleder/tsnep_main.c | 1 + drivers/net/ethernet/freescale/fec_main.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/params.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 1 + include/linux/skbuff.h | 4 +++- include/net/page_pool.h | 2 -- 9 files changed, 10 insertions(+), 3 deletions(-)<...>
Quoted 27 lines
include/linux/skbuff.h +3
-1@@ -32,7 +32,6 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif @@ -3422,6 +3421,9 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f)__skb_frag_ref (&skb_shinfo (skb)->frags[f]); } +/* Internal from net/core/page_pool.c, do not use in drivers directly */ +bool page_pool_return_skb_page (struct page *page,bool napi_safe); +static inline void napi_frag_unref (skb_frag_t *frag,bool recycle,bool napi_safe) {include/net/page_pool.h +0
-0include/net/page_pool.h inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool) · line 245
Quoted 8 lines
include/net/page_pool.h +0
-2@@ -240,8 +240,6 @@ inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool)return pool->p.dma_dir; } -bool page_pool_return_skb_page (struct page *page,bool napi_safe); -struct page_pool *page_pool_create (const struct page_pool_params *params);struct xdp_mem_info ;So the code as-is works, so I am providing my "Reviewed-by".
Reviewed-by Alexander Duyck <[email protected]>Consider the rest of this a suggestion or a "nice to have".
I wonder if we shouldn't also look at restructuring the function and just moving it to
net/core/skbuff.csomewhere next toskb_pp_recycle.
Quoted 6 lines
I suspect we could look at pulling parts of it out as well. The
pp_magiccheck should always be succeeding unless we have pages getting routed the wrong way somewhere. So maybe we should look at pulling it out and moving it to another part of the path such as__page_pool_put_page()and making it a bit more visible to catch those cases.
I've just noticed that this function is exported with no modular users ._. Anyway, I feel like it's a good way to go. The entire function, apart from the magic check, can be moved and made static. And the magic can be moved one level up, right...
v4 will happen either way I guess, so maybe I'll replace this patch with that kinda change.
Thanks,
Olek
Alexander Lobakin
maintainerRe: [PATCH net-next v3 06/12] net: skbuff: don't include <net/page_pool.h> into <linux/skbuff.h>
From: Alexander Lobakin <[email protected]>
Date: Wed, 31 May 2023 17:28:30 +0200
Quoted 81 lines
From: Alexander H Duyck <[email protected]>
Date: Wed, 31 May 2023 08:21:03 -0700Quoted 78 lines · Alexander Lobakin
Quoted 30 lines
Currently, touching <
net/page_pool.h> triggers a rebuild of more than a half of the kernel. That's because it's included in <linux/skbuff.h>.In
6a5bcd84e886("page_pool: Allow drivers to hint on SKB recycling"), Matteo included it to be able to call a couple functions defined there. Then, in57f05bc2ab24("page_pool: keep pp info as long as page pool owns the page") one of the calls was removed, so only one left. It's call topage_pool_return_skb_page()innapi_frag_unref(). The function is external and doesn't have any dependencies. Having include of very nichepage_pool.honly for that looks like an overkill. Instead, move the declaration of that function toskbuff.hitself, with a small comment that it's a special guest and should not be touched. Now, after a few include fixes in the drivers, touchingpage_pool.honly triggers rebuilding of the drivers using it and a couple core networking files.Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/engleder/tsnep_main.c | 1 + drivers/net/ethernet/freescale/fec_main.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/params.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 + drivers/net/wireless/mediatek/mt76/mt76.h | 1 + include/linux/skbuff.h | 4 +++- include/net/page_pool.h | 2 -- 9 files changed, 10 insertions(+), 3 deletions(-)<...>
Quoted 27 lines
include/linux/skbuff.h +3
-1@@ -32,7 +32,6 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif @@ -3422,6 +3421,9 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f)__skb_frag_ref (&skb_shinfo (skb)->frags[f]); } +/* Internal from net/core/page_pool.c, do not use in drivers directly */ +bool page_pool_return_skb_page (struct page *page,bool napi_safe); +static inline void napi_frag_unref (skb_frag_t *frag,bool recycle,bool napi_safe) {include/net/page_pool.h +0
-0include/net/page_pool.h inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool) · line 245
Quoted 8 lines
include/net/page_pool.h +0
-2@@ -240,8 +240,6 @@ inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool *pool)return pool->p.dma_dir; } -bool page_pool_return_skb_page (struct page *page,bool napi_safe); -struct page_pool *page_pool_create (const struct page_pool_params *params);struct xdp_mem_info ;So the code as-is works, so I am providing my "Reviewed-by".
Reviewed-by Alexander Duyck <[email protected]>Consider the rest of this a suggestion or a "nice to have".
I wonder if we shouldn't also look at restructuring the function and just moving it to
net/core/skbuff.csomewhere next toskb_pp_recycle.
Quoted 8 lines
Quoted 6 lines
I suspect we could look at pulling parts of it out as well. The
pp_magiccheck should always be succeeding unless we have pages getting routed the wrong way somewhere. So maybe we should look at pulling it out and moving it to another part of the path such as__page_pool_put_page()and making it a bit more visible to catch those cases.I've just noticed that this function is exported with no modular users ._.
^^^ pls ignore this nonsense lol
Quoted 8 lines
Anyway, I feel like it's a good way to go. The entire function, apart from the magic check, can be moved and made static. And the magic can be moved one level up, right...
v4 will happen either way I guess, so maybe I'll replace this patch with that kinda change.Thanks,
Olek
Alexander Lobakin
maintainerPATCH v3 7/12 net: page_pool: avoid calling no-op externals when possible
In reply to Alexander LobakinTurned out page_pool_put{,_full}_page() can burn quite a bunch of cycles even when on DMA-coherent platforms (like x86) with no active IOMMU or swiotlb, just for the call ladder.
Indeed, it's
page_pool_put_page()
page_pool_put_defragged_page() <- external
__page_pool_put_page()
page_pool_dma_sync_for_device() <- non-inline
dma_sync_single_range_for_device()
dma_sync_single_for_device() <- external
dma_direct_sync_single_for_device()
dev_is_dma_coherent() <- exit
For the inline functions, no guarantees the compiler won't uninline them (they're clearly not one-liners and sometimes compilers uninline even 2 + 2). The first external call is necessary, but the rest 2+ are done for nothing each time, plus a bunch of checks here and there. Since Page Pool mappings are long-term and for one "device + addr" pair dma_need_sync() will always return the same value (basically, whether it belongs to an swiotlb pool), addresses can be tested once right after they're obtained and the result can be reused until the page is unmapped. Define new PP flag, which will mean "do DMA syncs for device, but only when needed" and turn it on by default when the driver asks to sync pages. When a page is mapped, check whether it needs syncs and if so, replace that "sync when needed" back to "always do syncs" globally for the whole pool (better safe than sorry). As long as a pool has no pages requiring DMA syncs, this cuts off a good piece of calls and checks. On my x86_64, this gives from 2% to 5% performance benefit with no negative impact for cases when IOMMU is on and the shortcut can't be used.
--- include/net/page_pool.h | 3 +++ net/core/page_pool.c | 10 ++++++++++ 2 files changed, 13 insertions(+)
include/net/page_pool.h +3 -0
@@ -46,6 +46,9 @@* device driver responsibility */ #define PP_FLAG_PAGE_FRAG BIT(2)/* for page frag feature */ +#define PP_FLAG_DMA_MAYBE_SYNC BIT(3)/* Internal, should not be used in +* drivers +*/ #define PP_FLAG_ALL (PP_FLAG_DMA_MAP |\ PP_FLAG_DMA_SYNC_DEV |\ PP_FLAG_PAGE_FRAG)
net/core/page_pool.c +10 -0
@@ -198,6 +198,10 @@ static int page_pool_init(struct page_pool *pool,/* pool->p.offset has to be set according to the address * offset used by the DMA engine to start copying rx data */ + +/* Try to avoid calling no-op syncs */ + pool->p.flags |=PP_FLAG_DMA_MAYBE_SYNC ; + pool->p.flags &= ~PP_FLAG_DMA_SYNC_DEV ; } if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT &&
@@ -346,6 +350,12 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page)page_pool_set_dma_addr (page, dma); +if ((pool->p.flags &PP_FLAG_DMA_MAYBE_SYNC ) && +dma_need_sync (pool->p.dev, dma)) { + pool->p.flags |=PP_FLAG_DMA_SYNC_DEV ; + pool->p.flags &= ~PP_FLAG_DMA_MAYBE_SYNC ; + } +if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV )page_pool_dma_sync_for_device (pool, page, pool->p.max_len);
Signature · 1 line
2.40.1
Alexander Lobakin
maintainerPATCH v3 8/12 net: page_pool: add DMA-sync-for-CPU inline helpers
In reply to Alexander LobakinEach driver is responsible for syncing buffers written by HW for CPU before accessing them. Almost each PP-enabled driver uses the same pattern, which could be shorthanded into a static inline to make driver code a little bit more compact.
Introduce a couple such functions. The first one takes the actual size of the data written by HW and is the main one to be used on Rx. The second does the same, but only if the PP performs DMA synchronizations at all. The last one picks max_len from the PP params and is designed for more extreme cases when the size is unknown, but the buffer still needs to be synced.
Also constify pointer arguments of page_pool_get_dma_dir() and page_pool_get_dma_addr() to give a bit more room for optimization, as both of them are read-only.
--- include/net/page_pool.h | 64 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-)
include/net/page_pool.h +60 -4
@@ -32,7 +32,7 @@#include <linux/mm.h> /* Needed by ptr_ring */ #include <linux/ptr_ring.h> -#include <linux/dma-direction.h> +#include <linux/dma-mapping.h> #define PP_FLAG_DMA_MAP BIT(0)/* Should page_pool do the DMA * map/unmap
@@ -237,8 +237,8 @@ static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool,/* get the stored dma direction. A driver might decide to treat this locally and * avoid the extra cache line from page_pool to determine the direction */ -static -inline enum dma_data_direction page_pool_get_dma_dir (struct page_pool *pool) +static inline enum dma_data_direction +page_pool_get_dma_dir (const struct page_pool *pool) {return pool->p.dma_dir; }
@@ -361,7 +361,7 @@ static inline void page_pool_recycle_direct(struct page_pool *pool,#define PAGE_POOL_DMA_USE_PP_FRAG_COUNT \ (sizeof(dma_addr_t) > sizeof(unsigned long)) -static inline dma_addr_t page_pool_get_dma_addr (struct page *page) +static inline dma_addr_t page_pool_get_dma_addr (const struct page *page) {dma_addr_t ret = page->dma_addr;
@@ -378,6 +378,62 @@ static inline void page_pool_set_dma_addr(struct page *page, dma_addr_t addr) page->dma_addr_upper =upper_32_bits (addr); } +/** +* __page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW +* @pool: page_pool which this page belongs to +* @page: page to sync +* @dma_sync_size: size of the data written to the page +* +* Can be used as a shorthand to sync Rx pages before accessing them in the +* driver. Caller must ensure the pool was created with %PP_FLAG_DMA_MAP. +* Note that this version performs DMA sync unconditionally, even if the +* associated PP doesn't perform sync-for-device. Consider the non-underscored +* version first if unsure. +*/ +static inline void __page_pool_dma_sync_for_cpu (const struct page_pool *pool, +const struct page *page, +u32 dma_sync_size) +{ +dma_sync_single_range_for_cpu (pool->p.dev, +page_pool_get_dma_addr (page), + pool->p.offset, dma_sync_size, +page_pool_get_dma_dir (pool)); +} + +/** +* page_pool_dma_sync_for_cpu - sync Rx page for CPU if needed +* @pool: page_pool which this page belongs to +* @page: page to sync +* @dma_sync_size: size of the data written to the page +* +* Performs DMA sync for CPU, but *only* when: +* 1) page_pool was created with %PP_FLAG_DMA_SYNC_DEV to manage DMA syncs; +* 2) AND sync shortcut is not available (IOMMU, swiotlb, non-coherent DMA, ...) +*/ +static inline void page_pool_dma_sync_for_cpu (const struct page_pool *pool, +const struct page *page, +u32 dma_sync_size) +{ +if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) +__page_pool_dma_sync_for_cpu (pool, page, dma_sync_size); +} + +/** +* page_pool_dma_sync_full_for_cpu - sync full Rx page for CPU (if needed) +* @pool: page_pool which this page belongs to +* @page: page to sync +* +* Performs sync for the entire length exposed to hardware. Can be used on +* DMA errors or before freeing the page, when it's unknown whether the HW +* touched the buffer. +*/ +static inline void +page_pool_dma_sync_full_for_cpu (const struct page_pool *pool, +const struct page *page) +{ +page_pool_dma_sync_for_cpu (pool, page, pool->p.max_len); +} +static inline bool is_page_pool_compiled_in (void ) {#ifdef CONFIG_PAGE_POOL
Signature · 6 lines
2.40.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Alexander Lobakin
maintainerPATCH v3 9/12 iavf: switch to Page Pool
In reply to Alexander LobakinNow that the IAVF driver simply uses dev_alloc_page() + free_page() with no custom recycling logics and one whole page per frame, it can easily be switched to using Page Pool API instead.
Introduce libie_rx_page_pool_create(), a wrapper for creating a PP with the default libie settings applicable to all Intel hardware, and replace the alloc/free calls with the corresponding PP functions, including the newly added sync-for-CPU helpers. Use skb_mark_for_recycle() to bring back the recycling and restore the initial performance.
From the important object code changes, worth mentioning that __iavf_alloc_rx_pages() is now inlined due to the greatly reduced size. The resulting driver is on par with the pre-series code and 1-2% slower than the "optimized" version right before the recycling removal. But the number of locs and object code bytes slaughtered is much more important here after all, not speaking of that there's still a vast space for optimization and improvements.
--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/iavf/iavf_txrx.c | 126 +++++--------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 8 +- drivers/net/ethernet/intel/libie/rx.c | 28 +++++ include/linux/net/intel/libie/rx.h | 5 +- 5 files changed, 69 insertions(+), 99 deletions(-)
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -86,6 +86,7 @@ config E1000E_HWTS config LIBIE tristate + select PAGE_POOL help libie (Intel Ethernet library) is a common library containing routines shared by several Intel Ethernet drivers.
drivers/net/ethernet/intel/iavf/iavf_txrx.c +32 -94
252 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4 -4
@@ -83,9 +83,6 @@ enum iavf_dyn_idx_t {#define iavf_rx_desc iavf_32byte_rx_desc -#define IAVF_RX_DMA_ATTR \ - (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) -/** * iavf_test_staterr - tests bits in Rx descriptor status and error fields * @rx_desc: pointer to receive descriptor (in le64 format)
@@ -240,7 +237,10 @@ struct iavf_rx_queue_stats {struct iavf_ring {struct iavf_ring *next;/* pointer to next ring in q_vector */ void *desc;/* Descriptor ring memory */ -struct device *dev;/* Used for DMA mapping */ +union { +struct page_pool *pool;/* Used for Rx page management */ +struct device *dev;/* Used for DMA mapping on Tx */ + };struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi;
drivers/net/ethernet/intel/libie/rx.c +28 -0
@@ -105,6 +105,34 @@ const struct libie_rx_ptype_parsed libie_rx_ptype_lut[LIBIE_RX_PTYPE_NUM] = { };EXPORT_SYMBOL_NS_GPL (libie_rx_ptype_lut,LIBIE ); +/* Page Pool */ + +/** +* libie_rx_page_pool_create - create a PP with the default libie settings +* @napi: &napi_struct covering this PP (no usage outside its poll loops) +* @size: size of the PP, usually simply Rx queue len +* +* Returns &page_pool on success, casted -errno on failure. +*/ +struct page_pool *libie_rx_page_pool_create (struct napi_struct *napi, +u32 size) +{ +const struct page_pool_params pp = { + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .order =LIBIE_RX_PAGE_ORDER , + .pool_size = size, + .nid =NUMA_NO_NODE , + .dev = napi->dev->dev.parent, + .napi = napi, + .dma_dir =DMA_FROM_DEVICE , + .max_len =LIBIE_RX_BUF_LEN , + .offset =LIBIE_SKB_HEADROOM , + }; + +return page_pool_create (&pp); +} +EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_create,LIBIE ); +MODULE_AUTHOR ("Intel Corporation" );MODULE_DESCRIPTION ("Intel(R) Ethernet common library" );MODULE_LICENSE ("GPL" );
include/linux/net/intel/libie/rx.h +4 -1
@@ -5,7 +5,7 @@#define __LIBIE_RX_H#include <linux/if_vlan.h> -#include <linux/netdevice.h> +#include <net/page_pool.h> /* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed * bitfield struct.
@@ -160,4 +160,7 @@ static inline void libie_skb_set_hash(struct sk_buff *skb, u32 hash,/* Maximum frame size minus LL overhead */ #define LIBIE_MAX_MTU (LIBIE_MAX_RX_FRM_LEN - LIBIE_RX_LL_LEN) +struct page_pool *libie_rx_page_pool_create (struct napi_struct *napi, +u32 size); +#endif /* __LIBIE_RX_H */
Signature · 6 lines
2.40.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Re: [PATCH net-next v3 09/12] iavf: switch to Page Pool
Quoted 60 lines · Alexander Lobakin
Now that the IAVF driver simply uses
dev_alloc_page()+free_page()with no custom recycling logics and one whole page per frame, it can easily be switched to using Page Pool API instead.
Introducelibie_rx_page_pool_create(), a wrapper for creating a PP with the default libie settings applicable to all Intel hardware, and replace the alloc/free calls with the corresponding PP functions, including the newly added sync-for-CPU helpers. Useskb_mark_for_recycle()to bring back the recycling and restore the initial performance.From the important object code changes, worth mentioning that
__iavf_alloc_rx_pages()is now inlined due to the greatly reduced size. The resulting driver is on par with the pre-series code and 1-2% slower than the "optimized" version right before the recycling removal. But the number of locs and object code bytes slaughtered is much more important here after all, not speaking of that there's still a vast space for optimization and improvements.Signed-off-by Alexander Lobakin <[email protected]>--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/iavf/iavf_txrx.c | 126 +++++--------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 8 +- drivers/net/ethernet/intel/libie/rx.c | 28 +++++ include/linux/net/intel/libie/rx.h | 5 +- 5 files changed, 69 insertions(+), 99 deletions(-)drivers/net/ethernet/intel/Kconfig +1
-0@@ -86,6 +86,7 @@ config E1000E_HWTS config LIBIE tristate + select PAGE_POOL help libie (Intel Ethernet library) is a common library containing routines shared by several Intel Ethernet drivers.drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-3@@ -3,7 +3,6 @@#include <linux/net/intel/libie/rx.h> #include <linux/prefetch.h> -#include <net/page_pool.h> #include "iavf.h" #include "iavf_trace.h" @@ -691,8 +690,6 @@ int iavf_setup_tx_descriptors(struct iavf_ring *tx_ring)**/ void iavf_clean_rx_ring (struct iavf_ring *rx_ring) { -u16 i; -/* ring already cleared, nothing to do */ if (!rx_ring->rx_pages)return ;
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 703
Quoted 5 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +1
-1@@ -703,28 +700,17 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring) }/* Free all the Rx ring sk_buffs */ -for (i =0 ; i < rx_ring->count; i++) { +for (u32 i =0 ; i < rx_ring->count; i++) {
Did we make a change to our coding style to allow declaration of variables inside of for statements? Just wondering if this is a change since the recent updates to the ISO C standard, or if this doesn't match up with what we would expect per the coding standard.
Quoted 32 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +4
-13struct page *page = rx_ring->rx_pages[i]; -dma_addr_t dma;if (!page)continue ; - dma =page_pool_get_dma_addr (page); -/* Invalidate cache lines that may have been written to by * device so that we avoid corrupting memory. */ -dma_sync_single_range_for_cpu (rx_ring->dev, dma, -LIBIE_SKB_HEADROOM , -LIBIE_RX_BUF_LEN , -DMA_FROM_DEVICE ); - -/* free resources associated with mapping */ -dma_unmap_page_attrs (rx_ring->dev, dma,LIBIE_RX_TRUESIZE , -DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR ); - -__free_page (page); +page_pool_dma_sync_full_for_cpu (rx_ring->pool, page); +page_pool_put_full_page (rx_ring->pool, page, false); } rx_ring->next_to_clean =0 ;@@ -739,10 +725,15 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring)**/ void iavf_free_rx_resources (struct iavf_ring *rx_ring) { +struct device *dev = rx_ring->pool->p.dev; +
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 739
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +3
-0iavf_clean_rx_ring (rx_ring);kfree (rx_ring->rx_pages); rx_ring->rx_pages =NULL ; +page_pool_destroy (rx_ring->pool); + rx_ring->dev = dev; +if (rx_ring->desc) {dma_free_coherent (rx_ring->dev, rx_ring->size, rx_ring->desc, rx_ring->dma);
Not a fan of this switching back and forth between being a page pool pointer and a dev pointer. Seems problematic as it is easily misinterpreted. I would say that at a minimum stick to either it is page_pool(Rx) or dev(Tx) on a ring type basis.
Quoted 36 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +14
-1@@ -759,13 +750,15 @@ void iavf_free_rx_resources(struct iavf_ring *rx_ring)int iavf_setup_rx_descriptors (struct iavf_ring *rx_ring) {struct device *dev = rx_ring->dev; +struct page_pool *pool; +int ret = -ENOMEM ;/* warn if we are about to overwrite the pointer */ WARN_ON (rx_ring->rx_pages); rx_ring->rx_pages =kcalloc (rx_ring->count,sizeof (*rx_ring->rx_pages),GFP_KERNEL );if (!rx_ring->rx_pages) -return -ENOMEM ; +return ret;u64_stats_init (&rx_ring->syncp);@@ -781,15 +774,27 @@ int iavf_setup_rx_descriptors(struct iavf_ring *rx_ring) goto err; } + pool =libie_rx_page_pool_create (&rx_ring->q_vector->napi, + rx_ring->count); +if (IS_ERR (pool)) { + ret =PTR_ERR (pool); + goto err_free_dma; + } + + rx_ring->pool = pool; + rx_ring->next_to_clean =0 ; rx_ring->next_to_use =0 ;return 0 ; + +err_free_dma:
drivers/net/ethernet/intel/iavf/iavf_txrx.c int iavf_setup_rx_descriptors(struct iavf_ring *rx_ring) · line 800
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +2
-1+dma_free_coherent (dev, rx_ring->size, rx_ring->desc, rx_ring->dma); err:kfree (rx_ring->rx_pages); rx_ring->rx_pages =NULL ; -return -ENOMEM ; +return ret; }/**
This setup works for iavf, however for i40e/ice you may run into issues since the setup_rx_descriptors call is also used to setup the ethtool loopback test w/o a napi struct as I recall so there may not be a q_vector.
Quoted 173 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +8
-75@@ -810,40 +815,6 @@ static inline void iavf_release_rx_desc(struct iavf_ring *rx_ring, u32 val)writel (val, rx_ring->tail); } -/** -* iavf_alloc_mapped_page - allocate and map a new page -* @dev: device used for DMA mapping -* @gfp: GFP mask to allocate page -* -* Returns a new &page if the it was successfully allocated, %NULL otherwise. -**/ -static struct page *iavf_alloc_mapped_page (struct device *dev,gfp_t gfp) -{ -struct page *page; -dma_addr_t dma; - -/* alloc new page for storage */ - page =__dev_alloc_page (gfp); -if (unlikely (!page)) -return NULL ; - -/* map page for use */ - dma =dma_map_page_attrs (dev, page,0 ,PAGE_SIZE ,DMA_FROM_DEVICE , -IAVF_RX_DMA_ATTR ); - -/* if mapping failed free memory back to system since -* there isn't much point in holding memory we can't use -*/ -if (dma_mapping_error (dev, dma)) { -__free_page (page); -return NULL ; - } - -page_pool_set_dma_addr (page, dma); - -return page; -} -/** * iavf_receive_skb - Send a completed packet up the stack * @rx_ring: rx ring in play @@ -877,7 +848,7 @@ static void iavf_receive_skb(struct iavf_ring *rx_ring,static u32 __iavf_alloc_rx_pages (struct iavf_ring *rx_ring,u32 to_refill,gfp_t gfp) { -struct device *dev = rx_ring->dev; +struct page_pool *pool = rx_ring->pool;u32 ntu = rx_ring->next_to_use;union iavf_rx_desc *rx_desc;@@ -891,7 +862,7 @@ static u32 __iavf_alloc_rx_pages(struct iavf_ring *rx_ring, u32 to_refill,struct page *page;dma_addr_t dma; - page =iavf_alloc_mapped_page (dev, gfp); + page =page_pool_alloc_pages (pool, gfp);if (!page) { rx_ring->rx_stats.alloc_page_failed++;break ;@@ -900,11 +871,6 @@ static u32 __iavf_alloc_rx_pages(struct iavf_ring *rx_ring, u32 to_refill, rx_ring->rx_pages[ntu] = page; dma =page_pool_get_dma_addr (page); -/* sync the buffer for use by the device */ -dma_sync_single_range_for_device (dev, dma,LIBIE_SKB_HEADROOM , -LIBIE_RX_BUF_LEN , -DMA_FROM_DEVICE ); -/* Refresh the desc even if buffer_addrs didn't change * because each write-back erases this info. */ @@ -1091,21 +1057,6 @@ static void iavf_add_rx_frag(struct sk_buff *skb, struct page *page, u32 size) LIBIE_SKB_HEADROOM, size, LIBIE_RX_TRUESIZE); } -/** -* iavf_sync_rx_page - Synchronize received data for use -* @dev: device used for DMA mapping -* @page: Rx page containing the data -* @size: size of the received data -* -* This function will synchronize the Rx buffer for use by the CPU. -*/ -static void iavf_sync_rx_page (struct device *dev,struct page *page,u32 size) -{ -dma_sync_single_range_for_cpu (dev,page_pool_get_dma_addr (page), -LIBIE_SKB_HEADROOM , size, -DMA_FROM_DEVICE ); -} -/** * iavf_build_skb - Build skb around an existing buffer * @page: Rx page to with the data @@ -1128,6 +1079,8 @@ static struct sk_buff *iavf_build_skb(struct page *page, u32 size)if (unlikely (!skb))return NULL ; +skb_mark_for_recycle (skb); +/* update pointers within the skb to store the data */ skb_reserve (skb,LIBIE_SKB_HEADROOM );__skb_put (skb, size);@@ -1135,19 +1088,6 @@ static struct sk_buff *iavf_build_skb(struct page *page, u32 size)return skb; } -/** -* iavf_unmap_rx_page - Unmap used page -* @dev: device used for DMA mapping -* @page: page to release -*/ -static void iavf_unmap_rx_page (struct device *dev,struct page *page) -{ -dma_unmap_page_attrs (dev,page_pool_get_dma_addr (page), -LIBIE_RX_TRUESIZE ,DMA_FROM_DEVICE , -IAVF_RX_DMA_ATTR ); -page_pool_set_dma_addr (page,0 ); -} -/** * iavf_is_non_eop - process handling of non-EOP buffers * @rx_ring: Rx ring being processed @@ -1190,8 +1130,8 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)unsigned int total_rx_bytes =0 , total_rx_packets =0 ;const gfp_t gfp =GFP_ATOMIC | __GFP_NOWARN;u32 to_refill =IAVF_DESC_UNUSED (rx_ring); +struct page_pool *pool = rx_ring->pool;struct sk_buff *skb = rx_ring->skb; -struct device *dev = rx_ring->dev;u32 ntc = rx_ring->next_to_clean;u32 ring_size = rx_ring->count;u32 cleaned_count =0 ;@@ -1240,13 +1180,11 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)* stripped by the HW. */ if (unlikely (!size)) { -iavf_unmap_rx_page (dev, page); -__free_page (page); +page_pool_recycle_direct (pool, page); goto skip_data; } -iavf_sync_rx_page (dev, page, size); -iavf_unmap_rx_page (dev, page); +page_pool_dma_sync_for_cpu (pool, page, size);/* retrieve a buffer from the ring */ if (skb)@@ -1256,7 +1194,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)/* exit if we failed to retrieve a buffer */ if (!skb) { -__free_page (page); +page_pool_put_page (pool, page, size, true); rx_ring->rx_stats.alloc_buff_failed++;break ; }drivers/net/ethernet/intel/iavf/iavf_txrx.h +0
-3@@ -83,9 +83,6 @@ enum iavf_dyn_idx_t {#define iavf_rx_desc iavf_32byte_rx_desc -#define IAVF_RX_DMA_ATTR \ - (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) -/** * iavf_test_staterr - tests bits in Rx descriptor status and error fields * @rx_desc: pointer to receive descriptor (in le64 format) @@ -240,7 +237,10 @@ struct iavf_rx_queue_stats {struct iavf_ring {
drivers/net/ethernet/intel/iavf/iavf_txrx.h struct iavf_rx_queue_stats { · line 246
Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4
-1struct iavf_ring *next;/* pointer to next ring in q_vector */ void *desc;/* Descriptor ring memory */ -struct device *dev;/* Used for DMA mapping */ +union { +struct page_pool *pool;/* Used for Rx page management */ +struct device *dev;/* Used for DMA mapping on Tx */ + };struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi;
Would it make more sense to have the page pool in the q_vector rather than the ring? Essentially the page pool is associated per napi instance so it seems like it would make more sense to store it with the napi struct rather than potentially have multiple instances per napi.
Quoted 60 lines
drivers/net/ethernet/intel/libie/rx.c +28
-0@@ -105,6 +105,34 @@ const struct libie_rx_ptype_parsed libie_rx_ptype_lut[LIBIE_RX_PTYPE_NUM] = { };EXPORT_SYMBOL_NS_GPL (libie_rx_ptype_lut,LIBIE ); +/* Page Pool */ + +/** +* libie_rx_page_pool_create - create a PP with the default libie settings +* @napi: &napi_struct covering this PP (no usage outside its poll loops) +* @size: size of the PP, usually simply Rx queue len +* +* Returns &page_pool on success, casted -errno on failure. +*/ +struct page_pool *libie_rx_page_pool_create (struct napi_struct *napi, +u32 size) +{ +const struct page_pool_params pp = { + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .order =LIBIE_RX_PAGE_ORDER , + .pool_size = size, + .nid =NUMA_NO_NODE , + .dev = napi->dev->dev.parent, + .napi = napi, + .dma_dir =DMA_FROM_DEVICE , + .max_len =LIBIE_RX_BUF_LEN , + .offset =LIBIE_SKB_HEADROOM , + }; + +return page_pool_create (&pp); +} +EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_create,LIBIE ); +MODULE_AUTHOR ("Intel Corporation" );MODULE_DESCRIPTION ("Intel(R) Ethernet common library" );MODULE_LICENSE ("GPL" );include/linux/net/intel/libie/rx.h +4
-1@@ -5,7 +5,7 @@#define __LIBIE_RX_H#include <linux/if_vlan.h> -#include <linux/netdevice.h> +#include <net/page_pool.h> /* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed * bitfield struct. @@ -160,4 +160,7 @@ static inline void libie_skb_set_hash(struct sk_buff *skb, u32 hash,/* Maximum frame size minus LL overhead */ #define LIBIE_MAX_MTU (LIBIE_MAX_RX_FRM_LEN - LIBIE_RX_LL_LEN) +struct page_pool *libie_rx_page_pool_create (struct napi_struct *napi, +u32 size); +#endif /* __LIBIE_RX_H */
Alexander Lobakin
maintainerRe: [PATCH net-next v3 09/12] iavf: switch to Page Pool
From: Alexander H Duyck <[email protected]>
Date: Wed, 31 May 2023 09:19:06 -0700
Quoted 4 lines · Alexander Lobakin
Quoted 3 lines
Now that the IAVF driver simply uses
dev_alloc_page()+free_page()with no custom recycling logics and one whole page per frame, it can easily be switched to using Page Pool API instead.
[...]
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-2@@ -691,8 +690,6 @@ int iavf_setup_tx_descriptors(struct iavf_ring *tx_ring)**/ void iavf_clean_rx_ring (struct iavf_ring *rx_ring) { -u16 i; -/* ring already cleared, nothing to do */ if (!rx_ring->rx_pages)return ;@@ -703,28 +700,17 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring) }
Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 703
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +1
-1/* Free all the Rx ring sk_buffs */ -for (i =0 ; i < rx_ring->count; i++) { +for (u32 i =0 ; i < rx_ring->count; i++) {Did we make a change to our coding style to allow declaration of variables inside of for statements? Just wondering if this is a change since the recent updates to the ISO C standard, or if this doesn't match up with what we would expect per the coding standard.
It's optional right now, nobody would object declaring it either way. Doing it inside is allowed since we switched to C11, right. Here I did that because my heart was breaking to see this little u16 alone (and yeah, u16 on the stack).
Quoted 37 lines
Quoted 37 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +4
-13struct page *page = rx_ring->rx_pages[i]; -dma_addr_t dma;if (!page)continue ; - dma =page_pool_get_dma_addr (page); -/* Invalidate cache lines that may have been written to by * device so that we avoid corrupting memory. */ -dma_sync_single_range_for_cpu (rx_ring->dev, dma, -LIBIE_SKB_HEADROOM , -LIBIE_RX_BUF_LEN , -DMA_FROM_DEVICE ); - -/* free resources associated with mapping */ -dma_unmap_page_attrs (rx_ring->dev, dma,LIBIE_RX_TRUESIZE , -DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR ); - -__free_page (page); +page_pool_dma_sync_full_for_cpu (rx_ring->pool, page); +page_pool_put_full_page (rx_ring->pool, page, false); } rx_ring->next_to_clean =0 ;@@ -739,10 +725,15 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring)**/ void iavf_free_rx_resources (struct iavf_ring *rx_ring) { +struct device *dev = rx_ring->pool->p.dev; +iavf_clean_rx_ring (rx_ring);kfree (rx_ring->rx_pages); rx_ring->rx_pages =NULL ;
Quoted 11 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 739
Quoted 6 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +3
-0+page_pool_destroy (rx_ring->pool); + rx_ring->dev = dev; +if (rx_ring->desc) {dma_free_coherent (rx_ring->dev, rx_ring->size, rx_ring->desc, rx_ring->dma);Not a fan of this switching back and forth between being a page pool pointer and a dev pointer. Seems problematic as it is easily misinterpreted. I would say that at a minimum stick to either it is
page_pool(Rx)or dev(Tx) on a ring type basis.
The problem is that page_pool has lifetime from ifup to ifdown, while its ring lives longer. So I had to do something with this, but also I didn't want to have 2 pointers at the same time since it's redundant and +8 bytes to the ring for nothing.
[...]
Quoted 4 lines
This setup works for iavf, however for i40e/ice you may run into issues since the
setup_rx_descriptorscall is also used to setup the ethtool loopback test w/o a napi struct as I recall so there may not be aq_vector.
I'll handle that. Somehow :D Thanks for noticing, I'll take a look whether I should do something right now or it can be done later when switching the actual mentioned drivers.
[...]
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4
-1@@ -240,7 +237,10 @@ struct iavf_rx_queue_stats {struct iavf_ring {struct iavf_ring *next;/* pointer to next ring in q_vector */ void *desc;/* Descriptor ring memory */ -struct device *dev;/* Used for DMA mapping */ +union { +struct page_pool *pool;/* Used for Rx page management */ +struct device *dev;/* Used for DMA mapping on Tx */ + };
Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h struct iavf_rx_queue_stats { · line 246
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +0
-0struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi;Would it make more sense to have the page pool in the
q_vectorrather than the ring? Essentially the page pool is associated per napi instance so it seems like it would make more sense to store it with the napi struct rather than potentially have multiple instances per napi.
As per Page Pool design, you should have it per ring. Plus you have rxq_info (XDP-related structure), which is also per-ring and participates in recycling in some cases. So I wouldn't complicate. I went down the chain and haven't found any place where having more than 1 PP per NAPI would break anything. If I got it correctly, Jakub's optimization discourages having 1 PP per several NAPIs (or scheduling one NAPI on different CPUs), but not the other way around. The goal was to exclude concurrent access to one PP from different threads, and here it's impossible.
Lemme know. I can always disable NAPI optimization for cases when one vector is shared by several queues -- and it's not a usual case for these NICs anyway -- but I haven't found a reason for that.
[...]
Thanks,
Olek
Re: [PATCH net-next v3 09/12] iavf: switch to Page Pool
Quoted 32 lines · Alexander Lobakin
From: Alexander H Duyck <[email protected]>
Date: Wed, 31 May 2023 09:19:06 -0700Quoted 4 lines · Alexander Lobakin
Quoted 3 lines
Now that the IAVF driver simply uses
dev_alloc_page()+free_page()with no custom recycling logics and one whole page per frame, it can easily be switched to using Page Pool API instead.[...]
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +0
-2@@ -691,8 +690,6 @@ int iavf_setup_tx_descriptors(struct iavf_ring *tx_ring)**/ void iavf_clean_rx_ring (struct iavf_ring *rx_ring) { -u16 i; -/* ring already cleared, nothing to do */ if (!rx_ring->rx_pages)return ;@@ -703,28 +700,17 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring) }Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 703
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +1
-1/* Free all the Rx ring sk_buffs */ -for (i =0 ; i < rx_ring->count; i++) { +for (u32 i =0 ; i < rx_ring->count; i++) {Did we make a change to our coding style to allow declaration of variables inside of for statements? Just wondering if this is a change since the recent updates to the ISO C standard, or if this doesn't match up with what we would expect per the coding standard.
Quoted 4 lines
It's optional right now, nobody would object declaring it either way. Doing it inside is allowed since we switched to C11, right. Here I did that because my heart was breaking to see this little u16 alone (and yeah, u16 on the stack).
Yeah, that was back when I was declaring stack variables the exact same size as the ring parameters. So u16 should match the size of rx_ring->count not that it matters. It was just a quirk I had at the time.
Quoted 49 lines
Quoted 37 lines
Quoted 37 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +4
-13struct page *page = rx_ring->rx_pages[i]; -dma_addr_t dma;if (!page)continue ; - dma =page_pool_get_dma_addr (page); -/* Invalidate cache lines that may have been written to by * device so that we avoid corrupting memory. */ -dma_sync_single_range_for_cpu (rx_ring->dev, dma, -LIBIE_SKB_HEADROOM , -LIBIE_RX_BUF_LEN , -DMA_FROM_DEVICE ); - -/* free resources associated with mapping */ -dma_unmap_page_attrs (rx_ring->dev, dma,LIBIE_RX_TRUESIZE , -DMA_FROM_DEVICE ,IAVF_RX_DMA_ATTR ); - -__free_page (page); +page_pool_dma_sync_full_for_cpu (rx_ring->pool, page); +page_pool_put_full_page (rx_ring->pool, page, false); } rx_ring->next_to_clean =0 ;@@ -739,10 +725,15 @@ void iavf_clean_rx_ring(struct iavf_ring *rx_ring)**/ void iavf_free_rx_resources (struct iavf_ring *rx_ring) { +struct device *dev = rx_ring->pool->p.dev; +iavf_clean_rx_ring (rx_ring);kfree (rx_ring->rx_pages); rx_ring->rx_pages =NULL ;Quoted 11 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c void iavf_clean_rx_ring(struct iavf_ring *rx_ring) · line 739
Quoted 6 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.c +3
-0+page_pool_destroy (rx_ring->pool); + rx_ring->dev = dev; +if (rx_ring->desc) {dma_free_coherent (rx_ring->dev, rx_ring->size, rx_ring->desc, rx_ring->dma);Not a fan of this switching back and forth between being a page pool pointer and a dev pointer. Seems problematic as it is easily misinterpreted. I would say that at a minimum stick to either it is
page_pool(Rx)or dev(Tx) on a ring type basis.
Quoted 4 lines
The problem is that
page_poolhas lifetime from ifup to ifdown, while its ring lives longer. So I had to do something with this, but also I didn't want to have 2 pointers at the same time since it's redundant and +8 bytes to the ring for nothing.
It might be better to just go with NULL rather than populating it w/ two different possible values. Then at least you know if it is an rx_ring it is a page_pool and if it is a tx_ring it is dev. You can reset to the page pool when you repopulate the rest of the ring.
Quoted 29 lines
Quoted 4 lines
This setup works for iavf, however for i40e/ice you may run into issues since the
setup_rx_descriptorscall is also used to setup the ethtool loopback test w/o a napi struct as I recall so there may not be aq_vector.I'll handle that. Somehow :D Thanks for noticing, I'll take a look whether I should do something right now or it can be done later when switching the actual mentioned drivers.
[...]
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4
-1@@ -240,7 +237,10 @@ struct iavf_rx_queue_stats {struct iavf_ring {struct iavf_ring *next;/* pointer to next ring in q_vector */ void *desc;/* Descriptor ring memory */ -struct device *dev;/* Used for DMA mapping */ +union { +struct page_pool *pool;/* Used for Rx page management */ +struct device *dev;/* Used for DMA mapping on Tx */ + };Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h struct iavf_rx_queue_stats { · line 246
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +0
-0struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi;Would it make more sense to have the page pool in the
q_vectorrather than the ring? Essentially the page pool is associated per napi instance so it seems like it would make more sense to store it with the napi struct rather than potentially have multiple instances per napi.
Quoted 9 lines
As per Page Pool design, you should have it per ring. Plus you have
rxq_info(XDP-related structure), which is also per-ring and participates in recycling in some cases. So I wouldn't complicate. I went down the chain and haven't found any place where having more than 1 PP per NAPI would break anything. If I got it correctly, Jakub's optimization discourages having 1 PP per several NAPIs (or scheduling one NAPI on different CPUs), but not the other way around. The goal was to exclude concurrent access to one PP from different threads, and here it's impossible.
The xdp_rxq can be mapped many:1 to the page pool if I am not mistaken.
The only reason why I am a fan of trying to keep the page_pool tightly associated with the napi instance is because the napi instance is what essentially is guaranteeing the page_pool is consistent as it is only accessed by that one napi instance.
Quoted 3 lines
Lemme know. I can always disable NAPI optimization for cases when one vector is shared by several queues -- and it's not a usual case for these NICs anyway -- but I haven't found a reason for that.
I suppose we should be fine if we have a many to one mapping though I suppose. As you said the issue would be if multiple NAPI were accessing the same page pool.
Alexander Lobakin
maintainerRe: [PATCH net-next v3 09/12] iavf: switch to Page Pool
From: Alexander Duyck <[email protected]>
Date: Fri, 2 Jun 2023 11:00:07 -0700
Quoted 2 lines
On Fri, Jun 2, 2023 at 9:31 AM Alexander Lobakin
<[email protected]> wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
Not a fan of this switching back and forth between being a page pool pointer and a dev pointer. Seems problematic as it is easily misinterpreted. I would say that at a minimum stick to either it is
page_pool(Rx)or dev(Tx) on a ring type basis.The problem is that
page_poolhas lifetime from ifup to ifdown, while its ring lives longer. So I had to do something with this, but also I didn't want to have 2 pointers at the same time since it's redundant and +8 bytes to the ring for nothing.
Quoted 4 lines
It might be better to just go with NULL rather than populating it w/ two different possible values. Then at least you know if it is an
rx_ringit is apage_pooland if it is atx_ringit is dev. You can reset to the page pool when you repopulate the rest of the ring.
IIRC I did that to have struct device pointer at the moment of creating page_pools. But sounds reasonable, I'll take a look.
Quoted 40 lines
Quoted 30 lines
Quoted 5 lines
This setup works for iavf, however for i40e/ice you may run into issues since the
setup_rx_descriptorscall is also used to setup the ethtool loopback test w/o a napi struct as I recall so there may not be aq_vector.I'll handle that. Somehow :D Thanks for noticing, I'll take a look whether I should do something right now or it can be done later when switching the actual mentioned drivers.
[...]
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4
-1@@ -240,7 +237,10 @@ struct iavf_rx_queue_stats {struct iavf_ring {struct iavf_ring *next;/* pointer to next ring in q_vector */ void *desc;/* Descriptor ring memory */ -struct device *dev;/* Used for DMA mapping */ +union { +struct page_pool *pool;/* Used for Rx page management */ +struct device *dev;/* Used for DMA mapping on Tx */ + };Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h struct iavf_rx_queue_stats { · line 246
Quoted 3 lines
drivers/net/ethernet/intel/iavf/iavf_txrx.h +0
-0struct net_device *netdev;/* netdev ring maps to */ union {struct iavf_tx_buffer *tx_bi;Would it make more sense to have the page pool in the
q_vectorrather than the ring? Essentially the page pool is associated per napi instance so it seems like it would make more sense to store it with the napi struct rather than potentially have multiple instances per napi.Quoted 9 lines
As per Page Pool design, you should have it per ring. Plus you have
rxq_info(XDP-related structure), which is also per-ring and participates in recycling in some cases. So I wouldn't complicate. I went down the chain and haven't found any place where having more than 1 PP per NAPI would break anything. If I got it correctly, Jakub's optimization discourages having 1 PP per several NAPIs (or scheduling one NAPI on different CPUs), but not the other way around. The goal was to exclude concurrent access to one PP from different threads, and here it's impossible.
Quoted 6 lines
The
xdp_rxqcan be mapped many:1 to the page pool if I am not mistaken.The only reason why I am a fan of trying to keep the
page_pooltightly associated with the napi instance is because the napi instance is what essentially is guaranteeing thepage_poolis consistent as it is only accessed by that one napi instance.
Here we can't have more than one NAPI instance accessing one page_pool, so I did that unconditionally. I'm a fan of what you've said, too :p
Quoted 8 lines
Quoted 4 lines
Lemme know. I can always disable NAPI optimization for cases when one vector is shared by several queues -- and it's not a usual case for these NICs anyway -- but I haven't found a reason for that.
I suppose we should be fine if we have a many to one mapping though I suppose. As you said the issue would be if multiple NAPI were accessing the same page pool.
Thanks,
Olek
Alexander Lobakin
maintainerPATCH v3 10/12 libie: add common queue stats
In reply to Alexander LobakinNext stop, per-queue private stats. They have only subtle differences from driver to driver and can easily be resolved.
Define common structures, inline helpers and Ethtool helpers to collect, update and export the statistics. 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.
The drivers will be switched to use this API later on a per-driver basis, along with conversion to PP.
--- drivers/net/ethernet/intel/libie/Makefile | 1 + drivers/net/ethernet/intel/libie/stats.c | 119 ++++++++++++++ include/linux/net/intel/libie/stats.h | 179 ++++++++++++++++++++++ 3 files changed, 299 insertions(+) create mode 100644 drivers/net/ethernet/intel/libie/stats.c create mode 100644 include/linux/net/intel/libie/stats.h
drivers/net/ethernet/intel/libie/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_LIBIE) += libie.o libie-objs += rx.o +libie-objs += stats.o
drivers/net/ethernet/intel/libie/stats.c new file +119 -0
119 lines not on this page · raw message
include/linux/net/intel/libie/stats.h new file +179 -0
179 lines not on this page · raw message
Signature · 6 lines
2.40.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Alexander Lobakin
maintainerPATCH v3 11/12 libie: add per-queue Page Pool stats
In reply to Alexander LobakinExpand the libie generic per-queue stats with the generic Page Pool stats provided by the API itself, when CONFIG_PAGE_POOL is enabled. When it's not, there'll be no such fields in the stats structure, so no space wasted.
They are also a bit special in terms of how they are obtained. One &page_pool accumulates statistics until it's destroyed obviously, which happens on ifdown. So, in order to not lose any statistics, get the stats and store in the queue container before destroying a pool. This container survives ifups/downs, so it basically stores the statistics accumulated since the very first pool was allocated on this queue. When it's needed to export the stats, first get the numbers from this container and then add the "live" numbers -- the ones that the current active pool returns. The result values will always represent the actual device-lifetime* stats.
There's a cast from &page_pool_stats to u64 * in a couple functions, but they are guarded with stats asserts to make sure it's safe to do. FWIW it saves a lot of object code.
--- drivers/net/ethernet/intel/libie/internal.h | 23 +++++++ drivers/net/ethernet/intel/libie/rx.c | 20 ++++++ drivers/net/ethernet/intel/libie/stats.c | 73 ++++++++++++++++++++- include/linux/net/intel/libie/rx.h | 4 ++ include/linux/net/intel/libie/stats.h | 39 ++++++++++- 5 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/intel/libie/internal.h
drivers/net/ethernet/intel/libie/internal.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* libie internal declarations not to be used in drivers. +* +* Copyright(c) 2023 Intel Corporation. +*/ + +#ifndef __LIBIE_INTERNAL_H +#define __LIBIE_INTERNAL_H + +struct libie_rq_stats ; +struct page_pool ; + +#ifdef CONFIG_PAGE_POOL_STATS +void libie_rq_stats_sync_pp (struct libie_rq_stats *stats, +struct page_pool *pool); +#else +static inline void libie_rq_stats_sync_pp (struct libie_rq_stats *stats, +struct page_pool *pool) +{ +} +#endif + +#endif /* __LIBIE_INTERNAL_H */
drivers/net/ethernet/intel/libie/rx.c +20 -0
@@ -3,6 +3,8 @@#include <linux/net/intel/libie/rx.h> +#include "internal.h" +/* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed * bitfield struct. */
@@ -133,6 +135,24 @@ struct page_pool *libie_rx_page_pool_create(struct napi_struct *napi, }EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_create,LIBIE ); +/** +* libie_rx_page_pool_destroy - destroy a &page_pool created by libie +* @pool: pool to destroy +* @stats: RQ stats from the ring (or %NULL to skip updating PP stats) +* +* As the stats usually has the same lifetime as the device, but PP is usually +* created/destroyed on ifup/ifdown, in order to not lose the stats accumulated +* during the last ifup, the PP stats need to be added to the driver stats +* container. Then the PP gets destroyed. +*/ +void libie_rx_page_pool_destroy (struct page_pool *pool, +struct libie_rq_stats *stats) +{ +libie_rq_stats_sync_pp (stats, pool); +page_pool_destroy (pool); +} +EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_destroy,LIBIE ); +MODULE_AUTHOR ("Intel Corporation" );MODULE_DESCRIPTION ("Intel(R) Ethernet common library" );MODULE_LICENSE ("GPL" );
drivers/net/ethernet/intel/libie/stats.c +72 -1
98 lines not on this page · raw message
include/linux/net/intel/libie/rx.h +4 -0
@@ -160,7 +160,11 @@ static inline void libie_skb_set_hash(struct sk_buff *skb, u32 hash,/* Maximum frame size minus LL overhead */ #define LIBIE_MAX_MTU (LIBIE_MAX_RX_FRM_LEN - LIBIE_RX_LL_LEN) +struct libie_rq_stats ; +struct page_pool *libie_rx_page_pool_create (struct napi_struct *napi,u32 size); +void libie_rx_page_pool_destroy (struct page_pool *pool, +struct libie_rq_stats *stats);#endif /* __LIBIE_RX_H */
include/linux/net/intel/libie/stats.h +37 -2
@@ -49,6 +49,17 @@* fragments: number of processed descriptors carrying only a fragment * alloc_page_fail: number of Rx page allocation fails * build_skb_fail: number of build_skb() fails +* pp_alloc_fast: pages taken from the cache or ring +* pp_alloc_slow: actual page allocations +* pp_alloc_slow_ho: non-order-0 page allocations +* pp_alloc_empty: number of times the pool was empty +* pp_alloc_refill: number of cache refills +* pp_alloc_waive: NUMA node mismatches during recycling +* pp_recycle_cached: direct recyclings into the cache +* pp_recycle_cache_full: number of times the cache was full +* pp_recycle_ring: recyclings into the ring +* pp_recycle_ring_full: number of times the ring was full +* pp_recycle_released_ref: pages released due to elevated refcnt */ #define DECLARE_LIBIE_RQ_NAPI_STATS (act) \
@@ -60,9 +71,29 @@ act(alloc_page_fail) \ act(build_skb_fail) +#ifdef CONFIG_PAGE_POOL_STATS +#define DECLARE_LIBIE_RQ_PP_STATS (act) \ + act(pp_alloc_fast) \ + act(pp_alloc_slow) \ + act(pp_alloc_slow_ho) \ + act(pp_alloc_empty) \ + act(pp_alloc_refill) \ + act(pp_alloc_waive) \ + act(pp_recycle_cached) \ + act(pp_recycle_cache_full) \ + act(pp_recycle_ring) \ + act(pp_recycle_ring_full) \ + act(pp_recycle_released_ref) +#else +#define DECLARE_LIBIE_RQ_PP_STATS (act) +#endif +#define DECLARE_LIBIE_RQ_STATS (act) \ DECLARE_LIBIE_RQ_NAPI_STATS(act) \ - DECLARE_LIBIE_RQ_FAIL_STATS(act) + DECLARE_LIBIE_RQ_FAIL_STATS(act) \ + DECLARE_LIBIE_RQ_PP_STATS(act) + +struct page_pool ;struct libie_rq_stats {struct u64_stats_sync syncp;
@@ -72,6 +103,9 @@ struct libie_rq_stats {#define act (s) u64_stats_t s;DECLARE_LIBIE_RQ_NAPI_STATS (act);DECLARE_LIBIE_RQ_FAIL_STATS (act); +struct_group (pp, + DECLARE_LIBIE_RQ_PP_STATS(act); + );#undef act };DECLARE_FLEX_ARRAY (u64_stats_t, raw);
@@ -110,7 +144,8 @@ libie_rq_napi_stats_add(struct libie_rq_stats *qs,u32 libie_rq_stats_get_sset_count (void );void libie_rq_stats_get_strings (u8 **data,u32 qid); -void libie_rq_stats_get_data (u64 **data,const struct libie_rq_stats *stats); +void libie_rq_stats_get_data (u64 **data,const struct libie_rq_stats *stats, +struct page_pool *pool);/* Tx per-queue stats: * packets: packets sent from this queue
Signature · 6 lines
2.40.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Alexander Lobakin
maintainerPATCH v3 12/12 iavf: switch queue stats to libie
In reply to Alexander Lobakiniavf is pretty much ready for using the generic libie stats, so drop all the custom code and just use generic definitions. The only thing is that it previously lacked the counter of Tx queue stops. It's present in the other drivers, so add it here as well.
The rest is straightforward. There were two fields in the Tx stats struct, which didn't belong there. The first one has never been used, wipe it; and move the other to the queue structure. Plus move around a couple fields in &iavf_ring to account stats structs' alignment.
--- .../net/ethernet/intel/iavf/iavf_ethtool.c | 87 ++++------------ drivers/net/ethernet/intel/iavf/iavf_main.c | 2 + drivers/net/ethernet/intel/iavf/iavf_txrx.c | 98 ++++++++++--------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 47 +++------ 4 files changed, 87 insertions(+), 147 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +20 -67
@@ -46,16 +46,6 @@ struct iavf_stats { .stat_offset = offsetof(_type, _stat) \ } -/* Helper macro for defining some statistics related to queues */ -#define IAVF_QUEUE_STAT (_name, _stat) \ - IAVF_STAT(struct iavf_ring, _name, _stat) - -/* Stats associated with a Tx or Rx ring */ -static const struct iavf_stats iavf_gstrings_queue_stats[] = { -IAVF_QUEUE_STAT ("%s-%u.packets" , stats.packets), -IAVF_QUEUE_STAT ("%s-%u.bytes" , stats.bytes), -}; -/** * iavf_add_one_ethtool_stat - copy the stat into the supplied buffer * @data: location to store the stat value
@@ -141,43 +131,6 @@ __iavf_add_ethtool_stats(u64 **data, void *pointer,#define iavf_add_ethtool_stats (data, pointer, stats) \ __iavf_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats)) -/** -* iavf_add_queue_stats - copy queue statistics into supplied buffer -* @data: ethtool stats buffer -* @ring: the ring to copy -* -* Queue statistics must be copied while protected by -* u64_stats_fetch_begin, so we can't directly use iavf_add_ethtool_stats. -* Assumes that queue stats are defined in iavf_gstrings_queue_stats. If the -* ring pointer is null, zero out the queue stat values and update the data -* pointer. Otherwise safely copy the stats from the ring into the supplied -* buffer and update the data pointer when finished. -* -* This function expects to be called while under rcu_read_lock(). -**/ -static void -iavf_add_queue_stats (u64 **data,struct iavf_ring *ring) -{ -const unsigned int size =ARRAY_SIZE (iavf_gstrings_queue_stats); -const struct iavf_stats *stats = iavf_gstrings_queue_stats; -unsigned int start; -unsigned int i; - -/* To avoid invalid statistics values, ensure that we keep retrying -* the copy until we get a consistent value according to -* u64_stats_fetch_retry. But first, make sure our ring is -* non-null before attempting to access its syncp. -*/ -do { - start = !ring ?0 :u64_stats_fetch_begin (&ring->syncp); -for (i =0 ; i < size; i++) -iavf_add_one_ethtool_stat (&(*data)[i], ring, &stats[i]); - }while (ring &&u64_stats_fetch_retry (&ring->syncp, start)); - -/* Once we successfully copy the stats in, update the data pointer */ - *data += size; -} -/** * __iavf_add_stat_strings - copy stat strings into ethtool buffer * @p: ethtool supplied buffer
@@ -237,8 +190,6 @@ static const struct iavf_stats iavf_gstrings_stats[] = {#define IAVF_STATS_LEN ARRAY_SIZE(iavf_gstrings_stats) -#define IAVF_QUEUE_STATS_LEN ARRAY_SIZE(iavf_gstrings_queue_stats) -/** * iavf_get_link_ksettings - Get Link Speed and Duplex settings * @netdev: network interface device structure
@@ -308,18 +259,22 @@ static int iavf_get_link_ksettings(struct net_device *netdev,**/ static int iavf_get_sset_count (struct net_device *netdev,int sset) { -/* Report the maximum number queues, even if not every queue is -* currently configured. Since allocation of queues is in pairs, -* use netdev->real_num_tx_queues * 2. The real_num_tx_queues is set -* at device creation and never changes. -*/ +u32 num; -if (sset ==ETH_SS_STATS ) -return IAVF_STATS_LEN + - (IAVF_QUEUE_STATS_LEN *2 * - netdev->real_num_tx_queues); -else +switch (sset) { +case ETH_SS_STATS : +/* Per-queue */ + num =libie_rq_stats_get_sset_count (); + num +=libie_sq_stats_get_sset_count (); + num *= netdev->real_num_tx_queues; + +/* Global */ + num +=IAVF_STATS_LEN ; + +return num; +default :return -EINVAL ; + } }/**
@@ -346,15 +301,15 @@ static void iavf_get_ethtool_stats(struct net_device *netdev,* it to iterate over rings' stats. */ for (i =0 ; i < adapter->num_active_queues; i++) { -struct iavf_ring *ring; +const struct iavf_ring *ring;/* Tx rings stats */ - ring = &adapter->tx_rings[i]; -iavf_add_queue_stats (&data, ring); +libie_sq_stats_get_data (&data, &adapter->tx_rings[i].sq_stats);/* Rx rings stats */ ring = &adapter->rx_rings[i]; -iavf_add_queue_stats (&data, ring); +libie_rq_stats_get_data (&data, &ring->rq_stats, + ring->rx_pages ? ring->pool :NULL ); }rcu_read_unlock (); }
@@ -376,10 +331,8 @@ static void iavf_get_stat_strings(struct net_device *netdev, u8 *data)* real_num_tx_queues for both Tx and Rx queues. */ for (i =0 ; i < netdev->real_num_tx_queues; i++) { -iavf_add_stat_strings (&data, iavf_gstrings_queue_stats, -"tx" , i); -iavf_add_stat_strings (&data, iavf_gstrings_queue_stats, -"rx" , i); +libie_sq_stats_get_strings (&data, i); +libie_rq_stats_get_strings (&data, i); } }
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -0
@@ -1581,6 +1581,7 @@ static int iavf_alloc_queues(struct iavf_adapter *adapter) tx_ring->itr_setting =IAVF_ITR_TX_DEF ;if (adapter->flags &IAVF_FLAG_WB_ON_ITR_CAPABLE ) tx_ring->flags |=IAVF_TXR_FLAGS_WB_ON_ITR ; +u64_stats_init (&tx_ring->sq_stats.syncp); rx_ring = &adapter->rx_rings[i]; rx_ring->queue_index = i;
@@ -1588,6 +1589,7 @@ static int iavf_alloc_queues(struct iavf_adapter *adapter) rx_ring->dev = &adapter->pdev->dev; rx_ring->count = adapter->rx_desc_count; rx_ring->itr_setting =IAVF_ITR_RX_DEF ; +u64_stats_init (&rx_ring->rq_stats.syncp); } adapter->num_active_queues = num_active_queues;
drivers/net/ethernet/intel/iavf/iavf_txrx.c +51 -47
274 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +14 -33
74 lines not on this page · raw message
Signature · 6 lines
2.40.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan