evsel.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef __PERF_EVSEL_H
  2. #define __PERF_EVSEL_H 1
  3. #include <linux/list.h>
  4. #include <stdbool.h>
  5. #include "../../../include/linux/perf_event.h"
  6. #include "types.h"
  7. #include "xyarray.h"
  8. struct perf_counts_values {
  9. union {
  10. struct {
  11. u64 val;
  12. u64 ena;
  13. u64 run;
  14. };
  15. u64 values[3];
  16. };
  17. };
  18. struct perf_counts {
  19. s8 scaled;
  20. struct perf_counts_values aggr;
  21. struct perf_counts_values cpu[];
  22. };
  23. struct perf_evsel;
  24. /*
  25. * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
  26. * more than one entry in the evlist.
  27. */
  28. struct perf_sample_id {
  29. struct hlist_node node;
  30. u64 id;
  31. struct perf_evsel *evsel;
  32. };
  33. struct perf_evsel {
  34. struct list_head node;
  35. struct perf_event_attr attr;
  36. char *filter;
  37. struct xyarray *fd;
  38. struct xyarray *id;
  39. struct perf_counts *counts;
  40. int idx;
  41. void *priv;
  42. };
  43. struct cpu_map;
  44. struct thread_map;
  45. struct perf_evlist;
  46. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  47. void perf_evsel__init(struct perf_evsel *evsel,
  48. struct perf_event_attr *attr, int idx);
  49. void perf_evsel__exit(struct perf_evsel *evsel);
  50. void perf_evsel__delete(struct perf_evsel *evsel);
  51. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  52. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  53. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  54. int perf_evlist__alloc_mmap(struct perf_evlist *evlist, int ncpus);
  55. void perf_evsel__free_fd(struct perf_evsel *evsel);
  56. void perf_evsel__free_id(struct perf_evsel *evsel);
  57. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  58. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  59. struct cpu_map *cpus, bool group, bool inherit);
  60. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  61. struct thread_map *threads, bool group, bool inherit);
  62. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  63. struct thread_map *threads, bool group, bool inherit);
  64. int perf_evlist__mmap(struct perf_evlist *evlist, struct cpu_map *cpus,
  65. struct thread_map *threads, int pages, bool overwrite);
  66. void perf_evlist__munmap(struct perf_evlist *evlist, int ncpus);
  67. #define perf_evsel__match(evsel, t, c) \
  68. (evsel->attr.type == PERF_TYPE_##t && \
  69. evsel->attr.config == PERF_COUNT_##c)
  70. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  71. int cpu, int thread, bool scale);
  72. /**
  73. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  74. *
  75. * @evsel - event selector to read value
  76. * @cpu - CPU of interest
  77. * @thread - thread of interest
  78. */
  79. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  80. int cpu, int thread)
  81. {
  82. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  83. }
  84. /**
  85. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  86. *
  87. * @evsel - event selector to read value
  88. * @cpu - CPU of interest
  89. * @thread - thread of interest
  90. */
  91. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  92. int cpu, int thread)
  93. {
  94. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  95. }
  96. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  97. bool scale);
  98. /**
  99. * perf_evsel__read - Read the aggregate results on all CPUs
  100. *
  101. * @evsel - event selector to read value
  102. * @ncpus - Number of cpus affected, from zero
  103. * @nthreads - Number of threads affected, from zero
  104. */
  105. static inline int perf_evsel__read(struct perf_evsel *evsel,
  106. int ncpus, int nthreads)
  107. {
  108. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  109. }
  110. /**
  111. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  112. *
  113. * @evsel - event selector to read value
  114. * @ncpus - Number of cpus affected, from zero
  115. * @nthreads - Number of threads affected, from zero
  116. */
  117. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  118. int ncpus, int nthreads)
  119. {
  120. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  121. }
  122. #endif /* __PERF_EVSEL_H */