DPDK 25.07.0
rte_pmu.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2025 Marvell
3 */
4
5#ifndef RTE_PMU_H
6#define RTE_PMU_H
7
28#include <linux/perf_event.h>
29
30#include <rte_atomic.h>
32#include <rte_common.h>
33#include <rte_compat.h>
34#include <rte_lcore.h>
35
36#define RTE_PMU_SUPPORTED
37#if defined(RTE_ARCH_ARM64)
38#include "rte_pmu_pmc_arm64.h"
39#elif defined(RTE_ARCH_X86_64)
40#include "rte_pmu_pmc_x86_64.h"
41#else
42#undef RTE_PMU_SUPPORTED
43#endif
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
50#define RTE_MAX_NUM_GROUP_EVENTS 8
51
57 struct perf_event_mmap_page *mmap_pages[RTE_MAX_NUM_GROUP_EVENTS];
60 bool enabled;
61};
62
66struct rte_pmu {
67 struct rte_pmu_event_group event_groups[RTE_MAX_LCORE];
68 unsigned int num_group_events;
69 unsigned int initialized;
70 char *name;
71 TAILQ_HEAD(, rte_pmu_event) event_list;
72};
73
75extern struct rte_pmu rte_pmu;
76
77/* Each architecture supporting PMU needs to provide its own version. */
78#ifndef rte_pmu_pmc_read
79#define rte_pmu_pmc_read(index) ({ RTE_SET_USED(index); 0; })
80#endif
81
95__rte_experimental
96static __rte_always_inline uint64_t
97__rte_pmu_read_userpage(struct perf_event_mmap_page *pc)
98{
99#define __RTE_PMU_READ_ONCE(x) (*(const volatile typeof(x) *)&(x))
100 uint64_t width, offset;
101 uint32_t seq, index;
102 int64_t pmc;
103
104 for (;;) {
105 seq = __RTE_PMU_READ_ONCE(pc->lock);
107 index = __RTE_PMU_READ_ONCE(pc->index);
108 offset = __RTE_PMU_READ_ONCE(pc->offset);
109 width = __RTE_PMU_READ_ONCE(pc->pmc_width);
110
111 /* index set to 0 means that particular counter cannot be used */
112 if (likely(pc->cap_user_rdpmc && index)) {
113 pmc = rte_pmu_pmc_read(index - 1);
114 pmc <<= 64 - width;
115 pmc >>= 64 - width;
116 offset += pmc;
117 }
118
120
121 if (likely(__RTE_PMU_READ_ONCE(pc->lock) == seq))
122 return offset;
123 }
124
125 return 0;
126}
127
141__rte_experimental
142int
144
154__rte_experimental
155int
157
164__rte_experimental
165void
167
180__rte_experimental
181int
183
184/* quiesce warnings produced by chkincs caused by calling internal functions directly */
185#ifndef ALLOW_EXPERIMENTAL_API
186#define __rte_pmu_enable_group(group) ({ RTE_SET_USED(group); 0; })
187#define __rte_pmu_read_userpage(pc) ({ RTE_SET_USED(pc); 0; })
188#endif
189
210__rte_experimental
211static __rte_always_inline uint64_t
212rte_pmu_read(unsigned int index)
213{
214 unsigned int lcore_id = rte_lcore_id();
215 struct rte_pmu_event_group *group;
216
218 return 0;
219
220 /* non-EAL threads are not supported */
221 if (unlikely(lcore_id >= RTE_MAX_LCORE))
222 return 0;
223
224 if (unlikely(index >= rte_pmu.num_group_events))
225 return 0;
226
227 group = &rte_pmu.event_groups[lcore_id];
228 if (unlikely(!group->enabled)) {
229 if (__rte_pmu_enable_group(group))
230 return 0;
231 }
232
233 return __rte_pmu_read_userpage(group->mmap_pages[index]);
234}
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif /* RTE_PMU_H */
#define rte_compiler_barrier()
Definition: rte_atomic.h:157
#define likely(x)
#define unlikely(x)
#define __rte_cache_aligned
Definition: rte_common.h:739
#define __rte_always_inline
Definition: rte_common.h:490
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:78
__rte_experimental int rte_pmu_add_event(const char *name)
static __rte_experimental __rte_always_inline uint64_t rte_pmu_read(unsigned int index)
Definition: rte_pmu.h:212
__rte_experimental int __rte_pmu_enable_group(struct rte_pmu_event_group *group)
__rte_experimental int rte_pmu_init(void)
__rte_experimental void rte_pmu_fini(void)
#define RTE_MAX_NUM_GROUP_EVENTS
Definition: rte_pmu.h:50
static __rte_experimental __rte_always_inline uint64_t __rte_pmu_read_userpage(struct perf_event_mmap_page *pc)
Definition: rte_pmu.h:97
struct perf_event_mmap_page * mmap_pages[RTE_MAX_NUM_GROUP_EVENTS]
Definition: rte_pmu.h:57
TAILQ_ENTRY(rte_pmu_event_group) next
TAILQ_HEAD(, rte_pmu_event) event_list
struct rte_pmu_event_group event_groups[RTE_MAX_LCORE]
Definition: rte_pmu.h:67
char * name
Definition: rte_pmu.h:70
unsigned int num_group_events
Definition: rte_pmu.h:68
unsigned int initialized
Definition: rte_pmu.h:69