]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - tools/perf/util/auxtrace.h
perf evlist: Add support for mmapping an AUX area buffer
[mirror_ubuntu-artful-kernel.git] / tools / perf / util / auxtrace.h
CommitLineData
718c602d
AH
1/*
2 * auxtrace.h: AUX area trace support
3 * Copyright (c) 2013-2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#ifndef __PERF_AUXTRACE_H
17#define __PERF_AUXTRACE_H
18
19#include <sys/types.h>
20#include <stdbool.h>
21
22#include <linux/perf_event.h>
23#include <linux/types.h>
24
25#include "../perf.h"
26
27struct perf_evlist;
28
29/**
30 * struct auxtrace_mmap - records an mmap of the auxtrace buffer.
31 * @base: address of mapped area
32 * @userpg: pointer to buffer's perf_event_mmap_page
33 * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
34 * @len: size of mapped area
35 * @prev: previous aux_head
36 * @idx: index of this mmap
37 * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
38 * mmap) otherwise %0
39 * @cpu: cpu number for a per-cpu mmap otherwise %-1
40 */
41struct auxtrace_mmap {
42 void *base;
43 void *userpg;
44 size_t mask;
45 size_t len;
46 u64 prev;
47 int idx;
48 pid_t tid;
49 int cpu;
50};
51
52/**
53 * struct auxtrace_mmap_params - parameters to set up struct auxtrace_mmap.
54 * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
55 * @offset: file offset of mapped area
56 * @len: size of mapped area
57 * @prot: mmap memory protection
58 * @idx: index of this mmap
59 * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
60 * mmap) otherwise %0
61 * @cpu: cpu number for a per-cpu mmap otherwise %-1
62 */
63struct auxtrace_mmap_params {
64 size_t mask;
65 off_t offset;
66 size_t len;
67 int prot;
68 int idx;
69 pid_t tid;
70 int cpu;
71};
72
73static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm)
74{
75 struct perf_event_mmap_page *pc = mm->userpg;
76#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
77 u64 head = ACCESS_ONCE(pc->aux_head);
78#else
79 u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0);
80#endif
81
82 /* Ensure all reads are done after we read the head */
83 rmb();
84 return head;
85}
86
87static inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail)
88{
89 struct perf_event_mmap_page *pc = mm->userpg;
90#if BITS_PER_LONG != 64 && defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
91 u64 old_tail;
92#endif
93
94 /* Ensure all reads are done before we write the tail out */
95 mb();
96#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
97 pc->aux_tail = tail;
98#else
99 do {
100 old_tail = __sync_val_compare_and_swap(&pc->aux_tail, 0, 0);
101 } while (!__sync_bool_compare_and_swap(&pc->aux_tail, old_tail, tail));
102#endif
103}
104
105int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
106 struct auxtrace_mmap_params *mp,
107 void *userpg, int fd);
108void auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
109void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
110 off_t auxtrace_offset,
111 unsigned int auxtrace_pages,
112 bool auxtrace_overwrite);
113void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
114 struct perf_evlist *evlist, int idx,
115 bool per_cpu);
116
117#endif