lib/pmu: cleanups and trace integration
Subsystems (2)
cover lib/pmu: cleanups and trace integration
This series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
Tomasz Duszynski (6):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable fast test
trace: add PMU
MAINTAINERS | 1 + app/test/test_pmu.c | 4 +- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++ lib/eal/common/eal_common_trace_points.c | 6 ++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 3 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 86 +++++++++++++++++----- lib/pmu/pmu_arm64.c | 19 +++-- lib/pmu/pmu_private.h | 43 +++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 284 insertions(+), 43 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH 1/6 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH 2/6 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH 3/6 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 3/6] lib/pmu: reimplement per-arch ops as callbacks
16/06/2025 08:53, Tomasz Duszynski:
lib/pmu/pmu_private.h line 35
Quoted 5 lines
lib/pmu/pmu_private.h +5
-0+static inline int +pmu_arch_init (void ) +{ +if (arch_ops && arch_ops->init) +return arch_ops->init ();
These are not boolean values, please compare explicitly with NULL.
Re: [PATCH 3/6] lib/pmu: reimplement per-arch ops as callbacks
Quoted 8 lines
16/06/2025 08:53, Tomasz Duszynski:
lib/pmu/pmu_private.h line 35
Quoted 5 lines
lib/pmu/pmu_private.h +5
-0+static inline int +pmu_arch_init (void ) +{ +if (arch_ops && arch_ops->init) +return arch_ops->init ();These are not boolean values, please compare explicitly with NULL.
Okay.
PATCH 4/6 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
Re: [PATCH 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro
16/06/2025 08:53, Tomasz Duszynski:
Quoted 5 lines
RTE_LIB_PMUis defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.That said all cases where conditional compilation is required can be handled without introducing other macros.
You don't need to know if it is compiled for an unsupported arch?
What will happen when calling the unit test on RISC-V?
Re: [PATCH 4/6] lib/pmu: use build system defined RTE_LIB_PMU macro
Quoted 9 lines
16/06/2025 08:53, Tomasz Duszynski:
Quoted 5 lines
RTE_LIB_PMUis defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.That said all cases where conditional compilation is required can be handled without introducing other macros.
You don't need to know if it is compiled for an unsupported arch?
No, if arch isn't supported reading whatever counter returns 0. On the other hand if architecture does not require extra setup (eg., x86-64) all works automatically because Linux has consistent API for each supported arch.
Quoted 1 line
What will happen when calling the unit test on RISC-V?
Test will be skipped because event is set to 'NULL' by default. Supported architectures override it with valid name.
PATCH 5/6 test/pmu: enable fast test
In reply to Tomasz DuszynskiDPDK test suite provides much broader architecture coverage than what can be tested locally so enable the test to help identify potential issues.
--- app/test/test_pmu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
app/test/test_pmu.c +1 -3
@@ -52,6 +52,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH 6/6 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 6 ++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 3 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1851,6 +1851,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -59,6 +59,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +6 -0
@@ -119,3 +119,9 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_tread_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +2 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
@@ -86,6 +86,7 @@ always_enable = [ 'ring', 'stack', 'telemetry', + 'pmu', ] enable_deprecated_libs = []
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
Re: [PATCH 6/6] trace: add PMU
16/06/2025 08:53, Tomasz Duszynski:
lib/meson.build always_enable = [ · line 90
Quoted 6 lines
lib/meson.build +1
-0@@ -86,6 +86,7 @@ always_enable = [ 'ring', 'stack', 'telemetry', + 'pmu', ]
This list is alphabetically sorted.
What is the justification for always enabling PMU lib? Is it a good idea to always enable an experimental library?
Re: [PATCH 6/6] trace: add PMU
Quoted 9 lines
16/06/2025 08:53, Tomasz Duszynski:
lib/meson.build always_enable = [ · line 90
Quoted 6 lines
lib/meson.build +1
-0@@ -86,6 +86,7 @@ always_enable = [ 'ring', 'stack', 'telemetry', + 'pmu', ]This list is alphabetically sorted.
Right, missed that.
Quoted 3 lines
What is the justification for always enabling PMU lib? Is it a good idea to always enable an experimental library?
Well, since on Linux eal depends on pmu, disabling pmu ends up disabling eal, which breaks minimal build.
As for the second question - no. I think ideally lib should remain optional. However, since trace is part of eal, that indirectly forces pmu to be built.
Alternatively, I guess we could make the library explicitly optional by extra meson option. But given that there are already options for controlling libraries that approach is not perfect either.
Re: [PATCH 6/6] trace: add PMU
Quoted 16 lines · Tomasz Duszynski
Quoted 9 lines
16/06/2025 08:53, Tomasz Duszynski:
lib/meson.build always_enable = [ · line 90
Quoted 6 lines
lib/meson.build +1
-0@@ -86,6 +86,7 @@ always_enable = [ 'ring', 'stack', 'telemetry', + 'pmu', ]This list is alphabetically sorted.
Right, missed that.
Quoted 3 lines
What is the justification for always enabling PMU lib? Is it a good idea to always enable an experimental library?
Quoted 7 lines
Well, since on Linux eal depends on pmu, disabling pmu ends up disabling eal, which breaks minimal build.
As for the second question - no. I think ideally lib should remain optional. However, since trace is part of eal, that indirectly forces pmu to be built.
Or else you need to put ifdefs into the EAL code to only call the pmu functions when the library is enabled. Given that PMU library is only enabled for Linux, and yet there are changes in this patch to a number of common EAL files, that is probably a good option to take. It gives you the ability to make PMU optional, as well as supporting non-linux OS's.
/Bruce
RE: [PATCH 6/6] trace: add PMU
In reply to Tomasz DuszynskiQuoted 19 lines
From: Tomasz Duszynski [mailto:[email protected]]
Sent: Monday, 16 June 2025 11.49Quoted 9 lines
16/06/2025 08:53, Tomasz Duszynski:
lib/meson.build always_enable = [ · line 90
Quoted 6 lines
lib/meson.build +1
-0@@ -86,6 +86,7 @@ always_enable = [ 'ring', 'stack', 'telemetry', + 'pmu', ]This list is alphabetically sorted.
Right, missed that.
Quoted 3 lines
What is the justification for always enabling PMU lib? Is it a good idea to always enable an experimental library?
Quoted 6 lines
Well, since on Linux eal depends on pmu, disabling pmu ends up disabling eal, which breaks minimal build.
As for the second question - no. I think ideally lib should remain optional. However, since trace is part of eal, that indirectly forces pmu to be built.
Trace is optional, controlled by RTE_TRACE in /config/rte_config.h.
Quoted 4 lines
Alternatively, I guess we could make the library explicitly optional by extra meson option. But given that there are already options for controlling libraries that approach is not perfect either.
PMU should depend on EAL, not the other way around.
Please refer to this fix, where pmu.c is updated to call rte_mem_page_size(), which includes error handling, instead of directly calling sysconf(_SC_PAGE_SIZE) without handling errors from it:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
If there are cross dependency issues due to integration between PMU and Trace, adding the PMU related trace directly in the Trace library is a much better solution than making EAL depend on PMU.
Also, I agree with Thomas that PMU should not be considered a mandatory core library (always_enable).
v2 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (6):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable fast test
trace: add PMU
MAINTAINERS | 1 + app/test/test_pmu.c | 4 +- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++ lib/eal/common/eal_common_trace_points.c | 6 ++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 86 +++++++++++++++++----- lib/pmu/pmu_arm64.c | 19 +++-- lib/pmu/pmu_private.h | 43 +++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 283 insertions(+), 43 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v2 1/6 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v2 2/6 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v2 3/6 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 4/6 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v2 5/6 test/pmu: enable fast test
In reply to Tomasz DuszynskiDPDK test suite provides much broader architecture coverage than what can be tested locally so enable the test to help identify potential issues.
--- app/test/test_pmu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
app/test/test_pmu.c +1 -3
@@ -52,6 +52,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v2 6/6 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 6 ++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1851,6 +1851,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -59,6 +59,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +6 -0
@@ -119,3 +119,9 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_tread_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
RE: [PATCH v2 6/6] trace: add PMU
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
@Tomasz,
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around! How else is the PMU library supposed to use EAL functions like rte_mem_page_size()?
@Jerin or @Bruce, do any of you have some suggestions for how to achieve the proper dependency chain here?
Worst case, we will have to move PMU into EAL. :-(
[1]: https://inbox.dpdk.org/dev/[email protected]/T/#u
Besides that, good stuff. :-)
Re: [PATCH v2 6/6] trace: add PMU
18/06/2025 09:16, Morten Brørup:
Quoted 16 lines
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',@Tomasz,
Quoted 2 lines
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around!
It should depend on the low-level EAL, yes.
But as of now, EAL is not split so it is better to avoid EAL dependency if possible.
Quoted 3 lines
How else is the PMU library supposed to use EAL functions like
rte_mem_page_size()?@Jerin or @Bruce, do any of you have some suggestions for how to achieve the proper dependency chain here?
I propose we don't use rte_mem_page_size() in PMU lib for now,
so we keep not depending on EAL, to avoid mixing all in future. Later we could fix it if we manage to have high level EAL as a separate library.
Quoted 5 lines
Worst case, we will have to move PMU into EAL. :-(
[1]: https://inbox.dpdk.org/dev/[email protected]/T/#u
Besides that, good stuff. :-)
Re: [PATCH v2 6/6] trace: add PMU
Quoted 23 lines · Thomas Monjalon
18/06/2025 09:16, Morten Brørup:
Quoted 16 lines
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',@Tomasz,
Quoted 2 lines
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around!It should depend on the low-level EAL, yes.
But as of now, EAL is not split so it is better to avoid EAL dependency if possible.
Quoted 8 lines
Quoted 3 lines
How else is the PMU library supposed to use EAL functions like
rte_mem_page_size()?@Jerin or @Bruce, do any of you have some suggestions for how to achieve the proper dependency chain here?
I propose we don't use
rte_mem_page_size()in PMU lib for now,
so we keep not depending on EAL, to avoid mixing all in future. Later we could fix it if we manage to have high level EAL as a separate library.
For cases where we only need a single small function or snippet, there is no problem with circular dependencies if it can be made an inline function in a header file. We just need to add the appropriate include path to the build of the PMU library to pick up any EAL headers with inlines.
/Bruce
RE: [PATCH v2 6/6] trace: add PMU
Quoted 37 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 18 June 2025 12.28Quoted 17 lines · Thomas Monjalon
18/06/2025 09:16, Morten Brørup:
Quoted 16 lines
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',@Tomasz,
Quoted 5 lines
Quoted 2 lines
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around!It should depend on the low-level EAL, yes.
But as of now, EAL is not split so it is better to avoid EAL dependency ifpossible.
Quoted 2 lines
Quoted 2 lines
How else is the PMU library supposed to use EAL functions like
rte_mem_page_size()?Quoted 2 lines
Quoted 2 lines
@Jerin or @Bruce, do any of you have some suggestions for how to achieve
the proper dependency chain here?
Quoted 4 lines
I propose we don't use
rte_mem_page_size()in PMU lib for now, so we keep not depending on EAL, to avoid mixing all in future. Later we could fix it if we manage to have high level EAL as a separate
Quoted 6 lines
library.
Quoted 1 line
For cases where we only need a single small function or snippet, there is no problem with circular dependencies if it can be made an inline function in a header file. We just need to add the appropriate include path to the build of the PMU library to pick up any EAL headers with inlines.
Thanks for the suggestion, Bruce.
For the next version of my patch [2], I will consider if inlining the function is viable. It's an O/S dependent function, so it might be too ugly putting it in a header file. We'll see.
[2]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
RE: [PATCH v2 6/6] trace: add PMU
In reply to Morten BrørupQuoted 16 lines
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',@Tomasz,
Quoted 3 lines
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around! How else is the PMU library supposed to use EAL functions likerte_mem_page_size()?
Hi Morten,
Not addressing your comments wasn't intentional - just missed your reply prior to sending v2.
Tracing is tightly tied to eal right now so adding anything "external" there brings in extra deps. That's why I can't move pmu further down in the lib hierarchy - dpdk won't build if I do.
Once tracing is moved out into its own library, that kind of change should be possible.
Quoted 8 lines
@Jerin or @Bruce, do any of you have some suggestions for how to achieve the proper dependency chain here?
Worst case, we will have to move PMU into EAL. :-(
[1]: https://inbox.dpdk.org/dev/[email protected]/T/#u
Besides that, good stuff. :-)
RE: [PATCH v2 6/6] trace: add PMU
Quoted 30 lines
From: Tomasz Duszynski [mailto:[email protected]]
Sent: Wednesday, 18 June 2025 12.23Quoted 16 lines
lib/meson.build libraries = [ · line 19
Quoted 13 lines
lib/meson.build +1
-1@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',@Tomasz,
Quoted 3 lines
Please re-read my v1 review feedback [1]:
The PMU library should depend on the EAL, not the other way around! How else is the PMU library supposed to use EAL functions like
rte_mem_page_size()?Hi Morten,
Not addressing your comments wasn't intentional - just missed your reply prior to sending
v2.
Quoted 7 lines
Tracing is tightly tied to eal right now so adding anything "external" there brings in extra
deps. That's why I can't move pmu further down in the lib hierarchy - dpdk won't build if I do.Once tracing is moved out into its own library, that kind of change should be possible.
OK. Thomas seems to agree with this approach, so I will accept it too. :-)
Quoted 12 lines
Quoted 3 lines
@Jerin or @Bruce, do any of you have some suggestions for how to achieve the
proper dependency chain here?
Quoted 4 lines
Worst case, we will have to move PMU into EAL. :-(
[1]:
https://inbox.dpdk.org/dev/98CBD80474FA8B44BF855DF32C47DC35E9FCFA@smartserver.
smartshare.dk/T/#uQuoted 2 lines
Besides that, good stuff. :-)
v3 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (7):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable fast test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 44 ++++++++++- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 88 +++++++++++++++++----- lib/pmu/pmu_arm64.c | 22 ++++-- lib/pmu/pmu_private.h | 43 +++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 325 insertions(+), 45 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v3 1/7 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v3 2/7 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v3 3/7 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 4/7 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v3 5/7 test/pmu: enable fast test
In reply to Tomasz DuszynskiDPDK test suite provides much broader architecture coverage than what can be tested locally so enable the test to help identify potential issues.
--- app/test/test_pmu.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-)
app/test/test_pmu.c +41 -3
@@ -2,10 +2,47 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,6 +61,9 @@ test_pmu_read(void)return TEST_SKIPPED ; } +if (!perf_allowed_quirk ()) +return TEST_SKIPPED ; +if (rte_pmu_init () <0 )return TEST_FAILED ;
@@ -52,6 +92,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v3 6/7 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1851,6 +1851,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -59,6 +59,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +5 -0
@@ -119,3 +119,8 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
PATCH v3 7/7 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -130,7 +130,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -26,12 +26,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v4 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (7):
lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable fast test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 51 +++++++++++- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 27 ++++++- 21 files changed, 356 insertions(+), 81 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v4 1/7 lib/pmu: export only necessary arch headers
Install only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v4 2/7 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 3/7 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v4 4/7 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v4 5/7 test/pmu: enable fast test
In reply to Tomasz DuszynskiDPDK test suite provides much broader architecture coverage than what can be tested locally so enable the test to help identify potential issues.
--- app/test/test_pmu.c | 51 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-)
app/test/test_pmu.c +47 -4
@@ -2,10 +2,47 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,6 +61,9 @@ test_pmu_read(void)return TEST_SKIPPED ; } +if (!perf_allowed_quirk ()) +return TEST_SKIPPED ; +if (rte_pmu_init () <0 )return TEST_FAILED ;
@@ -33,7 +73,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +97,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v4 6/7 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +20 -0
@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
PATCH v4 7/7 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v5 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (8):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable fast test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 51 +++++++++++- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 360 insertions(+), 81 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v5 1/8 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v5 2/8 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v5 3/8 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 4/8 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v5 5/8 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v5 6/8 test/pmu: enable fast test
In reply to Tomasz DuszynskiDPDK test suite provides much broader architecture coverage than what can be tested locally so enable the test to help identify potential issues.
--- app/test/test_pmu.c | 51 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-)
app/test/test_pmu.c +47 -4
@@ -2,10 +2,47 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,6 +61,9 @@ test_pmu_read(void)return TEST_SKIPPED ; } +if (!perf_allowed_quirk ()) +return TEST_SKIPPED ; +if (rte_pmu_init () <0 )return TEST_FAILED ;
@@ -33,7 +73,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +97,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v5 7/8 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +20 -0
@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
PATCH v5 8/8 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v6 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (8):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 58 ++++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 366 insertions(+), 82 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v6 1/8 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v6 2/8 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v6 3/8 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v6 4/8 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v6 5/8 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v6 6/8 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-)
app/test/test_pmu.c +53 -5
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" );return TEST_FAILED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v6 7/8 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +20 -0
@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
PATCH v6 8/8 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v7 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (8):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 60 ++++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 31 +++++++- 21 files changed, 367 insertions(+), 83 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v7 1/8 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v7 2/8 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v7 3/8 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 4/8 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v7 5/8 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v7 6/8 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v7 7/8 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +20 -0
@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -145,6 +149,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +163,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +193,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
Re: [PATCH v7 7/8] trace: add PMU
Quoted 239 lines · Tomasz Duszynski
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.cMAINTAINERS +1
-0@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statisticsapp/test/test_trace_perf.c +10
-0@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;doc/guides/prog_guide/profile_app.rst +5
-0@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------doc/guides/prog_guide/trace_lib.rst +31
-0@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------doc/guides/rel_notes/release_25_07.rst +2
-0@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**lib/eal/common/eal_common_trace.c +4
-1@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();lib/eal/common/eal_common_trace_pmu.c new file +38
-0@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */ lib/eal/common/eal_common_trace_points.c +10
-0@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled.
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, · line 141
Quoted 10 lines
lib/eal/common/eal_common_trace_points.c +10
-0+* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif
From a quick look, could you export this symbol from the PMU library itself?
Signature · 1 line
David Marchand
Re: [PATCH v7 7/8] trace: add PMU
Quoted 244 lines · Tomasz Duszynski
Quoted 243 lines
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 20 +++++++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 17 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.cMAINTAINERS +1
-0@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statisticsapp/test/test_trace_perf.c +10
-0@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;doc/guides/prog_guide/profile_app.rst +5
-0@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------doc/guides/prog_guide/trace_lib.rst +31
-0@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------doc/guides/rel_notes/release_25_07.rst +2
-0@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**lib/eal/common/eal_common_trace.c +4
-1@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();lib/eal/common/eal_common_trace_pmu.c new file +38
-0@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */ lib/eal/common/eal_common_trace_points.c +14
-0@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files.
Quoted 8 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, · line 141
Quoted 6 lines
lib/eal/common/eal_common_trace_points.c +6
-0+* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif From a quick look, could you export this symbol from the PMU library itself?
Got caught up, but here is my take. It would likely make trace a dependency, but I believe the dependency should be reversed. Also from my perspective this suggestion feels more like a refactoring.
So unless I've misunderstood your point, I'd rater keep the current solution as is.
Re: [PATCH v7 7/8] trace: add PMU
21/07/2025 12:24, Tomasz Duszynski:
Quoted 8 lines
Quoted 8 lines · Tomasz Duszynski
Quoted 7 lines
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>
[...]
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
lib/eal/common/eal_common_trace_points.c +14
-0@@ -119,3 +119,23 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without +* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map +* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error +* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file +* to be present in the object files. Quoted 8 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, · line 141
Quoted 6 lines
lib/eal/common/eal_common_trace_points.c +6
-0+* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed +* in the map file if those symbols are not present in the binary. +*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif From a quick look, could you export this symbol from the PMU library itself?
Quoted 5 lines
Got caught up, but here is my take. It would likely make trace a dependency, but I believe the dependency should be reversed. Also from my perspective this suggestion feels more like a refactoring.
So unless I've misunderstood your point, I'd rater keep the current solution as is.
I think you got it right: a refactoring looks beneficial. Please think about it.
RE: [PATCH v7 7/8] trace: add PMU
Quoted 55 lines
From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 21 July 2025 12.4621/07/2025 12:24, Tomasz Duszynski:
Quoted 1 line
Quoted 1 line
On Fri, Jun 27, 2025 at 5:41 PM Tomasz Duszynski
Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
In order to profile app, one needs to store significant amount of
samples
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>[...]
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +0
-0@@ -119,3 +119,23 @@RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 11 lines
Quoted 11 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 11 lines
lib/eal/common/eal_common_trace_points.c +8
-0lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 130
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 134
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 138
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* in the map file if those symbols are not present in the binary.
Quoted 5 lines
Quoted 5 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, · line 141
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif From a quick look, could you export this symbol from the PMU library
itself?
Quoted 2 lines
Got caught up, but here is my take. It would likely make trace a
dependency, but I believe the
Quoted 1 line
dependency should be reversed. Also from my perspective this
Quoted 9 lines
suggestion feels more like a
Quoted 3 lines
refactoring.
So unless I've misunderstood your point, I'd rater keep the current
solution as is.
I think you got it right: a refactoring looks beneficial. Please think about it.
It's a long term goal (wishful thinking?) to move Trace out of the EAL, and into a separate library. Considering this long term goal, refactoring PMU to make it depend on Trace would be a step in the wrong direction.
However, if we disregard this long term goal, and do consider Trace a core part of the EAL, refactoring PMU to depend on Trace seems cleaner to me too.
I'm in favor of not adding more obstacles to moving Trace out of the EAL, i.e. don't refactor PMU to depend on Trace.
Also, I tend to agree with Tomasz about PMU being lower level than Trace, so PMU depending on Trace seems wrong. No strong opinion on this last point, though.
@Jerin, what do you think?
Re: [PATCH v7 7/8] trace: add PMU
Quoted 65 lines
Quoted 55 lines
From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 21 July 2025 12.4621/07/2025 12:24, Tomasz Duszynski:
Quoted 1 line
Quoted 1 line
On Fri, Jun 27, 2025 at 5:41 PM Tomasz Duszynski
Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
In order to profile app, one needs to store significant amount of
samples
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>[...]
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +0
-0@@ -119,3 +119,23 @@RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 11 lines
Quoted 11 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 11 lines
lib/eal/common/eal_common_trace_points.c +8
-0lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_trace_read, 25.07) +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif +#ifdef RTE_EXEC_ENV_IS_WINDOWS +/* gen-version-map.py script generates export symbol maps by scanning source files without
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 130
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* evaluating conditional compilation. Hence __rte_pmu_trace_read will be included the version map
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+* even if library is not compiled. +* +* On Windows if msvc linker is used this leads to a hard link error
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 134
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* (LNK2001: unresolved external symbol) because msvc requires all symbols listed in the .def file
Quoted 3 lines
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable,
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+* to be present in the object files. +* +* Other linkers, e.g: gnu ld or mingw ld, are more forgiving. They silently ignore symbols listed
Quoted 1 line
Quoted 1 line
lib/eal/common/eal_common_trace_points.c line 138
Quoted 1 line
lib/eal/common/eal_common_trace_points.c +1
-0+* in the map file if those symbols are not present in the binary.
Quoted 5 lines
Quoted 5 lines
lib/eal/common/eal_common_trace_points.c RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, · line 141
Quoted 3 lines
lib/eal/common/eal_common_trace_points.c +3
-0+*/ +rte_trace_point_t __rte_pmu_trace_read; +#endif From a quick look, could you export this symbol from the PMU library
itself?
Quoted 2 lines
Got caught up, but here is my take. It would likely make trace a
dependency, but I believe the
Quoted 1 line
dependency should be reversed. Also from my perspective this
Quoted 9 lines
suggestion feels more like a
Quoted 3 lines
refactoring.
So unless I've misunderstood your point, I'd rater keep the current
solution as is.
I think you got it right: a refactoring looks beneficial. Please think about it.
Quoted 6 lines
It's a long term goal (wishful thinking?) to move Trace out of the EAL, and into a separate library. Considering this long term goal, refactoring PMU to make it depend on Trace would be a step in the wrong direction.
However, if we disregard this long term goal, and do consider Trace a core part of the EAL, refactoring PMU to depend on Trace seems cleaner to me too.
I'm in favor of not adding more obstacles to moving Trace out of the EAL, i.e. don't refactor PMU to depend on Trace.
Tried moving that to pmu itself but unfortunately it won't compile due to current dependencies. PMU gets build before EAL so some symbols coming from trace (which is part of EAL anyway) cannot be resolved.
That said, I decided to cut corners and moved workaround along with lengthy explanation to rte_pmu.h. With that, at least EAL internals are cleaner and automatic symbol export is resolved too.
Let's continue discussion under v8.
Quoted 3 lines
Also, I tend to agree with Tomasz about PMU being lower level than Trace, so PMU depending on Trace seems wrong. No strong opinion on this last point, though.
@Jerin, what do you think?
PATCH v7 8/8 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v8 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v8:
- export __rte_pmu_trace_read from library itself to avoid build issues with msvc linker
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (8):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 60 ++++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 49 +++++++++++- 21 files changed, 370 insertions(+), 83 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v8 1/8 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
PATCH v8 2/8 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v8 3/8 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 4/8 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v8 5/8 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v8 6/8 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v8 7/8 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ doc/guides/rel_notes/release_25_07.rst | 2 + lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 42 +++++++++++++ 17 files changed, 239 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1850,6 +1850,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
doc/guides/rel_notes/release_25_07.rst +2 -0
@@ -71,6 +71,8 @@ New Features Added a Performance Monitoring Unit (PMU) library which allows Linux applications to perform self monitoring activities without depending on external utilities like perf. + After integration with :doc:`../prog_guide/trace_lib`, data gathered from hardware counters + can be stored in CTF format for further analysis. * **Added Mucse rnp net driver.**
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +5 -0
@@ -119,3 +119,8 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +42 -0
78 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 8/8 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v9 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v9:
- properly rebase patch integrating pmu and trace
v8:
- export __rte_pmu_trace_read from library itself to avoid build issues with msvc linker
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (8):
lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 60 ++++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 +++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 + lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 92 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 49 +++++++++++- 20 files changed, 368 insertions(+), 83 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
--
2.34.1
PATCH v9 1/8 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Add a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
Re: [PATCH v9 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 16 lines · On Wed, 23 Jul 2025 06:41:11 +0200 Tomasz Duszynski <[email protected]>…
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0
lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 239
Quoted 8 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif
Seems like a problem that could be fixed cleaner in chkincs?
Re: [PATCH v9 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 17 lines
Quoted 17 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)
Quoted 9 lines
lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 239
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like a problem that could be fixed cleaner in chkincs?
I don't think there is good solution to this problem. From one angle chinkcs should detect violations to experimental api calling conventions and it does that. This library is injected into eal tracing so calling experimental api happens hence warnings are showing up.
On the other hand adding some exception list (or whatever) to chkincs could encourage similar cases by making it a) easy b) looking clean. What I have now is at least not very appealing.
It looks like this library is the only one non-compliant to experimental api calling rules so I'd leave that workaround as is hoping that it won't be experimental for too long.
Re: [PATCH v9 1/8] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 31 lines · On Fri, 1 Aug 2025 11:37:06 +0200 Tomasz Duszynski <[email protected]>…
Quoted 17 lines
Quoted 17 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)Quoted 9 lines
lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 239
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like a problem that could be fixed cleaner in chkincs?
I don't think there is good solution to this problem. From one angle chinkcs should detect violations to experimental api calling conventions and it does that. This library is injected into eal tracing so calling experimental api happens hence warnings are showing up.
Quoted 5 lines
On the other hand adding some exception list (or whatever) to chkincs could encourage similar cases by making it a) easy b) looking clean. What I have now is at least not very appealing.
It looks like this library is the only one non-compliant to experimental api calling rules so I'd leave that workaround as is hoping that it won't be experimental for too long.
I would rather just make some of the function non-experimental or internal.
PATCH v9 2/8 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v9 3/8 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v9 4/8 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v9 5/8 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v9 6/8 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v9 7/8 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ lib/eal/common/eal_common_trace.c | 5 +- lib/eal/common/eal_common_trace_pmu.c | 38 ++++++++++++ lib/eal/common/eal_common_trace_points.c | 5 ++ lib/eal/common/eal_trace.h | 4 ++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 69 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 42 +++++++++++++ 16 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c
MAINTAINERS +1 -0
@@ -1849,6 +1849,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
lib/eal/common/eal_common_trace.c +4 -1
@@ -75,8 +75,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +94,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#include <rte_common.h> + +#include "eal_trace.h" + +#ifdef RTE_LIB_PMU + +#include <rte_pmu.h> + +void +trace_pmu_args_apply (const char *arg) +{ +static bool once; + +if (!once) { +if (rte_pmu_init ()) +return ; + once = true; + } + +rte_pmu_add_events_by_pattern (arg); +} + +void +trace_pmu_args_free (void ) +{ +rte_pmu_fini (); +} + +#else /* !RTE_LIB_PMU */ + +void trace_pmu_args_apply(const char *arg __rte_unused) { return; } +void trace_pmu_args_free (void ) {return ; } + +#endif /* RTE_LIB_PMU */
lib/eal/common/eal_common_trace_points.c +5 -0
@@ -119,3 +119,8 @@ RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_enable, lib.eal.intr.enable) RTE_TRACE_POINT_REGISTER(rte_eal_trace_intr_disable, lib.eal.intr.disable) + +#ifdef RTE_LIB_PMU +RTE_TRACE_POINT_REGISTER (rte_pmu_trace_read, + lib.pmu.read) +#endif
lib/eal/common/eal_trace.h +4 -0
@@ -104,6 +104,10 @@ int trace_epoch_time_save(void);void trace_mem_free (void );void trace_mem_per_thread_free (void ); +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); +/* EAL interface */ int eal_trace_init (void );void eal_trace_fini (void );
lib/eal/common/meson.build +1 -0
@@ -28,6 +28,7 @@ sources += files( 'eal_common_tailqs.c', 'eal_common_thread.c', 'eal_common_timer.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_points.c', 'eal_common_uuid.c', 'malloc_elem.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +67 -2
93 lines not on this page · raw message
lib/pmu/rte_pmu.h +42 -0
78 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v9 8/8 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v10 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v10:
- fix build without ALLOW_EXPERIMENTAL_API
- move rte_pmu_tread_read() registration to avoid MSVC linker issues v9:
- properly rebase patch integrating pmu and trace
v8:
- export __rte_pmu_trace_read from library itself to avoid build issues with msvc linker
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (10):
trace: change scope of conditional block
lib/pmu: fix build error if ALLOW_EXPERIMENAL_API is undefined lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs lib/pmu: export only necessary arch headers
lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 60 +++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 +++++++ lib/eal/common/eal_common_trace.c | 6 +- lib/eal/common/eal_common_trace_pmu.c | 45 ++++++++++ lib/eal/common/eal_trace_pmu.h | 12 +++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 ++++ lib/eal/include/rte_trace_point.h | 10 ++- lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 97 +++++++++++++++++----- lib/pmu/pmu_arm64.c | 59 +++++-------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 32 ++++++- 19 files changed, 369 insertions(+), 84 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c create mode 100644 lib/eal/common/eal_trace_pmu.h
--
2.34.1
PATCH v10 1/10 trace: change scope of conditional block
If ALLOW_EXPERIMENTAL_API isn't defined warnings should show up but build itself should not fail (unless -Dwerror=true).
In order to avoid build failures change the scope of conditional block.
--- lib/eal/include/rte_trace_point.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/eal/include/rte_trace_point.h +2 -1
@@ -289,7 +289,6 @@ int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,#ifndef __DOXYGEN__#ifndef _RTE_TRACE_POINT_REGISTER_H_ -#ifdef ALLOW_EXPERIMENTAL_API #define __RTE_TRACE_EVENT_HEADER_ID_SHIFT (48)
@@ -314,6 +313,8 @@ struct __rte_trace_header {uint8_t mem[]; }; +#ifdef ALLOW_EXPERIMENTAL_API + RTE_DECLARE_PER_LCORE(void *, trace_mem); static __rte_always_inline void *
Signature · 1 line
2.34.1
PATCH v10 2/10 lib/pmu: fix build error if ALLOW_EXPERIMENAL_API is undefined
In reply to Tomasz DuszynskiWorkaround that quiesces chincs check should be "turned-ff" not to cause build failures in scenarios where experimental apis are disallowed.
--- lib/pmu/pmu.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/pmu.c +4 -0
@@ -291,6 +291,10 @@ cleanup_events(struct rte_pmu_event_group *group) group->enabled = false; } +/* stop propagating chkincs quiescing to prevent unintended effects */ +#ifdef __rte_pmu_enable_group +#undef __rte_pmu_enable_group +#endif RTE_EXPORT_EXPERIMENTAL_SYMBOL(__rte_pmu_enable_group, 25.07)int __rte_pmu_enable_group (struct rte_pmu_event_group *group)
Signature · 1 line
2.34.1
PATCH v10 3/10 lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
In reply to Tomasz DuszynskiAdd a dummy rte_pmu_read() definition for chkincs when ALLOW_EXPERIMENTAL_API is not defined to suppress warnings from use of experimental APIs in tracepoints.
--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/pmu/rte_pmu.h +4 -0
@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif #ifdef __cplusplus }
Signature · 1 line
2.34.1
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 16 lines · On Fri, 1 Aug 2025 12:21:02 +0200 Tomasz Duszynski <[email protected]>…
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0
lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif
Seems like an awkward solution I would rather that fix chkincs or restructure this.
The way you are doing it will cause the checks for use of experimental API to not work.
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 27 lines
Quoted 16 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like an awkward solution I would rather that fix chkincs or restructure this.
Quoted 2 lines
The way you are doing it will cause the checks for use of experimental API to not work.
No matter how I shuffle things around, the experimental API keeps getting called from non-experimental code, so those warnings will show up.. Fixing chkincs would mean telling it to skip checks for this library, which is basically what I'm already doing here.
Dropping experimental tag feels too soon. The library still needs some time to bake.
So, unless anyone has got other ideas, which is the better trade off here: yanking experimental tags or tweaking chkincs to ignore the library checks?
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 30 lines
Quoted 27 lines
Quoted 16 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like an awkward solution I would rather that fix chkincs or restructure this.
Quoted 2 lines
The way you are doing it will cause the checks for use of experimental API to not work.
Quoted 8 lines
No matter how I shuffle things around, the experimental API keeps getting called from non-experimental code, so those warnings will show up.. Fixing chkincs would mean telling it to skip checks for this library, which is basically what I'm already doing here.
Dropping experimental tag feels too soon. The library still needs some time to bake.
So, unless anyone has got other ideas, which is the better trade off here: yanking experimental tags or tweaking chkincs to ignore the library checks?
Any preference or other comments regarding that?
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 34 lines
Quoted 34 lines
Quoted 27 lines
Quoted 16 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like an awkward solution I would rather that fix chkincs or restructure this.
Quoted 2 lines
The way you are doing it will cause the checks for use of experimental API to not work.
No matter how I shuffle things around, the experimental API keeps getting called from non-experimental code, so those warnings will show up.. Fixing chkincs would mean telling it to skip checks for this library, which is basically what I'm already doing here.
Quoted 6 lines
Quoted 4 lines
Dropping experimental tag feels too soon. The library still needs some time to bake.
So, unless anyone has got other ideas, which is the better trade off here: yanking experimental tags or tweaking chkincs to ignore the library checks?
Any preference or other comments regarding that?
Friendly reminder here. Can we agree on something?
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Quoted 35 lines · Tomasz Duszynski
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
Quoted 17 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like an awkward solution I would rather that fix chkincs or restructure this.
Quoted 2 lines
The way you are doing it will cause the checks for use of experimental API to not work.
No matter how I shuffle things around, the experimental API keeps getting called from non-experimental code, so those warnings will show up.. Fixing chkincs would mean telling it to skip checks for this library, which is basically what I'm already doing here.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Dropping experimental tag feels too soon. The library still needs some time to bake.
So, unless anyone has got other ideas, which is the better trade off here: yanking experimental tags or tweaking chkincs to ignore the library checks?
What we have been doing in other libraries is to hide calls to experimental symbols in inline helpers, which is the issue here, right?
Then add a RTE_VERIFY(false) so that an abort is triggered at runtime in case an application called this helper.
See a3e126fd58d1 ("bitset: fix build for GCC without experimental API") for example.
I see the same #define hiding for __rte_pmu_enable_group and __rte_pmu_read_userpage.
Something like below should be applied on main before looking at this new series.
$ git diff
lib/pmu/rte_pmu.h +1 -1
@@ -31,6 +31,7 @@#include <rte_branch_prediction.h> #include <rte_common.h> #include <rte_compat.h> +#include <rte_debug.h> #include <rte_lcore.h> #define RTE_PMU_SUPPORTED
@@ -181,12 +182,6 @@ __rte_experimentalint rte_pmu_add_event (const char *name); -/* quiesce warnings produced by chkincs caused by calling internal
functions directly */
-#ifndef ALLOW_EXPERIMENTAL_API
-#define __rte_pmu_enable_group(group) ({ RTE_SET_USED(group); 0; }) -#define __rte_pmu_read_userpage(pc) ({ RTE_SET_USED(pc); 0; }) -#endif
-
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
@@ -211,6 +206,7 @@ __rte_experimental
static __rte_always_inline uint64_t rte_pmu_read(unsigned int index)
{
+#ifdef ALLOW_EXPERIMENTAL_API
unsigned int lcore_id = rte_lcore_id();
struct rte_pmu_event_group *group;@@ -231,6 +227,10 @@ rte_pmu_read(unsigned int index)
}
return __rte_pmu_read_userpage(group->mmap_pages[index]);+#else
+ RTE_SET_USED(index);
+ RTE_VERIFY(false);
+#endif
}
#ifdef __cplusplus
Signature · 1 line
David Marchand
Re: [PATCH v10 03/10] lib/pmu: quiesce rte_pmu_read deprecation warning in chkincs
Hello Tomasz,
Recently David has improved the checks on headers. We would like to see a new revision
(with the approach described below by David) passing in the CI with the new checks.
Thanks
17/10/2025 10:45, David Marchand:
Quoted 103 lines · Tomasz Duszynski
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
Quoted 17 lines
Add a dummy
rte_pmu_read()definition for chkincs whenALLOW_EXPERIMENTAL_APIis not defined to suppress warnings from use of experimental APIs in tracepoints.Fixes 960c43184c4d ("pmu: introduce library for reading PMU events")Signed-off-by Tomasz Duszynski <[email protected]>--- lib/pmu/rte_pmu.h | 4 ++++ 1 file changed, 4 insertions(+)lib/pmu/rte_pmu.h +0
-0lib/pmu/rte_pmu.h rte_pmu_read(unsigned int index) · line 238
Quoted 7 lines
lib/pmu/rte_pmu.h +4
-0@@ -232,6 +232,10 @@ rte_pmu_read(unsigned int index)return __rte_pmu_read_userpage (group->mmap_pages[index]); } +/* quiesce warnings produced by chkincs */ +#ifndef ALLOW_EXPERIMENTAL_API +#define rte_pmu_read (pc) ({ RTE_SET_USED(pc); 0; }) +#endif Seems like an awkward solution I would rather that fix chkincs or restructure this.
Quoted 2 lines
The way you are doing it will cause the checks for use of experimental API to not work.
No matter how I shuffle things around, the experimental API keeps getting called from non-experimental code, so those warnings will show up.. Fixing chkincs would mean telling it to skip checks for this library, which is basically what I'm already doing here.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Dropping experimental tag feels too soon. The library still needs some time to bake.
So, unless anyone has got other ideas, which is the better trade off here: yanking experimental tags or tweaking chkincs to ignore the library checks?
What we have been doing in other libraries is to hide calls to experimental symbols in inline helpers, which is the issue here, right?
Then add aRTE_VERIFY(false)so that an abort is triggered at runtime in case an application called this helper.See
a3e126fd58d1("bitset: fix build for GCC without experimental API") for example.I see the same #define hiding for
__rte_pmu_enable_groupand__rte_pmu_read_userpage.
Something like below should be applied on main before looking at this new series.$ git difflib/pmu/rte_pmu.h +1
-1@@ -31,6 +31,7 @@#include <rte_branch_prediction.h> #include <rte_common.h> #include <rte_compat.h> +#include <rte_debug.h> #include <rte_lcore.h> #define RTE_PMU_SUPPORTED @@ -181,12 +182,6 @@ __rte_experimentalint rte_pmu_add_event (const char *name); -/* quiesce warnings produced by chkincs caused by calling internal functions directly */
lib/pmu/rte_pmu.h +5
-5-#ifndef ALLOW_EXPERIMENTAL_API -#define __rte_pmu_enable_group (group) ({ RTE_SET_USED(group); 0; }) -#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; }) -#endif -/** * @warning * @b EXPERIMENTAL: this API may change without prior notice. @@ -211,6 +206,7 @@ __rte_experimental static __rte_always_inline uint64_trte_pmu_read (unsigned int index) { +#ifdef ALLOW_EXPERIMENTAL_API unsigned int lcore_id =rte_lcore_id ();struct rte_pmu_event_group *group;@@ -231,6 +227,10 @@ rte_pmu_read(unsigned int index) }return __rte_pmu_read_userpage (group->mmap_pages[index]); +#else +RTE_SET_USED (index); +RTE_VERIFY (false); +#endif }#ifdef __cplusplus
PATCH v10 4/10 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v10 5/10 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 6/10 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
Re: [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64
Quoted 8 lines · On Fri, 1 Aug 2025 12:21:05 +0200 Tomasz Duszynski <[email protected]>…
/proc/sys/kernel/perf_user_accessattribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.Signed-off-by Tomasz Duszynski <[email protected]>---
What do Linux perf tools do in this case?
Re: [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64
Quoted 9 lines
Quoted 6 lines · On Fri, 1 Aug 2025 12:21:05 +0200 Tomasz Duszynski <[email protected]>…
/proc/sys/kernel/perf_user_accessattribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Tomasz Duszynski <[email protected]>---
What do Linux perf tools do in this case?
perf does not collect data directly reading pmu rigisters. It gets data by calling read() on descriptor returned by perf_event_open().
This series on the other hand, is for allowing that direct through-register access to save on cycles.
perf test -v user may be used to check if direct access can work.
On arm64 with perf_user_access=0:
$ perf test -v user Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc 4.2: User space counter reading of instructions : Skip (permissions) 4.3: User space counter reading of cycles : Skip (permissions)
On arm64 with perf_user_access=1:
$ perf test -v user Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc 4.2: User space counter reading of instructions : Ok 4.3: User space counter reading of cycles : Ok
On x86 there is no perf_user_access knob available so you achieve same functionality with perf_event_paranoid.
RE: [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz DuszynskiQuoted 9 lines
Subject: [PATCH v10 06/10] lib/pmu: do not try enabling perf counter access on arm64
/proc/sys/kernel/perf_user_accessattribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.Signed-off-by Tomasz Duszynski <[email protected]>
Quoted 110 lines
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)lib/pmu/pmu.c index 8cf2e89c69..97bab80368 renamed from lib/pmu/pmu.c +0
-0100644
lib/pmu/pmu.c +0
-0@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m)) RTE_LOG_REGISTER_DEFAULT(rte_pmu_logtype, INFO) -#define
RTE_LOGTYPE_PMUrte_pmu_logtypelib/pmu/pmu.c +0
-3- -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__)/* A structure describing an event */ struct rte_pmu_event {lib/pmu/pmu_arm64.c index renamed from lib/pmu/pmu_arm64.c +0
-0
3f4f5fa297..2c40b5f702100644lib/pmu/pmu_arm64.c +0
-2@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int(const char *path, int *val) { @@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)lib/pmu/pmu_arm64.c +7
-29return 0 ; } -static int -write_attr_int(const char *path, int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static voidlib/pmu/pmu_private.h index renamed from lib/pmu/pmu_private.h +0
-0
d74f7f4092..82118df8b3100644lib/pmu/pmu_private.h +8
-1@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */ --2.34.1
PATCH v10 7/10 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -33,13 +33,10 @@#include <rte_compat.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v10 8/10 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
PATCH v10 9/10 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ lib/eal/common/eal_common_trace.c | 6 +- lib/eal/common/eal_common_trace_pmu.c | 45 ++++++++++++++ lib/eal/common/eal_trace_pmu.h | 12 ++++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 16 +++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 70 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 25 ++++++++ 15 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c create mode 100644 lib/eal/common/eal_trace_pmu.h
MAINTAINERS +1 -0
@@ -1849,6 +1849,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
lib/eal/common/eal_common_trace.c +5 -1
@@ -16,6 +16,7 @@#include <eal_export.h> #include "eal_trace.h" +#include "eal_trace_pmu.h" RTE_EXPORT_EXPERIMENTAL_SYMBOL(per_lcore_trace_point_sz, 20.05) RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
@@ -75,8 +76,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +95,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +45 -0
45 lines not on this page · raw message
lib/eal/common/eal_trace_pmu.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#ifndef __EAL_TRACE_PMU_H +#define __EAL_TRACE_PMU_H + +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); + +#endif /* __EAL_TRACE_PMU_H */
lib/eal/common/meson.build +1 -0
@@ -48,6 +48,7 @@ if not is_windows 'eal_common_hypervisor.c', 'eal_common_proc.c', 'eal_common_trace.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_ctf.c', 'eal_common_trace_utils.c', 'hotplug_mp.c',
lib/eal/include/rte_eal_trace.h +16 -0
@@ -127,6 +127,22 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val = rte_pmu_read(index); + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['log', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +68 -2
100 lines not on this page · raw message
lib/pmu/rte_pmu.h +25 -0
@@ -21,12 +21,17 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */ #include <linux/perf_event.h> +#include <eal_export.h> #include <rte_atomic.h> #include <rte_branch_prediction.h> #include <rte_common.h>
@@ -145,6 +150,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -157,6 +164,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -184,6 +194,21 @@ rte_pmu_add_event(const char *name);#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; })#endif +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
PATCH v10 10/10 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v11 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiThis series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v11:
- rebase series
- hide calls to experimental syms in inline helpers
v10:
- fix build without ALLOW_EXPERIMENTAL_API
- move rte_pmu_tread_read() registration to avoid MSVC linker issues v9:
- properly rebase patch integrating pmu and trace
v8:
- export __rte_pmu_trace_read from library itself to avoid build issues with msvc linker
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
v3:
- do not export __rte_pmu_trace_read because that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config has RTE_LIB_PMU
Tomasz Duszynski (10):
trace: change scope of conditional block lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined RTE_LIB_PMU macro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
MAINTAINERS | 1 + app/test/test_pmu.c | 60 ++++++++++++-- app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++ lib/eal/common/eal_common_trace.c | 6 +- lib/eal/common/eal_common_trace_pmu.c | 45 +++++++++++ lib/eal/common/eal_trace_pmu.h | 12 +++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 23 ++++++ lib/eal/include/rte_trace_point.h | 10 ++- lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/meson.build | 10 +-- lib/pmu/pmu.c | 93 ++++++++++++++++------ lib/pmu/pmu_arm64.c | 59 +++++--------- lib/pmu/pmu_private.h | 51 ++++++++++-- lib/pmu/rte_pmu.h | 37 +++++++-- 19 files changed, 372 insertions(+), 89 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c create mode 100644 lib/eal/common/eal_trace_pmu.h
--
2.34.1
PATCH v11 1/9 pmu: quiesce chkincs warnings
chkincs tool produces warnings if internal functions are called directly.
There are multiple ways to quiesce these warnings but common pattern now is excluding experimental code from build and triggering abort in runtime.
Follow that pattern here.
--- lib/pmu/rte_pmu.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
lib/pmu/rte_pmu.h +6 -6
@@ -31,6 +31,7 @@#include <rte_branch_prediction.h> #include <rte_common.h> #include <rte_compat.h> +#include <rte_debug.h> #include <rte_lcore.h> #define RTE_PMU_SUPPORTED
@@ -181,12 +182,6 @@ __rte_experimentalint rte_pmu_add_event (const char *name); -/* quiesce warnings produced by chkincs caused by calling internal functions directly */ -#ifndef ALLOW_EXPERIMENTAL_API -#define __rte_pmu_enable_group (group) ({ RTE_SET_USED(group); 0; }) -#define __rte_pmu_read_userpage (pc) ({ RTE_SET_USED(pc); 0; }) -#endif -/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
@@ -211,6 +206,7 @@ __rte_experimental static __rte_always_inline uint64_trte_pmu_read (unsigned int index) { +#ifdef ALLOW_EXPERIMENTAL_API unsigned int lcore_id =rte_lcore_id ();struct rte_pmu_event_group *group;
@@ -231,6 +227,10 @@ rte_pmu_read(unsigned int index) }return __rte_pmu_read_userpage (group->mmap_pages[index]); +#else +RTE_SET_USED (index); +RTE_VERIFY (false); +#endif }#ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v11 2/9 trace: change scope of conditional block
In reply to Tomasz DuszynskiIf ALLOW_EXPERIMENTAL_API isn't defined warnings should show up but build itself should not fail (unless -Dwerror=true).
In order to avoid build failures change the scope of conditional block.
--- lib/eal/include/rte_trace_point.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/eal/include/rte_trace_point.h +2 -1
@@ -289,7 +289,6 @@ int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,#ifndef __DOXYGEN__#ifndef _RTE_TRACE_POINT_REGISTER_H_ -#ifdef ALLOW_EXPERIMENTAL_API #define __RTE_TRACE_EVENT_HEADER_ID_SHIFT (48)
@@ -314,6 +313,8 @@ struct __rte_trace_header {uint8_t mem[]; }; +#ifdef ALLOW_EXPERIMENTAL_API + RTE_DECLARE_PER_LCORE(void *, trace_mem); static __rte_always_inline void *
Signature · 1 line
2.34.1
PATCH v11 3/9 lib/pmu: export only necessary arch headers
In reply to Tomasz DuszynskiInstall only architecture specific headers to avoid header pollution.
--- lib/pmu/meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/pmu/meson.build +5 -5
@@ -10,13 +10,13 @@ endif headers = files('rte_pmu.h') sources = files('pmu.c') -indirect_headers += files( - 'rte_pmu_pmc_arm64.h', - 'rte_pmu_pmc_x86_64.h', -) - if dpdk_conf.has('RTE_ARCH_ARM64') + indirect_headers += files('rte_pmu_pmc_arm64.h') sources += files('pmu_arm64.c') endif +if dpdk_conf.has('RTE_ARCH_X86_64') + indirect_headers += files('rte_pmu_pmc_x86_64.h') +endif + deps += ['log']
Signature · 1 line
2.34.1
PATCH v11 4/9 lib/pmu: reimplement per-arch ops as callbacks
In reply to Tomasz DuszynskiReplace static per-architecture ops with a callback-based ops structure. This makes architecture-specific PMU implementations more modular and easier to extend.
--- lib/pmu/pmu.c | 17 +---------------- lib/pmu/pmu_arm64.c | 19 +++++++++++++------ lib/pmu/pmu_private.h | 43 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 28 deletions(-)
lib/pmu/pmu.c +1 -16
@@ -40,22 +40,7 @@ struct rte_pmu_event {RTE_EXPORT_INTERNAL_SYMBOL (rte_pmu) struct rte_pmu rte_pmu; -/* Stubs for arch-specific functions */ -#if !defined(RTE_PMU_SUPPORTED ) || defined(RTE_ARCH_X86_64 ) -int -pmu_arch_init (void ) -{ -return 0 ; -} -void -pmu_arch_fini (void ) -{ -} -void -pmu_arch_fixup_config(uint64_t __rte_unused config[3]) -{ -} -#endif +const struct pmu_arch_ops *arch_ops;static int get_term_format (const char *name,int *num,uint64_t *mask)
lib/pmu/pmu_arm64.c +13 -6
@@ -62,8 +62,8 @@ write_attr_int(const char *path, int val)return 0 ; } -int -pmu_arch_init (void ) +static int +pmu_arm64_init (void ) {int ret;
@@ -78,17 +78,24 @@ pmu_arch_init(void)return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); } -void -pmu_arch_fini (void ) +static void +pmu_arm64_fini (void ) {write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } -void -pmu_arch_fixup_config (uint64_t config[3 ]) +static void +pmu_arm64_fixup_config (uint64_t config[3 ]) {/* select 64 bit counters */ config[1 ] |=RTE_BIT64 (0 );/* enable userspace access */ config[1 ] |=RTE_BIT64 (1 ); } + +static const struct pmu_arch_ops arm64_ops = { + .init = pmu_arm64_init, + .fini = pmu_arm64_fini, + .fixup_config = pmu_arm64_fixup_config, +}; +PMU_SET_ARCH_OPS (arm64_ops)
lib/pmu/pmu_private.h +37 -6
64 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v11 5/9 lib/pmu: do not try enabling perf counter access on arm64
In reply to Tomasz Duszynski/proc/sys/kernel/perf_user_access attribute allow user process to access perf counters. Though in order to change it binary requires elevated capabilities or must be run as root. If that's not the case counter access remains disabled. Hence to avoid confusion log message that that warns user about that.
--- lib/pmu/pmu.c | 4 ---- lib/pmu/pmu_arm64.c | 39 +++++++-------------------------------- lib/pmu/pmu_private.h | 8 ++++++++ 3 files changed, 15 insertions(+), 36 deletions(-)
lib/pmu/pmu.c +0 -4
@@ -25,10 +25,6 @@#define FIELD_PREP (m, v) (((uint64_t)(v) << (rte_ffs64(m) - 1)) & (m))RTE_LOG_REGISTER_DEFAULT (rte_pmu_logtype,INFO ) -#define RTE_LOGTYPE_PMU rte_pmu_logtype - -#define PMU_LOG (level, ...) \ - RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) /* A structure describing an event */struct rte_pmu_event {
lib/pmu/pmu_arm64.c +7 -32
@@ -14,8 +14,6 @@#define PERF_USER_ACCESS_PATH "/proc/sys/kernel/perf_user_access" -static int restore_uaccess; -static int read_attr_int (const char *path,int *val) {
@@ -39,49 +37,26 @@ read_attr_int(const char *path, int *val)return 0 ; } -static int -write_attr_int (const char *path,int val) -{ -char buf[BUFSIZ ]; -int num, ret, fd; - - fd =open (path,O_WRONLY ); -if (fd ==-1 ) -return -errno; - - num =snprintf (buf,sizeof (buf),"%d" , val); - ret =write (fd, buf, num); -if (ret ==-1 ) { -close (fd); - -return -errno; - } - -close (fd); - -return 0 ; -} -static int pmu_arm64_init (void ) { -int ret; +int uaccess, ret; - ret =read_attr_int (PERF_USER_ACCESS_PATH , &restore_uaccess); + ret =read_attr_int (PERF_USER_ACCESS_PATH , &uaccess);if (ret)return ret; -/* user access already enabled */ -if (restore_uaccess ==1 ) -return 0 ; +if (uaccess !=1 ) +PMU_LOG (WARNING ,"access to perf counters disabled, " +"run 'echo 1 > %s' to enable" , +PERF_USER_ACCESS_PATH ); -return write_attr_int (PERF_USER_ACCESS_PATH ,1 ); +return ret; }static void pmu_arm64_fini (void ) { -write_attr_int (PERF_USER_ACCESS_PATH , restore_uaccess); } static void
lib/pmu/pmu_private.h +8 -0
@@ -5,6 +5,14 @@#ifndef PMU_PRIVATE_H #define PMU_PRIVATE_H +#include <rte_log.h> + +extern int rte_pmu_logtype; +#define RTE_LOGTYPE_PMU rte_pmu_logtype + +#define PMU_LOG (level, ...) \ + RTE_LOG_LINE(level, PMU, ## __VA_ARGS__) +/** * Structure describing architecture specific PMU operations. */
Signature · 1 line
2.34.1
PATCH v11 6/9 lib/pmu: use build system defined RTE_LIB_PMU macro
In reply to Tomasz DuszynskiRTE_LIB_PMU is defined by build system automatically if DPDK is build for Linux. Otherwise it's missing.
That said all cases where conditional compilation is required can be handled without introducing other macros.
--- lib/pmu/rte_pmu.h | 3 --- 1 file changed, 3 deletions(-)
lib/pmu/rte_pmu.h +0 -3
@@ -34,13 +34,10 @@#include <rte_debug.h> #include <rte_lcore.h> -#define RTE_PMU_SUPPORTED #if defined(RTE_ARCH_ARM64 )#include "rte_pmu_pmc_arm64.h" #elif defined(RTE_ARCH_X86_64 )#include "rte_pmu_pmc_x86_64.h" -#else -#undef RTE_PMU_SUPPORTED#endif #ifdef __cplusplus
Signature · 1 line
2.34.1
PATCH v11 7/9 test/pmu: enable test
In reply to Tomasz DuszynskiEnable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu);
Signature · 1 line
2.34.1
RE: [PATCH v11 7/9] test/pmu: enable test
Quoted 10 lines
From: Tomasz Duszynski [mailto:[email protected]]
Sent: Friday, 24 October 2025 07.48Enable test to allow users to verify basic functionality. Due to varying
configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.Signed-off-by Tomasz Duszynski <[email protected]>---
With these changes, the test can never return TEST_FAILED, it returns TEST_SKIPPED when something doesn't work.
IMO, the perf_allowed_quirk() check belongs in rte_pmu_init() instead.
Then, rte_pmu_init() could return a variety of error values depending on the reason for the inability to init/start the PMU library. Amongst the high level error values should be:-EACCES (insufficient privileges)-ENODEV (hardware has no PMU, or kernel is custom built without PMU)
The test should only return SKIPPED if rte_pmu_init() returns -ENODEV (no PMU present to test); any other non-success should cause the test to return FAILED.
Also, the possible return values from rte_pmu_init() should be documented in its function description.
Quoted 110 lines
app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)app/test/test_pmu.c +6
-0@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "
/proc/sys/kernel/perf_event_paranoid"app/test/test_pmu.c +16
-0+ +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged
app/test/test_pmu.c +3
-0+* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce
app/test/test_pmu.c +3
-0+* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to
perf_event_open()forapp/test/test_pmu.c +1
-0+* monitoring other processes, but still allows unprivileged self-monitoring.
app/test/test_pmu.c +1
-0+* See: https://lore.kernel.org/all/1469630746-32279-1-git- app/test/test_pmu.c +1
-0+* - Ubuntu adds level 4 (which is also the default), completely disabling
perf_event_open()app/test/test_pmu.c +1
-0+* for unprivileged users—effectively disabling self- monitoring.
app/test/test_pmu.c +2
-0+* +* That said, check below should be sufficient to enable this test on most kernels.
app/test/test_pmu.c +14
-3+*/ +return level <4 ; +} +static int test_pmu_read (void ) {@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't
app/test/test_pmu.c +1
-0+* necessarily mean the counter is actually zero. It might just signal a problem with setup
app/test/test_pmu.c +1
-0+* itself. So skip test to avoid testing failure and leave it to user to interpret this
app/test/test_pmu.c +4
-4+* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, true, true, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest, true, true, test_pmu); --2.34.1
PATCH v2 1/5 trace: change scope of conditional block
In reply to Tomasz DuszynskiFrom: Rakesh Kudurumalla <[email protected]>
If ALLOW_EXPERIMENTAL_API isn't defined warnings should show up but build itself should not fail (unless -Dwerror=true).
In order to avoid build failures change the scope of conditional block.
--- lib/eal/include/rte_trace_point.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/eal/include/rte_trace_point.h +2 -1
@@ -289,7 +289,6 @@ int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,#ifndef __DOXYGEN__#ifndef _RTE_TRACE_POINT_REGISTER_H_ -#ifdef ALLOW_EXPERIMENTAL_API #define __RTE_TRACE_EVENT_HEADER_ID_SHIFT (48)
@@ -314,6 +313,8 @@ struct __rte_trace_header {uint8_t mem[]; }; +#ifdef ALLOW_EXPERIMENTAL_API + RTE_DECLARE_PER_LCORE(void *, trace_mem); static __rte_always_inline void *
Signature · 1 line
2.25.1
PATCH v2 2/5 test/pmu: enable test
From: Rakesh Kudurumalla <[email protected]>
Enable test to allow users to verify basic functionality. Due to varying configuration options across distributions and kernels user should ensure that all requirements are satisfied before starting test.
--- app/test/test_pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
app/test/test_pmu.c +54 -6
@@ -2,10 +2,48 @@* Copyright(C) 2025 Marvell International Ltd. */ +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <rte_pmu.h> #include "test.h" +#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" + +static bool perf_allowed_quirk (void ) +{ +int level, ret; +FILE *fp; + + fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); +if (!fp) +return false; + + ret =fscanf (fp,"%d" , &level); +fclose (fp); +if (ret !=1 ) +return false; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +* +* That said, check below should be sufficient to enable this test on most kernels. +*/ +return level <4 ; +} +static int test_pmu_read (void ) {
@@ -24,8 +62,15 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if (rte_pmu_init () <0 ) -return TEST_FAILED ; +if ((getuid () !=0 ) && !perf_allowed_quirk ()) { +printf ("self-monitoring disabled\n" ); +return TEST_SKIPPED ; + } + +if (rte_pmu_init () <0 ) { +printf ("PMU not initialized\n" ); +return TEST_SKIPPED ; + } event =rte_pmu_add_event (name);while (tries--)
@@ -33,7 +78,12 @@ test_pmu_read(void)rte_pmu_fini (); -return val ?TEST_SUCCESS :TEST_FAILED ; +/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't +* necessarily mean the counter is actually zero. It might just signal a problem with setup +* itself. So skip test to avoid testing failure and leave it to user to interpret this +* outcome. +*/ +return val ?TEST_SUCCESS :TEST_SKIPPED ; }static struct unit_test_suite pmu_tests = {
@@ -52,6 +102,4 @@ test_pmu(void)return unit_test_suite_runner (&pmu_tests); } -/* disabled because of reported failures, waiting for a fix -* REGISTER_FAST_TEST(pmu_autotest, NOHUGE_OK, ASAN_OK, test_pmu); -*/ +REGISTER_FAST_TEST (pmu_autotest,NOHUGE_OK ,ASAN_OK , test_pmu);
Signature · 1 line
2.25.1
PATCH v2 3/5 trace: add PMU
In reply to rkudurumallaFrom: Rakesh Kudurumalla <[email protected]>
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 +++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 +++++++++ lib/eal/common/eal_common_trace.c | 6 +- lib/eal/common/eal_common_trace_pmu.c | 46 +++++++++++++ lib/eal/common/eal_trace_pmu.h | 13 ++++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 23 +++++++ lib/eal/include/rte_trace_point.h | 7 ++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 78 ++++++++++++++++++++-- lib/pmu/rte_pmu.h | 24 +++++++ 15 files changed, 244 insertions(+), 8 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c create mode 100644 lib/eal/common/eal_trace_pmu.h
MAINTAINERS +1 -0
@@ -1866,6 +1866,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
lib/eal/common/eal_common_trace.c +5 -1
@@ -16,6 +16,7 @@#include <eal_export.h> #include "eal_trace.h" +#include "eal_trace_pmu.h" RTE_EXPORT_EXPERIMENTAL_SYMBOL(per_lcore_trace_point_sz, 20.05) RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
@@ -75,8 +76,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +95,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +46 -0
46 lines not on this page · raw message
lib/eal/common/eal_trace_pmu.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#ifndef __EAL_TRACE_PMU_H +#define __EAL_TRACE_PMU_H + +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); + +#endif /* __EAL_TRACE_PMU_H */ +
lib/eal/common/meson.build +1 -0
@@ -48,6 +48,7 @@ if not is_windows 'eal_common_hypervisor.c', 'eal_common_proc.c', 'eal_common_trace.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_ctf.c', 'eal_common_trace_utils.c', 'hotplug_mp.c',
lib/eal/include/rte_eal_trace.h +23 -0
@@ -127,6 +127,29 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_debug.h> +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ +RTE_TRACE_POINT_EMBED_CODE ( + uint64_t val; +#ifdef ALLOW_EXPERIMENTAL_API + val = rte_pmu_read(index); +#else + RTE_SET_USED(index); + RTE_VERIFY(false); +#endif + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['argparse', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +72 -6
115 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -146,6 +150,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -158,6 +164,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -179,6 +188,21 @@ __rte_experimentalint rte_pmu_add_event (const char *name); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.25.1
Re: [PATCH v2 3/5] trace: add PMU
Hello,
This series is failing in the CI tests.
Are you working on a new version?
05/05/2026 07:30, rkudurumalla:
Quoted 9 lines
From: Rakesh Kudurumalla <[email protected]>
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>Signed-off-by Rakesh Kudurumalla <[email protected]>
PATCH v2 4/5 lib/pmu: fix out-of-bound access
In reply to rkudurumallaFrom: Rakesh Kudurumalla <[email protected]>
Make sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 54 +++++++++++++++++++++++++++++++++++++++++++-- lib/pmu/pmu_arm64.c | 3 ++- lib/pmu/rte_pmu.h | 12 +++++++++- 3 files changed, 65 insertions(+), 4 deletions(-)
lib/pmu/pmu.c +52 -2
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
@@ -419,6 +419,45 @@ rte_pmu_add_event(const char *name)return event->index; } +static int +check_perf_permissions (void ) +{ +const char *paranoid_path ="/proc/sys/kernel/perf_event_paranoid" ; +int level, ret; +FILE *fp; + +/* Check if user is root */ +if (getuid () ==0 ) +return 0 ;/* Root has access */ + + fp =fopen (paranoid_path,"r" ); +if (!fp) +return -ENOENT ;/* File doesn't exist */ + + ret =fscanf (fp,"%d" , &level); +fclose (fp); + +if (ret !=1 ) +return -EINVAL ; + +/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged +* processes to access performance counters. +* +* Debian / Ubuntu and their derivatives apply patches that introduce +* additional paranoia levels: +* +* - Debian adds level 3, which restricts access to perf_event_open() for +* monitoring other processes, but still allows unprivileged self-monitoring. +* See: https://lore.kernel.org/all/[email protected]/ +* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() +* for unprivileged users—effectively disabling self-monitoring. +*/ +if (level >=4 ) +return -EACCES ;/* Insufficient privileges */ + +return 0 ;/* Allowed */ +} +static int add_events (const char *pattern) {
@@ -492,10 +531,21 @@ rte_pmu_init(void)if (rte_pmu.initialized && ++rte_pmu.initialized)return 0 ; +/* Check permissions first */ + ret =check_perf_permissions (); +if (ret == -EACCES ) { +PMU_LOG (ERR ,"Insufficient privileges for PMU access (check perf_event_paranoid)" ); +return -EACCES ; + } +if (ret == -ENOENT ) { +PMU_LOG (ERR ,"Cannot access perf_event_paranoid file" ); +return -ENODEV ; + } + ret =scan_pmus ();if (ret) {PMU_LOG (ERR ,"Failed to scan for event sources" ); - goto out; +return -ENODEV ;/* No PMU hardware found */ } ret =pmu_arch_init ();
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
lib/pmu/rte_pmu.h +11 -1
@@ -150,10 +150,20 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* This function initializes the Performance Monitoring Unit (PMU) library +* by checking permissions, scanning for available PMU hardware, and setting up +* necessary architecture-specific internals. +* * It's safe to call it multiple times. * * @return -* 0 in case of success, negative value otherwise. +* 0 on success. +* -ENODEV if PMU hardware is not available or kernel lacks PMU support. +* -EACCES if insufficient privileges to access PMU. +* User should check /proc/sys/kernel/perf_event_paranoid settings. +* -ENOMEM if memory allocation failed. +* -EINVAL if invalid configuration detected. +* Other negative errno values on other failures. */ __rte_experimental int
Signature · 1 line
2.25.1
PATCH v2 5/5 test/pmu: improve error handling and enable test
In reply to rkudurumallaFrom: Rakesh Kudurumalla <[email protected]>
Improve test_pmu error handling to distinguish between different failure scenarios based on rte_pmu_init() return codes.
Changes:
- Handle -ENODEV (no hardware) -> return TEST_SKIPPED This is not a test failure, just missing hardware
- Handle -EACCES (permission denied) -> return TEST_FAILED This indicates a configuration issue that user must fix Provide helpful hint about adjusting perf_event_paranoid
- Handle other errors -> return TEST_FAILED
Unexpected errors should fail the test
- Add error checking for rte_pmu_add_event()
Print event name if addition fails
Properly cleanup with rte_pmu_fini()
- Check if PMU counter returned zero
Print message to help diagnose the issue
- Re-enable the test by adding REGISTER_FAST_TEST() Test was previously disabled due to failures
With improved error handling, failures can be properly diagnosed
This makes test results more informative:
- TEST_SKIPPED: No PMU hardware (expected on some platforms)
- TEST_FAILED: Configuration issue or real bug (requires action)
- TEST_SUCCESS: PMU working correctly
--- app/test/test_pmu.c | 74 +++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 49 deletions(-)
app/test/test_pmu.c +25 -49
@@ -2,53 +2,18 @@* Copyright(C) 2025 Marvell International Ltd. */ -#include <stdbool.h> +#include <errno.h> #include <stdio.h> -#include <sys/types.h> -#include <unistd.h> #include <rte_pmu.h> #include "test.h" -#define PERF_EVENT_PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" - -static bool perf_allowed_quirk (void ) -{ -int level, ret; -FILE *fp; - - fp =fopen (PERF_EVENT_PARANOID_PATH ,"r" ); -if (!fp) -return false; - - ret =fscanf (fp,"%d" , &level); -fclose (fp); -if (ret !=1 ) -return false; - -/* On vanilla Linux the default perf_event_paranoid level is 2, which allows non-privileged -* processes to access performance counters. -* -* Debian / Ubuntu and their derivatives apply patches that introduce -* additional paranoia levels: -* -* - Debian adds level 3, which restricts access to perf_event_open() for -* monitoring other processes, but still allows unprivileged self-monitoring. -* See: https://lore.kernel.org/all/[email protected]/ -* - Ubuntu adds level 4 (which is also the default), completely disabling perf_event_open() -* for unprivileged users—effectively disabling self-monitoring. -* -* That said, check below should be sufficient to enable this test on most kernels. -*/ -return level <4 ; -} -static int test_pmu_read (void ) {const char *name =NULL ; -int tries =10 , event; +int ret, tries =10 , event;uint64_t val =0 ;#if defined(RTE_ARCH_ARM64 )
@@ -62,28 +27,39 @@ test_pmu_read(void)return TEST_SKIPPED ; } -if ((getuid () !=0 ) && !perf_allowed_quirk ()) { -printf ("self-monitoring disabled\n" ); + ret =rte_pmu_init (); +if (ret == -ENODEV ) { +printf ("PMU hardware not available or kernel lacks PMU support\n" );return TEST_SKIPPED ; } - -if (rte_pmu_init () <0 ) { -printf ("PMU not initialized\n" ); -return TEST_SKIPPED ; +if (ret == -EACCES ) { +printf ("Insufficient privileges for PMU access\n" ); +printf ("Try: echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid\n" ); +return TEST_FAILED ; + } +if (ret <0 ) { +printf ("PMU initialization failed: %d\n" , ret); +return TEST_FAILED ; } event =rte_pmu_add_event (name); +if (event <0 ) { +printf ("Failed to add event '%s': %d\n" , name, event); +rte_pmu_fini (); +return TEST_FAILED ; + } +while (tries--) val +=rte_pmu_read (event);rte_pmu_fini (); -/* rte_pmu_read() returns zero if it can't read perf counter. Thus series of zeros doesn't -* necessarily mean the counter is actually zero. It might just signal a problem with setup -* itself. So skip test to avoid testing failure and leave it to user to interpret this -* outcome. -*/ -return val ?TEST_SUCCESS :TEST_SKIPPED ; +if (val ==0 ) { +printf ("PMU counter read returned zero\n" ); +return TEST_FAILED ; + } + +return TEST_SUCCESS ; }static struct unit_test_suite pmu_tests = {
Signature · 1 line
2.25.1
PATCH v11 8/9 trace: add PMU
In reply to Tomasz DuszynskiIn order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.
--- MAINTAINERS | 1 + app/test/test_trace_perf.c | 10 ++++ doc/guides/prog_guide/profile_app.rst | 5 ++ doc/guides/prog_guide/trace_lib.rst | 31 ++++++++++ lib/eal/common/eal_common_trace.c | 6 +- lib/eal/common/eal_common_trace_pmu.c | 45 ++++++++++++++ lib/eal/common/eal_trace_pmu.h | 12 ++++ lib/eal/common/meson.build | 1 + lib/eal/include/rte_eal_trace.h | 23 +++++++ lib/eal/include/rte_trace_point.h | 7 +++ lib/eal/include/rte_trace_point_register.h | 2 + lib/eal/meson.build | 3 + lib/meson.build | 2 +- lib/pmu/pmu.c | 70 +++++++++++++++++++++- lib/pmu/rte_pmu.h | 24 ++++++++ 15 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 lib/eal/common/eal_common_trace_pmu.c create mode 100644 lib/eal/common/eal_trace_pmu.h
MAINTAINERS +1 -0
@@ -1869,6 +1869,7 @@ F: doc/guides/prog_guide/eventdev/dispatcher_lib.rst PMU - EXPERIMENTAL M: Tomasz Duszynski <[email protected]> F: lib/pmu/ +F: lib/eal/common/eal_common_trace_pmu.c F: app/test/test_pmu.c Job statistics
app/test/test_trace_perf.c +10 -0
@@ -114,6 +114,10 @@ worker_fn_##func(void *arg) \#define GENERIC_DOUBLE rte_eal_trace_generic_double(3.66666)#define GENERIC_STR rte_eal_trace_generic_str("hello world")#define VOID_FP app_dpdk_test_fp() +#ifdef RTE_LIB_PMU +/* 0 corresponds first event passed via --trace= */ +#define READ_PMU rte_pmu_trace_read(0) +#endif WORKER_DEFINE (GENERIC_VOID)WORKER_DEFINE (GENERIC_U64)
@@ -122,6 +126,9 @@ WORKER_DEFINE(GENERIC_FLOAT) WORKER_DEFINE(GENERIC_DOUBLE) WORKER_DEFINE(GENERIC_STR) WORKER_DEFINE(VOID_FP) +#ifdef RTE_LIB_PMU +WORKER_DEFINE(READ_PMU) +#endif static void run_test (const char *str,lcore_function_t f,struct test_data *data,size_t sz)
@@ -174,6 +181,9 @@ test_trace_perf(void)run_test ("double" , worker_fn_GENERIC_DOUBLE, data, sz);run_test ("string" , worker_fn_GENERIC_STR, data, sz);run_test ("void_fp" , worker_fn_VOID_FP, data, sz); +#ifdef RTE_LIB_PMU +run_test ("read_pmu" , worker_fn_READ_PMU, data, sz); +#endif rte_free (data);return TEST_SUCCESS ;
doc/guides/prog_guide/profile_app.rst +5 -0
@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details. + Profiling on x86 ----------------
doc/guides/prog_guide/trace_lib.rst +31 -0
@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------
@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: + + --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``, +while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
lib/eal/common/eal_common_trace.c +5 -1
@@ -16,6 +16,7 @@#include <eal_export.h> #include "eal_trace.h" +#include "eal_trace_pmu.h" RTE_EXPORT_EXPERIMENTAL_SYMBOL(per_lcore_trace_point_sz, 20.05) RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
@@ -75,8 +76,10 @@ eal_trace_init(void) goto free_meta;/* Apply global configurations */ - STAILQ_FOREACH(arg, &trace.args, next) + STAILQ_FOREACH(arg, &trace.args, next) {trace_args_apply (arg->val); +trace_pmu_args_apply (arg->val); + }rte_trace_mode_set (trace.mode);
@@ -92,6 +95,7 @@ eal_trace_init(void)void eal_trace_fini (void ) { +trace_pmu_args_free ();trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free ();
lib/eal/common/eal_common_trace_pmu.c new file +45 -0
45 lines not on this page · raw message
lib/eal/common/eal_trace_pmu.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#ifndef __EAL_TRACE_PMU_H +#define __EAL_TRACE_PMU_H + +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); + +#endif /* __EAL_TRACE_PMU_H */
lib/eal/common/meson.build +1 -0
@@ -48,6 +48,7 @@ if not is_windows 'eal_common_hypervisor.c', 'eal_common_proc.c', 'eal_common_trace.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_ctf.c', 'eal_common_trace_utils.c', 'hotplug_mp.c',
lib/eal/include/rte_eal_trace.h +23 -0
@@ -127,6 +127,29 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_debug.h> +#include <rte_pmu.h> +RTE_TRACE_POINT_FP ( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), +/* Embedded code should only execute in runtime so cut it out during registration in order +* to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide +* any context. +*/ +RTE_TRACE_POINT_EMBED_CODE ( + uint64_t val; +#ifdef ALLOW_EXPERIMENTAL_API + val = rte_pmu_read(index); +#else + RTE_SET_USED(index); + RTE_VERIFY(false); +#endif + ) + rte_trace_point_emit_u64(val); +) +#endif + #ifdef __cplusplus }#endif
lib/eal/include/rte_trace_point.h +7 -0
@@ -46,6 +46,13 @@ typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;*/ #define RTE_TRACE_POINT_ARGS +/** +* Macro to define the tracepoint code in RTE_TRACE_POINT, RTE_TRACE_POINT_FP macros. + +* @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP +*/ +#define RTE_TRACE_POINT_EMBED_CODE (...) __VA_ARGS__ +/** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */ #define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \
lib/eal/include/rte_trace_point_register.h +2 -0
@@ -45,6 +45,8 @@ RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);#define RTE_TRACE_POINT_ARGS (...) \ (RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0, __VA_ARGS__), __VA_ARGS__)) +#define RTE_TRACE_POINT_EMBED_CODE (...) +#define __RTE_TRACE_POINT (_mode, _tp, _args, ...) \ extern rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args { } \
lib/eal/meson.build +3 -0
@@ -15,6 +15,9 @@ subdir(exec_env) subdir(arch_subdir) deps += ['argparse', 'kvargs'] +if is_linux and dpdk_conf.has('RTE_LIB_PMU') + deps += ['pmu'] +endif if not is_windows deps += ['telemetry'] endif
lib/meson.build +1 -1
@@ -13,7 +13,7 @@ libraries = [ 'kvargs', # eal depends on kvargs 'argparse', 'telemetry', # basic info querying - 'pmu', + 'pmu', # trace depends on pmu 'eal', # everything depends on eal 'ptr_compress', 'ring',
lib/pmu/pmu.c +68 -2
100 lines not on this page · raw message
lib/pmu/rte_pmu.h +24 -0
@@ -21,6 +21,10 @@* * rte_pmu_init() * rte_pmu_add_event() +* rte_pmu_add_event() [or rte_pmu_add_events_by_pattern()] +* +* Note that if -Denable_trace_fp=True was passed to Meson, +* rte_pmu_init() gets called automatically. * * Afterwards all threads can read events by calling rte_pmu_read(). */
@@ -146,6 +150,8 @@ __rte_pmu_enable_group(struct rte_pmu_event_group *group);* * Initialize PMU library. * +* It's safe to call it multiple times. +* * @return * 0 in case of success, negative value otherwise. */
@@ -158,6 +164,9 @@ rte_pmu_init(void);* @b EXPERIMENTAL: this API may change without prior notice. * * Finalize PMU library. +* +* Number of calls must match number of times rte_pmu_init() was called. +* Otherwise memory won't be freed properly. */ __rte_experimental void
@@ -179,6 +188,21 @@ __rte_experimentalint rte_pmu_add_event (const char *name); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add events matching pattern to the group of enabled events. +* +* @param pattern +* Pattern e=ev1[,ev2,...] matching events +* listed under /sys/bus/event_source/devices/pmu/events, +* where evX and PMU are placeholders for respectively an event and an event source. +*/ +__rte_experimental +int +rte_pmu_add_events_by_pattern (const char *pattern); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.34.1
Re: [PATCH v11 8/9] trace: add PMU
Hello,
Quoted 7 lines · Tomasz Duszynski
In order to profile app, one needs to store significant amount of samples somewhere for an analysis later on.
Since trace library supports storing data in a CTF format, lets take advantage of that and add a dedicated PMU tracepoint.Signed-off-by Tomasz Duszynski <[email protected]>
Two high level comments:
- the lib.pmu.read event has the following format:
event {
id = 532;
name = "lib.pmu.read";
fields := struct {
uint64_t val;
};
};Which means that traces will get PMU event, but without a way to differentiate between counters that may have been used. I propose a different tracepoint later in the comments.
- I have doubts on making pmu and tracing configurations intermixed within a single --trace= option.
The use of indexes based on the cmdline looks fragile. If an application calls the pmu API directly, won't the commandline break the indexes of the pmu counters?
More comments on the implementation:
[snip]
doc/guides/prog_guide/profile_app.rst Current implementation imposes certain limitations: · line 48
Quoted 12 lines
doc/guides/prog_guide/profile_app.rst +4
-0@@ -42,6 +42,11 @@ Current implementation imposes certain limitations: * EAL lcores must not share a CPU. * Each EAL lcore measures the same group of events. +Alternatively tracing library can be used, +which offers dedicated tracepoint ``rte_pmu_trace_read()``. + +Refer to :doc:`../prog_guide/trace_lib` for more details.
Nit: a simple :doc:trace_lib works.
Quoted 30 lines
doc/guides/prog_guide/profile_app.rst +1
-0+ Profiling on x86 ----------------doc/guides/prog_guide/trace_lib.rst +11
-0@@ -46,6 +46,7 @@ DPDK tracing library features trace format and is compatible with ``LTTng``. For detailed information, refer to `Common Trace Format <https://diamon.org/ctf/>`_. +- Support reading PMU events on ARM64 and x86-64 (Intel) How to add a tracepoint? ------------------------@@ -139,6 +140,36 @@ the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. ``RTE_TRACE_POINT_FP`` is compiled out by default and it can be enabled using the ``enable_trace_fp`` option for meson build. +PMU tracepoint +-------------- + +Performance Monitoring Unit (PMU) event values can be read from hardware registers +using the predefined ``rte_pmu_read`` tracepoint. + +Tracing is enabled via ``--trace`` EAL option by passing both expression +matching PMU tracepoint name i.e ``lib.eal.pmu.read`` +and expression ``e=ev1[,ev2,...]`` matching particular events:: +
doc/guides/prog_guide/trace_lib.rst the user must use ``RTE_TRACE_POINT_FP`` instead of ``RTE_TRACE_POINT``. · line 162
Quoted 10 lines
doc/guides/prog_guide/trace_lib.rst +10
-0+ --trace='.*pmu.read\|e=cpu_cycles,l1d_cache' + +Event names are available under ``/sys/bus/event_source/devices/PMU/events`` directory, +where ``PMU`` is a placeholder for either a ``cpu`` or a directory containing ``cpus``. + +In contrary to other tracepoints this does not need any extra variables +added to source files. +Instead, caller passes index +which follows the order of events specified via ``--trace`` parameter. +In the following example, index ``0`` corresponds to ``cpu_cyclces``,
Typo: cpu_cycles
Quoted 13 lines
doc/guides/prog_guide/trace_lib.rst +10
-0+while index ``1`` corresponds to ``l1d_cache``. + +.. code-block:: c + + rte_pmu_trace_read(0); + rte_pmu_trace_read(1); + +PMU tracing support must be explicitly enabled +using the ``enable_trace_fp`` option for Meson build. + Event record mode -----------------
[snip]
lib/eal/common/eal_trace_pmu.h line 6
Quoted 12 lines
lib/eal/common/eal_trace_pmu.h new file +6
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(C) 2025 Marvell International Ltd. +*/ + +#ifndef __EAL_TRACE_PMU_H +#define __EAL_TRACE_PMU_H
Nit: no __ prefix.
Quoted 11 lines
lib/eal/common/eal_trace_pmu.h new file +6
-0+ +/* PMU wrappers */ +void trace_pmu_args_apply (const char *arg); +void trace_pmu_args_free (void ); + +#endif /* __EAL_TRACE_PMU_H */ lib/eal/common/meson.build +0
-0
lib/eal/common/meson.build if not is_windows · line 53
Quoted 6 lines
lib/eal/common/meson.build +1
-0@@ -48,6 +48,7 @@ if not is_windows 'eal_common_hypervisor.c', 'eal_common_proc.c', 'eal_common_trace.c', + 'eal_common_trace_pmu.c', 'eal_common_trace_ctf.c', 'eal_common_trace_utils.c',
Nit: alphabetical order.
Quoted 22 lines
lib/eal/common/meson.build +0
-0'hotplug_mp.c',lib/eal/include/rte_eal_trace.h +13
-0@@ -127,6 +127,29 @@ RTE_TRACE_POINT(#define RTE_EAL_TRACE_GENERIC_FUNC rte_eal_trace_generic_func(__func__) +#ifdef RTE_LIB_PMU +#include <rte_debug.h> +#include <rte_pmu.h> +RTE_TRACE_POINT_FP( + rte_pmu_trace_read, + RTE_TRACE_POINT_ARGS(unsigned int index), + /* Embedded code should only execute in runtime so cut it out during registration in order + * to avoid compilation issues because rte_pmu_trace_read_register(void) does not provide + * any context. + */ + RTE_TRACE_POINT_EMBED_CODE( + uint64_t val; +#ifdef ALLOW_EXPERIMENTAL_API
lib/eal/include/rte_eal_trace.h RTE_TRACE_POINT( · line 152
Quoted 10 lines
lib/eal/include/rte_eal_trace.h +10
-0+ val =rte_pmu_read (index); +#else +RTE_SET_USED (index); +RTE_VERIFY (false); +#endif + ) +rte_trace_point_emit_u64 (val); +) +#endif +
As I commented earlier, with emitting a single u64, user will have no clue what this pmu trace was about.
We need at least the pmu counter index in this trace point.
Besides, putting #ifdef in the middle of a call to a macro will break MSVC, which I fixed with great pain recently.
And RTE_TRACE_POINT_EMBED_CODE will reintroduce issues too, please don't revert implicitly (issues are not seen in CI probably because this code is under #ifdef RTE_LIB_PMU).
In the end, the simpler and cleaner is to add a dedicated "emitter" helper.
This means here something like:
RTE_TRACE_POINT_FP(
rte_pmu_trace_read,
RTE_TRACE_POINT_ARGS(unsigned int index),
rte_trace_point_emit_pmu(index);
)
Then in rte_trace_point.h, add a skeletton for doxygen and a "empty" wrapper for the non ALLOW_EXPERIMENTAL_API block.
And add the new (non register) emitter as something like:
#ifdef RTE_LIB_PMU
#define rte_trace_point_emit_pmu(in) \
do { \
uint64_t val; \
__rte_trace_point_emit("index", &in, uint32_t); \
val = rte_pmu_read(in); \
__rte_trace_point_emit("val", &val, uint64_t); \
} while(0)
#else
#define rte_trace_point_emit_pmu(in) \
do { \
RTE_SET_USED(in); \
RTE_VERIFY(false); \
} while (0)#endif /* RTE_LIB_PMU */
For the register emitter in rte_trace_point_register.h, add something like:
#define rte_trace_point_emit_pmu(in) \
do { \
__rte_trace_point_emit_field(sizeof(uint32_t), \
"index", \
RTE_STR(uint32_t)); \
__rte_trace_point_emit_field(sizeof(uint64_t), \
"val", \
RTE_STR(uint64_t)); \Quoted 3 lines
lib/eal/include/rte_eal_trace.h +0
-0#ifdef __cplusplus }#endif
[snip]
Quoted 86 lines
lib/pmu/pmu.c +64
-0@@ -4,6 +4,7 @@#include <errno.h> #include <ctype.h> +#include <regex.h> #include <dirent.h> #include <stdlib.h> #include <unistd.h> @@ -371,6 +372,7 @@ static void free_event(struct rte_pmu_event *event) {free (event->name); + event->name =NULL ;free (event); }@@ -417,13 +419,77 @@ rte_pmu_add_event(const char *name)return event->index; } +static int +add_events (const char *pattern) +{ +char *token, *copy, *tmp; +int ret =0 ; + + copy =strdup (pattern); +if (copy ==NULL ) +return -ENOMEM ; + + token =strtok_r (copy,"," , &tmp); +while (token) { + ret =rte_pmu_add_event (token); +if (ret <0 ) +break ; + + token =strtok_r (NULL ,"," , &tmp); + } + +free (copy); + +return ret >=0 ?0 : ret; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmu_add_events_by_pattern, 25.11) +int +rte_pmu_add_events_by_pattern (const char *pattern) +{ +regmatch_t rmatch; +char buf[BUFSIZ ]; +unsigned int num; +regex_t reg; +int ret; + +/* events are matched against occurrences of e=ev1[,ev2,..] pattern */ + ret =regcomp (®,"e=([_[:alnum:]-],?)+" ,REG_EXTENDED ); +if (ret) { +PMU_LOG (ERR ,"Failed to compile event matching regexp" ); +return -EINVAL ; + } + +for (;;) { +if (regexec (®, pattern,1 , &rmatch,0 )) +break ; + + num = rmatch.rm_eo - rmatch.rm_so; +if (num >sizeof (buf)) + num =sizeof (buf); + +/* skip e= pattern prefix */ +memcpy (buf, pattern + rmatch.rm_so +2 , num -2 ); + buf[num -2 ] ='\0' ; + ret =add_events (buf); +if (ret) +break ; + + pattern += rmatch.rm_eo; + } + +regfree (®); + +return ret;
lib/pmu/pmu.c rte_pmu_add_event(const char *name) · line 492
Quoted 10 lines
lib/pmu/pmu.c +3
-1+} + RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmu_init, 25.07)int rte_pmu_init (void ) {int ret; -if (rte_pmu.initialized) +if (rte_pmu.initialized && ++rte_pmu.initialized)
It seems simpler as:
if (rte_pmu.initialized++ != 0)
lib/pmu/pmu.c rte_pmu_fini(void) · line 526
Quoted 9 lines
lib/pmu/pmu.c +1
-1return 0 ; ret =scan_pmus ();@@ -457,7 +523,7 @@ rte_pmu_fini(void)struct rte_pmu_event_group *group;unsigned int i; -if (!rte_pmu.initialized) +if (!rte_pmu.initialized || --rte_pmu.initialized)
if (--rte_pmu.initialized != 0)
Quoted 3 lines
lib/pmu/pmu.c +0
-0return ; RTE_TAILQ_FOREACH_SAFE(event, &rte_pmu.event_list, next, tmp_event) {
Signature · 1 line
David Marchand
PATCH v11 9/9 lib/pmu: fix out-of-bound access
In reply to Tomasz DuszynskiMake sure that out-of-bound access does not happen by saving one byte in buffer for NUL terminator.
--- lib/pmu/pmu.c | 2 +- lib/pmu/pmu_arm64.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
lib/pmu/pmu.c +1 -1
@@ -126,7 +126,7 @@ get_event_config(const char *name, uint64_t config[3])if (fp ==NULL )return -errno; - ret =fread (buf,1 ,sizeof (buf), fp); + ret =fread (buf,1 ,sizeof (buf) -1 , fp);if (ret ==0 ) {fclose (fp);
lib/pmu/pmu_arm64.c +2 -1
@@ -24,12 +24,13 @@ read_attr_int(const char *path, int *val)if (fd ==-1 )return -errno; - ret =read (fd, buf,sizeof (buf)); + ret =read (fd, buf,sizeof (buf) -1 );if (ret ==-1 ) {close (fd);return -errno; } + buf[ret] ='\0' ; *val =strtol (buf,NULL ,10 );close (fd);
Signature · 1 line
2.34.1
v11 cover lib/pmu: cleanups and trace integration
In reply to Tomasz DuszynskiAnything else required from your angle?
Hello,
Quoted 27 lines · Tomasz Duszynski
This series does some cleanup and refactoring around the rc1 code like: trimming unused headers, switching to callbacks for per-arch handling, and adding trace support. It also re-enables existing base test to help catch reported issues on some architectures.
v11:
- rebase series
- hide calls to experimental syms in inline helpers
v10:
- fix build withoutALLOW_EXPERIMENTAL_API
- moverte_pmu_tread_read()registration to avoid MSVC linker issues v9:
- properly rebase patch integrating pmu and trace
v8:
- export__rte_pmu_trace_readfrom library itself to avoid build issues with msvc linker
v7:
- change test return value
v6:
- add more logs to functional test
- skip test in case of setup failure, user must make sure system is properly configured to get valid results
v5:
- add missing patch that quiesces chincs check
v4:
- change fast test so that it won't fail on misconfigured system
- fix compilation on windows
Quoted 9 lines
v3:
- do not export__rte_pmu_trace_readbecause that breaks compilation on windows - script generating map files does not handle conditional compilation
- skip testing if paranoia is at wrong level
v2:
- explicitly check against NULL
- make pmu lib optional by checking if dpdk config hasRTE_LIB_PMU
Strange output in the cover letter.
Shortlog shows 10 patches:
Quoted 1 line
Tomasz Duszynski (10):
Followed by 8 lines:
Quoted 8 lines
trace: change scope of conditional block lib/pmu: export only necessary arch headers lib/pmu: reimplement per-arch ops as callbacks lib/pmu: do not try enabling perf counter access on arm64 lib/pmu: use build system defined
RTE_LIB_PMUmacro test/pmu: enable test
trace: add PMU
lib/pmu: fix out-of-bound access
But the series has 9 patches.
In any case,
- patch 2 "trace: change scope of conditional block" is unneeded, I see nothing wrong with current code. I tried stopping at various points of the series, no build issue,
- patch 7 has a comment from Morten,
- patch 8 has comments from me,
- patch 9 is vague, what is this about? Fixing coverity or some static analysis tool bug report?
I applied the rest of the series, as other patches look valid fixes / cleanups.
Signature · 1 line
David Marchand