^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __PERF_HEADER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __PERF_HEADER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <stdio.h> // FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "env.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "pmu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) HEADER_RESERVED = 0, /* always cleared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) HEADER_FIRST_FEATURE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) HEADER_TRACING_DATA = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) HEADER_BUILD_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) HEADER_HOSTNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) HEADER_OSRELEASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) HEADER_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) HEADER_ARCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) HEADER_NRCPUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) HEADER_CPUDESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) HEADER_CPUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) HEADER_TOTAL_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) HEADER_CMDLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) HEADER_EVENT_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) HEADER_CPU_TOPOLOGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) HEADER_NUMA_TOPOLOGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) HEADER_BRANCH_STACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) HEADER_PMU_MAPPINGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) HEADER_GROUP_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) HEADER_AUXTRACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) HEADER_STAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) HEADER_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) HEADER_SAMPLE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) HEADER_MEM_TOPOLOGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) HEADER_CLOCKID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) HEADER_DIR_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) HEADER_BPF_PROG_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) HEADER_BPF_BTF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) HEADER_COMPRESSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) HEADER_CPU_PMU_CAPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) HEADER_CLOCK_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) HEADER_LAST_FEATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) HEADER_FEAT_BITS = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) enum perf_header_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) PERF_HEADER_VERSION_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) PERF_HEADER_VERSION_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct perf_file_section {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct perf_file_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u64 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u64 attr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct perf_file_section attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct perf_file_section data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* event_types is ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct perf_file_section event_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct perf_pipe_file_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u64 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct perf_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int perf_file_header__read(struct perf_file_header *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct perf_header *ph, int fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct perf_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) enum perf_header_version version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) bool needs_swap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u64 data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u64 data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u64 feat_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct perf_env env;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct feat_fd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct perf_header *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void *buf; /* Either buf != NULL or fd >= 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ssize_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct evsel *events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct perf_header_feature_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int (*write)(struct feat_fd *ff, struct evlist *evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void (*print)(struct feat_fd *ff, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int (*process)(struct feat_fd *ff, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) bool full_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool synthesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct perf_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct perf_tool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) union perf_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int perf_session__read_header(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int perf_session__write_header(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct evlist *evlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int fd, bool at_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int perf_header__write_pipe(int fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void perf_header__set_feat(struct perf_header *header, int feat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) void perf_header__clear_feat(struct perf_header *header, int feat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) bool perf_header__has_feat(const struct perf_header *header, int feat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int perf_header__set_cmdline(int argc, const char **argv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int perf_header__process_sections(struct perf_header *header, int fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int (*process)(struct perf_file_section *section,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct perf_header *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int feat, int fd, void *data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int perf_event__process_feature(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) union perf_event *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct evlist **pevlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int perf_event__process_event_update(struct perf_tool *tool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct evlist **pevlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int perf_event__process_tracing_data(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) union perf_event *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int perf_event__process_build_id(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) union perf_event *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) bool is_perf_magic(u64 magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define NAME_ALIGN 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct feat_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int do_write(struct feat_fd *fd, const void *buf, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int write_padded(struct feat_fd *fd, const void *bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) size_t count, size_t count_aligned);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * arch specific callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int get_cpuid(char *buffer, size_t sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int strcmp_cpuid_str(const char *s1, const char *s2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #endif /* __PERF_HEADER_H */