Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 2 | #ifndef __PERF_HEADER_H |
| 3 | #define __PERF_HEADER_H |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 4 | |
Arnaldo Carvalho de Melo | 44fe619 | 2018-07-30 13:15:03 -0300 | [diff] [blame] | 5 | #include <linux/stddef.h> |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 6 | #include <linux/perf_event.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 7 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | 2783061 | 2019-09-10 16:42:52 +0100 | [diff] [blame] | 8 | #include <stdio.h> // FILE |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 9 | #include <stdbool.h> |
Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 10 | #include <linux/bitmap.h> |
| 11 | #include <linux/types.h> |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 12 | #include "env.h" |
Ganapatrao Kulkarni | 54e32dc | 2017-10-17 00:02:18 +0530 | [diff] [blame] | 13 | #include "pmu.h" |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 14 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 15 | enum { |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 16 | HEADER_RESERVED = 0, /* always cleared */ |
Robert Richter | 781ba9d | 2011-12-15 17:32:40 +0100 | [diff] [blame] | 17 | HEADER_FIRST_FEATURE = 1, |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 18 | HEADER_TRACING_DATA = 1, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 19 | HEADER_BUILD_ID, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 20 | |
| 21 | HEADER_HOSTNAME, |
| 22 | HEADER_OSRELEASE, |
| 23 | HEADER_VERSION, |
| 24 | HEADER_ARCH, |
| 25 | HEADER_NRCPUS, |
| 26 | HEADER_CPUDESC, |
| 27 | HEADER_CPUID, |
| 28 | HEADER_TOTAL_MEM, |
| 29 | HEADER_CMDLINE, |
| 30 | HEADER_EVENT_DESC, |
| 31 | HEADER_CPU_TOPOLOGY, |
| 32 | HEADER_NUMA_TOPOLOGY, |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 33 | HEADER_BRANCH_STACK, |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 34 | HEADER_PMU_MAPPINGS, |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 35 | HEADER_GROUP_DESC, |
Adrian Hunter | 4025ea4 | 2015-04-09 18:53:41 +0300 | [diff] [blame] | 36 | HEADER_AUXTRACE, |
Jiri Olsa | ffa517a | 2015-10-25 15:51:43 +0100 | [diff] [blame] | 37 | HEADER_STAT, |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 38 | HEADER_CACHE, |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 39 | HEADER_SAMPLE_TIME, |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 40 | HEADER_MEM_TOPOLOGY, |
Alexey Budankov | cf79051 | 2018-10-09 17:36:24 +0300 | [diff] [blame] | 41 | HEADER_CLOCKID, |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 42 | HEADER_DIR_FORMAT, |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 43 | HEADER_BPF_PROG_INFO, |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 44 | HEADER_BPF_BTF, |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 45 | HEADER_COMPRESSED, |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 46 | HEADER_CPU_PMU_CAPS, |
Jiri Olsa | d1e325c | 2020-08-05 11:34:40 +0200 | [diff] [blame] | 47 | HEADER_CLOCK_DATA, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 48 | HEADER_LAST_FEATURE, |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 49 | HEADER_FEAT_BITS = 256, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 50 | }; |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 51 | |
Jiri Olsa | 2a08c3e | 2013-07-17 19:49:47 +0200 | [diff] [blame] | 52 | enum perf_header_version { |
| 53 | PERF_HEADER_VERSION_1, |
| 54 | PERF_HEADER_VERSION_2, |
| 55 | }; |
| 56 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 57 | struct perf_file_section { |
| 58 | u64 offset; |
| 59 | u64 size; |
| 60 | }; |
| 61 | |
| 62 | struct perf_file_header { |
| 63 | u64 magic; |
| 64 | u64 size; |
| 65 | u64 attr_size; |
| 66 | struct perf_file_section attrs; |
| 67 | struct perf_file_section data; |
Jiri Olsa | 44b3c57 | 2013-07-11 17:28:31 +0200 | [diff] [blame] | 68 | /* event_types is ignored */ |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 69 | struct perf_file_section event_types; |
| 70 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
| 71 | }; |
| 72 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 73 | struct perf_pipe_file_header { |
| 74 | u64 magic; |
| 75 | u64 size; |
| 76 | }; |
| 77 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 78 | struct perf_header; |
| 79 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 80 | int perf_file_header__read(struct perf_file_header *header, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 81 | struct perf_header *ph, int fd); |
| 82 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 83 | struct perf_header { |
Jiri Olsa | 2a08c3e | 2013-07-17 19:49:47 +0200 | [diff] [blame] | 84 | enum perf_header_version version; |
| 85 | bool needs_swap; |
| 86 | u64 data_offset; |
| 87 | u64 data_size; |
| 88 | u64 feat_offset; |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 89 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
Kan Liang | ce80d3b | 2015-08-28 05:48:04 -0400 | [diff] [blame] | 90 | struct perf_env env; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Arnaldo Carvalho de Melo | 055c67e | 2019-09-18 16:08:52 -0300 | [diff] [blame] | 93 | struct feat_fd { |
| 94 | struct perf_header *ph; |
| 95 | int fd; |
| 96 | void *buf; /* Either buf != NULL or fd >= 0 */ |
| 97 | ssize_t offset; |
| 98 | size_t size; |
| 99 | struct evsel *events; |
| 100 | }; |
| 101 | |
| 102 | struct perf_header_feature_ops { |
| 103 | int (*write)(struct feat_fd *ff, struct evlist *evlist); |
| 104 | void (*print)(struct feat_fd *ff, FILE *fp); |
| 105 | int (*process)(struct feat_fd *ff, void *data); |
| 106 | const char *name; |
| 107 | bool full_only; |
| 108 | bool synthesize; |
| 109 | }; |
| 110 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 111 | struct evlist; |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 112 | struct perf_session; |
Arnaldo Carvalho de Melo | 2783061 | 2019-09-10 16:42:52 +0100 | [diff] [blame] | 113 | struct perf_tool; |
| 114 | union perf_event; |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 115 | |
Jiri Olsa | d433956 | 2013-07-17 19:49:41 +0200 | [diff] [blame] | 116 | int perf_session__read_header(struct perf_session *session); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 117 | int perf_session__write_header(struct perf_session *session, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 118 | struct evlist *evlist, |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 119 | int fd, bool at_exit); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 120 | int perf_header__write_pipe(int fd); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 121 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 122 | void perf_header__set_feat(struct perf_header *header, int feat); |
| 123 | void perf_header__clear_feat(struct perf_header *header, int feat); |
| 124 | bool perf_header__has_feat(const struct perf_header *header, int feat); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 125 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 126 | int perf_header__set_cmdline(int argc, const char **argv); |
| 127 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 128 | int perf_header__process_sections(struct perf_header *header, int fd, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 129 | void *data, |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 130 | int (*process)(struct perf_file_section *section, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 131 | struct perf_header *ph, |
| 132 | int feat, int fd, void *data)); |
| 133 | |
| 134 | int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 135 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 136 | int perf_event__process_feature(struct perf_session *session, |
| 137 | union perf_event *event); |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 138 | int perf_event__process_attr(struct perf_tool *tool, union perf_event *event, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 139 | struct evlist **pevlist); |
Arnaldo Carvalho de Melo | b8f8eb8 | 2016-03-22 13:09:37 -0300 | [diff] [blame] | 140 | int perf_event__process_event_update(struct perf_tool *tool, |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 141 | union perf_event *event, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 142 | struct evlist **pevlist); |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 143 | size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp); |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 144 | int perf_event__process_tracing_data(struct perf_session *session, |
| 145 | union perf_event *event); |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 146 | int perf_event__process_build_id(struct perf_session *session, |
| 147 | union perf_event *event); |
Feng Tang | e84ba4e | 2012-10-30 11:56:07 +0800 | [diff] [blame] | 148 | bool is_perf_magic(u64 magic); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 149 | |
Namhyung Kim | e195fac | 2014-11-04 10:14:30 +0900 | [diff] [blame] | 150 | #define NAME_ALIGN 64 |
| 151 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 152 | struct feat_fd; |
David Carrillo-Cisneros | 3b8f51a | 2017-07-17 21:25:38 -0700 | [diff] [blame] | 153 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 154 | int do_write(struct feat_fd *fd, const void *buf, size_t size); |
| 155 | |
| 156 | int write_padded(struct feat_fd *fd, const void *bf, |
| 157 | size_t count, size_t count_aligned); |
Adrian Hunter | 1f625b0 | 2014-07-22 16:17:23 +0300 | [diff] [blame] | 158 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 159 | /* |
| 160 | * arch specific callback |
| 161 | */ |
| 162 | int get_cpuid(char *buffer, size_t sz); |
| 163 | |
Ganapatrao Kulkarni | 54e32dc | 2017-10-17 00:02:18 +0530 | [diff] [blame] | 164 | char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); |
Thomas Richter | 4cb7d3e | 2018-02-13 16:14:18 +0100 | [diff] [blame] | 165 | int strcmp_cpuid_str(const char *s1, const char *s2); |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 166 | #endif /* __PERF_HEADER_H */ |