blob: 5e3422f40ed5fa0ed52e64ae0a71a18f0ad02e8e [file] [log] [blame]
Jiri Olsa547740f2019-07-27 22:07:44 +02001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LIBPERF_INTERNAL_MMAP_H
3#define __LIBPERF_INTERNAL_MMAP_H
4
Jiri Olsa4443e6d2019-07-27 22:47:58 +02005#include <linux/compiler.h>
Jiri Olsae03edfe2019-07-27 22:35:35 +02006#include <linux/refcount.h>
Jiri Olsaebe4d722019-07-27 22:39:53 +02007#include <linux/types.h>
Jiri Olsa8df7a862019-07-27 22:42:56 +02008#include <stdbool.h>
Jiri Olsae03edfe2019-07-27 22:35:35 +02009
Jiri Olsa4443e6d2019-07-27 22:47:58 +020010/* perf sample has 16 bits size limit */
11#define PERF_SAMPLE_MAX_SIZE (1 << 16)
12
Jiri Olsa80e53d12019-10-07 14:53:15 +020013struct perf_mmap;
Rob Herring47d01e72021-04-14 11:07:39 -050014struct perf_counts_values;
Jiri Olsa80e53d12019-10-07 14:53:15 +020015
16typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
17
Jiri Olsa547740f2019-07-27 22:07:44 +020018/**
19 * struct perf_mmap - perf's ring buffer mmap details
20 *
21 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
22 */
23struct perf_mmap {
Jiri Olsa80e53d12019-10-07 14:53:15 +020024 void *base;
25 int mask;
26 int fd;
27 int cpu;
28 refcount_t refcnt;
29 u64 prev;
30 u64 start;
31 u64 end;
32 bool overwrite;
33 u64 flush;
34 libperf_unmap_cb_t unmap_cb;
35 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
Jiri Olsa6eb65f72019-10-17 12:59:09 +020036 struct perf_mmap *next;
Jiri Olsa547740f2019-07-27 22:07:44 +020037};
38
Jiri Olsae4409792019-10-07 14:53:10 +020039struct perf_mmap_param {
40 int prot;
41 int mask;
42};
43
Jiri Olsabf59b302019-10-07 14:53:11 +020044size_t perf_mmap__mmap_len(struct perf_mmap *map);
45
Jiri Olsa6eb65f72019-10-17 12:59:09 +020046void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
47 bool overwrite, libperf_unmap_cb_t unmap_cb);
Jiri Olsa32c261c2019-10-07 14:53:12 +020048int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
49 int fd, int cpu);
Jiri Olsa59d7ea622019-10-07 14:53:14 +020050void perf_mmap__munmap(struct perf_mmap *map);
Jiri Olsae75710f2019-10-07 14:53:13 +020051void perf_mmap__get(struct perf_mmap *map);
Jiri Olsa80e53d12019-10-07 14:53:15 +020052void perf_mmap__put(struct perf_mmap *map);
Jiri Olsa353120b2019-10-07 14:53:09 +020053
Jiri Olsa7728fa02019-10-07 14:53:17 +020054u64 perf_mmap__read_head(struct perf_mmap *map);
55
Rob Herring47d01e72021-04-14 11:07:39 -050056int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count);
57
Jiri Olsa547740f2019-07-27 22:07:44 +020058#endif /* __LIBPERF_INTERNAL_MMAP_H */