blob: bf9cc7d005ab3113a2485818256469b237e1d196 [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;
14
15typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
16
Jiri Olsa547740f2019-07-27 22:07:44 +020017/**
18 * struct perf_mmap - perf's ring buffer mmap details
19 *
20 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
21 */
22struct perf_mmap {
Jiri Olsa80e53d12019-10-07 14:53:15 +020023 void *base;
24 int mask;
25 int fd;
26 int cpu;
27 refcount_t refcnt;
28 u64 prev;
29 u64 start;
30 u64 end;
31 bool overwrite;
32 u64 flush;
33 libperf_unmap_cb_t unmap_cb;
34 char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
Jiri Olsa547740f2019-07-27 22:07:44 +020035};
36
Jiri Olsae4409792019-10-07 14:53:10 +020037struct perf_mmap_param {
38 int prot;
39 int mask;
40};
41
Jiri Olsabf59b302019-10-07 14:53:11 +020042size_t perf_mmap__mmap_len(struct perf_mmap *map);
43
Jiri Olsa80e53d12019-10-07 14:53:15 +020044void perf_mmap__init(struct perf_mmap *map, bool overwrite,
45 libperf_unmap_cb_t unmap_cb);
Jiri Olsa32c261c2019-10-07 14:53:12 +020046int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
47 int fd, int cpu);
Jiri Olsa59d7ea622019-10-07 14:53:14 +020048void perf_mmap__munmap(struct perf_mmap *map);
Jiri Olsae75710f2019-10-07 14:53:13 +020049void perf_mmap__get(struct perf_mmap *map);
Jiri Olsa80e53d12019-10-07 14:53:15 +020050void perf_mmap__put(struct perf_mmap *map);
Jiri Olsa353120b2019-10-07 14:53:09 +020051
Jiri Olsa547740f2019-07-27 22:07:44 +020052#endif /* __LIBPERF_INTERNAL_MMAP_H */