blob: a60e6ead7255350053f5edc073690e7fd31c3c46 [file] [log] [blame]
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -03001#ifndef __PERF_MMAP_H
2#define __PERF_MMAP_H 1
3
Jiri Olsa547740f2019-07-27 22:07:44 +02004#include <internal/mmap.h>
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -03005#include <linux/compiler.h>
6#include <linux/refcount.h>
7#include <linux/types.h>
Daniel Borkmann09d621542018-10-19 15:51:02 +02008#include <linux/ring_buffer.h>
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -03009#include <stdbool.h>
Arnaldo Carvalho de Melof2a39fe2019-08-30 14:45:20 -030010#include <pthread.h> // for cpu_set_t
Alexey Budankov0b773832018-11-06 12:03:35 +030011#ifdef HAVE_AIO_SUPPORT
12#include <aio.h>
13#endif
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030014#include "auxtrace.h"
15#include "event.h"
16
Alexey Budankovd3d1af62018-11-06 12:04:58 +030017struct aiocb;
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030018/**
Jiri Olsaa5830532019-07-27 20:30:53 +020019 * struct mmap - perf's ring buffer mmap details
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030020 *
21 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
22 */
Jiri Olsaa5830532019-07-27 20:30:53 +020023struct mmap {
Jiri Olsa547740f2019-07-27 22:07:44 +020024 struct perf_mmap core;
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030025 struct auxtrace_mmap auxtrace_mmap;
Alexey Budankov0b773832018-11-06 12:03:35 +030026#ifdef HAVE_AIO_SUPPORT
27 struct {
Alexey Budankov93f20c02018-11-06 12:07:19 +030028 void **data;
29 struct aiocb *cblocks;
30 struct aiocb **aiocb;
Alexey Budankovd3d1af62018-11-06 12:04:58 +030031 int nr_cblocks;
Alexey Budankov0b773832018-11-06 12:03:35 +030032 } aio;
33#endif
Alexey Budankov9d2ed642019-01-22 20:47:43 +030034 cpu_set_t affinity_mask;
Alexey Budankov51255a82019-03-18 20:42:19 +030035 void *data;
36 int comp_level;
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030037};
38
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030039struct mmap_params {
Jiri Olsae4409792019-10-07 14:53:10 +020040 struct perf_mmap_param core;
41 int nr_cblocks, affinity, flush, comp_level;
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030042 struct auxtrace_mmap_params auxtrace_mp;
43};
44
Jiri Olsa32c261c2019-10-07 14:53:12 +020045int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
Jiri Olsaa5830532019-07-27 20:30:53 +020046void perf_mmap__munmap(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030047
Jiri Olsaa5830532019-07-27 20:30:53 +020048void perf_mmap__get(struct mmap *map);
49void perf_mmap__put(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030050
Jiri Olsaa5830532019-07-27 20:30:53 +020051void perf_mmap__consume(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030052
Jiri Olsaa5830532019-07-27 20:30:53 +020053static inline u64 perf_mmap__read_head(struct mmap *mm)
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030054{
Jiri Olsa547740f2019-07-27 22:07:44 +020055 return ring_buffer_read_head(mm->core.base);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030056}
57
Jiri Olsaa5830532019-07-27 20:30:53 +020058static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030059{
Jiri Olsa547740f2019-07-27 22:07:44 +020060 ring_buffer_write_tail(md->core.base, tail);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030061}
62
Jiri Olsaa5830532019-07-27 20:30:53 +020063union perf_event *perf_mmap__read_forward(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030064
Jiri Olsaa5830532019-07-27 20:30:53 +020065union perf_event *perf_mmap__read_event(struct mmap *map);
Kan Liang7bb45972018-01-18 13:26:23 -080066
Jiri Olsaa5830532019-07-27 20:30:53 +020067int perf_mmap__push(struct mmap *md, void *to,
68 int push(struct mmap *map, void *to, void *buf, size_t size));
Arnaldo Carvalho de Melo73c17d82017-10-06 10:46:01 -030069
Jiri Olsabf59b302019-10-07 14:53:11 +020070size_t mmap__mmap_len(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030071
Jiri Olsaa5830532019-07-27 20:30:53 +020072int perf_mmap__read_init(struct mmap *md);
73void perf_mmap__read_done(struct mmap *map);
Arnaldo Carvalho de Melo16958492017-10-06 10:31:47 -030074#endif /*__PERF_MMAP_H */