Linux Audio

Check our new training course

Loading...
v5.4
 1#ifndef __PERF_MMAP_H
 2#define __PERF_MMAP_H 1
 3
 4#include <internal/mmap.h>
 5#include <linux/compiler.h>
 6#include <linux/refcount.h>
 7#include <linux/types.h>
 8#include <linux/ring_buffer.h>
 9#include <stdbool.h>
10#include <pthread.h> // for cpu_set_t
11#ifdef HAVE_AIO_SUPPORT
12#include <aio.h>
13#endif
14#include "auxtrace.h"
15#include "event.h"
16
17struct aiocb;
18/**
19 * struct mmap - perf's ring buffer mmap details
20 *
21 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
22 */
23struct mmap {
24	struct perf_mmap	core;
 
 
 
 
 
 
 
25	struct auxtrace_mmap auxtrace_mmap;
26#ifdef HAVE_AIO_SUPPORT
27	struct {
28		void		 **data;
29		struct aiocb	 *cblocks;
30		struct aiocb	 **aiocb;
31		int		 nr_cblocks;
32	} aio;
33#endif
34	cpu_set_t	affinity_mask;
35	void		*data;
36	int		comp_level;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37};
38
39struct mmap_params {
40	int prot, mask, nr_cblocks, affinity, flush, comp_level;
41	struct auxtrace_mmap_params auxtrace_mp;
42};
43
44int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
45void perf_mmap__munmap(struct mmap *map);
46
47void perf_mmap__get(struct mmap *map);
48void perf_mmap__put(struct mmap *map);
49
50void perf_mmap__consume(struct mmap *map);
51
52static inline u64 perf_mmap__read_head(struct mmap *mm)
53{
54	return ring_buffer_read_head(mm->core.base);
 
 
 
55}
56
57static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
58{
59	ring_buffer_write_tail(md->core.base, tail);
 
 
 
 
 
 
60}
61
62union perf_event *perf_mmap__read_forward(struct mmap *map);
63
64union perf_event *perf_mmap__read_event(struct mmap *map);
65
66int perf_mmap__push(struct mmap *md, void *to,
67		    int push(struct mmap *map, void *to, void *buf, size_t size));
68
69size_t perf_mmap__mmap_len(struct mmap *map);
70
71int perf_mmap__read_init(struct mmap *md);
72void perf_mmap__read_done(struct mmap *map);
73#endif /*__PERF_MMAP_H */
v4.17
  1#ifndef __PERF_MMAP_H
  2#define __PERF_MMAP_H 1
  3
 
  4#include <linux/compiler.h>
  5#include <linux/refcount.h>
  6#include <linux/types.h>
  7#include <asm/barrier.h>
  8#include <stdbool.h>
 
 
 
 
  9#include "auxtrace.h"
 10#include "event.h"
 11
 
 12/**
 13 * struct perf_mmap - perf's ring buffer mmap details
 14 *
 15 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
 16 */
 17struct perf_mmap {
 18	void		 *base;
 19	int		 mask;
 20	int		 fd;
 21	refcount_t	 refcnt;
 22	u64		 prev;
 23	u64		 start;
 24	u64		 end;
 25	bool		 overwrite;
 26	struct auxtrace_mmap auxtrace_mmap;
 27	char		 event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 28};
 29
 30/*
 31 * State machine of bkw_mmap_state:
 32 *
 33 *                     .________________(forbid)_____________.
 34 *                     |                                     V
 35 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
 36 *                     ^  ^              |   ^               |
 37 *                     |  |__(forbid)____/   |___(forbid)___/|
 38 *                     |                                     |
 39 *                      \_________________(3)_______________/
 40 *
 41 * NOTREADY     : Backward ring buffers are not ready
 42 * RUNNING      : Backward ring buffers are recording
 43 * DATA_PENDING : We are required to collect data from backward ring buffers
 44 * EMPTY        : We have collected data from backward ring buffers.
 45 *
 46 * (0): Setup backward ring buffer
 47 * (1): Pause ring buffers for reading
 48 * (2): Read from ring buffers
 49 * (3): Resume ring buffers for recording
 50 */
 51enum bkw_mmap_state {
 52	BKW_MMAP_NOTREADY,
 53	BKW_MMAP_RUNNING,
 54	BKW_MMAP_DATA_PENDING,
 55	BKW_MMAP_EMPTY,
 56};
 57
 58struct mmap_params {
 59	int			    prot, mask;
 60	struct auxtrace_mmap_params auxtrace_mp;
 61};
 62
 63int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd);
 64void perf_mmap__munmap(struct perf_mmap *map);
 65
 66void perf_mmap__get(struct perf_mmap *map);
 67void perf_mmap__put(struct perf_mmap *map);
 68
 69void perf_mmap__consume(struct perf_mmap *map);
 70
 71static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
 72{
 73	struct perf_event_mmap_page *pc = mm->base;
 74	u64 head = READ_ONCE(pc->data_head);
 75	rmb();
 76	return head;
 77}
 78
 79static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
 80{
 81	struct perf_event_mmap_page *pc = md->base;
 82
 83	/*
 84	 * ensure all reads are done before we write the tail out.
 85	 */
 86	mb();
 87	pc->data_tail = tail;
 88}
 89
 90union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
 91
 92union perf_event *perf_mmap__read_event(struct perf_mmap *map);
 93
 94int perf_mmap__push(struct perf_mmap *md, void *to,
 95		    int push(void *to, void *buf, size_t size));
 96
 97size_t perf_mmap__mmap_len(struct perf_mmap *map);
 98
 99int perf_mmap__read_init(struct perf_mmap *md);
100void perf_mmap__read_done(struct perf_mmap *map);
101#endif /*__PERF_MMAP_H */