Skip to contentSkip to conversation

Introduce mempool object new debug capabilities

RFC PATCH In review Shani Peretz 7 participants 106 messages Jun 16, 2025 – Oct 24, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Introduce mempool object new debug capabilities

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects flow.

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Shani Peretz (5):
mempool: record mempool objects operations history
drivers: add mempool history compilation flag net/mlx5: mark an operation in mempool object's history app/testpmd: add testpmd command to dump mempool history
usertool: add a script to parse mempool history dump

 app/test-pmd/cmdline.c                        |  59 +++++++-
 config/meson.build                            |   1 +
 drivers/meson.build                           |   7 +
 drivers/net/af_packet/meson.build             |   1 +
 drivers/net/af_xdp/meson.build                |   1 +
 drivers/net/ark/meson.build                   |   2 +
 drivers/net/atlantic/meson.build              |   2 +
 drivers/net/avp/meson.build                   |   2 +
 drivers/net/axgbe/meson.build                 |   2 +
 drivers/net/bnx2x/meson.build                 |   1 +
 drivers/net/bnxt/meson.build                  |   2 +
 drivers/net/bonding/meson.build               |   1 +
 drivers/net/cnxk/meson.build                  |   1 +
 drivers/net/cxgbe/meson.build                 |   2 +
 drivers/net/dpaa/meson.build                  |   2 +
 drivers/net/dpaa2/meson.build                 |   2 +
 drivers/net/ena/meson.build                   |   2 +
 drivers/net/enetc/meson.build                 |   2 +
 drivers/net/enetfec/meson.build               |   2 +
 drivers/net/enic/meson.build                  |   2 +
 drivers/net/failsafe/meson.build              |   1 +
 drivers/net/gve/meson.build                   |   2 +
 drivers/net/hinic/meson.build                 |   2 +
 drivers/net/hns3/meson.build                  |   1 +
 drivers/net/intel/cpfl/meson.build            |   2 +
 drivers/net/intel/e1000/meson.build           |   2 +
 drivers/net/intel/fm10k/meson.build           |   2 +
 drivers/net/intel/i40e/meson.build            |   2 +
 drivers/net/intel/iavf/meson.build            |   2 +
 drivers/net/intel/ice/meson.build             |   1 +
 drivers/net/intel/idpf/meson.build            |   2 +
 drivers/net/intel/ixgbe/meson.build           |   2 +
 drivers/net/ionic/meson.build                 |   2 +
 drivers/net/mana/meson.build                  |   2 +
 drivers/net/memif/meson.build                 |   1 +
 drivers/net/mlx4/meson.build                  |   2 +
 drivers/net/mlx5/meson.build                  |   1 +
 drivers/net/mlx5/mlx5_rx.c                    |   9 ++
 drivers/net/mlx5/mlx5_rx.h                    |   2 +
 drivers/net/mlx5/mlx5_rxq.c                   |   9 +-
 drivers/net/mlx5/mlx5_rxtx_vec.c              |   6 +
 drivers/net/mlx5/mlx5_tx.h                    |   7 +
 drivers/net/mlx5/mlx5_txq.c                   |   1 +
 drivers/net/mvneta/meson.build                |   2 +
 drivers/net/mvpp2/meson.build                 |   2 +
 drivers/net/netvsc/meson.build                |   2 +
 drivers/net/nfb/meson.build                   |   2 +
 drivers/net/nfp/meson.build                   |   2 +
 drivers/net/ngbe/meson.build                  |   2 +
 drivers/net/ntnic/meson.build                 |   4 +
 drivers/net/null/meson.build                  |   1 +
 drivers/net/octeon_ep/meson.build             |   2 +
 drivers/net/octeontx/meson.build              |   2 +
 drivers/net/pcap/meson.build                  |   1 +
 drivers/net/pfe/meson.build                   |   2 +
 drivers/net/qede/meson.build                  |   2 +
 drivers/net/r8169/meson.build                 |   4 +-
 drivers/net/ring/meson.build                  |   1 +
 drivers/net/sfc/meson.build                   |   2 +
 drivers/net/softnic/meson.build               |   2 +
 drivers/net/tap/meson.build                   |   1 +
 drivers/net/thunderx/meson.build              |   2 +
 drivers/net/txgbe/meson.build                 |   2 +
 drivers/net/vdev_netvsc/meson.build           |   2 +
 drivers/net/vhost/meson.build                 |   2 +
 drivers/net/virtio/meson.build                |   2 +
 drivers/net/vmxnet3/meson.build               |   2 +
 drivers/net/xsc/meson.build                   |   2 +
 drivers/net/zxdh/meson.build                  |   4 +
 lib/ethdev/rte_ethdev.h                       |  14 ++
 lib/mempool/rte_mempool.c                     | 111 +++++++++++++++
 lib/mempool/rte_mempool.h                     | 106 ++++++++++++++
 meson_options.txt                             |   2 +
 .../dpdk-mempool_object_history_parser.py     | 129 ++++++++++++++++++
 74 files changed, 571 insertions(+), 4 deletions(-)
 create mode 100755 usertools/dpdk-mempool_object_history_parser.py
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH 1/5 mempool: record mempool objects operations history

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects flow.

added a bitmap to the mempool object header that records the most recent operations.
Each operation is represented by a 4-bit value, and for each mempool object the history field stores 16 steps.

---
 lib/ethdev/rte_ethdev.h   |  14 +++++
 lib/mempool/rte_mempool.c | 111 ++++++++++++++++++++++++++++++++++++++
 lib/mempool/rte_mempool.h | 106 ++++++++++++++++++++++++++++++++++++
 3 files changed, 231 insertions(+)
lib/ethdev/rte_ethdev.h +14 -0
index f9fb6ae549..77d15f1bcb 100644
@@ -167,6 +167,7 @@
 #include <rte_common.h>
 #include <rte_config.h>
 #include <rte_power_intrinsics.h>
+#include <rte_mempool.h>
 
 #include "rte_ethdev_trace_fp.h"
 #include "rte_dev_info.h"
@@ -6334,6 +6335,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mempool_history_bulk((void **)rx_pkts, nb_rx, RTE_MEMPOOL_APP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6692,8 +6695,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+#if RTE_MEMPOOL_DEBUG_OBJECTS_HISTORY
+	uint16_t requested_pkts = nb_pkts;
+	rte_mempool_history_bulk((void **)tx_pkts, nb_pkts, RTE_MEMPOOL_PMD_TX);
+#endif
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MEMPOOL_DEBUG_OBJECTS_HISTORY
+	if (requested_pkts > nb_pkts)
+		rte_mempool_history_bulk((void **)tx_pkts + nb_pkts,
+				    requested_pkts - nb_pkts, RTE_MEMPOOL_BUSY_TX);
+#endif
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
lib/mempool/rte_mempool.c +111 -0

120 lines not on this page · raw message

lib/mempool/rte_mempool.h +106 -0

142 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

RFC PATCH 2/5 drivers: add mempool history compilation flag

In reply to Shani Peretz

This commit adds a new compilation flag to enable
mempool history recording in DPDK drivers.

- Add support check for mempool history feature in each driver's meson
- Skip building drivers that don't support mempool history when enabled

Drivers must explicitly support this feature in their meson file to be built when RTE_MEMPOOL_DEBUG_OBJECTS_HISTORY is enabled.

---
 config/meson.build                  | 1 +
 drivers/meson.build                 | 7 +++++++
 drivers/net/af_packet/meson.build   | 1 +
 drivers/net/af_xdp/meson.build      | 1 +
 drivers/net/ark/meson.build         | 2 ++
 drivers/net/atlantic/meson.build    | 2 ++
 drivers/net/avp/meson.build         | 2 ++
 drivers/net/axgbe/meson.build       | 2 ++
 drivers/net/bnx2x/meson.build       | 1 +
 drivers/net/bnxt/meson.build        | 2 ++
 drivers/net/bonding/meson.build     | 1 +
 drivers/net/cnxk/meson.build        | 1 +
 drivers/net/cxgbe/meson.build       | 2 ++
 drivers/net/dpaa/meson.build        | 2 ++
 drivers/net/dpaa2/meson.build       | 2 ++
 drivers/net/ena/meson.build         | 2 ++
 drivers/net/enetc/meson.build       | 2 ++
 drivers/net/enetfec/meson.build     | 2 ++
 drivers/net/enic/meson.build        | 2 ++
 drivers/net/failsafe/meson.build    | 1 +
 drivers/net/gve/meson.build         | 2 ++
 drivers/net/hinic/meson.build       | 2 ++
 drivers/net/hns3/meson.build        | 1 +
 drivers/net/intel/cpfl/meson.build  | 2 ++
 drivers/net/intel/e1000/meson.build | 2 ++
 drivers/net/intel/fm10k/meson.build | 2 ++
 drivers/net/intel/i40e/meson.build  | 2 ++
 drivers/net/intel/iavf/meson.build  | 2 ++
 drivers/net/intel/ice/meson.build   | 1 +
 drivers/net/intel/idpf/meson.build  | 2 ++
 drivers/net/intel/ixgbe/meson.build | 2 ++
 drivers/net/ionic/meson.build       | 2 ++
 drivers/net/mana/meson.build        | 2 ++
 drivers/net/memif/meson.build       | 1 +
 drivers/net/mlx4/meson.build        | 2 ++
 drivers/net/mlx5/meson.build        | 1 +
 drivers/net/mvneta/meson.build      | 2 ++
 drivers/net/mvpp2/meson.build       | 2 ++
 drivers/net/netvsc/meson.build      | 2 ++
 drivers/net/nfb/meson.build         | 2 ++
 drivers/net/nfp/meson.build         | 2 ++
 drivers/net/ngbe/meson.build        | 2 ++
 drivers/net/ntnic/meson.build       | 4 ++++
 drivers/net/null/meson.build        | 1 +
 drivers/net/octeon_ep/meson.build   | 2 ++
 drivers/net/octeontx/meson.build    | 2 ++
 drivers/net/pcap/meson.build        | 1 +
 drivers/net/pfe/meson.build         | 2 ++
 drivers/net/qede/meson.build        | 2 ++
 drivers/net/r8169/meson.build       | 4 +++-
 drivers/net/ring/meson.build        | 1 +
 drivers/net/sfc/meson.build         | 2 ++
 drivers/net/softnic/meson.build     | 2 ++
 drivers/net/tap/meson.build         | 1 +
 drivers/net/thunderx/meson.build    | 2 ++
 drivers/net/txgbe/meson.build       | 2 ++
 drivers/net/vdev_netvsc/meson.build | 2 ++
 drivers/net/vhost/meson.build       | 2 ++
 drivers/net/virtio/meson.build      | 2 ++
 drivers/net/vmxnet3/meson.build     | 2 ++
 drivers/net/xsc/meson.build         | 2 ++
 drivers/net/zxdh/meson.build        | 4 ++++
 meson_options.txt                   | 2 ++
 63 files changed, 121 insertions(+), 1 deletion(-)
config/meson.build +1 -0
index f31fef216c..78d3574eb2 100644
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MEMPOOL_DEBUG_OBJECTS_HISTORY', get_option('enable_mempool_history'))
 
 compile_time_cpuflags = []
 subdir(arch_subdir)
drivers/meson.build +7 -0
index 7b7205dfac..253180bccd 100644
@@ -143,6 +143,7 @@ foreach subpath:subdirs
         pkgconfig_extra_libs = []
         testpmd_sources = []
         require_iova_in_mbuf = true
+        support_mempool_history = true
         # for handling base code files which may need extra cflags
         base_sources = []
         base_cflags = []
@@ -174,6 +175,12 @@ foreach subpath:subdirs
                 build = false
                 reason = 'requires IOVA in mbuf (set enable_iova_as_pa option)'
             endif
+
+            if dpdk_conf.get('RTE_MEMPOOL_DEBUG_OBJECTS_HISTORY') == 1 and not support_mempool_history
+                build = false
+                reason = 'driver does not support mempool history tracing'
+            endif
+
             # error out if we can't build a driver and that driver was explicitly requested,
             # i.e. not via wildcard.
             if not build and require_drivers and get_option('enable_drivers').contains(drv_path)
drivers/net/af_packet/meson.build +1 -0
index f45e4491d4..476d10e132 100644
@@ -7,3 +7,4 @@ if not is_linux
 endif
 sources = files('rte_eth_af_packet.c')
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/af_xdp/meson.build +1 -0
index 2d37bcc869..09228d8e54 100644
@@ -92,3 +92,4 @@ if build
 endif
 
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/ark/meson.build +2 -0
index 12b3935b85..c3126f570f 100644
@@ -18,3 +18,5 @@ sources = files(
         'ark_pktgen.c',
         'ark_udm.c',
 )
+
+support_mempool_history = false
drivers/net/atlantic/meson.build +2 -0
index bf5e47eaaf..09085f853c 100644
@@ -17,3 +17,5 @@ sources = files(
         'hw_atl/hw_atl_utils.c',
         'rte_pmd_atlantic.c',
 )
+
+support_mempool_history = false
drivers/net/avp/meson.build +2 -0
index ea9dd1f20e..ee46fca105 100644
@@ -7,3 +7,5 @@ if not is_linux
 endif
 sources = files('avp_ethdev.c')
 headers = files('rte_avp_common.h', 'rte_avp_fifo.h')
+
+support_mempool_history = false
drivers/net/axgbe/meson.build +2 -0
index b1cbe3d810..426b470673 100644
@@ -20,3 +20,5 @@ cflags += '-Wno-cast-qual'
 if arch_subdir == 'x86'
     sources += files('axgbe_rxtx_vec_sse.c')
 endif
+
+support_mempool_history = false
drivers/net/bnx2x/meson.build +1 -0
index bc66ab8032..12a2f1a5e4 100644
@@ -23,3 +23,4 @@ sources = files(
 )
 
 annotate_locks = false
+support_mempool_history = false
drivers/net/bnxt/meson.build +2 -0
index 79300eb6ac..4ef555a78c 100644
@@ -64,3 +64,5 @@ elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64')
 endif
 
 annotate_locks = false
+support_mempool_history = false
+
drivers/net/bonding/meson.build +1 -0
index d87e7a2522..d13ab392c6 100644
@@ -24,5 +24,6 @@ deps += ['ip_frag']
 headers = files('rte_eth_bond.h', 'rte_eth_bond_8023ad.h')
 
 require_iova_in_mbuf = false
+support_mempool_history = false
 
 cflags += no_wvla_cflag
drivers/net/cnxk/meson.build +1 -0
index d20a8601eb..ad5faa57f2 100644
@@ -343,5 +343,6 @@ endforeach
 headers = files('rte_pmd_cnxk.h')
 
 require_iova_in_mbuf = false
+support_mempool_history = false
 
 annotate_locks = false
drivers/net/cxgbe/meson.build +2 -0
index 95cb58ab44..a3dc7ff906 100644
@@ -25,3 +25,5 @@ sources = files(
 includes += include_directories('base')
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/dpaa/meson.build +2 -0
index b1e4bbafb5..6d33f1a2b8 100644
@@ -24,3 +24,5 @@ if cc.has_argument('-Wno-pointer-arith')
 endif
 
 headers = files('rte_pmd_dpaa.h')
+
+support_mempool_history = false
drivers/net/dpaa2/meson.build +2 -0
index 89932b3037..e44e01ab95 100644
@@ -29,3 +29,5 @@ includes += include_directories('base', 'mc')
 headers = files('rte_pmd_dpaa2.h')
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/ena/meson.build +2 -0
index d02ed3f64f..620bdeeb82 100644
@@ -17,3 +17,5 @@ sources = files(
 deps += ['timer']
 
 includes += include_directories('base', 'base/ena_defs')
+
+support_mempool_history = false
drivers/net/enetc/meson.build +2 -0
index 966dc694fc..36e3740042 100644
@@ -13,3 +13,5 @@ sources = files(
 )
 
 includes += include_directories('base')
+
+support_mempool_history = false
drivers/net/enetfec/meson.build +2 -0
index 29a464424b..c213da7640 100644
@@ -11,3 +11,5 @@ sources = files(
         'enet_uio.c',
         'enet_rxtx.c',
 )
+
+support_mempool_history = false
drivers/net/enic/meson.build +2 -0
index a48a497e46..1c160fdc62 100644
@@ -35,3 +35,5 @@ if dpdk_conf.has('RTE_ARCH_X86_64')
 endif
 
 annotate_locks = false
+support_mempool_history = false
+
drivers/net/failsafe/meson.build +1 -0
index 90c965b705..889eb383bd 100644
@@ -29,6 +29,7 @@ sources = files(
 )
 
 require_iova_in_mbuf = false
+support_mempool_history = false
 
 if is_freebsd
     annotate_locks = false
drivers/net/gve/meson.build +2 -0
index ed5ef0a1fc..c7155cc15d 100644
@@ -20,3 +20,5 @@ sources = files(
 includes += include_directories('base')
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/hinic/meson.build +2 -0
index 36cc9431a6..0cd5fe6f72 100644
@@ -21,3 +21,5 @@ includes += include_directories('base')
 if is_freebsd
     annotate_locks = false
 endif
+
+support_mempool_history = false
drivers/net/hns3/meson.build +1 -0
index 53a9dd6f39..ca9bbec971 100644
@@ -34,6 +34,7 @@ sources = files(
 )
 
 require_iova_in_mbuf = false
+support_mempool_history = false
 
 annotate_locks = false
 
drivers/net/intel/cpfl/meson.build +2 -0
index 1f0269d50b..a821e5e999 100644
@@ -35,3 +35,5 @@ if dpdk_conf.has('RTE_HAS_JANSSON')
     )
     ext_deps += jansson_dep
 endif
+
+support_mempool_history = false
drivers/net/intel/e1000/meson.build +2 -0
index 924fe4ecae..a80de1964f 100644
@@ -23,3 +23,5 @@ if not is_windows
                 'igc_txrx.c',
         )
 endif
+
+support_mempool_history = false
drivers/net/intel/fm10k/meson.build +2 -0
index fac4750f8d..a7e68959e8 100644
@@ -16,3 +16,5 @@ sources += files(
 if arch_subdir == 'x86'
     sources += files('fm10k_rxtx_vec.c')
 endif
+
+support_mempool_history = false
drivers/net/intel/i40e/meson.build +2 -0
index 49e7f899e6..c4840f9bef 100644
@@ -47,3 +47,5 @@ elif arch_subdir == 'arm'
 endif
 
 headers = files('rte_pmd_i40e.h')
+
+support_mempool_history = false
drivers/net/intel/iavf/meson.build +2 -0
index 0db94d6fe6..1c94518b5f 100644
@@ -35,3 +35,5 @@ elif arch_subdir == 'arm'
 endif
 
 headers = files('rte_pmd_iavf.h')
+
+support_mempool_history = false
drivers/net/intel/ice/meson.build +1 -0
index 8a20d0f297..d2e570d79c 100644
@@ -45,3 +45,4 @@ sources += files(
 )
 
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/intel/idpf/meson.build +2 -0
index a805d02ea2..e61df7a5f0 100644
@@ -24,3 +24,5 @@ if arch_subdir == 'x86' and dpdk_conf.get('RTE_IOVA_IN_MBUF') == 1
     sources_avx2 += files('idpf_common_rxtx_avx2.c')
     sources_avx512 += files('idpf_common_rxtx_avx512.c')
 endif
+
+support_mempool_history = false
drivers/net/intel/ixgbe/meson.build +2 -0
index d1122bb9cd..d525ef3871 100644
@@ -32,3 +32,5 @@ elif arch_subdir == 'arm'
 endif
 
 headers = files('rte_pmd_ixgbe.h')
+
+support_mempool_history = false
drivers/net/ionic/meson.build +2 -0
index cc6d5ce4db..ed96a3074b 100644
@@ -24,3 +24,5 @@ sources = files(
 )
 
 includes += include_directories('../../common/ionic')
+
+support_mempool_history = false
drivers/net/mana/meson.build +2 -0
index e320da7fc4..01655c2cd7 100644
@@ -53,3 +53,5 @@ foreach arg:required_symbols
         subdir_done()
     endif
 endforeach
+
+support_mempool_history = false
drivers/net/memif/meson.build +1 -0
index 8b2aab1f39..07d106a3f9 100644
@@ -14,3 +14,4 @@ sources = files(
 deps += ['hash']
 
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/mlx4/meson.build +2 -0
index 869d2895c8..7bd54ff6aa 100644
@@ -136,3 +136,5 @@ if dlopen_ibverbs
         install_dir: dlopen_install_dir,
     )
 endif
+
+support_mempool_history = false
drivers/net/mlx5/meson.build +1 -0
index 6a91692759..a259de5b87 100644
@@ -90,6 +90,7 @@ else
 endif
 
 require_iova_in_mbuf = false
+support_mempool_history = true
 
 testpmd_sources += files('mlx5_testpmd.c')
 
drivers/net/mvneta/meson.build +2 -0
index 2b0a94ddd0..41f68d0d60 100644
@@ -26,3 +26,5 @@ sources = files(
 deps += ['cfgfile', 'common_mvep']
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/mvpp2/meson.build +2 -0
index 396e382128..8853fbe809 100644
@@ -29,3 +29,5 @@ sources = files(
 cflags += no_wvla_cflag
 
 deps += ['cfgfile', 'common_mvep']
+
+support_mempool_history = false
drivers/net/netvsc/meson.build +2 -0
index ca94d97989..463f05aeeb 100644
@@ -17,3 +17,5 @@ sources = files(
 )
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/nfb/meson.build +2 -0
index d7a255c928..e5f1f1f03c 100644
@@ -23,3 +23,5 @@ sources = files(
 )
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/nfp/meson.build +2 -0
index 4c34a73b70..a5d07ec813 100644
@@ -65,3 +65,5 @@ else
 endif
 
 deps += ['hash', 'security', 'common_nfp']
+
+support_mempool_history = false
drivers/net/ngbe/meson.build +2 -0
index 319eb23c35..e4d90a290d 100644
@@ -24,3 +24,5 @@ if arch_subdir == 'x86'
 elif arch_subdir == 'arm'
     sources += files('ngbe_rxtx_vec_neon.c')
 endif
+
+support_mempool_history = false
drivers/net/ntnic/meson.build +4 -0
index b4c6cfe7de..bd46794ec3 100644
@@ -124,3 +124,7 @@ sources = files(
         'ntnic_vfio.c',
         'ntnic_ethdev.c',
 )
+
+cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/null/meson.build +1 -0
index bad7dc1af7..4127a07959 100644
@@ -3,3 +3,4 @@
 
 sources = files('rte_eth_null.c')
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/octeon_ep/meson.build +2 -0
index cbb729b689..f5ff3b8a9d 100644
@@ -28,3 +28,5 @@ foreach flag: extra_flags
         cflags += flag
     endif
 endforeach
+
+support_mempool_history = false
drivers/net/octeontx/meson.build +2 -0
index fc8a5a73f2..82247a87a0 100644
@@ -18,3 +18,5 @@ sources = files(
 deps += ['mempool_octeontx', 'eventdev']
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/pcap/meson.build +1 -0
index 676c55018e..28c86267a8 100644
@@ -17,3 +17,4 @@ if is_windows
 endif
 
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/pfe/meson.build +2 -0
index 684b062090..2fb4ec4408 100644
@@ -19,3 +19,5 @@ if cc.has_argument('-Wno-pointer-arith')
 endif
 
 includes += include_directories('base')
+
+support_mempool_history = false
drivers/net/qede/meson.build +2 -0
index e1b21d6ff5..a58811c9fe 100644
@@ -22,3 +22,5 @@ sources = files(
 if cc.has_argument('-Wno-format-nonliteral')
     cflags += '-Wno-format-nonliteral'
 endif
+
+support_mempool_history = false
drivers/net/r8169/meson.build +3 -1
index d1e65377a3..56eb726c84 100644
@@ -18,4 +18,6 @@ sources = files(
         'base/rtl8126a.c',
         'base/rtl8126a_mcu.c',
         'base/rtl8168kb.c',
-)
\ No newline at end of file
+)
+
+support_mempool_history = false
drivers/net/ring/meson.build +1 -0
index 9b713c9370..a37c7294f6 100644
@@ -4,3 +4,4 @@
 sources = files('rte_eth_ring.c')
 headers = files('rte_eth_ring.h')
 require_iova_in_mbuf = false
+support_mempool_history = false
drivers/net/sfc/meson.build +2 -0
index 90c38231e1..924771c1ea 100644
@@ -108,3 +108,5 @@ sources = files(
         'sfc_repr.c',
         'sfc_nic_dma.c',
 )
+
+support_mempool_history = false
drivers/net/softnic/meson.build +2 -0
index e8d7290062..7f018f6a60 100644
@@ -17,3 +17,5 @@ sources = files(
 )
 deps += ['pipeline', 'port', 'table']
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/tap/meson.build +1 -0
index 7160e9e98d..11c25589eb 100644
@@ -19,6 +19,7 @@ cflags += max_queues
 cflags += no_wvla_cflag
 
 require_iova_in_mbuf = false
+support_mempool_history = false
 
 if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT')
     cflags += '-DHAVE_TCA_FLOWER'
drivers/net/thunderx/meson.build +2 -0
index 03262af8ca..a93e6c0403 100644
@@ -22,3 +22,5 @@ endif
 if cc.has_argument('-Wno-maybe-uninitialized')
     cflags += '-Wno-maybe-uninitialized'
 endif
+
+support_mempool_history = false
drivers/net/txgbe/meson.build +2 -0
index 4dbbf597bb..baa6f549a9 100644
@@ -32,3 +32,5 @@ elif arch_subdir == 'arm'
 endif
 
 install_headers('rte_pmd_txgbe.h')
+
+support_mempool_history = false
drivers/net/vdev_netvsc/meson.build +2 -0
index bd35a13f3d..cbbef57633 100644
@@ -19,3 +19,5 @@ foreach option:cflags_options
                 cflags += option
         endif
 endforeach
+
+support_mempool_history = false
drivers/net/vhost/meson.build +2 -0
index f481a3a4b8..9462f9db05 100644
@@ -10,3 +10,5 @@ endif
 deps += 'vhost'
 sources = files('rte_eth_vhost.c')
 headers = files('rte_eth_vhost.h')
+
+support_mempool_history = false
drivers/net/virtio/meson.build +2 -0
index d3caa3a3b4..1aa77bb7fa 100644
@@ -56,3 +56,5 @@ if is_linux
         'virtio_user/virtio_user_dev.c')
     deps += ['bus_vdev']
 endif
+
+support_mempool_history = false
drivers/net/vmxnet3/meson.build +2 -0
index ed563386d5..63881d02ce 100644
@@ -17,3 +17,5 @@ foreach flag: error_cflags
                 cflags += flag
         endif
 endforeach
+
+support_mempool_history = false
drivers/net/xsc/meson.build +2 -0
index fe88bbee8c..e6410e92f1 100644
@@ -17,3 +17,5 @@ sources = files(
 )
 
 cflags += no_wvla_cflag
+
+support_mempool_history = false
drivers/net/zxdh/meson.build +4 -0
index a48a0d43c2..28fa70f319 100644
@@ -25,3 +25,7 @@ sources = files(
         'zxdh_ethdev_ops.c',
         'zxdh_mtr.c',
 )
+
+cflags += no_wvla_cflag
+
+support_mempool_history = false
meson_options.txt +2 -0
index e49b2fc089..8be20c7456 100644
@@ -16,6 +16,8 @@ option('drivers_install_subdir', type: 'string', value: 'dpdk/pmds-<VERSION>', d
        'Subdirectory of libdir where to install PMDs. Defaults to using a versioned subdirectory.')
 option('enable_docs', type: 'boolean', value: false, description:
        'build documentation')
+option('enable_mempool_history', type: 'boolean', value: false, description:
+       'Enable mempool history tracking for debugging purposes. This will track mempool objects allocation and free operations. Default is false.')
 option('enable_apps', type: 'string', value: '', description:
        'Comma-separated list of apps to build. If unspecified, build all apps.')
 option('enable_deprecated_libs', type: 'string', value: '', description:
Signature · 1 line
2.34.1
#3 lore raw

RFC PATCH 3/5 net/mlx5: mark an operation in mempool object's history

In reply to Shani Peretz

record operations on mempool objects when it is allocated and released inside the mlx5 PMD.

---
 drivers/net/mlx5/mlx5_rx.c       | 9 +++++++++
 drivers/net/mlx5/mlx5_rx.h       | 2 ++
 drivers/net/mlx5/mlx5_rxq.c      | 9 +++++++--
 drivers/net/mlx5/mlx5_rxtx_vec.c | 6 ++++++
 drivers/net/mlx5/mlx5_tx.h       | 7 +++++++
 drivers/net/mlx5/mlx5_txq.c      | 1 +
 6 files changed, 32 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5_rx.c +9 -0
index 5f4a93fe8c..a86ed2180e 100644
@@ -560,12 +560,15 @@ mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec,
 					elt_idx = (elts_ci + i) & e_mask;
 					elt = &(*rxq->elts)[elt_idx];
 					*elt = rte_mbuf_raw_alloc(rxq->mp);
+					rte_mempool_history_mark(*elt, RTE_MEMPOOL_PMD_ALLOC);
 					if (!*elt) {
 						for (i--; i >= 0; --i) {
 							elt_idx = (elts_ci +
 								   i) & elts_n;
 							elt = &(*rxq->elts)
 								[elt_idx];
+							rte_mempool_history_mark(*elt,
+									RTE_MEMPOOL_PMD_FREE);
 							rte_pktmbuf_free_seg
 								(*elt);
 						}
@@ -952,6 +955,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rte_prefetch0(wqe);
 		/* Allocate the buf from the same pool. */
 		rep = rte_mbuf_raw_alloc(seg->pool);
+		rte_mempool_history_mark(rep, RTE_MEMPOOL_PMD_ALLOC);
 		if (unlikely(rep == NULL)) {
 			++rxq->stats.rx_nombuf;
 			if (!pkt) {
@@ -966,6 +970,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 				rep = NEXT(pkt);
 				NEXT(pkt) = NULL;
 				NB_SEGS(pkt) = 1;
+				rte_mempool_history_mark(pkt, RTE_MEMPOOL_PMD_FREE);
 				rte_mbuf_raw_free(pkt);
 				pkt = rep;
 			}
@@ -979,6 +984,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 			len = mlx5_rx_poll_len(rxq, cqe, cqe_n, cqe_mask, &mcqe, &skip_cnt, false);
 			if (unlikely(len & MLX5_ERROR_CQE_MASK)) {
 				/* We drop packets with non-critical errors */
+				rte_mempool_history_mark(rep, RTE_MEMPOOL_PMD_FREE);
 				rte_mbuf_raw_free(rep);
 				if (len == MLX5_CRITICAL_ERROR_CQE_RET) {
 					rq_ci = rxq->rq_ci << sges_n;
@@ -992,6 +998,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 				continue;
 			}
 			if (len == 0) {
+				rte_mempool_history_mark(rep, RTE_MEMPOOL_PMD_FREE);
 				rte_mbuf_raw_free(rep);
 				break;
 			}
@@ -1268,6 +1275,7 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 			++rxq->stats.rx_nombuf;
 			break;
 		}
+		rte_mempool_history_mark(pkt, RTE_MEMPOOL_PMD_ALLOC);
 		len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
 		MLX5_ASSERT((int)len >= (rxq->crc_present << 2));
 		if (rxq->crc_present)
@@ -1275,6 +1283,7 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rxq_code = mprq_buf_to_pkt(rxq, pkt, len, buf,
 					   strd_idx, strd_cnt);
 		if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
+			rte_mempool_history_mark(pkt, RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(pkt);
 			if (rxq_code == MLX5_RXQ_CODE_DROPPED) {
 				++rxq->stats.idropped;
drivers/net/mlx5/mlx5_rx.h +2 -0
index 6380895502..db4ef10ca1 100644
@@ -516,6 +516,7 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
 
 				if (unlikely(next == NULL))
 					return MLX5_RXQ_CODE_NOMBUF;
+				rte_mempool_history_mark(next, RTE_MEMPOOL_PMD_ALLOC);
 				NEXT(prev) = next;
 				SET_DATA_OFF(next, 0);
 				addr = RTE_PTR_ADD(addr, seg_len);
@@ -579,6 +580,7 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
 
 			if (unlikely(seg == NULL))
 				return MLX5_RXQ_CODE_NOMBUF;
+			rte_mempool_history_mark(seg, RTE_MEMPOOL_PMD_ALLOC);
 			SET_DATA_OFF(seg, 0);
 			rte_memcpy(rte_pktmbuf_mtod(seg, void *),
 				RTE_PTR_ADD(addr, len - hdrm_overlap),
drivers/net/mlx5/mlx5_rxq.c +7 -2
index f5df451a32..e95bef9d55 100644
@@ -164,6 +164,7 @@ rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 			rte_errno = ENOMEM;
 			goto error;
 		}
+		rte_mempool_history_mark(buf, RTE_MEMPOOL_PMD_ALLOC);
 		/* Only vectored Rx routines rely on headroom size. */
 		MLX5_ASSERT(!has_vec_support ||
 			    DATA_OFF(buf) >= RTE_PKTMBUF_HEADROOM);
@@ -221,8 +222,10 @@ rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 	err = rte_errno; /* Save rte_errno before cleanup. */
 	elts_n = i;
 	for (i = 0; (i != elts_n); ++i) {
-		if ((*rxq_ctrl->rxq.elts)[i] != NULL)
+		if ((*rxq_ctrl->rxq.elts)[i] != NULL) {
+			rte_mempool_history_mark((*rxq_ctrl->rxq.elts)[i], RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
+		}
 		(*rxq_ctrl->rxq.elts)[i] = NULL;
 	}
 	if (rxq_ctrl->share_group == 0)
@@ -324,8 +327,10 @@ rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 		rxq->rq_pi = elts_ci;
 	}
 	for (i = 0; i != q_n; ++i) {
-		if ((*rxq->elts)[i] != NULL)
+		if ((*rxq->elts)[i] != NULL) {
+			rte_mempool_history_mark((*rxq->elts)[i], RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg((*rxq->elts)[i]);
+		}
 		(*rxq->elts)[i] = NULL;
 	}
 }
drivers/net/mlx5/mlx5_rxtx_vec.c +6 -0
index 1b701801c5..ffaa10c547 100644
@@ -64,6 +64,7 @@ rxq_handle_pending_error(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			err_bytes += PKT_LEN(pkt);
 #endif
+			rte_mempool_history_mark(pkt, RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(pkt);
 		} else {
 			pkts[n++] = pkt;
@@ -107,6 +108,7 @@ mlx5_rx_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
 			rxq->stats.rx_nombuf += n;
 			return;
 		}
+		rte_mempool_history_bulk((void *)elts, n, RTE_MEMPOOL_PMD_ALLOC);
 		if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1)) {
 			for (i = 0; i < n; ++i) {
 				/*
@@ -171,6 +173,7 @@ mlx5_rx_mprq_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
 			rxq->stats.rx_nombuf += n;
 			return;
 		}
+		rte_mempool_history_bulk((void *)elts, n, RTE_MEMPOOL_PMD_ALLOC);
 		rxq->elts_ci += n;
 		/* Prevent overflowing into consumed mbufs. */
 		elts_idx = rxq->elts_ci & wqe_mask;
@@ -224,6 +227,7 @@ rxq_copy_mprq_mbuf_v(struct mlx5_rxq_data *rxq,
 
 		if (!elts[i]->pkt_len) {
 			rxq->consumed_strd = strd_n;
+			rte_mempool_history_mark(elts[i], RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(elts[i]);
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			rxq->stats.ipackets -= 1;
@@ -236,6 +240,7 @@ rxq_copy_mprq_mbuf_v(struct mlx5_rxq_data *rxq,
 					   buf, rxq->consumed_strd, strd_cnt);
 		rxq->consumed_strd += strd_cnt;
 		if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
+			rte_mempool_history_mark(elts[i], RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(elts[i]);
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			rxq->stats.ipackets -= 1;
@@ -586,6 +591,7 @@ mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rte_io_wmb();
 		*rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
 	} while (tn != pkts_n);
+
 	return tn;
 }
 
drivers/net/mlx5/mlx5_tx.h +7 -0
index 55568c41b1..7b61d87120 100644
@@ -553,6 +553,7 @@ mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
 	if (!MLX5_TXOFF_CONFIG(MULTI) && txq->fast_free) {
 		mbuf = *pkts;
 		pool = mbuf->pool;
+		rte_mempool_history_bulk((void *)pkts, pkts_n, RTE_MEMPOOL_PMD_FREE);
 		rte_mempool_put_bulk(pool, (void *)pkts, pkts_n);
 		return;
 	}
@@ -608,6 +609,7 @@ mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
 			 * Free the array of pre-freed mbufs
 			 * belonging to the same memory pool.
 			 */
+			rte_mempool_history_bulk((void *)p_free, n_free, RTE_MEMPOOL_PMD_FREE);
 			rte_mempool_put_bulk(pool, (void *)p_free, n_free);
 			if (unlikely(mbuf != NULL)) {
 				/* There is the request to start new scan. */
@@ -1223,6 +1225,7 @@ mlx5_tx_mseg_memcpy(uint8_t *pdst,
 			/* Exhausted packet, just free. */
 			mbuf = loc->mbuf;
 			loc->mbuf = mbuf->next;
+			rte_mempool_history_mark(mbuf, RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(mbuf);
 			loc->mbuf_off = 0;
 			MLX5_ASSERT(loc->mbuf_nseg > 1);
@@ -1265,6 +1268,7 @@ mlx5_tx_mseg_memcpy(uint8_t *pdst,
 				/* Exhausted packet, just free. */
 				mbuf = loc->mbuf;
 				loc->mbuf = mbuf->next;
+				rte_mempool_history_mark(mbuf, RTE_MEMPOOL_PMD_FREE);
 				rte_pktmbuf_free_seg(mbuf);
 				loc->mbuf_off = 0;
 				MLX5_ASSERT(loc->mbuf_nseg >= 1);
@@ -1715,6 +1719,7 @@ mlx5_tx_mseg_build(struct mlx5_txq_data *__rte_restrict txq,
 			/* Zero length segment found, just skip. */
 			mbuf = loc->mbuf;
 			loc->mbuf = loc->mbuf->next;
+			rte_mempool_history_mark(mbuf, RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(mbuf);
 			if (--loc->mbuf_nseg == 0)
 				break;
@@ -2018,6 +2023,7 @@ mlx5_tx_packet_multi_send(struct mlx5_txq_data *__rte_restrict txq,
 			wqe->cseg.sq_ds -= RTE_BE32(1);
 			mbuf = loc->mbuf;
 			loc->mbuf = mbuf->next;
+			rte_mempool_history_mark(mbuf, RTE_MEMPOOL_PMD_FREE);
 			rte_pktmbuf_free_seg(mbuf);
 			if (--nseg == 0)
 				break;
@@ -3317,6 +3323,7 @@ mlx5_tx_burst_single_send(struct mlx5_txq_data *__rte_restrict txq,
 				 * Packet data are completely inlined,
 				 * free the packet immediately.
 				 */
+				rte_mempool_history_mark(loc->mbuf, RTE_MEMPOOL_PMD_FREE);
 				rte_pktmbuf_free_seg(loc->mbuf);
 			} else if ((!MLX5_TXOFF_CONFIG(EMPW) ||
 				     MLX5_TXOFF_CONFIG(MPW)) &&
drivers/net/mlx5/mlx5_txq.c +1 -0
index 5fee5bc4e8..156f8c2ef8 100644
@@ -78,6 +78,7 @@ txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl)
 		struct rte_mbuf *elt = (*elts)[elts_tail & elts_m];
 
 		MLX5_ASSERT(elt != NULL);
+		rte_mempool_history_mark(elt, RTE_MEMPOOL_PMD_FREE);
 		rte_pktmbuf_free_seg(elt);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		/* Poisoning. */
Signature · 1 line
2.34.1
#4 lore raw

RFC PATCH 4/5 app/testpmd: add testpmd command to dump mempool history

In reply to Shani Peretz

dumps the mempool object history to console or to a file.

The dump will contain:
- Operation history for each mempool object
- Summary and statistics about all mempool objects

testpmd> dump_mempool_objects_history
testpmd> dump_mempool_objects_history <file_name>

---
 app/test-pmd/cmdline.c | 59 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
app/test-pmd/cmdline.c +58 -1
index 7b4e27eddf..3233b9d663 100644
@@ -296,6 +296,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump_log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump_mempool_objects_history\n"
+			"    Dumps the mempool objects history\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9170,6 +9173,8 @@ static void cmd_dump_parsed(void *parsed_result,
 #endif
 	else if (!strcmp(res->dump, "dump_log_types"))
 		rte_log_dump(stdout);
+	else if (!strcmp(res->dump, "dump_mempool_objects_history"))
+		rte_mempool_objects_dump(stdout);
 }
 
 static cmdline_parse_token_string_t cmd_dump_dump =
@@ -9191,7 +9196,8 @@ cmd_dump_init(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 		"dump_trace#"
 #endif
-		"dump_log_types";
+		"dump_log_types#"
+		"dump_mempool_objects_history";
 }
 
 static cmdline_parse_inst_t cmd_dump = {
@@ -9253,6 +9259,56 @@ static cmdline_parse_inst_t cmd_dump_one = {
 	},
 };
 
+/* Dump mempool objects history to file */
+struct cmd_dump_to_file_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_to_file_parsed(void *parsed_result, struct cmdline *cl,
+				__rte_unused void *data)
+{
+	struct cmd_dump_to_file_result *res = parsed_result;
+	FILE *file = stdout;
+	char *file_name = res->file;
+
+	if (strcmp(res->dump, "dump_mempool_objects_history")) {
+		cmdline_printf(cl, "Invalid dump type\n");
+		return;
+	}
+
+	if (file_name && strlen(file_name)) {
+		file = fopen(file_name, "w");
+		if (!file) {
+			fprintf(stderr, "Failed to create file %s: %s\n",
+				file_name, strerror(errno));
+			return;
+		}
+	}
+	rte_mempool_objects_dump(file);
+	printf("Flow dump finished\n");
+	if (file_name && strlen(file_name))
+		fclose(file);
+}
+
+static cmdline_parse_token_string_t cmd_dump_to_file_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_to_file_result, dump,
+				 "dump_mempool_objects_history");
+
+static cmdline_parse_token_string_t cmd_dump_to_file_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_to_file_result, file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_to_file = {
+	.f = cmd_dump_to_file_parsed,  /* function to call */
+	.data = NULL,      /* 2nd arg of func */
+	.help_str = "dump_mempool_objects_history <file_name>: Dump mempool objects history to file",
+	.tokens = {        /* token list, NULL terminated */
+		(void *)&cmd_dump_to_file_dump,
+		(void *)&cmd_dump_to_file_file,
+		NULL,
+	},
+};
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13992,6 +14048,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump,
 	&cmd_dump_one,
+	&cmd_dump_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
Signature · 1 line
2.34.1
#5 lore raw

RFC PATCH 5/5 usertool: add a script to parse mempool history dump

In reply to Shani Peretz

Added a Python script that parses the history dump of a mempool object generated by rte_mempool_objects_dump and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 .../dpdk-mempool_object_history_parser.py     | 129 ++++++++++++++++++
 1 file changed, 129 insertions(+)
 create mode 100755 usertools/dpdk-mempool_object_history_parser.py
usertools/dpdk-mempool_object_history_parser.py new file +129 -0
new file mode 100755
index 0000000000..0224a97e22
@@ -0,0 +1,129 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023 NVIDIA Corporation & Affiliates
+
+import sys
+import re
+import os
+
+RED = "\033[91m"
+RESET = "\033[0m"
+ENUM_PATTERN = r'enum\s+rte_mempool_history_op\s*{([^}]+)}'
+VALUE_PATTERN = r'([A-Z_]+)\s*=\s*(\d+),\s*(?:/\*\s*(.*?)\s*\*/)?'
+
+def match_field(match: re.Match) -> tuple[int, str]:
+    name, value, _ = match.groups()
+    return (int(value), name.replace('RTE_MEMPOOL_', ''))
+
+def parse_history_enum(header_file: str) -> dict[int, str]:
+    with open(header_file, 'r') as f:
+        content = f.read()
+
+    # Extract each enum value and its comment
+    enum_content = re.search(ENUM_PATTERN, content, re.DOTALL).group(1)
+    return dict(map(match_field, re.finditer(VALUE_PATTERN, enum_content)))
+
+
+# Generate HISTORY_OPS from the header file
+HEADER_FILE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib/mempool/rte_mempool.h')
+try:
+    HISTORY_OPS = parse_history_enum(HEADER_FILE)
+except Exception as e:
+    print(f"Warning: Could not generate HISTORY_OPS from header file: {e}")
+
+
+def op_to_string(op: int) -> str:
+    return HISTORY_OPS.get(op, f"UNKNOWN({op})")
+
+def parse_mempool_object_history(line: str) -> list[str]:
+    line = line.strip().replace('0x', '')
+    return [op_to_string(int(digit)) for digit in line]
+
+def parse_metrics(lines: list[str]) -> dict[str, int]:
+    metrics = {}
+    for line in lines:
+        if ':' not in line:
+            continue
+        key, value = line.split(':', 1)
+        metrics[key.strip()] = int(value.strip())
+    return metrics
+
+def print_history_sequence(ops: list[str]) -> bool:
+    sequence = []
+    had_repeat = False
+    for idx, op in enumerate(ops):
+        if idx > 0 and op == ops[idx-1] and op != 'NEVER':
+            sequence.append(RED + op + RESET)
+            had_repeat = True
+        else:
+            sequence.append(op)
+
+    if not sequence:
+        return had_repeat
+
+    max_op_width = max(len(re.sub(r'\x1b\[[0-9;]*m', '', op)) for op in sequence)
+    OP_WIDTH = max_op_width
+    for i in range(0, len(sequence), 4):
+        chunk = sequence[i:i+4]
+        formatted_ops = [f"{op:<{OP_WIDTH}}" for op in chunk]
+        line = ""
+        for j, op in enumerate(formatted_ops):
+            line += op
+            if j < len(formatted_ops) - 1:
+                line += " -> "
+        if i + 4 < len(sequence):
+            line += " ->"
+        print("\t" + line)
+    return had_repeat
+
+def main():
+    if len(sys.argv) != 2:
+        print("Usage: {} <history_file>".format(sys.argv[0]))
+        sys.exit(1)
+
+    try:
+        with open(sys.argv[1], 'r') as f:
+            lines = f.readlines()
+
+        # Find where metrics start
+        metrics_start = -1
+        for i, line in enumerate(lines):
+            if "Populated:" in line:
+                metrics_start = i
+                break
+
+        # Process mempool object history traces
+        marked_mempool_objects = []
+        mempool_object_id = 1
+        for line in lines[:metrics_start] if metrics_start != -1 else lines:
+            if not line.strip():
+                continue
+            ops = parse_mempool_object_history(line)
+            print(f"MEMPOOL OBJECT {mempool_object_id}:")
+            had_repeat = print_history_sequence(ops)
+            print()  # Empty line between mempool objects
+            if had_repeat:
+                marked_mempool_objects.append(mempool_object_id)
+            mempool_object_id += 1
+
+        if marked_mempool_objects:
+            print("MEMPOOL OBJECTS with repeated ops:", marked_mempool_objects)
+
+        if metrics_start != -1:
+            print("=== Metrics Summary ===")
+            metrics = parse_metrics(lines[metrics_start:])
+            # Find max width of metric names for alignment
+            max_name_width = max(len(name) for name in metrics.keys())
+            # Print metrics in aligned format
+            for name, value in metrics.items():
+                print(f"{name + ':':<{max_name_width + 2}} {value}")
+
+    except FileNotFoundError:
+        print(f"Error: File {sys.argv[1]} not found")
+        sys.exit(1)
+    except Exception as e:
+        print(f"Error processing file: {e}")
+        sys.exit(1)
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
2.34.1
#6 lore raw
In reply to Shani Peretz
Quoted 92 lines · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects flow.

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Shani Peretz (5):
mempool: record mempool objects operations history
drivers: add mempool history compilation flag net/mlx5: mark an operation in mempool object's history app/testpmd: add testpmd command to dump mempool history
usertool: add a script to parse mempool history dump

 app/test-pmd/cmdline.c                        |  59 +++++++-
 config/meson.build                            |   1 +
 drivers/meson.build                           |   7 +
 drivers/net/af_packet/meson.build             |   1 +
 drivers/net/af_xdp/meson.build                |   1 +
 drivers/net/ark/meson.build                   |   2 +
 drivers/net/atlantic/meson.build              |   2 +
 drivers/net/avp/meson.build                   |   2 +
 drivers/net/axgbe/meson.build                 |   2 +
 drivers/net/bnx2x/meson.build                 |   1 +
 drivers/net/bnxt/meson.build                  |   2 +
 drivers/net/bonding/meson.build               |   1 +
 drivers/net/cnxk/meson.build                  |   1 +
 drivers/net/cxgbe/meson.build                 |   2 +
 drivers/net/dpaa/meson.build                  |   2 +
 drivers/net/dpaa2/meson.build                 |   2 +
 drivers/net/ena/meson.build                   |   2 +
 drivers/net/enetc/meson.build                 |   2 +
 drivers/net/enetfec/meson.build               |   2 +
 drivers/net/enic/meson.build                  |   2 +
 drivers/net/failsafe/meson.build              |   1 +
 drivers/net/gve/meson.build                   |   2 +
 drivers/net/hinic/meson.build                 |   2 +
 drivers/net/hns3/meson.build                  |   1 +
 drivers/net/intel/cpfl/meson.build            |   2 +
 drivers/net/intel/e1000/meson.build           |   2 +
 drivers/net/intel/fm10k/meson.build           |   2 +
 drivers/net/intel/i40e/meson.build            |   2 +
 drivers/net/intel/iavf/meson.build            |   2 +
 drivers/net/intel/ice/meson.build             |   1 +
 drivers/net/intel/idpf/meson.build            |   2 +
 drivers/net/intel/ixgbe/meson.build           |   2 +
 drivers/net/ionic/meson.build                 |   2 +
 drivers/net/mana/meson.build                  |   2 +
 drivers/net/memif/meson.build                 |   1 +
 drivers/net/mlx4/meson.build                  |   2 +
 drivers/net/mlx5/meson.build                  |   1 +
 drivers/net/mlx5/mlx5_rx.c                    |   9 ++
 drivers/net/mlx5/mlx5_rx.h                    |   2 +
 drivers/net/mlx5/mlx5_rxq.c                   |   9 +-
 drivers/net/mlx5/mlx5_rxtx_vec.c              |   6 +
 drivers/net/mlx5/mlx5_tx.h                    |   7 +
 drivers/net/mlx5/mlx5_txq.c                   |   1 +
 drivers/net/mvneta/meson.build                |   2 +
 drivers/net/mvpp2/meson.build                 |   2 +
 drivers/net/netvsc/meson.build                |   2 +
 drivers/net/nfb/meson.build                   |   2 +
 drivers/net/nfp/meson.build                   |   2 +
 drivers/net/ngbe/meson.build                  |   2 +
 drivers/net/ntnic/meson.build                 |   4 +
 drivers/net/null/meson.build                  |   1 +
 drivers/net/octeon_ep/meson.build             |   2 +
 drivers/net/octeontx/meson.build              |   2 +
 drivers/net/pcap/meson.build                  |   1 +
 drivers/net/pfe/meson.build                   |   2 +
 drivers/net/qede/meson.build                  |   2 +
 drivers/net/r8169/meson.build                 |   4 +-
 drivers/net/ring/meson.build                  |   1 +
 drivers/net/sfc/meson.build                   |   2 +
 drivers/net/softnic/meson.build               |   2 +
 drivers/net/tap/meson.build                   |   1 +
 drivers/net/thunderx/meson.build              |   2 +
 drivers/net/txgbe/meson.build                 |   2 +
 drivers/net/vdev_netvsc/meson.build           |   2 +
 drivers/net/vhost/meson.build                 |   2 +
 drivers/net/virtio/meson.build                |   2 +
 drivers/net/vmxnet3/meson.build               |   2 +
 drivers/net/xsc/meson.build                   |   2 +
Quoted 9 lines
 drivers/net/zxdh/meson.build                  |   4 +
 lib/ethdev/rte_ethdev.h                       |  14 ++
 lib/mempool/rte_mempool.c                     | 111 +++++++++++++++
 lib/mempool/rte_mempool.h                     | 106 ++++++++++++++
 meson_options.txt                             |   2 +
 .../dpdk-mempool_object_history_parser.py     | 129 ++++++++++++++++++
 74 files changed, 571 insertions(+), 4 deletions(-)
 create mode 100755 usertools/dpdk-mempool_object_history_parser.py

Could this not already be done with tracing infrastructure?

#7 lore raw
Quoted 32 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 16 June 2025 17.30

Quoted 5 lines · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects

flow.

Quoted 12 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Quoted 7 lines

Shani Peretz (5):
mempool: record mempool objects operations history
drivers: add mempool history compilation flag net/mlx5: mark an operation in mempool object's history app/testpmd: add testpmd command to dump mempool history
usertool: add a script to parse mempool history dump

Quoted 1 line

Could this not already be done with tracing infrastructure?

I agree with Stephen on this.

And, if you plan to use this for performance measurements, you can use the coming PMU trace to trace the objects' movements between CPU caches and RAM, so you can discriminate between hot and cold objects.

#8 lore raw
Quoted 47 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Thursday, 19 June 2025 15:57
To: Stephen Hemminger <[email protected]>; Shani Peretz <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/5] Introduce mempool object new debug capabilities

External email: Use caution opening links or attachments

Quoted 33 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 16 June 2025 17.30

Quoted 6 lines · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects

flow.

Quoted 19 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Shani Peretz (5):
mempool: record mempool objects operations history
drivers: add mempool history compilation flag net/mlx5: mark an operation in mempool object's history app/testpmd: add testpmd command to dump mempool history
usertool: add a script to parse mempool history dump

Quoted 7 lines
Quoted 1 line

Could this not already be done with tracing infrastructure?

I agree with Stephen on this.

And, if you plan to use this for performance measurements, you can use the coming PMU trace to trace the objects' movements between CPU caches and RAM, so you can discriminate between hot and cold objects.

We want to track when the transition of objects between the app and the PMD. So I don't know if PMU library is helpful in this case, isn't it?

#9 lore raw
In reply to Stephen Hemminger
Quoted 115 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, 16 June 2025 18:30
To: Shani Peretz <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/5] Introduce mempool object new debug capabilities

External email: Use caution opening links or attachments

Quoted 5 lines · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and

understanding objects flow.

Quoted 85 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Shani Peretz (5):
mempool: record mempool objects operations history
drivers: add mempool history compilation flag net/mlx5: mark an operation in mempool object's history app/testpmd: add testpmd command to dump mempool history
usertool: add a script to parse mempool history dump

 app/test-pmd/cmdline.c                        |  59 +++++++-
 config/meson.build                            |   1 +
 drivers/meson.build                           |   7 +
 drivers/net/af_packet/meson.build             |   1 +
 drivers/net/af_xdp/meson.build                |   1 +
 drivers/net/ark/meson.build                   |   2 +
 drivers/net/atlantic/meson.build              |   2 +
 drivers/net/avp/meson.build                   |   2 +
 drivers/net/axgbe/meson.build                 |   2 +
 drivers/net/bnx2x/meson.build                 |   1 +
 drivers/net/bnxt/meson.build                  |   2 +
 drivers/net/bonding/meson.build               |   1 +
 drivers/net/cnxk/meson.build                  |   1 +
 drivers/net/cxgbe/meson.build                 |   2 +
 drivers/net/dpaa/meson.build                  |   2 +
 drivers/net/dpaa2/meson.build                 |   2 +
 drivers/net/ena/meson.build                   |   2 +
 drivers/net/enetc/meson.build                 |   2 +
 drivers/net/enetfec/meson.build               |   2 +
 drivers/net/enic/meson.build                  |   2 +
 drivers/net/failsafe/meson.build              |   1 +
 drivers/net/gve/meson.build                   |   2 +
 drivers/net/hinic/meson.build                 |   2 +
 drivers/net/hns3/meson.build                  |   1 +
 drivers/net/intel/cpfl/meson.build            |   2 +
 drivers/net/intel/e1000/meson.build           |   2 +
 drivers/net/intel/fm10k/meson.build           |   2 +
 drivers/net/intel/i40e/meson.build            |   2 +
 drivers/net/intel/iavf/meson.build            |   2 +
 drivers/net/intel/ice/meson.build             |   1 +
 drivers/net/intel/idpf/meson.build            |   2 +
 drivers/net/intel/ixgbe/meson.build           |   2 +
 drivers/net/ionic/meson.build                 |   2 +
 drivers/net/mana/meson.build                  |   2 +
 drivers/net/memif/meson.build                 |   1 +
 drivers/net/mlx4/meson.build                  |   2 +
 drivers/net/mlx5/meson.build                  |   1 +
 drivers/net/mlx5/mlx5_rx.c                    |   9 ++
 drivers/net/mlx5/mlx5_rx.h                    |   2 +
 drivers/net/mlx5/mlx5_rxq.c                   |   9 +-
 drivers/net/mlx5/mlx5_rxtx_vec.c              |   6 +
 drivers/net/mlx5/mlx5_tx.h                    |   7 +
 drivers/net/mlx5/mlx5_txq.c                   |   1 +
 drivers/net/mvneta/meson.build                |   2 +
 drivers/net/mvpp2/meson.build                 |   2 +
 drivers/net/netvsc/meson.build                |   2 +
 drivers/net/nfb/meson.build                   |   2 +
 drivers/net/nfp/meson.build                   |   2 +
 drivers/net/ngbe/meson.build                  |   2 +
 drivers/net/ntnic/meson.build                 |   4 +
 drivers/net/null/meson.build                  |   1 +
 drivers/net/octeon_ep/meson.build             |   2 +
 drivers/net/octeontx/meson.build              |   2 +
 drivers/net/pcap/meson.build                  |   1 +
 drivers/net/pfe/meson.build                   |   2 +
 drivers/net/qede/meson.build                  |   2 +
 drivers/net/r8169/meson.build                 |   4 +-
 drivers/net/ring/meson.build                  |   1 +
 drivers/net/sfc/meson.build                   |   2 +
 drivers/net/softnic/meson.build               |   2 +
 drivers/net/tap/meson.build                   |   1 +
 drivers/net/thunderx/meson.build              |   2 +
 drivers/net/txgbe/meson.build                 |   2 +
 drivers/net/vdev_netvsc/meson.build           |   2 +
 drivers/net/vhost/meson.build                 |   2 +
 drivers/net/virtio/meson.build                |   2 +
Quoted 8 lines
 drivers/net/vmxnet3/meson.build               |   2 +
 drivers/net/xsc/meson.build                   |   2 +
 drivers/net/zxdh/meson.build                  |   4 +
 lib/ethdev/rte_ethdev.h                       |  14 ++
 lib/mempool/rte_mempool.c                     | 111 +++++++++++++++
 lib/mempool/rte_mempool.h                     | 106 ++++++++++++++
 meson_options.txt                             |   2 +
 .../dpdk-mempool_object_history_parser.py     | 129
Quoted 6 lines

++++++++++++++++++

Quoted 3 lines
 74 files changed, 571 insertions(+), 4 deletions(-)  create mode

100755 usertools/dpdk-mempool_object_history_parser.py

Could this not already be done with tracing infrastructure?

Hey,
We did consider tracing but:
- It has limited capacity, which will result in older mbufs being lost in the tracing output while they are still in use
- Some operations may be lost, and we might not capture the complete picture due to trace misses caused by the performance overhead of tracking on the datapath as far as I understand
WDYT?

#10 lore raw
Quoted 30 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Monday, 7 July 2025 07.45

Quoted 25 lines

From: Stephen Hemminger <[email protected]>
Sent: Monday, 16 June 2025 18:30

Quoted 5 lines · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and

understanding objects flow.

Quoted 12 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Quoted 1 line

Could this not already be done with tracing infrastructure?

Quoted 8 lines

Hey,
We did consider tracing but:
- It has limited capacity, which will result in older mbufs being
lost in the tracing output while they are still in use
- Some operations may be lost, and we might not capture the
complete picture due to trace misses caused by the performance overhead of tracking on the datapath as far as I understand
WDYT?

This looks like an alternative trace infrastructure, just for mempool objects.
But the list of operations is limited to basic operations on mbuf mempool objects.
It lacks support for other operations on mbufs, e.g. IP fragmentation/defragmentation library operations, application specific operations, and transitions between the mempool cache and the mempool backing store. It also lacks support for operations on other mempool objects than mbufs.

You might better off using the trace infrastructure, or something similar.
Using the trace infrastructure allows you to record more detailed information along with the transitions of "owners" of each mbuf.

I'm not opposing this RFC, but I think it is very limited, and not sufficiently expandable.

I get the point that trace can cause old events on active mbufs to be lost, and the concept of a trace buffer per mempool object is a good solution to that. But I think you need to be able to store much more information with each transition; at least a timestamp. And if you do that, you need much more than 4 bits per event.

Alternatively, if you do proceed with the RFC in the current form, I have two key suggestions:
1. Make it possible to register operations at runtime. (Look at dynamic mbuf fields for inspiration.)
2. Use 8 bits for the operation, instead of 4.
And if you need a longer trace history, you can use the rte_bitset library instead of a single uint64_t.

#11 lore raw
Quoted 70 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 7 July 2025 14.11

Quoted 10 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Monday, 7 July 2025 07.45

Quoted 7 lines

From: Stephen Hemminger <[email protected]>
Sent: Monday, 16 June 2025 18:30

Quoted 1 line · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool

objects

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and

understanding objects flow.

Quoted 12 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Quoted 8 lines
Quoted 1 line

Could this not already be done with tracing infrastructure?

Hey,
We did consider tracing but:
- It has limited capacity, which will result in older mbufs being
lost in the tracing output while they are still in use
- Some operations may be lost, and we might not capture the
complete picture due to trace misses caused by the performance

overhead

Quoted 2 lines

of tracking on the datapath as far as I understand WDYT?

This looks like an alternative trace infrastructure, just for mempool objects.
But the list of operations is limited to basic operations on mbuf mempool objects.
It lacks support for other operations on mbufs, e.g. IP fragmentation/defragmentation library operations, application specific operations, and transitions between the mempool cache and the mempool backing store.
It also lacks support for operations on other mempool objects than mbufs.

You might better off using the trace infrastructure, or something similar.
Using the trace infrastructure allows you to record more detailed information along with the transitions of "owners" of each mbuf.

I'm not opposing this RFC, but I think it is very limited, and not sufficiently expandable.

I get the point that trace can cause old events on active mbufs to be lost, and the concept of a trace buffer per mempool object is a good solution to that.
But I think you need to be able to store much more information with each transition; at least a timestamp. And if you do that, you need much more than 4 bits per event.

Quoted 7 lines

Alternatively, if you do proceed with the RFC in the current form, I have two key suggestions:
1. Make it possible to register operations at runtime. (Look at dynamic mbuf fields for inspiration.)
2. Use 8 bits for the operation, instead of 4.
And if you need a longer trace history, you can use the rte_bitset library instead of a single uint64_t.

One more comment:
If this feature is meant for mbuf type mempool objects only, it might be possible to add it to the mbuf library (and store the trace in the rte_mbuf structure) instead of the mempool library. Although that would prevent tracing internal mempool library operations, specifically moving the object between the mempool cache and mempool backing store.

#12 lore raw

Hi, Morten

Quoted 53 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Saturday, July 19, 2025 5:39 PM
To: Shani Peretz <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>
Subject: RE: [RFC PATCH 0/5] Introduce mempool object new debug capabilities

Quoted 45 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 7 July 2025 14.11

Quoted 10 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Monday, 7 July 2025 07.45

Quoted 7 lines

From: Stephen Hemminger <[email protected]>
Sent: Monday, 16 June 2025 18:30

Quoted 1 line · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool

objects

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and

understanding objects flow.

Quoted 12 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Quoted 8 lines
Quoted 1 line

Could this not already be done with tracing infrastructure?

Hey,
We did consider tracing but:
- It has limited capacity, which will result in older mbufs being
lost in the tracing output while they are still in use
- Some operations may be lost, and we might not capture the
complete picture due to trace misses caused by the performance

overhead

Quoted 1 line

of tracking on the datapath as far as I understand WDYT?

This looks like an alternative trace infrastructure, just for mempool objects.

It is rather not alternative, but some orthogonal way to trace.
We gather the life history per mbuf and it helps a lot with nailing the issues on the user's sites. From our practice - it helped instantly to find the mbuf double free, and core policy violations for rx/tx_burst routines in the user applications .

Quoted 2 lines
Quoted 2 lines

But the list of operations is limited to basic operations on mbuf mempool objects.

Agree, but this limitation is because of only mbuf life milestones are well-defined in DPDK:
- alloc by app/tx_burst/tx queued|tx_busy/free by PMD|app
- alloc by PMD/rx replenish/rx_burst_returned/free by app

No other mempool-based object milestones are defined so well. So, do you think we should move this history data to the mbuf object itself ?

Quoted 2 lines
Quoted 2 lines

It lacks support for other operations on mbufs, e.g. IP fragmentation/defragmentation library operations, application specific

Yes, these ones can be added later, once we see the user's request.
There are too many options to cover and limited field bit width to embrace all of them 😊

Quoted 7 lines
Quoted 7 lines

operations, and transitions between the mempool cache and the mempool backing store.
It also lacks support for operations on other mempool objects than mbufs.

You might better off using the trace infrastructure, or something similar.

We considered using the existing trace feature.
We even tried in practice to achieve our debugging goals with trace
on the user's sites:
Trace:
- is overwhelming - to many events with too many mbufs
- is incomplete - sometimes there were longtime runs to catch the bug conditions and it was a little bit hard to record all the huge trace to the files in real time, usually we had gaps
- is performance impacting. It records the full event information, that is redundant, queries timestamp (and this action might introduce execution barriers), uses more memory (as a large linear address range - it impacts cache performance). Sometimes it is crucially not to impact the datapath performance to have an issue repro onsite.

Quoted 5 lines
Quoted 5 lines

Using the trace infrastructure allows you to record more detailed information along with the transitions of "owners" of each mbuf.

I'm not opposing this RFC, but I think it is very limited, and not sufficiently expandable.

It was intentionally developed to be limited, very compact and very fast.

Quoted 8 lines
Quoted 8 lines

I get the point that trace can cause old events on active mbufs to be lost, and the concept of a trace buffer per mempool object is a good solution to that.
But I think you need to be able to store much more information with each transition; at least a timestamp. And if you do that, you need rdtsc much more than 4 bits per event.

Quoted 5 lines
Quoted 5 lines

Alternatively, if you do proceed with the RFC in the current form, I have two key suggestions:
1. Make it possible to register operations at runtime. (Look at dynamic mbuf fields for inspiration.) 2. Use 8 bits for the operation, instead of 4.

OK, we can do:
- narrow the gather history feature to mbuf only
- use the dynamic mbuf field for that
- registration would involve the extra memory access and affects the perf, I would prefer to have fixed set of events to record, at least on the feature firstintoduction.

Quoted 2 lines
Quoted 2 lines

And if you need a longer trace history, you can use the rte_bitset library instead of a single uint64_t.

Would be not the best option for the perf ☹

Quoted 9 lines

One more comment:
If this feature is meant for mbuf type mempool objects only, it might be possible to add it to the mbuf library (and store the trace in the rte_mbuf structure) instead of the mempool library.

Although that would prevent tracing internal mempool library operations, specifically moving the object between the mempool cache and mempool backing store.

We can update free/alloc mbuf functions, so functionality will not be lost.

With best regards,
Slava

#13 lore raw
Quoted 51 lines

From: Slava Ovsiienko [mailto:[email protected]]
Sent: Monday, 25 August 2025 13.28

Hi, Morten

Quoted 46 lines

From: Morten Brørup <[email protected]>
Sent: Saturday, July 19, 2025 5:39 PM

Quoted 43 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 7 July 2025 14.11

Quoted 10 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Monday, 7 July 2025 07.45

Quoted 7 lines

From: Stephen Hemminger <[email protected]>
Sent: Monday, 16 June 2025 18:30

Quoted 1 line · On Mon, 16 Jun 2025 10:29:05 +0300 Shani Peretz <[email protected]> wrote:

This feature is designed to monitor the lifecycle of mempool

objects

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and

understanding objects flow.

Quoted 12 lines

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Quoted 8 lines
Quoted 1 line

Could this not already be done with tracing infrastructure?

Hey,
We did consider tracing but:
- It has limited capacity, which will result in older mbufs being
lost in the tracing output while they are still in use
- Some operations may be lost, and we might not capture the
complete picture due to trace misses caused by the performance

overhead

Quoted 1 line

of tracking on the datapath as far as I understand WDYT?

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

This looks like an alternative trace infrastructure, just for mempool objects.

It is rather not alternative, but some orthogonal way to trace. We gather the life history per mbuf and it helps a lot with nailing the issues on the user's sites. From our practice - it helped instantly to find the mbuf double free,
and core policy violations for rx/tx_burst routines in the user applications .

Great with some real life use cases, proving the value of this patch series!

<sidetracking>
The mbuf library has a performance optimization where it keeps ref_cnt==1 for free mbufs in the pool, so double free of mbufs cannot be detected (without this series). Some other patch series could make that performance optimization optional, so double free can be detected by the mbuf library at runtime. Although that would be a major API change, considering how many drivers bypass the mbuf library and call the mempool library directly for allocating/freeing mbufs. </sidetracking>

What are "core policy violations for rx/tx_burst routines"?
(I'm trying to understand what other types of bugs this series has helped you track down.)

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

But the list of operations is limited to basic operations on mbuf mempool objects.

Quoted 8 lines

Agree, but this limitation is because of only mbuf life milestones are well-defined in DPDK:
- alloc by app/tx_burst/tx queued|tx_busy/free by PMD|app
- alloc by PMD/rx replenish/rx_burst_returned/free by app

No other mempool-based object milestones are defined so well. So, do you think we should move this history data to the mbuf object itself ?

This series specifically targets mbufs, and it doesn't look useful for generic mempool objects, so yes, please move the history data to the mbuf object itself.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

It lacks support for other operations on mbufs, e.g. IP fragmentation/defragmentation library operations, application specific

Yes, these ones can be added later, once we see the user's request. There are too many options to cover and limited field bit width to embrace all of them 😊

Agree.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines

operations, and transitions between the mempool cache and the mempool backing store.
It also lacks support for operations on other mempool objects than mbufs.

You might better off using the trace infrastructure, or something similar.

We considered using the existing trace feature.
We even tried in practice to achieve our debugging goals with trace on the user's sites:
Trace:
- is overwhelming - to many events with too many mbufs
- is incomplete - sometimes there were longtime runs to catch the bug conditions
and it was a little bit hard to record all the huge trace to the files in real time,

Quoted 8 lines

usually we had gaps
- is performance impacting. It records the full event information, that is redundant,
queries timestamp (and this action might introduce execution barriers), uses more memory
(as a large linear address range - it impacts cache performance). Sometimes it is crucially
not to impact the datapath performance to have an issue repro onsite.

OK. Personally, I'm not a big fan of trace in the fast path either.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

Using the trace infrastructure allows you to record more detailed information along with the transitions of "owners" of each mbuf.

I'm not opposing this RFC, but I think it is very limited, and not sufficiently expandable.

It was intentionally developed to be limited, very compact and very fast.

OK. I agree to focusing only on the lifecycle of mbufs with this series.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

I get the point that trace can cause old events on active mbufs to be lost, and the concept of a trace buffer per mempool object is a good solution to that.
But I think you need to be able to store much more information with each transition; at least a timestamp. And if you do that, you need rdtsc much more than 4 bits per event.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

Alternatively, if you do proceed with the RFC in the current form, I have two key suggestions:
1. Make it possible to register operations at runtime. (Look at dynamic mbuf fields for inspiration.) 2. Use 8 bits for the operation, instead of 4.

OK, we can do:
- narrow the gather history feature to mbuf only

Agree.

Quoted 1 line

- use the dynamic mbuf field for that

Agree.

Quoted 3 lines

- registration would involve the extra memory access and affects the perf, I would prefer to have fixed set of events to record, at least on the feature firstintoduction.

OK, let's stick with a fixed set of event types for now.
Patch 1/5 has only 8 event types, so using 4 bits for each event history entry probably suffices. That still leaves room for 8 more event types.
Suggest adding event types USR1 = 15, USR2 = 14, USR3 = 13, USR4 = 12 for application use.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

And if you need a longer trace history, you can use the rte_bitset library instead of a single uint64_t.

Would be not the best option for the perf ☹

Agree.
I suppose a trace history of 16 or 8 entries suffices for debugging.

Quoted 6 lines
Quoted 5 lines

One more comment:
If this feature is meant for mbuf type mempool objects only, it might be possible to add it to the mbuf library (and store the trace in the rte_mbuf structure) instead of the mempool library.

Quoted 9 lines
Quoted 3 lines

Although that would prevent tracing internal mempool library operations, specifically moving the object between the mempool cache and mempool backing store.

We can update free/alloc mbuf functions, so functionality will not be lost.

With best regards,
Slava

Please go ahead with this, Slava.

I'm looking forward to seeing the next version of this series. :-)

-Morten

#14 lore raw

v2 cover add mbuf debug capabilities

In reply to Shani Peretz

v2:
narrow scope to mbuf only - move the history tracking data to the rte_mbuf structure. use a dynamic mbuf field to store the tracking bitmap.
remove the compilation flag.

v1:
This feature is designed to monitor the lifecycle of mempool objects as they move between the application and the PMD.

It will allow us to track the operations and transitions of each mempool object throughout the system, helping in debugging and understanding objects flow.

The implementation include several key components:
1. Added a bitmap to mempool's header (rte_mempool_objhdr) that represent the operations history.
2. Added functions that allow marking operations on an mempool objects.
3. Dumps the history to a file or the console (rte_mempool_objects_dump).
4. Added python script that can parse, analyze the data and present it in an human readable format.
5. Added compilation flag to enable the feature.

Shani Peretz (4):
mbuf: record mbuf operations history net/mlx5: mark an operation in mbuf's history app/testpmd: add testpmd command to dump mbuf history
usertool: add a script to parse mbuf history dump

 app/test-pmd/cmdline.c                |  60 ++++++++-
 config/meson.build                    |   1 +
 drivers/net/mlx5/mlx5_rx.c            |  25 ++++
 drivers/net/mlx5/mlx5_rx.h            |   6 +
 drivers/net/mlx5/mlx5_rxq.c           |  15 ++-
 drivers/net/mlx5/mlx5_rxtx_vec.c      |  16 +++
 drivers/net/mlx5/mlx5_tx.h            |  21 +++
 drivers/net/mlx5/mlx5_txq.c           |   3 +
 lib/ethdev/rte_ethdev.h               |  15 +++
 lib/mbuf/meson.build                  |   2 +
 lib/mbuf/rte_mbuf.c                   |  10 +-
 lib/mbuf/rte_mbuf.h                   |  23 +++-
 lib/mbuf/rte_mbuf_dyn.h               |   7 +
 lib/mbuf/rte_mbuf_history.c           | 181 ++++++++++++++++++++++++++
 lib/mbuf/rte_mbuf_history.h           | 154 ++++++++++++++++++++++
 meson_options.txt                     |   2 +
 usertools/dpdk-mbuf_history_parser.py | 173 ++++++++++++++++++++++++
 17 files changed, 708 insertions(+), 6 deletions(-)
 create mode 100644 lib/mbuf/rte_mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf_history_parser.py
Signature · 1 line
2.34.1
#15 lore raw

PATCH v2 1/4 mbuf: record mbuf operations history

This feature is designed to monitor the lifecycle of mbufs as they move between the applicationand the PMD.

It will allow us to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

The implementation uses a dynamic field to store a 64-bit history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked per mbuf. The dynamic field is automatically initialized when the first mbuf pool is created.

---
 config/meson.build          |   1 +
 lib/ethdev/rte_ethdev.h     |  15 +++
 lib/mbuf/meson.build        |   2 +
 lib/mbuf/rte_mbuf.c         |  10 +-
 lib/mbuf/rte_mbuf.h         |  23 ++++-
 lib/mbuf/rte_mbuf_dyn.h     |   7 ++
 lib/mbuf/rte_mbuf_history.c | 181 ++++++++++++++++++++++++++++++++++++
 lib/mbuf/rte_mbuf_history.h | 154 ++++++++++++++++++++++++++++++
 meson_options.txt           |   2 +
 9 files changed, 392 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/rte_mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/meson.build +1 -0
index 55497f0bf5..d1f21f3115 100644
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG', get_option('enable_mbuf_history'))
 
 compile_time_cpuflags = []
 subdir(arch_subdir)
lib/ethdev/rte_ethdev.h +15 -0
index d23c143eed..d0f6cd2582 100644
@@ -6336,6 +6336,10 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_bulk(rx_pkts, nb_rx, RTE_MBUF_APP_RX);
+#endif
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6692,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+#if RTE_MBUF_HISTORY_DEBUG
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_bulk(tx_pkts, nb_pkts, RTE_MBUF_PMD_TX);
+#endif
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_bulk(tx_pkts + nb_pkts,
+				     requested_pkts - nb_pkts, RTE_MBUF_BUSY_TX);
+#endif
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
lib/mbuf/meson.build +2 -0
index 0435c5e628..2c840ee2f2 100644
@@ -6,6 +6,7 @@ sources = files(
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
         'rte_mbuf_dyn.c',
+        'rte_mbuf_history.c',
 )
 headers = files(
         'rte_mbuf.h',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +9 -1
index 9e7731a8a2..362dd252bc 100644
@@ -281,6 +281,10 @@ rte_pktmbuf_pool_create(const char *name, unsigned int n,
 	unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
 	int socket_id)
 {
+#if RTE_MBUF_HISTORY_DEBUG
+		if (rte_mbuf_history_init() < 0)
+			RTE_LOG(ERR, MBUF, "Failed to enable mbuf history\n");
+#endif
 	return rte_pktmbuf_pool_create_by_ops(name, n, cache_size, priv_size,
 			data_room_size, socket_id, NULL);
 }
@@ -516,8 +520,12 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_bulk(pending, nb_pending, RTE_MBUF_FREE);
+#endif
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending, nb_pending);
+	}
 }
 
 /* Creates a shallow copy of mbuf */
lib/mbuf/rte_mbuf.h +21 -2
index 06ab7502a5..8126f09de4 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include "rte_mbuf_history.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,9 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC);
+#endif
 	return ret.m;
 }
 
@@ -642,9 +646,14 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_ALLOC);
+#endif
+		}
+	}
 	return rc;
 }
 
@@ -667,6 +676,9 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(m, RTE_MBUF_FREE);
+#endif
 }
 
 /**
@@ -701,6 +713,9 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_FREE);
+#endif
 	}
 
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1028,10 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_bulk(mbufs, count, RTE_MBUF_ALLOC);
+#endif
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +7 -0
index 865c90f579..8ae31b4e65 100644
@@ -240,6 +240,13 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking for mbuf objects through the system.
+ * It records a fixed set of predefined operations to maintain performance
+ * while providing debugging capabilities.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.c new file +181 -0

181 lines not on this page · raw message

lib/mbuf/rte_mbuf_history.h new file +154 -0

154 lines not on this page · raw message

meson_options.txt +2 -0
index e49b2fc089..48f6d4a9a5 100644
@@ -16,6 +16,8 @@ option('drivers_install_subdir', type: 'string', value: 'dpdk/pmds-<VERSION>', d
        'Subdirectory of libdir where to install PMDs. Defaults to using a versioned subdirectory.')
 option('enable_docs', type: 'boolean', value: false, description:
        'build documentation')
+option('enable_mbuf_history', type: 'boolean', value: false, description:
+       'Enable mbuf history tracking for debugging purposes. This will track mbufs allocation and free operations. Default is false.')
 option('enable_apps', type: 'string', value: '', description:
        'Comma-separated list of apps to build. If unspecified, build all apps.')
 option('enable_deprecated_libs', type: 'string', value: '', description:
Signature · 1 line
2.34.1
#16 lore raw

Re: [PATCH v2 1/4] mbuf: record mbuf operations history

lib/mbuf/rte_mbuf.h static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp) · line 615

Quoted 9 lines · On Tue, 16 Sep 2025 18:12:04 +0300 Shani Peretz <[email protected]> wrote:
lib/mbuf/rte_mbuf.h +3 -0
@@ -607,6 +608,9 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC);
+#endif
 	return ret.m;
 }

If you made rte_mbuf_history_mark a dummy function if RTE_MBUF_HISTORY_DEBUG was not defined, then you could remove most of the #ifdef clutter and would get type checking on normal builds.

#17 lore raw

Re: [PATCH v2 1/4] mbuf: record mbuf operations history

16/09/2025 23:17, Stephen Hemminger:

Quoted 16 lines

lib/mbuf/rte_mbuf.h static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp) · line 615

Quoted 9 lines · On Tue, 16 Sep 2025 18:12:04 +0300 Shani Peretz <[email protected]> wrote:
lib/mbuf/rte_mbuf.h +3 -0
@@ -607,6 +608,9 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC);
+#endif
 	return ret.m;
 }

If you made rte_mbuf_history_mark a dummy function if RTE_MBUF_HISTORY_DEBUG was not defined, then you could remove most of the #ifdef clutter and would get type checking on normal builds.

Yes good idea!
We need to check whether an empty inline function will be completely optimized out by the compilers (clang and GCC).

#18 lore raw

RE: [PATCH v2 1/4] mbuf: record mbuf operations history

Quoted 19 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 16 September 2025 23.34

16/09/2025 23:17, Stephen Hemminger:

Quoted 4 lines

Review static inline struct rte_mbuf

Quoted 1 line · On Tue, 16 Sep 2025 18:12:04 +0300 Shani Peretz <[email protected]> wrote:
(quoted diff) +0 -0
@@ -607,6 +608,9 @@ static inline struct rte_mbuf

*rte_mbuf_raw_alloc(struct rte_mempool *mp)

Quoted 10 lines

lib/mbuf/rte_mbuf.h static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp) · line 615

Quoted 8 lines
lib/mbuf/rte_mbuf.h +3 -0
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC);
+#endif
 	return ret.m;
 }

If you made rte_mbuf_history_mark a dummy function if

Quoted 5 lines

RTE_MBUF_HISTORY_DEBUG

Quoted 2 lines

was not defined, then you could remove most of the #ifdef clutter and would get type checking on normal builds.

Yes good idea!

+1

Quoted 3 lines

We need to check whether an empty inline function will be completely optimized out by the compilers (clang and GCC).

It works for trace.

#19 lore raw

RE: [PATCH v2 1/4] mbuf: record mbuf operations history

In reply to Shani Peretz
Quoted 10 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Tuesday, 16 September 2025 17.12

This feature is designed to monitor the lifecycle of mbufs as they move between the applicationand the PMD.

It will allow us to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

Quoted 7 lines

The implementation uses a dynamic field to store a 64-bit history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked per mbuf. The dynamic field is automatically initialized when the first mbuf pool is created.

Looking really good.
Some comments inline below.

Quoted 90 lines
---
 config/meson.build          |   1 +
 lib/ethdev/rte_ethdev.h     |  15 +++
 lib/mbuf/meson.build        |   2 +
 lib/mbuf/rte_mbuf.c         |  10 +-
 lib/mbuf/rte_mbuf.h         |  23 ++++-
 lib/mbuf/rte_mbuf_dyn.h     |   7 ++
 lib/mbuf/rte_mbuf_history.c | 181 ++++++++++++++++++++++++++++++++++++
 lib/mbuf/rte_mbuf_history.h | 154 ++++++++++++++++++++++++++++++
 meson_options.txt           |   2 +
 9 files changed, 392 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/rte_mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/meson.build +1 -0
index 55497f0bf5..d1f21f3115 100644
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG',
 get_option('enable_mbuf_history'))
 
 compile_time_cpuflags = []

subdir(arch_subdir)

lib/ethdev/rte_ethdev.h +4 -0
index d23c143eed..d0f6cd2582 100644
@@ -6336,6 +6336,10 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t
 queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_bulk(rx_pkts, nb_rx, RTE_MBUF_APP_RX);
+#endif
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
lib/ethdev/rte_ethdev.h +11 -0
 		void *cb;
@@ -6688,8 +6692,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t
 queue_id,
 	}
 #endif
 
+#if RTE_MBUF_HISTORY_DEBUG
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_bulk(tx_pkts, nb_pkts, RTE_MBUF_PMD_TX);
+#endif
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_bulk(tx_pkts + nb_pkts,
+				     requested_pkts - nb_pkts,
 RTE_MBUF_BUSY_TX);
+#endif
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts,

nb_pkts);

lib/ethdev/rte_ethdev.h +0 -0
 	return nb_pkts;
 }
lib/mbuf/meson.build +2 -0
index 0435c5e628..2c840ee2f2 100644
@@ -6,6 +6,7 @@ sources = files(
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
         'rte_mbuf_dyn.c',
+        'rte_mbuf_history.c',
 )
 headers = files(
         'rte_mbuf.h',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +0 -0
index 9e7731a8a2..362dd252bc 100644

lib/mbuf/rte_mbuf.c rte_pktmbuf_pool_create(const char *name, unsigned · line 290

Quoted 10 lines
lib/mbuf/rte_mbuf.c +4 -0
@@ -281,6 +281,10 @@ rte_pktmbuf_pool_create(const char *name, unsigned
 int n,
 	unsigned int cache_size, uint16_t priv_size, uint16_t
 data_room_size,
 	int socket_id)
 {
+#if RTE_MBUF_HISTORY_DEBUG
+		if (rte_mbuf_history_init() < 0)
+			RTE_LOG(ERR, MBUF, "Failed to enable mbuf
 history\n");
+#endif

rte_mbuf_history_init() must be called from all mbuf library functions to create a pktmbuf_pool.

Quoted 106 lines

return rte_pktmbuf_pool_create_by_ops(name, n, cache_size,
priv_size,

lib/mbuf/rte_mbuf.c +5 -1
 			data_room_size, socket_id, NULL);
 }
@@ -516,8 +520,12 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf
 **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_bulk(pending, nb_pending, RTE_MBUF_FREE);
+#endif
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending,
 nb_pending);
+	}
 }

/* Creates a shallow copy of mbuf */

lib/mbuf/rte_mbuf.h +14 -2
index 06ab7502a5..8126f09de4 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include "rte_mbuf_history.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,9 @@ static inline struct rte_mbuf
 *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC);
+#endif
 	return ret.m;
 }
@@ -642,9 +646,14 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf
 **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_ALLOC);
+#endif
+		}
+	}
 	return rc;
 }
@@ -667,6 +676,9 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_mark(m, RTE_MBUF_FREE);
+#endif
 }
 
 /**
@@ -701,6 +713,9 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp,

struct rte_mbuf **mbufs, unsigned

lib/mbuf/rte_mbuf.h +7 -0
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_FREE);
+#endif
 	}
 
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1028,10 @@ static inline int rte_pktmbuf_alloc_bulk(struct
 rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+#if RTE_MBUF_HISTORY_DEBUG
+	rte_mbuf_history_bulk(mbufs, count, RTE_MBUF_ALLOC);
+#endif
+
 	/* To understand duff's device on loop unwinding optimization,

see

lib/mbuf/rte_mbuf.h +0 -0
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid

extra

lib/mbuf/rte_mbuf_dyn.h +2 -0
index 865c90f579..8ae31b4e65 100644
@@ -240,6 +240,13 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking for mbuf
Quoted 6 lines

objects through the system.
+ * It records a fixed set of predefined operations to maintain performance
+ * while providing debugging capabilities.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"

Suggest you also define the mbuf history type here:
typedef uint64_t rte_mbuf_history_t;

Or even better, to support cloned mbufs accessed simultaneously by multiple lcores:
typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;

<feature creep>
It could be uint32_t on 32 bit architectures, for performance. </feature creep>

Quoted 86 lines
lib/mbuf/rte_mbuf_dyn.h +1 -0
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.c new file +28 -0
new file mode 100644
index 0000000000..5be56289ca
@@ -0,0 +1,181 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates
+ */
+
+#include <rte_mbuf_history.h>
+#include <rte_mbuf_dyn.h>
+#include <rte_log.h>
+#include <rte_errno.h>
+#include <eal_export.h>
+#include <rte_mempool.h>
+#include <rte_tailq.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+/* Global offset for the history field */
+int rte_mbuf_history_field_offset = -1;
+RTE_EXPORT_SYMBOL(rte_mbuf_history_field_offset);
+
+#if RTE_MBUF_HISTORY_DEBUG
+/* Dynamic field definition for mbuf history */
+static const struct rte_mbuf_dynfield mbuf_dynfield_history = {
+	.name = RTE_MBUF_DYNFIELD_HISTORY_NAME,
+	.size = sizeof(uint64_t),
+	.align = RTE_ALIGN(sizeof(uint64_t), 8),
+};
+
+/* Context structure for combined statistics counting and mbuf history

printing */

lib/mbuf/rte_mbuf_history.c new file +7 -0
+struct count_and_print_ctx {
+	uint64_t *stats;
+	FILE *f;
+};
+
+static void
+mbuf_history_count_stats_and_print(struct rte_mempool *mp

__rte_unused, void *opaque,

lib/mbuf/rte_mbuf_history.c new file +3 -0
+					void *obj, unsigned obj_idx __rte_unused)
+{
+	struct count_and_print_ctx *ctx = (struct count_and_print_ctx

*)opaque;

lib/mbuf/rte_mbuf_history.c new file +4 -0
+
+	struct rte_mbuf *mbuf = (struct rte_mbuf *)obj;
+
+	if (obj == NULL || ctx == NULL || ctx->stats == NULL || ctx->f ==

NULL)

lib/mbuf/rte_mbuf_history.c new file +30 -0
+		return;
+
+	/* Get mbuf history */
+	uint64_t history = rte_mbuf_history_get(mbuf);
+
+	ctx->stats[0]++; /* n_total */
+
+	if (history == 0) {
+		ctx->stats[1]++; /* n_never */
+		return;
+	}
+
+	/* Extract the most recent operation */
+	uint64_t op = history & RTE_MBUF_HISTORY_MASK;
+
+	switch (op) {
+	case RTE_MBUF_FREE:
+		ctx->stats[2]++; /* n_free */
+		break;
+	case RTE_MBUF_PMD_FREE:
+		ctx->stats[3]++; /* n_pmd_free */
+		break;
+	case RTE_MBUF_PMD_TX:
+		ctx->stats[4]++; /* n_pmd_tx */
+		break;
+	case RTE_MBUF_APP_RX:
+		ctx->stats[5]++; /* n_app_rx */
+		break;
+	case RTE_MBUF_PMD_ALLOC:
+		ctx->stats[6]++; /* n_pmd_alloc */

lib/mbuf/rte_mbuf_history.c line 82

Quoted 10 lines
lib/mbuf/rte_mbuf_history.c new file +10 -0
+		break;
+	case RTE_MBUF_ALLOC:
+		ctx->stats[7]++; /* n_alloc */
+		break;
+	case RTE_MBUF_BUSY_TX:
+		ctx->stats[8]++; /* n_busy_tx */
+		break;
+	default:
+		break;
+	}

Intead of using stats[9], use stats[RTE_MBUF_HISTORY_OP_MAX]. Then your switch/case can be replaced by a simple one-liner:
ctx->stats[op]++;

This can also handle future history operation types not yet defined in the enumeration of operations.

Quoted 4 lines
lib/mbuf/rte_mbuf_history.c new file +4 -0
+
+	/* Print the mbuf history value */
+	fprintf(ctx->f, "mbuf %p: %016" PRIX64 "\n", mbuf, history);
+

lib/mbuf/rte_mbuf_history.c line 96

Quoted 10 lines
lib/mbuf/rte_mbuf_history.c new file +10 -0
+}
+
+static void
+mbuf_history_get_stat(struct rte_mempool *mp, void *arg)
+{
+	FILE *f = (FILE *)arg;
+	uint64_t stats[9] = {0};
+
+	if (f == NULL)
+		return;

It would be nice if mempools can somehow be marked with the type of objects they hold, or at least can be marked that they hold mbufs. One simple way could be prefixing the mempool name with "MBUF_" when the mbuf library calls the mempool library to create a mempool.

Then this function can skip mempools holding other objects than mbufs.

Quoted 30 lines
lib/mbuf/rte_mbuf_history.c new file +9 -0
+
+	/* Output mempool header */
+	fprintf(f, "=== Mempool: %s ===\n", mp->name);
+
+	/* Create context structure for combined counting and printing */
+	struct count_and_print_ctx ctx = { .stats = stats, .f = f };
+
+	/* Single pass: collect statistics and print mbuf history */
+	rte_mempool_obj_iter(mp, mbuf_history_count_stats_and_print,

&ctx);

lib/mbuf/rte_mbuf_history.c new file +19 -0
+
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated = stats[3] + stats[4] + stats[5] +
+	stats[6] + stats[7] + stats[8];
+
+	/* Print statistics summary */
+	fprintf(f, "\n"
+		"Populated:       %u\n"
+		"Never allocated: %" PRIu64 "\n"
+		"Free:            %" PRIu64 "\n"
+		"Allocated:       %" PRIu64 "\n"
+		"PMD owned Tx:    %" PRIu64 "\n"
+		"PMD owned Rx:    %" PRIu64 "\n"
+		"App owned alloc: %" PRIu64 "\n"
+		"App owned Rx:    %" PRIu64 "\n"
+		"App owned busy:  %" PRIu64 "\n"
+		"Counted total:   %" PRIu64 "\n",
+		mp->populated_size, stats[1], stats[2], total_allocated,
+		stats[4], stats[6], stats[7], stats[5], stats[8],

stats[0]);

lib/mbuf/rte_mbuf_history.c

Quoted 2 lines
lib/mbuf/rte_mbuf_history.c new file +2 -0
+
+	fprintf(f, "---\n");

Please follow the convention of other "dump" functions, e.g. like rte_mempool_dump():
- Use hierarchical indentation
- Use " value=%" PRIu64 "\n".

Quoted 100 lines
lib/mbuf/rte_mbuf_history.c new file +14 -0
+}
+#endif
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump, 25.11)
+#if RTE_MBUF_HISTORY_DEBUG
+void rte_mbuf_history_dump(FILE *f)
+{
+	if (f == NULL) {
+		RTE_LOG(ERR, MBUF, "Invalid file pointer\n");
+		return;
+	}
+
+	fprintf(f, "=== MBUF History Statistics ===\n");
+	fprintf(f, "Dumping complete mbuf history for all

mempools...\n");

lib/mbuf/rte_mbuf_history.c new file +4 -0
+
+	/* Check if mbuf history is initialized */
+	if (rte_mbuf_history_field_offset == -1) {
+		fprintf(f, "WARNING: MBUF history not initialized. Call

rte_mbuf_history_init() first.\n\n");

lib/mbuf/rte_mbuf_history.c new file +15 -0
+		return;
+	}
+
+	/* Use rte_mempool_walk to iterate over all mempools */
+	rte_mempool_walk(mbuf_history_get_stat, f);
+}
+
+int rte_mbuf_history_init(void)
+{
+	if (rte_mbuf_history_field_offset != -1) {
+		/* Already initialized */
+		return 0;
+	}
+
+	rte_mbuf_history_field_offset =

rte_mbuf_dynfield_register(&mbuf_dynfield_history);

lib/mbuf/rte_mbuf_history.c new file +2 -0
+	if (rte_mbuf_history_field_offset < 0) {
+		RTE_LOG(ERR, MBUF, "Failed to register mbuf history dynamic

field: %s\n",

lib/mbuf/rte_mbuf_history.c new file +20 -0
+			rte_strerror(rte_errno));
+		return -1;
+	}
+	return 0;
+}
+#else
+void rte_mbuf_history_dump(FILE *f)
+{
+	RTE_SET_USED(f);
+	RTE_LOG(INFO, MBUF, "Mbuf history recorder is not supported\n");
+}
+
+int rte_mbuf_history_init(void)
+{
+	rte_errno = ENOTSUP;
+	return -1;
+}
+#endif
+RTE_EXPORT_SYMBOL(rte_mbuf_history_init);
+RTE_EXPORT_SYMBOL(rte_mbuf_history_dump);
lib/mbuf/rte_mbuf_history.h new file +12 -0
new file mode 100644
index 0000000000..4448ad1557
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates
+ */
+
+#ifndef _RTE_MBUF_HISTORY_H_
+#define _RTE_MBUF_HISTORY_H_
+
+/**
+ * @file
+ * MBUF History
+ *
+ * This module provides history tracking for mbuf objects using

dynamic fields.
+ * It tracks the lifecycle of mbuf objects through the system with a fixed set
+ * of predefined events to maintain performance.
+ *
+ * The history is stored as a 64-bit value in the mbuf dynamic field area,
+ * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
+ */

lib/mbuf/rte_mbuf_history.h new file +13 -0
+
+#include <stdint.h>
+#include <rte_mbuf_dyn.h>
+#include <rte_common.h>
+#include <rte_branch_prediction.h>
+#include "mbuf_log.h"
+
+/* Forward declaration to avoid circular dependency */
+struct rte_mbuf;
+
+#ifdef __cplusplus
+extern "C" {
+#endif

lib/mbuf/rte_mbuf_history.h line 41

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +10 -0
+
+/**
+ * Number of bits for each history operation
+ */
+#define RTE_MBUF_HISTORY_BITS          4
+
+/**
+ * Maximum number of history operations that can be stored
+ */
+#define RTE_MBUF_HISTORY_MAX_OPS       16

Suggest:
#define RTE_MBUF_HISTORY_MAX_OPS (sizeof(rte_mbuf_history_t) * 8 / RTE_MBUF_HISTORY_BITS)

lib/mbuf/rte_mbuf_history.h line 51

Quoted 11 lines
lib/mbuf/rte_mbuf_history.h new file +5 -0
+
+/**
+ * Mask for extracting the most recent operation from history
+ */
+#define RTE_MBUF_HISTORY_MASK          ((1ULL <<

RTE_MBUF_HISTORY_BITS) - 1)

lib/mbuf/rte_mbuf_history.h new file +5 -0
+
+/**
+ * History operation types
+ */
+enum rte_mbuf_history_op {

These values should be prefixed RTE_MBUF_HISTORY_OP_ or RTE_MBUF_HISTORY_ or something similar. Also, naming should be hierarchical. Suggest:

lib/mbuf/rte_mbuf_history.h line 52

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_NEVER = 0,        /* Initial state - never allocated */

RTE_MBUF_HISTORY_OP_NEVER

lib/mbuf/rte_mbuf_history.h line 53

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_FREE = 1,         /* Freed back to pool */

RTE_MBUF_HISTORY_OP_FREE

lib/mbuf/rte_mbuf_history.h line 54

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_PMD_FREE = 2,     /* Freed by PMD back to pool*/

RTE_MBUF_HISTORY_OP_PMD_FREE

lib/mbuf/rte_mbuf_history.h line 55

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_PMD_TX = 3,       /* Sent to PMD for Tx */

RTE_MBUF_HISTORY_OP_PMD_TX

lib/mbuf/rte_mbuf_history.h line 56

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_APP_RX = 4,       /* Returned to application on Rx */

RTE_MBUF_HISTORY_OP_PMD_RX

lib/mbuf/rte_mbuf_history.h line 57

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_PMD_ALLOC = 5,    /* Allocated by PMD for Rx */

RTE_MBUF_HISTORY_OP_PMD_RX_ALLOC

lib/mbuf/rte_mbuf_history.h line 58

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_ALLOC = 6,        /* Allocated by application */

RTE_MBUF_HISTORY_OP_ALLOC

lib/mbuf/rte_mbuf_history.h line 59

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_BUSY_TX = 7,      /* Returned to app due to Tx busy */

RTE_MBUF_HISTORY_OP_PMD_TX_BUSY

Quoted 31 lines
lib/mbuf/rte_mbuf_history.h new file +16 -0
+	RTE_MBUF_USR3 = 13,        /* Application-defined event 3 */
+	RTE_MBUF_USR2 = 14,        /* Application-defined event 2 */
+	RTE_MBUF_USR1 = 15,        /* Application-defined event 1 */
+	RTE_MBUF_MAX = 16,          /* Maximum trace operation value */
+};
+
+
+/**
+ * Global offset for the history field (set during initialization)
+ */
+extern int rte_mbuf_history_field_offset;
+
+/**
+ * Initialize the mbuf history system
+ *
+ * This function registers the dynamic field for mbuf history

tracking.
+ * It should be called once during application initialization.
+ *
+ * Note: This function is called by rte_pktmbuf_pool_create,
+ * so explicit invocation is usually not required unless initializing manually.
+ *
+ * @return
+ * 0 on success, -1 on failure with rte_errno set
+ */

lib/mbuf/rte_mbuf_history.h new file +5 -0
+int rte_mbuf_history_init(void);
+
+#if RTE_MBUF_HISTORY_DEBUG
+/**
+ * Get the history value from an mbuf

lib/mbuf/rte_mbuf_history.h line 98

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +10 -0
+ *
+ * @param m
+ *   Pointer to the mbuf
+ * @return
+ *   The history value, or 0 if history is not available
+ */
+static inline uint64_t rte_mbuf_history_get(const struct rte_mbuf *m)
+{
+	if (unlikely(m == NULL || rte_mbuf_history_field_offset == -1))
+		return 0;

These are fast path, so don't validate params at runtime. Suggest:

    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
	if (unlikely(m == NULL))
		return 0;
Quoted 3 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+
+	return *RTE_MBUF_DYNFIELD(m, rte_mbuf_history_field_offset,

uint64_t *);

Mbufs may be cloned, so this should be an atomic operation.

Quoted 15 lines
lib/mbuf/rte_mbuf_history.h new file +11 -0
+}
+
+/**
+ * Mark an mbuf with a history event
+ *
+ * @param m
+ *   Pointer to the mbuf
+ * @param op
+ *   The operation to record
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t

op)

lib/mbuf/rte_mbuf_history.h new file +2 -0
+{
+	if (unlikely(m == NULL || op >= RTE_MBUF_MAX ||

rte_mbuf_history_field_offset == -1))

lib/mbuf/rte_mbuf_history.h

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+		return;

These are fast path, so don't validate params at runtime. Suggest:

    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
    RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
	if (unlikely(m == NULL))
		return 0;

lib/mbuf/rte_mbuf_history.h line 117

Quoted 4 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+
+	uint64_t *history = RTE_MBUF_DYNFIELD(m,

rte_mbuf_history_field_offset, uint64_t *);

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	*history = (*history << RTE_MBUF_HISTORY_BITS) | op;

Mbufs may be cloned, so this should be an atomic operation.

Quoted 14 lines
lib/mbuf/rte_mbuf_history.h new file +13 -0
+}
+
+/**
+ * Mark multiple mbufs with a history event
+ *
+ * @param mbufs
+ *   Array of mbuf pointers
+ * @param n
+ *   Number of mbufs to mark
+ * @param op
+ *   The operation to record
+ */
+static inline void rte_mbuf_history_bulk(struct rte_mbuf * const

*mbufs,

lib/mbuf/rte_mbuf_history.h line 131

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+					uint32_t n, uint32_t op)

rte_mbuf_history_bulk() -> rte_mbuf_history_mark_bulk()

lib/mbuf/rte_mbuf_history.h

Quoted 4 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+{
+	if (unlikely(mbufs == NULL || op >= RTE_MBUF_MAX ||

rte_mbuf_history_field_offset == -1))

lib/mbuf/rte_mbuf_history.h new file +1 -0
+		return;

These are fast path, so don't validate params at runtime. Suggest:

    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
    RTE_ASSERT(mbufs != NULL);
    RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
Quoted 4 lines
lib/mbuf/rte_mbuf_history.h new file +4 -0
+
+	while (n--)
+		rte_mbuf_history_mark(*mbufs++, op);
+}

lib/mbuf/rte_mbuf_history.h line 148

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +10 -0
+#endif
+
+/**
+ * Dump mbuf history statistics for all mempools to a file
+ *
+ * @param f
+ *   File pointer to write the history statistics to
+ */
+__rte_experimental
+void rte_mbuf_history_dump(FILE *f);

<feature creep>
It would be nice to expose three dump functions:
1) dump the history of one mbuf:
void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf * mbuf);
2) dump the history of one mbuf pool, and
void rte_mbuf_history_dump_mempool(FILE *f, const struct rte_mempool * mp);
3) dump the history of all mbuf pools.
void rte_mbuf_history_dump_all(FILE *f);
<feature creep>

Quoted 27 lines
lib/mbuf/rte_mbuf_history.h new file +6 -0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_MBUF_HISTORY_H_ */
meson_options.txt +0 -0
index e49b2fc089..48f6d4a9a5 100644
@@ -16,6 +16,8 @@ option('drivers_install_subdir', type: 'string',

value: 'dpdk/pmds-<VERSION>', d
'Subdirectory of libdir where to install PMDs. Defaults to
using a versioned subdirectory.')
option('enable_docs', type: 'boolean', value: false, description:
'build documentation')
+option('enable_mbuf_history', type: 'boolean', value: false, description:
+ 'Enable mbuf history tracking for debugging purposes. This will
track mbufs allocation and free operations. Default is false.')
option('enable_apps', type: 'string', value: '', description:
'Comma-separated list of apps to build. If unspecified, build
all apps.')
option('enable_deprecated_libs', type: 'string', value: '',
description:
--
2.34.1

#20 lore raw

RE: [PATCH v2 1/4] mbuf: record mbuf operations history

Quoted 131 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Wednesday, 17 September 2025 17:46
To: Shani Peretz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: RE: [PATCH v2 1/4] mbuf: record mbuf operations history

External email: Use caution opening links or attachments

Quoted 10 lines

From: Shani Peretz [mailto:[email protected]]
Sent: Tuesday, 16 September 2025 17.12

This feature is designed to monitor the lifecycle of mbufs as they move between the applicationand the PMD.

It will allow us to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

Quoted 6 lines

The implementation uses a dynamic field to store a 64-bit history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked per mbuf. The dynamic field is automatically initialized when the first mbuf pool is created.

Looking really good.
Some comments inline below.

Quoted 93 lines
---
 config/meson.build          |   1 +
 lib/ethdev/rte_ethdev.h     |  15 +++
 lib/mbuf/meson.build        |   2 +
 lib/mbuf/rte_mbuf.c         |  10 +-
 lib/mbuf/rte_mbuf.h         |  23 ++++-
 lib/mbuf/rte_mbuf_dyn.h     |   7 ++
 lib/mbuf/rte_mbuf_history.c | 181
++++++++++++++++++++++++++++++++++++
 lib/mbuf/rte_mbuf_history.h | 154 ++++++++++++++++++++++++++++++
 meson_options.txt           |   2 +
 9 files changed, 392 insertions(+), 3 deletions(-)  create mode

100644 lib/mbuf/rte_mbuf_history.c create mode 100644 lib/mbuf/rte_mbuf_history.h

config/meson.build index renamed from config/meson.build +0 -0

55497f0bf5..d1f21f3115 100644

config/meson.build +1 -0
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)  endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG',
 get_option('enable_mbuf_history'))
 
 compile_time_cpuflags = []
 subdir(arch_subdir)
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d23c143eed..d0f6cd2582 100644

lib/ethdev/rte_ethdev.h +13 -0
@@ -6336,6 +6336,10 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t
 queue_id,
 
      nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+     rte_mbuf_history_bulk(rx_pkts, nb_rx, RTE_MBUF_APP_RX); #endif
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
      {
              void *cb;
@@ -6688,8 +6692,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t
 queue_id,
      }
 #endif
 
+#if RTE_MBUF_HISTORY_DEBUG
+     uint16_t requested_pkts = nb_pkts;
+     rte_mbuf_history_bulk(tx_pkts, nb_pkts, RTE_MBUF_PMD_TX); #endif
+
      nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+     if (requested_pkts > nb_pkts)
+             rte_mbuf_history_bulk(tx_pkts + nb_pkts,
+                                  requested_pkts - nb_pkts,
 RTE_MBUF_BUSY_TX);
+#endif
+
      rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts,
nb_pkts);
      return nb_pkts;

}

lib/mbuf/meson.build index renamed from lib/mbuf/meson.build +0 -0

0435c5e628..2c840ee2f2 100644

lib/mbuf/meson.build +2 -0
@@ -6,6 +6,7 @@ sources = files(
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
         'rte_mbuf_dyn.c',
+        'rte_mbuf_history.c',
 )
 headers = files(
         'rte_mbuf.h',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c index renamed from lib/mbuf/rte_mbuf.c +0 -0

9e7731a8a2..362dd252bc 100644

lib/mbuf/rte_mbuf.c +0 -0
@@ -281,6 +281,10 @@ rte_pktmbuf_pool_create(const char *name,
 unsigned int n,
      unsigned int cache_size, uint16_t priv_size, uint16_t
 data_room_size,
      int socket_id)
 {
Quoted 9 lines

lib/mbuf/rte_mbuf.c rte_pktmbuf_pool_create(const char *name, unsigned int n, · line 287

Quoted 5 lines
lib/mbuf/rte_mbuf.c +4 -0
+#if RTE_MBUF_HISTORY_DEBUG
+             if (rte_mbuf_history_init() < 0)
+                     RTE_LOG(ERR, MBUF, "Failed to enable mbuf
 history\n");
+#endif

rte_mbuf_history_init() must be called from all mbuf library functions to create a pktmbuf_pool.

Will update

Quoted 107 lines
Quoted 99 lines

return rte_pktmbuf_pool_create_by_ops(name, n, cache_size,
priv_size,

                      data_room_size, socket_id, NULL);  } @@ -516,8
+520,12 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs,
unsigned int count)
              } while (m != NULL);
      }
lib/mbuf/rte_mbuf.c +4 -1
-     if (nb_pending > 0)
+     if (nb_pending > 0) {
+#if RTE_MBUF_HISTORY_DEBUG
+             rte_mbuf_history_bulk(pending, nb_pending,
+RTE_MBUF_FREE); #endif
              rte_mempool_put_bulk(pending[0]->pool, (void **)pending,

nb_pending);

lib/mbuf/rte_mbuf.c +1 -0
+     }
 }
 
 /* Creates a shallow copy of mbuf */
lib/mbuf/rte_mbuf.h index renamed from lib/mbuf/rte_mbuf.h +0 -0

06ab7502a5..8126f09de4 100644

lib/mbuf/rte_mbuf.h +3 -0
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include "rte_mbuf_history.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,9 @@ static inline struct rte_mbuf
 *rte_mbuf_raw_alloc(struct rte_mempool *mp)
      if (rte_mempool_get(mp, &ret.ptr) < 0)
              return NULL;
      __rte_mbuf_raw_sanity_check(ret.m);
+#if RTE_MBUF_HISTORY_DEBUG
+     rte_mbuf_history_mark(ret.m, RTE_MBUF_ALLOC); #endif
      return ret.m;
 }
@@ -642,9 +646,14 @@ static __rte_always_inline int

rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf

**mbufs, unsigned int count)  {
      int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
lib/mbuf/rte_mbuf.h +9 -2
-     if (likely(rc == 0))
-             for (unsigned int idx = 0; idx < count; idx++)
+     if (likely(rc == 0)) {
+             for (unsigned int idx = 0; idx < count; idx++) {
                      __rte_mbuf_raw_sanity_check(mbufs[idx]);
+#if RTE_MBUF_HISTORY_DEBUG
+                     rte_mbuf_history_mark(mbufs[idx],
+RTE_MBUF_ALLOC); #endif
+             }
+     }
      return rc;
 }
@@ -667,6 +676,9 @@ rte_mbuf_raw_free(struct rte_mbuf *m)  {
      __rte_mbuf_raw_sanity_check(m);
      rte_mempool_put(m->pool, m);
+#if RTE_MBUF_HISTORY_DEBUG
+     rte_mbuf_history_mark(m, RTE_MBUF_FREE); #endif
 }
 
 /**
@@ -701,6 +713,9 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp,

struct rte_mbuf **mbufs, unsigned

              RTE_ASSERT(m != NULL);
              RTE_ASSERT(m->pool == mp);
              __rte_mbuf_raw_sanity_check(m);
lib/mbuf/rte_mbuf.h +3 -0
+#if RTE_MBUF_HISTORY_DEBUG
+             rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_FREE); #endif
      }
 
      rte_mempool_put_bulk(mp, (void **)mbufs, count); @@ -1013,6
+1028,10 @@ static inline int rte_pktmbuf_alloc_bulk(struct

rte_mempool *pool,

      if (unlikely(rc))
              return rc;
lib/mbuf/rte_mbuf.h +3 -0
+#if RTE_MBUF_HISTORY_DEBUG
+     rte_mbuf_history_bulk(mbufs, count, RTE_MBUF_ALLOC); #endif
+
      /* To understand duff's device on loop unwinding optimization,

see
* https://en.wikipedia.org/wiki/Duff's_device.
* Here while() loop is used rather than do() while{} to avoid
extra diff --git a/lib/mbuf/rte_mbuf_dyn.h b/lib/mbuf/rte_mbuf_dyn.h index 865c90f579..8ae31b4e65 100644

lib/mbuf/rte_mbuf_dyn.h +3 -0
@@ -240,6 +240,13 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking for
+mbuf
Quoted 6 lines

objects through the system.
+ * It records a fixed set of predefined operations to maintain performance
+ * while providing debugging capabilities.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME

"rte_mbuf_dynfield_history"

Quoted 6 lines

Suggest you also define the mbuf history type here:
typedef uint64_t rte_mbuf_history_t;

Or even better, to support cloned mbufs accessed simultaneously by multiple lcores:
typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;

Yes make sense I'll add this

Quoted 106 lines

<feature creep>
It could be uint32_t on 32 bit architectures, for performance. </feature creep>

Quoted 86 lines

+
/*
* The metadata dynamic field provides some extra packet information
* to interact with RTE Flow engine. The metadata in sent mbufs can
be diff --git a/lib/mbuf/rte_mbuf_history.c b/lib/mbuf/rte_mbuf_history.c new file mode 100644 index 0000000000..5be56289ca

lib/mbuf/rte_mbuf_history.c new file +27 -0
@@ -0,0 +1,181 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates  */
+
+#include <rte_mbuf_history.h>
+#include <rte_mbuf_dyn.h>
+#include <rte_log.h>
+#include <rte_errno.h>
+#include <eal_export.h>
+#include <rte_mempool.h>
+#include <rte_tailq.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+/* Global offset for the history field */ int
+rte_mbuf_history_field_offset = -1;
+RTE_EXPORT_SYMBOL(rte_mbuf_history_field_offset);
+
+#if RTE_MBUF_HISTORY_DEBUG
+/* Dynamic field definition for mbuf history */ static const struct
+rte_mbuf_dynfield mbuf_dynfield_history = {
+     .name = RTE_MBUF_DYNFIELD_HISTORY_NAME,
+     .size = sizeof(uint64_t),
+     .align = RTE_ALIGN(sizeof(uint64_t), 8), };
+
+/* Context structure for combined statistics counting and mbuf
+history

printing */

lib/mbuf/rte_mbuf_history.c new file +7 -0
+struct count_and_print_ctx {
+     uint64_t *stats;
+     FILE *f;
+};
+
+static void
+mbuf_history_count_stats_and_print(struct rte_mempool *mp

__rte_unused, void *opaque,

lib/mbuf/rte_mbuf_history.c new file +3 -0
+                                     void *obj, unsigned obj_idx
+__rte_unused) {
+     struct count_and_print_ctx *ctx = (struct count_and_print_ctx

*)opaque;

lib/mbuf/rte_mbuf_history.c new file +5 -0
+
+     struct rte_mbuf *mbuf = (struct rte_mbuf *)obj;
+
+     if (obj == NULL || ctx == NULL || ctx->stats == NULL || ctx->f
+ ==

NULL)

lib/mbuf/rte_mbuf_history.c new file +30 -0
+             return;
+
+     /* Get mbuf history */
+     uint64_t history = rte_mbuf_history_get(mbuf);
+
+     ctx->stats[0]++; /* n_total */
+
+     if (history == 0) {
+             ctx->stats[1]++; /* n_never */
+             return;
+     }
+
+     /* Extract the most recent operation */
+     uint64_t op = history & RTE_MBUF_HISTORY_MASK;
+
+     switch (op) {
+     case RTE_MBUF_FREE:
+             ctx->stats[2]++; /* n_free */
+             break;
+     case RTE_MBUF_PMD_FREE:
+             ctx->stats[3]++; /* n_pmd_free */
+             break;
+     case RTE_MBUF_PMD_TX:
+             ctx->stats[4]++; /* n_pmd_tx */
+             break;
+     case RTE_MBUF_APP_RX:
+             ctx->stats[5]++; /* n_app_rx */
+             break;
+     case RTE_MBUF_PMD_ALLOC:
+             ctx->stats[6]++; /* n_pmd_alloc */

lib/mbuf/rte_mbuf_history.c line 82

Quoted 10 lines
lib/mbuf/rte_mbuf_history.c new file +10 -0
+             break;
+     case RTE_MBUF_ALLOC:
+             ctx->stats[7]++; /* n_alloc */
+             break;
+     case RTE_MBUF_BUSY_TX:
+             ctx->stats[8]++; /* n_busy_tx */
+             break;
+     default:
+             break;
+     }

Intead of using stats[9], use stats[RTE_MBUF_HISTORY_OP_MAX]. Then your switch/case can be replaced by a simple one-liner:
ctx->stats[op]++;

Quoted 2 lines

This can also handle future history operation types not yet defined in the enumeration of operations.

Yes good idea I'll fix it

Quoted 170 lines
Quoted 4 lines
lib/mbuf/rte_mbuf_history.c new file +3 -0
+
+     /* Print the mbuf history value */
+     fprintf(ctx->f, "mbuf %p: %016" PRIX64 "\n", mbuf, history);

lib/mbuf/rte_mbuf_history.c line 96

Quoted 10 lines
lib/mbuf/rte_mbuf_history.c new file +10 -0
+
+}
+
+static void
+mbuf_history_get_stat(struct rte_mempool *mp, void *arg) {
+     FILE *f = (FILE *)arg;
+     uint64_t stats[9] = {0};
+
+     if (f == NULL)
+             return;

It would be nice if mempools can somehow be marked with the type of objects they hold, or at least can be marked that they hold mbufs. One simple way could be prefixing the mempool name with "MBUF_" when the mbuf library calls the mempool library to create a mempool.

Then this function can skip mempools holding other objects than mbufs.

Quoted 30 lines
lib/mbuf/rte_mbuf_history.c new file +9 -0
+
+     /* Output mempool header */
+     fprintf(f, "=== Mempool: %s ===\n", mp->name);
+
+     /* Create context structure for combined counting and printing */
+     struct count_and_print_ctx ctx = { .stats = stats, .f = f };
+
+     /* Single pass: collect statistics and print mbuf history */
+     rte_mempool_obj_iter(mp, mbuf_history_count_stats_and_print,

&ctx);

lib/mbuf/rte_mbuf_history.c new file +19 -0
+
+     /* Calculate total allocated mbufs */
+     uint64_t total_allocated = stats[3] + stats[4] + stats[5] +
+     stats[6] + stats[7] + stats[8];
+
+     /* Print statistics summary */
+     fprintf(f, "\n"
+             "Populated:       %u\n"
+             "Never allocated: %" PRIu64 "\n"
+             "Free:            %" PRIu64 "\n"
+             "Allocated:       %" PRIu64 "\n"
+             "PMD owned Tx:    %" PRIu64 "\n"
+             "PMD owned Rx:    %" PRIu64 "\n"
+             "App owned alloc: %" PRIu64 "\n"
+             "App owned Rx:    %" PRIu64 "\n"
+             "App owned busy:  %" PRIu64 "\n"
+             "Counted total:   %" PRIu64 "\n",
+             mp->populated_size, stats[1], stats[2], total_allocated,
+             stats[4], stats[6], stats[7], stats[5], stats[8],

stats[0]);

lib/mbuf/rte_mbuf_history.c

Quoted 2 lines
lib/mbuf/rte_mbuf_history.c new file +2 -0
+
+     fprintf(f, "---\n");

Please follow the convention of other "dump" functions, e.g. like rte_mempool_dump():
- Use hierarchical indentation
- Use " value=%" PRIu64 "\n".

lib/mbuf/rte_mbuf_history.c line 130

Quoted 4 lines
lib/mbuf/rte_mbuf_history.c new file +4 -0
+}
+#endif
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump, 25.11)

#if

Quoted 90 lines
lib/mbuf/rte_mbuf_history.c new file +8 -0
+RTE_MBUF_HISTORY_DEBUG void rte_mbuf_history_dump(FILE *f) {
+     if (f == NULL) {
+             RTE_LOG(ERR, MBUF, "Invalid file pointer\n");
+             return;
+     }
+
+     fprintf(f, "=== MBUF History Statistics ===\n");
+     fprintf(f, "Dumping complete mbuf history for all

mempools...\n");

lib/mbuf/rte_mbuf_history.c new file +4 -0
+
+     /* Check if mbuf history is initialized */
+     if (rte_mbuf_history_field_offset == -1) {
+             fprintf(f, "WARNING: MBUF history not initialized. Call

rte_mbuf_history_init() first.\n\n");

lib/mbuf/rte_mbuf_history.c new file +14 -0
+             return;
+     }
+
+     /* Use rte_mempool_walk to iterate over all mempools */
+     rte_mempool_walk(mbuf_history_get_stat, f); }
+
+int rte_mbuf_history_init(void)
+{
+     if (rte_mbuf_history_field_offset != -1) {
+             /* Already initialized */
+             return 0;
+     }
+
+     rte_mbuf_history_field_offset =

rte_mbuf_dynfield_register(&mbuf_dynfield_history);

lib/mbuf/rte_mbuf_history.c new file +3 -0
+     if (rte_mbuf_history_field_offset < 0) {
+             RTE_LOG(ERR, MBUF, "Failed to register mbuf history
+ dynamic

field: %s\n",

lib/mbuf/rte_mbuf_history.c new file +20 -0
+                     rte_strerror(rte_errno));
+             return -1;
+     }
+     return 0;
+}
+#else
+void rte_mbuf_history_dump(FILE *f)
+{
+     RTE_SET_USED(f);
+     RTE_LOG(INFO, MBUF, "Mbuf history recorder is not supported\n");
+}
+
+int rte_mbuf_history_init(void)
+{
+     rte_errno = ENOTSUP;
+     return -1;
+}
+#endif
+RTE_EXPORT_SYMBOL(rte_mbuf_history_init);
+RTE_EXPORT_SYMBOL(rte_mbuf_history_dump);
lib/mbuf/rte_mbuf_history.h new file +11 -0
new file mode 100644 index 0000000000..4448ad1557
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates  */
+
+#ifndef _RTE_MBUF_HISTORY_H_
+#define _RTE_MBUF_HISTORY_H_
+
+/**
+ * @file
+ * MBUF History
+ *
+ * This module provides history tracking for mbuf objects using

dynamic fields.
+ * It tracks the lifecycle of mbuf objects through the system with a fixed set
+ * of predefined events to maintain performance.
+ *
+ * The history is stored as a 64-bit value in the mbuf dynamic field area,
+ * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
+ */

lib/mbuf/rte_mbuf_history.h new file +11 -0
+
+#include <stdint.h>
+#include <rte_mbuf_dyn.h>
+#include <rte_common.h>
+#include <rte_branch_prediction.h>
+#include "mbuf_log.h"
+
+/* Forward declaration to avoid circular dependency */ struct
+rte_mbuf;
+
+#ifdef __cplusplus

lib/mbuf/rte_mbuf_history.h line 41

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +10 -0
+extern "C" {
+#endif
+
+/**
+ * Number of bits for each history operation  */
+#define RTE_MBUF_HISTORY_BITS          4
+
+/**
+ * Maximum number of history operations that can be stored  */
+#define RTE_MBUF_HISTORY_MAX_OPS       16

Suggest:
#define RTE_MBUF_HISTORY_MAX_OPS (sizeof(rte_mbuf_history_t) * 8 / RTE_MBUF_HISTORY_BITS)

Quoted 15 lines

lib/mbuf/rte_mbuf_history.h line 51

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +4 -0
+
+/**
+ * Mask for extracting the most recent operation from history  */
+#define RTE_MBUF_HISTORY_MASK          ((1ULL <<

RTE_MBUF_HISTORY_BITS) - 1)

lib/mbuf/rte_mbuf_history.h new file +5 -0
+
+/**
+ * History operation types
+ */
+enum rte_mbuf_history_op {

These values should be prefixed RTE_MBUF_HISTORY_OP_ or RTE_MBUF_HISTORY_ or something similar.
Also, naming should be hierarchical. Suggest:

Make sense, I'll rename it

Quoted 102 lines
Quoted 1 line

+ RTE_MBUF_NEVER = 0, /* Initial state - never allocated */

RTE_MBUF_HISTORY_OP_NEVER

Quoted 1 line

+ RTE_MBUF_FREE = 1, /* Freed back to pool */

RTE_MBUF_HISTORY_OP_FREE

Quoted 1 line

+ RTE_MBUF_PMD_FREE = 2, /* Freed by PMD back to pool*/

RTE_MBUF_HISTORY_OP_PMD_FREE

Quoted 1 line

+ RTE_MBUF_PMD_TX = 3, /* Sent to PMD for Tx */

RTE_MBUF_HISTORY_OP_PMD_TX

Quoted 1 line

+ RTE_MBUF_APP_RX = 4, /* Returned to application on Rx */

RTE_MBUF_HISTORY_OP_PMD_RX

Quoted 1 line

+ RTE_MBUF_PMD_ALLOC = 5, /* Allocated by PMD for Rx */

RTE_MBUF_HISTORY_OP_PMD_RX_ALLOC

Quoted 1 line

+ RTE_MBUF_ALLOC = 6, /* Allocated by application */

RTE_MBUF_HISTORY_OP_ALLOC

Quoted 1 line

+ RTE_MBUF_BUSY_TX = 7, /* Returned to app due to Tx busy */

RTE_MBUF_HISTORY_OP_PMD_TX_BUSY

Quoted 30 lines
lib/mbuf/rte_mbuf_history.h new file +15 -0
+     RTE_MBUF_USR3 = 13,        /* Application-defined event 3 */
+     RTE_MBUF_USR2 = 14,        /* Application-defined event 2 */
+     RTE_MBUF_USR1 = 15,        /* Application-defined event 1 */
+     RTE_MBUF_MAX = 16,          /* Maximum trace operation value */
+};
+
+
+/**
+ * Global offset for the history field (set during initialization)
+*/ extern int rte_mbuf_history_field_offset;
+
+/**
+ * Initialize the mbuf history system
+ *
+ * This function registers the dynamic field for mbuf history

tracking.
+ * It should be called once during application initialization.
+ *
+ * Note: This function is called by rte_pktmbuf_pool_create,
+ * so explicit invocation is usually not required unless initializing manually.
+ *
+ * @return
+ * 0 on success, -1 on failure with rte_errno set
+ */

lib/mbuf/rte_mbuf_history.h new file +5 -0
+int rte_mbuf_history_init(void);
+
+#if RTE_MBUF_HISTORY_DEBUG
+/**
+ * Get the history value from an mbuf

lib/mbuf/rte_mbuf_history.h line 98

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +10 -0
+ *
+ * @param m
+ *   Pointer to the mbuf
+ * @return
+ *   The history value, or 0 if history is not available
+ */
+static inline uint64_t rte_mbuf_history_get(const struct rte_mbuf *m)
+{
+     if (unlikely(m == NULL || rte_mbuf_history_field_offset == -1))
+             return 0;

These are fast path, so don't validate params at runtime. Suggest:

    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
        if (unlikely(m == NULL))
                return 0;
Quoted 3 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+
+     return *RTE_MBUF_DYNFIELD(m, rte_mbuf_history_field_offset,

uint64_t *);

Mbufs may be cloned, so this should be an atomic operation.

Quoted 14 lines
lib/mbuf/rte_mbuf_history.h new file +11 -0
+}
+
+/**
+ * Mark an mbuf with a history event
+ *
+ * @param m
+ *   Pointer to the mbuf
+ * @param op
+ *   The operation to record
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t

op)

lib/mbuf/rte_mbuf_history.h new file +2 -0
+{
+     if (unlikely(m == NULL || op >= RTE_MBUF_MAX ||
Quoted 2 lines

rte_mbuf_history_field_offset == -1))
+ return;

These are fast path, so don't validate params at runtime. Suggest:

Quoted 5 lines
    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
    RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
        if (unlikely(m == NULL))
                return 0;

Sure

Quoted 77 lines
Quoted 4 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+
+     uint64_t *history = RTE_MBUF_DYNFIELD(m,

rte_mbuf_history_field_offset, uint64_t *);
+ *history = (*history << RTE_MBUF_HISTORY_BITS) | op;

Mbufs may be cloned, so this should be an atomic operation.

Quoted 13 lines
lib/mbuf/rte_mbuf_history.h new file +13 -0
+}
+
+/**
+ * Mark multiple mbufs with a history event
+ *
+ * @param mbufs
+ *   Array of mbuf pointers
+ * @param n
+ *   Number of mbufs to mark
+ * @param op
+ *   The operation to record
+ */
+static inline void rte_mbuf_history_bulk(struct rte_mbuf * const
Quoted 2 lines

*mbufs,
+ uint32_t n, uint32_t op)

rte_mbuf_history_bulk() -> rte_mbuf_history_mark_bulk()

Quoted 4 lines
lib/mbuf/rte_mbuf_history.h new file +2 -0
+{
+     if (unlikely(mbufs == NULL || op >= RTE_MBUF_MAX ||

rte_mbuf_history_field_offset == -1))
+ return;

These are fast path, so don't validate params at runtime. Suggest:

    RTE_ASSERT(rte_mbuf_history_field_offset != -1);
    RTE_ASSERT(mbufs != NULL);
    RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);

lib/mbuf/rte_mbuf_history.h line 148

Quoted 12 lines
lib/mbuf/rte_mbuf_history.h new file +12 -0
+
+     while (n--)
+             rte_mbuf_history_mark(*mbufs++, op); } #endif
+
+/**
+ * Dump mbuf history statistics for all mempools to a file
+ *
+ * @param f
+ *   File pointer to write the history statistics to
+ */
+__rte_experimental
+void rte_mbuf_history_dump(FILE *f);

<feature creep>
It would be nice to expose three dump functions:
1) dump the history of one mbuf:
void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf * mbuf);
2) dump the history of one mbuf pool, and void rte_mbuf_history_dump_mempool(FILE *f, const struct rte_mempool * mp);
3) dump the history of all mbuf pools.
void rte_mbuf_history_dump_all(FILE *f); <feature creep>

Quoted 20 lines
lib/mbuf/rte_mbuf_history.h new file +6 -0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_MBUF_HISTORY_H_ */
meson_options.txt index renamed from meson_options.txt +0 -0

e49b2fc089..48f6d4a9a5 100644

meson_options.txt +0 -0
@@ -16,6 +16,8 @@ option('drivers_install_subdir', type: 'string',

value: 'dpdk/pmds-<VERSION>', d
'Subdirectory of libdir where to install PMDs. Defaults to
using a versioned subdirectory.') option('enable_docs', type:
'boolean', value: false, description:
'build documentation')
+option('enable_mbuf_history', type: 'boolean', value: false, description:
+ 'Enable mbuf history tracking for debugging purposes. This
+ will

Quoted 8 lines
Quoted 8 lines

track mbufs allocation and free operations. Default is false.') option('enable_apps', type: 'string', value: '', description:
'Comma-separated list of apps to build. If unspecified, build
all apps.') option('enable_deprecated_libs', type: 'string', value:
'',
description:
--
2.34.1

Thanks for the detailed review! I'll fix it and send an update!

#21 lore raw

PATCH v2 2/4 net/mlx5: mark an operation in mbuf's history

In reply to Shani Peretz

record operations on mbufs when it is allocated
and released inside the mlx5 PMD.

---
 drivers/net/mlx5/mlx5_rx.c       | 25 +++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_rx.h       |  6 ++++++
 drivers/net/mlx5/mlx5_rxq.c      | 15 +++++++++++++--
 drivers/net/mlx5/mlx5_rxtx_vec.c | 16 ++++++++++++++++
 drivers/net/mlx5/mlx5_tx.h       | 21 +++++++++++++++++++++
 drivers/net/mlx5/mlx5_txq.c      |  3 +++
 6 files changed, 84 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5_rx.c +25 -0
index 420a03068d..4e44892d93 100644
@@ -640,12 +640,19 @@ mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec,
 					elt_idx = (elts_ci + i) & e_mask;
 					elt = &(*rxq->elts)[elt_idx];
 					*elt = rte_mbuf_raw_alloc(rxq->mp);
+#if RTE_MBUF_HISTORY_DEBUG
+					rte_mbuf_history_mark(*elt, RTE_MBUF_PMD_ALLOC);
+#endif
 					if (!*elt) {
 						for (i--; i >= 0; --i) {
 							elt_idx = (elts_ci +
 								   i) & elts_n;
 							elt = &(*rxq->elts)
 								[elt_idx];
+#if RTE_MBUF_HISTORY_DEBUG
+							rte_mbuf_history_mark(*elt,
+								RTE_MBUF_PMD_FREE);
+#endif
 							rte_pktmbuf_free_seg
 								(*elt);
 						}
@@ -1048,6 +1055,9 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rte_prefetch0(wqe);
 		/* Allocate the buf from the same pool. */
 		rep = rte_mbuf_raw_alloc(seg->pool);
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(rep, RTE_MBUF_PMD_ALLOC);
+#endif
 		if (unlikely(rep == NULL)) {
 			++rxq->stats.rx_nombuf;
 			if (!pkt) {
@@ -1062,6 +1072,9 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 				rep = NEXT(pkt);
 				NEXT(pkt) = NULL;
 				NB_SEGS(pkt) = 1;
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(pkt, RTE_MBUF_PMD_FREE);
+#endif
 				rte_mbuf_raw_free(pkt);
 				pkt = rep;
 			}
@@ -1076,6 +1089,9 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 					       &mcqe, &skip_cnt, false, NULL);
 			if (unlikely(len & MLX5_ERROR_CQE_MASK)) {
 				/* We drop packets with non-critical errors */
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(rep, RTE_MBUF_PMD_FREE);
+#endif
 				rte_mbuf_raw_free(rep);
 				if (len == MLX5_CRITICAL_ERROR_CQE_RET) {
 					rq_ci = rxq->rq_ci << sges_n;
@@ -1089,6 +1105,9 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 				continue;
 			}
 			if (len == 0) {
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(rep, RTE_MBUF_PMD_FREE);
+#endif
 				rte_mbuf_raw_free(rep);
 				break;
 			}
@@ -1540,6 +1559,9 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 			++rxq->stats.rx_nombuf;
 			break;
 		}
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(pkt, RTE_MBUF_PMD_ALLOC);
+#endif
 		len = (byte_cnt & MLX5_MPRQ_LEN_MASK) >> MLX5_MPRQ_LEN_SHIFT;
 		MLX5_ASSERT((int)len >= (rxq->crc_present << 2));
 		if (rxq->crc_present)
@@ -1547,6 +1569,9 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rxq_code = mprq_buf_to_pkt(rxq, pkt, len, buf,
 					   strd_idx, strd_cnt);
 		if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(pkt, RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(pkt);
 			if (rxq_code == MLX5_RXQ_CODE_DROPPED) {
 				++rxq->stats.idropped;
drivers/net/mlx5/mlx5_rx.h +6 -0
index 7be31066a5..075b4bfc4b 100644
@@ -525,6 +525,9 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
 
 				if (unlikely(next == NULL))
 					return MLX5_RXQ_CODE_NOMBUF;
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(next, RTE_MBUF_PMD_ALLOC);
+#endif
 				NEXT(prev) = next;
 				SET_DATA_OFF(next, 0);
 				addr = RTE_PTR_ADD(addr, seg_len);
@@ -588,6 +591,9 @@ mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
 
 			if (unlikely(seg == NULL))
 				return MLX5_RXQ_CODE_NOMBUF;
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(seg, RTE_MBUF_PMD_ALLOC);
+#endif
 			SET_DATA_OFF(seg, 0);
 			rte_memcpy(rte_pktmbuf_mtod(seg, void *),
 				RTE_PTR_ADD(addr, len - hdrm_overlap),
drivers/net/mlx5/mlx5_rxq.c +13 -2
index aeefece8c1..434a57ca32 100644
@@ -164,6 +164,9 @@ rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 			rte_errno = ENOMEM;
 			goto error;
 		}
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(buf, RTE_MBUF_PMD_ALLOC);
+#endif
 		/* Only vectored Rx routines rely on headroom size. */
 		MLX5_ASSERT(!has_vec_support ||
 			    DATA_OFF(buf) >= RTE_PKTMBUF_HEADROOM);
@@ -221,8 +224,12 @@ rxq_alloc_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 	err = rte_errno; /* Save rte_errno before cleanup. */
 	elts_n = i;
 	for (i = 0; (i != elts_n); ++i) {
-		if ((*rxq_ctrl->rxq.elts)[i] != NULL)
+		if ((*rxq_ctrl->rxq.elts)[i] != NULL) {
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark((*rxq_ctrl->rxq.elts)[i], RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg((*rxq_ctrl->rxq.elts)[i]);
+		}
 		(*rxq_ctrl->rxq.elts)[i] = NULL;
 	}
 	if (rxq_ctrl->share_group == 0)
@@ -324,8 +331,12 @@ rxq_free_elts_sprq(struct mlx5_rxq_ctrl *rxq_ctrl)
 		rxq->rq_pi = elts_ci;
 	}
 	for (i = 0; i != q_n; ++i) {
-		if ((*rxq->elts)[i] != NULL)
+		if ((*rxq->elts)[i] != NULL) {
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark((*rxq->elts)[i], RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg((*rxq->elts)[i]);
+		}
 		(*rxq->elts)[i] = NULL;
 	}
 }
drivers/net/mlx5/mlx5_rxtx_vec.c +16 -0
index 1b701801c5..c7ca808f43 100644
@@ -63,6 +63,9 @@ rxq_handle_pending_error(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
 		if (pkt->packet_type == RTE_PTYPE_ALL_MASK || rxq->err_state) {
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			err_bytes += PKT_LEN(pkt);
+#endif
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(pkt, RTE_MBUF_PMD_FREE);
 #endif
 			rte_pktmbuf_free_seg(pkt);
 		} else {
@@ -107,6 +110,9 @@ mlx5_rx_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
 			rxq->stats.rx_nombuf += n;
 			return;
 		}
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_bulk(elts, n, RTE_MBUF_PMD_ALLOC);
+#endif
 		if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1)) {
 			for (i = 0; i < n; ++i) {
 				/*
@@ -171,6 +177,9 @@ mlx5_rx_mprq_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq)
 			rxq->stats.rx_nombuf += n;
 			return;
 		}
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_bulk(elts, n, RTE_MBUF_PMD_ALLOC);
+#endif
 		rxq->elts_ci += n;
 		/* Prevent overflowing into consumed mbufs. */
 		elts_idx = rxq->elts_ci & wqe_mask;
@@ -224,6 +233,9 @@ rxq_copy_mprq_mbuf_v(struct mlx5_rxq_data *rxq,
 
 		if (!elts[i]->pkt_len) {
 			rxq->consumed_strd = strd_n;
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(elts[i], RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(elts[i]);
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			rxq->stats.ipackets -= 1;
@@ -236,6 +248,9 @@ rxq_copy_mprq_mbuf_v(struct mlx5_rxq_data *rxq,
 					   buf, rxq->consumed_strd, strd_cnt);
 		rxq->consumed_strd += strd_cnt;
 		if (unlikely(rxq_code != MLX5_RXQ_CODE_EXIT)) {
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(elts[i], RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(elts[i]);
 #ifdef MLX5_PMD_SOFT_COUNTERS
 			rxq->stats.ipackets -= 1;
@@ -586,6 +601,7 @@ mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rte_io_wmb();
 		*rxq->cq_db = rte_cpu_to_be_32(rxq->cq_ci);
 	} while (tn != pkts_n);
+
 	return tn;
 }
 
drivers/net/mlx5/mlx5_tx.h +21 -0
index 16307206e2..c3d69942a8 100644
@@ -555,6 +555,9 @@ mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
 	if (!MLX5_TXOFF_CONFIG(MULTI) && txq->fast_free) {
 		mbuf = *pkts;
 		pool = mbuf->pool;
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_bulk(pkts, pkts_n, RTE_MBUF_PMD_FREE);
+#endif
 		rte_mempool_put_bulk(pool, (void *)pkts, pkts_n);
 		return;
 	}
@@ -610,6 +613,9 @@ mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
 			 * Free the array of pre-freed mbufs
 			 * belonging to the same memory pool.
 			 */
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_bulk(p_free, n_free, RTE_MBUF_PMD_FREE);
+#endif
 			rte_mempool_put_bulk(pool, (void *)p_free, n_free);
 			if (unlikely(mbuf != NULL)) {
 				/* There is the request to start new scan. */
@@ -1225,6 +1231,9 @@ mlx5_tx_mseg_memcpy(uint8_t *pdst,
 			/* Exhausted packet, just free. */
 			mbuf = loc->mbuf;
 			loc->mbuf = mbuf->next;
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(mbuf, RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(mbuf);
 			loc->mbuf_off = 0;
 			MLX5_ASSERT(loc->mbuf_nseg > 1);
@@ -1267,6 +1276,9 @@ mlx5_tx_mseg_memcpy(uint8_t *pdst,
 				/* Exhausted packet, just free. */
 				mbuf = loc->mbuf;
 				loc->mbuf = mbuf->next;
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(mbuf, RTE_MBUF_PMD_FREE);
+#endif
 				rte_pktmbuf_free_seg(mbuf);
 				loc->mbuf_off = 0;
 				MLX5_ASSERT(loc->mbuf_nseg >= 1);
@@ -1717,6 +1729,9 @@ mlx5_tx_mseg_build(struct mlx5_txq_data *__rte_restrict txq,
 			/* Zero length segment found, just skip. */
 			mbuf = loc->mbuf;
 			loc->mbuf = loc->mbuf->next;
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(mbuf, RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(mbuf);
 			if (--loc->mbuf_nseg == 0)
 				break;
@@ -2020,6 +2035,9 @@ mlx5_tx_packet_multi_send(struct mlx5_txq_data *__rte_restrict txq,
 			wqe->cseg.sq_ds -= RTE_BE32(1);
 			mbuf = loc->mbuf;
 			loc->mbuf = mbuf->next;
+#if RTE_MBUF_HISTORY_DEBUG
+			rte_mbuf_history_mark(mbuf, RTE_MBUF_PMD_FREE);
+#endif
 			rte_pktmbuf_free_seg(mbuf);
 			if (--nseg == 0)
 				break;
@@ -3319,6 +3337,9 @@ mlx5_tx_burst_single_send(struct mlx5_txq_data *__rte_restrict txq,
 				 * Packet data are completely inlined,
 				 * free the packet immediately.
 				 */
+#if RTE_MBUF_HISTORY_DEBUG
+				rte_mbuf_history_mark(loc->mbuf, RTE_MBUF_PMD_FREE);
+#endif
 				rte_pktmbuf_free_seg(loc->mbuf);
 			} else if ((!MLX5_TXOFF_CONFIG(EMPW) ||
 				     MLX5_TXOFF_CONFIG(MPW)) &&
drivers/net/mlx5/mlx5_txq.c +3 -0
index 2aa2475a8a..445d1d62c4 100644
@@ -79,6 +79,9 @@ txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl)
 		struct rte_mbuf *elt = (*elts)[elts_tail & elts_m];
 
 		MLX5_ASSERT(elt != NULL);
+#if RTE_MBUF_HISTORY_DEBUG
+		rte_mbuf_history_mark(elt, RTE_MBUF_PMD_FREE);
+#endif
 		rte_pktmbuf_free_seg(elt);
 #ifdef RTE_LIBRTE_MLX5_DEBUG
 		/* Poisoning. */
Signature · 1 line
2.34.1
#22 lore raw

Re: [PATCH v2 2/4] net/mlx5: mark an operation in mbuf's history

Quoted 5 lines · On Tue, 16 Sep 2025 18:12:05 +0300 Shani Peretz <[email protected]> wrote:

record operations on mbufs when it is allocated
and released inside the mlx5 PMD.

---

If you are adding this to one driver, it means it should be done to all drivers. Which means it is creating lots of churn and testing.

For me, this amount of churn and #ifdef is not worth it. Think of a better way using some other mechanism.

#23 lore raw

Re: [PATCH v2 2/4] net/mlx5: mark an operation in mbuf's history

16/09/2025 23:14, Stephen Hemminger:

Quoted 6 lines
Quoted 3 lines · On Tue, 16 Sep 2025 18:12:05 +0300 Shani Peretz <[email protected]> wrote:

record operations on mbufs when it is allocated
and released inside the mlx5 PMD.

Quoted 6 lines
Quoted 2 lines

---

If you are adding this to one driver, it means it should be done to all drivers. Which means it is creating lots of churn and testing.

Why a new feature should be applied to all drivers? We never force a new feature to be implemented by all, it is impossible to do.

Quoted 1 line

For me, this amount of churn and #ifdef is not worth it.

I agree we could avoid the #ifdef with a dummy function which would be optimized out by the compiler.

Quoted 1 line

Think of a better way using some other mechanism.

Except avoiding the #ifdef, I don't see what better to do for tracking what the driver is doing with mbufs.

#24 lore raw

Re: [PATCH v2 2/4] net/mlx5: mark an operation in mbuf's history

Quoted 10 lines · On Tue, 16 Sep 2025 23:31:34 +0200 Thomas Monjalon <[email protected]> wrote:

16/09/2025 23:14, Stephen Hemminger:

Quoted 9 lines
Quoted 5 lines · On Tue, 16 Sep 2025 18:12:05 +0300 Shani Peretz <[email protected]> wrote:

record operations on mbufs when it is allocated
and released inside the mlx5 PMD.

---

Quoted 7 lines
Quoted 3 lines

If you are adding this to one driver, it means it should be done to all drivers. Which means it is creating lots of churn and testing.

Why a new feature should be applied to all drivers? We never force a new feature to be implemented by all, it is impossible to do.

It should at least be a reasonable subset of drivers. Doing it for only one device makes it much less usable. At a minimum need to cover the drivers that are commonly used and part of the CI test structure. It really isn't that hard for this history stuff to find where to put a few calls.

Also the obvious ones like null, ring, and any demo skeleton code.

Quoted 10 lines
Quoted 2 lines

For me, this amount of churn and #ifdef is not worth it.

I agree we could avoid the #ifdef with a dummy function which would be optimized out by the compiler.

Quoted 1 line

Think of a better way using some other mechanism.

Except avoiding the #ifdef, I don't see what better to do for tracking what the driver is doing with mbufs.

Tx and Rx burst could do one marking step.

#25 lore raw

PATCH v2 3/4 app/testpmd: add testpmd command to dump mbuf history

In reply to Shani Peretz

dumps the mbufs history to console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

testpmd> dump_mbuf_history
testpmd> dump_mbuf_history <file_name>

---
 app/test-pmd/cmdline.c | 60 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
app/test-pmd/cmdline.c +59 -1
index 3731fba370..7a1cba5094 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump_log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump_mbuf_history\n"
+			"    Dumps the mbuf history\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9177,6 +9181,8 @@ static void cmd_dump_parsed(void *parsed_result,
 #endif
 	else if (!strcmp(res->dump, "dump_log_types"))
 		rte_log_dump(stdout);
+	else if (!strcmp(res->dump, "dump_mbuf_history"))
+		rte_mbuf_history_dump(stdout);
 }
 
 static cmdline_parse_token_string_t cmd_dump_dump =
@@ -9198,7 +9204,8 @@ cmd_dump_init(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 		"dump_trace#"
 #endif
-		"dump_log_types";
+		"dump_log_types#"
+		"dump_mbuf_history";
 }
 
 static cmdline_parse_inst_t cmd_dump = {
@@ -9260,6 +9267,56 @@ static cmdline_parse_inst_t cmd_dump_one = {
 	},
 };
 
+/* Dump mbuf history to file */
+struct cmd_dump_mbuf_to_file_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_mbuf_to_file_parsed(void *parsed_result, struct cmdline *cl,
+				__rte_unused void *data)
+{
+	struct cmd_dump_mbuf_to_file_result *res = parsed_result;
+	FILE *file = stdout;
+	char *file_name = res->file;
+
+	if (strcmp(res->dump, "dump_mbuf_history")) {
+		cmdline_printf(cl, "Invalid dump type\n");
+		return;
+	}
+
+	if (file_name && strlen(file_name)) {
+		file = fopen(file_name, "w");
+		if (!file) {
+			rte_mbuf_history_dump(stdout);
+			return;
+		}
+	}
+	rte_mbuf_history_dump(file);
+	printf("Flow dump finished\n");
+	if (file_name && strlen(file_name))
+		fclose(file);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, dump,
+				 "dump_mbuf_history");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_to_file = {
+	.f = cmd_dump_mbuf_to_file_parsed,  /* function to call */
+	.data = NULL,      /* 2nd arg of func */
+	.help_str = "dump_mbuf_history <file_name>: Dump mbuf history to file",
+	.tokens = {        /* token list, NULL terminated */
+		(void *)&cmd_dump_mbuf_to_file_dump,
+		(void *)&cmd_dump_mbuf_to_file_file,
+		NULL,
+	},
+};
+
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13999,6 +14056,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump,
 	&cmd_dump_one,
+	&cmd_dump_mbuf_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
Signature · 1 line
2.34.1
#26 lore raw

PATCH v2 4/4 usertool: add a script to parse mbuf history dump

In reply to Shani Peretz

Added a Python script that parses the history dump of a mbufs generated by rte_mbuf_objects_dump and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 usertools/dpdk-mbuf_history_parser.py | 173 ++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100755 usertools/dpdk-mbuf_history_parser.py
usertools/dpdk-mbuf_history_parser.py new file +173 -0
new file mode 100755
index 0000000000..c39a796d5d
@@ -0,0 +1,173 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023 NVIDIA Corporation & Affiliates
+
+import sys
+import re
+import os
+import enum
+
+RED = "\033[91m"
+RESET = "\033[0m"
+ENUM_PATTERN = r'enum\s+rte_mbuf_history_op\s*{([^}]+)}'
+VALUE_PATTERN = r'([A-Z_]+)\s*=\s*(\d+),\s*(?:/\*\s*(.*?)\s*\*/)?'
+HEADER_FILE = os.path.join(
+    os.path.dirname(os.path.dirname(__file__)),
+    'lib/mbuf/rte_mbuf_history.h'
+)
+
+
+def print_history_sequence(address: str, sequence: list[str]):
+    max_op_width = max(
+        len(re.sub(r'\x1b\[[0-9;]*m', '', op)) for op in sequence
+    )
+    op_width = max_op_width
+    for i in range(0, len(sequence), 4):
+        chunk = sequence[i:i + 4]
+        formatted_ops = [f"{op:<{op_width}}" for op in chunk]
+        line = ""
+        for j, op in enumerate(formatted_ops):
+            line += op
+            if j < len(formatted_ops) - 1:
+                line += " -> "
+        if i + 4 < len(sequence):
+            line += " ->"
+        print(f"mbuf {address}: " + line)
+    print()
+
+
+def match_field(match: re.Match) -> tuple[int, str]:
+    name, value, _ = match.groups()
+    return (int(value), name.replace('RTE_MBUF_', ''))
+
+
+class HistoryEnum:
+    def __init__(self, ops: enum.Enum):
+        self.ops = ops
+
+    @staticmethod
+    def from_header(header_file: str) -> 'HistoryEnum':
+        with open(header_file, 'r') as f:
+            content = f.read()
+
+        # Extract each enum value and its comment
+        enum_content = re.search(ENUM_PATTERN, content, re.DOTALL).group(1)
+        fields = map(match_field, re.finditer(VALUE_PATTERN, enum_content))
+        fields = dict({v: k for k, v in fields})
+        return HistoryEnum(enum.Enum('HistoryOps', fields))
+
+
+class HistoryLine:
+    def __init__(self, address: str, ops: list):
+        self.address = address
+        self.ops = ops
+
+    def repeats(self) -> [list[str], str | None]:
+        repeated = None
+        sequence = []
+        for idx, op in enumerate(self.ops):
+            if idx > 0 and op == self.ops[idx - 1] and op.name != 'NEVER':
+                sequence[-1] = f"{RED}{op.name}{RESET}"
+                sequence.append(f"{RED}{op.name}{RESET}")
+                repeated = op.name
+            else:
+                sequence.append(op.name)
+        return sequence, repeated
+
+
+class HistoryMetrics:
+    def __init__(self, metrics: dict[str, int]):
+        self.metrics = metrics
+
+    def max_name_width(self) -> int:
+        return max(len(name) for name in self.metrics.keys())
+
+
+class HistoryParser:
+    def __init__(self):
+        self.history_enum = HistoryEnum.from_header(HEADER_FILE)
+
+    def parse(
+        self, dump_file: str
+    ) -> tuple[list[HistoryLine], 'HistoryMetrics']:
+        with open(dump_file, 'r') as f:
+            lines = [line for line in f.readlines() if line.strip()]
+            populated = next(line for line in lines if "Populated:" in line)
+            metrics_start = lines.index(populated)
+
+        history_lines = lines[3:metrics_start]
+        metrics_lines = lines[metrics_start:-1]
+        return (
+            self._parse_history(history_lines),
+            self._parse_metrics(metrics_lines)
+        )
+
+    def _parse_metrics(self, lines: list[str]) -> HistoryMetrics:
+        metrics = {}
+        for line in lines:
+            key, value = line.split(':', 1)
+            metrics[key] = int(value)
+        return HistoryMetrics(metrics)
+
+    def _parse_history(self, lines: list[str]) -> list[HistoryLine]:
+        # Parse the format "mbuf 0x1054b9980: 0000000000000065"
+        history_lines = []
+        for line in lines:
+            address = line.split(':')[0].split('mbuf ')[1]
+            history = line.split(':')[1]
+            history_lines.append(
+                HistoryLine(
+                    address=address,
+                    ops=self._parse(int(history, 16))
+                )
+            )
+        return history_lines
+
+    def _parse(self, history: int) -> list[str]:
+        ops = []
+        for _ in range(16):  # 64 bits / 4 bits = 16 possible operations
+            op = history & 0xF  # Extract lowest 4 bits
+            if op == 0:
+                break
+            ops.append(self.history_enum.ops(op))
+            history >>= 4
+
+        ops.reverse()
+        return ops
+
+
+def print_history_lines(history_lines: list[HistoryLine]):
+    lines = [
+        (line.address, line.repeats()) for line in history_lines
+    ]
+
+    for address, (sequence, _) in lines:
+        print_history_sequence(address, sequence)
+
+    print("=== Violations ===")
+    for address, (sequence, repeated) in lines:
+        if repeated:
+            print(f"mbuf {address} has repeated ops: {RED}{repeated}{RESET}")
+
+
+def print_metrics(metrics: HistoryMetrics):
+    print("=== Metrics Summary ===")
+    for name, value in metrics.metrics.items():
+        print(f"{name + ':':<{metrics.max_name_width() + 2}} {value}")
+
+
+def main():
+    if len(sys.argv) != 2:
+        print("Usage: {} <history_file>".format(sys.argv[0]))
+        sys.exit(1)
+
+    history_parser = HistoryParser()
+    history_lines, metrics = history_parser.parse(sys.argv[1])
+
+    print_history_lines(history_lines)
+    print()
+    print_metrics(metrics)
+
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
2.34.1
#27 lore raw

v3 cover add mbuf debug capabilities

In reply to Shani Peretz

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

The changes in this v3 are mainly in the mbuf library.
Most comments are addressed, except suggestions for the mempool library. The patch adding detailed marks in the mlx5 PMD is removed from this series.

Shani Peretz (4):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
app/testpmd: add commands to dump mbuf history
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (1):
mbuf: move header include for logs

 app/test-pmd/cmdline.c                | 246 +++++++++++++++++++++++++-
 config/meson.build                    |   1 +
 lib/ethdev/rte_ethdev.h               |  15 ++
 lib/mbuf/mbuf_history.c               | 214 ++++++++++++++++++++++
 lib/mbuf/mbuf_log.h                   |   2 +
 lib/mbuf/meson.build                  |   2 +
 lib/mbuf/rte_mbuf.c                   |   7 +-
 lib/mbuf/rte_mbuf.h                   |  13 +-
 lib/mbuf/rte_mbuf_dyn.h               |  18 ++
 lib/mbuf/rte_mbuf_history.h           | 174 ++++++++++++++++++
 meson_options.txt                     |   2 +
 usertools/dpdk-mbuf_history_parser.py | 173 ++++++++++++++++++
 12 files changed, 862 insertions(+), 5 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf_history_parser.py
Signature · 1 line
2.51.0
#28 lore raw

PATCH v3 1/5 mbuf: move header include for logs

The header mbuf_log.h depends on rte_log.h, so it should include it. After this move, no need to include rte_log.h in addition of mbuf_log.h.

---
 lib/mbuf/mbuf_log.h | 2 ++
 lib/mbuf/rte_mbuf.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/mbuf/mbuf_log.h +2 -0
index 8feaf20747..f163cbd71c 100644
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 
+#include <rte_log.h>
+
 extern int mbuf_logtype;
 #define RTE_LOGTYPE_MBUF	mbuf_logtype
 #define MBUF_LOG(level, ...) \
lib/mbuf/rte_mbuf.c +0 -1
index 9e7731a8a2..22d7cfc475 100644
@@ -12,7 +12,6 @@
 #include <eal_export.h>
 #include <rte_debug.h>
 #include <rte_common.h>
-#include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
Signature · 1 line
2.51.0
#29 lore raw

PATCH v3 2/5 mbuf: record mbuf operations history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/meson.build          |   1 +
 lib/mbuf/mbuf_history.c     | 214 ++++++++++++++++++++++++++++++++++++
 lib/mbuf/meson.build        |   2 +
 lib/mbuf/rte_mbuf.c         |   6 +-
 lib/mbuf/rte_mbuf.h         |  13 ++-
 lib/mbuf/rte_mbuf_dyn.h     |  18 +++
 lib/mbuf/rte_mbuf_history.h | 174 +++++++++++++++++++++++++++++
 meson_options.txt           |   2 +
 8 files changed, 427 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/meson.build +1 -0
index 55497f0bf5..d1f21f3115 100644
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG', get_option('enable_mbuf_history'))
 
 compile_time_cpuflags = []
 subdir(arch_subdir)
lib/mbuf/mbuf_history.c new file +214 -0

214 lines not on this page · raw message

lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +5 -1
index 22d7cfc475..d96c2196a3 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
 	if (user_mbp_priv == NULL) {
@@ -515,8 +517,10 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+		rte_mbuf_history_mark_bulk(pending, nb_pending, RTE_MBUF_HISTORY_OP_LIB_FREE);
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending, nb_pending);
+	}
 }
 
 /* Creates a shallow copy of mbuf */
lib/mbuf/rte_mbuf.h +11 -2
index 06ab7502a5..a6c6b21253 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,7 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 	return ret.m;
 }
 
@@ -642,9 +644,12 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+			rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+		}
+	}
 	return rc;
 }
 
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 }
 
 /**
@@ -701,6 +707,7 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+		rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_FREE);
 	}
 
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1020,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +174 -0

174 lines not on this page · raw message

meson_options.txt +2 -0
index e28d24054c..5543a07583 100644
@@ -26,6 +26,8 @@ option('enable_driver_sdk', type: 'boolean', value: false, description:
        'Install headers to build drivers.')
 option('enable_libs', type: 'string', value: '', description:
        'Comma-separated list of optional libraries to explicitly enable. [NOTE: mandatory libs are always enabled]')
+option('enable_mbuf_history', type: 'boolean', value: false, description:
+       'Track mbufs for debugging purpose. Default is false.')
 option('examples', type: 'string', value: '', description:
        'Comma-separated list of examples to build by default')
 option('ibverbs_link', type: 'combo', choices : ['static', 'shared', 'dlopen'], value: 'shared', description:
Signature · 1 line
2.51.0
#30 lore raw

Re: [PATCH v3 2/5] mbuf: record mbuf operations history

I forgot to mention it is experimental in Doxygen.

I will add this to the header file and each function:

* @warning
* @b EXPERIMENTAL: this API may change without prior notice.

#31 lore raw

RE: [PATCH v3 2/5] mbuf: record mbuf operations history

In reply to Thomas Monjalon
Quoted 26 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, 1 October 2025 01.25

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---

[...]

config/meson.build if get_option('mbuf_refcnt_atomic') · line 383

Quoted 10 lines
config/meson.build +1 -0
index 55497f0bf5..d1f21f3115 100644
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG',
 get_option('enable_mbuf_history'))

Not really important, just a suggestion:
The mempool library has its debug options defined in /config/rte_config.h.
For consistency, the mbuf history debug option also belongs in /config/rte_config.h, instead of being a meson option. It also means using "#ifdef RTE_MBUF_HISTORY_DEBUG" instead of "#if RTE_MBUF_HISTORY_DEBUG".

[...]

Quoted 4 lines
config/meson.build +4 -0
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool, 25.11)
+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp)
+{
+#if !RTE_MBUF_HISTORY_DEBUG

config/meson.build if get_option('mbuf_refcnt_atomic')

Quoted 10 lines
config/meson.build +10 -0
+	RTE_SET_USED(f);
+	RTE_SET_USED(mp);
+	MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+	if (f == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf dump file.");
+		return;
+	}
+	if (mp == NULL) {
+		fprintf(f, "ERROR: Invalid mempool pointer\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 5 lines
config/meson.build +4 -0
+		return;
+	}
+	if (rte_mbuf_history_field_offset < 0) {
+		fprintf(f, "WARNING: mbuf history not initialized. Call

rte_mbuf_history_init() first.\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

config/meson.build

Quoted 2 lines
config/meson.build +2 -0
+		return;
+	}

Since the type of objects held in a mempool is not identifiable as mbufs, you should check that (mp->elt_size >= sizeof(struct rte_mbuf)). Imagine some non-mbuf mempool holding 64 byte sized objects, and rte_mbuf_history_field_offset being in the second cache line.

You might want to log an error if called directly, and silently skip of called from rte_mbuf_history_dump_all(), so suggest adding a wrapper when calling this function through rte_mempool_walk().

Quoted 25 lines
config/meson.build +18 -0
+	mbuf_history_get_stats(mp, f);
+#endif
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_all, 25.11)
+void rte_mbuf_history_dump_all(FILE *f)
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(f);
+	MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+	if (f == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf dump file.");
+		return;
+	}
+	fprintf(f, "mbuf history statistics:\n");
+	if (rte_mbuf_history_field_offset < 0) {
+		fprintf(f, "WARNING: mbuf history not initialized. Call

rte_mbuf_history_init() first.\n\n");

config/meson.build +6 -0
+		return;
+	}
+	rte_mempool_walk(mbuf_history_get_stats, f);
+#endif
+}
+

[...]

Quoted 26 lines
config/meson.build +9 -0
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t

op)

config/meson.build +13 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(m);
+	RTE_SET_USED(op);
+#else
+	RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+	RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+	if (unlikely (m == NULL))
+		return;
+
+	rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+			rte_mbuf_history_field_offset, rte_mbuf_history_t *);
+	uint64_t history = rte_atomic_load_explicit(history_field,

rte_memory_order_acquire);

config/meson.build +2 -0
+	history = (history << RTE_MBUF_HISTORY_BITS) | op;
+	rte_atomic_store_explicit(history_field, history,
Quoted 1 line

rte_memory_order_release);

This is not thread safe.
Some other thread can race to update history_field after this thread loads it, so when this tread stores the updated history, the other thread's history update is overwritten and lost. To make it thread safe, you must use a CAS operation and start over if it failed.

Quoted 2 lines
config/meson.build +2 -0
+#endif
+}
#32 lore raw

Re: [PATCH v3 2/5] mbuf: record mbuf operations history

02/10/2025 09:37, Morten Brørup:

Quoted 14 lines

From: Thomas Monjalon [mailto:[email protected]]

config/meson.build if get_option('mbuf_refcnt_atomic') · line 383

Quoted 8 lines
config/meson.build +1 -0
@@ -379,6 +379,7 @@ if get_option('mbuf_refcnt_atomic')
     dpdk_conf.set('RTE_MBUF_REFCNT_ATOMIC', true)
 endif
 dpdk_conf.set10('RTE_IOVA_IN_MBUF', get_option('enable_iova_as_pa'))
+dpdk_conf.set10('RTE_MBUF_HISTORY_DEBUG',
 get_option('enable_mbuf_history'))

Not really important, just a suggestion:
The mempool library has its debug options defined in /config/rte_config.h.
For consistency, the mbuf history debug option also belongs in /config/rte_config.h, instead of being a meson option. It also means using "#ifdef RTE_MBUF_HISTORY_DEBUG" instead of "#if RTE_MBUF_HISTORY_DEBUG".

Yes I was thinking about it.
The separation between rte_config.h and meson_options.txt is not clear. The idea was to keep the list of Meson options short.
But I think we should make more options visible to most users.

The first thing I will fix in the next revision
(after removing this option from Meson)
is to better document the mbuf debug options.

In future we should create a single debug option in Meson for simplicity. I think about such a Meson option to enable some debugs selectively:
debug=assert,dma,rcu,mempool,mbuf-sanity,mbuf-history,flow

#33 lore raw

Re: [PATCH v3 2/5] mbuf: record mbuf operations history

In reply to Morten Brørup

02/10/2025 09:37, Morten Brørup:

Quoted 23 lines
Quoted 4 lines
lib/mbuf/mbuf_history.c new file +4 -0
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool, 25.11)
+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp)
+{
+#if !RTE_MBUF_HISTORY_DEBUG

lib/mbuf/mbuf_history.c line 168

Quoted 10 lines
lib/mbuf/mbuf_history.c new file +10 -0
+      RTE_SET_USED(f);
+      RTE_SET_USED(mp);
+      MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+      if (f == NULL) {
+              MBUF_LOG(ERR, "Invalid mbuf dump file.");
+              return;
+      }
+      if (mp == NULL) {
+              fprintf(f, "ERROR: Invalid mempool pointer\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +4 -0
+              return;
+      }
+      if (rte_mbuf_history_field_offset < 0) {
+              fprintf(f, "WARNING: mbuf history not initialized. Call

rte_mbuf_history_init() first.\n");

Quoted 8 lines

Should be MBUF_LOG(ERR, ...), not fprintf().

Review

Quoted 2 lines
(quoted diff) +2 -0
+              return;
+      }

Since the type of objects held in a mempool is not identifiable as mbufs, you should check that (mp->elt_size >= sizeof(struct rte_mbuf)). Imagine some non-mbuf mempool holding 64 byte sized objects, and rte_mbuf_history_field_offset being in the second cache line.

You might want to log an error if called directly, and silently skip of called from rte_mbuf_history_dump_all(), so suggest adding a wrapper when calling this function through rte_mempool_walk().

Yes good idea.

Quoted 27 lines
Quoted 3 lines
lib/mbuf/mbuf_history.c new file +3 -0
+      mbuf_history_get_stats(mp, f);
+#endif
+}

[...]

Quoted 22 lines
lib/mbuf/rte_mbuf_history.h new file +9 -0
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t

op)

lib/mbuf/rte_mbuf_history.h new file +12 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(m);
+      RTE_SET_USED(op);
+#else
+      RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+      RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+      if (unlikely (m == NULL))
+              return;
+
+      rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+                      rte_mbuf_history_field_offset, rte_mbuf_history_t *);
Quoted 8 lines
Quoted 5 lines

+ uint64_t history = rte_atomic_load_explicit(history_field,
rte_memory_order_acquire);

(quoted diff) +2 -0
+      history = (history << RTE_MBUF_HISTORY_BITS) | op;
+      rte_atomic_store_explicit(history_field, history,

rte_memory_order_release);

This is not thread safe.
Some other thread can race to update history_field after this thread loads it, so when this tread stores the updated history, the other thread's history update is overwritten and lost.

You're right.
I suppose this change was to align with the atomic read operation done in the "get" function.

Quoted 1 line

To make it thread safe, you must use a CAS operation and start over if it failed.

By "failed", you mean if the previous value returned by the CAS operation is different of what we used earlier to build our new value?

I suggest this:

    rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
            rte_mbuf_history_field_offset, rte_mbuf_history_t *);
    uint64_t old_history = rte_atomic_load_explicit(history_field,
            rte_memory_order_acquire);
    uint64_t new_history;
    do {
        new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
    } while (!rte_atomic_compare_exchange_weak_explicit(history_field,
            &old_history, new_history,
            rte_memory_order_release, rte_memory_order_relaxed));
#34 lore raw

RE: [PATCH v3 2/5] mbuf: record mbuf operations history

Quoted 32 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 13 October 2025 20.39

02/10/2025 09:37, Morten Brørup:

Quoted 1 line
Quoted 1 line

+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool,

25.11)

Quoted 1 line
Quoted 1 line

+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool

*mp)

Quoted 6 lines
Quoted 6 lines
lib/mbuf/mbuf_history.c new file +6 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(f);
+      RTE_SET_USED(mp);
+      MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
Quoted 13 lines

lib/mbuf/mbuf_history.c line 168

Quoted 6 lines
lib/mbuf/mbuf_history.c new file +6 -0
+      if (f == NULL) {
+              MBUF_LOG(ERR, "Invalid mbuf dump file.");
+              return;
+      }
+      if (mp == NULL) {
+              fprintf(f, "ERROR: Invalid mempool pointer\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 4 lines
lib/mbuf/mbuf_history.c new file +4 -0
+              return;
+      }
+      if (rte_mbuf_history_field_offset < 0) {
+              fprintf(f, "WARNING: mbuf history not initialized.

Call

Quoted 4 lines
Quoted 1 line

rte_mbuf_history_init() first.\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+              return;
+      }

Since the type of objects held in a mempool is not identifiable as

mbufs, you should check that (mp->elt_size >= sizeof(struct rte_mbuf)). Imagine some non-mbuf mempool holding 64 byte sized objects, and rte_mbuf_history_field_offset being in the second cache line.

<feature creep>
You can check more properties of the mempool to identify mbuf mempools, seeking inspiration from the RTE_ASSERT()'s in rte_pktmbuf_pool_init():
https://elixir.bootlin.com/dpdk/v25.07/source/lib/mbuf/rte_mbuf.c#L35
</feature creep>

Quoted 60 lines
Quoted 2 lines

You might want to log an error if called directly, and silently skip

of called from rte_mbuf_history_dump_all(), so suggest adding a wrapper when calling this function through rte_mempool_walk().

Yes good idea.

Quoted 5 lines
Quoted 3 lines
lib/mbuf/mbuf_history.c new file +3 -0
+      mbuf_history_get_stats(mp, f);
+#endif
+}

[...]

Quoted 9 lines

lib/mbuf/rte_mbuf_history.h

Quoted 9 lines
lib/mbuf/rte_mbuf_history.h new file +9 -0
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m,

uint32_t

Quoted 5 lines
Quoted 5 lines

op)

lib/mbuf/rte_mbuf_history.h new file +4 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(m);
+      RTE_SET_USED(op);
Quoted 8 lines

lib/mbuf/rte_mbuf_history.h

Quoted 8 lines
lib/mbuf/rte_mbuf_history.h new file +8 -0
+#else
+      RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+      RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+      if (unlikely (m == NULL))
+              return;
+
+      rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+                      rte_mbuf_history_field_offset,

rte_mbuf_history_t *);

Quoted 8 lines
Quoted 5 lines

+ uint64_t history = rte_atomic_load_explicit(history_field,
rte_memory_order_acquire);

(quoted diff) +2 -0
+      history = (history << RTE_MBUF_HISTORY_BITS) | op;
+      rte_atomic_store_explicit(history_field, history,

rte_memory_order_release);

This is not thread safe.
Some other thread can race to update history_field after this thread

loads it, so when this tread stores the updated history, the other thread's history update is overwritten and lost.

You're right.
I suppose this change was to align with the atomic read operation done in the "get" function.

Quoted 1 line

To make it thread safe, you must use a CAS operation and start over

if it failed.

By "failed", you mean if the previous value returned by the CAS operation
is different of what we used earlier to build our new value?

I suggest this:

Quoted 10 lines
    rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
            rte_mbuf_history_field_offset, rte_mbuf_history_t *);
    uint64_t old_history = rte_atomic_load_explicit(history_field,
            rte_memory_order_acquire);
    uint64_t new_history;
    do {
        new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
    } while (!rte_atomic_compare_exchange_weak_explicit(history_field,
            &old_history, new_history,
            rte_memory_order_release, rte_memory_order_relaxed));

Yes, that was the thread safety concept I was looking for.

Small bugfix: rte_memory_order_relaxed should be rte_memory_order_acquire (when the CAS comparison fails), like when first loading old_history with rte_atomic_load_explicit().

Also, consider adding unlikely: "do {...} while (unlikely(!CAS(...)));".

#35 lore raw

Re: [PATCH v3 2/5] mbuf: record mbuf operations history

13/10/2025 22:08, Morten Brørup:

Quoted 36 lines
Quoted 36 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 13 October 2025 20.39

02/10/2025 09:37, Morten Brørup:

Quoted 1 line
Quoted 1 line

+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool,

25.11)

Quoted 1 line
Quoted 1 line

+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool

*mp)

Quoted 6 lines
Quoted 6 lines
lib/mbuf/mbuf_history.c new file +6 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(f);
+      RTE_SET_USED(mp);
+      MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
Quoted 13 lines

lib/mbuf/mbuf_history.c line 168

Quoted 6 lines
lib/mbuf/mbuf_history.c new file +6 -0
+      if (f == NULL) {
+              MBUF_LOG(ERR, "Invalid mbuf dump file.");
+              return;
+      }
+      if (mp == NULL) {
+              fprintf(f, "ERROR: Invalid mempool pointer\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 4 lines
lib/mbuf/mbuf_history.c new file +4 -0
+              return;
+      }
+      if (rte_mbuf_history_field_offset < 0) {
+              fprintf(f, "WARNING: mbuf history not initialized.

Call

Quoted 8 lines
Quoted 1 line

rte_mbuf_history_init() first.\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Review

Quoted 2 lines
(quoted diff) +2 -0
+              return;
+      }

Since the type of objects held in a mempool is not identifiable as

Quoted 8 lines
Quoted 3 lines

mbufs, you should check that (mp->elt_size >= sizeof(struct rte_mbuf)). Imagine some non-mbuf mempool holding 64 byte sized objects, and rte_mbuf_history_field_offset being in the second cache line.

<feature creep>
You can check more properties of the mempool to identify mbuf mempools, seeking inspiration from the RTE_ASSERT()'s in rte_pktmbuf_pool_init():
https://elixir.bootlin.com/dpdk/v25.07/source/lib/mbuf/rte_mbuf.c#L35
</feature creep>

I'm not sure what we can use to identify mbuf pools. Anyway I suggest doing such optimization later.

Quoted 70 lines
Quoted 59 lines
Quoted 1 line

You might want to log an error if called directly, and silently skip

of called from rte_mbuf_history_dump_all(), so suggest adding a wrapper when calling this function through rte_mempool_walk().

Yes good idea.

Quoted 5 lines
Quoted 3 lines
lib/mbuf/mbuf_history.c new file +3 -0
+      mbuf_history_get_stats(mp, f);
+#endif
+}

[...]

Quoted 9 lines

lib/mbuf/rte_mbuf_history.h

Quoted 9 lines
lib/mbuf/rte_mbuf_history.h new file +9 -0
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m,

uint32_t

Quoted 5 lines
Quoted 5 lines

op)

lib/mbuf/rte_mbuf_history.h new file +4 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(m);
+      RTE_SET_USED(op);
Quoted 8 lines

lib/mbuf/rte_mbuf_history.h

Quoted 8 lines
lib/mbuf/rte_mbuf_history.h new file +8 -0
+#else
+      RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+      RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+      if (unlikely (m == NULL))
+              return;
+
+      rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+                      rte_mbuf_history_field_offset,

rte_mbuf_history_t *);

Quoted 8 lines
Quoted 5 lines

+ uint64_t history = rte_atomic_load_explicit(history_field,
rte_memory_order_acquire);

(quoted diff) +2 -0
+      history = (history << RTE_MBUF_HISTORY_BITS) | op;
+      rte_atomic_store_explicit(history_field, history,

rte_memory_order_release);

This is not thread safe.
Some other thread can race to update history_field after this thread

loads it, so when this tread stores the updated history, the other thread's history update is overwritten and lost.

You're right.
I suppose this change was to align with the atomic read operation done in the "get" function.

Quoted 1 line

To make it thread safe, you must use a CAS operation and start over

if it failed.

By "failed", you mean if the previous value returned by the CAS operation
is different of what we used earlier to build our new value?

I suggest this:

Quoted 10 lines
    rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
            rte_mbuf_history_field_offset, rte_mbuf_history_t *);
    uint64_t old_history = rte_atomic_load_explicit(history_field,
            rte_memory_order_acquire);
    uint64_t new_history;
    do {
        new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
    } while (!rte_atomic_compare_exchange_weak_explicit(history_field,
            &old_history, new_history,
            rte_memory_order_release, rte_memory_order_relaxed));
Quoted 3 lines

Yes, that was the thread safety concept I was looking for.

Small bugfix: rte_memory_order_relaxed should be rte_memory_order_acquire (when the CAS comparison fails), like when first loading old_history with rte_atomic_load_explicit().

OK thanks.

Quoted 1 line

Also, consider adding unlikely: "do {...} while (unlikely(!CAS(...)));".

unlikely because it happens only for cloned mbufs?

#36 lore raw

RE: [PATCH v3 2/5] mbuf: record mbuf operations history

Quoted 49 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 13 October 2025 23.08

13/10/2025 22:08, Morten Brørup:

Quoted 23 lines
Quoted 23 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 13 October 2025 20.39

02/10/2025 09:37, Morten Brørup:

Quoted 1 line
Quoted 1 line

+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool,

25.11)

Quoted 1 line
Quoted 1 line

+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool

*mp)

Quoted 15 lines

lib/mbuf/mbuf_history.c line 168

Quoted 12 lines
lib/mbuf/mbuf_history.c new file +12 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(f);
+      RTE_SET_USED(mp);
+      MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+      if (f == NULL) {
+              MBUF_LOG(ERR, "Invalid mbuf dump file.");
+              return;
+      }
+      if (mp == NULL) {
+              fprintf(f, "ERROR: Invalid mempool pointer\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/mbuf/mbuf_history.c

Quoted 4 lines
lib/mbuf/mbuf_history.c new file +4 -0
+              return;
+      }
+      if (rte_mbuf_history_field_offset < 0) {
+              fprintf(f, "WARNING: mbuf history not

initialized.

Quoted 9 lines
Quoted 9 lines

Call

Quoted 8 lines
Quoted 1 line

rte_mbuf_history_init() first.\n");

Should be MBUF_LOG(ERR, ...), not fprintf().

Review

Quoted 2 lines
(quoted diff) +2 -0
+              return;
+      }

Since the type of objects held in a mempool is not identifiable

as

Quoted 1 line
Quoted 1 line

mbufs, you should check that (mp->elt_size >= sizeof(struct

rte_mbuf)).

Quoted 5 lines
Quoted 2 lines

Imagine some non-mbuf mempool holding 64 byte sized objects, and rte_mbuf_history_field_offset being in the second cache line.

<feature creep>
You can check more properties of the mempool to identify mbuf

Quoted 7 lines

mempools, seeking inspiration from the RTE_ASSERT()'s in rte_pktmbuf_pool_init():

Quoted 2 lines

https://elixir.bootlin.com/dpdk/v25.07/source/lib/mbuf/rte_mbuf.c#L35
</feature creep>

I'm not sure what we can use to identify mbuf pools. Anyway I suggest doing such optimization later.

+1

Quoted 83 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

You might want to log an error if called directly, and silently

skip

Quoted 1 line
Quoted 1 line

of called from rte_mbuf_history_dump_all(), so suggest adding a

wrapper

Quoted 33 lines
Quoted 33 lines

when calling this function through rte_mempool_walk().

Yes good idea.

Quoted 5 lines
Quoted 3 lines
lib/mbuf/mbuf_history.c new file +3 -0
+      mbuf_history_get_stats(mp, f);
+#endif
+}

[...]

Quoted 9 lines

lib/mbuf/rte_mbuf_history.h

Quoted 9 lines
lib/mbuf/rte_mbuf_history.h new file +9 -0
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m,

uint32_t

Quoted 5 lines
Quoted 5 lines

op)

lib/mbuf/rte_mbuf_history.h new file +4 -0
+{
+#if !RTE_MBUF_HISTORY_DEBUG
+      RTE_SET_USED(m);
+      RTE_SET_USED(op);
Quoted 8 lines

lib/mbuf/rte_mbuf_history.h

Quoted 8 lines
lib/mbuf/rte_mbuf_history.h new file +8 -0
+#else
+      RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+      RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+      if (unlikely (m == NULL))
+              return;
+
+      rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+                      rte_mbuf_history_field_offset,

rte_mbuf_history_t *);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ uint64_t history =

rte_atomic_load_explicit(history_field,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

rte_memory_order_acquire);

(quoted diff) +2 -0
+      history = (history << RTE_MBUF_HISTORY_BITS) | op;
+      rte_atomic_store_explicit(history_field, history,

rte_memory_order_release);

This is not thread safe.
Some other thread can race to update history_field after this

thread

Quoted 8 lines
Quoted 8 lines

loads it, so when this tread stores the updated history, the other thread's history update is overwritten and lost.

You're right.
I suppose this change was to align with the atomic read operation done in the "get" function.

Quoted 1 line

To make it thread safe, you must use a CAS operation and start

over

Quoted 8 lines
Quoted 8 lines

if it failed.

By "failed", you mean if the previous value returned by the CAS operation
is different of what we used earlier to build our new value?

I suggest this:

Quoted 8 lines
Quoted 8 lines
    rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
            rte_mbuf_history_field_offset, rte_mbuf_history_t *);
    uint64_t old_history = rte_atomic_load_explicit(history_field,
            rte_memory_order_acquire);
    uint64_t new_history;
    do {
        new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
    } while

(!rte_atomic_compare_exchange_weak_explicit(history_field,

Quoted 6 lines
Quoted 2 lines
            &old_history, new_history,
            rte_memory_order_release, rte_memory_order_relaxed));

Yes, that was the thread safety concept I was looking for.

Small bugfix: rte_memory_order_relaxed should be

rte_memory_order_acquire (when the CAS comparison fails), like when first loading old_history with rte_atomic_load_explicit().

Quoted 6 lines

OK thanks.

Quoted 1 line

Also, consider adding unlikely: "do {...} while

(unlikely(!CAS(...)));".

unlikely because it happens only for cloned mbufs?

Yes.

#37 lore raw

PATCH v3 3/5 ethdev: mark mbufs in burst functions

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/ethdev/rte_ethdev.h +15 -0
index d23c143eed..8a9683c5e9 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx, RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6690,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+#if RTE_MBUF_HISTORY_DEBUG
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX);
+#endif
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts, RTE_MBUF_HISTORY_OP_BUSY_TX);
+#endif
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
@@ -6785,6 +6798,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_PREP_TX);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
 }
 
Signature · 1 line
2.51.0
#38 lore raw

RE: [PATCH v3 3/5] ethdev: mark mbufs in burst functions

Quoted 29 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, 1 October 2025 01.25

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/ethdev/rte_ethdev.h +2 -0
index d23c143eed..8a9683c5e9 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t
 queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx,
 RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
lib/ethdev/rte_ethdev.h +0 -0
 	{
 		void *cb;

lib/ethdev/rte_ethdev.h rte_eth_tx_burst(uint16_t port_id, uint16_t · line 6698

Quoted 9 lines
lib/ethdev/rte_ethdev.h +4 -0
@@ -6688,8 +6690,19 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t
 queue_id,
 	}
 #endif
 
+#if RTE_MBUF_HISTORY_DEBUG
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts,
 RTE_MBUF_HISTORY_OP_TX);
+#endif

I think the compiler is clever enough to optimize away this if rte_mbuf_history_mark_bulk() does nothing. So you can omit the "#if RTE_MBUF_HISTORY_DEBUG". Also below.

Quoted 27 lines
lib/ethdev/rte_ethdev.h +7 -0
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+#if RTE_MBUF_HISTORY_DEBUG
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts,
 RTE_MBUF_HISTORY_OP_BUSY_TX);
+#endif
+

rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts,
nb_pkts);

lib/ethdev/rte_ethdev.h +2 -0
 	return nb_pkts;
 }
@@ -6785,6 +6798,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t
 queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts,
 RTE_MBUF_HISTORY_OP_PREP_TX);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);

}

--
2.51.0

#39 lore raw

Re: [PATCH v3 3/5] ethdev: mark mbufs in burst functions

02/10/2025 09:44, Morten Brørup:

Quoted 7 lines
Quoted 5 lines
lib/ethdev/rte_ethdev.h +3 -0
+#if RTE_MBUF_HISTORY_DEBUG
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts,

RTE_MBUF_HISTORY_OP_TX);
+#endif

I think the compiler is clever enough to optimize away this if rte_mbuf_history_mark_bulk() does nothing. So you can omit the "#if RTE_MBUF_HISTORY_DEBUG". Also below.

OK let's do that.

#40 lore raw

PATCH v3 4/5 app/testpmd: add commands to dump mbuf history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbuf pools:
testpmd> dump_mbuf_history_all

Dump the history of one mbuf pool:
testpmd> dump_mbuf_history_single_mempool <mempool_name> [file_name]

Dump the history of one mbuf:
testpmd> dump_mbuf_history_single

---
 app/test-pmd/cmdline.c | 246 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 245 insertions(+), 1 deletion(-)
app/test-pmd/cmdline.c +245 -1
index 3731fba370..113db68f8c 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump_log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump_mbuf_history_all\n"
+			"    Dumps the mbuf history for all mempools\n\n"
+
+			"dump_mbuf_history_single <mbuf_ptr>\n"
+			"    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"
+
+			"dump_mbuf_history_single_mempool <mempool_name> [file_name]\n"
+			"    Dumps the history for a specific mempool\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9177,6 +9187,8 @@ static void cmd_dump_parsed(void *parsed_result,
 #endif
 	else if (!strcmp(res->dump, "dump_log_types"))
 		rte_log_dump(stdout);
+	else if (!strcmp(res->dump, "dump_mbuf_history_all"))
+		rte_mbuf_history_dump_all(stdout);
 }
 
 static cmdline_parse_token_string_t cmd_dump_dump =
@@ -9198,7 +9210,8 @@ cmd_dump_init(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
 		"dump_trace#"
 #endif
-		"dump_log_types";
+		"dump_log_types#"
+		"dump_mbuf_history";
 }
 
 static cmdline_parse_inst_t cmd_dump = {
@@ -9260,6 +9273,232 @@ static cmdline_parse_inst_t cmd_dump_one = {
 	},
 };
 
+/* Dump mbuf history to file */
+struct cmd_dump_mbuf_to_file_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_mbuf_to_file_parsed(void *parsed_result,
+		struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_dump_mbuf_to_file_result *res = parsed_result;
+	FILE *file = stdout;
+	char *file_name = res->file;
+
+	if (strcmp(res->dump, "dump_mbuf_history_all")) {
+		cmdline_printf(cl, "Invalid dump type\n");
+		return;
+	}
+
+	if (file_name && strlen(file_name)) {
+		file = fopen(file_name, "w");
+		if (!file) {
+			rte_mbuf_history_dump_all(stdout);
+			return;
+		}
+	}
+	rte_mbuf_history_dump_all(file);
+	printf("Flow dump finished\n");
+	if (file_name && strlen(file_name))
+		fclose(file);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, dump,
+			"dump_mbuf_history_all");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_to_file = {
+	.f = cmd_dump_mbuf_to_file_parsed,  /* function to call */
+	.data = NULL,      /* 2nd arg of func */
+	.help_str = "dump_mbuf_history_all <file_name>: Dump mbuf history to file",
+	.tokens = {        /* token list, NULL terminated */
+		(void *)&cmd_dump_mbuf_to_file_dump,
+		(void *)&cmd_dump_mbuf_to_file_file,
+		NULL,
+	},
+};
+
+/* Dump single mbuf history */
+struct cmd_dump_mbuf_history_single_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mbuf_ptr;
+};
+
+static void cmd_dump_mbuf_history_single_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_single_result *res = parsed_result;
+	struct rte_mbuf *mbuf;
+	uintptr_t mbuf_addr;
+
+	/* Parse the mbuf pointer from hex string */
+	if (sscanf(res->mbuf_ptr, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+		printf("Invalid mbuf pointer format. Use 0x<address>\n");
+		return;
+	}
+
+	mbuf = (struct rte_mbuf *)mbuf_addr;
+
+	printf("Dumping history for mbuf at %p:\n", mbuf);
+	rte_mbuf_history_dump(stdout, mbuf);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_result, dump,
+			"dump_mbuf_history_single");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_ptr =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_result, mbuf_ptr,
+			NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single = {
+	.f = cmd_dump_mbuf_history_single_parsed,
+	.data = NULL,
+	.help_str = "dump_mbuf_history_single <mbuf_ptr>: Dump history for specific mbuf",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_single_dump,
+		(void *)&cmd_dump_mbuf_history_single_ptr,
+		NULL,
+	},
+};
+
+/* Dump single mempool history */
+struct cmd_dump_mbuf_history_single_mempool_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mempool_name;
+};
+
+static void cmd_dump_mbuf_history_single_mempool_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_single_mempool_result *res = parsed_result;
+	struct rte_mempool *mp;
+
+	mp = rte_mempool_lookup(res->mempool_name);
+	if (mp == NULL) {
+		printf("Mempool '%s' not found\n", res->mempool_name);
+		return;
+	}
+
+	printf("Dumping history for mempool '%s':\n", res->mempool_name);
+
+	rte_mbuf_history_dump_mempool(stdout, mp);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_result,
+			dump, "dump_mbuf_history_single_mempool");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_result,
+			mempool_name, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool = {
+	.f = cmd_dump_mbuf_history_single_mempool_parsed,
+	.data = NULL,
+	.help_str = "dump_mbuf_history_single_mempool <mempool_name>: Dump history for specific mempool",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_single_mempool_dump,
+		(void *)&cmd_dump_mbuf_history_single_mempool_name,
+		NULL,
+	},
+};
+
+/* Dump single mempool history to file only */
+struct cmd_dump_mbuf_history_single_mempool_to_file_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mempool_name;
+	cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_mbuf_history_single_mempool_to_file_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_single_mempool_to_file_result *res = parsed_result;
+	struct rte_mempool *mp;
+	FILE *file = NULL;
+	char *file_name = res->file;
+
+	mp = rte_mempool_lookup(res->mempool_name);
+	if (mp == NULL) {
+		printf("Mempool '%s' not found\n", res->mempool_name);
+		return;
+	}
+
+	if (file_name && strlen(file_name)) {
+		file = fopen(file_name, "w");
+		if (!file) {
+			printf("Failed to open file '%s'\n", file_name);
+			return;
+		}
+	} else {
+		printf("File name required for this command\n");
+		return;
+	}
+
+	printf("Dumping history for mempool '%s' to file '%s'...\n", res->mempool_name, file_name);
+	rte_mbuf_history_dump_mempool(file, mp);
+	printf("Mempool history dump finished\n");
+	fclose(file);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,
+			dump, "dump_mbuf_history_single_mempool");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,
+			mempool_name, NULL);
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_mempool_to_file_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_single_mempool_to_file_result,
+			file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool_to_file = {
+	.f = cmd_dump_mbuf_history_single_mempool_to_file_parsed,
+	.data = NULL,
+	.help_str = "dump_mbuf_history_single_mempool <mempool_name> <file_name>: Dump history for specific mempool to file",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_single_mempool_to_file_dump,
+		(void *)&cmd_dump_mbuf_history_single_mempool_to_file_name,
+		(void *)&cmd_dump_mbuf_history_single_mempool_to_file_file,
+		NULL,
+	},
+};
+
+/* Dump all mempools history */
+struct cmd_dump_mbuf_history_all_result {
+	cmdline_fixed_string_t dump;
+};
+
+static void cmd_dump_mbuf_history_all_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+	__rte_unused struct cmd_dump_mempool_history_all_result *res = parsed_result;
+
+	printf("Dumping history for all mempools:\n");
+	rte_mbuf_history_dump_all(stdout);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_all_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_all_result, dump,
+			"dump_mbuf_history_all");
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all = {
+	.f = cmd_dump_mbuf_history_all_parsed,
+	.data = NULL,
+	.help_str = "dump_mbuf_history_all: Dump history for all mempools",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_all_dump,
+		NULL,
+	},
+};
+
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13999,6 +14238,11 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump,
 	&cmd_dump_one,
+	&cmd_dump_mbuf_to_file,
+	&cmd_dump_mbuf_history_single,
+	&cmd_dump_mbuf_history_single_mempool,
+	&cmd_dump_mbuf_history_single_mempool_to_file,
+	&cmd_dump_mbuf_history_all,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
Signature · 1 line
2.51.0
#41 lore raw

Re: [PATCH v3 4/5] app/testpmd: add commands to dump mbuf history

Most testpmd commands use spaces not underline as word separator.

Quoted 347 lines · On Wed, Oct 1, 2025, 01:39 Thomas Monjalon <[email protected]> wrote:

From: Shani Peretz <[email protected]>

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbuf pools:
testpmd> dump_mbuf_history_all

Dump the history of one mbuf pool:
testpmd> dump_mbuf_history_single_mempool <mempool_name> [file_name]

Dump the history of one mbuf:
testpmd> dump_mbuf_history_single

---
 app/test-pmd/cmdline.c | 246 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 245 insertions(+), 1 deletion(-)
app/test-pmd/cmdline.c +1 -0
index 3731fba370..113db68f8c 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "dump_log_types\n"
                        "    Dumps the log level for all the dpdk

modules\n\n"

app/test-pmd/cmdline.c +5 -0
+                       "dump_mbuf_history_all\n"
+                       "    Dumps the mbuf history for all mempools\n\n"
+
+                       "dump_mbuf_history_single <mbuf_ptr>\n"
+                       "    Dumps the history for a specific mbuf (use

0x<address> format)\n\n"

app/test-pmd/cmdline.c +2 -0
+
+                       "dump_mbuf_history_single_mempool <mempool_name>

[file_name]\n"

app/test-pmd/cmdline.c +2 -0
+                       "    Dumps the history for a specific mempool\n\n"
+
                        "show port (port_id) speed_lanes capabilities"
                        "       Show speed lanes capabilities of a

port.\n\n"

                );
app/test-pmd/cmdline.c +84 -1
@@ -9177,6 +9187,8 @@ static void cmd_dump_parsed(void *parsed_result,
 #endif
        else if (!strcmp(res->dump, "dump_log_types"))
                rte_log_dump(stdout);
+       else if (!strcmp(res->dump, "dump_mbuf_history_all"))
+               rte_mbuf_history_dump_all(stdout);
 }
 
 static cmdline_parse_token_string_t cmd_dump_dump =
@@ -9198,7 +9210,8 @@ cmd_dump_init(void)
 #ifndef RTE_EXEC_ENV_WINDOWS
                "dump_trace#"
 #endif
-               "dump_log_types";
+               "dump_log_types#"
+               "dump_mbuf_history";
 }
 
 static cmdline_parse_inst_t cmd_dump = {
@@ -9260,6 +9273,232 @@ static cmdline_parse_inst_t cmd_dump_one = {
        },
 };
 
+/* Dump mbuf history to file */
+struct cmd_dump_mbuf_to_file_result {
+       cmdline_fixed_string_t dump;
+       cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_mbuf_to_file_parsed(void *parsed_result,
+               struct cmdline *cl, __rte_unused void *data)
+{
+       struct cmd_dump_mbuf_to_file_result *res = parsed_result;
+       FILE *file = stdout;
+       char *file_name = res->file;
+
+       if (strcmp(res->dump, "dump_mbuf_history_all")) {
+               cmdline_printf(cl, "Invalid dump type\n");
+               return;
+       }
+
+       if (file_name && strlen(file_name)) {
+               file = fopen(file_name, "w");
+               if (!file) {
+                       rte_mbuf_history_dump_all(stdout);
+                       return;
+               }
+       }
+       rte_mbuf_history_dump_all(file);
+       printf("Flow dump finished\n");
+       if (file_name && strlen(file_name))
+               fclose(file);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_dump =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result, dump,
+                       "dump_mbuf_history_all");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_to_file_file =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_to_file_result,
 file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_to_file = {
+       .f = cmd_dump_mbuf_to_file_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = "dump_mbuf_history_all <file_name>: Dump mbuf history
 to file",
+       .tokens = {        /* token list, NULL terminated */
+               (void *)&cmd_dump_mbuf_to_file_dump,
+               (void *)&cmd_dump_mbuf_to_file_file,
+               NULL,
+       },
+};
+
+/* Dump single mbuf history */
+struct cmd_dump_mbuf_history_single_result {
+       cmdline_fixed_string_t dump;
+       cmdline_fixed_string_t mbuf_ptr;
+};
+
+static void cmd_dump_mbuf_history_single_parsed(void *parsed_result,
+               __rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+       struct cmd_dump_mbuf_history_single_result *res = parsed_result;
+       struct rte_mbuf *mbuf;
+       uintptr_t mbuf_addr;
+
+       /* Parse the mbuf pointer from hex string */
+       if (sscanf(res->mbuf_ptr, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+               printf("Invalid mbuf pointer format. Use 0x<address>\n");
+               return;
+       }
+
+       mbuf = (struct rte_mbuf *)mbuf_addr;
+
+       printf("Dumping history for mbuf at %p:\n", mbuf);
+       rte_mbuf_history_dump(stdout, mbuf);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_dump =
+       TOKEN_STRING_INITIALIZER(struct
 cmd_dump_mbuf_history_single_result, dump,
+                       "dump_mbuf_history_single");
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_single_ptr =
+       TOKEN_STRING_INITIALIZER(struct

cmd_dump_mbuf_history_single_result, mbuf_ptr,

app/test-pmd/cmdline.c +6 -0
+                       NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single = {
+       .f = cmd_dump_mbuf_history_single_parsed,
+       .data = NULL,
+       .help_str = "dump_mbuf_history_single <mbuf_ptr>: Dump history for

specific mbuf",

app/test-pmd/cmdline.c +14 -0
+       .tokens = {
+               (void *)&cmd_dump_mbuf_history_single_dump,
+               (void *)&cmd_dump_mbuf_history_single_ptr,
+               NULL,
+       },
+};
+
+/* Dump single mempool history */
+struct cmd_dump_mbuf_history_single_mempool_result {
+       cmdline_fixed_string_t dump;
+       cmdline_fixed_string_t mempool_name;
+};
+
+static void cmd_dump_mbuf_history_single_mempool_parsed(void

*parsed_result,

app/test-pmd/cmdline.c +3 -0
+               __rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+       struct cmd_dump_mbuf_history_single_mempool_result *res =

parsed_result;

app/test-pmd/cmdline.c +14 -0
+       struct rte_mempool *mp;
+
+       mp = rte_mempool_lookup(res->mempool_name);
+       if (mp == NULL) {
+               printf("Mempool '%s' not found\n", res->mempool_name);
+               return;
+       }
+
+       printf("Dumping history for mempool '%s':\n", res->mempool_name);
+
+       rte_mbuf_history_dump_mempool(stdout, mp);
+}
+
+static cmdline_parse_token_string_t

cmd_dump_mbuf_history_single_mempool_dump =
+ TOKEN_STRING_INITIALIZER(struct
cmd_dump_mbuf_history_single_mempool_result,

app/test-pmd/cmdline.c +3 -0
+                       dump, "dump_mbuf_history_single_mempool");
+
+static cmdline_parse_token_string_t

cmd_dump_mbuf_history_single_mempool_name =
+ TOKEN_STRING_INITIALIZER(struct
cmd_dump_mbuf_history_single_mempool_result,

app/test-pmd/cmdline.c +6 -0
+                       mempool_name, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool = {
+       .f = cmd_dump_mbuf_history_single_mempool_parsed,
+       .data = NULL,
+       .help_str = "dump_mbuf_history_single_mempool <mempool_name>: Dump

history for specific mempool",

app/test-pmd/cmdline.c +15 -0
+       .tokens = {
+               (void *)&cmd_dump_mbuf_history_single_mempool_dump,
+               (void *)&cmd_dump_mbuf_history_single_mempool_name,
+               NULL,
+       },
+};
+
+/* Dump single mempool history to file only */
+struct cmd_dump_mbuf_history_single_mempool_to_file_result {
+       cmdline_fixed_string_t dump;
+       cmdline_fixed_string_t mempool_name;
+       cmdline_fixed_string_t file;
+};
+
+static void cmd_dump_mbuf_history_single_mempool_to_file_parsed(void

*parsed_result,

app/test-pmd/cmdline.c +3 -0
+               __rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+       struct cmd_dump_mbuf_history_single_mempool_to_file_result *res =

parsed_result;

app/test-pmd/cmdline.c +22 -0
+       struct rte_mempool *mp;
+       FILE *file = NULL;
+       char *file_name = res->file;
+
+       mp = rte_mempool_lookup(res->mempool_name);
+       if (mp == NULL) {
+               printf("Mempool '%s' not found\n", res->mempool_name);
+               return;
+       }
+
+       if (file_name && strlen(file_name)) {
+               file = fopen(file_name, "w");
+               if (!file) {
+                       printf("Failed to open file '%s'\n", file_name);
+                       return;
+               }
+       } else {
+               printf("File name required for this command\n");
+               return;
+       }
+
+       printf("Dumping history for mempool '%s' to file '%s'...\n",

res->mempool_name, file_name);

app/test-pmd/cmdline.c +6 -0
+       rte_mbuf_history_dump_mempool(file, mp);
+       printf("Mempool history dump finished\n");
+       fclose(file);
+}
+
+static cmdline_parse_token_string_t

cmd_dump_mbuf_history_single_mempool_to_file_dump =
+ TOKEN_STRING_INITIALIZER(struct
cmd_dump_mbuf_history_single_mempool_to_file_result,

app/test-pmd/cmdline.c +3 -0
+                       dump, "dump_mbuf_history_single_mempool");
+
+static cmdline_parse_token_string_t

cmd_dump_mbuf_history_single_mempool_to_file_name =
+ TOKEN_STRING_INITIALIZER(struct
cmd_dump_mbuf_history_single_mempool_to_file_result,

app/test-pmd/cmdline.c +3 -0
+                       mempool_name, NULL);
+
+static cmdline_parse_token_string_t

cmd_dump_mbuf_history_single_mempool_to_file_file =
+ TOKEN_STRING_INITIALIZER(struct
cmd_dump_mbuf_history_single_mempool_to_file_result,

app/test-pmd/cmdline.c +3 -0
+                       file, NULL);
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_single_mempool_to_file

= {

app/test-pmd/cmdline.c +3 -0
+       .f = cmd_dump_mbuf_history_single_mempool_to_file_parsed,
+       .data = NULL,
+       .help_str = "dump_mbuf_history_single_mempool <mempool_name>

<file_name>: Dump history for specific mempool to file",

app/test-pmd/cmdline.c +17 -0
+       .tokens = {
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_dump,
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_name,
+               (void *)&cmd_dump_mbuf_history_single_mempool_to_file_file,
+               NULL,
+       },
+};
+
+/* Dump all mempools history */
+struct cmd_dump_mbuf_history_all_result {
+       cmdline_fixed_string_t dump;
+};
+
+static void cmd_dump_mbuf_history_all_parsed(void *parsed_result,
+               __rte_unused struct cmdline *cl, __rte_unused void *data)
+{
+       __rte_unused struct cmd_dump_mempool_history_all_result *res =

parsed_result;

app/test-pmd/cmdline.c +7 -0
+
+       printf("Dumping history for all mempools:\n");
+       rte_mbuf_history_dump_all(stdout);
+}
+
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_all_dump =
+       TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_all_result,

dump,

app/test-pmd/cmdline.c +18 -1
+                       "dump_mbuf_history_all");
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all = {
+       .f = cmd_dump_mbuf_history_all_parsed,
+       .data = NULL,
+       .help_str = "dump_mbuf_history_all: Dump history for all mempools",
+       .tokens = {
+               (void *)&cmd_dump_mbuf_history_all_dump,
+               NULL,
+       },
+};
+
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13999,6 +14238,11 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
        &cmd_cleanup_txq_mbufs,
        &cmd_dump,
        &cmd_dump_one,
+       &cmd_dump_mbuf_to_file,
+       &cmd_dump_mbuf_history_single,
+       &cmd_dump_mbuf_history_single_mempool,
+       &cmd_dump_mbuf_history_single_mempool_to_file,
+       &cmd_dump_mbuf_history_all,
        &cmd_flow,
        &cmd_show_port_meter_cap,
        &cmd_add_port_meter_profile_srtcm,
--

2.51.0

#42 lore raw

Re: [PATCH v3 4/5] app/testpmd: add commands to dump mbuf history

01/10/2025 10:20, Stephen Hemminger:

Quoted 1 line

Most testpmd commands use spaces not underline as word separator.

I agree.

The existing dump commands should also use a space separator.

Quoted 19 lines · On Wed, Oct 1, 2025, 01:39 Thomas Monjalon <[email protected]> wrote:
Quoted 18 lines

From: Shani Peretz <[email protected]>

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbuf pools:
testpmd> dump_mbuf_history_all

Dump the history of one mbuf pool:
testpmd> dump_mbuf_history_single_mempool <mempool_name> [file_name]

Dump the history of one mbuf:
testpmd> dump_mbuf_history_single

#43 lore raw

PATCH v3 5/5 usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 usertools/dpdk-mbuf_history_parser.py | 173 ++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100755 usertools/dpdk-mbuf_history_parser.py
usertools/dpdk-mbuf_history_parser.py new file +173 -0
new file mode 100755
index 0000000000..dfb02d99be
@@ -0,0 +1,173 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023 NVIDIA Corporation & Affiliates
+
+import sys
+import re
+import os
+import enum
+
+RED = "\033[91m"
+RESET = "\033[0m"
+ENUM_PATTERN = r'enum\s+rte_mbuf_history_op\s*{([^}]+)}'
+VALUE_PATTERN = r'([A-Z_]+)\s*=\s*(\d+),\s*(?:/\*\s*(.*?)\s*\*/)?'
+HEADER_FILE = os.path.join(
+    os.path.dirname(os.path.dirname(__file__)),
+    'lib/mbuf/rte_mbuf_history.h'
+)
+
+
+def print_history_sequence(address: str, sequence: list[str]):
+    max_op_width = max(
+        len(re.sub(r'\x1b\[[0-9;]*m', '', op)) for op in sequence
+    )
+    op_width = max_op_width
+    for i in range(0, len(sequence), 4):
+        chunk = sequence[i:i + 4]
+        formatted_ops = [f"{op:<{op_width}}" for op in chunk]
+        line = ""
+        for j, op in enumerate(formatted_ops):
+            line += op
+            if j < len(formatted_ops) - 1:
+                line += " -> "
+        if i + 4 < len(sequence):
+            line += " ->"
+        print(f"mbuf {address}: " + line)
+    print()
+
+
+def match_field(match: re.Match) -> tuple[int, str]:
+    name, value, _ = match.groups()
+    return (int(value), name.replace('RTE_MBUF_', ''))
+
+
+class HistoryEnum:
+    def __init__(self, ops: enum.Enum):
+        self.ops = ops
+
+    @staticmethod
+    def from_header(header_file: str) -> 'HistoryEnum':
+        with open(header_file, 'r') as f:
+            content = f.read()
+
+        # Extract each enum value and its comment
+        enum_content = re.search(ENUM_PATTERN, content, re.DOTALL).group(1)
+        fields = map(match_field, re.finditer(VALUE_PATTERN, enum_content))
+        fields = dict({v: k for k, v in fields})
+        return HistoryEnum(enum.Enum('HistoryOps', fields))
+
+
+class HistoryLine:
+    def __init__(self, address: str, ops: list):
+        self.address = address
+        self.ops = ops
+
+    def repeats(self) -> [list[str], str | None]:
+        repeated = None
+        sequence = []
+        for idx, op in enumerate(self.ops):
+            if idx > 0 and op == self.ops[idx - 1] and op.name != 'NEVER':
+                sequence[-1] = f"{RED}{op.name}{RESET}"
+                sequence.append(f"{RED}{op.name}{RESET}")
+                repeated = op.name
+            else:
+                sequence.append(op.name)
+        return sequence, repeated
+
+
+class HistoryMetrics:
+    def __init__(self, metrics: dict[str, int]):
+        self.metrics = metrics
+
+    def max_name_width(self) -> int:
+        return max(len(name) for name in self.metrics.keys())
+
+
+class HistoryParser:
+    def __init__(self):
+        self.history_enum = HistoryEnum.from_header(HEADER_FILE)
+
+    def parse(
+        self, dump_file: str
+    ) -> tuple[list[HistoryLine], 'HistoryMetrics']:
+        with open(dump_file, 'r') as f:
+            lines = [line for line in f.readlines() if line.strip()]
+            populated = next(line for line in lines if "  populated=" in line)
+            metrics_start = lines.index(populated)
+
+        history_lines = lines[3:metrics_start]
+        metrics_lines = lines[metrics_start:-1]
+        return (
+            self._parse_history(history_lines),
+            self._parse_metrics(metrics_lines)
+        )
+
+    def _parse_metrics(self, lines: list[str]) -> HistoryMetrics:
+        metrics = {}
+        for line in lines:
+            key, value = line.split('=', 1)
+            metrics[key] = int(value)
+        return HistoryMetrics(metrics)
+
+    def _parse_history(self, lines: list[str]) -> list[HistoryLine]:
+        # Parse the format "mbuf 0x1054b9980: 0000000000000065"
+        history_lines = []
+        for line in lines:
+            address = line.split(':')[0].split('mbuf ')[1]
+            history = line.split(':')[1]
+            history_lines.append(
+                HistoryLine(
+                    address=address,
+                    ops=self._parse(int(history, 16))
+                )
+            )
+        return history_lines
+
+    def _parse(self, history: int) -> list[str]:
+        ops = []
+        for _ in range(16):  # 64 bits / 4 bits = 16 possible operations
+            op = history & 0xF  # Extract lowest 4 bits
+            if op == 0:
+                break
+            ops.append(self.history_enum.ops(op))
+            history >>= 4
+
+        ops.reverse()
+        return ops
+
+
+def print_history_lines(history_lines: list[HistoryLine]):
+    lines = [
+        (line.address, line.repeats()) for line in history_lines
+    ]
+
+    for address, (sequence, _) in lines:
+        print_history_sequence(address, sequence)
+
+    print("=== Violations ===")
+    for address, (sequence, repeated) in lines:
+        if repeated:
+            print(f"mbuf {address} has repeated ops: {RED}{repeated}{RESET}")
+
+
+def print_metrics(metrics: HistoryMetrics):
+    print("=== Metrics Summary ===")
+    for name, value in metrics.metrics.items():
+        print(f"{name + ':':<{metrics.max_name_width() + 2}} {value}")
+
+
+def main():
+    if len(sys.argv) != 2:
+        print("Usage: {} <history_file>".format(sys.argv[0]))
+        sys.exit(1)
+
+    history_parser = HistoryParser()
+    history_lines, metrics = history_parser.parse(sys.argv[1])
+
+    print_history_lines(history_lines)
+    print()
+    print_metrics(metrics)
+
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
2.51.0
#44 lore raw

Re: [PATCH v3 5/5] usertools/mbuf: parse mbuf history dump

Hi Thomas, Shani,

Sorry, I had completely forgotten about this patch.

Thomas Monjalon, Oct 01, 2025 at 01:25:

Quoted 21 lines

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 usertools/dpdk-mbuf_history_parser.py | 173 ++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100755 usertools/dpdk-mbuf_history_parser.py
usertools/dpdk-mbuf_history_parser.py new file +0 -0
new file mode 100755
index 0000000000..dfb02d99be

usertools/dpdk-mbuf_history_parser.py line 4

Quoted 4 lines
usertools/dpdk-mbuf_history_parser.py new file +4 -0
@@ -0,0 +1,173 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023 NVIDIA Corporation & Affiliates
+

Could you add a top level docstring to this module? You can probably copy paste the contents of the commit message here:

"""
Parse the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and present it in a human-readable format. """

usertools/dpdk-mbuf_history_parser.py line 8

Quoted 4 lines
usertools/dpdk-mbuf_history_parser.py new file +4 -0
+import sys
+import re
+import os
+import enum

Imports are not sorted alphabetically. Could you process the file with black[1] before submitting a respin? That way we have consistent coding style for new python code.

[1] https://github.com/psf/black

Quoted 144 lines
usertools/dpdk-mbuf_history_parser.py new file +144 -0
+
+RED = "\033[91m"
+RESET = "\033[0m"
+ENUM_PATTERN = r'enum\s+rte_mbuf_history_op\s*{([^}]+)}'
+VALUE_PATTERN = r'([A-Z_]+)\s*=\s*(\d+),\s*(?:/\*\s*(.*?)\s*\*/)?'
+HEADER_FILE = os.path.join(
+    os.path.dirname(os.path.dirname(__file__)),
+    'lib/mbuf/rte_mbuf_history.h'
+)
+
+
+def print_history_sequence(address: str, sequence: list[str]):
+    max_op_width = max(
+        len(re.sub(r'\x1b\[[0-9;]*m', '', op)) for op in sequence
+    )
+    op_width = max_op_width
+    for i in range(0, len(sequence), 4):
+        chunk = sequence[i:i + 4]
+        formatted_ops = [f"{op:<{op_width}}" for op in chunk]
+        line = ""
+        for j, op in enumerate(formatted_ops):
+            line += op
+            if j < len(formatted_ops) - 1:
+                line += " -> "
+        if i + 4 < len(sequence):
+            line += " ->"
+        print(f"mbuf {address}: " + line)
+    print()
+
+
+def match_field(match: re.Match) -> tuple[int, str]:
+    name, value, _ = match.groups()
+    return (int(value), name.replace('RTE_MBUF_', ''))
+
+
+class HistoryEnum:
+    def __init__(self, ops: enum.Enum):
+        self.ops = ops
+
+    @staticmethod
+    def from_header(header_file: str) -> 'HistoryEnum':
+        with open(header_file, 'r') as f:
+            content = f.read()
+
+        # Extract each enum value and its comment
+        enum_content = re.search(ENUM_PATTERN, content, re.DOTALL).group(1)
+        fields = map(match_field, re.finditer(VALUE_PATTERN, enum_content))
+        fields = dict({v: k for k, v in fields})
+        return HistoryEnum(enum.Enum('HistoryOps', fields))
+
+
+class HistoryLine:
+    def __init__(self, address: str, ops: list):
+        self.address = address
+        self.ops = ops
+
+    def repeats(self) -> [list[str], str | None]:
+        repeated = None
+        sequence = []
+        for idx, op in enumerate(self.ops):
+            if idx > 0 and op == self.ops[idx - 1] and op.name != 'NEVER':
+                sequence[-1] = f"{RED}{op.name}{RESET}"
+                sequence.append(f"{RED}{op.name}{RESET}")
+                repeated = op.name
+            else:
+                sequence.append(op.name)
+        return sequence, repeated
+
+
+class HistoryMetrics:
+    def __init__(self, metrics: dict[str, int]):
+        self.metrics = metrics
+
+    def max_name_width(self) -> int:
+        return max(len(name) for name in self.metrics.keys())
+
+
+class HistoryParser:
+    def __init__(self):
+        self.history_enum = HistoryEnum.from_header(HEADER_FILE)
+
+    def parse(
+        self, dump_file: str
+    ) -> tuple[list[HistoryLine], 'HistoryMetrics']:
+        with open(dump_file, 'r') as f:
+            lines = [line for line in f.readlines() if line.strip()]
+            populated = next(line for line in lines if "  populated=" in line)
+            metrics_start = lines.index(populated)
+
+        history_lines = lines[3:metrics_start]
+        metrics_lines = lines[metrics_start:-1]
+        return (
+            self._parse_history(history_lines),
+            self._parse_metrics(metrics_lines)
+        )
+
+    def _parse_metrics(self, lines: list[str]) -> HistoryMetrics:
+        metrics = {}
+        for line in lines:
+            key, value = line.split('=', 1)
+            metrics[key] = int(value)
+        return HistoryMetrics(metrics)
+
+    def _parse_history(self, lines: list[str]) -> list[HistoryLine]:
+        # Parse the format "mbuf 0x1054b9980: 0000000000000065"
+        history_lines = []
+        for line in lines:
+            address = line.split(':')[0].split('mbuf ')[1]
+            history = line.split(':')[1]
+            history_lines.append(
+                HistoryLine(
+                    address=address,
+                    ops=self._parse(int(history, 16))
+                )
+            )
+        return history_lines
+
+    def _parse(self, history: int) -> list[str]:
+        ops = []
+        for _ in range(16):  # 64 bits / 4 bits = 16 possible operations
+            op = history & 0xF  # Extract lowest 4 bits
+            if op == 0:
+                break
+            ops.append(self.history_enum.ops(op))
+            history >>= 4
+
+        ops.reverse()
+        return ops
+
+
+def print_history_lines(history_lines: list[HistoryLine]):
+    lines = [
+        (line.address, line.repeats()) for line in history_lines
+    ]
+
+    for address, (sequence, _) in lines:
+        print_history_sequence(address, sequence)
+
+    print("=== Violations ===")
+    for address, (sequence, repeated) in lines:
+        if repeated:
+            print(f"mbuf {address} has repeated ops: {RED}{repeated}{RESET}")
+
+

usertools/dpdk-mbuf_history_parser.py line 162

Quoted 10 lines
usertools/dpdk-mbuf_history_parser.py new file +10 -0
+def print_metrics(metrics: HistoryMetrics):
+    print("=== Metrics Summary ===")
+    for name, value in metrics.metrics.items():
+        print(f"{name + ':':<{metrics.max_name_width() + 2}} {value}")
+
+
+def main():
+    if len(sys.argv) != 2:
+        print("Usage: {} <history_file>".format(sys.argv[0]))
+        sys.exit(1)

Could you use argparse for this? I know it is a bit overkill but it takes care of the usage, help and error messages for you.

parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("history_file")
args = parser.parse_args()

usertools/dpdk-mbuf_history_parser.py line 165

Quoted 3 lines
usertools/dpdk-mbuf_history_parser.py new file +3 -0
+
+    history_parser = HistoryParser()
+    history_lines, metrics = history_parser.parse(sys.argv[1])

history_lines, metrics = history_parser.parse(args.history_file)

Quoted 8 lines
usertools/dpdk-mbuf_history_parser.py new file +8 -0
+
+    print_history_lines(history_lines)
+    print()
+    print_metrics(metrics)
+
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
Robin
Quoted 1 line

No motorized vehicles allowed.

#45 lore raw

v4 cover add mbuf debug capabilities

In reply to Shani Peretz

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

The changes in this v4 are:
- fix/rewrite testpmd commands
- fix python script
- fix thread safety
- fix checks
- fix logs
- change config (no Meson option)
- add documentation

Shani Peretz (3):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (4):
doc: explain debug options in mbuf guide
mbuf: move header include for logs app/testpmd: use space separator in dump commands app/testpmd: add commands to dump mbuf history

 app/test-pmd/cmdline.c                      | 338 ++++++++++++++------
 config/rte_config.h                         |   1 +
 doc/guides/howto/debug_troubleshoot.rst     |   7 +
 doc/guides/prog_guide/mbuf_lib.rst          |  18 +-
 doc/guides/rel_notes/release_25_11.rst      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  33 +-
 lib/ethdev/rte_ethdev.h                     |  11 +
 lib/mbuf/mbuf_history.c                     | 227 +++++++++++++
 lib/mbuf/mbuf_log.h                         |   2 +
 lib/mbuf/meson.build                        |   2 +
 lib/mbuf/rte_mbuf.c                         |   7 +-
 lib/mbuf/rte_mbuf.h                         |  13 +-
 lib/mbuf/rte_mbuf_dyn.h                     |  18 ++
 lib/mbuf/rte_mbuf_history.h                 | 206 ++++++++++++
 usertools/dpdk-mbuf-history-parser.py       | 166 ++++++++++
 15 files changed, 949 insertions(+), 107 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
Signature · 1 line
2.51.0
#46 lore raw

PATCH v4 1/7 doc: explain debug options in mbuf guide

Mention RTE_LIBRTE_MBUF_DEBUG and RTE_ENABLE_ASSERT which enable many debug checks in the mbuf library.

---
 doc/guides/prog_guide/mbuf_lib.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
doc/guides/prog_guide/mbuf_lib.rst +7 -2
index 4ad2a21f3f..badc0f3501 100644
@@ -266,8 +266,13 @@ can be found in several of the sample applications, for example, the IPv4 Multic
 Debug
 -----
 
-In debug mode, the functions of the mbuf library perform sanity checks before any operation (such as, buffer corruption,
-bad type, and so on).
+When ``RTE_LIBRTE_MBUF_DEBUG`` is enabled at compilation,
+some major mbuf operations (clone, copy, freeing)
+perform sanity checks (such as buffer corruption, bad type, and so on).
+
+When ``RTE_ENABLE_ASSERT`` is enabled,
+more basic checks are done in many functions.
+
 
 Use Cases
 ---------
Signature · 1 line
2.51.0
#47 lore raw

PATCH v4 2/7 mbuf: move header include for logs

In reply to Thomas Monjalon

The header mbuf_log.h depends on rte_log.h, so it should include it. After this move, no need to include rte_log.h in addition of mbuf_log.h.

---
 lib/mbuf/mbuf_log.h | 2 ++
 lib/mbuf/rte_mbuf.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/mbuf/mbuf_log.h +2 -0
index 8feaf20747..f163cbd71c 100644
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 
+#include <rte_log.h>
+
 extern int mbuf_logtype;
 #define RTE_LOGTYPE_MBUF	mbuf_logtype
 #define MBUF_LOG(level, ...) \
lib/mbuf/rte_mbuf.c +0 -1
index 9e7731a8a2..22d7cfc475 100644
@@ -12,7 +12,6 @@
 #include <eal_export.h>
 #include <rte_debug.h>
 #include <rte_common.h>
-#include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
Signature · 1 line
2.51.0
#48 lore raw

PATCH v4 3/7 mbuf: record mbuf operations history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/rte_config.h                     |   1 +
 doc/guides/howto/debug_troubleshoot.rst |   6 +
 doc/guides/prog_guide/mbuf_lib.rst      |   7 +
 doc/guides/rel_notes/release_25_11.rst  |   6 +
 lib/mbuf/mbuf_history.c                 | 227 ++++++++++++++++++++++++
 lib/mbuf/meson.build                    |   2 +
 lib/mbuf/rte_mbuf.c                     |   6 +-
 lib/mbuf/rte_mbuf.h                     |  13 +-
 lib/mbuf/rte_mbuf_dyn.h                 |  18 ++
 lib/mbuf/rte_mbuf_history.h             | 203 +++++++++++++++++++++
 10 files changed, 486 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/rte_config.h +1 -0
index 05344e2619..aee137717b 100644
@@ -64,6 +64,7 @@
 
 /* mbuf defines */
 #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
+/* RTE_MBUF_HISTORY_DEBUG is not set */
 
 /* ether defines */
 #define RTE_MAX_QUEUES_PER_PORT 1024
doc/guides/howto/debug_troubleshoot.rst +6 -0
index df69fa8bcc..16feeb1e54 100644
@@ -217,6 +217,12 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
      desired value and frequently uses ``rte_pktmbuf_prefree_seg`` and does
      not release MBUF back to mempool.
 
+   The mbuf lifecycle can be tracked
+   by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
+   Then the libraries will mark the mbufs,
+   and more marks can be added in the application.
+   Some dump functions must be used to collect the history.
+
 #. Lower performance between the pipeline processing stages can be
 
    * The NUMA instance for packets or objects from NIC, mempool, and ring
doc/guides/prog_guide/mbuf_lib.rst +7 -0
index badc0f3501..ae72eecc61 100644
@@ -273,6 +273,13 @@ perform sanity checks (such as buffer corruption, bad type, and so on).
 When ``RTE_ENABLE_ASSERT`` is enabled,
 more basic checks are done in many functions.
 
+When ``RTE_MBUF_HISTORY_DEBUG`` is enabled,
+the mbuf lifecycle is tracked.
+More marks can be added by the application
+by calling functions like ``rte_mbuf_history_mark_bulk()``.
+Then the history can be stored in a file
+by calling functions like ``rte_mbuf_history_dump_all()``.
+
 
 Use Cases
 ---------
doc/guides/rel_notes/release_25_11.rst +6 -0
index c3b94e1896..6854090096 100644
@@ -60,6 +60,12 @@ New Features
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
   and some devices already support this speed.
 
+* **Added mbuf tracking for debug.**
+
+  Added history dynamic field in mbuf (disabled by default)
+  to store successive states of the mbuf lifecycle.
+  Some functions were added to dump statistics.
+
 * **Updated NXP DPAA2 ethernet driver.**
 
   * Enabled software taildrop for ordered queues.
lib/mbuf/mbuf_history.c new file +227 -0

227 lines not on this page · raw message

lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +5 -1
index 22d7cfc475..d96c2196a3 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
 	if (user_mbp_priv == NULL) {
@@ -515,8 +517,10 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+		rte_mbuf_history_mark_bulk(pending, nb_pending, RTE_MBUF_HISTORY_OP_LIB_FREE);
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending, nb_pending);
+	}
 }
 
 /* Creates a shallow copy of mbuf */
lib/mbuf/rte_mbuf.h +11 -2
index 06ab7502a5..a6c6b21253 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,7 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 	return ret.m;
 }
 
@@ -642,9 +644,12 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+			rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+		}
+	}
 	return rc;
 }
 
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 }
 
 /**
@@ -701,6 +707,7 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+		rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_FREE);
 	}
 
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1020,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
2.51.0
#49 lore raw

PATCH v4 4/7 ethdev: mark mbufs in burst functions

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/ethdev/rte_ethdev.h +11 -0
index d23c143eed..8d59e81d66 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx, RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6690,15 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX);
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts, RTE_MBUF_HISTORY_OP_BUSY_TX);
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
@@ -6785,6 +6794,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_PREP_TX);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
 }
 
Signature · 1 line
2.51.0
#50 lore raw

PATCH v4 5/7 app/testpmd: use space separator in dump commands

In reply to Thomas Monjalon

In order to make dump commands look like other commands which have keywords separated with space, replace these commands:
- dump_physmem
- dump_socket_mem
- dump_memzone
- dump_struct_sizes
- dump_ring [name]
- dump_mempool [name]
- dump_devargs
- dump_lcores
- dump_trace
- dump_log_types
with these ones:
- dump physmem
- dump socket_mem
- dump memzone
- dump struct_sizes
- dump ring [name]
- dump mempool [name]
- dump devargs
- dump lcores
- dump trace
- dump log_types

Both parsing functions (with and without name argument) are merged together.

The function cmd_dump_init() is removed
as it seems useless to define tokens at runtime.

---
 app/test-pmd/cmdline.c                      | 194 +++++++++-----------
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  20 +-
 2 files changed, 98 insertions(+), 116 deletions(-)
app/test-pmd/cmdline.c +88 -106
index 3731fba370..b6db44c65f 100644
@@ -266,34 +266,34 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"show port (port_id) flow_ctrl"
 			"	Show flow control info of a port.\n\n"
 
-			"dump_physmem\n"
+			"dump physmem\n"
 			"    Dumps all physical memory segment layouts\n\n"
 
-			"dump_socket_mem\n"
+			"dump socket_mem\n"
 			"    Dumps the memory usage of all sockets\n\n"
 
-			"dump_memzone\n"
+			"dump memzone\n"
 			"    Dumps the layout of all memory zones\n\n"
 
-			"dump_struct_sizes\n"
+			"dump struct_sizes\n"
 			"    Dumps the size of all memory structures\n\n"
 
-			"dump_ring\n"
+			"dump ring [name]\n"
 			"    Dumps the status of all or specific element in DPDK rings\n\n"
 
-			"dump_mempool\n"
+			"dump mempool [name]\n"
 			"    Dumps the statistics of all or specific memory pool\n\n"
 
-			"dump_devargs\n"
+			"dump devargs\n"
 			"    Dumps the user device list\n\n"
 
-			"dump_lcores\n"
+			"dump lcores\n"
 			"    Dumps the logical cores list\n\n"
 
-			"dump_trace\n"
+			"dump trace\n"
 			"    Dumps the tracing data to the folder according to the current EAL settings\n\n"
 
-			"dump_log_types\n"
+			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
 			"show port (port_id) speed_lanes capabilities"
@@ -9085,9 +9085,35 @@ static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
 
 /* ******************************************************************************** */
 
-struct cmd_dump_result {
+struct cmd_dump_simple_result {
 	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
 };
+static cmdline_parse_token_string_t cmd_dump_simple_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_simple_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"physmem#"
+		"socket_mem#"
+		"memzone#"
+		"struct_sizes#"
+		"ring#"
+		"mempool#"
+		"devargs#"
+		"lcores#"
+#ifndef RTE_EXEC_ENV_WINDOWS
+		"trace#"
+#endif
+		"log_types"
+);
+static cmdline_parse_token_string_t cmd_dump_named_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"ring#"
+		"mempool#"
+);
+static cmdline_parse_token_string_t cmd_dump_named_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, name, NULL);
 
 static void
 dump_struct_sizes(void)
@@ -9099,7 +9125,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)
@@ -9114,7 +9139,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)
@@ -9149,113 +9173,72 @@ dump_socket_mem(FILE *f)
 	last_total = total;
 }
 
-static void cmd_dump_parsed(void *parsed_result,
-			    __rte_unused struct cmdline *cl,
-			    __rte_unused void *data)
+static void cmd_dump_simple_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
 {
-	struct cmd_dump_result *res = parsed_result;
+	struct cmd_dump_simple_result *res = parsed_result;
 
-	if (!strcmp(res->dump, "dump_physmem"))
+	if (strcmp(res->obj, "physmem") == 0)
 		rte_dump_physmem_layout(stdout);
-	else if (!strcmp(res->dump, "dump_socket_mem"))
+	else if (strcmp(res->obj, "socket_mem") == 0)
 		dump_socket_mem(stdout);
-	else if (!strcmp(res->dump, "dump_memzone"))
+	else if (strcmp(res->obj, "memzone") == 0)
 		rte_memzone_dump(stdout);
-	else if (!strcmp(res->dump, "dump_struct_sizes"))
+	else if (strcmp(res->obj, "struct_sizes") == 0)
 		dump_struct_sizes();
-	else if (!strcmp(res->dump, "dump_ring"))
-		rte_ring_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_mempool"))
-		rte_mempool_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_devargs"))
+	else if (strcmp(res->obj, "ring") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_ring_list_dump(stdout);
+		} else {
+			struct rte_ring *r;
+			r = rte_ring_lookup(res->name);
+			if (r == NULL) {
+				cmdline_printf(cl, "Cannot find ring\n");
+				return;
+			}
+			rte_ring_dump(stdout, r);
+		}
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_mempool_list_dump(stdout);
+		} else {
+			struct rte_mempool *mp;
+			mp = rte_mempool_lookup(res->name);
+			if (mp == NULL) {
+				cmdline_printf(cl, "Cannot find mempool\n");
+				return;
+			}
+			rte_mempool_dump(stdout, mp);
+		}
+	} else if (strcmp(res->obj, "devargs") == 0)
 		rte_devargs_dump(stdout);
-	else if (!strcmp(res->dump, "dump_lcores"))
+	else if (strcmp(res->obj, "lcores") == 0)
 		rte_lcore_dump(stdout);
 #ifndef RTE_EXEC_ENV_WINDOWS
-	else if (!strcmp(res->dump, "dump_trace"))
+	else if (strcmp(res->obj, "trace") == 0)
 		rte_trace_save();
 #endif
-	else if (!strcmp(res->dump, "dump_log_types"))
+	else if (strcmp(res->obj, "log_types") == 0)
 		rte_log_dump(stdout);
 }
 
-static cmdline_parse_token_string_t cmd_dump_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
-		"" /* defined at init */);
-
-static void
-cmd_dump_init(void)
-{
-	cmd_dump_dump.string_data.str =
-		"dump_physmem#"
-		"dump_memzone#"
-		"dump_socket_mem#"
-		"dump_struct_sizes#"
-		"dump_ring#"
-		"dump_mempool#"
-		"dump_devargs#"
-		"dump_lcores#"
-#ifndef RTE_EXEC_ENV_WINDOWS
-		"dump_trace#"
-#endif
-		"dump_log_types";
-}
-
-static cmdline_parse_inst_t cmd_dump = {
-	.f = cmd_dump_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "Dump status",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_dump,
+static cmdline_parse_inst_t cmd_dump_simple = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "Dump objects",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_simple_obj,
 		NULL,
 	},
 };
-
-/* ******************************************************************************** */
-
-struct cmd_dump_one_result {
-	cmdline_fixed_string_t dump;
-	cmdline_fixed_string_t name;
-};
-
-static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
-				__rte_unused void *data)
-{
-	struct cmd_dump_one_result *res = parsed_result;
-
-	if (!strcmp(res->dump, "dump_ring")) {
-		struct rte_ring *r;
-		r = rte_ring_lookup(res->name);
-		if (r == NULL) {
-			cmdline_printf(cl, "Cannot find ring\n");
-			return;
-		}
-		rte_ring_dump(stdout, r);
-	} else if (!strcmp(res->dump, "dump_mempool")) {
-		struct rte_mempool *mp;
-		mp = rte_mempool_lookup(res->name);
-		if (mp == NULL) {
-			cmdline_printf(cl, "Cannot find mempool\n");
-			return;
-		}
-		rte_mempool_dump(stdout, mp);
-	}
-}
-
-static cmdline_parse_token_string_t cmd_dump_one_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
-				 "dump_ring#dump_mempool");
-
-static cmdline_parse_token_string_t cmd_dump_one_name =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
-
-static cmdline_parse_inst_t cmd_dump_one = {
-	.f = cmd_dump_one_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_one_dump,
-		(void *)&cmd_dump_one_name,
+static cmdline_parse_inst_t cmd_dump_named = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "dump ring|mempool <name>: Dump one ring/mempool",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_named_obj,
+		(void *)&cmd_dump_named_name,
 		NULL,
 	},
 };
@@ -13997,8 +13980,8 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_config_rss_hash_key,
 	&cmd_config_rss_hash_algo,
 	&cmd_cleanup_txq_mbufs,
-	&cmd_dump,
-	&cmd_dump_one,
+	&cmd_dump_simple,
+	&cmd_dump_named,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
@@ -14131,7 +14114,6 @@ init_cmdline(void)
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
-	cmd_dump_init();
 
 	count = 0;
 	for (i = 0; builtin_ctx[i] != NULL; i++)
doc/guides/testpmd_app_ug/testpmd_funcs.rst +10 -10
index fefcf5b419..e4bef31d06 100644
@@ -568,70 +568,70 @@ dump physmem
 
 Dumps all physical memory segment layouts::
 
-   testpmd> dump_physmem
+   testpmd> dump physmem
 
 dump memzone
 ~~~~~~~~~~~~
 
 Dumps the layout of all memory zones::
 
-   testpmd> dump_memzone
+   testpmd> dump memzone
 
 dump socket memory
 ~~~~~~~~~~~~~~~~~~
 
 Dumps the memory usage of all sockets::
 
-   testpmd> dump_socket_mem
+   testpmd> dump socket_mem
 
 dump struct size
 ~~~~~~~~~~~~~~~~
 
 Dumps the size of all memory structures::
 
-   testpmd> dump_struct_sizes
+   testpmd> dump struct_sizes
 
 dump ring
 ~~~~~~~~~
 
 Dumps the status of all or specific element in DPDK rings::
 
-   testpmd> dump_ring [ring_name]
+   testpmd> dump ring [ring_name]
 
 dump mempool
 ~~~~~~~~~~~~
 
 Dumps the statistics of all or specific memory pool::
 
-   testpmd> dump_mempool [mempool_name]
+   testpmd> dump mempool [mempool_name]
 
 dump devargs
 ~~~~~~~~~~~~
 
 Dumps the user device list::
 
-   testpmd> dump_devargs
+   testpmd> dump devargs
 
 dump lcores
 ~~~~~~~~~~~
 
 Dumps the logical cores list::
 
-   testpmd> dump_lcores
+   testpmd> dump lcores
 
 dump trace
 ~~~~~~~~~~
 
 Dumps the tracing data to the folder according to the current EAL settings::
 
-   testpmd> dump_trace
+   testpmd> dump trace
 
 dump log types
 ~~~~~~~~~~~~~~
 
 Dumps the log level for all the dpdk modules::
 
-   testpmd> dump_log_types
+   testpmd> dump log_types
 
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.51.0
#51 lore raw

PATCH v4 6/7 app/testpmd: add commands to dump mbuf history

In reply to Thomas Monjalon

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

---
 app/test-pmd/cmdline.c                      | 174 ++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  13 ++
 2 files changed, 187 insertions(+)
app/test-pmd/cmdline.c +174 -0
index b6db44c65f..76b8841a5c 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump mbuf history all [file_name]\n"
+			"    Dumps the mbuf history for all mempools\n\n"
+
+			"dump mbuf history mempool <mempool_name> [file_name]\n"
+			"    Dumps the history for a specific mempool\n\n"
+
+			"dump mbuf history one <mbuf_addr> [file_name]\n"
+			"    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9243,6 +9253,164 @@ static cmdline_parse_inst_t cmd_dump_named = {
 	},
 };
 
+struct cmd_dump_mbuf_history_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mbuf;
+	cmdline_fixed_string_t history;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
+	cmdline_fixed_string_t addr;
+	cmdline_fixed_string_t file;
+};
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mbuf =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, mbuf, "mbuf");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_history =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, history, "history");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_one =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "one");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mempool =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "mempool");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_all =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "all");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, name, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_addr =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, addr, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, file, NULL);
+
+static void cmd_dump_mbuf_history_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_result *res = parsed_result;
+	FILE *out = stdout;
+
+	if (strcmp(res->file, "") != 0) {
+		out = fopen(res->file, "w");
+		if (out == NULL) {
+			cmdline_printf(cl,
+					"Failed to open file '%s'\n",
+					res->file);
+			return;
+		}
+	}
+
+	if (strcmp(res->obj, "all") == 0) {
+		rte_mbuf_history_dump_all(out);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump written in '%s'\n",
+					res->file);
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		struct rte_mempool *mp = rte_mempool_lookup(res->name);
+		if (mp == NULL) {
+			cmdline_printf(cl,
+					"Failed to find mempool '%s'\n",
+					res->name);
+			return;
+		}
+		rte_mbuf_history_dump_mempool(out, mp);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mempool '%s' written in '%s'\n",
+					res->name, res->file);
+	} else if (strcmp(res->obj, "one") == 0) {
+		struct rte_mbuf *mbuf;
+		uintptr_t mbuf_addr;
+		if (sscanf(res->addr, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+			cmdline_printf(cl,
+					"Invalid mbuf pointer format. Use 0x<address>\n");
+			return;
+		}
+		mbuf = (struct rte_mbuf *)mbuf_addr;
+		rte_mbuf_history_dump(out, mbuf);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mbuf '%p' written in '%s'\n",
+					mbuf, res->file);
+	}
+
+	if (out != stdout)
+		fclose(out);
+}
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_one_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history one <address>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_one,
+		(void *)&cmd_dump_mbuf_history_addr,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_one_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history one <address> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_one,
+		(void *)&cmd_dump_mbuf_history_addr,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_mempool_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history mempool <name>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_mempool,
+		(void *)&cmd_dump_mbuf_history_name,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_mempool_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history mempool <name> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_mempool,
+		(void *)&cmd_dump_mbuf_history_name,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_all,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_all,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13982,6 +14150,12 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump_simple,
 	&cmd_dump_named,
+	&cmd_dump_mbuf_history_all_stdout,
+	&cmd_dump_mbuf_history_all_to_file,
+	&cmd_dump_mbuf_history_mempool_stdout,
+	&cmd_dump_mbuf_history_mempool_to_file,
+	&cmd_dump_mbuf_history_one_stdout,
+	&cmd_dump_mbuf_history_one_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +13 -0
index e4bef31d06..2e984bf5f1 100644
@@ -633,6 +633,19 @@ Dumps the log level for all the dpdk modules::
 
    testpmd> dump log_types
 
+dump mbuf history
+~~~~~~~~~~~~~~~~~
+
+The mbuf history is tracked
+if enabled at compilation with ``RTE_MBUF_HISTORY_DEBUG``.
+
+This tracking can be displayed or saved to a file
+for all mbufs or specific ones selected by pointer or mempool name::
+
+   testpmd> dump mbuf history all [file]
+   testpmd> dump mbuf history mempool <mp_name> [file]
+   testpmd> dump mbuf history one <mbuf_addr> [file]
+
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.51.0
#52 lore raw

PATCH v4 7/7 usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 doc/guides/howto/debug_troubleshoot.rst |   3 +-
 doc/guides/prog_guide/mbuf_lib.rst      |   2 +
 doc/guides/rel_notes/release_25_11.rst  |   1 +
 lib/mbuf/rte_mbuf_history.h             |   3 +
 usertools/dpdk-mbuf-history-parser.py   | 166 ++++++++++++++++++++++++
 5 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
doc/guides/howto/debug_troubleshoot.rst +2 -1
index 16feeb1e54..c19aada6f8 100644
@@ -221,7 +221,8 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
    by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
    Then the libraries will mark the mbufs,
    and more marks can be added in the application.
-   Some dump functions must be used to collect the history.
+   Some dump functions must be used to collect the history,
+   and a script can parse it.
 
 #. Lower performance between the pipeline processing stages can be
 
doc/guides/prog_guide/mbuf_lib.rst +2 -0
index ae72eecc61..382bfbdca4 100644
@@ -279,6 +279,8 @@ More marks can be added by the application
 by calling functions like ``rte_mbuf_history_mark_bulk()``.
 Then the history can be stored in a file
 by calling functions like ``rte_mbuf_history_dump_all()``.
+The dump file will be easier to read after being processed
+by the script ``dpdk-mbuf-history-parser.py``.
 
 
 Use Cases
doc/guides/rel_notes/release_25_11.rst +1 -0
index 6854090096..6c26d3be10 100644
@@ -65,6 +65,7 @@ New Features
   Added history dynamic field in mbuf (disabled by default)
   to store successive states of the mbuf lifecycle.
   Some functions were added to dump statistics.
+  A script was added to parse mbuf tracking stored in a file.
 
 * **Updated NXP DPAA2 ethernet driver.**
 
lib/mbuf/rte_mbuf_history.h +3 -0
index 915fb13dac..042570762b 100644
@@ -19,6 +19,9 @@
  * The history is stored as an atomic value (64-bit) in a dynamic field of the mbuf,
  * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
  * Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores.
+ *
+ * After dumping the history in a file,
+ * the script dpdk-mbuf-history-parser.py can be used for parsing.
  */
 
 #include <rte_common.h>
usertools/dpdk-mbuf-history-parser.py new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
2.51.0
#53 lore raw

v5 cover add mbuf debug capabilities

In reply to Shani Peretz

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

---

v5 change:
- fix MSVC build in testpmd

v4 changes:
- fix/rewrite testpmd commands
- fix python script
- fix thread safety
- fix checks
- fix logs
- change config (no Meson option)
- add documentation

v3 changes:
- use atomic
- fix prefix
- add asserts
- reformat dump
- remove #ifdef clutter
- remove mlx5 patch

v2 changes:
- move to mbuf in dynamic field

v1:
- mempool feature

---

Shani Peretz (3):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (4):
doc: explain debug options in mbuf guide
mbuf: move header include for logs app/testpmd: use space separator in dump commands app/testpmd: add commands to dump mbuf history

 app/test-pmd/cmdline.c                      | 340 ++++++++++++++------
 config/rte_config.h                         |   1 +
 doc/guides/howto/debug_troubleshoot.rst     |   7 +
 doc/guides/prog_guide/mbuf_lib.rst          |  18 +-
 doc/guides/rel_notes/release_25_11.rst      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  33 +-
 lib/ethdev/rte_ethdev.h                     |  11 +
 lib/mbuf/mbuf_history.c                     | 227 +++++++++++++
 lib/mbuf/mbuf_log.h                         |   2 +
 lib/mbuf/meson.build                        |   2 +
 lib/mbuf/rte_mbuf.c                         |   7 +-
 lib/mbuf/rte_mbuf.h                         |  13 +-
 lib/mbuf/rte_mbuf_dyn.h                     |  18 ++
 lib/mbuf/rte_mbuf_history.h                 | 206 ++++++++++++
 usertools/dpdk-mbuf-history-parser.py       | 166 ++++++++++
 15 files changed, 950 insertions(+), 108 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
Signature · 1 line
2.51.0
#54 lore raw

PATCH v5 1/7 doc: explain debug options in mbuf guide

Mention RTE_LIBRTE_MBUF_DEBUG and RTE_ENABLE_ASSERT which enable many debug checks in the mbuf library.

---
 doc/guides/prog_guide/mbuf_lib.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
doc/guides/prog_guide/mbuf_lib.rst +7 -2
index 4ad2a21f3f..badc0f3501 100644
@@ -266,8 +266,13 @@ can be found in several of the sample applications, for example, the IPv4 Multic
 Debug
 -----
 
-In debug mode, the functions of the mbuf library perform sanity checks before any operation (such as, buffer corruption,
-bad type, and so on).
+When ``RTE_LIBRTE_MBUF_DEBUG`` is enabled at compilation,
+some major mbuf operations (clone, copy, freeing)
+perform sanity checks (such as buffer corruption, bad type, and so on).
+
+When ``RTE_ENABLE_ASSERT`` is enabled,
+more basic checks are done in many functions.
+
 
 Use Cases
 ---------
Signature · 1 line
2.51.0
#55 lore raw

PATCH v5 2/7 mbuf: move header include for logs

In reply to Thomas Monjalon

The header mbuf_log.h depends on rte_log.h, so it should include it. After this move, no need to include rte_log.h in addition of mbuf_log.h.

---
 lib/mbuf/mbuf_log.h | 2 ++
 lib/mbuf/rte_mbuf.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/mbuf/mbuf_log.h +2 -0
index 8feaf20747..f163cbd71c 100644
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 
+#include <rte_log.h>
+
 extern int mbuf_logtype;
 #define RTE_LOGTYPE_MBUF	mbuf_logtype
 #define MBUF_LOG(level, ...) \
lib/mbuf/rte_mbuf.c +0 -1
index 9e7731a8a2..22d7cfc475 100644
@@ -12,7 +12,6 @@
 #include <eal_export.h>
 #include <rte_debug.h>
 #include <rte_common.h>
-#include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
Signature · 1 line
2.51.0
#57 lore raw

PATCH v5 3/7 mbuf: record mbuf operations history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/rte_config.h                     |   1 +
 doc/guides/howto/debug_troubleshoot.rst |   6 +
 doc/guides/prog_guide/mbuf_lib.rst      |   7 +
 doc/guides/rel_notes/release_25_11.rst  |   6 +
 lib/mbuf/mbuf_history.c                 | 227 ++++++++++++++++++++++++
 lib/mbuf/meson.build                    |   2 +
 lib/mbuf/rte_mbuf.c                     |   6 +-
 lib/mbuf/rte_mbuf.h                     |  13 +-
 lib/mbuf/rte_mbuf_dyn.h                 |  18 ++
 lib/mbuf/rte_mbuf_history.h             | 203 +++++++++++++++++++++
 10 files changed, 486 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/rte_config.h +1 -0
index 05344e2619..aee137717b 100644
@@ -64,6 +64,7 @@
 
 /* mbuf defines */
 #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
+/* RTE_MBUF_HISTORY_DEBUG is not set */
 
 /* ether defines */
 #define RTE_MAX_QUEUES_PER_PORT 1024
doc/guides/howto/debug_troubleshoot.rst +6 -0
index df69fa8bcc..16feeb1e54 100644
@@ -217,6 +217,12 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
      desired value and frequently uses ``rte_pktmbuf_prefree_seg`` and does
      not release MBUF back to mempool.
 
+   The mbuf lifecycle can be tracked
+   by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
+   Then the libraries will mark the mbufs,
+   and more marks can be added in the application.
+   Some dump functions must be used to collect the history.
+
 #. Lower performance between the pipeline processing stages can be
 
    * The NUMA instance for packets or objects from NIC, mempool, and ring
doc/guides/prog_guide/mbuf_lib.rst +7 -0
index badc0f3501..ae72eecc61 100644
@@ -273,6 +273,13 @@ perform sanity checks (such as buffer corruption, bad type, and so on).
 When ``RTE_ENABLE_ASSERT`` is enabled,
 more basic checks are done in many functions.
 
+When ``RTE_MBUF_HISTORY_DEBUG`` is enabled,
+the mbuf lifecycle is tracked.
+More marks can be added by the application
+by calling functions like ``rte_mbuf_history_mark_bulk()``.
+Then the history can be stored in a file
+by calling functions like ``rte_mbuf_history_dump_all()``.
+
 
 Use Cases
 ---------
doc/guides/rel_notes/release_25_11.rst +6 -0
index c3b94e1896..6854090096 100644
@@ -60,6 +60,12 @@ New Features
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
   and some devices already support this speed.
 
+* **Added mbuf tracking for debug.**
+
+  Added history dynamic field in mbuf (disabled by default)
+  to store successive states of the mbuf lifecycle.
+  Some functions were added to dump statistics.
+
 * **Updated NXP DPAA2 ethernet driver.**
 
   * Enabled software taildrop for ordered queues.
lib/mbuf/mbuf_history.c new file +227 -0

227 lines not on this page · raw message

lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +5 -1
index 22d7cfc475..d96c2196a3 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
 	if (user_mbp_priv == NULL) {
@@ -515,8 +517,10 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+		rte_mbuf_history_mark_bulk(pending, nb_pending, RTE_MBUF_HISTORY_OP_LIB_FREE);
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending, nb_pending);
+	}
 }
 
 /* Creates a shallow copy of mbuf */
lib/mbuf/rte_mbuf.h +11 -2
index 06ab7502a5..a6c6b21253 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,7 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 	return ret.m;
 }
 
@@ -642,9 +644,12 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+			rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+		}
+	}
 	return rc;
 }
 
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 }
 
 /**
@@ -701,6 +707,7 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+		rte_mbuf_history_mark(mbufs[idx], RTE_MBUF_HISTORY_OP_LIB_FREE);
 	}
 
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1020,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
2.51.0
Acked-by on v5 3/7
#58 lore raw

RE: [PATCH v5 3/7] mbuf: record mbuf operations history

Quoted 118 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 08.59

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/rte_config.h                     |   1 +
 doc/guides/howto/debug_troubleshoot.rst |   6 +
 doc/guides/prog_guide/mbuf_lib.rst      |   7 +
 doc/guides/rel_notes/release_25_11.rst  |   6 +
 lib/mbuf/mbuf_history.c                 | 227 ++++++++++++++++++++++++
 lib/mbuf/meson.build                    |   2 +
 lib/mbuf/rte_mbuf.c                     |   6 +-
 lib/mbuf/rte_mbuf.h                     |  13 +-
 lib/mbuf/rte_mbuf_dyn.h                 |  18 ++
 lib/mbuf/rte_mbuf_history.h             | 203 +++++++++++++++++++++
 10 files changed, 486 insertions(+), 3 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/rte_config.h +1 -0
index 05344e2619..aee137717b 100644
@@ -64,6 +64,7 @@
 
 /* mbuf defines */
 #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
+/* RTE_MBUF_HISTORY_DEBUG is not set */
 
 /* ether defines */
 #define RTE_MAX_QUEUES_PER_PORT 1024
doc/guides/howto/debug_troubleshoot.rst +0 -0
index df69fa8bcc..16feeb1e54 100644
@@ -217,6 +217,12 @@ Memory objects close to NUMA

:numref:dtg_mempool.
desired value and frequently uses ``rte_pktmbuf_prefree_seg`` and
does
not release MBUF back to mempool.

doc/guides/howto/debug_troubleshoot.rst +6 -0
+   The mbuf lifecycle can be tracked
+   by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
+   Then the libraries will mark the mbufs,
+   and more marks can be added in the application.
+   Some dump functions must be used to collect the history.
+
 #. Lower performance between the pipeline processing stages can be
 
    * The NUMA instance for packets or objects from NIC, mempool, and

ring

doc/guides/prog_guide/mbuf_lib.rst +0 -0
index badc0f3501..ae72eecc61 100644
@@ -273,6 +273,13 @@ perform sanity checks (such as buffer corruption,

bad type, and so on).
When ``RTE_ENABLE_ASSERT`` is enabled,
more basic checks are done in many functions.

doc/guides/prog_guide/mbuf_lib.rst +7 -0
+When ``RTE_MBUF_HISTORY_DEBUG`` is enabled,
+the mbuf lifecycle is tracked.
+More marks can be added by the application
+by calling functions like ``rte_mbuf_history_mark_bulk()``.
+Then the history can be stored in a file
+by calling functions like ``rte_mbuf_history_dump_all()``.
+
 
 Use Cases
 ---------
doc/guides/rel_notes/release_25_11.rst +6 -0
index c3b94e1896..6854090096 100644
@@ -60,6 +60,12 @@ New Features
   Added Ethernet link speed for 800 Gb/s as it is well standardized in
 IEEE,
   and some devices already support this speed.
 
+* **Added mbuf tracking for debug.**
+
+  Added history dynamic field in mbuf (disabled by default)
+  to store successive states of the mbuf lifecycle.
+  Some functions were added to dump statistics.
+
 * **Updated NXP DPAA2 ethernet driver.**
 

* Enabled software taildrop for ordered queues.

lib/mbuf/mbuf_history.c new file +0 -0
new file mode 100644
index 0000000000..e3203c0d5c

lib/mbuf/mbuf_history.c line 2

Quoted 2 lines
lib/mbuf/mbuf_history.c new file +2 -0
@@ -0,0 +1,227 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates

Suggest: 2024 -> 2025
Also in other files.

Quoted 9 lines
lib/mbuf/mbuf_history.c new file +9 -0
+ */
+
+#include <rte_errno.h>
+#include <eal_export.h>
+#include <rte_bitops.h>
+#include <rte_mempool.h>
+
+#include "rte_mbuf_history.h"
+#include "rte_mbuf_dyn.h"

lib/mbuf/mbuf_history.c line 21

Quoted 10 lines
lib/mbuf/mbuf_history.c new file +10 -0
+#include "rte_mbuf.h"
+#include "mbuf_log.h"
+
+/* Dynamic field offset */
+RTE_EXPORT_SYMBOL(rte_mbuf_history_field_offset);
+int rte_mbuf_history_field_offset = -1;
+
+#ifdef RTE_MBUF_HISTORY_DEBUG
+
+#define HISTORY_LAST_MASK (RTE_BIT64(RTE_MBUF_HISTORY_BITS) - 1)

Various places in the code has something like:
+ last_op = history & HISTORY_LAST_MASK;
+ RTE_ASSERT(last_op < RTE_MBUF_HISTORY_OP_MAX);

Suggest replacing those by adding a static_assert here instead:
static_assert(RTE_MBUF_HISTORY_OP_MAX == HISTORY_LAST_MASK + 1, "Op size mismatch")

Quoted 37 lines
lib/mbuf/mbuf_history.c new file +24 -0
+
+/* Dynamic field definition for mbuf history */
+static const struct rte_mbuf_dynfield mbuf_dynfield_history = {
+	.name = RTE_MBUF_DYNFIELD_HISTORY_NAME,
+	.size = sizeof(rte_mbuf_history_t),
+	.align = RTE_ALIGN(sizeof(rte_mbuf_history_t), 8),
+};
+
+/* Context structure for statistics counting and history printing */
+struct count_and_print_ctx {
+	uint64_t *stats;
+	FILE *f;
+};
+
+static uint64_t
+mbuf_history_get(const struct rte_mbuf *m)
+{
+	if (rte_mbuf_history_field_offset < 0 || m == NULL)
+		return 0;
+
+	rte_mbuf_history_t *history = RTE_MBUF_DYNFIELD(m,
+			rte_mbuf_history_field_offset, rte_mbuf_history_t *);
+
+	return rte_atomic_load_explicit(history,

rte_memory_order_acquire);

lib/mbuf/mbuf_history.c new file +4 -0
+}
+
+static int
+mbuf_history_print(FILE *f, const struct rte_mbuf *m, uint64_t

history)

lib/mbuf/mbuf_history.c new file +6 -0
+{
+	return fprintf(f, "mbuf %p: %016" PRIx64 "\n", m, history);
+}
+
+static void
+mbuf_history_count_stats_and_print(struct rte_mempool *mp

__rte_unused,

lib/mbuf/mbuf_history.c line 56

Quoted 1 line
lib/mbuf/mbuf_history.c new file +1 -0
+		void *opaque, void *obj, unsigned obj_idx __rte_unused)

Fix:
unsigned -> unsigned int

lib/mbuf/mbuf_history.c line 60

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +2 -0
+{
+	struct count_and_print_ctx *ctx = (struct count_and_print_ctx

*)opaque;

lib/mbuf/mbuf_history.c new file +2 -0
+	struct rte_mbuf *m = (struct rte_mbuf *)obj;
+	uint64_t history, last_op;

Suggest using the enum type for operation variables:
uint64_t history;
enum rte_mbuf_history_op last_op;

Also elsewhere in the code.

Quoted 278 lines
lib/mbuf/mbuf_history.c new file +2 -0
+
+	if (obj == NULL || ctx == NULL || ctx->stats == NULL || ctx->f ==

NULL)

lib/mbuf/mbuf_history.c new file +25 -0
+		return;
+
+	history = mbuf_history_get(m);
+	/* Extract the most recent operation */
+	last_op = history & HISTORY_LAST_MASK;
+	RTE_ASSERT(last_op < RTE_MBUF_HISTORY_OP_MAX);
+
+	ctx->stats[last_op]++;
+	ctx->stats[RTE_MBUF_HISTORY_OP_MAX]++; /* total */
+
+	if (history != 0)
+		mbuf_history_print(ctx->f, m, history);
+}
+
+static void
+mbuf_history_get_stats(struct rte_mempool *mp, FILE *f)
+{
+	uint64_t stats[RTE_MBUF_HISTORY_OP_MAX + 1] = {0};
+	struct count_and_print_ctx ctx = {
+		.stats = stats,
+		.f = f
+	};
+
+	if (mp->elt_size < sizeof(struct rte_mbuf)) {
+		MBUF_LOG(ERR, "Invalid mempool element size (less than

mbuf)");

lib/mbuf/mbuf_history.c new file +11 -0
+		return;
+	}
+
+	if (f == NULL)
+		return;
+
+	/* Output mempool header */
+	fprintf(f, "mempool <%s>@%p\n", mp->name, mp);
+
+	/* Single pass: collect statistics and print mbuf history */
+	rte_mempool_obj_iter(mp, mbuf_history_count_stats_and_print,

&ctx);

lib/mbuf/mbuf_history.c new file +16 -0
+
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated =
+		stats[RTE_MBUF_HISTORY_OP_LIB_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_PMD_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_APP_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_RX] +
+		stats[RTE_MBUF_HISTORY_OP_TX] +
+		stats[RTE_MBUF_HISTORY_OP_PREP_TX] +
+		stats[RTE_MBUF_HISTORY_OP_BUSY_TX] +
+		stats[RTE_MBUF_HISTORY_OP_ENQUEUE] +
+		stats[RTE_MBUF_HISTORY_OP_DEQUEUE];
+
+	/* Print statistics summary */
+	fprintf(f, "  populated = %u\n", mp->populated_size);
+	fprintf(f, "  never allocated = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_NEVER]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  lib free = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_LIB_FREE]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  PMD free = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_PMD_FREE]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  app free = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_APP_FREE]);

lib/mbuf/mbuf_history.c new file +2 -0
+	fprintf(f, "  allocated = %" PRIu64 "\n", total_allocated);
+	fprintf(f, "  lib alloc = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_LIB_ALLOC]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  PMD alloc = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_PMD_ALLOC]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  app alloc = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_APP_ALLOC]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  Rx = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_RX]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  Tx = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_TX]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  prep Tx = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_PREP_TX]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  busy Tx = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_BUSY_TX]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  enqueue = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_ENQUEUE]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  dequeue = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_DEQUEUE]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  user defined 1 = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_USR1]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  user defined 2 = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_USR2]);

lib/mbuf/mbuf_history.c new file +1 -0
+	fprintf(f, "  counted total = %" PRIu64 "\n",

stats[RTE_MBUF_HISTORY_OP_MAX]);

lib/mbuf/mbuf_history.c new file +31 -0
+}
+
+static void
+mbuf_history_get_stats_walking(struct rte_mempool *mp, void *arg)
+{
+	if (mp->elt_size < sizeof(struct rte_mbuf))
+		return; /* silently ignore while walking in all mempools */
+
+	mbuf_history_get_stats(mp, arg);
+}
+
+#endif /* RTE_MBUF_HISTORY_DEBUG */
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump, 25.11)
+void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf *m)
+{
+#ifndef RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(f);
+	RTE_SET_USED(m);
+	MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+	if (f == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf dump file");
+		return;
+	}
+	if (m == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf pointer");
+		return;
+	}
+	if (rte_mbuf_history_field_offset < 0) {
+		MBUF_LOG(WARNING, "mbuf history not initialized, call

rte_mbuf_history_init()");

lib/mbuf/mbuf_history.c new file +24 -0
+		return;
+	}
+	mbuf_history_print(f, m, mbuf_history_get(m));
+#endif
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_mempool, 25.11)
+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp)
+{
+#ifndef RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(f);
+	RTE_SET_USED(mp);
+	MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+	if (f == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf dump file");
+		return;
+	}
+	if (mp == NULL) {
+		MBUF_LOG(ERR, "Invalid mempool pointer");
+		return;
+	}
+	if (rte_mbuf_history_field_offset < 0) {
+		MBUF_LOG(WARNING, "mbuf history not initialized, call

rte_mbuf_history_init()");

lib/mbuf/mbuf_history.c new file +19 -0
+		return;
+	}
+	mbuf_history_get_stats(mp, f);
+#endif
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_dump_all, 25.11)
+void rte_mbuf_history_dump_all(FILE *f)
+{
+#ifndef RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(f);
+	MBUF_LOG(INFO, "mbuf history recorder is not enabled");
+#else
+	if (f == NULL) {
+		MBUF_LOG(ERR, "Invalid mbuf dump file");
+		return;
+	}
+	if (rte_mbuf_history_field_offset < 0) {
+		MBUF_LOG(WARNING, "mbuf history not initialized, call

rte_mbuf_history_init()");

lib/mbuf/mbuf_history.c new file +17 -0
+		return;
+	}
+	fprintf(f, "mbuf history statistics:\n");
+	rte_mempool_walk(mbuf_history_get_stats_walking, f);
+#endif
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_mbuf_history_init, 25.11)
+void rte_mbuf_history_init(void)
+{
+#ifdef RTE_MBUF_HISTORY_DEBUG
+	if (rte_mbuf_history_field_offset >= 0) {
+		/* already initialized */
+		return;
+	}
+
+	rte_mbuf_history_field_offset =

rte_mbuf_dynfield_register(&mbuf_dynfield_history);

lib/mbuf/mbuf_history.c new file +2 -0
+	if (rte_mbuf_history_field_offset < 0) {
+		MBUF_LOG(ERR, "Failed to register mbuf history dynamic

field: %s\n",

lib/mbuf/mbuf_history.c new file +4 -0
+			rte_strerror(rte_errno));
+	}
+#endif
+}
lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +2 -0
index 22d7cfc475..d96c2196a3 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void
 *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
lib/mbuf/rte_mbuf.c +3 -1
 	if (user_mbp_priv == NULL) {
@@ -515,8 +517,10 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf
 **mbufs, unsigned int count)
 		} while (m != NULL);
 	}
 
-	if (nb_pending > 0)
+	if (nb_pending > 0) {
+		rte_mbuf_history_mark_bulk(pending, nb_pending,
 RTE_MBUF_HISTORY_OP_LIB_FREE);
 		rte_mempool_put_bulk(pending[0]->pool, (void **)pending,
 nb_pending);
+	}

}

/* Creates a shallow copy of mbuf */

lib/mbuf/rte_mbuf.h +7 -2
index 06ab7502a5..a6c6b21253 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,7 @@ static inline struct rte_mbuf
 *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 	return ret.m;
 }
@@ -642,9 +644,12 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf
 **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
-		for (unsigned int idx = 0; idx < count; idx++)
+	if (likely(rc == 0)) {
+		for (unsigned int idx = 0; idx < count; idx++) {
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+			rte_mbuf_history_mark(mbufs[idx],
 RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+		}
+	}
 	return rc;

}

lib/mbuf/rte_mbuf.h rte_mbuf_raw_free(struct rte_mbuf *m) · line 675

Quoted 4 lines
lib/mbuf/rte_mbuf.h +1 -0
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);

Fix: For improved race protection, mark the mbuf before actually freeing it, like this:
__rte_mbuf_raw_sanity_check(m);
+ rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
rte_mempool_put(m->pool, m);

Quoted 11 lines
lib/mbuf/rte_mbuf.h +0 -0
 }
 
 /**
@@ -701,6 +707,7 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp,

struct rte_mbuf **mbufs, unsigned

lib/mbuf/rte_mbuf.h +1 -0
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+		rte_mbuf_history_mark(mbufs[idx],

RTE_MBUF_HISTORY_OP_LIB_FREE);
}

Fix: The loop is normally omitted, so use rte_mbuf_history_mark_bulk() here instead of rte_mbuf_history_mark() inside the loop. It also makes the code easier to read.

Quoted 128 lines
lib/mbuf/rte_mbuf.h +2 -0
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
@@ -1013,6 +1020,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct
 rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count,
 RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization,

see

lib/mbuf/rte_mbuf.h +0 -0
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid

extra

lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +14 -0
new file mode 100644
index 0000000000..915fb13dac
@@ -0,0 +1,203 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates
+ */
+
+#ifndef _RTE_MBUF_HISTORY_H_
+#define _RTE_MBUF_HISTORY_H_
+
+/**
+ * @file
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * These functions allow to track history of mbuf objects using a

dynamic field.
+ *
+ * It tracks the lifecycle of mbuf objects through the system
+ * with a fixed set of predefined events to maintain performance.
+ *
+ * The history is stored as an atomic value (64-bit) in a dynamic field of the mbuf,
+ * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
+ * Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores.
+ */

lib/mbuf/rte_mbuf_history.h new file +23 -0
+
+#include <rte_common.h>
+#include <rte_debug.h>
+
+#include <rte_mbuf_dyn.h>
+
+/* Forward declaration to avoid circular dependency. */
+struct rte_mbuf;
+struct rte_mempool;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Number of bits for each history operation.
+ */
+#define RTE_MBUF_HISTORY_BITS 4
+
+/**
+ * Maximum number of history operations that can be stored.
+ */
+#define RTE_MBUF_HISTORY_MAX (sizeof(rte_mbuf_history_t) * 8 /

RTE_MBUF_HISTORY_BITS)

lib/mbuf/rte_mbuf_history.h new file +6 -0
+
+/**
+ * History operation types.
+ */
+enum rte_mbuf_history_op {
+	RTE_MBUF_HISTORY_OP_NEVER     =  0, /**< Initial state - never

allocated */

lib/mbuf/rte_mbuf_history.h new file +4 -0
+	RTE_MBUF_HISTORY_OP_LIB_FREE  =  1, /**< Freed back to pool */
+	RTE_MBUF_HISTORY_OP_PMD_FREE  =  2, /**< Freed by PMD */
+	RTE_MBUF_HISTORY_OP_APP_FREE  =  3, /**< Freed by application */
+	RTE_MBUF_HISTORY_OP_LIB_ALLOC =  4, /**< Allocation in mbuf

library */

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_PMD_ALLOC =  5, /**< Allocated by PMD for Rx

*/

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_APP_ALLOC =  6, /**< Allocated by application

*/

lib/mbuf/rte_mbuf_history.h new file +3 -0
+	RTE_MBUF_HISTORY_OP_RX        =  7, /**< Received */
+	RTE_MBUF_HISTORY_OP_TX        =  8, /**< Sent */
+	RTE_MBUF_HISTORY_OP_PREP_TX   =  9, /**< Being prepared before Tx

*/

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_BUSY_TX   = 10, /**< Returned due to Tx busy
Quoted 1 line

*/

Suggest:
RTE_MBUF_HISTORY_OP_PREP_TX -> RTE_MBUF_HISTORY_OP_TX_PREP RTE_MBUF_HISTORY_OP_BUSY_TX -> RTE_MBUF_HISTORY_OP_TX_BUSY

Quoted 10 lines
lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_ENQUEUE   = 11, /**< Enqueued for processing

*/

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_DEQUEUE   = 12, /**< Dequeued for processing

*/

lib/mbuf/rte_mbuf_history.h new file +2 -0
+	/*                              13,      reserved for future */
+	RTE_MBUF_HISTORY_OP_USR2      = 14, /**< Application-defined

event 2 */

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_USR1      = 15, /**< Application-defined

event 1 */

lib/mbuf/rte_mbuf_history.h new file +1 -0
+	RTE_MBUF_HISTORY_OP_MAX       = 16, /**< Maximum number of
Quoted 2 lines

operation types */
+};

Suggest adding:
static_assert(RTE_MBUF_HISTORY_OP_MAX == 1 << RTE_MBUF_HISTORY_BITS, "Enum vs bitsize mismatch");

Quoted 35 lines
lib/mbuf/rte_mbuf_history.h new file +3 -0
+
+/**
+ * Global offset for the history dynamic field (set during

initialization).
+ */

lib/mbuf/rte_mbuf_history.h new file +9 -0
+extern int rte_mbuf_history_field_offset;
+
+/**
+ * Initialize the mbuf history system.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * This function registers the dynamic field for mbuf history

tracking.
+ * It should be called once during application initialization.
+ *
+ * Note: This function is called by rte_pktmbuf_pool_create,
+ * so explicit invocation is usually not required.
+ */

lib/mbuf/rte_mbuf_history.h new file +15 -0
+__rte_experimental
+void rte_mbuf_history_init(void);
+
+/**
+ * Mark an mbuf with a history event.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param m
+ *   Pointer to the mbuf.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t
Quoted 1 line

op)

Fix:
uint32_t op -> enum rte_mbuf_history_op op

Quoted 40 lines
lib/mbuf/rte_mbuf_history.h new file +18 -0
+{
+#ifndef RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(m);
+	RTE_SET_USED(op);
+#else
+	RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+	RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+	if (unlikely(m == NULL))
+		return;
+
+	rte_mbuf_history_t *history_field = RTE_MBUF_DYNFIELD(m,
+			rte_mbuf_history_field_offset, rte_mbuf_history_t *);
+	uint64_t old_history = rte_atomic_load_explicit(history_field,
+			rte_memory_order_acquire);
+	uint64_t new_history;
+	do {
+		new_history = (old_history << RTE_MBUF_HISTORY_BITS) | op;
+	} while

(unlikely(!rte_atomic_compare_exchange_weak_explicit(history_field,

lib/mbuf/rte_mbuf_history.h new file +2 -0
+			&old_history, new_history,
+			rte_memory_order_release,

rte_memory_order_acquire)));

lib/mbuf/rte_mbuf_history.h new file +17 -0
+#endif
+}
+
+/**
+ * Mark multiple mbufs with a history event.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param mbufs
+ *   Array of mbuf pointers.
+ * @param n
+ *   Number of mbufs to mark.
+ * @param op
+ *   The operation to record.
+ */
+static inline void rte_mbuf_history_mark_bulk(struct rte_mbuf * const

*mbufs,

lib/mbuf/rte_mbuf_history.h line 139

Quoted 1 line
lib/mbuf/rte_mbuf_history.h new file +1 -0
+		uint32_t n, uint32_t op)

Fix:
uint32_t n -> unsigned int count (for consistency) uint32_t op -> enum rte_mbuf_history_op op

Quoted 65 lines
lib/mbuf/rte_mbuf_history.h new file +64 -1
+{
+#ifndef RTE_MBUF_HISTORY_DEBUG
+	RTE_SET_USED(mbufs);
+	RTE_SET_USED(n);
+	RTE_SET_USED(op);
+#else
+	RTE_ASSERT(rte_mbuf_history_field_offset >= 0);
+	RTE_ASSERT(op < RTE_MBUF_HISTORY_OP_MAX);
+	if (unlikely(mbufs == NULL))
+		return;
+
+	while (n--)
+		rte_mbuf_history_mark(*mbufs++, op);
+#endif
+}
+
+/**
+ * Dump mbuf history for a single mbuf to a file.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param f
+ *   File pointer to write the history to.
+ * @param m
+ *   Pointer to the mbuf to dump history for.
+ */
+__rte_experimental
+void rte_mbuf_history_dump(FILE *f, const struct rte_mbuf *m);
+
+/**
+ * Dump mbuf history statistics for a single mempool to a file.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param f
+ *   File pointer to write the history statistics to.
+ * @param mp
+ *   Pointer to the mempool to dump history for.
+ */
+__rte_experimental
+void rte_mbuf_history_dump_mempool(FILE *f, struct rte_mempool *mp);
+
+/**
+ * Dump mbuf history statistics for all mempools to a file.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param f
+ *   File pointer to write the history statistics to.
+ */
+__rte_experimental
+void rte_mbuf_history_dump_all(FILE *f);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_MBUF_HISTORY_H_ */
--
Quoted 1 line

2.51.0

With fixes (suggestions optional),

#59 lore raw

Re: [PATCH v5 3/7] mbuf: record mbuf operations history

14/10/2025 11:59, Morten Brørup:

Quoted 9 lines

From: Thomas Monjalon [mailto:[email protected]]

lib/mbuf/mbuf_history.c line 2

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +2 -0
@@ -0,0 +1,227 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 NVIDIA Corporation & Affiliates

Suggest: 2024 -> 2025
Also in other files.

No, it is the year of initial write.
It has been used internally before pushing upstream.

[...]

lib/mbuf/mbuf_history.c line 68

Quoted 5 lines

lib/mbuf/mbuf_history.c line 21

Quoted 1 line
lib/mbuf/mbuf_history.c new file +1 -0
+#define HISTORY_LAST_MASK (RTE_BIT64(RTE_MBUF_HISTORY_BITS) - 1)

Various places in the code has something like:

lib/mbuf/mbuf_history.c new file +2 -0
+	last_op = history & HISTORY_LAST_MASK;
+	RTE_ASSERT(last_op < RTE_MBUF_HISTORY_OP_MAX);

There is only one.
Other asserts are validating function parameters to be of the right size.

Quoted 2 lines

Suggest replacing those by adding a static_assert here instead:
static_assert(RTE_MBUF_HISTORY_OP_MAX == HISTORY_LAST_MASK + 1, "Op size mismatch")

It is just checking RTE_MBUF_HISTORY_BITS and RTE_MBUF_HISTORY_OP_MAX are in sync. Honestly I don't see a real benefit, but I will add RTE_BUILD_BUG_ON(RTE_MBUF_HISTORY_OP_MAX > HISTORY_LAST_MASK + 1);

[...]

Quoted 7 lines

lib/mbuf/mbuf_history.c line 56

Quoted 4 lines
lib/mbuf/mbuf_history.c new file +2 -0
+static void
+mbuf_history_count_stats_and_print(struct rte_mempool *mp

__rte_unused,

lib/mbuf/mbuf_history.c new file +1 -0
+		void *opaque, void *obj, unsigned obj_idx __rte_unused)

Fix:
unsigned -> unsigned int

It is the definition:
typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,

        void *opaque, void *obj, unsigned obj_idx);
Quoted 11 lines

lib/mbuf/mbuf_history.c line 60

Quoted 6 lines
lib/mbuf/mbuf_history.c new file +2 -0
+{
+	struct count_and_print_ctx *ctx = (struct count_and_print_ctx

*)opaque;

lib/mbuf/mbuf_history.c new file +2 -0
+	struct rte_mbuf *m = (struct rte_mbuf *)obj;
+	uint64_t history, last_op;

Suggest using the enum type for operation variables:
uint64_t history;
enum rte_mbuf_history_op last_op;

Quoted 1 line

Also elsewhere in the code.

Yes it would be better to use the right type.

[...]

lib/mbuf/rte_mbuf.h rte_mbuf_raw_free(struct rte_mbuf *m)

Quoted 10 lines

lib/mbuf/mbuf_history.c rte_mbuf_raw_free(struct rte_mbuf *m) · line 675

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +1 -0
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);

Fix: For improved race protection, mark the mbuf before actually freeing it, like this:

lib/mbuf/rte_mbuf.h +1 -0
 	__rte_mbuf_raw_sanity_check(m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 	rte_mempool_put(m->pool, m);

The race is about a debugging mark.
The benefit of marking after is that the last mark is the upper level, so we can easily distinguish between a free initiated by the app or the PMD.

[...]

Quoted 11 lines
Quoted 8 lines
lib/mbuf/mbuf_history.c new file +0 -0
@@ -701,6 +707,7 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp,

struct rte_mbuf **mbufs, unsigned

lib/mbuf/mbuf_history.c new file +1 -0
 		RTE_ASSERT(m != NULL);
 		RTE_ASSERT(m->pool == mp);
 		__rte_mbuf_raw_sanity_check(m);
+		rte_mbuf_history_mark(mbufs[idx],

RTE_MBUF_HISTORY_OP_LIB_FREE);
}

Fix: The loop is normally omitted, so use rte_mbuf_history_mark_bulk() here instead of rte_mbuf_history_mark() inside the loop. It also makes the code easier to read.

OK

[...]

Quoted 14 lines
Quoted 14 lines
lib/mbuf/mbuf_history.c new file +2 -0
+enum rte_mbuf_history_op {
+	RTE_MBUF_HISTORY_OP_NEVER     =  0, /**< Initial state - never

allocated */

lib/mbuf/mbuf_history.c new file +4 -0
+	RTE_MBUF_HISTORY_OP_LIB_FREE  =  1, /**< Freed back to pool */
+	RTE_MBUF_HISTORY_OP_PMD_FREE  =  2, /**< Freed by PMD */
+	RTE_MBUF_HISTORY_OP_APP_FREE  =  3, /**< Freed by application */
+	RTE_MBUF_HISTORY_OP_LIB_ALLOC =  4, /**< Allocation in mbuf

library */

lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_PMD_ALLOC =  5, /**< Allocated by PMD for Rx

*/

lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_APP_ALLOC =  6, /**< Allocated by application

*/

lib/mbuf/mbuf_history.c new file +2 -0
+	RTE_MBUF_HISTORY_OP_RX        =  7, /**< Received */
+	RTE_MBUF_HISTORY_OP_TX        =  8, /**< Sent */
Quoted 8 lines
Quoted 4 lines
lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_PREP_TX   =  9, /**< Being prepared before Tx

*/

lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_BUSY_TX   = 10, /**< Returned due to Tx busy

*/

Suggest:
RTE_MBUF_HISTORY_OP_PREP_TX -> RTE_MBUF_HISTORY_OP_TX_PREP RTE_MBUF_HISTORY_OP_BUSY_TX -> RTE_MBUF_HISTORY_OP_TX_BUSY

OK

Quoted 7 lines
Quoted 7 lines
lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_ENQUEUE   = 11, /**< Enqueued for processing

*/

lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_DEQUEUE   = 12, /**< Dequeued for processing

*/

lib/mbuf/mbuf_history.c new file +2 -0
+	/*                              13,      reserved for future */
+	RTE_MBUF_HISTORY_OP_USR2      = 14, /**< Application-defined

event 2 */

Quoted 8 lines
Quoted 5 lines
lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_USR1      = 15, /**< Application-defined

event 1 */

lib/mbuf/mbuf_history.c new file +1 -0
+	RTE_MBUF_HISTORY_OP_MAX       = 16, /**< Maximum number of

operation types */
+};

Suggest adding:
static_assert(RTE_MBUF_HISTORY_OP_MAX == 1 << RTE_MBUF_HISTORY_BITS, "Enum vs bitsize mismatch");

Done with RTE_BUILD_BUG_ON(RTE_MBUF_HISTORY_OP_MAX > HISTORY_LAST_MASK + 1); in next version.

No need to test equality.
Being more tolerant allows playing with tuning easily.

[...]

Quoted 8 lines
Quoted 8 lines

+/**
+ * Mark an mbuf with a history event.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param m
+ * Pointer to the mbuf.

Quoted 8 lines
Quoted 5 lines

+ * @param op
+ * The operation to record.
+ */
+static inline void rte_mbuf_history_mark(struct rte_mbuf *m, uint32_t op)

Fix:
uint32_t op -> enum rte_mbuf_history_op op

Yes

[...]

Quoted 12 lines
Quoted 12 lines

+/**
+ * Mark multiple mbufs with a history event.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @param mbufs
+ * Array of mbuf pointers.
+ * @param n
+ * Number of mbufs to mark.
+ * @param op
+ * The operation to record.

Quoted 8 lines

lib/mbuf/mbuf_history.c

Quoted 4 lines

+ */
+static inline void rte_mbuf_history_mark_bulk(struct rte_mbuf * const *mbufs,

lib/mbuf/mbuf_history.c new file +1 -0
+		uint32_t n, uint32_t op)

Fix:
uint32_t n -> unsigned int count (for consistency) uint32_t op -> enum rte_mbuf_history_op op

Yes

[...]

Quoted 2 lines

With fixes (suggestions optional),

Thanks for the very detailed review.

#60 lore raw

Re: [PATCH v5 3/7] mbuf: record mbuf operations history

14/10/2025 14:03, Thomas Monjalon:

Quoted 16 lines

14/10/2025 11:59, Morten Brørup:

lib/mbuf/rte_mbuf.h rte_mbuf_raw_free(struct rte_mbuf *m)

Quoted 11 lines

From: Thomas Monjalon [mailto:[email protected]]

lib/mbuf/rte_mbuf.h rte_mbuf_raw_free(struct rte_mbuf *m) · line 675

Quoted 5 lines
lib/mbuf/rte_mbuf.h +1 -0
@@ -667,6 +672,7 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
 	rte_mempool_put(m->pool, m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);

Fix: For improved race protection, mark the mbuf before actually freeing it, like this:

lib/mbuf/rte_mbuf.h +1 -0
 	__rte_mbuf_raw_sanity_check(m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 	rte_mempool_put(m->pool, m);

The race is about a debugging mark.
The benefit of marking after is that the last mark is the upper level, so we can easily distinguish between a free initiated by the app or the PMD.

I've messed up with another consideration.
Here we are in the mbuf lib, so the lowest level. You're right it is better to mark RTE_MBUF_HISTORY_OP_LIB_FREE before freeing effectively.

#61 lore raw

PATCH v5 4/7 ethdev: mark mbufs in burst functions

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/ethdev/rte_ethdev.h +11 -0
index d23c143eed..8d59e81d66 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx, RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6690,15 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX);
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts, RTE_MBUF_HISTORY_OP_BUSY_TX);
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
@@ -6785,6 +6794,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_PREP_TX);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
 }
 
Signature · 1 line
2.51.0
#62 lore raw

PATCH v5 5/7 app/testpmd: use space separator in dump commands

In reply to Thomas Monjalon

In order to make dump commands look like other commands which have keywords separated with space, replace these commands:
- dump_physmem
- dump_socket_mem
- dump_memzone
- dump_struct_sizes
- dump_ring [name]
- dump_mempool [name]
- dump_devargs
- dump_lcores
- dump_trace
- dump_log_types
with these ones:
- dump physmem
- dump socket_mem
- dump memzone
- dump struct_sizes
- dump ring [name]
- dump mempool [name]
- dump devargs
- dump lcores
- dump trace
- dump log_types

Both parsing functions (with and without name argument) are merged together.

The function cmd_dump_init() is removed
as it seems useless to define tokens at runtime.

Trace is explicitly warned as not supported on Windows, because #ifndef in the tokens is not possible with MSVC.

---
 app/test-pmd/cmdline.c                      | 196 +++++++++-----------
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  20 +-
 2 files changed, 99 insertions(+), 117 deletions(-)
app/test-pmd/cmdline.c +89 -107
index 3731fba370..487a95cd16 100644
@@ -266,34 +266,34 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"show port (port_id) flow_ctrl"
 			"	Show flow control info of a port.\n\n"
 
-			"dump_physmem\n"
+			"dump physmem\n"
 			"    Dumps all physical memory segment layouts\n\n"
 
-			"dump_socket_mem\n"
+			"dump socket_mem\n"
 			"    Dumps the memory usage of all sockets\n\n"
 
-			"dump_memzone\n"
+			"dump memzone\n"
 			"    Dumps the layout of all memory zones\n\n"
 
-			"dump_struct_sizes\n"
+			"dump struct_sizes\n"
 			"    Dumps the size of all memory structures\n\n"
 
-			"dump_ring\n"
+			"dump ring [name]\n"
 			"    Dumps the status of all or specific element in DPDK rings\n\n"
 
-			"dump_mempool\n"
+			"dump mempool [name]\n"
 			"    Dumps the statistics of all or specific memory pool\n\n"
 
-			"dump_devargs\n"
+			"dump devargs\n"
 			"    Dumps the user device list\n\n"
 
-			"dump_lcores\n"
+			"dump lcores\n"
 			"    Dumps the logical cores list\n\n"
 
-			"dump_trace\n"
+			"dump trace\n"
 			"    Dumps the tracing data to the folder according to the current EAL settings\n\n"
 
-			"dump_log_types\n"
+			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
 			"show port (port_id) speed_lanes capabilities"
@@ -9085,9 +9085,33 @@ static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
 
 /* ******************************************************************************** */
 
-struct cmd_dump_result {
+struct cmd_dump_simple_result {
 	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
 };
+static cmdline_parse_token_string_t cmd_dump_simple_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_simple_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"physmem#"
+		"socket_mem#"
+		"memzone#"
+		"struct_sizes#"
+		"ring#"
+		"mempool#"
+		"devargs#"
+		"lcores#"
+		"trace#"
+		"log_types"
+);
+static cmdline_parse_token_string_t cmd_dump_named_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"ring#"
+		"mempool#"
+);
+static cmdline_parse_token_string_t cmd_dump_named_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, name, NULL);
 
 static void
 dump_struct_sizes(void)
@@ -9099,7 +9123,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)
@@ -9114,7 +9137,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)
@@ -9149,113 +9171,74 @@ dump_socket_mem(FILE *f)
 	last_total = total;
 }
 
-static void cmd_dump_parsed(void *parsed_result,
-			    __rte_unused struct cmdline *cl,
-			    __rte_unused void *data)
+static void cmd_dump_simple_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
 {
-	struct cmd_dump_result *res = parsed_result;
+	struct cmd_dump_simple_result *res = parsed_result;
 
-	if (!strcmp(res->dump, "dump_physmem"))
+	if (strcmp(res->obj, "physmem") == 0)
 		rte_dump_physmem_layout(stdout);
-	else if (!strcmp(res->dump, "dump_socket_mem"))
+	else if (strcmp(res->obj, "socket_mem") == 0)
 		dump_socket_mem(stdout);
-	else if (!strcmp(res->dump, "dump_memzone"))
+	else if (strcmp(res->obj, "memzone") == 0)
 		rte_memzone_dump(stdout);
-	else if (!strcmp(res->dump, "dump_struct_sizes"))
+	else if (strcmp(res->obj, "struct_sizes") == 0)
 		dump_struct_sizes();
-	else if (!strcmp(res->dump, "dump_ring"))
-		rte_ring_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_mempool"))
-		rte_mempool_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_devargs"))
+	else if (strcmp(res->obj, "ring") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_ring_list_dump(stdout);
+		} else {
+			struct rte_ring *r;
+			r = rte_ring_lookup(res->name);
+			if (r == NULL) {
+				cmdline_printf(cl, "Cannot find ring\n");
+				return;
+			}
+			rte_ring_dump(stdout, r);
+		}
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_mempool_list_dump(stdout);
+		} else {
+			struct rte_mempool *mp;
+			mp = rte_mempool_lookup(res->name);
+			if (mp == NULL) {
+				cmdline_printf(cl, "Cannot find mempool\n");
+				return;
+			}
+			rte_mempool_dump(stdout, mp);
+		}
+	} else if (strcmp(res->obj, "devargs") == 0)
 		rte_devargs_dump(stdout);
-	else if (!strcmp(res->dump, "dump_lcores"))
+	else if (strcmp(res->obj, "lcores") == 0)
 		rte_lcore_dump(stdout);
-#ifndef RTE_EXEC_ENV_WINDOWS
-	else if (!strcmp(res->dump, "dump_trace"))
+	else if (strcmp(res->obj, "trace") == 0)
+#ifdef RTE_EXEC_ENV_WINDOWS
+		cmdline_printf(cl, "trace is not supported on Windows\n");
+#else
 		rte_trace_save();
 #endif
-	else if (!strcmp(res->dump, "dump_log_types"))
+	else if (strcmp(res->obj, "log_types") == 0)
 		rte_log_dump(stdout);
 }
 
-static cmdline_parse_token_string_t cmd_dump_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
-		"" /* defined at init */);
-
-static void
-cmd_dump_init(void)
-{
-	cmd_dump_dump.string_data.str =
-		"dump_physmem#"
-		"dump_memzone#"
-		"dump_socket_mem#"
-		"dump_struct_sizes#"
-		"dump_ring#"
-		"dump_mempool#"
-		"dump_devargs#"
-		"dump_lcores#"
-#ifndef RTE_EXEC_ENV_WINDOWS
-		"dump_trace#"
-#endif
-		"dump_log_types";
-}
-
-static cmdline_parse_inst_t cmd_dump = {
-	.f = cmd_dump_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "Dump status",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_dump,
+static cmdline_parse_inst_t cmd_dump_simple = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "Dump objects",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_simple_obj,
 		NULL,
 	},
 };
-
-/* ******************************************************************************** */
-
-struct cmd_dump_one_result {
-	cmdline_fixed_string_t dump;
-	cmdline_fixed_string_t name;
-};
-
-static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
-				__rte_unused void *data)
-{
-	struct cmd_dump_one_result *res = parsed_result;
-
-	if (!strcmp(res->dump, "dump_ring")) {
-		struct rte_ring *r;
-		r = rte_ring_lookup(res->name);
-		if (r == NULL) {
-			cmdline_printf(cl, "Cannot find ring\n");
-			return;
-		}
-		rte_ring_dump(stdout, r);
-	} else if (!strcmp(res->dump, "dump_mempool")) {
-		struct rte_mempool *mp;
-		mp = rte_mempool_lookup(res->name);
-		if (mp == NULL) {
-			cmdline_printf(cl, "Cannot find mempool\n");
-			return;
-		}
-		rte_mempool_dump(stdout, mp);
-	}
-}
-
-static cmdline_parse_token_string_t cmd_dump_one_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
-				 "dump_ring#dump_mempool");
-
-static cmdline_parse_token_string_t cmd_dump_one_name =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
-
-static cmdline_parse_inst_t cmd_dump_one = {
-	.f = cmd_dump_one_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_one_dump,
-		(void *)&cmd_dump_one_name,
+static cmdline_parse_inst_t cmd_dump_named = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "dump ring|mempool <name>: Dump one ring/mempool",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_named_obj,
+		(void *)&cmd_dump_named_name,
 		NULL,
 	},
 };
@@ -13997,8 +13980,8 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_config_rss_hash_key,
 	&cmd_config_rss_hash_algo,
 	&cmd_cleanup_txq_mbufs,
-	&cmd_dump,
-	&cmd_dump_one,
+	&cmd_dump_simple,
+	&cmd_dump_named,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
@@ -14131,7 +14114,6 @@ init_cmdline(void)
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
-	cmd_dump_init();
 
 	count = 0;
 	for (i = 0; builtin_ctx[i] != NULL; i++)
doc/guides/testpmd_app_ug/testpmd_funcs.rst +10 -10
index fefcf5b419..e4bef31d06 100644
@@ -568,70 +568,70 @@ dump physmem
 
 Dumps all physical memory segment layouts::
 
-   testpmd> dump_physmem
+   testpmd> dump physmem
 
 dump memzone
 ~~~~~~~~~~~~
 
 Dumps the layout of all memory zones::
 
-   testpmd> dump_memzone
+   testpmd> dump memzone
 
 dump socket memory
 ~~~~~~~~~~~~~~~~~~
 
 Dumps the memory usage of all sockets::
 
-   testpmd> dump_socket_mem
+   testpmd> dump socket_mem
 
 dump struct size
 ~~~~~~~~~~~~~~~~
 
 Dumps the size of all memory structures::
 
-   testpmd> dump_struct_sizes
+   testpmd> dump struct_sizes
 
 dump ring
 ~~~~~~~~~
 
 Dumps the status of all or specific element in DPDK rings::
 
-   testpmd> dump_ring [ring_name]
+   testpmd> dump ring [ring_name]
 
 dump mempool
 ~~~~~~~~~~~~
 
 Dumps the statistics of all or specific memory pool::
 
-   testpmd> dump_mempool [mempool_name]
+   testpmd> dump mempool [mempool_name]
 
 dump devargs
 ~~~~~~~~~~~~
 
 Dumps the user device list::
 
-   testpmd> dump_devargs
+   testpmd> dump devargs
 
 dump lcores
 ~~~~~~~~~~~
 
 Dumps the logical cores list::
 
-   testpmd> dump_lcores
+   testpmd> dump lcores
 
 dump trace
 ~~~~~~~~~~
 
 Dumps the tracing data to the folder according to the current EAL settings::
 
-   testpmd> dump_trace
+   testpmd> dump trace
 
 dump log types
 ~~~~~~~~~~~~~~
 
 Dumps the log level for all the dpdk modules::
 
-   testpmd> dump_log_types
+   testpmd> dump log_types
 
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.51.0
#63 lore raw

PATCH v5 6/7 app/testpmd: add commands to dump mbuf history

In reply to Thomas Monjalon

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

---
 app/test-pmd/cmdline.c                      | 174 ++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  13 ++
 2 files changed, 187 insertions(+)
app/test-pmd/cmdline.c +174 -0
index 487a95cd16..e2d5b6696f 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump mbuf history all [file_name]\n"
+			"    Dumps the mbuf history for all mempools\n\n"
+
+			"dump mbuf history mempool <mempool_name> [file_name]\n"
+			"    Dumps the history for a specific mempool\n\n"
+
+			"dump mbuf history one <mbuf_addr> [file_name]\n"
+			"    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9243,6 +9253,164 @@ static cmdline_parse_inst_t cmd_dump_named = {
 	},
 };
 
+struct cmd_dump_mbuf_history_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mbuf;
+	cmdline_fixed_string_t history;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
+	cmdline_fixed_string_t addr;
+	cmdline_fixed_string_t file;
+};
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mbuf =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, mbuf, "mbuf");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_history =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, history, "history");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_one =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "one");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mempool =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "mempool");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_all =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "all");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, name, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_addr =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, addr, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, file, NULL);
+
+static void cmd_dump_mbuf_history_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_result *res = parsed_result;
+	FILE *out = stdout;
+
+	if (strcmp(res->file, "") != 0) {
+		out = fopen(res->file, "w");
+		if (out == NULL) {
+			cmdline_printf(cl,
+					"Failed to open file '%s'\n",
+					res->file);
+			return;
+		}
+	}
+
+	if (strcmp(res->obj, "all") == 0) {
+		rte_mbuf_history_dump_all(out);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump written in '%s'\n",
+					res->file);
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		struct rte_mempool *mp = rte_mempool_lookup(res->name);
+		if (mp == NULL) {
+			cmdline_printf(cl,
+					"Failed to find mempool '%s'\n",
+					res->name);
+			return;
+		}
+		rte_mbuf_history_dump_mempool(out, mp);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mempool '%s' written in '%s'\n",
+					res->name, res->file);
+	} else if (strcmp(res->obj, "one") == 0) {
+		struct rte_mbuf *mbuf;
+		uintptr_t mbuf_addr;
+		if (sscanf(res->addr, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+			cmdline_printf(cl,
+					"Invalid mbuf pointer format. Use 0x<address>\n");
+			return;
+		}
+		mbuf = (struct rte_mbuf *)mbuf_addr;
+		rte_mbuf_history_dump(out, mbuf);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mbuf '%p' written in '%s'\n",
+					mbuf, res->file);
+	}
+
+	if (out != stdout)
+		fclose(out);
+}
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_one_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history one <address>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_one,
+		(void *)&cmd_dump_mbuf_history_addr,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_one_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history one <address> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_one,
+		(void *)&cmd_dump_mbuf_history_addr,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_mempool_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history mempool <name>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_mempool,
+		(void *)&cmd_dump_mbuf_history_name,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_mempool_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history mempool <name> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_mempool,
+		(void *)&cmd_dump_mbuf_history_name,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_all,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_all_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_all,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13982,6 +14150,12 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump_simple,
 	&cmd_dump_named,
+	&cmd_dump_mbuf_history_all_stdout,
+	&cmd_dump_mbuf_history_all_to_file,
+	&cmd_dump_mbuf_history_mempool_stdout,
+	&cmd_dump_mbuf_history_mempool_to_file,
+	&cmd_dump_mbuf_history_one_stdout,
+	&cmd_dump_mbuf_history_one_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +13 -0
index e4bef31d06..2e984bf5f1 100644
@@ -633,6 +633,19 @@ Dumps the log level for all the dpdk modules::
 
    testpmd> dump log_types
 
+dump mbuf history
+~~~~~~~~~~~~~~~~~
+
+The mbuf history is tracked
+if enabled at compilation with ``RTE_MBUF_HISTORY_DEBUG``.
+
+This tracking can be displayed or saved to a file
+for all mbufs or specific ones selected by pointer or mempool name::
+
+   testpmd> dump mbuf history all [file]
+   testpmd> dump mbuf history mempool <mp_name> [file]
+   testpmd> dump mbuf history one <mbuf_addr> [file]
+
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.51.0
Acked-by on v5 6/7
#64 lore raw

RE: [PATCH v5 6/7] app/testpmd: add commands to dump mbuf history

Quoted 9 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 08.59

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Quoted 8 lines

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

The "one" seems superfluous. I think this would suffice:
testpmd> dump mbuf history <mbuf_addr> [file]

Quoted 4 lines

---

With or without suggested change,

#65 lore raw

Re: [PATCH v5 6/7] app/testpmd: add commands to dump mbuf history

14/10/2025 10:45, Morten Brørup:

Quoted 12 lines
Quoted 12 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 08.59

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Quoted 8 lines
Quoted 5 lines

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

The "one" seems superfluous. I think this would suffice:
testpmd> dump mbuf history <mbuf_addr> [file]

It's not superfluous :)
Without it, the cmdline library cannot distinguish easily between
dump mbuf history <mbuf_addr> [file]
and
dump mbuf history mempool <mp_name>

#66 lore raw

Re: [PATCH v5 6/7] app/testpmd: add commands to dump mbuf history

Quoted 22 lines · Thomas Monjalon

14/10/2025 10:45, Morten Brørup:

Quoted 12 lines
Quoted 12 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 08.59

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Quoted 8 lines
Quoted 5 lines

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

The "one" seems superfluous. I think this would suffice:
testpmd> dump mbuf history <mbuf_addr> [file]

Quoted 7 lines

It's not superfluous :)
Without it, the cmdline library cannot distinguish easily between
dump mbuf history <mbuf_addr> [file]
and
dump mbuf history mempool <mp_name>

The latter might read better as "dump mbuf pool history <mp_name>", which would also resolve the ambiguity.

Even without cmdline lib resolving the ambiguity, it should be easy enough for the cmdline callback to do strcmp() on the 4th parameter to check if it's the string "mempool" and then direct appropriately.

/Bruce

#67 lore raw

Re: [PATCH v5 6/7] app/testpmd: add commands to dump mbuf history

14/10/2025 11:48, Bruce Richardson:

Quoted 30 lines · Thomas Monjalon
Quoted 22 lines

14/10/2025 10:45, Morten Brørup:

Quoted 12 lines
Quoted 12 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 08.59

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Quoted 8 lines
Quoted 5 lines

Dump the history of one mbuf pool:
testpmd> dump mbuf history mempool <mp_name> [file]

Dump the history of one mbuf:
testpmd> dump mbuf history one <mbuf_addr> [file]

The "one" seems superfluous. I think this would suffice:
testpmd> dump mbuf history <mbuf_addr> [file]

Quoted 7 lines

It's not superfluous :)
Without it, the cmdline library cannot distinguish easily between
dump mbuf history <mbuf_addr> [file]
and
dump mbuf history mempool <mp_name>

Quoted 2 lines

The latter might read better as "dump mbuf pool history <mp_name>", which would also resolve the ambiguity.

I'll try that.

Quoted 3 lines

Even without cmdline lib resolving the ambiguity, it should be easy enough for the cmdline callback to do strcmp() on the 4th parameter to check if it's the string "mempool" and then direct appropriately.

It is already doing strcmp(), but first, cmdline parsing must not be ambiguous.

#68 lore raw

PATCH v5 7/7 usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 doc/guides/howto/debug_troubleshoot.rst |   3 +-
 doc/guides/prog_guide/mbuf_lib.rst      |   2 +
 doc/guides/rel_notes/release_25_11.rst  |   1 +
 lib/mbuf/rte_mbuf_history.h             |   3 +
 usertools/dpdk-mbuf-history-parser.py   | 166 ++++++++++++++++++++++++
 5 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
doc/guides/howto/debug_troubleshoot.rst +2 -1
index 16feeb1e54..c19aada6f8 100644
@@ -221,7 +221,8 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
    by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
    Then the libraries will mark the mbufs,
    and more marks can be added in the application.
-   Some dump functions must be used to collect the history.
+   Some dump functions must be used to collect the history,
+   and a script can parse it.
 
 #. Lower performance between the pipeline processing stages can be
 
doc/guides/prog_guide/mbuf_lib.rst +2 -0
index ae72eecc61..382bfbdca4 100644
@@ -279,6 +279,8 @@ More marks can be added by the application
 by calling functions like ``rte_mbuf_history_mark_bulk()``.
 Then the history can be stored in a file
 by calling functions like ``rte_mbuf_history_dump_all()``.
+The dump file will be easier to read after being processed
+by the script ``dpdk-mbuf-history-parser.py``.
 
 
 Use Cases
doc/guides/rel_notes/release_25_11.rst +1 -0
index 6854090096..6c26d3be10 100644
@@ -65,6 +65,7 @@ New Features
   Added history dynamic field in mbuf (disabled by default)
   to store successive states of the mbuf lifecycle.
   Some functions were added to dump statistics.
+  A script was added to parse mbuf tracking stored in a file.
 
 * **Updated NXP DPAA2 ethernet driver.**
 
lib/mbuf/rte_mbuf_history.h +3 -0
index 915fb13dac..042570762b 100644
@@ -19,6 +19,9 @@
  * The history is stored as an atomic value (64-bit) in a dynamic field of the mbuf,
  * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
  * Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores.
+ *
+ * After dumping the history in a file,
+ * the script dpdk-mbuf-history-parser.py can be used for parsing.
  */
 
 #include <rte_common.h>
usertools/dpdk-mbuf-history-parser.py new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
2.51.0
#69 lore raw

v6 cover add mbuf debug capabilities

In reply to Shani Peretz

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

---

v6 changes:
- simplify testpmd commands
- use enum op type
- rename Tx ops
- mark free before freeing
- mark out of sanity check loop

v5 change:
- fix MSVC build in testpmd

v4 changes:
- fix/rewrite testpmd commands
- fix python script
- fix thread safety
- fix checks
- fix logs
- change config (no Meson option)
- add documentation

v3 changes:
- use atomic
- fix prefix
- add asserts
- reformat dump
- remove #ifdef clutter
- remove mlx5 patch

v2 changes:
- move to mbuf in dynamic field

v1:
- mempool feature

---

Shani Peretz (3):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (4):
doc: explain debug options in mbuf guide
mbuf: move header include for logs app/testpmd: use space separator in dump commands app/testpmd: add commands to dump mbuf history

 app/test-pmd/cmdline.c                      | 309 ++++++++++++++------
 config/rte_config.h                         |   1 +
 doc/guides/howto/debug_troubleshoot.rst     |   7 +
 doc/guides/prog_guide/mbuf_lib.rst          |  18 +-
 doc/guides/rel_notes/release_25_11.rst      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  33 ++-
 lib/ethdev/rte_ethdev.h                     |  11 +
 lib/mbuf/mbuf_history.c                     | 229 +++++++++++++++
 lib/mbuf/mbuf_log.h                         |   2 +
 lib/mbuf/meson.build                        |   2 +
 lib/mbuf/rte_mbuf.c                         |   5 +-
 lib/mbuf/rte_mbuf.h                         |  15 +-
 lib/mbuf/rte_mbuf_dyn.h                     |  18 ++
 lib/mbuf/rte_mbuf_history.h                 | 206 +++++++++++++
 usertools/dpdk-mbuf-history-parser.py       | 166 +++++++++++
 15 files changed, 923 insertions(+), 106 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
Signature · 1 line
2.51.0
#70 lore raw

PATCH v6 1/7 doc: explain debug options in mbuf guide

Mention RTE_LIBRTE_MBUF_DEBUG and RTE_ENABLE_ASSERT which enable many debug checks in the mbuf library.

---
 doc/guides/prog_guide/mbuf_lib.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
doc/guides/prog_guide/mbuf_lib.rst +7 -2
index 4ad2a21f3f..badc0f3501 100644
@@ -266,8 +266,13 @@ can be found in several of the sample applications, for example, the IPv4 Multic
 Debug
 -----
 
-In debug mode, the functions of the mbuf library perform sanity checks before any operation (such as, buffer corruption,
-bad type, and so on).
+When ``RTE_LIBRTE_MBUF_DEBUG`` is enabled at compilation,
+some major mbuf operations (clone, copy, freeing)
+perform sanity checks (such as buffer corruption, bad type, and so on).
+
+When ``RTE_ENABLE_ASSERT`` is enabled,
+more basic checks are done in many functions.
+
 
 Use Cases
 ---------
Signature · 1 line
2.51.0
#71 lore raw

PATCH v6 2/7 mbuf: move header include for logs

In reply to Thomas Monjalon

The header mbuf_log.h depends on rte_log.h, so it should include it. After this move, no need to include rte_log.h in addition of mbuf_log.h.

---
 lib/mbuf/mbuf_log.h | 2 ++
 lib/mbuf/rte_mbuf.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/mbuf/mbuf_log.h +2 -0
index 8feaf20747..f163cbd71c 100644
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 
+#include <rte_log.h>
+
 extern int mbuf_logtype;
 #define RTE_LOGTYPE_MBUF	mbuf_logtype
 #define MBUF_LOG(level, ...) \
lib/mbuf/rte_mbuf.c +0 -1
index 9e7731a8a2..22d7cfc475 100644
@@ -12,7 +12,6 @@
 #include <eal_export.h>
 #include <rte_debug.h>
 #include <rte_common.h>
-#include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
Signature · 1 line
2.51.0
#72 lore raw

PATCH v6 3/7 mbuf: record mbuf operations history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/rte_config.h                     |   1 +
 doc/guides/howto/debug_troubleshoot.rst |   6 +
 doc/guides/prog_guide/mbuf_lib.rst      |   7 +
 doc/guides/rel_notes/release_25_11.rst  |   6 +
 lib/mbuf/mbuf_history.c                 | 229 ++++++++++++++++++++++++
 lib/mbuf/meson.build                    |   2 +
 lib/mbuf/rte_mbuf.c                     |   4 +
 lib/mbuf/rte_mbuf.h                     |  15 +-
 lib/mbuf/rte_mbuf_dyn.h                 |  18 ++
 lib/mbuf/rte_mbuf_history.h             | 203 +++++++++++++++++++++
 10 files changed, 490 insertions(+), 1 deletion(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/rte_config.h +1 -0
index 05344e2619..aee137717b 100644
@@ -64,6 +64,7 @@
 
 /* mbuf defines */
 #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
+/* RTE_MBUF_HISTORY_DEBUG is not set */
 
 /* ether defines */
 #define RTE_MAX_QUEUES_PER_PORT 1024
doc/guides/howto/debug_troubleshoot.rst +6 -0
index df69fa8bcc..16feeb1e54 100644
@@ -217,6 +217,12 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
      desired value and frequently uses ``rte_pktmbuf_prefree_seg`` and does
      not release MBUF back to mempool.
 
+   The mbuf lifecycle can be tracked
+   by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
+   Then the libraries will mark the mbufs,
+   and more marks can be added in the application.
+   Some dump functions must be used to collect the history.
+
 #. Lower performance between the pipeline processing stages can be
 
    * The NUMA instance for packets or objects from NIC, mempool, and ring
doc/guides/prog_guide/mbuf_lib.rst +7 -0
index badc0f3501..ae72eecc61 100644
@@ -273,6 +273,13 @@ perform sanity checks (such as buffer corruption, bad type, and so on).
 When ``RTE_ENABLE_ASSERT`` is enabled,
 more basic checks are done in many functions.
 
+When ``RTE_MBUF_HISTORY_DEBUG`` is enabled,
+the mbuf lifecycle is tracked.
+More marks can be added by the application
+by calling functions like ``rte_mbuf_history_mark_bulk()``.
+Then the history can be stored in a file
+by calling functions like ``rte_mbuf_history_dump_all()``.
+
 
 Use Cases
 ---------
doc/guides/rel_notes/release_25_11.rst +6 -0
index c3b94e1896..6854090096 100644
@@ -60,6 +60,12 @@ New Features
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
   and some devices already support this speed.
 
+* **Added mbuf tracking for debug.**
+
+  Added history dynamic field in mbuf (disabled by default)
+  to store successive states of the mbuf lifecycle.
+  Some functions were added to dump statistics.
+
 * **Updated NXP DPAA2 ethernet driver.**
 
   * Enabled software taildrop for ordered queues.
lib/mbuf/mbuf_history.c new file +229 -0

229 lines not on this page · raw message

lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +4 -0
index 22d7cfc475..d2fcb5db19 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
 	if (user_mbp_priv == NULL) {
@@ -499,6 +501,8 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 	struct rte_mbuf *m, *m_next, *pending[RTE_PKTMBUF_FREE_PENDING_SZ];
 	unsigned int idx, nb_pending = 0;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_FREE);
+
 	for (idx = 0; idx < count; idx++) {
 		m = mbufs[idx];
 		if (unlikely(m == NULL))
lib/mbuf/rte_mbuf.h +14 -1
index 06ab7502a5..95a4f9841b 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,9 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	return ret.m;
 }
 
@@ -642,9 +646,13 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
+	if (likely(rc == 0)) {
 		for (unsigned int idx = 0; idx < count; idx++)
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+	}
+
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	return rc;
 }
 
@@ -666,6 +674,7 @@ static __rte_always_inline void
 rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 	rte_mempool_put(m->pool, m);
 }
 
@@ -703,6 +712,8 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		__rte_mbuf_raw_sanity_check(m);
 	}
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_FREE);
+
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
 }
 
@@ -1013,6 +1024,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +203 -0

203 lines not on this page · raw message

Signature · 1 line
2.51.0
#73 lore raw

RE: [PATCH v6 3/7] mbuf: record mbuf operations history

lib/mbuf/mbuf_history.c line 112

Quoted 11 lines
lib/mbuf/mbuf_history.c new file +11 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated =
+		stats[RTE_MBUF_HISTORY_OP_LIB_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_PMD_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_APP_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_RX] +
+		stats[RTE_MBUF_HISTORY_OP_TX] +
+		stats[RTE_MBUF_HISTORY_OP_TX_PREP] +
+		stats[RTE_MBUF_HISTORY_OP_TX_BUSY] +
+		stats[RTE_MBUF_HISTORY_OP_ENQUEUE] +
+		stats[RTE_MBUF_HISTORY_OP_DEQUEUE];

Assuming the purpose of total_allocated is to count the mbufs not sitting available in the mempool, it's not calculated correctly. E.g. USR1 and USR2 are missing.

Instead of summing some specific states, just sum all states (for op=0; op<OP_MAX; op++) and subtract OP_NEVER and OP_LIB_FREE.

#74 lore raw

Re: [PATCH v6 3/7] mbuf: record mbuf operations history

16/10/2025 11:04, Morten Brørup:

Quoted 14 lines

lib/mbuf/mbuf_history.c line 112

Quoted 11 lines
lib/mbuf/mbuf_history.c new file +11 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated =
+		stats[RTE_MBUF_HISTORY_OP_LIB_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_PMD_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_APP_ALLOC] +
+		stats[RTE_MBUF_HISTORY_OP_RX] +
+		stats[RTE_MBUF_HISTORY_OP_TX] +
+		stats[RTE_MBUF_HISTORY_OP_TX_PREP] +
+		stats[RTE_MBUF_HISTORY_OP_TX_BUSY] +
+		stats[RTE_MBUF_HISTORY_OP_ENQUEUE] +
+		stats[RTE_MBUF_HISTORY_OP_DEQUEUE];

Assuming the purpose of total_allocated is to count the mbufs not sitting available in the mempool, it's not calculated correctly. E.g. USR1 and USR2 are missing.

Quoted 1 line

Instead of summing some specific states, just sum all states (for op=0; op<OP_MAX; op++) and subtract OP_NEVER and OP_LIB_FREE.

Good idea

#75 lore raw

PATCH v6 4/7 ethdev: mark mbufs in burst functions

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/ethdev/rte_ethdev.h +11 -0
index d23c143eed..5e250e5083 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx, RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6690,15 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX);
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts, RTE_MBUF_HISTORY_OP_TX_BUSY);
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
@@ -6785,6 +6794,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX_PREP);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
 }
 
Signature · 1 line
2.51.0
#77 lore raw

PATCH v6 5/7 app/testpmd: use space separator in dump commands

In reply to Thomas Monjalon

In order to make dump commands look like other commands which have keywords separated with space, replace these commands:
- dump_physmem
- dump_socket_mem
- dump_memzone
- dump_struct_sizes
- dump_ring [name]
- dump_mempool [name]
- dump_devargs
- dump_lcores
- dump_trace
- dump_log_types
with these ones:
- dump physmem
- dump socket_mem
- dump memzone
- dump struct_sizes
- dump ring [name]
- dump mempool [name]
- dump devargs
- dump lcores
- dump trace
- dump log_types

Both parsing functions (with and without name argument) are merged together.

The function cmd_dump_init() is removed
as it seems useless to define tokens at runtime.

Trace is explicitly warned as not supported on Windows, because #ifndef in the tokens is not possible with MSVC.

---
 app/test-pmd/cmdline.c                      | 196 +++++++++-----------
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  20 +-
 2 files changed, 99 insertions(+), 117 deletions(-)
app/test-pmd/cmdline.c +89 -107
index 3731fba370..487a95cd16 100644
@@ -266,34 +266,34 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"show port (port_id) flow_ctrl"
 			"	Show flow control info of a port.\n\n"
 
-			"dump_physmem\n"
+			"dump physmem\n"
 			"    Dumps all physical memory segment layouts\n\n"
 
-			"dump_socket_mem\n"
+			"dump socket_mem\n"
 			"    Dumps the memory usage of all sockets\n\n"
 
-			"dump_memzone\n"
+			"dump memzone\n"
 			"    Dumps the layout of all memory zones\n\n"
 
-			"dump_struct_sizes\n"
+			"dump struct_sizes\n"
 			"    Dumps the size of all memory structures\n\n"
 
-			"dump_ring\n"
+			"dump ring [name]\n"
 			"    Dumps the status of all or specific element in DPDK rings\n\n"
 
-			"dump_mempool\n"
+			"dump mempool [name]\n"
 			"    Dumps the statistics of all or specific memory pool\n\n"
 
-			"dump_devargs\n"
+			"dump devargs\n"
 			"    Dumps the user device list\n\n"
 
-			"dump_lcores\n"
+			"dump lcores\n"
 			"    Dumps the logical cores list\n\n"
 
-			"dump_trace\n"
+			"dump trace\n"
 			"    Dumps the tracing data to the folder according to the current EAL settings\n\n"
 
-			"dump_log_types\n"
+			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
 			"show port (port_id) speed_lanes capabilities"
@@ -9085,9 +9085,33 @@ static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
 
 /* ******************************************************************************** */
 
-struct cmd_dump_result {
+struct cmd_dump_simple_result {
 	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
 };
+static cmdline_parse_token_string_t cmd_dump_simple_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_simple_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"physmem#"
+		"socket_mem#"
+		"memzone#"
+		"struct_sizes#"
+		"ring#"
+		"mempool#"
+		"devargs#"
+		"lcores#"
+		"trace#"
+		"log_types"
+);
+static cmdline_parse_token_string_t cmd_dump_named_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"ring#"
+		"mempool#"
+);
+static cmdline_parse_token_string_t cmd_dump_named_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, name, NULL);
 
 static void
 dump_struct_sizes(void)
@@ -9099,7 +9123,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)
@@ -9114,7 +9137,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)
@@ -9149,113 +9171,74 @@ dump_socket_mem(FILE *f)
 	last_total = total;
 }
 
-static void cmd_dump_parsed(void *parsed_result,
-			    __rte_unused struct cmdline *cl,
-			    __rte_unused void *data)
+static void cmd_dump_simple_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
 {
-	struct cmd_dump_result *res = parsed_result;
+	struct cmd_dump_simple_result *res = parsed_result;
 
-	if (!strcmp(res->dump, "dump_physmem"))
+	if (strcmp(res->obj, "physmem") == 0)
 		rte_dump_physmem_layout(stdout);
-	else if (!strcmp(res->dump, "dump_socket_mem"))
+	else if (strcmp(res->obj, "socket_mem") == 0)
 		dump_socket_mem(stdout);
-	else if (!strcmp(res->dump, "dump_memzone"))
+	else if (strcmp(res->obj, "memzone") == 0)
 		rte_memzone_dump(stdout);
-	else if (!strcmp(res->dump, "dump_struct_sizes"))
+	else if (strcmp(res->obj, "struct_sizes") == 0)
 		dump_struct_sizes();
-	else if (!strcmp(res->dump, "dump_ring"))
-		rte_ring_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_mempool"))
-		rte_mempool_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_devargs"))
+	else if (strcmp(res->obj, "ring") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_ring_list_dump(stdout);
+		} else {
+			struct rte_ring *r;
+			r = rte_ring_lookup(res->name);
+			if (r == NULL) {
+				cmdline_printf(cl, "Cannot find ring\n");
+				return;
+			}
+			rte_ring_dump(stdout, r);
+		}
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_mempool_list_dump(stdout);
+		} else {
+			struct rte_mempool *mp;
+			mp = rte_mempool_lookup(res->name);
+			if (mp == NULL) {
+				cmdline_printf(cl, "Cannot find mempool\n");
+				return;
+			}
+			rte_mempool_dump(stdout, mp);
+		}
+	} else if (strcmp(res->obj, "devargs") == 0)
 		rte_devargs_dump(stdout);
-	else if (!strcmp(res->dump, "dump_lcores"))
+	else if (strcmp(res->obj, "lcores") == 0)
 		rte_lcore_dump(stdout);
-#ifndef RTE_EXEC_ENV_WINDOWS
-	else if (!strcmp(res->dump, "dump_trace"))
+	else if (strcmp(res->obj, "trace") == 0)
+#ifdef RTE_EXEC_ENV_WINDOWS
+		cmdline_printf(cl, "trace is not supported on Windows\n");
+#else
 		rte_trace_save();
 #endif
-	else if (!strcmp(res->dump, "dump_log_types"))
+	else if (strcmp(res->obj, "log_types") == 0)
 		rte_log_dump(stdout);
 }
 
-static cmdline_parse_token_string_t cmd_dump_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
-		"" /* defined at init */);
-
-static void
-cmd_dump_init(void)
-{
-	cmd_dump_dump.string_data.str =
-		"dump_physmem#"
-		"dump_memzone#"
-		"dump_socket_mem#"
-		"dump_struct_sizes#"
-		"dump_ring#"
-		"dump_mempool#"
-		"dump_devargs#"
-		"dump_lcores#"
-#ifndef RTE_EXEC_ENV_WINDOWS
-		"dump_trace#"
-#endif
-		"dump_log_types";
-}
-
-static cmdline_parse_inst_t cmd_dump = {
-	.f = cmd_dump_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "Dump status",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_dump,
+static cmdline_parse_inst_t cmd_dump_simple = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "Dump objects",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_simple_obj,
 		NULL,
 	},
 };
-
-/* ******************************************************************************** */
-
-struct cmd_dump_one_result {
-	cmdline_fixed_string_t dump;
-	cmdline_fixed_string_t name;
-};
-
-static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
-				__rte_unused void *data)
-{
-	struct cmd_dump_one_result *res = parsed_result;
-
-	if (!strcmp(res->dump, "dump_ring")) {
-		struct rte_ring *r;
-		r = rte_ring_lookup(res->name);
-		if (r == NULL) {
-			cmdline_printf(cl, "Cannot find ring\n");
-			return;
-		}
-		rte_ring_dump(stdout, r);
-	} else if (!strcmp(res->dump, "dump_mempool")) {
-		struct rte_mempool *mp;
-		mp = rte_mempool_lookup(res->name);
-		if (mp == NULL) {
-			cmdline_printf(cl, "Cannot find mempool\n");
-			return;
-		}
-		rte_mempool_dump(stdout, mp);
-	}
-}
-
-static cmdline_parse_token_string_t cmd_dump_one_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
-				 "dump_ring#dump_mempool");
-
-static cmdline_parse_token_string_t cmd_dump_one_name =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
-
-static cmdline_parse_inst_t cmd_dump_one = {
-	.f = cmd_dump_one_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_one_dump,
-		(void *)&cmd_dump_one_name,
+static cmdline_parse_inst_t cmd_dump_named = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "dump ring|mempool <name>: Dump one ring/mempool",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_named_obj,
+		(void *)&cmd_dump_named_name,
 		NULL,
 	},
 };
@@ -13997,8 +13980,8 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_config_rss_hash_key,
 	&cmd_config_rss_hash_algo,
 	&cmd_cleanup_txq_mbufs,
-	&cmd_dump,
-	&cmd_dump_one,
+	&cmd_dump_simple,
+	&cmd_dump_named,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
@@ -14131,7 +14114,6 @@ init_cmdline(void)
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
-	cmd_dump_init();
 
 	count = 0;
 	for (i = 0; builtin_ctx[i] != NULL; i++)
doc/guides/testpmd_app_ug/testpmd_funcs.rst +10 -10
index fefcf5b419..e4bef31d06 100644
@@ -568,70 +568,70 @@ dump physmem
 
 Dumps all physical memory segment layouts::
 
-   testpmd> dump_physmem
+   testpmd> dump physmem
 
 dump memzone
 ~~~~~~~~~~~~
 
 Dumps the layout of all memory zones::
 
-   testpmd> dump_memzone
+   testpmd> dump memzone
 
 dump socket memory
 ~~~~~~~~~~~~~~~~~~
 
 Dumps the memory usage of all sockets::
 
-   testpmd> dump_socket_mem
+   testpmd> dump socket_mem
 
 dump struct size
 ~~~~~~~~~~~~~~~~
 
 Dumps the size of all memory structures::
 
-   testpmd> dump_struct_sizes
+   testpmd> dump struct_sizes
 
 dump ring
 ~~~~~~~~~
 
 Dumps the status of all or specific element in DPDK rings::
 
-   testpmd> dump_ring [ring_name]
+   testpmd> dump ring [ring_name]
 
 dump mempool
 ~~~~~~~~~~~~
 
 Dumps the statistics of all or specific memory pool::
 
-   testpmd> dump_mempool [mempool_name]
+   testpmd> dump mempool [mempool_name]
 
 dump devargs
 ~~~~~~~~~~~~
 
 Dumps the user device list::
 
-   testpmd> dump_devargs
+   testpmd> dump devargs
 
 dump lcores
 ~~~~~~~~~~~
 
 Dumps the logical cores list::
 
-   testpmd> dump_lcores
+   testpmd> dump lcores
 
 dump trace
 ~~~~~~~~~~
 
 Dumps the tracing data to the folder according to the current EAL settings::
 
-   testpmd> dump_trace
+   testpmd> dump trace
 
 dump log types
 ~~~~~~~~~~~~~~
 
 Dumps the log level for all the dpdk modules::
 
-   testpmd> dump_log_types
+   testpmd> dump log_types
 
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.51.0
#78 lore raw

Re: [PATCH v6 5/7] app/testpmd: use space separator in dump commands

Quoted 9 lines · On Tue, 14 Oct 2025 14:33:38 +0200 Thomas Monjalon <[email protected]> wrote:
app/test-pmd/cmdline.c +0 -1
@@ -9099,7 +9123,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)

app/test-pmd/cmdline.c dump_socket_mem(FILE *f) · line 9142

Quoted 7 lines
app/test-pmd/cmdline.c +0 -1
@@ -9114,7 +9137,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)

Unrelated whitespace changes in patches are discouraged.

#79 lore raw

Re: [PATCH v6 5/7] app/testpmd: use space separator in dump commands

15/10/2025 19:52, Stephen Hemminger:

Quoted 15 lines
Quoted 12 lines · On Tue, 14 Oct 2025 14:33:38 +0200 Thomas Monjalon <[email protected]> wrote:
app/test-pmd/cmdline.c +0 -1
@@ -9099,7 +9123,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)
@@ -9114,7 +9137,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
Quoted 6 lines

app/test-pmd/cmdline.c dump_socket_mem(FILE *f) · line 9142

Quoted 4 lines
app/test-pmd/cmdline.c +0 -1
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)

Unrelated whitespace changes in patches are discouraged.

It is quite related given this patch is about dump commands, including this dump_socket_mem().
But yes, no other lines are changed in this specific function. Do you really think removing extra blank lines is bad in this case?

Acked-by on v6 5/7
#80 lore raw

RE: [PATCH v6 5/7] app/testpmd: use space separator in dump commands

In reply to Thomas Monjalon
Quoted 31 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 14.34

In order to make dump commands look like other commands which have keywords separated with space, replace these commands:
- dump_physmem
- dump_socket_mem
- dump_memzone
- dump_struct_sizes
- dump_ring [name]
- dump_mempool [name]
- dump_devargs
- dump_lcores
- dump_trace
- dump_log_types
with these ones:
- dump physmem
- dump socket_mem
- dump memzone
- dump struct_sizes
- dump ring [name]
- dump mempool [name]
- dump devargs
- dump lcores
- dump trace
- dump log_types

Both parsing functions (with and without name argument) are merged together.

Quoted 8 lines

The function cmd_dump_init() is removed
as it seems useless to define tokens at runtime.

Trace is explicitly warned as not supported on Windows, because #ifndef in the tokens is not possible with MSVC.

---

#81 lore raw

PATCH v6 6/7 app/testpmd: add commands to dump mbuf history

In reply to Thomas Monjalon

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Dump the history of one mbuf:
testpmd> dump mbuf history <mbuf_addr> [file]

Dump the history of one mbuf pool:
testpmd> dump mbuf pool history <mp_name> [file]

---
 app/test-pmd/cmdline.c                      | 143 ++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  13 ++
 2 files changed, 156 insertions(+)
app/test-pmd/cmdline.c +143 -0
index 487a95cd16..cc35540115 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump mbuf history all [file_name]\n"
+			"    Dumps the mbuf history for all mempools\n\n"
+
+			"dump mbuf history <mbuf_addr> [file_name]\n"
+			"    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"
+
+			"dump mbuf pool history <mempool_name> [file_name]\n"
+			"    Dumps the history for a specific mempool\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9243,6 +9253,135 @@ static cmdline_parse_inst_t cmd_dump_named = {
 	},
 };
 
+struct cmd_dump_mbuf_history_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mbuf;
+	cmdline_fixed_string_t history;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
+	cmdline_fixed_string_t addr;
+	cmdline_fixed_string_t file;
+};
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mbuf =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, mbuf, "mbuf");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_history =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, history, "history");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_pool =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "pool");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, name, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, file, NULL);
+
+static void cmd_dump_mbuf_history_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_result *res = parsed_result;
+	FILE *out = stdout;
+
+	if (strcmp(res->file, "") != 0) {
+		out = fopen(res->file, "w");
+		if (out == NULL) {
+			cmdline_printf(cl,
+					"Failed to open file '%s'\n",
+					res->file);
+			return;
+		}
+	}
+
+	if (strcmp(res->obj, "all") == 0) {
+		rte_mbuf_history_dump_all(out);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump written in '%s'\n",
+					res->file);
+	} else if (strcmp(res->obj, "pool") == 0) {
+		struct rte_mempool *mp = rte_mempool_lookup(res->name);
+		if (mp == NULL) {
+			cmdline_printf(cl,
+					"Failed to find mempool '%s'\n",
+					res->name);
+			return;
+		}
+		rte_mbuf_history_dump_mempool(out, mp);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mempool '%s' written in '%s'\n",
+					res->name, res->file);
+	} else {
+		struct rte_mbuf *mbuf;
+		uintptr_t mbuf_addr;
+		if (sscanf(res->obj, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+			cmdline_printf(cl,
+					"Invalid mbuf pointer format. Use 0x<address>\n");
+			return;
+		}
+		mbuf = (struct rte_mbuf *)mbuf_addr;
+		rte_mbuf_history_dump(out, mbuf);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mbuf '%p' written in '%s'\n",
+					mbuf, res->file);
+	}
+
+	if (out != stdout)
+		fclose(out);
+}
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all|<address>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_obj,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all|<address> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_obj,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_pool_history_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf pool history <name>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_pool,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_name,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_pool_history_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf pool history <name> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_pool,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_name,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -13982,6 +14121,10 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump_simple,
 	&cmd_dump_named,
+	&cmd_dump_mbuf_history_stdout,
+	&cmd_dump_mbuf_history_to_file,
+	&cmd_dump_mbuf_pool_history_stdout,
+	&cmd_dump_mbuf_pool_history_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +13 -0
index e4bef31d06..f3b9a55fb2 100644
@@ -633,6 +633,19 @@ Dumps the log level for all the dpdk modules::
 
    testpmd> dump log_types
 
+dump mbuf history
+~~~~~~~~~~~~~~~~~
+
+The mbuf history is tracked
+if enabled at compilation with ``RTE_MBUF_HISTORY_DEBUG``.
+
+This tracking can be displayed or saved to a file
+for all mbufs or specific ones selected by pointer or mempool name::
+
+   testpmd> dump mbuf history all [file]
+   testpmd> dump mbuf history <mbuf_addr> [file]
+   testpmd> dump mbuf pool history <mp_name> [file]
+
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.51.0
#82 lore raw

PATCH v6 7/7 usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 doc/guides/howto/debug_troubleshoot.rst |   3 +-
 doc/guides/prog_guide/mbuf_lib.rst      |   2 +
 doc/guides/rel_notes/release_25_11.rst  |   1 +
 lib/mbuf/rte_mbuf_history.h             |   3 +
 usertools/dpdk-mbuf-history-parser.py   | 166 ++++++++++++++++++++++++
 5 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
doc/guides/howto/debug_troubleshoot.rst +2 -1
index 16feeb1e54..c19aada6f8 100644
@@ -221,7 +221,8 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
    by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
    Then the libraries will mark the mbufs,
    and more marks can be added in the application.
-   Some dump functions must be used to collect the history.
+   Some dump functions must be used to collect the history,
+   and a script can parse it.
 
 #. Lower performance between the pipeline processing stages can be
 
doc/guides/prog_guide/mbuf_lib.rst +2 -0
index ae72eecc61..382bfbdca4 100644
@@ -279,6 +279,8 @@ More marks can be added by the application
 by calling functions like ``rte_mbuf_history_mark_bulk()``.
 Then the history can be stored in a file
 by calling functions like ``rte_mbuf_history_dump_all()``.
+The dump file will be easier to read after being processed
+by the script ``dpdk-mbuf-history-parser.py``.
 
 
 Use Cases
doc/guides/rel_notes/release_25_11.rst +1 -0
index 6854090096..6c26d3be10 100644
@@ -65,6 +65,7 @@ New Features
   Added history dynamic field in mbuf (disabled by default)
   to store successive states of the mbuf lifecycle.
   Some functions were added to dump statistics.
+  A script was added to parse mbuf tracking stored in a file.
 
 * **Updated NXP DPAA2 ethernet driver.**
 
lib/mbuf/rte_mbuf_history.h +3 -0
index f5f95a0c60..c4ca38e746 100644
@@ -19,6 +19,9 @@
  * The history is stored as an atomic value (64-bit) in a dynamic field of the mbuf,
  * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
  * Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores.
+ *
+ * After dumping the history in a file,
+ * the script dpdk-mbuf-history-parser.py can be used for parsing.
  */
 
 #include <rte_common.h>
usertools/dpdk-mbuf-history-parser.py new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
2.51.0
Acked-by on v6 7/7
#83 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

Thomas Monjalon, Oct 14, 2025 at 14:33:

Quoted 11 lines

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---

#84 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon
Quoted 10 lines · On Tue, 14 Oct 2025 14:33:40 +0200 Thomas Monjalon <[email protected]> wrote:

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

Minor stuff.

$ flake8 --max-line-length=100 dpdk-mbuf-history-parser.py 
dpdk-mbuf-history-parser.py:14:1: F401 'sys' imported but unused
dpdk-mbuf-history-parser.py:29:27: E203 whitespace before ':'
#85 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

15/10/2025 19:50, Stephen Hemminger:

Quoted 12 lines
Quoted 9 lines · On Tue, 14 Oct 2025 14:33:40 +0200 Thomas Monjalon <[email protected]> wrote:

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

Quoted 7 lines
Quoted 1 line

Minor stuff.

$ flake8 --max-line-length=100 dpdk-mbuf-history-parser.py 
dpdk-mbuf-history-parser.py:14:1: F401 'sys' imported but unused
dpdk-mbuf-history-parser.py:29:27: E203 whitespace before ':'

Interesting, thanks.

I'm a bit lost about Python linters.
I ran black, should I run flake8 + black? something else?

#86 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

Thomas Monjalon, Oct 15, 2025 at 21:11:

Quoted 11 lines

15/10/2025 19:50, Stephen Hemminger:

Quoted 5 lines

Minor stuff.

$ flake8 --max-line-length=100 dpdk-mbuf-history-parser.py 
dpdk-mbuf-history-parser.py:14:1: F401 'sys' imported but unused
dpdk-mbuf-history-parser.py:29:27: E203 whitespace before ':'

Interesting, thanks.

I'm a bit lost about Python linters.
I ran black, should I run flake8 + black? something else?

Just black. Flake8 style is completely obsolete. The unused import warning is legit though.

We should have a centralized python linter process in DPDK. The main issue is that most of the code will not pass as it is :D

Signature · 1 line
Robin
Quoted 1 line

Do not pick the flowers.

#87 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

Quoted 10 lines · Robin Jarry

Thomas Monjalon, Oct 15, 2025 at 21:11:

Quoted 9 lines

15/10/2025 19:50, Stephen Hemminger:

Quoted 5 lines

Minor stuff.

$ flake8 --max-line-length=100 dpdk-mbuf-history-parser.py 
dpdk-mbuf-history-parser.py:14:1: F401 'sys' imported but unused
dpdk-mbuf-history-parser.py:29:27: E203 whitespace before ':'

Interesting, thanks.

Quoted 9 lines
Quoted 2 lines

I'm a bit lost about Python linters.
I ran black, should I run flake8 + black? something else?

Just black. Flake8 style is completely obsolete. The unused import warning is legit though.

We should have a centralized python linter process in DPDK. The main issue is that most of the code will not pass as it is :D

... yet!

For python scripts in DPDK I wouldn't have a major issue about having a patchset with the results of a black run on them. History tracking of the python files is not as important as for the C files, since they don't have that many bug fixes on them to root cause. Once we get everything nicely formatted then we can mandate proper formatting going forward (and integrate into CI perhaps).

/Bruce

#88 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

16/10/2025 10:10, Bruce Richardson:

Quoted 20 lines · Robin Jarry
Quoted 10 lines

Thomas Monjalon, Oct 15, 2025 at 21:11:

Quoted 9 lines

15/10/2025 19:50, Stephen Hemminger:

Quoted 5 lines

Minor stuff.

$ flake8 --max-line-length=100 dpdk-mbuf-history-parser.py 
dpdk-mbuf-history-parser.py:14:1: F401 'sys' imported but unused
dpdk-mbuf-history-parser.py:29:27: E203 whitespace before ':'

Interesting, thanks.

Quoted 9 lines
Quoted 2 lines

I'm a bit lost about Python linters.
I ran black, should I run flake8 + black? something else?

Just black. Flake8 style is completely obsolete. The unused import warning is legit though.

We should have a centralized python linter process in DPDK. The main issue is that most of the code will not pass as it is :D

Quoted 8 lines

... yet!

For python scripts in DPDK I wouldn't have a major issue about having a patchset with the results of a black run on them. History tracking of the python files is not as important as for the C files, since they don't have that many bug fixes on them to root cause. Once we get everything nicely formatted then we can mandate proper formatting going forward (and integrate into CI perhaps).

I fully agree.

#89 lore raw

Re: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

Thomas Monjalon, Oct 16, 2025 at 10:42:

Quoted 7 lines

16/10/2025 10:10, Bruce Richardson:

Quoted 6 lines · Robin Jarry
Quoted 3 lines

We should have a centralized python linter process in DPDK. The main issue is that most of the code will not pass as it is :D

... yet!

Quoted 8 lines
Quoted 6 lines

For python scripts in DPDK I wouldn't have a major issue about having a patchset with the results of a black run on them. History tracking of the python files is not as important as for the C files, since they don't have that many bug fixes on them to root cause. Once we get everything nicely formatted then we can mandate proper formatting going forward (and integrate into CI perhaps).

I fully agree.

I'll draft a series that introduces *some* python discipline in DPDK, then :)

Signature · 1 line
Robin
Quoted 1 line

Filmed before a live audience.

Acked-by on v6 7/7
#90 lore raw

RE: [PATCH v6 7/7] usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon
Quoted 9 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 14 October 2025 14.34

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

Quoted 5 lines

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---

I haven't reviewed the code, so I hope someone else does. For the concept of this script,

#91 lore raw

v7 cover add mbuf debug capabilities

In reply to Shani Peretz

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

---

v7 changes:
- loop for sum of allocated mbufs
- remove unused Python import

v6 changes:
- simplify testpmd commands
- use enum op type
- rename Tx ops
- mark free before freeing
- mark out of sanity check loop

v5 change:
- fix MSVC build in testpmd

v4 changes:
- fix/rewrite testpmd commands
- fix python script
- fix thread safety
- fix checks
- fix logs
- change config (no Meson option)
- add documentation

v3 changes:
- use atomic
- fix prefix
- add asserts
- reformat dump
- remove #ifdef clutter
- remove mlx5 patch

v2 changes:
- move to mbuf in dynamic field

v1:
- mempool feature

---

Shani Peretz (3):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (4):
doc: explain debug options in mbuf guide
mbuf: move header include for logs app/testpmd: use space separator in dump commands app/testpmd: add commands to dump mbuf history

 app/test-pmd/cmdline.c                      | 309 ++++++++++++++------
 config/rte_config.h                         |   1 +
 doc/guides/howto/debug_troubleshoot.rst     |   7 +
 doc/guides/prog_guide/mbuf_lib.rst          |  18 +-
 doc/guides/rel_notes/release_25_11.rst      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  33 ++-
 lib/ethdev/rte_ethdev.h                     |  11 +
 lib/mbuf/mbuf_history.c                     | 223 ++++++++++++++
 lib/mbuf/mbuf_log.h                         |   2 +
 lib/mbuf/meson.build                        |   2 +
 lib/mbuf/rte_mbuf.c                         |   5 +-
 lib/mbuf/rte_mbuf.h                         |  15 +-
 lib/mbuf/rte_mbuf_dyn.h                     |  18 ++
 lib/mbuf/rte_mbuf_history.h                 | 207 +++++++++++++
 usertools/dpdk-mbuf-history-parser.py       | 165 +++++++++++
 15 files changed, 917 insertions(+), 106 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
Signature · 1 line
2.51.0
#92 lore raw

PATCH v7 1/7 doc: explain debug options in mbuf guide

Mention RTE_LIBRTE_MBUF_DEBUG and RTE_ENABLE_ASSERT which enable many debug checks in the mbuf library.

---
 doc/guides/prog_guide/mbuf_lib.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
doc/guides/prog_guide/mbuf_lib.rst +7 -2
index 4ad2a21f3f..badc0f3501 100644
@@ -266,8 +266,13 @@ can be found in several of the sample applications, for example, the IPv4 Multic
 Debug
 -----
 
-In debug mode, the functions of the mbuf library perform sanity checks before any operation (such as, buffer corruption,
-bad type, and so on).
+When ``RTE_LIBRTE_MBUF_DEBUG`` is enabled at compilation,
+some major mbuf operations (clone, copy, freeing)
+perform sanity checks (such as buffer corruption, bad type, and so on).
+
+When ``RTE_ENABLE_ASSERT`` is enabled,
+more basic checks are done in many functions.
+
 
 Use Cases
 ---------
Signature · 1 line
2.51.0
#94 lore raw

PATCH v7 2/7 mbuf: move header include for logs

In reply to Thomas Monjalon

The header mbuf_log.h depends on rte_log.h, so it should include it. After this move, no need to include rte_log.h in addition of mbuf_log.h.

---
 lib/mbuf/mbuf_log.h | 2 ++
 lib/mbuf/rte_mbuf.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
lib/mbuf/mbuf_log.h +2 -0
index 8feaf20747..f163cbd71c 100644
@@ -1,5 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause */
 
+#include <rte_log.h>
+
 extern int mbuf_logtype;
 #define RTE_LOGTYPE_MBUF	mbuf_logtype
 #define MBUF_LOG(level, ...) \
lib/mbuf/rte_mbuf.c +0 -1
index 9e7731a8a2..22d7cfc475 100644
@@ -12,7 +12,6 @@
 #include <eal_export.h>
 #include <rte_debug.h>
 #include <rte_common.h>
-#include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
Signature · 1 line
2.51.0
#95 lore raw

PATCH v7 3/7 mbuf: record mbuf operations history

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

This feature is designed to monitor the lifecycle of mbufs as they move between the application and the PMD. It will allow to track the operations and transitions of each mbuf throughout the system, helping in debugging and understanding objects flow.

As a debug feature impacting the data path, it is disabled by default.

The implementation uses a dynamic field to store a 64-bit atomic history value in each mbuf. Each operation is represented by a 4-bit value, allowing up to 16 operations to be tracked. Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores. The dynamic field is automatically initialized when the first mbuf pool is created.

Some operations done in the mbuf library are marked.
More operations from other libraries or the application can be marked.

---
 config/rte_config.h                     |   1 +
 doc/guides/howto/debug_troubleshoot.rst |   6 +
 doc/guides/prog_guide/mbuf_lib.rst      |   7 +
 doc/guides/rel_notes/release_25_11.rst  |   6 +
 lib/mbuf/mbuf_history.c                 | 223 ++++++++++++++++++++++++
 lib/mbuf/meson.build                    |   2 +
 lib/mbuf/rte_mbuf.c                     |   4 +
 lib/mbuf/rte_mbuf.h                     |  15 +-
 lib/mbuf/rte_mbuf_dyn.h                 |  18 ++
 lib/mbuf/rte_mbuf_history.h             | 204 ++++++++++++++++++++++
 10 files changed, 485 insertions(+), 1 deletion(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
config/rte_config.h +1 -0
index 05344e2619..aee137717b 100644
@@ -64,6 +64,7 @@
 
 /* mbuf defines */
 #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
+/* RTE_MBUF_HISTORY_DEBUG is not set */
 
 /* ether defines */
 #define RTE_MAX_QUEUES_PER_PORT 1024
doc/guides/howto/debug_troubleshoot.rst +6 -0
index df69fa8bcc..16feeb1e54 100644
@@ -217,6 +217,12 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
      desired value and frequently uses ``rte_pktmbuf_prefree_seg`` and does
      not release MBUF back to mempool.
 
+   The mbuf lifecycle can be tracked
+   by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
+   Then the libraries will mark the mbufs,
+   and more marks can be added in the application.
+   Some dump functions must be used to collect the history.
+
 #. Lower performance between the pipeline processing stages can be
 
    * The NUMA instance for packets or objects from NIC, mempool, and ring
doc/guides/prog_guide/mbuf_lib.rst +7 -0
index badc0f3501..ae72eecc61 100644
@@ -273,6 +273,13 @@ perform sanity checks (such as buffer corruption, bad type, and so on).
 When ``RTE_ENABLE_ASSERT`` is enabled,
 more basic checks are done in many functions.
 
+When ``RTE_MBUF_HISTORY_DEBUG`` is enabled,
+the mbuf lifecycle is tracked.
+More marks can be added by the application
+by calling functions like ``rte_mbuf_history_mark_bulk()``.
+Then the history can be stored in a file
+by calling functions like ``rte_mbuf_history_dump_all()``.
+
 
 Use Cases
 ---------
doc/guides/rel_notes/release_25_11.rst +6 -0
index 3c32b26e3b..4d6a02179a 100644
@@ -71,6 +71,12 @@ New Features
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
   and some devices already support this speed.
 
+* **Added mbuf tracking for debug.**
+
+  Added history dynamic field in mbuf (disabled by default)
+  to store successive states of the mbuf lifecycle.
+  Some functions were added to dump statistics.
+
 * **Updated NXP DPAA2 ethernet driver.**
 
   * Enabled software taildrop for ordered queues.
lib/mbuf/mbuf_history.c new file +223 -0

223 lines not on this page · raw message

lib/mbuf/meson.build +2 -0
index 0435c5e628..a394db2b19 100644
@@ -2,6 +2,7 @@
 # Copyright(c) 2017 Intel Corporation
 
 sources = files(
+        'mbuf_history.c',
         'rte_mbuf.c',
         'rte_mbuf_ptype.c',
         'rte_mbuf_pool_ops.c',
@@ -13,5 +14,6 @@ headers = files(
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
         'rte_mbuf_dyn.h',
+        'rte_mbuf_history.h',
 )
 deps += ['mempool']
lib/mbuf/rte_mbuf.c +4 -0
index 22d7cfc475..d2fcb5db19 100644
@@ -41,6 +41,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
 		   sizeof(struct rte_pktmbuf_pool_private));
 	RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
 
+	rte_mbuf_history_init();
+
 	/* if no structure is provided, assume no mbuf private area */
 	user_mbp_priv = opaque_arg;
 	if (user_mbp_priv == NULL) {
@@ -499,6 +501,8 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 	struct rte_mbuf *m, *m_next, *pending[RTE_PKTMBUF_FREE_PENDING_SZ];
 	unsigned int idx, nb_pending = 0;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_FREE);
+
 	for (idx = 0; idx < count; idx++) {
 		m = mbufs[idx];
 		if (unlikely(m == NULL))
lib/mbuf/rte_mbuf.h +14 -1
index 06ab7502a5..95a4f9841b 100644
@@ -40,6 +40,7 @@
 #include <rte_branch_prediction.h>
 #include <rte_mbuf_ptype.h>
 #include <rte_mbuf_core.h>
+#include <rte_mbuf_history.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -607,6 +608,9 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &ret.ptr) < 0)
 		return NULL;
 	__rte_mbuf_raw_sanity_check(ret.m);
+
+	rte_mbuf_history_mark(ret.m, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	return ret.m;
 }
 
@@ -642,9 +646,13 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0))
+	if (likely(rc == 0)) {
 		for (unsigned int idx = 0; idx < count; idx++)
 			__rte_mbuf_raw_sanity_check(mbufs[idx]);
+	}
+
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	return rc;
 }
 
@@ -666,6 +674,7 @@ static __rte_always_inline void
 rte_mbuf_raw_free(struct rte_mbuf *m)
 {
 	__rte_mbuf_raw_sanity_check(m);
+	rte_mbuf_history_mark(m, RTE_MBUF_HISTORY_OP_LIB_FREE);
 	rte_mempool_put(m->pool, m);
 }
 
@@ -703,6 +712,8 @@ rte_mbuf_raw_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned
 		__rte_mbuf_raw_sanity_check(m);
 	}
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_FREE);
+
 	rte_mempool_put_bulk(mp, (void **)mbufs, count);
 }
 
@@ -1013,6 +1024,8 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
+	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
+
 	/* To understand duff's device on loop unwinding optimization, see
 	 * https://en.wikipedia.org/wiki/Duff's_device.
 	 * Here while() loop is used rather than do() while{} to avoid extra
lib/mbuf/rte_mbuf_dyn.h +18 -0
index 865c90f579..dc1d4f146a 100644
@@ -69,6 +69,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <rte_stdatomic.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -240,6 +241,23 @@ void rte_mbuf_dyn_dump(FILE *out);
  * and parameters together.
  */
 
+/**
+ * The mbuf history dynamic field provides lifecycle tracking
+ * for mbuf objects through the system.
+ * It records a fixed set of predefined operations for debugging.
+ */
+#define RTE_MBUF_DYNFIELD_HISTORY_NAME "rte_mbuf_dynfield_history"
+
+/**
+ * Type for mbuf history dynamic field.
+ *
+ * Use atomic operations to support cloned mbufs
+ * accessed simultaneously by multiple lcores.
+ *
+ * The size is 64-bit for better performance on modern systems.
+ */
+typedef RTE_ATOMIC(uint64_t) rte_mbuf_history_t;
+
 /*
  * The metadata dynamic field provides some extra packet information
  * to interact with RTE Flow engine. The metadata in sent mbufs can be
lib/mbuf/rte_mbuf_history.h new file +204 -0

204 lines not on this page · raw message

Signature · 1 line
2.51.0
#96 lore raw

RE: [PATCH v7 3/7] mbuf: record mbuf operations history

lib/mbuf/mbuf_history.c line 106

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +5 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated = 0;
+	for (enum rte_mbuf_history_op op = RTE_MBUF_HISTORY_OP_LIB_ALLOC;
+			op < RTE_MBUF_HISTORY_OP_MAX; op++)
+		total_allocated += stats[op];

I might be overly cautious here, but the app (or driver) might have a bug, and mark the mbuf with OP_APP_FREE (or OP_PMD_FREE) without actually freeing the mbuf back to the mempool. So you should only trust the mempool library (OP_LIB_FREE) to mark the mbuf as actually freed. I.e. start the loop at op = RTE_MBUF_HISTORY_OP_LIB_FREE. The app/driver should eventually call rte_mbuf_raw_free_bulk() or similar to release the mbuf back to the mempool.

Quoted 34 lines
lib/mbuf/rte_mbuf_history.h new file +5 -0
+/**
+ * History operation types.
+ */
+enum rte_mbuf_history_op {
+	RTE_MBUF_HISTORY_OP_NEVER     =  0, /**< Initial state - never

allocated */

lib/mbuf/rte_mbuf_history.h new file +5 -0
+	RTE_MBUF_HISTORY_OP_LIB_FREE  =  1, /**< Freed back to pool */
+	RTE_MBUF_HISTORY_OP_PMD_FREE  =  2, /**< Freed by PMD */
+	RTE_MBUF_HISTORY_OP_APP_FREE  =  3, /**< Freed by application */
+	/* With ops below, mbuf is considered allocated. */
+	RTE_MBUF_HISTORY_OP_LIB_ALLOC =  4, /**< Allocation in mbuf

library */

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_PMD_ALLOC =  5, /**< Allocated by PMD for Rx

*/

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_APP_ALLOC =  6, /**< Allocated by application

*/

lib/mbuf/rte_mbuf_history.h new file +3 -0
+	RTE_MBUF_HISTORY_OP_RX        =  7, /**< Received */
+	RTE_MBUF_HISTORY_OP_TX        =  8, /**< Sent */
+	RTE_MBUF_HISTORY_OP_TX_PREP   =  9, /**< Being prepared before Tx

*/

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_TX_BUSY   = 10, /**< Returned due to Tx busy

*/

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_ENQUEUE   = 11, /**< Enqueued for processing

*/

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_DEQUEUE   = 12, /**< Dequeued for processing

*/

(quoted diff) +2 -0
+	/*                              13,      reserved for future */
+	RTE_MBUF_HISTORY_OP_USR2      = 14, /**< Application-defined

event 2 */

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_USR1      = 15, /**< Application-defined

event 1 */

(quoted diff) +1 -0
+	RTE_MBUF_HISTORY_OP_MAX       = 16, /**< Maximum number of

operation types */
+};

#97 lore raw

Re: [PATCH v7 3/7] mbuf: record mbuf operations history

17/10/2025 00:29, Morten Brørup:

Quoted 7 lines

lib/mbuf/mbuf_history.c line 106

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +5 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated = 0;
+	for (enum rte_mbuf_history_op op = RTE_MBUF_HISTORY_OP_LIB_ALLOC;
+			op < RTE_MBUF_HISTORY_OP_MAX; op++)
+		total_allocated += stats[op];

I might be overly cautious here, but the app (or driver) might have a bug, and mark the mbuf with OP_APP_FREE (or OP_PMD_FREE) without actually freeing the mbuf back to the mempool.

Yes

Quoted 1 line

So you should only trust the mempool library (OP_LIB_FREE) to mark the mbuf as actually freed. I.e. start the loop at op = RTE_MBUF_HISTORY_OP_LIB_FREE.

We cannot because these statistics are about the latest state. So if the app marks the mbuf as freed after the library, they should be reported as non allocated.

Quoted 1 line

The app/driver should eventually call rte_mbuf_raw_free_bulk() or similar to release the mbuf back to the mempool.

Because we don't know in which order the mbufs are marked in the call stack, we must trust these free ops.

I really think there is room for improvements in the details of the marks and their usage. I suggest we merge and play with this experimental feature, and discuss in the next cycle how to improve the markers.

#98 lore raw

RE: [PATCH v7 3/7] mbuf: record mbuf operations history

Quoted 16 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Friday, 17 October 2025 09.32

17/10/2025 00:29, Morten Brørup:

Quoted 7 lines

lib/mbuf/mbuf_history.c line 106

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +5 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated = 0;
+	for (enum rte_mbuf_history_op op = RTE_MBUF_HISTORY_OP_LIB_ALLOC;
+			op < RTE_MBUF_HISTORY_OP_MAX; op++)
+		total_allocated += stats[op];

I might be overly cautious here, but the app (or driver) might have a

bug, and mark the mbuf with OP_APP_FREE (or OP_PMD_FREE) without actually freeing the mbuf back to the mempool.

Yes

Quoted 7 lines
Quoted 1 line

So you should only trust the mempool library (OP_LIB_FREE) to mark

the mbuf as actually freed. I.e. start the loop at op = RTE_MBUF_HISTORY_OP_LIB_FREE.

We cannot because these statistics are about the latest state. So if the app marks the mbuf as freed after the library, they should be reported as non allocated.

The app cannot mark the mbuf after calling rte_mbuf_raw_free_bulk(). That would be a "use after free" bug.

Quoted 4 lines
Quoted 2 lines

The app/driver should eventually call rte_mbuf_raw_free_bulk() or

similar to release the mbuf back to the mempool.

Quoted 9 lines

Because we don't know in which order the mbufs are marked in the call stack, we must trust these free ops.

I really think there is room for improvements in the details of the marks
and their usage. I suggest we merge and play with this experimental feature,
and discuss in the next cycle how to improve the markers.

Since it's only a minor detail in the dump function that I'm having minor doubts about, merging as-is is OK with me.

It's more important getting the feature included than making it perfect at its introduction - as you mention yourself: it's an experimental feature.

#99 lore raw

Re: [PATCH v7 3/7] mbuf: record mbuf operations history

17/10/2025 09:55, Morten Brørup:

Quoted 17 lines
Quoted 17 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Friday, 17 October 2025 09.32

17/10/2025 00:29, Morten Brørup:

Quoted 7 lines

lib/mbuf/mbuf_history.c line 106

Quoted 5 lines
lib/mbuf/mbuf_history.c new file +5 -0
+	/* Calculate total allocated mbufs */
+	uint64_t total_allocated = 0;
+	for (enum rte_mbuf_history_op op = RTE_MBUF_HISTORY_OP_LIB_ALLOC;
+			op < RTE_MBUF_HISTORY_OP_MAX; op++)
+		total_allocated += stats[op];

I might be overly cautious here, but the app (or driver) might have a

bug, and mark the mbuf with OP_APP_FREE (or OP_PMD_FREE) without actually freeing the mbuf back to the mempool.

Yes

Quoted 1 line

So you should only trust the mempool library (OP_LIB_FREE) to mark

Quoted 8 lines
Quoted 6 lines

the mbuf as actually freed. I.e. start the loop at op = RTE_MBUF_HISTORY_OP_LIB_FREE.

We cannot because these statistics are about the latest state. So if the app marks the mbuf as freed after the library, they should be reported as non allocated.

The app cannot mark the mbuf after calling rte_mbuf_raw_free_bulk(). That would be a "use after free" bug.

Yes but it can happen :)
Anyway there is also the transient of mbuf marked by PMD or app before being marked by the lib.
I think in those cases it is expected to consider the mbuf as non-allocated in the stats.

Quoted 13 lines
Quoted 12 lines
Quoted 1 line

The app/driver should eventually call rte_mbuf_raw_free_bulk() or

similar to release the mbuf back to the mempool.

Because we don't know in which order the mbufs are marked in the call stack, we must trust these free ops.

I really think there is room for improvements in the details of the marks
and their usage. I suggest we merge and play with this experimental feature,
and discuss in the next cycle how to improve the markers.

Quoted 3 lines

Since it's only a minor detail in the dump function that I'm having minor doubts about, merging as-is is OK with me.

It's more important getting the feature included than making it perfect at its introduction - as you mention yourself: it's an experimental feature.

Yes let's play with it, we may discover that the markers should be changed more deeply.

#100 lore raw

PATCH v7 4/7 ethdev: mark mbufs in burst functions

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Mark the Rx/Tx steps in mbufs for debugging.
It has no performance impact if mbuf history is disabled (by default).

---
 lib/ethdev/rte_ethdev.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/ethdev/rte_ethdev.h +11 -0
index d23c143eed..5e250e5083 100644
@@ -6336,6 +6336,8 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 
 	nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
 
+	rte_mbuf_history_mark_bulk(rx_pkts, nb_rx, RTE_MBUF_HISTORY_OP_RX);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	{
 		void *cb;
@@ -6688,8 +6690,15 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	uint16_t requested_pkts = nb_pkts;
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX);
+
 	nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
 
+	if (requested_pkts > nb_pkts)
+		rte_mbuf_history_mark_bulk(tx_pkts + nb_pkts,
+				requested_pkts - nb_pkts, RTE_MBUF_HISTORY_OP_TX_BUSY);
+
 	rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
 	return nb_pkts;
 }
@@ -6785,6 +6794,8 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
 	}
 #endif
 
+	rte_mbuf_history_mark_bulk(tx_pkts, nb_pkts, RTE_MBUF_HISTORY_OP_TX_PREP);
+
 	return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
 }
 
Signature · 1 line
2.51.0
#101 lore raw

PATCH v7 5/7 app/testpmd: use space separator in dump commands

In reply to Thomas Monjalon

In order to make dump commands look like other commands which have keywords separated with space, replace these commands:
- dump_physmem
- dump_socket_mem
- dump_memzone
- dump_struct_sizes
- dump_ring [name]
- dump_mempool [name]
- dump_devargs
- dump_lcores
- dump_trace
- dump_log_types
with these ones:
- dump physmem
- dump socket_mem
- dump memzone
- dump struct_sizes
- dump ring [name]
- dump mempool [name]
- dump devargs
- dump lcores
- dump trace
- dump log_types

Both parsing functions (with and without name argument) are merged together.

The function cmd_dump_init() is removed
as it seems useless to define tokens at runtime.

Trace is explicitly warned as not supported on Windows, because #ifndef in the tokens is not possible with MSVC.

---
 app/test-pmd/cmdline.c                      | 196 +++++++++-----------
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  20 +-
 2 files changed, 99 insertions(+), 117 deletions(-)
app/test-pmd/cmdline.c +89 -107
index 7803e14bdc..d332236924 100644
@@ -266,34 +266,34 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"show port (port_id) flow_ctrl"
 			"	Show flow control info of a port.\n\n"
 
-			"dump_physmem\n"
+			"dump physmem\n"
 			"    Dumps all physical memory segment layouts\n\n"
 
-			"dump_socket_mem\n"
+			"dump socket_mem\n"
 			"    Dumps the memory usage of all sockets\n\n"
 
-			"dump_memzone\n"
+			"dump memzone\n"
 			"    Dumps the layout of all memory zones\n\n"
 
-			"dump_struct_sizes\n"
+			"dump struct_sizes\n"
 			"    Dumps the size of all memory structures\n\n"
 
-			"dump_ring\n"
+			"dump ring [name]\n"
 			"    Dumps the status of all or specific element in DPDK rings\n\n"
 
-			"dump_mempool\n"
+			"dump mempool [name]\n"
 			"    Dumps the statistics of all or specific memory pool\n\n"
 
-			"dump_devargs\n"
+			"dump devargs\n"
 			"    Dumps the user device list\n\n"
 
-			"dump_lcores\n"
+			"dump lcores\n"
 			"    Dumps the logical cores list\n\n"
 
-			"dump_trace\n"
+			"dump trace\n"
 			"    Dumps the tracing data to the folder according to the current EAL settings\n\n"
 
-			"dump_log_types\n"
+			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
 			"show port (port_id) speed_lanes capabilities"
@@ -9085,9 +9085,33 @@ static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
 
 /* ******************************************************************************** */
 
-struct cmd_dump_result {
+struct cmd_dump_simple_result {
 	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
 };
+static cmdline_parse_token_string_t cmd_dump_simple_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_simple_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"physmem#"
+		"socket_mem#"
+		"memzone#"
+		"struct_sizes#"
+		"ring#"
+		"mempool#"
+		"devargs#"
+		"lcores#"
+		"trace#"
+		"log_types"
+);
+static cmdline_parse_token_string_t cmd_dump_named_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, obj,
+		"ring#"
+		"mempool#"
+);
+static cmdline_parse_token_string_t cmd_dump_named_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_simple_result, name, NULL);
 
 static void
 dump_struct_sizes(void)
@@ -9099,7 +9123,6 @@ dump_struct_sizes(void)
 #undef DUMP_SIZE
 }
 
-
 /* Dump the socket memory statistics on console */
 static void
 dump_socket_mem(FILE *f)
@@ -9114,7 +9137,6 @@ dump_socket_mem(FILE *f)
 	static size_t last_allocs;
 	static size_t last_total;
 
-
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
 		if (rte_malloc_get_socket_stats(i, &socket_stats) ||
 		    !socket_stats.heap_totalsz_bytes)
@@ -9149,113 +9171,74 @@ dump_socket_mem(FILE *f)
 	last_total = total;
 }
 
-static void cmd_dump_parsed(void *parsed_result,
-			    __rte_unused struct cmdline *cl,
-			    __rte_unused void *data)
+static void cmd_dump_simple_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
 {
-	struct cmd_dump_result *res = parsed_result;
+	struct cmd_dump_simple_result *res = parsed_result;
 
-	if (!strcmp(res->dump, "dump_physmem"))
+	if (strcmp(res->obj, "physmem") == 0)
 		rte_dump_physmem_layout(stdout);
-	else if (!strcmp(res->dump, "dump_socket_mem"))
+	else if (strcmp(res->obj, "socket_mem") == 0)
 		dump_socket_mem(stdout);
-	else if (!strcmp(res->dump, "dump_memzone"))
+	else if (strcmp(res->obj, "memzone") == 0)
 		rte_memzone_dump(stdout);
-	else if (!strcmp(res->dump, "dump_struct_sizes"))
+	else if (strcmp(res->obj, "struct_sizes") == 0)
 		dump_struct_sizes();
-	else if (!strcmp(res->dump, "dump_ring"))
-		rte_ring_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_mempool"))
-		rte_mempool_list_dump(stdout);
-	else if (!strcmp(res->dump, "dump_devargs"))
+	else if (strcmp(res->obj, "ring") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_ring_list_dump(stdout);
+		} else {
+			struct rte_ring *r;
+			r = rte_ring_lookup(res->name);
+			if (r == NULL) {
+				cmdline_printf(cl, "Cannot find ring\n");
+				return;
+			}
+			rte_ring_dump(stdout, r);
+		}
+	} else if (strcmp(res->obj, "mempool") == 0) {
+		if (strcmp(res->name, "") == 0) {
+			rte_mempool_list_dump(stdout);
+		} else {
+			struct rte_mempool *mp;
+			mp = rte_mempool_lookup(res->name);
+			if (mp == NULL) {
+				cmdline_printf(cl, "Cannot find mempool\n");
+				return;
+			}
+			rte_mempool_dump(stdout, mp);
+		}
+	} else if (strcmp(res->obj, "devargs") == 0)
 		rte_devargs_dump(stdout);
-	else if (!strcmp(res->dump, "dump_lcores"))
+	else if (strcmp(res->obj, "lcores") == 0)
 		rte_lcore_dump(stdout);
-#ifndef RTE_EXEC_ENV_WINDOWS
-	else if (!strcmp(res->dump, "dump_trace"))
+	else if (strcmp(res->obj, "trace") == 0)
+#ifdef RTE_EXEC_ENV_WINDOWS
+		cmdline_printf(cl, "trace is not supported on Windows\n");
+#else
 		rte_trace_save();
 #endif
-	else if (!strcmp(res->dump, "dump_log_types"))
+	else if (strcmp(res->obj, "log_types") == 0)
 		rte_log_dump(stdout);
 }
 
-static cmdline_parse_token_string_t cmd_dump_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
-		"" /* defined at init */);
-
-static void
-cmd_dump_init(void)
-{
-	cmd_dump_dump.string_data.str =
-		"dump_physmem#"
-		"dump_memzone#"
-		"dump_socket_mem#"
-		"dump_struct_sizes#"
-		"dump_ring#"
-		"dump_mempool#"
-		"dump_devargs#"
-		"dump_lcores#"
-#ifndef RTE_EXEC_ENV_WINDOWS
-		"dump_trace#"
-#endif
-		"dump_log_types";
-}
-
-static cmdline_parse_inst_t cmd_dump = {
-	.f = cmd_dump_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "Dump status",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_dump,
+static cmdline_parse_inst_t cmd_dump_simple = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "Dump objects",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_simple_obj,
 		NULL,
 	},
 };
-
-/* ******************************************************************************** */
-
-struct cmd_dump_one_result {
-	cmdline_fixed_string_t dump;
-	cmdline_fixed_string_t name;
-};
-
-static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
-				__rte_unused void *data)
-{
-	struct cmd_dump_one_result *res = parsed_result;
-
-	if (!strcmp(res->dump, "dump_ring")) {
-		struct rte_ring *r;
-		r = rte_ring_lookup(res->name);
-		if (r == NULL) {
-			cmdline_printf(cl, "Cannot find ring\n");
-			return;
-		}
-		rte_ring_dump(stdout, r);
-	} else if (!strcmp(res->dump, "dump_mempool")) {
-		struct rte_mempool *mp;
-		mp = rte_mempool_lookup(res->name);
-		if (mp == NULL) {
-			cmdline_printf(cl, "Cannot find mempool\n");
-			return;
-		}
-		rte_mempool_dump(stdout, mp);
-	}
-}
-
-static cmdline_parse_token_string_t cmd_dump_one_dump =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
-				 "dump_ring#dump_mempool");
-
-static cmdline_parse_token_string_t cmd_dump_one_name =
-	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
-
-static cmdline_parse_inst_t cmd_dump_one = {
-	.f = cmd_dump_one_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dump_one_dump,
-		(void *)&cmd_dump_one_name,
+static cmdline_parse_inst_t cmd_dump_named = {
+	.f = cmd_dump_simple_parsed,
+	.help_str = "dump ring|mempool <name>: Dump one ring/mempool",
+	.tokens = {
+		(void *)&cmd_dump_simple_dump,
+		(void *)&cmd_dump_named_obj,
+		(void *)&cmd_dump_named_name,
 		NULL,
 	},
 };
@@ -14035,8 +14018,8 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_config_rss_hash_key,
 	&cmd_config_rss_hash_algo,
 	&cmd_cleanup_txq_mbufs,
-	&cmd_dump,
-	&cmd_dump_one,
+	&cmd_dump_simple,
+	&cmd_dump_named,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
@@ -14169,7 +14152,6 @@ init_cmdline(void)
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
-	cmd_dump_init();
 
 	count = 0;
 	for (i = 0; builtin_ctx[i] != NULL; i++)
doc/guides/testpmd_app_ug/testpmd_funcs.rst +10 -10
index 24e1cb05f7..23a4a86cc3 100644
@@ -569,70 +569,70 @@ dump physmem
 
 Dumps all physical memory segment layouts::
 
-   testpmd> dump_physmem
+   testpmd> dump physmem
 
 dump memzone
 ~~~~~~~~~~~~
 
 Dumps the layout of all memory zones::
 
-   testpmd> dump_memzone
+   testpmd> dump memzone
 
 dump socket memory
 ~~~~~~~~~~~~~~~~~~
 
 Dumps the memory usage of all sockets::
 
-   testpmd> dump_socket_mem
+   testpmd> dump socket_mem
 
 dump struct size
 ~~~~~~~~~~~~~~~~
 
 Dumps the size of all memory structures::
 
-   testpmd> dump_struct_sizes
+   testpmd> dump struct_sizes
 
 dump ring
 ~~~~~~~~~
 
 Dumps the status of all or specific element in DPDK rings::
 
-   testpmd> dump_ring [ring_name]
+   testpmd> dump ring [ring_name]
 
 dump mempool
 ~~~~~~~~~~~~
 
 Dumps the statistics of all or specific memory pool::
 
-   testpmd> dump_mempool [mempool_name]
+   testpmd> dump mempool [mempool_name]
 
 dump devargs
 ~~~~~~~~~~~~
 
 Dumps the user device list::
 
-   testpmd> dump_devargs
+   testpmd> dump devargs
 
 dump lcores
 ~~~~~~~~~~~
 
 Dumps the logical cores list::
 
-   testpmd> dump_lcores
+   testpmd> dump lcores
 
 dump trace
 ~~~~~~~~~~
 
 Dumps the tracing data to the folder according to the current EAL settings::
 
-   testpmd> dump_trace
+   testpmd> dump trace
 
 dump log types
 ~~~~~~~~~~~~~~
 
 Dumps the log level for all the dpdk modules::
 
-   testpmd> dump_log_types
+   testpmd> dump log_types
 
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.51.0
#102 lore raw

PATCH v7 6/7 app/testpmd: add commands to dump mbuf history

In reply to Thomas Monjalon

Dump the mbuf history to the console or to a file.

The dump will contain:
- Operation history for each mbuf
- Summary and statistics about all mbufs

Dump the history of all mbufs:
testpmd> dump mbuf history all [file]

Dump the history of one mbuf:
testpmd> dump mbuf history <mbuf_addr> [file]

Dump the history of one mbuf pool:
testpmd> dump mbuf pool history <mp_name> [file]

---
 app/test-pmd/cmdline.c                      | 143 ++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  13 ++
 2 files changed, 156 insertions(+)
app/test-pmd/cmdline.c +143 -0
index d332236924..9205bc8573 100644
@@ -40,6 +40,7 @@
 #include <rte_gro.h>
 #endif
 #include <rte_mbuf_dyn.h>
+#include <rte_mbuf_history.h>
 #include <rte_trace.h>
 
 #include <cmdline_rdline.h>
@@ -296,6 +297,15 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"dump log_types\n"
 			"    Dumps the log level for all the dpdk modules\n\n"
 
+			"dump mbuf history all [file_name]\n"
+			"    Dumps the mbuf history for all mempools\n\n"
+
+			"dump mbuf history <mbuf_addr> [file_name]\n"
+			"    Dumps the history for a specific mbuf (use 0x<address> format)\n\n"
+
+			"dump mbuf pool history <mempool_name> [file_name]\n"
+			"    Dumps the history for a specific mempool\n\n"
+
 			"show port (port_id) speed_lanes capabilities"
 			"	Show speed lanes capabilities of a port.\n\n"
 		);
@@ -9243,6 +9253,135 @@ static cmdline_parse_inst_t cmd_dump_named = {
 	},
 };
 
+struct cmd_dump_mbuf_history_result {
+	cmdline_fixed_string_t dump;
+	cmdline_fixed_string_t mbuf;
+	cmdline_fixed_string_t history;
+	cmdline_fixed_string_t obj;
+	cmdline_fixed_string_t name;
+	cmdline_fixed_string_t addr;
+	cmdline_fixed_string_t file;
+};
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_dump =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, dump, "dump");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_mbuf =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, mbuf, "mbuf");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_history =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, history, "history");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_obj =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_pool =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, obj, "pool");
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_name =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, name, NULL);
+static cmdline_parse_token_string_t cmd_dump_mbuf_history_file =
+	TOKEN_STRING_INITIALIZER(struct cmd_dump_mbuf_history_result, file, NULL);
+
+static void cmd_dump_mbuf_history_parsed(void *parsed_result,
+		struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_dump_mbuf_history_result *res = parsed_result;
+	FILE *out = stdout;
+
+	if (strcmp(res->file, "") != 0) {
+		out = fopen(res->file, "w");
+		if (out == NULL) {
+			cmdline_printf(cl,
+					"Failed to open file '%s'\n",
+					res->file);
+			return;
+		}
+	}
+
+	if (strcmp(res->obj, "all") == 0) {
+		rte_mbuf_history_dump_all(out);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump written in '%s'\n",
+					res->file);
+	} else if (strcmp(res->obj, "pool") == 0) {
+		struct rte_mempool *mp = rte_mempool_lookup(res->name);
+		if (mp == NULL) {
+			cmdline_printf(cl,
+					"Failed to find mempool '%s'\n",
+					res->name);
+			return;
+		}
+		rte_mbuf_history_dump_mempool(out, mp);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mempool '%s' written in '%s'\n",
+					res->name, res->file);
+	} else {
+		struct rte_mbuf *mbuf;
+		uintptr_t mbuf_addr;
+		if (sscanf(res->obj, "0x%" SCNxPTR, &mbuf_addr) != 1) {
+			cmdline_printf(cl,
+					"Invalid mbuf pointer format. Use 0x<address>\n");
+			return;
+		}
+		mbuf = (struct rte_mbuf *)mbuf_addr;
+		rte_mbuf_history_dump(out, mbuf);
+		if (out != stdout)
+			cmdline_printf(cl,
+					"Dump for mbuf '%p' written in '%s'\n",
+					mbuf, res->file);
+	}
+
+	if (out != stdout)
+		fclose(out);
+}
+
+static cmdline_parse_inst_t cmd_dump_mbuf_history_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all|<address>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_obj,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_history_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf history all|<address> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_obj,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_pool_history_stdout = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf pool history <name>",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_pool,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_name,
+		NULL,
+	},
+};
+static cmdline_parse_inst_t cmd_dump_mbuf_pool_history_to_file = {
+	.f = cmd_dump_mbuf_history_parsed,
+	.help_str = "dump mbuf pool history <name> [file]",
+	.tokens = {
+		(void *)&cmd_dump_mbuf_history_dump,
+		(void *)&cmd_dump_mbuf_history_mbuf,
+		(void *)&cmd_dump_mbuf_history_pool,
+		(void *)&cmd_dump_mbuf_history_history,
+		(void *)&cmd_dump_mbuf_history_name,
+		(void *)&cmd_dump_mbuf_history_file,
+		NULL,
+	},
+};
+
 /* *** Filters Control *** */
 
 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
@@ -14020,6 +14159,10 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_cleanup_txq_mbufs,
 	&cmd_dump_simple,
 	&cmd_dump_named,
+	&cmd_dump_mbuf_history_stdout,
+	&cmd_dump_mbuf_history_to_file,
+	&cmd_dump_mbuf_pool_history_stdout,
+	&cmd_dump_mbuf_pool_history_to_file,
 	&cmd_flow,
 	&cmd_show_port_meter_cap,
 	&cmd_add_port_meter_profile_srtcm,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +13 -0
index 23a4a86cc3..e423abd40e 100644
@@ -634,6 +634,19 @@ Dumps the log level for all the dpdk modules::
 
    testpmd> dump log_types
 
+dump mbuf history
+~~~~~~~~~~~~~~~~~
+
+The mbuf history is tracked
+if enabled at compilation with ``RTE_MBUF_HISTORY_DEBUG``.
+
+This tracking can be displayed or saved to a file
+for all mbufs or specific ones selected by pointer or mempool name::
+
+   testpmd> dump mbuf history all [file]
+   testpmd> dump mbuf history <mbuf_addr> [file]
+   testpmd> dump mbuf pool history <mp_name> [file]
+
 show (raw_encap|raw_decap)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.51.0
#103 lore raw

PATCH v7 7/7 usertools/mbuf: parse mbuf history dump

In reply to Thomas Monjalon

From: Shani Peretz <[email protected]>

Add a Python script that parses the history dump of mbufs generated by rte_mbuf_history_dump() and related functions, and presents it in a human-readable format.

If an operation ID is repeated, such as in the case of a double free, it will be highlighted in red and listed at the end of the file.

---
 doc/guides/howto/debug_troubleshoot.rst |   3 +-
 doc/guides/prog_guide/mbuf_lib.rst      |   2 +
 doc/guides/rel_notes/release_25_11.rst  |   1 +
 lib/mbuf/rte_mbuf_history.h             |   3 +
 usertools/dpdk-mbuf-history-parser.py   | 165 ++++++++++++++++++++++++
 5 files changed, 173 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-mbuf-history-parser.py
doc/guides/howto/debug_troubleshoot.rst +2 -1
index 16feeb1e54..c19aada6f8 100644
@@ -221,7 +221,8 @@ Memory objects close to NUMA :numref:`dtg_mempool`.
    by defining the compilation flag ``RTE_MBUF_HISTORY_DEBUG``.
    Then the libraries will mark the mbufs,
    and more marks can be added in the application.
-   Some dump functions must be used to collect the history.
+   Some dump functions must be used to collect the history,
+   and a script can parse it.
 
 #. Lower performance between the pipeline processing stages can be
 
doc/guides/prog_guide/mbuf_lib.rst +2 -0
index ae72eecc61..382bfbdca4 100644
@@ -279,6 +279,8 @@ More marks can be added by the application
 by calling functions like ``rte_mbuf_history_mark_bulk()``.
 Then the history can be stored in a file
 by calling functions like ``rte_mbuf_history_dump_all()``.
+The dump file will be easier to read after being processed
+by the script ``dpdk-mbuf-history-parser.py``.
 
 
 Use Cases
doc/guides/rel_notes/release_25_11.rst +1 -0
index 4d6a02179a..95e64d5d57 100644
@@ -76,6 +76,7 @@ New Features
   Added history dynamic field in mbuf (disabled by default)
   to store successive states of the mbuf lifecycle.
   Some functions were added to dump statistics.
+  A script was added to parse mbuf tracking stored in a file.
 
 * **Updated NXP DPAA2 ethernet driver.**
 
lib/mbuf/rte_mbuf_history.h +3 -0
index 56a975a484..daf3cda34c 100644
@@ -19,6 +19,9 @@
  * The history is stored as an atomic value (64-bit) in a dynamic field of the mbuf,
  * with each event encoded in 4 bits, allowing up to 16 events to be tracked.
  * Atomic operations ensure thread safety for cloned mbufs accessed by multiple lcores.
+ *
+ * After dumping the history in a file,
+ * the script dpdk-mbuf-history-parser.py can be used for parsing.
  */
 
 #include <rte_common.h>
usertools/dpdk-mbuf-history-parser.py new file +165 -0

165 lines not on this page · raw message

Signature · 1 line
2.51.0
#104 lore raw

Re: [PATCH v7 0/7] add mbuf debug capabilities

In reply to Thomas Monjalon

16/10/2025 22:34, Thomas Monjalon:

Quoted 10 lines

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

Applied
It is an experimental debug feature.
It would be interesting to get some test feedback about how much it is useful and what can be improved.

#105 lore raw

Re: [PATCH v7 0/7] add mbuf debug capabilities

In reply to Thomas Monjalon
Quoted 74 lines · On Thu, 16 Oct 2025 22:34:38 +0200 Thomas Monjalon <[email protected]> wrote:

History is added to mbuf for debugging.

This series set some marks in mbuf allocation/freeing and ethdev Rx/Tx. More marks could be added in other libraries.
Drivers could benefit a finer debugging by marking alloc/free calls, in addition to marks already done in the mbuf library.
Even better, the application could add its own marks.

As part of this series, mbuf statistics can be dumped, and a Python script will help to parse mbuf history.

---

v7 changes:
- loop for sum of allocated mbufs
- remove unused Python import

v6 changes:
- simplify testpmd commands
- use enum op type
- rename Tx ops
- mark free before freeing
- mark out of sanity check loop

v5 change:
- fix MSVC build in testpmd

v4 changes:
- fix/rewrite testpmd commands
- fix python script
- fix thread safety
- fix checks
- fix logs
- change config (no Meson option)
- add documentation

v3 changes:
- use atomic
- fix prefix
- add asserts
- reformat dump
- remove #ifdef clutter
- remove mlx5 patch

v2 changes:
- move to mbuf in dynamic field

v1:
- mempool feature

---

Shani Peretz (3):
mbuf: record mbuf operations history
ethdev: mark mbufs in burst functions
usertools/mbuf: parse mbuf history dump

Thomas Monjalon (4):
doc: explain debug options in mbuf guide
mbuf: move header include for logs app/testpmd: use space separator in dump commands app/testpmd: add commands to dump mbuf history

 app/test-pmd/cmdline.c                      | 309 ++++++++++++++------
 config/rte_config.h                         |   1 +
 doc/guides/howto/debug_troubleshoot.rst     |   7 +
 doc/guides/prog_guide/mbuf_lib.rst          |  18 +-
 doc/guides/rel_notes/release_25_11.rst      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  33 ++-
 lib/ethdev/rte_ethdev.h                     |  11 +
 lib/mbuf/mbuf_history.c                     | 223 ++++++++++++++
 lib/mbuf/mbuf_log.h                         |   2 +
 lib/mbuf/meson.build                        |   2 +
 lib/mbuf/rte_mbuf.c                         |   5 +-
Quoted 9 lines
 lib/mbuf/rte_mbuf.h                         |  15 +-
 lib/mbuf/rte_mbuf_dyn.h                     |  18 ++
 lib/mbuf/rte_mbuf_history.h                 | 207 +++++++++++++
 usertools/dpdk-mbuf-history-parser.py       | 165 +++++++++++
 15 files changed, 917 insertions(+), 106 deletions(-)
 create mode 100644 lib/mbuf/mbuf_history.c
 create mode 100644 lib/mbuf/rte_mbuf_history.h
 create mode 100755 usertools/dpdk-mbuf-history-parser.py

If build is done with lots of debug enabled it now fails. Looks like typo in history code.

FAILED: lib/librte_mbuf.a.p/mbuf_mbuf_history.c.o
cc -Ilib/librte_mbuf.a.p -Ilib -I../lib -Ilib/mbuf -I../lib/mbuf -Ilib/eal/common -I../lib/eal/common -I. -I.. -Iconfig -I../config -Ilib/eal/include -I../lib/eal/include -Ilib/eal/linux/include -I../lib/eal/linux/include -Ilib/eal/x86/include -I../lib/eal/x86/include -I../kernel/linux -Ilib/eal -I../lib/eal -Ilib/kvargs -I../lib/kvargs -Ilib/log -I../lib/log -Ilib/metrics -I../lib/metrics -Ilib/telemetry -I../lib/telemetry -Ilib/argparse -I../lib/argparse -Ilib/mempool -I../lib/mempool -Ilib/ring -I../lib/ring -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c11 -O3 -include rte_config.h -Wvla -Wcast-qual -Wdeprecated -Wformat -Wformat-nonliteral -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings -Wno-packed-not-aligned -Wno-missing-field-initializers -fzero-init-padding-bits=all -D_GNU_SOURCE -DRTE_ENABLE_ASSERT -DRTE_LIBRTE_ETHDEV_DEBUG=1 -DRTE_LIBRTE_IPFRAG_TBL_STAT -DRTE_LIBRTE_MEMPOOL_STATS -DRTE_LIBRTE_MEMPOOL_DEBUG -DRTE_MBUF_HISTORY_DEBUG -fPIC -march=native -mrtm -DALLOW_EXPERIMENTAL_API -DALLOW_INTERNAL_API -Wno-format-truncation -DRTE_LOG_DEFAULT_LOGTYPE=lib.mbuf -MD -MQ lib/librte_mbuf.a.p/mbuf_mbuf_history.c.o -MF lib/librte_mbuf.a.p/mbuf_mbuf_history.c.o.d -o lib/librte_mbuf.a.p/mbuf_mbuf_history.c.o -c ../lib/mbuf/mbuf_history.c In file included from ../lib/eal/x86/include/rte_vect.h:14,

                 from ../lib/eal/x86/include/rte_memcpy.h:17,
                 from ../lib/mempool/rte_mempool.h:50,
                 from ../lib/mbuf/mbuf_history.c:8:
../lib/mbuf/mbuf_history.c: In function ‘rte_mbuf_history_init’:
../lib/log/rte_log.h:364:9: error: static assertion failed: "This log format string contains a \\n"
  364 |         static_assert(!__builtin_strchr(fmt, '\n'), \
      |         ^~~~~~~~~~~~~
../lib/log/rte_log.h:387:9: note: in expansion of macro ‘RTE_LOG_CHECK_NO_NEWLINE’
  387 |         RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
../lib/mbuf/mbuf_log.h:8:9: note: in expansion of macro ‘RTE_LOG_LINE’
    8 |         RTE_LOG_LINE(level, MBUF, "" __VA_ARGS__)
      |         ^~~~~~~~~~~~
../lib/mbuf/mbuf_history.c:219:17: note: in expansion of macro ‘MBUF_LOG’
  219 |                 MBUF_LOG(ERR, "Failed to register mbuf history dynamic field: %s\n",
      |                 ^~~~~~~~