net: intel: start The Great Code Dedup + Page Pool for iavf
Subsystems (5)
Alexander Lobakin
maintainerv6 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 are in the commit messages; here's a 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 name that came to my mind was "libie" -- "Intel Ethernet common library". Also this sounds like "lovelie" (-> one word, no "lib I E" pls) and can be expanded as "lib Internet Explorer" :P
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?". The final destination is very ambitious: have only one unified driver for at least i40e, ice, iavf, and idpf with a struct ops for each generation. That's never gonna happen, right? But you still can at least try.
PP conversion for iavf lands within the same series as these two are tied closely. libie will support Page Pool model only, so that 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):
page_pool: make sure frag API fields don't span between cachelines
page_pool: don't use driver-set flags field directly
net: intel: introduce Intel Ethernet common library
iavf: kill "legacy-rx" for good
iavf: drop page splitting and recycling
page_pool: constify some read-only function arguments
page_pool: add DMA-sync-for-CPU inline helper
libie: add Rx buffer management (via Page Pool)
iavf: pack iavf_ring more efficiently
iavf: switch to Page Pool
libie: add common queue stats
iavf: switch queue stats to libie
MAINTAINERS | 3 +- drivers/net/ethernet/intel/Kconfig | 6 + 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 | 72 +- 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 | 235 +------ drivers/net/ethernet/intel/iavf/iavf_main.c | 42 +- .../net/ethernet/intel/iavf/iavf_prototype.h | 7 - drivers/net/ethernet/intel/iavf/iavf_txrx.c | 624 ++++-------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 174 +---- drivers/net/ethernet/intel/iavf/iavf_type.h | 90 --- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 17 +- .../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/Kconfig | 9 + drivers/net/ethernet/intel/libie/Makefile | 7 + drivers/net/ethernet/intel/libie/rx.c | 179 +++++ drivers/net/ethernet/intel/libie/stats.c | 121 ++++ include/linux/net/intel/libie/rx.h | 259 ++++++++ include/linux/net/intel/libie/stats.h | 179 +++++ include/net/page_pool/helpers.h | 34 +- include/net/page_pool/types.h | 19 +- net/core/page_pool.c | 42 +- 29 files changed, 1058 insertions(+), 2057 deletions(-) create mode 100644 drivers/net/ethernet/intel/libie/Kconfig create mode 100644 drivers/net/ethernet/intel/libie/Makefile 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 :p
From v5[0]:
* drop Page Pool DMA shortcut: will pick up Eric's more global DMA sync optimization[1] and expand it to cover both IOMMU and direct DMA a bit later (Yunsheng);
* drop per-queue Page Pool Ethtool stats: they are now exported via generic Netlink interface (Jakub);
* #01: leave a comment why exactly this alignment (Jakub, Yunsheng);
* #08: make use of page_pool_params::netdev when calculating PP params;
* #08: rename ``libie_rx_queue`` -> ``libie_buf_queue``.
From v4[2]:
* make use of Jakub's &page_pool_params split;
* #01: prevent frag fields from spanning into 2 cachelines after splitting &page_pool_params into fast and slow;
* #02-03: bring back the DMA sync shortcut, now as a per-page flag (me, Yunsheng);
* #04: let libie have its own Kconfig to stop further bloating of poor intel/Kconfig;
* #06: merge page split-reuse-recycle drop into one commit (Alex);
* #07: decouple constifying of several Page Pool function arguments into a separate commit, constify some more;
* #09: stop abusing internal PP fields in the driver code (Yunsheng);
* #09: calculate DMA sync size (::max_len) correctly: within one page, not one buffer (Yunsheng);
* #10: decouple rearranging &iavf_ring into separate commit, optimize it even more;
* #11: let the driver get back to the last descriptor to process after an skb allocation fail, don't drop it (Alex);
* #11: stop touching unrelated stuff like watchdog timeout etc. (Alex);
* fix "Return:" in the kdoc (now W=12 C=1 is clean), misc typos.
From v3[3]:
* base on the latest net-next, update bloat-o-meter and perf stats;
* split generic PP optimizations into a separate series;
* drop "optimize hotpath a bunch" commit: a lot of [controversial] changes in one place, worth own series (Alex);
* 02: pick Rev-by (Alex);
* 03: move in-place recycling removal here from the dropped patch;
* 05: new, add libie Rx buffer API separatelly from IAVF changes;
* 05-06: use new "hybrid" allocation API from[4] to reduce memory usage when a page can fit more than 1 truesize (also asked by David);
* 06: merge with "always use order-0 page" commit to reduce diffs and simplify things (Alex);
* 09: fix page_alloc_fail counter.
From v2[5]:
* 0006: fix page_pool.h include in OcteonTX2 files (Jakub, Patchwork);
* no functional changes.
From v1[6]:
* 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]
[2] https://lore.kernel.org/netdev/[email protected]
[3] https://lore.kernel.org/netdev/[email protected]
[4] https://lore.kernel.org/netdev/[email protected]
[5] https://lore.kernel.org/netdev/[email protected]
[6] https://lore.kernel.org/netdev/[email protected]
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 1/12 page_pool: make sure frag API fields don't span between cachelines
After commit 5027ec19f104 ("net: page_pool: split the page_pool_params into fast and slow") that made &page_pool contain only "hot" params at the start, cacheline boundary chops frag API fields group in the middle again.
To not bother with this each time fast params get expanded or shrunk, let's just align them to 4 * sizeof(long), the closest upper pow-2 to their actual size (2 longs + 2 ints). This ensures 16-byte alignment for the 32-bit architectures and 32-byte alignment for the 64-bit ones, excluding unnecessary false-sharing.
--- include/net/page_pool/types.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
include/net/page_pool/types.h +10 -1
@@ -130,7 +130,16 @@ struct page_pool {bool has_init_callback; -long frag_users; +/* The following block must stay within one cacheline. On 32-bit +* systems, sizeof(long) == sizeof(int), so that the block size is +* precisely ``4 * sizeof(long)``. On 64-bit systems, the actual size +* is ``2 * sizeof(long) + 2 * sizeof(int)``, i.e. 24 bytes, but the +* closest pow-2 to that is 32 bytes, which also equals to +* ``4 * sizeof(long)``, so just use that one for simplicity. +* Having it aligned to a cacheline boundary may be excessive and +* doesn't bring any good. +*/ +long frag_users__aligned(4 * sizeof(long)) ;struct page *frag_page;unsigned int frag_offset;u32 pages_state_hold_cnt;
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 2/12 page_pool: don't use driver-set flags field directly
In reply to Alexander Lobakinpage_pool::p is driver-defined params, copied directly from the structure passed to page_pool_create(). The structure isn't meant to be modified by the Page Pool core code and this even might look confusing[0][1].
In order to be able to alter some flags, let's define our own, internal fields the same way as the already existing one (::has_init_callback). They are defined as bits in the driver-set params, leave them so here as well, to not waste byte-per-bit or so. Almost 30 bits are still free for future extensions.
We could've defined only new flags here or only the ones we may need to alter, but checking some flags in one place while others in another doesn't sound convenient or intuitive. ::flags passed by the driver can now go to the "slow" PP params.
Link[0]: https://lore.kernel.org/netdev/[email protected]
Link[1]: https://lore.kernel.org/netdev/CAKgT0UfZCGnWgOH96E4GV3ZP6LLbROHM7SHE8NKwq+exX+Gk_Q@mail.gmail.com
--- include/net/page_pool/types.h | 8 +++++--- net/core/page_pool.c | 34 ++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 19 deletions(-)
include/net/page_pool/types.h +5 -3
@@ -44,7 +44,6 @@ struct pp_alloc_cache {/** * struct page_pool_params - page pool parameters -* @flags: PP_FLAG_DMA_MAP, PP_FLAG_DMA_SYNC_DEV * @order: 2^order pages on allocation * @pool_size: size of the ptr_ring * @nid: NUMA node id to allocate from pages from
@@ -54,10 +53,10 @@ struct pp_alloc_cache {* @dma_dir: DMA mapping direction * @max_len: max DMA sync memory size for PP_FLAG_DMA_SYNC_DEV * @offset: DMA sync address offset for PP_FLAG_DMA_SYNC_DEV +* @flags: PP_FLAG_DMA_MAP, PP_FLAG_DMA_SYNC_DEV */ struct page_pool_params { struct_group_tagged(page_pool_params_fast, fast, - unsigned int flags; unsigned int order;unsigned int pool_size;int nid;
@@ -68,6 +67,7 @@ struct page_pool_params {unsigned int offset; );struct_group_tagged (page_pool_params_slow, slow, + unsigned int flags; struct net_device *netdev;/* private: used by test code only */ void (*init_callback)(struct page *page,void *arg);
@@ -128,7 +128,9 @@ struct page_pool_stats {struct page_pool {struct page_pool_params_fast p; -bool has_init_callback; +bool dma_map:1 ;/* Perform DMA mapping */ +bool dma_sync:1 ;/* Perform DMA sync */ +bool has_init_callback:1 ;/* slow.init_callback is set */ /* The following block must stay within one cacheline. On 32-bit * systems, sizeof(long) == sizeof(int), so that the block size is
net/core/page_pool.c +18 -16
@@ -179,7 +179,7 @@ static int page_pool_init(struct page_pool *pool,memcpy (&pool->slow, ¶ms->slow,sizeof (pool->slow));/* Validate only known flags were used */ -if (pool->p.flags & ~(PP_FLAG_ALL )) +if (pool->slow.flags & ~(PP_FLAG_ALL ))return -EINVAL ;if (pool->p.pool_size)
@@ -193,22 +193,26 @@ static int page_pool_init(struct page_pool *pool,* DMA_BIDIRECTIONAL is for allowing page used for DMA sending, * which is the XDP_TX use-case. */ -if (pool->p.flags &PP_FLAG_DMA_MAP ) { +if (pool->slow.flags &PP_FLAG_DMA_MAP ) {if ((pool->p.dma_dir !=DMA_FROM_DEVICE ) && (pool->p.dma_dir !=DMA_BIDIRECTIONAL ))return -EINVAL ; + + pool->dma_map = true; } -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) { +if (pool->slow.flags &PP_FLAG_DMA_SYNC_DEV ) {/* In order to request DMA-sync-for-device the page * needs to be mapped */ -if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +if (!(pool->slow.flags &PP_FLAG_DMA_MAP ))return -EINVAL ;if (!pool->p.max_len)return -EINVAL ; + pool->dma_sync = true; +/* pool->p.offset has to be set according to the address * offset used by the DMA engine to start copying rx data */
@@ -234,7 +238,7 @@ static int page_pool_init(struct page_pool *pool,/* Driver calling page_pool_create() also call page_pool_destroy() */ refcount_set (&pool->user_cnt,1 ); -if (pool->p.flags &PP_FLAG_DMA_MAP ) +if (pool->dma_map)get_device (pool->p.dev);return 0 ;
@@ -244,7 +248,7 @@ static void page_pool_uninit(struct page_pool *pool) {ptr_ring_cleanup (&pool->ring,NULL ); -if (pool->p.flags &PP_FLAG_DMA_MAP ) +if (pool->dma_map)put_device (pool->p.dev);#ifdef CONFIG_PAGE_POOL_STATS
@@ -387,7 +391,7 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page)if (page_pool_set_dma_addr (page, dma)) goto unmap_failed; -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) +if (pool->dma_sync)page_pool_dma_sync_for_device (pool, page, pool->p.max_len);return true;
@@ -433,8 +437,7 @@ static struct page *__page_pool_alloc_page_order(struct page_pool *pool,if (unlikely (!page))return NULL ; -if ((pool->p.flags &PP_FLAG_DMA_MAP ) && -unlikely (!page_pool_dma_map (pool, page))) { +if (pool->dma_map &&unlikely (!page_pool_dma_map (pool, page))) {put_page (page);return NULL ; }
@@ -454,8 +457,8 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, gfp_t gfp) {const int bulk =PP_ALLOC_CACHE_REFILL ; -unsigned int pp_flags = pool->p.flags;unsigned int pp_order = pool->p.order; +bool dma_map = pool->dma_map;struct page *page;int i, nr_pages;
@@ -480,8 +483,7 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool,*/ for (i =0 ; i < nr_pages; i++) { page = pool->alloc.cache[i]; -if ((pp_flags &PP_FLAG_DMA_MAP ) && -unlikely (!page_pool_dma_map (pool, page))) { +if (dma_map &&unlikely (!page_pool_dma_map (pool, page))) {put_page (page);continue ; }
@@ -558,7 +560,7 @@ static void page_pool_return_page(struct page_pool *pool, struct page *page)dma_addr_t dma;int count; -if (!(pool->p.flags &PP_FLAG_DMA_MAP )) +if (!pool->dma_map)/* Always account for inflight pages, even if we didn't * map them */
@@ -624,7 +626,7 @@ static bool page_pool_recycle_in_cache(struct page *page, }/* If the page refcnt == 1, this will try to recycle the page. -* if PP_FLAG_DMA_SYNC_DEV is set, we'll try to sync the DMA area for +* If pool->dma_sync is set, we'll try to sync the DMA area for * the configured size min(dma_sync_size, pool->max_len). * If the page refcnt != 1, then the page will be returned to memory * subsystem.
@@ -647,7 +649,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page,if (likely (page_ref_count (page) ==1 && !page_is_pfmemalloc (page))) {/* Read barrier done in page_ref_count / READ_ONCE */ -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) +if (pool->dma_sync)page_pool_dma_sync_for_device (pool, page, dma_sync_size);
@@ -760,7 +762,7 @@ static struct page *page_pool_drain_frag(struct page_pool *pool,return NULL ;if (page_ref_count (page) ==1 && !page_is_pfmemalloc (page)) { -if (pool->p.flags &PP_FLAG_DMA_SYNC_DEV ) +if (pool->dma_sync)page_pool_dma_sync_for_device (pool, page,-1 );return page;
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 3/12 net: intel: introduce Intel Ethernet common library
In reply to Alexander LobakinNot 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 | 6 + 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 | 72 +--- 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/Kconfig | 8 + drivers/net/ethernet/intel/libie/Makefile | 6 + drivers/net/ethernet/intel/libie/rx.c | 110 ++++++ include/linux/net/intel/libie/rx.h | 128 +++++++ 20 files changed, 315 insertions(+), 1178 deletions(-) create mode 100644 drivers/net/ethernet/intel/libie/Kconfig 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
@@ -10651,7 +10651,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 +6 -0
@@ -16,6 +16,8 @@ config NET_VENDOR_INTEL if NET_VENDOR_INTEL +source "drivers/net/ethernet/intel/libie/Kconfig" + config E100 tristate "Intel(R) PRO/100+ support" depends on PCI
@@ -225,6 +227,7 @@ config I40E depends on PTP_1588_CLOCK_OPTIONAL depends on PCI select AUXILIARY_BUS + select LIBIE select NET_DEVLINK help This driver supports Intel(R) Ethernet Controller XL710 Family of
@@ -253,6 +256,8 @@ config I40E_DCB # so that CONFIG_IAVF symbol will always mirror the state of CONFIG_I40EVF config IAVF tristate + select LIBIE + config I40EVF tristate "Intel(R) Ethernet Adaptive Virtual Function support" select IAVF
@@ -283,6 +288,7 @@ config ICE depends on GNSS || GNSS = n select AUXILIARY_BUS select DIMLIB + select LIBIE select NET_DEVLINK select PLDMFW select DPLL
drivers/net/ethernet/intel/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_IAVF) += iavf/ obj-$(CONFIG_FM10K) += fm10k/ obj-$(CONFIG_ICE) += ice/ obj-$(CONFIG_IDPF) += idpf/ +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
@@ -100,6 +100,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
@@ -371,13 +371,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 +17 -55
129 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
@@ -45,6 +45,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
@@ -45,13 +45,6 @@ enum iavf_status iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 seid,enum iavf_status iavf_aq_set_rss_key (struct iavf_hw *hw,u16 seid,struct iavf_aqc_get_set_rss_key_data *key); -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_aq_send_msg_to_pf(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
@@ -36,6 +36,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/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright(c) 2023 Intel Corporation. + +config LIBIE + tristate + help + libie (Intel Ethernet library) is a common library containing + routines shared between several Intel Ethernet drivers.
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.43.0
Alexander Lobakin
maintainerPATCH v6 4/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/4 grow/shrink: 0/7 up/down: 0/-721 (-721) 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 | 141 ------------------ 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 | 27 +--- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 3 +- 6 files changed, 8 insertions(+), 259 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +1 -1
@@ -287,7 +287,7 @@ struct iavf_adapter {#define IAVF_FLAG_RESET_PENDING BIT(4)#define IAVF_FLAG_RESET_NEEDED BIT(5)#define IAVF_FLAG_WB_ON_ITR_CAPABLE BIT(6) -#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 -141
182 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -9
@@ -740,9 +740,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
@@ -759,16 +757,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 -25
@@ -82,20 +82,11 @@ enum iavf_dyn_idx_t { BIT_ULL(IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP))/* Supported Rx Buffer Sizes (a multiple of 128) */ -#define IAVF_RXBUFFER_256 256#define IAVF_RXBUFFER_1536 1536/* 128B aligned standard Ethernet frame */ #define IAVF_RXBUFFER_2048 2048#define IAVF_RXBUFFER_3072 3072/* Used for large frames w/ padding */ #define IAVF_MAX_RXBUFFER 9728/* largest size for single descriptor */ -/* NOTE: netdev_alloc_skb reserves up to 64 bytes, NET_IP_ALIGN means we -* reserve 2 more, and skb_shared_info adds an additional 384 bytes more, -* this adds up to 512 bytes of extra data meaning the smallest allocation -* we could have is 1K. -* i.e. RXBUFFER_256 --> 960 byte skb (size-1024 slab) -* i.e. RXBUFFER_512 --> 1216 byte skb (size-2048 slab) -*/ -#define IAVF_RX_HDR_SIZE IAVF_RXBUFFER_256#define IAVF_PACKET_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))#define iavf_rx_desc iavf_32byte_rx_desc
@@ -362,7 +353,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 +385,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
@@ -289,8 +289,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.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v6 04/12] iavf: kill "legacy-rx" for good
Quoted 3 lines · On Thu, 7 Dec 2023 18:20:02 +0100 Alexander Lobakin wrote:
Ever 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.
This one has a conflict on net-next :(
Signature · 1 line
pw-bot: cr
Alexander Lobakin
maintainerPATCH v6 5/12 iavf: drop page splitting and recycling
In reply to Alexander LobakinAs an intermediate step, remove all page splitting/recycling code. Just always allocate a new page and don't touch its refcount, so that it gets freed by the core stack later.
Same for the "in-place" recycling, i.e. when an unused buffer gets assigned to a first needs-refilling descriptor. In some cases, this was leading to moving up to 63 &iavf_rx_buf structures around the ring on a per-field basis -- not something wanted on hotpath.
The change allows to greatly simplify certain parts of the code:
Function: add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-744 (-744)
Although the array of &iavf_rx_buf is barely used now and could be replaced with just page pointer array, don't touch it now to not complicate replacing it with libie Rx buffer struct later on. No surprise perf loses up to 30% here, but that regression will go away once PP lands.
Note that iavf_rx_pg_*() definitions are left to reduce diffstat. They will be removed with the conversion to Page Pool.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 24 +-- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 152 +----------------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 65 -------- drivers/net/ethernet/intel/iavf/iavf_type.h | 2 - .../net/ethernet/intel/iavf/iavf_virtchnl.c | 8 +- 5 files changed, 10 insertions(+), 241 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -23
@@ -736,32 +736,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; - } }/**
drivers/net/ethernet/intel/iavf/iavf_txrx.c +8 -144
258 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +0 -65
109 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 +1 -7
@@ -288,10 +288,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;
@@ -308,9 +304,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 =IAVF_RXBUFFER_3072 ;if (CRC_OFFLOAD_ALLOWED (adapter)) vqpi->rxq.crc_disable = !!(adapter->netdev->features &NETIF_F_RXFCS );
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 6/12 page_pool: constify some read-only function arguments
In reply to Alexander LobakinThere are several functions taking pointers to data they don't modify. This includes statistics fetching, page and page_pool parameters, etc. Constify the pointers, so that call sites will be able to pass const pointers as well.
No functional changes, no visible changes in functions sizes.
--- include/net/page_pool/helpers.h | 10 +++++----- net/core/page_pool.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-)
include/net/page_pool/helpers.h +5 -5
@@ -58,7 +58,7 @@/* Deprecated driver-facing API, use netlink instead */ int page_pool_ethtool_stats_get_count (void );u8 *page_pool_ethtool_stats_get_strings (u8 *data); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats); +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats);bool page_pool_get_stats (const struct page_pool *pool,struct page_pool_stats *stats);
@@ -73,7 +73,7 @@ static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)return data; } -static inline u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +static inline u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) {return data; }
@@ -204,8 +204,8 @@ static inline void *page_pool_dev_alloc_va(struct page_pool *pool,* Get the stored dma direction. A driver might decide to store 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; }
@@ -357,7 +357,7 @@ static inline void page_pool_free_va(struct page_pool *pool, void *va,* Fetch the DMA address of the page. The page pool to which the page belongs * must had been created with PP_FLAG_DMA_MAP. */ -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;
net/core/page_pool.c +4 -4
@@ -121,9 +121,9 @@ int page_pool_ethtool_stats_get_count(void) }EXPORT_SYMBOL (page_pool_ethtool_stats_get_count); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) { -struct page_pool_stats *pool_stats = stats; +const struct page_pool_stats *pool_stats = stats; *data++ = pool_stats->alloc_stats.fast; *data++ = pool_stats->alloc_stats.slow;
@@ -360,8 +360,8 @@ static struct page *__page_pool_get_cached(struct page_pool *pool)return page; } -static void page_pool_dma_sync_for_device (struct page_pool *pool, -struct page *page, +static void page_pool_dma_sync_for_device (const struct page_pool *pool, +const struct page *page,unsigned int dma_sync_size) {dma_addr_t dma_addr =page_pool_get_dma_addr (page);
Signature · 1 line
2.43.0
Re: [Intel-wired-lan] [PATCH net-next v6 06/12] page_pool: constify some read-only function arguments
Quoted 91 lines · Alexander Lobakin
There are several functions taking pointers to data they don't modify. This includes statistics fetching, page and
page_poolparameters, etc. Constify the pointers, so that call sites will be able to pass const pointers as well.
No functional changes, no visible changes in functions sizes.Signed-off-by Alexander Lobakin <[email protected]>--- include/net/page_pool/helpers.h | 10 +++++----- net/core/page_pool.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-)include/net/page_pool/helpers.h +2
-2@@ -58,7 +58,7 @@/* Deprecated driver-facing API, use netlink instead */ int page_pool_ethtool_stats_get_count (void );u8 *page_pool_ethtool_stats_get_strings (u8 *data); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats); +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats);bool page_pool_get_stats (const struct page_pool *pool,struct page_pool_stats *stats);@@ -73,7 +73,7 @@ static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)return data; } -static inline u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +static inline u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) {return data;}
include/net/page_pool/helpers.h +0
-0@@ -204,8 +204,8 @@ static inline void *page_pool_dev_alloc_va(structpage_pool *pool, * Get the stored dma direction. A driver might decide to store thislocally
* and avoid the extra cache line frompage_poolto determine the
direction.
*/include/net/page_pool/helpers.h +0
-2-static -inline enum dma_data_direction page_pool_get_dma_dir(struct page_pool*pool)
include/net/page_pool/helpers.h +2
-0+static inline enum dma_data_direction +page_pool_get_dma_dir (const struct page_pool *pool) {return pool->p.dma_dir; }@@ -357,7 +357,7 @@ static inline void page_pool_free_va(struct page_pool *pool, void *va, * Fetch the DMA address of the page. The page pool to which the pagebelongs
* must had been created withPP_FLAG_DMA_MAP.
*/include/net/page_pool/helpers.h +1
-1-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;net/core/page_pool.c +4
-4@@ -121,9 +121,9 @@ int page_pool_ethtool_stats_get_count(void) }EXPORT_SYMBOL (page_pool_ethtool_stats_get_count); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) { -struct page_pool_stats *pool_stats = stats; +const struct page_pool_stats *pool_stats = stats; *data++ = pool_stats->alloc_stats.fast; *data++ = pool_stats->alloc_stats.slow;@@ -360,8 +360,8 @@ static struct page *__page_pool_get_cached(struct page_pool *pool)return page; } -static void page_pool_dma_sync_for_device (struct page_pool *pool, -struct page *page, +static void page_pool_dma_sync_for_device (const struct page_pool *pool, +const struct page *page,unsigned int dma_sync_size) {dma_addr_t dma_addr = page_pool_get_dma_addr(page);
Quoted 3 lines
--
2.43.0
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Re: [PATCH net-next v6 06/12] page_pool: constify some read-only function arguments
In reply to Alexander LobakinApologies for the noise,
Resending without HTML
Quoted 83 lines · Alexander Lobakin
There are several functions taking pointers to data they don't modify. This includes statistics fetching, page and
page_poolparameters, etc. Constify the pointers, so that call sites will be able to pass const pointers as well.
No functional changes, no visible changes in functions sizes.Signed-off-by Alexander Lobakin <[email protected]>--- include/net/page_pool/helpers.h | 10 +++++----- net/core/page_pool.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-)include/net/page_pool/helpers.h +5
-5@@ -58,7 +58,7 @@/* Deprecated driver-facing API, use netlink instead */ int page_pool_ethtool_stats_get_count (void );u8 *page_pool_ethtool_stats_get_strings (u8 *data); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats); +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats);bool page_pool_get_stats (const struct page_pool *pool,struct page_pool_stats *stats);@@ -73,7 +73,7 @@ static inline u8 *page_pool_ethtool_stats_get_strings(u8 *data)return data; } -static inline u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +static inline u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) {return data; }@@ -204,8 +204,8 @@ static inline void *page_pool_dev_alloc_va(struct page_pool *pool,* Get the stored dma direction. A driver might decide to store 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; }@@ -357,7 +357,7 @@ static inline void page_pool_free_va(struct page_pool *pool, void *va,* Fetch the DMA address of the page. The page pool to which the page belongs * must had been created with PP_FLAG_DMA_MAP. */ -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;net/core/page_pool.c +4
-5@@ -121,9 +121,9 @@ int page_pool_ethtool_stats_get_count(void) }EXPORT_SYMBOL (page_pool_ethtool_stats_get_count); -u64 *page_pool_ethtool_stats_get (u64 *data,void *stats) +u64 *page_pool_ethtool_stats_get (u64 *data,const void *stats) { -struct page_pool_stats *pool_stats = stats; +const struct page_pool_stats *pool_stats = stats; *data++ = pool_stats->alloc_stats.fast; *data++ = pool_stats->alloc_stats.slow;@@ -360,8 +360,8 @@ static struct page *__page_pool_get_cached(struct page_pool *pool)return page; } -static void page_pool_dma_sync_for_device (struct page_pool *pool, -struct page *page, +static void page_pool_dma_sync_for_device (const struct page_pool *pool, +const struct page *page,unsigned int dma_sync_size) {dma_addr_t dma_addr =page_pool_get_dma_addr (page); --
Quoted 2 lines
2.43.0
Alexander Lobakin
maintainerPATCH v6 7/12 page_pool: add DMA-sync-for-CPU inline helper
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 simple helper which performs DMA synchronization for the size passed from the driver. It can be used even when the pool doesn't manage DMA-syncs-for-device, just make sure the page has a correct DMA address set via page_pool_set_dma_addr().
--- include/net/page_pool/helpers.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
include/net/page_pool/helpers.h +24 -0
@@ -52,6 +52,8 @@#ifndef _NET_PAGE_POOL_HELPERS_H#define _NET_PAGE_POOL_HELPERS_H +#include <linux/dma-mapping.h> +#include <net/page_pool/types.h> #ifdef CONFIG_PAGE_POOL_STATS
@@ -382,6 +384,28 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)return false; } +/** +* page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW +* @pool: &page_pool the @page belongs to +* @page: page to sync +* @offset: offset from page start to "hard" start if using PP frags +* @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. +*/ +static inline void page_pool_dma_sync_for_cpu (const struct page_pool *pool, +const struct page *page, +u32 offset,u32 dma_sync_size) +{ +dma_sync_single_range_for_cpu (pool->p.dev, +page_pool_get_dma_addr (page), + offset + pool->p.offset, dma_sync_size, +page_pool_get_dma_dir (pool)); +} +static inline bool page_pool_put (struct page_pool *pool) {return refcount_dec_and_test (&pool->user_cnt);
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 8/12 libie: add Rx buffer management (via Page Pool)
In reply to Alexander LobakinAdd a couple intuitive helpers to hide Rx buffer implementation details in the library and not multiplicate it between drivers. The settings are optimized for Intel hardware, but nothing really HW-specific here. Use the new page_pool_dev_alloc() to dynamically switch between split-page and full-page modes depending on MTU, page size, required headroom etc. For example, on x86_64 with the default driver settings each page is shared between 2 buffers. Turning on XDP (not in this series) -> increasing headroom requirement pushes truesize out of 2048 boundary, leading to that each buffer starts getting a full page. The "ceiling" limit is %PAGE_SIZE, as only order-0 pages are used to avoid compound overhead. For the above architecture, this means maximum linear frame size of 3712 w/o XDP.
Not that &libie_buf_queue is not a complete queue/ring structure for now, rather a shim, but eventually the libie-enabled drivers will move to it, with iavf being the first one.
--- drivers/net/ethernet/intel/libie/Kconfig | 1 + drivers/net/ethernet/intel/libie/rx.c | 69 ++++++++++++ include/linux/net/intel/libie/rx.h | 133 ++++++++++++++++++++++- 3 files changed, 202 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/libie/Kconfig +1 -0
@@ -3,6 +3,7 @@ config LIBIE tristate + select PAGE_POOL help libie (Intel Ethernet library) is a common library containing routines shared between several Intel Ethernet drivers.
drivers/net/ethernet/intel/libie/rx.c +69 -0
75 lines not on this page · raw message
include/linux/net/intel/libie/rx.h +132 -1
139 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH net-next v6 08/12] libie: add Rx buffer management (via Page Pool)
On 2023/12/8 1:20, Alexander Lobakin wrote:
...
Quoted 6 lines
drivers/net/ethernet/intel/libie/rx.c +6
-0+ +/** +* libie_rx_page_pool_create - create a PP with the default libie settings +* @bq: buffer queue struct to fill +* @napi: &napi_struct covering this PP (no usage outside its poll loops) +*
drivers/net/ethernet/intel/libie/rx.c line 41
Quoted 10 lines
drivers/net/ethernet/intel/libie/rx.c +10
-0+* Return: 0 on success, -errno on failure. +*/ +int libie_rx_page_pool_create (struct libie_buf_queue *bq, +struct napi_struct *napi) +{ +struct page_pool_params pp = { + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .order =LIBIE_RX_PAGE_ORDER , + .pool_size = bq->count, + .nid =NUMA_NO_NODE ,
Is there a reason the NUMA_NO_NODE is used here instead of dev_to_node(napi->dev->dev.parent)?
Quoted 22 lines
drivers/net/ethernet/intel/libie/rx.c +22
-0+ .dev = napi->dev->dev.parent, + .netdev = napi->dev, + .napi = napi, + .dma_dir = DMA_FROM_DEVICE, + .offset = LIBIE_SKB_HEADROOM, + }; + +/* HW-writeable / syncable length per one page */ + pp.max_len =LIBIE_RX_BUF_LEN (pp.offset); + +/* HW-writeable length per buffer */ + bq->rx_buf_len =libie_rx_hw_len (&pp); +/* Buffer size to allocate */ + bq->truesize =roundup_pow_of_two (SKB_HEAD_ALIGN (pp.offset + + bq->rx_buf_len)); + + bq->pp =page_pool_create (&pp); + +return PTR_ERR_OR_ZERO (bq->pp); +} +EXPORT_SYMBOL_NS_GPL (libie_rx_page_pool_create,LIBIE ); +
...
Quoted 16 lines
include/linux/net/intel/libie/rx.h +16
-0+/** +* libie_rx_sync_for_cpu - synchronize or recycle buffer post DMA +* @buf: buffer to process +* @len: frame length from the descriptor +* +* Process the buffer after it's written by HW. The regular path is to +* synchronize DMA for CPU, but in case of no data it will be immediately +* recycled back to its PP. +* +* Return: true when there's data to process, false otherwise. +*/ +static inline bool libie_rx_sync_for_cpu (const struct libie_rx_buffer *buf, +u32 len) +{ +struct page *page = buf->page; +
include/linux/net/intel/libie/rx.h line 135
Quoted 10 lines
include/linux/net/intel/libie/rx.h +10
-0+/* Very rare, but possible case. The most common reason: +* the last fragment contained FCS only, which was then +* stripped by the HW. +*/ +if (unlikely (!len)) { +page_pool_recycle_direct (page->pp, page); +return false; + } + +page_pool_dma_sync_for_cpu (page->pp, page, buf->offset, len);
Is there a reason why page_pool_dma_sync_for_cpu() is still used when page_pool_create() is called with PP_FLAG_DMA_SYNC_DEV flag? Isn't syncing already handled in page_pool core when when PP_FLAG_DMA_SYNC_DEV flag is set?
Quoted 7 lines
include/linux/net/intel/libie/rx.h +3
-0+ +return true; +}/* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed * bitfield struct.
Re: [PATCH net-next v6 08/12] libie: add Rx buffer management (via Page Pool)
Quoted 7 lines · Yunsheng Lin
Review
Quoted 2 lines
(quoted diff) +2
-0+ + page_pool_dma_sync_for_cpu(page->pp, page, buf->offset, len);Is there a reason why
page_pool_dma_sync_for_cpu()is still used whenpage_pool_create()is called withPP_FLAG_DMA_SYNC_DEVflag? Isn't syncing already handled inpage_poolcore when whenPP_FLAG_DMA_SYNC_DEVflag is set?
Ah, it is a sync_for_cpu.
Ignore this one.
Alexander Lobakin
maintainerRe: [PATCH net-next v6 08/12] libie: add Rx buffer management (via Page Pool)
In reply to Yunsheng LinFrom: Yunsheng Lin <[email protected]>
Date: Fri, 8 Dec 2023 17:28:21 +0800
Quoted 14 lines · Alexander Lobakin
...
Quoted 11 lines
drivers/net/ethernet/intel/libie/rx.c +11
-0+ +/** +* libie_rx_page_pool_create - create a PP with the default libie settings +* @bq: buffer queue struct to fill +* @napi: &napi_struct covering this PP (no usage outside its poll loops) +* +* Return: 0 on success, -errno on failure. +*/ +int libie_rx_page_pool_create (struct libie_buf_queue *bq, +struct napi_struct *napi) +{
Quoted 8 lines
drivers/net/ethernet/intel/libie/rx.c line 41
Quoted 5 lines
drivers/net/ethernet/intel/libie/rx.c +5
-0+struct page_pool_params pp = { + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .order =LIBIE_RX_PAGE_ORDER , + .pool_size = bq->count, + .nid =NUMA_NO_NODE ,Is there a reason the
NUMA_NO_NODEis used here instead ofdev_to_node(napi->dev->dev.parent)?
NUMA_NO_NODE creates a "dynamic" page_pool and makes sure the pages are local to the CPU where PP allocation functions are called. Setting ::nid to a "static" value pins the PP to a particular node.
But the main reason is that Rx queues can be distributed across several nodes and in that case NUMA_NO_NODE will make sure each page_pool is local to the queue it's running on. dev_to_node() will return the same value, thus forcing some PPs to allocate remote pages.
Ideally, I'd like to pass a CPU ID this queue will be run on and use cpu_to_node(), but currently there's no NUMA-aware allocations in the Intel drivers and Rx queues don't get the corresponding CPU ID when configuring. I may revisit this later, but for now NUMA_NO_NODE is the most optimal solution here.
[...]
Thanks,
Olek
Jakub Kicinski
maintainerRe: [PATCH net-next v6 08/12] libie: add Rx buffer management (via Page Pool)
Quoted 5 lines · On Mon, 11 Dec 2023 11:16:20 +0100 Alexander Lobakin wrote:
Ideally, I'd like to pass a CPU ID this queue will be run on and use
cpu_to_node(), but currently there's no NUMA-aware allocations in the Intel drivers and Rx queues don't get the corresponding CPU ID when configuring. I may revisit this later, but for nowNUMA_NO_NODEis the most optimal solution here.
Hm, I've been wondering about persistent IRQ mappings. Drivers resetting IRQ mapping on reconfiguration is a major PITA in production clusters. You change the RSS hash and some NICs suddenly forget affinitization 🤯️
The connection with memory allocations changes the math on that a bit.
The question is really whether we add CPU <> NAPI config as a netdev Netlink API or build around the generic IRQ affinity API. The latter is definitely better from "don't duplicate uAPI" perspective. But we need to reset the queues and reallocate their state when the mapping is changed. And shutting down queues on
echo $cpu > /../smp_affinity_list
seems moderately insane. Perhaps some middle-ground exists.
Anyway, if you do find cycles to tackle this - pls try to do it generically not just for Intel? :)
Alexander Lobakin
maintainerRe: [Intel-wired-lan] [PATCH net-next v6 08/12] libie: add Rx buffer management (via Page Pool)
From: Jakub Kicinski <[email protected]>
Date: Mon, 11 Dec 2023 11:23:32 -0800
Quoted 20 lines · On Mon, 11 Dec 2023 11:16:20 +0100 Alexander Lobakin wrote:
Quoted 5 lines
Ideally, I'd like to pass a CPU ID this queue will be run on and use
cpu_to_node(), but currently there's no NUMA-aware allocations in the Intel drivers and Rx queues don't get the corresponding CPU ID when configuring. I may revisit this later, but for nowNUMA_NO_NODEis the most optimal solution here.Hm, I've been wondering about persistent IRQ mappings. Drivers resetting IRQ mapping on reconfiguration is a major PITA in production clusters. You change the RSS hash and some NICs suddenly forget affinitization 🤯️
The connection with memory allocations changes the math on that a bit.
The question is really whether we add CPU <> NAPI config as a netdev Netlink API or build around the generic IRQ affinity API. The latter is definitely better from "don't duplicate uAPI" perspective. But we need to reset the queues and reallocate their state when the mapping is changed. And shutting down queues on
Quoted 6 lines
echo $cpu > /../smp_affinity_list
seems moderately insane. Perhaps some middle-ground exists.
Anyway, if you do find cycles to tackle this - pls try to do it generically not just for Intel? :)
Sounds good, adding to my fathomless backlog :>
Thanks,
Olek
Alexander Lobakin
maintainerPATCH v6 9/12 iavf: pack iavf_ring more efficiently
In reply to Alexander LobakinBefore replacing the Rx buffer management with libie, clean up &iavf_ring a bit.
There are several fields not used anywhere in the code -- simply remove them. Move ::tail up to remove a hole. Replace ::arm_wb boolean with 1-bit flag in ::flags to free 1 more byte. Finally, move ::prev_pkt_ctr out of &iavf_tx_queue_stats -- it doesn't belong there (used for Tx stall detection). Place it next to the stats on the ring itself to fill the 4-byte slot.
The result: no holes and all the hot fields fit into the first 64-byte cacheline.
--- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 12 +++++------ drivers/net/ethernet/intel/iavf/iavf_txrx.h | 22 +++------------------ 2 files changed, 9 insertions(+), 25 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_txrx.c +6 -6
@@ -184,7 +184,7 @@ void iavf_detect_recover_hung(struct iavf_vsi *vsi)* pending work. */ packets = tx_ring->stats.packets &INT_MAX ; -if (tx_ring->tx_stats.prev_pkt_ctr == packets) { +if (tx_ring->prev_pkt_ctr == packets) {iavf_force_wb (vsi, tx_ring->q_vector);continue ; }
@@ -193,7 +193,7 @@ void iavf_detect_recover_hung(struct iavf_vsi *vsi)* to iavf_get_tx_pending() */ smp_rmb (); - tx_ring->tx_stats.prev_pkt_ctr = + tx_ring->prev_pkt_ctr =iavf_get_tx_pending (tx_ring, true) ? packets :-1 ; } }
@@ -319,7 +319,7 @@ static bool iavf_clean_tx_irq(struct iavf_vsi *vsi, ((j /WB_STRIDE ) ==0 ) && (j >0 ) && !test_bit (__IAVF_VSI_DOWN, vsi->state) && (IAVF_DESC_UNUSED(tx_ring) != tx_ring->count)) - tx_ring->arm_wb = true; + tx_ring->flags |= IAVF_TXR_FLAGS_ARM_WB; }/* notify netdev of completed buffers */
@@ -674,7 +674,7 @@ int iavf_setup_tx_descriptors(struct iavf_ring *tx_ring) tx_ring->next_to_use =0 ; tx_ring->next_to_clean =0 ; - tx_ring->tx_stats.prev_pkt_ctr =-1 ; + tx_ring->prev_pkt_ctr =-1 ;return 0 ; err:
@@ -1494,8 +1494,8 @@ int iavf_napi_poll(struct napi_struct *napi, int budget) clean_complete = false;continue ; } - arm_wb |= ring->arm_wb; - ring->arm_wb = false; + arm_wb |= !!(ring->flags &IAVF_TXR_FLAGS_ARM_WB ); + ring->flags &= ~IAVF_TXR_FLAGS_ARM_WB ; }/* Handle case where we are called by netpoll with a budget of 0 */
drivers/net/ethernet/intel/iavf/iavf_txrx.h +3 -19
@@ -228,7 +228,6 @@ struct iavf_tx_queue_stats {u64 tx_done_old;u64 tx_linearize;u64 tx_force_wb; -int prev_pkt_ctr;u64 tx_lost_interrupt; };
@@ -238,12 +237,6 @@ struct iavf_rx_queue_stats {u64 alloc_buff_failed; }; -enum iavf_ring_state_t { - __IAVF_TX_FDIR_INIT_DONE, - __IAVF_TX_XPS_INIT_DONE, - __IAVF_RING_STATE_NBITS/* must be last */ -}; -/* some useful defines for virtchannel interface, which * is the only remaining user of header split */
@@ -265,10 +258,8 @@ struct iavf_ring {struct iavf_tx_buffer *tx_bi;struct iavf_rx_buffer *rx_bi; }; -DECLARE_BITMAP (state, __IAVF_RING_STATE_NBITS); -u16 queue_index;/* Queue number of ring */ -u8 dcb_tc;/* Traffic class of ring */ u8 __iomem *tail; +u16 queue_index;/* Queue number of ring */ /* high bit set means dynamic, use accessors routines to read/write. * hardware only supports 2us resolution for the ITR registers.
@@ -278,22 +269,14 @@ struct iavf_ring {u16 itr_setting;u16 count;/* Number of descriptors */ -u16 reg_idx;/* HW register index of the ring */ /* used in interrupt processing */ u16 next_to_use;u16 next_to_clean; -u8 atr_sample_rate; -u8 atr_count; - -bool ring_active;/* is ring online or not */ -bool arm_wb;/* do something to arm write back */ -u8 packet_stride; -u16 flags;#define IAVF_TXR_FLAGS_WB_ON_ITR BIT(0) -/* BIT(1) is free, was IAVF_RXR_FLAGS_BUILD_SKB_ENABLED */ +#define IAVF_TXR_FLAGS_ARM_WB BIT(1)/* BIT(2) is free */ #define IAVF_TXRX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(3)#define IAVF_TXR_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(4)
@@ -307,6 +290,7 @@ struct iavf_ring {struct iavf_rx_queue_stats rx_stats; }; +int prev_pkt_ctr;/* For Tx stall detection */ unsigned int size;/* length of descriptor ring in bytes */ dma_addr_t dma;/* physical address of ring */
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 10/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, it can easily be switched to using Page Pool / libie API instead.
This allows to removing the whole dancing around headroom, HW buffer size, and page order. All DMA-for-device is now done in the PP core, for-CPU -- in the libie helper.
Use skb_mark_for_recycle() to bring back the recycling and restore the performance. Speaking of performance: on par with the baseline and faster with the PP optimization series applied. But the memory usage for 1500b MTU is now almost 2x lower (x86_64) thanks to allocating a page every second descriptor.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 7 +- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 246 ++++++------------ drivers/net/ethernet/intel/iavf/iavf_txrx.h | 34 +-- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 10 +- 4 files changed, 92 insertions(+), 205 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +4 -3
@@ -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" /* All iavf tracepoints are defined by the include below, which must
@@ -1605,7 +1607,6 @@ static int iavf_alloc_queues(struct iavf_adapter *adapter) rx_ring = &adapter->rx_rings[i]; rx_ring->queue_index = i; rx_ring->netdev = adapter->netdev; - rx_ring->dev = &adapter->pdev->dev; rx_ring->count = adapter->rx_desc_count; rx_ring->itr_setting =IAVF_ITR_RX_DEF ; }
@@ -2637,9 +2638,9 @@ static void iavf_init_config_adapter(struct iavf_adapter *adapter)iavf_set_ethtool_ops (netdev); netdev->watchdog_timeo =5 *HZ ; -/* MTU range: 68 - 9710 */ +/* MTU range: 68 - 16356 */ 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 +73 -173
406 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +9 -25
@@ -81,18 +81,8 @@ enum iavf_dyn_idx_t { BIT_ULL(IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \ BIT_ULL(IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP)) -/* Supported Rx Buffer Sizes (a multiple of 128) */ -#define IAVF_RXBUFFER_3072 3072/* Used for large frames w/ padding */ -#define IAVF_MAX_RXBUFFER 9728/* largest size for single descriptor */ - -#define IAVF_PACKET_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))#define iavf_rx_desc iavf_32byte_rx_desc -#define IAVF_RX_DMA_ATTR \ - (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) - -#define IAVF_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) -/** * iavf_test_staterr - tests bits in Rx descriptor status and error fields * @rx_desc: pointer to receive descriptor (in le64 format)
@@ -211,12 +201,6 @@ struct iavf_tx_buffer {u32 tx_flags; }; -struct iavf_rx_buffer { -dma_addr_t dma; -struct page *page; -__u32 page_offset; -}; -struct iavf_queue_stats {u64 packets;u64 bytes;
@@ -252,13 +236,18 @@ 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 *pp;/* Used on Rx for buffer management */ +struct device *dev;/* Used on Tx for DMA mapping */ + };struct net_device *netdev;/* netdev ring maps to */ union { +struct libie_rx_buffer *rx_bi;struct iavf_tx_buffer *tx_bi; -struct iavf_rx_buffer *rx_bi; };u8 __iomem *tail; +u32 truesize; +u16 queue_index;/* Queue number of ring */ /* high bit set means dynamic, use accessors routines to read/write.
@@ -306,6 +295,8 @@ struct iavf_ring {* iavf_clean_rx_ring_irq() is called * for this ring. */ + +u32 rx_buf_len; }____cacheline_internodealigned_in_smp ;#define IAVF_ITR_ADAPTIVE_MIN_INC 0x0002
@@ -329,13 +320,6 @@ struct iavf_ring_container {#define iavf_for_each_ring (pos, head) \ for (pos = (head).ring; pos != NULL; pos = pos->next) -static inline unsigned int iavf_rx_pg_order (struct iavf_ring *ring) -{ -return 0 ; -} - -#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);netdev_tx_t iavf_xmit_frame (struct sk_buff *skb,struct net_device *netdev);int iavf_setup_tx_descriptors (struct iavf_ring *tx_ring);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +6 -4
@@ -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"
@@ -268,13 +270,13 @@ 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;int pairs = adapter->num_active_queues;struct virtchnl_queue_pair_info *vqpi; +u32 i, max_frame;size_t len; -if (max_frame >IAVF_MAX_RXBUFFER || !max_frame) - max_frame =IAVF_MAX_RXBUFFER ; + max_frame =LIBIE_MAX_RX_FRM_LEN (adapter->rx_rings->pp->p.offset); + max_frame =min_not_zero (adapter->vf_res->max_mtu, max_frame);if (adapter->current_op !=VIRTCHNL_OP_UNKNOWN ) {/* bail because we already have a command pending */
@@ -304,7 +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 =IAVF_RXBUFFER_3072 ; + vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len;if (CRC_OFFLOAD_ALLOWED (adapter)) vqpi->rxq.crc_disable = !!(adapter->netdev->features &NETIF_F_RXFCS );
Signature · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 11/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 | 121 +++++++++++++++ include/linux/net/intel/libie/stats.h | 179 ++++++++++++++++++++++ 3 files changed, 301 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 +121 -0
121 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 · 1 line
2.43.0
Alexander Lobakin
maintainerPATCH v6 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. Note that it makes the ring structure 1 CL bigger, but no layout changes since the stats structures are 32-byte aligned.
--- .../net/ethernet/intel/iavf/iavf_ethtool.c | 94 +++++-------------- drivers/net/ethernet/intel/iavf/iavf_main.c | 2 + drivers/net/ethernet/intel/iavf/iavf_txrx.c | 84 +++++++++-------- drivers/net/ethernet/intel/iavf/iavf_txrx.h | 28 +----- 4 files changed, 72 insertions(+), 136 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +22 -72
@@ -2,9 +2,10 @@/* Copyright(c) 2013 - 2018 Intel Corporation. */ /* ethtool support for iavf */ -#include "iavf.h" -#include <linux/uaccess.h> +#include <linux/net/intel/libie/rx.h> + +#include "iavf.h" /* ethtool statistics helpers */
@@ -46,16 +47,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 +132,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 +191,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 +260,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 +302,11 @@ 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; +/* Rx rings stats */ +libie_rq_stats_get_data (&data, &adapter->rx_rings[i].rq_stats);/* Tx rings stats */ - ring = &adapter->tx_rings[i]; -iavf_add_queue_stats (&data, ring); - -/* Rx rings stats */ - ring = &adapter->rx_rings[i]; -iavf_add_queue_stats (&data, ring); +libie_sq_stats_get_data (&data, &adapter->tx_rings[i].sq_stats); }rcu_read_unlock (); }
@@ -376,10 +328,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_rq_stats_get_strings (&data, i); +libie_sq_stats_get_strings (&data, i); } }
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -0
@@ -1603,12 +1603,14 @@ 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; rx_ring->netdev = adapter->netdev; 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 +44 -40
231 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_txrx.h +4 -24
@@ -4,6 +4,8 @@#ifndef _IAVF_TXRX_H_#define _IAVF_TXRX_H_ +#include <linux/net/intel/libie/stats.h> +/* Interrupt Throttling and Rate Limiting Goodies */ #define IAVF_DEFAULT_IRQ_WORK 256
@@ -201,26 +203,6 @@ struct iavf_tx_buffer {u32 tx_flags; }; -struct iavf_queue_stats { -u64 packets; -u64 bytes; -}; - -struct iavf_tx_queue_stats { -u64 restart_queue; -u64 tx_busy; -u64 tx_done_old; -u64 tx_linearize; -u64 tx_force_wb; -u64 tx_lost_interrupt; -}; - -struct iavf_rx_queue_stats { -u64 non_eop_descs; -u64 alloc_page_failed; -u64 alloc_buff_failed; -}; -/* some useful defines for virtchannel interface, which * is the only remaining user of header split */
@@ -272,11 +254,9 @@ struct iavf_ring {#define IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2 BIT(5)/* stats structs */ -struct iavf_queue_stats stats; -struct u64_stats_sync syncp;union { -struct iavf_tx_queue_stats tx_stats; -struct iavf_rx_queue_stats rx_stats; +struct libie_rq_stats rq_stats; +struct libie_sq_stats sq_stats; };int prev_pkt_ctr;/* For Tx stall detection */
Signature · 1 line
2.43.0