evsel.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LIBPERF_INTERNAL_EVSEL_H
  3. #define __LIBPERF_INTERNAL_EVSEL_H
  4. #include <linux/types.h>
  5. #include <linux/perf_event.h>
  6. #include <stdbool.h>
  7. #include <sys/types.h>
  8. #include <internal/cpumap.h>
  9. struct perf_thread_map;
  10. struct xyarray;
  11. /*
  12. * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
  13. * more than one entry in the evlist.
  14. */
  15. struct perf_sample_id {
  16. struct hlist_node node;
  17. u64 id;
  18. struct perf_evsel *evsel;
  19. /*
  20. * 'idx' will be used for AUX area sampling. A sample will have AUX area
  21. * data that will be queued for decoding, where there are separate
  22. * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
  23. * The sample ID can be used to lookup 'idx' which is effectively the
  24. * queue number.
  25. */
  26. int idx;
  27. struct perf_cpu cpu;
  28. pid_t tid;
  29. /* Guest machine pid and VCPU, valid only if machine_pid is non-zero */
  30. pid_t machine_pid;
  31. struct perf_cpu vcpu;
  32. /* Holds total ID period value for PERF_SAMPLE_READ processing. */
  33. u64 period;
  34. };
  35. struct perf_evsel {
  36. struct list_head node;
  37. struct perf_event_attr attr;
  38. /** The commonly used cpu map of CPUs the event should be opened upon, etc. */
  39. struct perf_cpu_map *cpus;
  40. /**
  41. * The cpu map read from the PMU. For core PMUs this is the list of all
  42. * CPUs the event can be opened upon. For other PMUs this is the default
  43. * cpu map for opening the event on, for example, the first CPU on a
  44. * socket for an uncore event.
  45. */
  46. struct perf_cpu_map *own_cpus;
  47. struct perf_thread_map *threads;
  48. struct xyarray *fd;
  49. struct xyarray *mmap;
  50. struct xyarray *sample_id;
  51. u64 *id;
  52. u32 ids;
  53. struct perf_evsel *leader;
  54. /* parse modifier helper */
  55. int nr_members;
  56. /*
  57. * system_wide is for events that need to be on every CPU, irrespective
  58. * of user requested CPUs or threads. Tha main example of this is the
  59. * dummy event. Map propagation will set cpus for this event to all CPUs
  60. * as software PMU events like dummy, have a CPU map that is empty.
  61. */
  62. bool system_wide;
  63. /*
  64. * Some events, for example uncore events, require a CPU.
  65. * i.e. it cannot be the 'any CPU' value of -1.
  66. */
  67. bool requires_cpu;
  68. /** Is the PMU for the event a core one? Effects the handling of own_cpus. */
  69. bool is_pmu_core;
  70. int idx;
  71. };
  72. void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
  73. int idx);
  74. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  75. void perf_evsel__close_fd(struct perf_evsel *evsel);
  76. void perf_evsel__free_fd(struct perf_evsel *evsel);
  77. int perf_evsel__read_size(struct perf_evsel *evsel);
  78. int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
  79. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  80. void perf_evsel__free_id(struct perf_evsel *evsel);
  81. #endif /* __LIBPERF_INTERNAL_EVSEL_H */