summaryrefslogtreecommitdiff
path: root/tools/lib/perf/include/internal/mmap.h
blob: 5f08cab61ecec6d25cd1a80e4a1c5bd83a0d12e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __LIBPERF_INTERNAL_MMAP_H
#define __LIBPERF_INTERNAL_MMAP_H

#include <linux/compiler.h>
#include <linux/refcount.h>
#include <linux/types.h>
#include <stdbool.h>
#include <internal/cpumap.h>

/* perf sample has 16 bits size limit */
#define PERF_SAMPLE_MAX_SIZE (1 << 16)

struct perf_mmap;
struct perf_counts_values;

typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);

/**
 * struct perf_mmap - perf's ring buffer mmap details
 *
 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
 */
struct perf_mmap {
	void			*base;
	int			 mask;
	int			 fd;
	struct perf_cpu		 cpu;
	refcount_t		 refcnt;
	u64			 prev;
	u64			 start;
	u64			 end;
	bool			 overwrite;
	u64			 flush;
	libperf_unmap_cb_t	 unmap_cb;
	void			*event_copy;
	size_t			 event_copy_sz;
	struct perf_mmap	*next;
};

struct perf_mmap_param {
	int	prot;
	int	mask;
};

size_t perf_mmap__mmap_len(struct perf_mmap *map);

void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
		     bool overwrite, libperf_unmap_cb_t unmap_cb);
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
		    int fd, struct perf_cpu cpu);
void perf_mmap__munmap(struct perf_mmap *map);
void perf_mmap__get(struct perf_mmap *map);
void perf_mmap__put(struct perf_mmap *map);

u64 perf_mmap__read_head(struct perf_mmap *map);

int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count);

#endif /* __LIBPERF_INTERNAL_MMAP_H */