blob: 5a062af8e9d8e2200aaecc3e110b7a750c2f78e7 [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>
Ian Rogers6d188042022-01-04 22:13:51 -08009#include <internal/cpumap.h>
Jiri Olsae03edfe2019-07-27 22:35:35 +020010
Jiri Olsa4443e6d2019-07-27 22:47:58 +020011/* perf sample has 16 bits size limit */
12#define PERF_SAMPLE_MAX_SIZE (1 << 16)
13
Jiri Olsa80e53d12019-10-07 14:53:15 +020014struct perf_mmap;
Rob Herring47d01e72021-04-14 11:07:39 -050015struct perf_counts_values;
Jiri Olsa80e53d12019-10-07 14:53:15 +020016
17typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
18
Jiri Olsa547740f2019-07-27 22:07:44 +020019/**
20 * struct perf_mmap - perf's ring buffer mmap details
21 *
22 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
23 */
24struct perf_mmap {
Jiri Olsa80e53d12019-10-07 14:53:15 +020025 void *base;
26 int mask;
27 int fd;
Ian Rogers6d188042022-01-04 22:13:51 -080028 struct perf_cpu cpu;
Jiri Olsa80e53d12019-10-07 14:53:15 +020029 refcount_t refcnt;
30 u64 prev;
31 u64 start;
32 u64 end;
33 bool overwrite;
34 u64 flush;
35 libperf_unmap_cb_t unmap_cb;
36 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
Jiri Olsa6eb65f72019-10-17 12:59:09 +020037 struct perf_mmap *next;
Jiri Olsa547740f2019-07-27 22:07:44 +020038};
39
Jiri Olsae4409792019-10-07 14:53:10 +020040struct perf_mmap_param {
41 int prot;
42 int mask;
43};
44
Jiri Olsabf59b302019-10-07 14:53:11 +020045size_t perf_mmap__mmap_len(struct perf_mmap *map);
46
Jiri Olsa6eb65f72019-10-17 12:59:09 +020047void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
48 bool overwrite, libperf_unmap_cb_t unmap_cb);
Jiri Olsa32c261c2019-10-07 14:53:12 +020049int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
Ian Rogers6d188042022-01-04 22:13:51 -080050 int fd, struct perf_cpu cpu);
Jiri Olsa59d7ea622019-10-07 14:53:14 +020051void perf_mmap__munmap(struct perf_mmap *map);
Jiri Olsae75710f2019-10-07 14:53:13 +020052void perf_mmap__get(struct perf_mmap *map);
Jiri Olsa80e53d12019-10-07 14:53:15 +020053void perf_mmap__put(struct perf_mmap *map);
Jiri Olsa353120b2019-10-07 14:53:09 +020054
Jiri Olsa7728fa02019-10-07 14:53:17 +020055u64 perf_mmap__read_head(struct perf_mmap *map);
56
Rob Herring47d01e72021-04-14 11:07:39 -050057int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count);
58
Jiri Olsa547740f2019-07-27 22:07:44 +020059#endif /* __LIBPERF_INTERNAL_MMAP_H */