blob: 2aca71763ecfcbc5287f6ec4ead3dffebeff7824 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
John Kacur8b40f522009-09-24 18:02:18 +02002#ifndef __PERF_HEADER_H
3#define __PERF_HEADER_H
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +02004
Arnaldo Carvalho de Melo44fe6192018-07-30 13:15:03 -03005#include <linux/stddef.h>
David Howellsd2709c72012-11-19 22:21:03 +00006#include <linux/perf_event.h>
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +02007#include <sys/types.h>
Arnaldo Carvalho de Melo27830612019-09-10 16:42:52 +01008#include <stdio.h> // FILE
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -02009#include <stdbool.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +020010#include <linux/bitmap.h>
11#include <linux/types.h>
Arnaldo Carvalho de Melof0ce8882015-09-08 13:30:00 -030012#include "env.h"
Ganapatrao Kulkarni54e32dc2017-10-17 00:02:18 +053013#include "pmu.h"
Frederic Weisbeckerdb9f11e2009-10-17 17:57:18 +020014
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020015enum {
Robert Richterb1e5a9b2011-12-07 10:02:57 +010016 HEADER_RESERVED = 0, /* always cleared */
Robert Richter781ba9d2011-12-15 17:32:40 +010017 HEADER_FIRST_FEATURE = 1,
Stephane Eranian2eeaaa02012-05-15 13:28:13 +020018 HEADER_TRACING_DATA = 1,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020019 HEADER_BUILD_ID,
Stephane Eranianfbe96f22011-09-30 15:40:40 +020020
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 Eranian330aa672012-03-08 23:47:46 +010033 HEADER_BRANCH_STACK,
Robert Richter50a96672012-08-16 21:10:24 +020034 HEADER_PMU_MAPPINGS,
Namhyung Kima8bb5592013-01-22 18:09:31 +090035 HEADER_GROUP_DESC,
Adrian Hunter4025ea42015-04-09 18:53:41 +030036 HEADER_AUXTRACE,
Jiri Olsaffa517a2015-10-25 15:51:43 +010037 HEADER_STAT,
Jiri Olsa720e98b2016-02-16 16:01:43 +010038 HEADER_CACHE,
Jin Yao60115182017-12-08 21:13:41 +080039 HEADER_SAMPLE_TIME,
Jiri Olsae2091ce2018-03-07 16:50:08 +010040 HEADER_MEM_TOPOLOGY,
Alexey Budankovcf790512018-10-09 17:36:24 +030041 HEADER_CLOCKID,
Jiri Olsa258031c2019-03-08 14:47:39 +010042 HEADER_DIR_FORMAT,
Song Liu606f9722019-03-11 22:30:43 -070043 HEADER_BPF_PROG_INFO,
Song Liua70a112312019-03-11 22:30:45 -070044 HEADER_BPF_BTF,
Alexey Budankov42e1fd82019-03-18 20:41:33 +030045 HEADER_COMPRESSED,
Kan Liang6f91ea22020-03-19 13:25:02 -070046 HEADER_CPU_PMU_CAPS,
Jiri Olsad1e325c2020-08-05 11:34:40 +020047 HEADER_CLOCK_DATA,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020048 HEADER_LAST_FEATURE,
Robert Richterb1e5a9b2011-12-07 10:02:57 +010049 HEADER_FEAT_BITS = 256,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020050};
Frederic Weisbecker2ba08252009-10-17 17:12:34 +020051
Jiri Olsa2a08c3e2013-07-17 19:49:47 +020052enum perf_header_version {
53 PERF_HEADER_VERSION_1,
54 PERF_HEADER_VERSION_2,
55};
56
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020057struct perf_file_section {
58 u64 offset;
59 u64 size;
60};
61
62struct 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 Olsa44b3c572013-07-11 17:28:31 +020068 /* event_types is ignored */
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020069 struct perf_file_section event_types;
70 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
71};
72
Tom Zanussi8dc58102010-04-01 23:59:15 -050073struct perf_pipe_file_header {
74 u64 magic;
75 u64 size;
76};
77
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020078struct perf_header;
79
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -030080int perf_file_header__read(struct perf_file_header *header,
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -020081 struct perf_header *ph, int fd);
82
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020083struct perf_header {
Jiri Olsa2a08c3e2013-07-17 19:49:47 +020084 enum perf_header_version version;
85 bool needs_swap;
86 u64 data_offset;
87 u64 data_size;
88 u64 feat_offset;
Frederic Weisbeckerdb9f11e2009-10-17 17:57:18 +020089 DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
Kan Liangce80d3b2015-08-28 05:48:04 -040090 struct perf_env env;
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +020091};
92
Arnaldo Carvalho de Melo055c67e2019-09-18 16:08:52 -030093struct 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
102struct 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 Olsa63503db2019-07-21 13:23:52 +0200111struct evlist;
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200112struct perf_session;
Arnaldo Carvalho de Melo27830612019-09-10 16:42:52 +0100113struct perf_tool;
114union perf_event;
Arnaldo Carvalho de Melo361c99a2011-01-11 20:56:53 -0200115
Jiri Olsad4339562013-07-17 19:49:41 +0200116int perf_session__read_header(struct perf_session *session);
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -0300117int perf_session__write_header(struct perf_session *session,
Jiri Olsa63503db2019-07-21 13:23:52 +0200118 struct evlist *evlist,
Arnaldo Carvalho de Meloa91e5432011-03-10 11:15:54 -0300119 int fd, bool at_exit);
Tom Zanussi8dc58102010-04-01 23:59:15 -0500120int perf_header__write_pipe(int fd);
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +0200121
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -0300122void perf_header__set_feat(struct perf_header *header, int feat);
123void perf_header__clear_feat(struct perf_header *header, int feat);
124bool perf_header__has_feat(const struct perf_header *header, int feat);
Peter Zijlstra7c6a1c62009-06-25 17:05:54 +0200125
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200126int perf_header__set_cmdline(int argc, const char **argv);
127
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -0300128int perf_header__process_sections(struct perf_header *header, int fd,
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200129 void *data,
Arnaldo Carvalho de Melo1c0b04d2011-03-09 08:13:19 -0300130 int (*process)(struct perf_file_section *section,
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200131 struct perf_header *ph,
132 int feat, int fd, void *data));
133
134int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Melo37562ea2009-11-16 16:32:43 -0200135
Jiri Olsa89f16882018-09-13 14:54:03 +0200136int perf_event__process_feature(struct perf_session *session,
137 union perf_event *event);
Adrian Hunter47c3d102013-07-04 16:20:21 +0300138int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
Jiri Olsa63503db2019-07-21 13:23:52 +0200139 struct evlist **pevlist);
Arnaldo Carvalho de Melob8f8eb82016-03-22 13:09:37 -0300140int perf_event__process_event_update(struct perf_tool *tool,
Jiri Olsaffe777252015-10-25 15:51:36 +0100141 union perf_event *event,
Jiri Olsa63503db2019-07-21 13:23:52 +0200142 struct evlist **pevlist);
Jiri Olsac853f932015-10-25 15:51:41 +0100143size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
Jiri Olsa89f16882018-09-13 14:54:03 +0200144int perf_event__process_tracing_data(struct perf_session *session,
145 union perf_event *event);
Jiri Olsa89f16882018-09-13 14:54:03 +0200146int perf_event__process_build_id(struct perf_session *session,
147 union perf_event *event);
Feng Tange84ba4e2012-10-30 11:56:07 +0800148bool is_perf_magic(u64 magic);
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200149
Namhyung Kime195fac2014-11-04 10:14:30 +0900150#define NAME_ALIGN 64
151
David Carrillo-Cisnerosccebbeb2017-07-17 21:25:39 -0700152struct feat_fd;
David Carrillo-Cisneros3b8f51a2017-07-17 21:25:38 -0700153
David Carrillo-Cisnerosccebbeb2017-07-17 21:25:39 -0700154int do_write(struct feat_fd *fd, const void *buf, size_t size);
155
156int write_padded(struct feat_fd *fd, const void *bf,
157 size_t count, size_t count_aligned);
Adrian Hunter1f625b02014-07-22 16:17:23 +0300158
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200159/*
160 * arch specific callback
161 */
162int get_cpuid(char *buffer, size_t sz);
163
Ganapatrao Kulkarni54e32dc2017-10-17 00:02:18 +0530164char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
Thomas Richter4cb7d3e2018-02-13 16:14:18 +0100165int strcmp_cpuid_str(const char *s1, const char *s2);
John Kacur8b40f522009-09-24 18:02:18 +0200166#endif /* __PERF_HEADER_H */