Path: blob/master/tools/lib/perf/include/internal/evsel.h
26302 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __LIBPERF_INTERNAL_EVSEL_H2#define __LIBPERF_INTERNAL_EVSEL_H34#include <linux/types.h>5#include <linux/perf_event.h>6#include <stdbool.h>7#include <sys/types.h>8#include <internal/cpumap.h>910struct perf_thread_map;11struct xyarray;1213/**14* The per-thread accumulated period storage node.15*/16struct perf_sample_id_period {17struct list_head node;18struct hlist_node hnode;19/* Holds total ID period value for PERF_SAMPLE_READ processing. */20u64 period;21/* The TID that the values belongs to */22u32 tid;23};2425/**26* perf_evsel_for_each_per_thread_period_safe - safely iterate thru all the27* per_stream_periods28* @evlist:perf_evsel instance to iterate29* @item: struct perf_sample_id_period iterator30* @tmp: struct perf_sample_id_period temp iterator31*/32#define perf_evsel_for_each_per_thread_period_safe(evsel, tmp, item) \33list_for_each_entry_safe(item, tmp, &(evsel)->per_stream_periods, node)343536#define PERF_SAMPLE_ID__HLIST_BITS 437#define PERF_SAMPLE_ID__HLIST_SIZE (1 << PERF_SAMPLE_ID__HLIST_BITS)3839/*40* Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are41* more than one entry in the evlist.42*/43struct perf_sample_id {44struct hlist_node node;45u64 id;46struct perf_evsel *evsel;47/*48* 'idx' will be used for AUX area sampling. A sample will have AUX area49* data that will be queued for decoding, where there are separate50* queues for each CPU (per-cpu tracing) or task (per-thread tracing).51* The sample ID can be used to lookup 'idx' which is effectively the52* queue number.53*/54int idx;55struct perf_cpu cpu;56pid_t tid;5758/* Guest machine pid and VCPU, valid only if machine_pid is non-zero */59pid_t machine_pid;60struct perf_cpu vcpu;6162/*63* Per-thread, and global event counts are mutually exclusive:64* Whilst it is possible to combine events into a group with differing65* values of PERF_SAMPLE_READ, it is not valid to have inconsistent66* values for `inherit`. Therefore it is not possible to have a67* situation where a per-thread event is sampled as a global event;68* all !inherit groups are global, and all groups where the sampling69* event is inherit + PERF_SAMPLE_READ will be per-thread. Any event70* that is part of such a group that is inherit but not PERF_SAMPLE_READ71* will be read as per-thread. If such an event can also trigger a72* sample (such as with sample_period > 0) then it will not cause73* `read_format` to be included in its PERF_RECORD_SAMPLE, and74* therefore will not expose the per-thread group members as global.75*/76union {77/*78* Holds total ID period value for PERF_SAMPLE_READ processing79* (when period is not per-thread).80*/81u64 period;82/*83* Holds total ID period value for PERF_SAMPLE_READ processing84* (when period is per-thread).85*/86struct hlist_head periods[PERF_SAMPLE_ID__HLIST_SIZE];87};88};8990struct perf_evsel {91struct list_head node;92struct perf_event_attr attr;93/** The commonly used cpu map of CPUs the event should be opened upon, etc. */94struct perf_cpu_map *cpus;95/**96* The cpu map read from the PMU. For core PMUs this is the list of all97* CPUs the event can be opened upon. For other PMUs this is the default98* cpu map for opening the event on, for example, the first CPU on a99* socket for an uncore event.100*/101struct perf_cpu_map *pmu_cpus;102struct perf_thread_map *threads;103struct xyarray *fd;104struct xyarray *mmap;105struct xyarray *sample_id;106u64 *id;107u32 ids;108struct perf_evsel *leader;109110/* For events where the read_format value is per-thread rather than111* global, stores the per-thread cumulative period */112struct list_head per_stream_periods;113114/* parse modifier helper */115int nr_members;116/*117* system_wide is for events that need to be on every CPU, irrespective118* of user requested CPUs or threads. Tha main example of this is the119* dummy event. Map propagation will set cpus for this event to all CPUs120* as software PMU events like dummy, have a CPU map that is empty.121*/122bool system_wide;123/*124* Some events, for example uncore events, require a CPU.125* i.e. it cannot be the 'any CPU' value of -1.126*/127bool requires_cpu;128/** Is the PMU for the event a core one? Effects the handling of own_cpus. */129bool is_pmu_core;130int idx;131};132133void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,134int idx);135void perf_evsel__exit(struct perf_evsel *evsel);136int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);137void perf_evsel__close_fd(struct perf_evsel *evsel);138void perf_evsel__free_fd(struct perf_evsel *evsel);139int perf_evsel__read_size(struct perf_evsel *evsel);140int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);141142int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);143void perf_evsel__free_id(struct perf_evsel *evsel);144145bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel);146147u64 *perf_sample_id__get_period_storage(struct perf_sample_id *sid, u32 tid,148bool per_thread);149150#endif /* __LIBPERF_INTERNAL_EVSEL_H */151152153